Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get latest version of file from TFS

Tags:

c#

I am trying to update local files from TFS but I can't get it to work. I don't even know why it is failing because TFS doesn't throw me an exception or anything, it just silently defies me and doesn't update anything.

public bool getLatest(string[] items)
{
    try
    {
        Workspace myWorkspace = createWorkspace();
        myWorkspace.Get(items, 
                        VersionSpec.Latest, 
                        RecursionType.Full, 
                        GetOptions.Overwrite);

        return true;
    }
    catch (Exception ex)
    {
        Tools.MessageLogger.LogError(ex.Message);
        return false;
    }
}

I have to add that all other communication with the TFS is just fine, pendingchanges, checkin or checkout are all working. This is quite frustrating.

like image 961
Flobbo Avatar asked Oct 21 '22 21:10

Flobbo


1 Answers

Whilst I've no prior knowledge in this, I thought I'd expand on my comment a little in the hope it might help (as no-one else seems to be answering).

According to the documentation, WorkSpace.Get() should return a GetStatus object which tells you how many warnings/failures/conflicts there were - at the moment you're just throwing this information away.

If you wanted to log the failures in getting latest in the same way that you're logging other errors, you could try this sort of thing:

public bool getLatest(string[] items)
{
    try
    {
        Workspace myWorkspace = createWorkspace();

        var results = myWorkspace.Get(items, VersionSpec.Latest, RecursionType.Full, GetOptions.Overwrite);
        var failures = results.GetFailures();

        foreach(var fail in failures)
        {
            Tools.MessageLogger.LogError(fail.GetFormattedMessage());
        }

        return failures.Count == 0;
    }
    catch (Exception ex)
    {
        Tools.MessageLogger.LogError(ex.Message);
        return false;
    }
}

I did write this in a text editor rather than a proper IDE, so apologies if I've made a typo/done something silly.

like image 96
Bridge Avatar answered Oct 27 '22 11:10

Bridge