How to get all Iteration Paths with a TFS API 2013

社会主义新天地 提交于 2019-12-02 00:50:36

Your question answered my question on how to get the team specific iterations so the least I can do is offer this snippet that gets the full iteration hierarchy. I think I originally found this code on this blog:

    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);
            }
        }
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!