Get current iteration path from TFS

I am trying to get the current iteration path for a TFS project for teams. The way I am trying to do this is using the blog from http://blog.johnsworkshop.net/tfs11-api-reading-the-team-configuration-iterations-and-areas/ . I start by getting the command configurations from the following code:

        TfsTeamProjectCollection tpc = TFSConncetion(@"http://tfs/url");
        var configSvc = tpc.GetService<TeamSettingsConfigurationService>();
        var configs = configSvc.GetTeamConfigurationsForUser(projectUri);

      

The problem is that my configs are always zero, even though I am a member of the team. I'm pretty sure my projects URIs are correct as well. After that, I get the command settings and use it to display the current iteration path.

TeamSettings ts = config.TeamSettings;
Console.WriteLine(ts.CurrentIterationPath);

      

Even if that didn't work, I can still query the iteration dates from the command setup to get one iteration that has a start date before today and an end date after today. The main problem is that I cannot get my TeamSettingsConfigurationService to return anything other than null when I try to get the command configuration with my projects URI.

+3


source to share


2 answers


I got the answer myself myself, not using TeamSettingsConfigurationService. This is how I did it:

    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;
                }
            }
        }

      

Where currentIterationPath is the current iteration path from TFS. The key to this was getting the NodeInfo [] array of NodeInfo structures and iterations from these two lines of code that I got from chamindacNavantis https://social.msdn.microsoft.com/Forums/vstudio/en-US/4b785ae7-66c0-47ee- a6d2-c0ad8a3bd420 / tfs-get-iteration-dates-metadata? forum = tfsgeneral :



    NodeInfo[] structures = css.ListStructures(teamProject.Uri.ToString());
    NodeInfo iterations = structures.FirstOrDefault(n => n.StructureType.Equals("ProjectLifecycle"));

      

After that, I created xml with nodes of each iteration inside the team project. These nodes also have a start and end date for each iteration. So I checked each node for the start date before DateTime.Now and ended the date after DateTime.Now, which is all FindCurrentIteration (nodeList). And that will give you the current node iteration.

0


source


There must be something wrong with your server connection or the project you are uploading, as the other code looks fine.

Maybe try something like this:

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("http://server:8080/tfs/collection"),
                          new System.Net.NetworkCredential(tfsUserName, tfsPassword));
tpc.EnsureAuthenticated();

      

Connect to Team Foundation Server from a Console Application

There is a good sample here that you can download (WPF client) and it will allow you to choose between server connection, Team Project and Team:



TFS API Part 46 (VS11) - Command Settings

You can go through it and check the values ​​that you are passing into your code.

The sample gets the command configuration information just like it does in your code.

TeamSettingsConfigurationService teamConfig = tfs.GetService<TeamSettingsConfigurationService>();
    var configs = teamConfig.GetTeamConfigurationsForUser(new[] { projectInfo.Uri });

      

When you have a collection of items TeamConfiguration

, you needTeamSettings.CurrentIterationPath

+3


source







All Articles