[英]How to get all Iteration Paths with a TFS API 2013
我已經使用TFS API庫已有一段時間了,並且在與TFS 2010交互以獲取迭代路徑時(從此頁面獲取代碼)一直在使用以下代碼...
public IList<string> GetIterationPaths(Project project)
{
List<string> iterations = new List<string>();
foreach (Node node in project.IterationRootNodes)
AddChildren(string.Empty, node, iterations);
return iterations;
}
private void AddChildren(string prefix, Node node, List<string> items)
{
items.Add(node.Path);
foreach (Node item in node.ChildNodes)
AddChildren(prefix + node.Name + "/", item, items);
}
當我希望在TFS 2013中獲得所有迭代時,事情發生了變化。 在TFS 2013中,迭代的概念略有更改,並且TFS 2013的API程序集沒有IterationRootNodes
我已經使用以下代碼獲取團隊迭代,但這是基於團隊的,而不是針對項目的完整迭代...(目前正在獲得第一團隊,但可以進行編碼以獲取其他團隊)
var cred = new TfsClientCredentials(new WindowsCredential(), true);
TfsTeamProjectCollection coll = new TfsTeamProjectCollection("{URI to SERVER}", cred);
coll.EnsureAuthenticated();
var teamConfig = coll.GetService<TeamSettingsConfigurationService>();
var css = coll.GetService<ICommonStructureService4>();
var project = css.GetProjectFromName(projectInfo.ProjectName);
IEnumerable<TeamConfiguration> configs = teamConfig.GetTeamConfigurationsForUser(new[] { project.Uri.ToString() });
TeamConfiguration team = configs.FirstOrDefault(x => x.ProjectUri == project.Uri.ToString());
var iterations = BuildIterationTree(team, css);
BuildIterationTree
看起來像...
private IList<IterationInfo> BuildIterationTree(TeamConfiguration team, ICommonStructureService4 css)
{
string[] paths = team.TeamSettings.IterationPaths;
var result = new List<IterationInfo>();
foreach (string nodePath in paths.OrderBy(x => x))
{
var projectNameIndex = nodePath.IndexOf("\\", 2);
var fullPath = nodePath.Insert(projectNameIndex, "\\Iteration");
var nodeInfo = css.GetNodeFromPath(fullPath);
var name = nodeInfo.Name;
var startDate = nodeInfo.StartDate;
var endDate = nodeInfo.FinishDate;
result.Add(new IterationInfo
{
IterationPath = fullPath.Replace("\\Iteration", ""),
StartDate = startDate,
FinishDate = endDate,
});
}
return result;
}
我的問題是...如何獲得完整的迭代樹,而不是TFS 2013的特定於團隊的迭代?
可以將特定於團隊的迭代配置為通過Web門戶顯示或不顯示該迭代復選框。
您的問題回答了我關於如何獲取特定於團隊的迭代的問題,因此,我能做的至少是提供可獲取完整迭代層次結構的代碼段。 我想我最初是在此博客上找到此代碼的:
public static void GetIterations(TfsTeamProjectCollection collection,
ICommonStructureService4 css, ProjectInfo project)
{
TeamSettingsConfigurationService teamConfigService = collection.GetService<TeamSettingsConfigurationService>();
NodeInfo[] structures = css.ListStructures(project.Uri);
NodeInfo iterations = structures.FirstOrDefault(n => n.StructureType.Equals("ProjectLifecycle"));
XmlElement iterationsTree = css.GetNodesXml(new[] { iterations.Uri }, true);
string baseName = project.Name + @"\";
BuildIterationTree(iterationsTree.ChildNodes[0].ChildNodes, baseName);
}
private static void BuildIterationTree(XmlNodeList items, string baseName)
{
foreach (XmlNode node in items)
{
if (node.Attributes["NodeID"] != null &&
node.Attributes["Name"] != null &&
node.Attributes["StartDate"] != null &&
node.Attributes["FinishDate"] != null)
{
string name = node.Attributes["Name"].Value;
DateTime startDate = DateTime.Parse(node.Attributes["StartDate"].Value, CultureInfo.InvariantCulture);
DateTime finishDate = DateTime.Parse(node.Attributes["FinishDate"].Value, CultureInfo.InvariantCulture);
// Found Iteration with start / end dates
}
else if (node.Attributes["Name"] != null)
{
string name = node.Attributes["Name"].Value;
// Found Iteration without start / end dates
}
if (node.ChildNodes.Count > 0)
{
string name = baseName;
if (node.Attributes["Name"] != null)
name += node.Attributes["Name"].Value + @"\";
BuildIterationTree(node.ChildNodes, name);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.