2017-12-19 8 views
0

TFSプロジェクトから現在の反復のパスを取得する必要があります。 REST APIクエリ<server>/<project>/_apis/work/teamsettings/iterations?$timeframe=current&api-version=v2.0-previewを使用することはできますが、クエリを実行してJSON応答を解析したくありません。 .NET client libraries for VSTS (and TFS)に適切なAPIを使用したいと思います。TFSから現在の反復を取得

私はVssConnectionのインスタンスを持っています。このオブジェクトから現在の反復のパスを取得するにはどうすればよいですか?ここで

答えて

0

を私はVssConnectionを使用して解決策を見つけた:

var workClient = connection.GetClient<WorkHttpClient>(); 
var iterations = workClient.GetTeamIterationsAsync(new TeamContext("project-name")).Result; 

var currentDate = DateTime.Now.Date; 
var currentIterationPath = iterations 
    .Select(i => new { i.Path, i.Attributes }) 
    .FirstOrDefault(i => currentDate >= i.Attributes.StartDate && 
         currentDate <= i.Attributes.FinishDate) 
    ?.Path; 
0

はケースであるソリューション提供:Get the current iteration path from TFS

private static XmlNode currentIterationNode; 
    TfsTeamProjectCollection tpc = TFSConncetion(@"http://tfs/url"); 

    ICommonStructureService4 css = tpc.GetService<ICommonStructureService4>();; 
    WorkItemStore workItemStore = new WorkItemStore(tpc); 

     foreach (Project teamProject in workItemStore.Projects) 
     { 
      if (teamProject.Name.Equals("TeamProjectNameGoesHere")) 
      { 
       NodeInfo[] structures = css.ListStructures(teamProject.Uri.ToString()); 
       NodeInfo iterations = structures.FirstOrDefault(n => n.StructureType.Equals("ProjectLifecycle")); 

       if (iterations != null) 
       { 
        XmlElement iterationsTree = css.GetNodesXml(new[] { iterations.Uri }, true); 
        XmlNodeList nodeList = iterationsTree.ChildNodes; 
        currentIterationNode = FindCurrentIteration(nodeList); 
        String currentIterationPath = currentIterationNode.Attributes["Path"].Value; 
       } 
      } 
     }