RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Programming Team Foundation Server with the TFS SDK : Page 3

Team Foundation Server, Microsoft's offering for software lifecycle management, is both customizable and extensible through the TFS SDK.

Retrieving Work Item Details with WIQL
In TFS, work items themselves are complex objects with methods and properties, but you don't access them directly. Instead, you can use Work Item Query Language (WIQL) to query work item details and retrieve them from the work item repository.

As an example, the following ReadWorkItems method connects to TFS, retrieves project and work item details from the work item repository, and then displays the relevant details.

   public void ReadWorkItems(String tfsServer, int? workItemID)
      TeamFoundationServer tfs = 
      WorkItemStore workItemStore = new WorkItemStore(tfsServer);
      foreach (Project tfsProject in workItemStore.Projects)
         WorkItemCollection workItemCollection = workItemStore.Query(
             " SELECT [System.Id], [System.WorkItemType],"+
             " [System.State], [System.AssignedTo], [System.Title] "+
             " FROM WorkItems " +
             " WHERE [System.TeamProject] = '" + tfsProject.Name + 
             "' ORDER BY [System.WorkItemType], [System.Id]");
         foreach (WorkItem workItem in workItemCollection)
            if (workItemID != null)
               if (workItem.Id == workItemID)
                  Response.Write("<BR>"+ " Title: "+workItem.Title + 
                     "[" + workItem.Type.Name + "]" + " Description:"  
                     + workItem.Description);
               Response.Write("WorkItem ID :" + workItem.Id + 
                  " Title: " + workItem.Title + "[" + 
                  workItem.Type.Name + "]" + " Description: " + 
Figure 15. Reading a Specific Work Item: Calling the ReadWorkItems method and passing the ID of the "Bug" work item produces this output.
The last parameter of the ReadWorkItems method accepts a nullable int—a WorkItemId. If that parameter is null, the method displays the details of all the work items in the repository; otherwise, it displays the details for the specified work item. So, to get a single work item, you'd call:

   <span class="pf">ReadWorkItems(tfsServer, 500);</span> 
Executing the preceding line produces the output shown in Figure 15.

You can also use WIQL to manage work items. The following code snippet illustrates how to display the version history of a particular work item.

   private void DisplayWorkItemHistory(int workItemID)
    WorkItemStore workItemStore = new WorkItemStore(tfsServer);
         WorkItem workItem = workItemStore.GetWorkItem(workItemID);
         Response.Write("Status: " +
         foreach (Revision revision in workItem.Revisions)
           Response.Write("<BR>Changed By: " + revision.Fields[
              "Changed By"].Value.ToString());
           Response.Write("<BR>Changed Date: " + revision.Fields[
              "Changed Date"].Value.ToString());
Figure 16. Work Item History: The figure shows some typical output produced by calling the DisplayWorkItem method and passing a specific work item ID.
Now, you can call the above method to retrieve the work item history details of a particular work item in the work item repository:

Figure 16 shows the output from executing that call.

In this article you've seen the basics of how to use the TFS SDK and WIQL to retrieve project information, and create, display and manage work items in the work item repository. You can implement your own application using the using the TFS SDK and the concepts discussed in this article to track work item history details, pending work items, and so forth to help manage your team.

Joydip Kanjilal has over 10 years of industry experience with C, C++, Java, C#, VB, VC++, ASP.Net, XML, Design Patterns, UML, etc. He currently works as a senior project leader in a reputable multinational company in Hyderabad, India, and has contributed articles on .NET and related technologies to www.aspalliance.com.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date