Cancel TFS

Is there a way to cancel a software check in C #?

Files are extracted programmatically, but if the code does not change at runtime, I want the check to be canceled.

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);
}

The above code is my statement code.

+4
source share
2 answers

I completed this task as follows:

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
        }
    }
0
source

Source: https://habr.com/ru/post/1532427/


All Articles