I have been using the TFS API libraries for some time and have been using the follwoing code when interfacing with TFS 2010 to get the Iteration Paths (code from this page)...
public IList<string> GetIterationPaths(Project project)
{
List<string> iterations = new List<string>();
foreach (Node node in project.IterationRootNodes)
AddChildren(string.Empty, node, iterations);
return iterations;
}
private void AddChildren(string prefix, Node node, List<string> items)
{
items.Add(node.Path);
foreach (Node item in node.ChildNodes)
AddChildren(prefix + node.Name + "/", item, items);
}
When I was looking at getting all the iterations within TFS 2013 things changed. In TFS 2013 the concept of iterations changed slightly and the API assemblies for TFS 2013 do not have IterationRootNodes
I have used the following code to get Team Iterations but that is team based and not the full set of Iterations against the project... (currently getting the first team but can be coded to get others)
var cred = new TfsClientCredentials(new WindowsCredential(), true);
TfsTeamProjectCollection coll = new TfsTeamProjectCollection("{URI to SERVER}", cred);
coll.EnsureAuthenticated();
var teamConfig = coll.GetService<TeamSettingsConfigurationService>();
var css = coll.GetService<ICommonStructureService4>();
var project = css.GetProjectFromName(projectInfo.ProjectName);
IEnumerable<TeamConfiguration> configs = teamConfig.GetTeamConfigurationsForUser(new[] { project.Uri.ToString() });
TeamConfiguration team = configs.FirstOrDefault(x => x.ProjectUri == project.Uri.ToString());
var iterations = BuildIterationTree(team, css);
where BuildIterationTree
looks like...
private IList<IterationInfo> BuildIterationTree(TeamConfiguration team, ICommonStructureService4 css)
{
string[] paths = team.TeamSettings.IterationPaths;
var result = new List<IterationInfo>();
foreach (string nodePath in paths.OrderBy(x => x))
{
var projectNameIndex = nodePath.IndexOf("\\", 2);
var fullPath = nodePath.Insert(projectNameIndex, "\\Iteration");
var nodeInfo = css.GetNodeFromPath(fullPath);
var name = nodeInfo.Name;
var startDate = nodeInfo.StartDate;
var endDate = nodeInfo.FinishDate;
result.Add(new IterationInfo
{
IterationPath = fullPath.Replace("\\Iteration", ""),
StartDate = startDate,
FinishDate = endDate,
});
}
return result;
}
My question is... How do I get the full iteration tree rather than Team specific Iterations for TFS 2013?
Team specific iterations can be configured to show or not via the Web Portal via a checkbox against the iteration.