0

Creating a simple iteration path in TFS 2013 is described here. Traversing a whole tree of unknown depth is described here. I need to create an iteration path of which I know the exact path, and which contains sub-directories, as in \{ProjectName}\Iteration\{Year}\{Iteration}


EDIT: In order to do that safely, I need to first check the existence of the iteration path, which requires me to check the existence of {Year} and {Iteration}. Otherwise an exception is thrown and I'd like to avoid exception-based logic.


I can find only one way of doing that, and it is level by level, using the method CommonStructureService.GetNodesXml(), but then I have to parse XML and I lose the advantage of using the provided API types such as NodeInfo. Is there a better way to check for existence of a deeper child with a known path while retaining the API domain model?

Community
  • 1
  • 1
tsemer
  • 2,959
  • 3
  • 29
  • 26

2 Answers2

1

You can create the iterations one by one: Create the node {Year} first, and then create the {Iteration} under {Year}. See following code for details:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;

namespace AAAPI
{
    class Program
    {
        static void Main(string[] args)
        {
            string project = "https://xxx.xxx.xxx.xxx/tfs";
            string projectName = "XXX";
            string node1 = "Year";
            string node2 = "Iter1";
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(project));
            tpc.Authenticate();
            Console.WriteLine("Creating node" + node1);
            var css = tpc.GetService<ICommonStructureService>();
            string rootNodePath = string.Format("\\{0}\\Iteration", projectName);
            var pt = css.GetNodeFromPath(rootNodePath);
            css.CreateNode(node1, pt.Uri);
            Console.WriteLine("Creating" + node1 + "Successfully");
            Console.WriteLine("Creating node" + node2);
            string parentNodePath = string.Format("\\{0}\\Iteration\\{1}", projectName, node1);
            var pt1 = css.GetNodeFromPath(parentNodePath);
            css.CreateNode(node2, pt1.Uri);
            Console.WriteLine("Creating" + node2 + "Successfully");
            Console.ReadLine();
        }
    }
}
Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
  • Yes, I see now that I didn't state my question clearly enough. This code is good for creation. Please see my explained use case and revised question. – tsemer Jan 22 '16 at 13:31
  • @tsemer You can refer to this article for details: http://blog.wibeck.org/2013/02/get-all-iteration-paths-in-tfs-programtically/ – Eddie Chen - MSFT Jan 25 '16 at 05:41
  • *Come on SO let me add @Eddie's name* :-/ thank you, unfortunately the post you provided uses the `WorkItemStore`, where the structure is somewhat different and more importantly iterations there are read only. I need to use `ICommonStructureService` in order to add iterations, so I need to check existence in that particular service. – tsemer Jan 25 '16 at 10:25
0

As no valid answers have come I'm going to assume the following answer:

No, there's no way to read any deeper part than the top level while retaining the API typed domain model. XML is currently the only option.

tsemer
  • 2,959
  • 3
  • 29
  • 26