如何得到一个TFS API 2013所有迭代路径 [英] How to get all Iteration Paths with a TFS API 2013

查看:310
本文介绍了如何得到一个TFS API 2013所有迭代路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直使用TFS API库了一段时间,并已使用follwoing code。与TFS 2010接口,以获得迭代路径时
此页)...

I have been using the TFS API libraries for some time and have been using the follwoing code when interfacing with TFS 2010 to get the Iteration Paths (code from this page)...

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

When I was looking at getting all the iterations within TFS 2013 things changed. In TFS 2013 the concept of iterations changed slightly and the API assemblies for TFS 2013 do not have IterationRootNodes

我用下面的code获得团队迭代但这是基于团队的,而不是一整套针对项目的迭代...(目前获得了一线队,但可以通过codeD让别人)

I have used the following code to get Team Iterations but that is team based and not the full set of Iterations against the project... (currently getting the first team but can be coded to get others)

 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?

My question is... How do I get the full iteration tree rather than Team specific Iterations for TFS 2013?

团队具体迭代可以配置为显示或不通过门户网站通过对迭代的复选框。

Team specific iterations can be configured to show or not via the Web Portal via a checkbox against the iteration.

推荐答案

您的问题回答我如何得到球队具体迭代问题所以至少我能做的就是提供这种片段,得到完整的迭代层次结构。我想我最初发现在这个博客

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);
            }
        }
    }

这篇关于如何得到一个TFS API 2013所有迭代路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆