2011-07-27 36 views
0

我正在尋找一個很好的示例來與TFS 2010集合,項目和工作項目一起工作。如何從特定集合中檢索TFS2010項目

我可以通過使用下面的代碼集合和項目迭代(感謝原來的編碼器)

Dim tfsServer As String = "http://test.domain.com:8080/tfs" 
    tfsServer = tfsServer.Trim() 
    Dim tfsUri As Uri 
    tfsUri = New Uri(tfsServer) 
    Dim configurationServer As New TfsConfigurationServer(tfsUri) 
    configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri) 

    ' Get the catalog of team project collections 
    Dim collectionNodes As ReadOnlyCollection(Of CatalogNode) 
    Dim gVar As Guid() = New Guid() {CatalogResourceTypes.ProjectCollection} 
    collectionNodes = configurationServer.CatalogNode.QueryChildren(gVar, False, CatalogQueryOptions.None) 

    Dim strName As New StringBuilder 
    Dim strCollection As New StringBuilder 

    For Each collectionNode In collectionNodes 
     Dim collectionId As Guid = New Guid(collectionNode.Resource.Properties("InstanceID")) 
     strName.Length = 0 
     Dim teamProjectCollection As New TfsTeamProjectCollection(tfsUri) 
     teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId) 
     Response.Write("Collection:" & teamProjectCollection.Name & "<br/>") 

     ' Get a catalog of team projects for the collection 
     Dim hVar As Guid() = New Guid() {CatalogResourceTypes.TeamProject} 

     Dim projectNodes As ReadOnlyCollection(Of CatalogNode) 
     projectNodes = collectionNode.QueryChildren(hVar, False, CatalogQueryOptions.None) 

     ' List the team projects in the collection 
     For Each projectNode In projectNodes 
      strName.AppendLine(projectNode.Resource.DisplayName & "<br>") 
      'System.Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName) 
     Next 

     Response.Write(strName.ToString()) 

    Next 

我想從一個集合讀取特定項目,並通過工作項(任務,錯誤,問題重複,等等)。任何幫助將不勝感激。

謝謝。

回答

1

您可以運行您在teamProjectCollection喜歡的任何查詢 - 與級別: - 字符串中的東西,爲你提供你所需要的

 WorkItemStore workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore)); 
     WorkItemCollection queryResults = workItemStore.Query(query); 

     foreach (WorkItem workitem in queryResults) 
     { 
      Console.WriteLine(workitem.Title);    
     } 

現在你只需要制定query。查詢有WIQL - like。這很基本的可以給你一個TeamProject內的所有工作項目:

SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] FROM WorkItems WHERE [System.TeamProject] = @project 


@project是在我們的例子中projectNode.Resource.DisplayName

(可以保存你已經在TFS圖形設置爲'任何查詢保存爲'as a * .wiq文件&然後以編程方式使用它的內容)

+0

非常感謝你@pantelif。代碼完全正是我想要的。 – SSiddiqui

相關問題