2016-01-13 54 views
0

在TFS 2013中創建簡單迭代路徑的描述here。遍歷未知深度的整棵樹被描述爲here。我需要創建一個迭代路徑,其中我知道確切的路徑,以及其中包含的子目錄,如\{ProjectName}\Iteration\{Year}\{Iteration}爲已知深度路徑編程創建TFS迭代


編輯: 爲了做到這一點安全,我需要先檢查迭代路徑的存在性,這要求我檢查{Year}和{Iteration}是否存在。否則會引發異常,我想避免基於異常的邏輯。


我能找到的唯一一個這樣做的方式,它是一層一層,使用方法CommonStructureService.GetNodesXml(),但後來我不得不解析XML和我失去了使用所提供的API類型,如NodeInfo的優勢。有沒有更好的方法來檢查是否存在具有已知路徑的更深的孩子,同時保留API域模型?

回答

0

由於沒有有效的答案來了,我要承擔以下答案:

沒有,有沒有辦法讀出比頂級任何更深的部分,同時保留API類型的域模型。 XML是目前唯一的選擇。

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(); 
     } 
    } 
} 
+0

是的,我現在看到,我沒有清楚地陳述我的問題。此代碼適用於創建。請參閱我解釋的用例和修改後的問題。 – tsemer

+0

@tsemer你可以參考這篇文章的詳細信息:http://blog.wibeck.org/2013/02/get-all-iteration-paths-in-tfs-programtically/ –

+0

*來吧所以讓我添加@埃迪的name *: -/thank you,不幸的是你提供的帖子使用了'WorkItemStore',其中結構有些不同,更重要的是,迭代只能讀取。我需要使用'ICommonStructureService'來添加迭代,所以我需要檢查該特定服務中是否存在。 – tsemer