2011-07-27 40 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

相关问题