以编程方式为已知深度路径创建TFS迭代

时间:2016-01-13 16:39:05

标签: c# api tfs tfs2013

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

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

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

2 个答案:

答案 0 :(得分: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();
        }
    }
}

答案 1 :(得分:0)

由于没有有效的答案,我将采取以下答案:

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

相关问题