从TFS获取当前迭代路径 [英] Get the current iteration path from TFS
问题描述
我正在尝试获取团队TFS项目的当前迭代路径.我尝试执行此操作的方法是使用 http://blog.johnsworkshop.net/tfs11-api-reading-the-team-configuration-iterations-and-areas/.我首先从以下代码获取团队配置:
I'm trying to get the current iteration path for the teams TFS project. The way I'm trying to do this is by using the blog from http://blog.johnsworkshop.net/tfs11-api-reading-the-team-configuration-iterations-and-areas/ . I start by getting the team configurations from the following code:
TfsTeamProjectCollection tpc = TFSConncetion(@"http://tfs/url");
var configSvc = tpc.GetService<TeamSettingsConfigurationService>();
var configs = configSvc.GetTeamConfigurationsForUser(projectUri);
问题是,即使我是团队成员,我的配置也始终为null.我很肯定我的项目URI也正确.之后,我将获取团队设置并使用它来显示当前迭代路径.
The problem with this is that my configs is always null, even though I'm a member of the team. I'm positive my projects URI is correct as well. After this I would get the team settings and use that to display the current iteration path.
TeamSettings ts = config.TeamSettings;
Console.WriteLine(ts.CurrentIterationPath);
即使这种方法行不通,我仍然可以从团队设置中查询迭代日期,以获取具有今天之前的开始日期和今天之后的结束日期的一个迭代.主要问题是,当我尝试使用项目URI获取团队配置时,我无法让TeamSettingsConfigurationService返回任何内容,但只能返回null.
Even if this didn't work I can still query the iteration dates from the team setting to get the one iteration that has a start date before today and finish date after today. The main problem is that I can't get my TeamSettingsConfigurationService to return anything but null when I try to get the team configurations with my projects URI.
推荐答案
我实际上根本没有使用TeamSettingsConfigurationService就能得到答案.这是我的操作方式:
I actually got the answer myself without using TeamSettingsConfigurationService at all. Here's how I did it:
private static XmlNode currentIterationNode;
TfsTeamProjectCollection tpc = TFSConncetion(@"http://tfs/url");
ICommonStructureService4 css = tpc.GetService<ICommonStructureService4>();;
WorkItemStore workItemStore = new WorkItemStore(tpc);
foreach (Project teamProject in workItemStore.Projects)
{
if (teamProject.Name.Equals("TeamProjectNameGoesHere"))
{
NodeInfo[] structures = css.ListStructures(teamProject.Uri.ToString());
NodeInfo iterations = structures.FirstOrDefault(n => n.StructureType.Equals("ProjectLifecycle"));
if (iterations != null)
{
XmlElement iterationsTree = css.GetNodesXml(new[] { iterations.Uri }, true);
XmlNodeList nodeList = iterationsTree.ChildNodes;
currentIterationNode = FindCurrentIteration(nodeList);
String currentIterationPath = currentIterationNode.Attributes["Path"].Value;
}
}
}
其中currentIterationPath是TFS的当前迭代路径.这样做的关键是从我从chamindacNavantis
Where currentIterationPath is the current iteration path from TFS. The key to doing this was to get the NodeInfo[] array of structures and the NodeInfo iterations from these two lines of code I got from chamindacNavantis https://social.msdn.microsoft.com/Forums/vstudio/en-US/4b785ae7-66c0-47ee-a6d2-c0ad8a3bd420/tfs-get-iteration-dates-metadata?forum=tfsgeneral:
NodeInfo[] structures = css.ListStructures(teamProject.Uri.ToString());
NodeInfo iterations = structures.FirstOrDefault(n => n.StructureType.Equals("ProjectLifecycle"));
此后,我创建了一个xml,其中包含团队项目中每个迭代的节点.这些节点还具有每次迭代的开始日期和结束日期.因此,我检查了每个节点的DateTime.Now之前的开始日期和DateTime.Now之后的完成日期,这是FindCurrentIteration(nodeList)所做的全部工作.这将为您提供当前的迭代节点.
After that I created an xml with nodes of every iteration inside the team project. These nodes also have the start date and end dates of each iteration. So I checked each node for a start date before DateTime.Now and finish date after DateTime.Now, which is all FindCurrentIteration(nodeList) does. And that will give you the current iteration node.
这篇关于从TFS获取当前迭代路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!