2014-07-17 124 views
1

您好可以有人請幫助我獲得給定團隊項目中的所有團隊。TFS SDK 2013在給定的團隊項目中獲取團隊名稱

當前的代碼所有團隊項目(從http://msdn.microsoft.com/en-us/library/bb286958.aspx

public void getTeamProjects() 
    { 
     TfsConfigurationServer configServer = TfsConfigurationServerFactory.GetConfigurationServer(_uri); 
     ReadOnlyCollection<CatalogNode> collectionNodes = configServer.CatalogNode.QueryChildren(
      new[] { CatalogResourceTypes.ProjectCollection }, 
      false, CatalogQueryOptions.None); 

     foreach (CatalogNode collectionNode in collectionNodes) 
     { 
      Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]); 
      TfsTeamProjectCollection teamProjectCollection = configServer.GetTeamProjectCollection(collectionId); 
      Console.WriteLine("Collection: " + teamProjectCollection.Name); 

      ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
      new[] { CatalogResourceTypes.TeamProject }, 
      false, CatalogQueryOptions.None); 

      foreach (CatalogNode projectNode in projectNodes) 
      { 
       Console.WriteLine("Team Project: " + projectNode.Resource.DisplayName); 
       // How do I access the Team names of each projectNode. 
      } 

     } 

     Console.WriteLine("Finished"); 
     Console.ReadKey(); 
    } 

目前,它被正確地打印出所有的團隊項目的控制檯上。我希望能夠訪問每個團隊項目中的團隊名稱。

回答

2

從codeplex上的ALM Rangers中檢查TFS團隊工具的源代碼。 The ListTeams method does exactly what you're after

this.teamService = this.teamProjectCollection.GetService<TfsTeamService>(); 

public List<string> ListTeams() 
{ 
    var teams = this.teamService.QueryTeams(this.projectInfo.Uri); 
    return (from t in teams select t.Name).ToList(); 
}