如何获取VSTS迭代的TimeFrame(当前或将来)

时间:2018-12-24 20:11:18

标签: c# azure-devops

我正在使用VSTS REST API来获取某个项目的迭代。我要弄清楚的是“当前迭代”。

 var vstsConnection = new VssConnection(new Uri(VstsUrl), new VssBasicCredential(string.Empty, VstsPAT));
            var witClient = vstsConnection.GetClient<WorkItemTrackingHttpClient>();
//get current iteration in VS
            var iterations = witClient.GetClassificationNodeAsync(project: VstsProject, structureGroup: Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.TreeStructureGroup.Iterations, depth: 5).Result;


 // i could iterate over the iterations but i'll just get the first one for now..      
            var attributes = iterations.Children.FirstOrDefault().Attributes;

这里的属性只给我开始日期和结束日期。我感兴趣的是在“时间范围”内告诉我它是当前还是将来。

通过致电https://dev.azure.com/{organization}/{project}/{teamid}/_apis/work/teamsettings/iterations

我确实得到了3个字段:

{"count":3,"value":[{"id":"f2ac8484-de34-4d5c-8838-cd388a952257","name":"Iteration 1","path":"Web And Mobile Team - Project Documentation\\Iteration 1","attributes":{"startDate":"2018-12-24T00:00:00Z","finishDate":"2018-12-31T00:00:00Z","timeFrame":"current"},"url":"https://url/_apis/work/teamsettings/iterations/f2ac8484-de34-4d5c-8838-cd388a952257"},{"id":"f57903a8-22e5-474a-a450-a7401a53511e","name":"Iteration 2","path":"Web And Mobile Team - Project Documentation\\Iteration 2","attributes":{"startDate":null,"finishDate":null,"**timeFrame**":"future"},"url":"url/_apis/work/teamsettings/iterations/f57903a8-22e5-474a-a450-a7401a53511e"},{"id":"2cfc4be3-0665-46de-81e0-0302138bd276","name":"Iteration 3","path":"Web And Mobile Team - Project Documentation\\Iteration 3","attributes":{"startDate":null,"finishDate":null,"**timeFrame**":"future"},"url":"url/_apis/work/teamsettings/iterations/2cfc4be3-0665-46de-81e0-0302138bd276"}]}

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

在REST Api中,您可以添加属性$timeframe=current,您将获得当前的迭代:

https://dev.azure.com/{organization}/{project}/{teamid}/_apis/work/teamsettings/iterations?$timeframe=current&api-version=4.0

答案 1 :(得分:-1)

尝试以下示例:

string projectName = ""; // your project
string teamName = null; //change it for nondefault team 

var WorkClient = Connection.GetClient<WorkHttpClient>();
TeamContext tcx = new TeamContext(projectName, teamName);

TeamSetting tmsettings = WorkClient.GetTeamSettingsAsync(tcx).Result; // current iteration without dates

Console.WriteLine("Current Iteration: {0} - {1}", tmsettings.DefaultIteration.Name, tmsettings.DefaultIteration.Path);

List<TeamSettingsIteration> iterations = WorkClient.GetTeamIterationsAsync(tcx).Result;  // full information for iterations

foreach (TeamSettingsIteration iteration in iterations)
     Console.WriteLine("{0}: {1} : {2}-{3}", iteration.Attributes.TimeFrame, iteration.Name, iteration.Attributes.StartDate, iteration.Attributes.FinishDate);

TeamSettingsIteration currentiteration = (WorkClient.GetTeamIterationsAsync(tcx, "Current").Result).FirstOrDefault(); // get only current

if (currentiteration != null) Console.WriteLine("Current iteration - {0} : {1}-{2}", currentiteration.Name, currentiteration.Attributes.StartDate, currentiteration.Attributes.FinishDate);