撤消结帐TFS

时间:2014-03-19 07:05:50

标签: c# tfs

有没有办法在C#中以编程方式撤消结帐?

文件以编程方式检出,但如果代码在执行时没有改变,我希望撤消结帐。

public static void CheckOutFromTFS(string fileName)
{
    var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName);
    if (workspaceInfo == null)
        return;

    var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
    var workspace = workspaceInfo.GetWorkspace(server);
    workspace.PendEdit(fileName);
}

以上代码是我的结帐代码。

2 个答案:

答案 0 :(得分:5)

答案 1 :(得分:0)

我已按以下方式完成此任务:

private const string ConstTfsServerUri = @"http://YourTfsAddress:8080/tfs/";
 #region Undo
    public async Task<bool> UndoPendingChangesAsync(string path)
    {
        return await Task.Run(() => UndoPendingChanges(path));
    }

    private bool UndoPendingChanges(string path)
    {
        using (var tfs = TeamFoundationServerFactory.GetServer(ConstTfsServerUri))
        {
            tfs.Authenticate();
            // Create a new workspace for the currently authenticated user.   
            int res = 0;
            try
            {
                var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(ConstDefaultFlowsTfsPath);
                var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
                Workspace workspace = workspaceInfo.GetWorkspace(server);
                res = workspace.Undo(path, RecursionType.Full);

            }
            catch (Exception ex)
            {
                UIHelper.Instance.RunOnUiThread(() => MessageBox.Show(ex.Message));
            }

            return res == 1;//undo has been done succesfully
        }
    }