2017-12-19 9 views
0

Ich brauche den aktuellen Iterationspfad vom TFS-Projekt. Ich bin in der Lage, REST-API-Abfrage <server>/<project>/_apis/work/teamsettings/iterations?$timeframe=current&api-version=v2.0-preview zu verwenden, aber ich möchte keine Abfrage ausführen und JSON-Antwort analysieren. Ich möchte die entsprechende API in .NET client libraries for VSTS (and TFS) verwenden.Aktuelle Iteration von TFS erhalten

Ich habe eine Instanz der VssConnection. Wie kann ich den Pfad der aktuellen Iteration von diesem Objekt erhalten? Hier

Antwort

0

Ich fand eine Lösung mit 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

ist ein Fall, eine Lösung bietet: 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; 
       } 
      } 
     }