Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# TFS客户端API-查询以获取链接到特定文件的工作项?_C#_.net_Visual Studio 2008_Tfs - Fatal编程技术网

C# TFS客户端API-查询以获取链接到特定文件的工作项?

C# TFS客户端API-查询以获取链接到特定文件的工作项?,c#,.net,visual-studio-2008,tfs,C#,.net,Visual Studio 2008,Tfs,我们正在使用TFS客户端API编写一个定制工具,用于连接TFS,获取项目的工作项等 我们正在使用WIQL查询工作项存储 给定一个完全限定的文件名,获取具有包含指定文件的更改集的工作项列表的最简单方法是什么 我不确定是否有一种简单的方法可以使用TFS API执行您请求的查询。我知道你肯定不能用WIQL来做这件事。我认为,使用API,您必须迭代所有工作项——在其中获取变更集链接,然后在每个变更集中查找您要查找的文件路径。这显然没有多大用处 但是,您可以使用TFS数据仓库数据库获取该数据。此信息将落

我们正在使用TFS客户端API编写一个定制工具,用于连接TFS,获取项目的工作项等


我们正在使用WIQL查询工作项存储


给定一个完全限定的文件名,获取具有包含指定文件的更改集的工作项列表的最简单方法是什么

我不确定是否有一种简单的方法可以使用TFS API执行您请求的查询。我知道你肯定不能用WIQL来做这件事。我认为,使用API,您必须迭代所有工作项——在其中获取变更集链接,然后在每个变更集中查找您要查找的文件路径。这显然没有多大用处


但是,您可以使用TFS数据仓库数据库获取该数据。此信息将落后于实时操作存储信息,因为仓库只会定期更新,但允许您非常轻松地按文件夹/文件维度跟踪信息。

此小代码片段将为您提供一个TFS服务器名称和项目的工作项集合。。它还过滤掉处于已删除状态的工作项

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

    namespace EngineTFSAutomation
    {
        class TFSHelper
        {
            static public WorkItemCollection QueryWorkItems(string server, string projectname)
            {
                TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(server);
                WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
                Project p = workItemStore.Projects[projectname];
                string wiqlQuery = "Select * from Issue where [System.TeamProject] = '"+projectname+"'";
                wiqlQuery += " and [System.State] <> 'Deleted'";
                wiqlQuery+= " order by ID";
                WorkItemCollection witCollection = workItemStore.Query(wiqlQuery);
                return witCollection;
            }
        }
    }
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用Microsoft.TeamFoundation.Client;
使用Microsoft.TeamFoundation.WorkItemTracking.Client;
命名空间EngineTFSAutomation
{
TFSHelper类
{
静态公共工作项集合查询工作项(字符串服务器、字符串项目名称)
{
TeamFoundationServer tfs=TeamFoundationServerFactory.GetServer(服务器);
WorkItemStore WorkItemStore=(WorkItemStore)tfs.GetService(typeof(WorkItemStore));
Project p=workItemStore.Projects[projectname];
string wiqlQuery=“Select*from Issue,其中[System.TeamProject]=”“+projectname+”;
wiqlQuery+=”和[System.State]“已删除”;
wiqlQuery+=“按ID排序”;
WorkItemCollection-witCollection=workItemStore.Query(wiqlQuery);
回收;
}
}
}

适用于2012年TFS

    Uri tfsUri = new Uri("http://xxx.xx.xx.xxx:8080/tfs2012");
    TfsConfigurationServer configurationServer =TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);                  
    ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(new[] {CatalogResourceTypes.ProjectCollection },false,CatalogQueryOptions.None);   

    foreach (CatalogNode collectionNode in collectionNodes)
    {
        // Use the InstanceId property to get the team project collection
        Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
        TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);

        WorkItemStore workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));

        string query = "SELECT [System.Id] FROM WorkItems where [Assigned to]=@Me";
        WorkItemCollection queryResults = workItemStore.Query(query);

    }
Uri-tfsUri=新Uri(“http://xxx.xx.xx.xxx:8080/tfs2012");
TfsConfigurationServer configurationServer=TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
ReadOnlyCollectionNodes=configurationServer.CatalogNode.QueryChildren(新[]{CatalogResourceTypes.ProjectCollection},false,CatalogQueryOptions.None);
foreach(collectionNodes中的CatalogNode collectionNode)
{
//使用InstanceId属性获取团队项目集合
Guid collectionId=新Guid(collectionNode.Resource.Properties[“InstanceId”]);
TfsTeamProjectCollection teamProjectCollection=configurationServer.GetTeamProjectCollection(collectionId);
WorkItemStore WorkItemStore=(WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));
string query=“从工作项中选择[System.Id],其中[Assigned to]=@Me”;
WorkItemCollection queryResults=workItemStore.Query(查询);
}

对于TFS 2013,以下代码用于访问TFS项目信息:

var tfsUri = new Uri("http://tfs.xxx.xxx.com:8080/tfs/myCollection");
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);
tfs.EnsureAuthenticated();
var iis = tfs.GetService<Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore>();
// here access to a particular Project with its name
var uriWithGuid = iis.Projects["My project name"].Uri;
var-tfsUri=新Uri(“http://tfs.xxx.xxx.com:8080/tfs/myCollection");
var tfs=tfstreamprojectcollectionfactory.GetTeamProjectCollection(tfsUri);
tfs.确保重新验证();
var iis=tfs.GetService();
//在这里,您可以访问具有其名称的特定项目
var uriWithGuid=iis.Projects[“我的项目名称”].Uri;

我刚刚意识到,您正在寻找一种方法来获取具有影响特定文件的变更集的所有工作项的列表。WIQL查询将为您提供所有工作项,然后我想您可以迭代每个具有链接的工作项。如果链接是变更集,您可以查看变更集是否包含有问题的文件。我将看看是否可以编写类似的代码,稍后我将修改我的答案。我正在尝试您提供的代码,并得到警告,TeamFoundationServer类在TFS 2010中不推荐使用。我使用了
tfstreamprojectcollection tfs=newtfstreamprojectcollection(newuri(server));tfs.确保重新验证()虽然有效,但查询似乎永远运行(并且不会结束)。你有什么提示吗?