【问题标题】:Programmatically creating a TFS iteration for a known deep path以编程方式为已知深度路径创建 TFS 迭代
【发布时间】:2016-01-25 18:31:41
【问题描述】:

描述了在 TFS 2013 中创建简单的迭代路径 herehere 描述了遍历未知深度的整个树。我需要创建一个迭代路径我知道它的确切路径,其中包含子目录,如\{ProjectName}\Iteration\{Year}\{Iteration}


编辑: 为了安全地做到这一点,我需要首先检查迭代路径的存在,这需要我检查 {Year} 和 {Iteration} 的存在。否则会抛出异常,我想避免基于异常的逻辑。


我只能找到一种方法,它是逐级的,使用方法CommonStructureService.GetNodesXml(),但是我必须解析XML,我失去了使用提供的API类型的优势,例如NodeInfo .有没有更好的方法来检查是否存在具有已知路径的更深的子节点,同时保留 API 域模型?

【问题讨论】:

    标签: c# api tfs


    【解决方案1】:

    您可以逐个创建迭代:先创建节点{Year},然后在{Year}下创建{Iteration}。详情见以下代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.Server;
    
    namespace AAAPI
    {
        class Program
        {
            static void Main(string[] args)
            {
                string project = "https://xxx.xxx.xxx.xxx/tfs";
                string projectName = "XXX";
                string node1 = "Year";
                string node2 = "Iter1";
                TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(project));
                tpc.Authenticate();
                Console.WriteLine("Creating node" + node1);
                var css = tpc.GetService<ICommonStructureService>();
                string rootNodePath = string.Format("\\{0}\\Iteration", projectName);
                var pt = css.GetNodeFromPath(rootNodePath);
                css.CreateNode(node1, pt.Uri);
                Console.WriteLine("Creating" + node1 + "Successfully");
                Console.WriteLine("Creating node" + node2);
                string parentNodePath = string.Format("\\{0}\\Iteration\\{1}", projectName, node1);
                var pt1 = css.GetNodeFromPath(parentNodePath);
                css.CreateNode(node2, pt1.Uri);
                Console.WriteLine("Creating" + node2 + "Successfully");
                Console.ReadLine();
            }
        }
    }
    

    【讨论】:

    • 是的,我现在明白我的问题表述不够清楚。这段代码很适合创建。请参阅我解释的用例和修改后的问题。
    • @tsemer 详情可以参考这篇文章:blog.wibeck.org/2013/02/…
    • 来吧,让我添加@Eddie 的名字 :-/ 谢谢,不幸的是,您提供的帖子使用了WorkItemStore,其中的结构有些不同,更重要的是那里的迭代是只读的。我需要使用ICommonStructureService 来添加迭代,所以我需要检查该特定服务是否存在。
    【解决方案2】:

    由于没有有效的答案,我将假设以下答案:

    不,在保留 API 类型域模型的同时,没有办法阅读比顶层更深的部分。 XML 目前是唯一的选择。

    【讨论】:

      猜你喜欢
      • 2018-09-08
      • 1970-01-01
      • 2015-05-28
      • 2011-08-12
      • 1970-01-01
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多