none
TFS API. How to get percent complete when getting latest version.

    Question

  • Hello,

    I try to get latest source code from TFS in my C# program. I've added event handler of VersionControlServer's Getting event. Now, I would like to add progress bar to visualize the getting process, but GettingEventArgs does not contains a Percent Complete properties or something else. So, How can I get percent complete when getting source code from TFS?

    ...
    var vcs = tfs.GetService<VersionControlServer>();
    var workspace = vcs.QueryWorkspaces(null, vcs.AuthorizedUser, Environment.MachineName)[0];
    vcs.Getting += new GettingEventHandler(vcs_Getting);
    var status = workspace.Get(new GetRequest(sourceLocation, RecursionType.Full, VersionSpec.Latest), GetOptions.GetAll);
    ...
    
    void vcs_Getting(object sender, GettingEventArgs e)
    {	
     // Can I get percent complete here or somewhere else?
    }
    

    I use TFS API for Visual Studio 2010

    Thanks!

    Wednesday, July 13, 2011 7:59 AM

Answers

  • Hi foux,

    Very good question. I think you can do the following,

    public static void GetWorkSpaceDownLoadProgress()
        {
          var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfs2010/tfs/default"));
          tfs.EnsureAuthenticated();
          var vcs = tfs.GetService<VersionControlServer>();
          var workspace = vcs.QueryWorkspaces(null, vcs.AuthorizedUser, Environment.MachineName)[0];
          vcs.Getting += new GettingEventHandler(vcs_Getting);
          var status = workspace.Get(new GetRequest(@"$\ETRM\MAIN", RecursionType.Full, VersionSpec.Latest),
                        GetOptions.GetAll);
    
        }
    
        static void vcs_Getting(object sender, GettingEventArgs e)
        {
          var status = ((GettingEventArgs) e);
    // 2 internal properties
    // 1. Current
    // 2. Total
          
        }

    Attached a screen shot of the 2 available internal properties @ => http://geekswithblogs.net/images/geekswithblogs_net/TarunArora/12866/o_GetWorkspaceOperationStatus.png 

    So, you can base your progress bar on the current and the total count.

    HTH.

    Cheers, Tarun


    Tarun Arora if the post helps 'Propose as Answer'. My Blog http://geekswithblogs.net/tarunArora/default.aspx
    • Marked as answer by foux Wednesday, July 13, 2011 1:07 PM
    Wednesday, July 13, 2011 10:52 AM

All replies

  • Hi foux,

    Very good question. I think you can do the following,

    public static void GetWorkSpaceDownLoadProgress()
        {
          var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfs2010/tfs/default"));
          tfs.EnsureAuthenticated();
          var vcs = tfs.GetService<VersionControlServer>();
          var workspace = vcs.QueryWorkspaces(null, vcs.AuthorizedUser, Environment.MachineName)[0];
          vcs.Getting += new GettingEventHandler(vcs_Getting);
          var status = workspace.Get(new GetRequest(@"$\ETRM\MAIN", RecursionType.Full, VersionSpec.Latest),
                        GetOptions.GetAll);
    
        }
    
        static void vcs_Getting(object sender, GettingEventArgs e)
        {
          var status = ((GettingEventArgs) e);
    // 2 internal properties
    // 1. Current
    // 2. Total
          
        }

    Attached a screen shot of the 2 available internal properties @ => http://geekswithblogs.net/images/geekswithblogs_net/TarunArora/12866/o_GetWorkspaceOperationStatus.png 

    So, you can base your progress bar on the current and the total count.

    HTH.

    Cheers, Tarun


    Tarun Arora if the post helps 'Propose as Answer'. My Blog http://geekswithblogs.net/tarunArora/default.aspx
    • Marked as answer by foux Wednesday, July 13, 2011 1:07 PM
    Wednesday, July 13, 2011 10:52 AM
  • Hi Tarun,

    It works. Great! Thank you.

    Wednesday, July 13, 2011 1:07 PM
  • Hi foux, how were you able to access these internal properties of GettingEventArgs? 

    Monday, March 12, 2012 11:13 AM
  • Hi foux,

    Very good question. I think you can do the following,

    public static void GetWorkSpaceDownLoadProgress()
        {
          var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfs2010/tfs/default"));
          tfs.EnsureAuthenticated();
          var vcs = tfs.GetService<VersionControlServer>();
          var workspace = vcs.QueryWorkspaces(null, vcs.AuthorizedUser, Environment.MachineName)[0];
          vcs.Getting += new GettingEventHandler(vcs_Getting);
          var status = workspace.Get(new GetRequest(@"$\ETRM\MAIN", RecursionType.Full, VersionSpec.Latest),
                        GetOptions.GetAll);
    
        }
    
        static void vcs_Getting(object sender, GettingEventArgs e)
        {
          var status = ((GettingEventArgs) e);
    // 2 internal properties
    // 1. Current
    // 2. Total
          
        }

    Attached a screen shot of the 2 available internal properties @ => http://geekswithblogs.net/images/geekswithblogs_net/TarunArora/12866/o_GetWorkspaceOperationStatus.png 

    So, you can base your progress bar on the current and the total count.

    HTH.

    Cheers, Tarun


    Tarun Arora if the post helps 'Propose as Answer'. My Blog http://geekswithblogs.net/tarunArora/default.aspx

    I had the same question... how the heck do you access the internal properties...

    This will never work :

    static void vcs_Getting(object sender, GettingEventArgs e)
        {
          var status = ((GettingEventArgs) e);
          int currentItem = e.Current;
          
        }

    Does any one know an answer to this ?

    Friday, July 13, 2012 9:53 AM
  • Hi Tarun,

    It works. Great! Thank you.

    Really????  Do tell us how you accessed INTERNAL properties of the GettingEventArgs object ?
    Friday, July 13, 2012 9:54 AM
  • Reflection would be the only way. I believe the Total property has been made public in the TFS 2012 object model. You can count the number of GettingEventArgs you get yourself to provide a value for "Current".

    This will only be an accurate progress mechanism if the number of items you are getting is less than 250,000, which is the "page size" for Get. I believe this is why these properties have been marked internal for so long.

    Thanks,
    P. Kelley

    Friday, July 13, 2012 11:55 AM
  • Hi, I was able to get the values by using the below code 


    internal static object GetInstanceField(Type type, object instance, string fieldName)
            {
                const BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                                               | BindingFlags.Static;
                PropertyInfo  field = type.GetProperty(fieldName, bindFlags);

                return field.GetValue(instance, null);

            }

      Total = (GetInstanceField(typeof(GettingEventArgs), e, "Total")).ToString();

                
    Saturday, October 05, 2013 9:49 AM