使用TFS API检测文件删除更改(自动,无需VS交互) [英] Detect file delete changes with TFS API (automated, without VS interaction)

查看:99
本文介绍了使用TFS API检测文件删除更改(自动,无需VS交互)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在tfs工作区中有一个本地文件夹,并使用TFS-API.

I have a local folder within the tfs workspace and use the TFS-API.

每天晚上,我都会删除此文件夹,然后将数据库脚本编写为.sql文件. 如果现在添加或编辑了某些内容,将找到更改并进入待处理的更改以进行签入.

Every night i do delete this folder and and after that script a database as .sql files. If now something was added or edited, the changes will be found and get into the pending changes to checkin.

问题是我如何使用TFS-API来检测文件丢失(有意地,因为不再存在于数据库中,并且因为不再编写脚本). 第一步很明显,删除所有文件并在空文件夹中添加脚本.

The question is how i can detect with the TFS-API that a file is missing (intentionally, because no longer in database and becaus of that no longer scripted). The first step is obvious, delete all files and script all in the empty folder.

我在一开始使用workspace.PendEdit,这使我能够从外部覆盖文件. 数据库脚本编写完成后,我将创建一个工作区.PendEdit和工作区.PendAdd.

I use workspace.PendEdit at the beginning which makes me able to override the files from external. After the scripting of database is done, i will do a workspace.PendEdit and workspace.PendAdd.

这按预期工作.但是workspace.PendDelete找不到已删除的文件,因此无法将这些已删除的文件添加到挂起的更改中.

This works as expected. But workspace.PendDelete does not find deleted files, and therefore cannot adding theses as deleted to the pending changes.

动力工具中有一个用于tfs的命令工具,它具有一个在线标志,我该这样做.

There is a commeandline tool from power tools for tfs which has a online flag which should do that, what i wan.

我的问题:我可以用tfs-api描述什么吗? 如果这不起作用,那么有人有这个在线标志吗?

My Question: is it possible to do, what i described with the tfs-api? If this wont working, has anybody expierence with this online-flag?

我在本地文件夹中有两个文件:1.sql和2.sql 最初将这两个文件签入.

I have two files in a local folder: 1.sql and 2.sql These two files are checked in initially.

我删除了2.sql local(不了解tfs) 我添加一个文件:3.sql 我编辑1. sql

I delete 2.sql local (without knowledge of tfs) I add one file: 3.sql I edit 1. sql

现在,我使用workspace.PendEdit和工作区PendAdd来检测已编辑和已添加的文件.这些文件将被检测为正常.

Now, i use workspace.PendEdit and workspace PendAdd to detect edited and added files. These files will be detected just fine.

这是问题所在:缺少2.sql的删除或删除操作将不会被检测到,因此无法在服务器上删除.

And here is the problem: the deletion oder the missing of 2.sql will not be detected and therefore cannot be deleted on the server.

那么:如何在不了解tfs的情况下检测丢失的文件/本地删除的文件?

So: how to detect missing files / locally deleted files without knowledge of tfs?

我希望这可以澄清我的问题.

I hope this clarifies my question.

伪代码示例:

DeleteWorkspaceFolderContent(); // Because i do not delete but regenerate my Sql scripts.
GenerateSqlScriptsToWorkspaceFolder(); // .sql files are generated to the same folder, they were deleted before

//现在,我做了workspace.PendAdd(localPath, true);workspace.PendEdit(localPath, RecursionType.Full);,它们像一个Sharm一样工作,因此将在新的.sql文件之前添加和编辑(实际更改的脚本)在"change-Checkin"之前.

// Now at this point, i did workspace.PendAdd(localPath, true); and workspace.PendEdit(localPath, RecursionType.Full); which worked like a sharm, so new .sql files will be pended for adding and edited (real changed scripts) pended for "change-Checkin".

//至此,我开始执行workspace.PendDelete(new [] { localPath }, RecurstionType.Fulll);相同的操作:看到文件本地丢失,然后将其挂出以在服务器上删除.但这不会发生.没有添加待处理的更改.

// At this point i tought workspace.PendDelete(new [] { localPath }, RecurstionType.Fulll); does the same: Seeing that a file is locally missing and then pend this files for deletion on the server. But this does not happen. No pending changes are added.

var pendingChanges = workspace.GetPendingChanges(localPath, RecursionType.Full);

workspace.CheckIn(pendingChanges, "Per TFS-API, " + DateTime.Now.ToString());

推荐答案

您真正想做的是使用本地工作区,然后让TFS为您处理.它将检测文件的修改,添加和删除,并自动为您挂起.

What you really want to do is use a Local Workspace and let TFS deal with this for you. It will detect modifications, additions and removals of files and pend them for you automatically.

如果要为此使用TFS API,则需要检查候选挂起的更改"(TFS客户端已确定在磁盘上存在的更改),然后将其升级为实际的挂起的更改.例如:

If you want to use the TFS API for this, then you will need to examine your "candidate pending changes" (the ones that the TFS client has determined exist on disk) and then promote them to actual pending changes. For example:

PendingChange[] candidates;
workspace.GetPendingChangesWithCandidates(
    new ItemSpec[] { new ItemSpec(@"C:\Local\Path", RecursionType.Full) },
    false,
    out candidates);

foreach (PendingChange pc in candidates)
{
    if ((pc.ChangeType & ChangeType.Delete) == ChangeType.Delete)
    {
        workspace.PendDelete(pc.LocalItem);
    }
    else if ((pc.ChangeType & ChangeType.Add) == ChangeType.Add)
    {
        workspace.PendAdd(pc.LocalItem);
    }
    else
    {
        workspace.PendEdit(pc.LocalItem);
    }
}

PendingChange[] changes = workspace.GetPendingChanges();

/* Now you can review and CheckIn your changes. */

如果您不能执行此操作(因为您正在运行TFS或Visual Studio的旧版本,或由于其他原因),则应使用

If you can't do that (because you're running old versions of TFS or Visual Studio, or for some other reason) then you should just use the TFS Power Tools and run tfpt online.

如果您真的真的要使用TFS API,那么您只需执行tfpt online命令的操作即可:

If you really, really want to use the TFS API for this, then you'll simply have to do what the tfpt online command does:

  1. 扫描整个本地工作文件夹映射
  2. 针对本地工作文件夹映射运行QueryItems
  3. 对于本地项目中存在但服务器上不存在的任何文件,请添加
  4. 对于服务器项中存在但本地文件系统中不存在的任何文件,请删除
  5. 对于其他任何项目,请确定其是否可写.如果是这样,请进行编辑. (请注意,您可能希望检查文件的MD5哈希值,以确定它是实际上编辑过的还是刚刚被标记为可写的.)
  1. Scan the entire local working folder mappings
  2. Run a QueryItems against the local working folder mappings
  3. For any files that exist in the local items but do not exist on the server, pend an add
  4. For any files that exist in the server items but do not exist on the local filesystem, pend a delete
  5. For any other item, determine if it is writable. If so, pend an edit. (Note, you may wish to check the MD5 hash of the file to determine if it was actually edited or just marked writable.)

这篇关于使用TFS API检测文件删除更改(自动,无需VS交互)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆