TFS API Part 9: Get Area/Iteration Programmatically

30/01/2009

one comment

TFS API Part 9: Get Area/Iteration Programmatically

Over the last posts I talked about TFS API Part 7: Use IEventService To Get User Event Subscriptions and TFS API Part 8: Subscribe/Unsubscribe Events Using IEventService.

This summing up how to programmatically get / set Event Subscription using TFS API.

More about IEventService on later posts.

On this post I will show how to get Area and Iteration tree.

This can be useful to map your Area/Iteration tree on third party applications.

 

First add reference for Microsoft.TeamFoundation, Microsoft.TeamFoundation.Client, Microsoft.TeamFoundation.Common.dll,Microsoft.TeamFoundation.WorkItemTracking.Client.dll
located in – C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\

image

Download Demo

Add using for:

using Microsoft.TeamFoundation.Proxy;

using Microsoft.TeamFoundation.Server;

using Microsoft.TeamFoundation.Client;

Use ICommonStructureService to get the Area/Iteration nodes by specific project.

private void PopulateIteration()

{

    ICommonStructureService css = (ICommonStructureService)server.GetService(typeof(ICommonStructureService));

    //Gets Area/Iteration base Project

    ProjectInfo projectInfo = css.GetProjectFromName(combo_project_list.SelectedValue.ToString());

    NodeInfo[] nodes = css.ListStructures(projectInfo.Uri);

 

    //GetNodes can use with:

    //Area = 1

    //Iteration = 0

    XmlElement AreaTree = css.GetNodesXml(new string[] { nodes[1].Uri }, true);

    XmlElement IterationsTree = css.GetNodesXml(new string[] { nodes[0].Uri }, true);

 

    list_area.Items.Clear();

    list_iteration.Items.Clear();

 

    XmlNode AreaNodes = AreaTree.ChildNodes[0];

    XmlNode IterationsNodes = IterationsTree.ChildNodes[0];

 

    MakeList(AreaNodes, StructureType.Area);

    MakeList(IterationsNodes, StructureType.Iteration);

}

 

Define structures – Area or Iteration

 

enum StructureType

{

    Iteration = 0,

    Area = 1

}

 

Building Area/Iteration tree using ChildNode from XmlElement

 

private void MakeList(XmlNode tree, StructureType type)

{

    //Check if Area/Iteration has Childerns

    if (tree.FirstChild != null)

    {

        int myNodeCount = tree.FirstChild.ChildNodes.Count;

        for (int i = 0; i < myNodeCount; i++)

        {

            XmlNode Node = tree.ChildNodes[0].ChildNodes[i];

            if (type == StructureType.Area)

                list_area.Items.Add(Node.Attributes["Name"].Value);

            else

                list_iteration.Items.Add(Node.Attributes["Name"].Value);

        }

    }

}

Download Demo

Add comment
facebook linkedin twitter email

Leave a Reply

one comment

  1. Nagaraj26/06/2012 ב 18:59

    Hi Shai Raiten,

    Your Post has really helped me to develop the Admin tool.

    I have implemented code permissions for Groups at Version control level. But not able to find how to get permissions for Groups at Team project level.

    It would be great if you provide some guidance.

    Thanks & Regards,
    Nagaraj