Click here to Skip to main content
Click here to Skip to main content

Team Foundation Server (TFS) API Wrapper

, 23 Jun 2010
Rate this:
Please Sign up or sign in to vote.
A simple wrapper that encapsulates exposed functions of the Microsoft Team Foundation Server (TFS) client API
team-foundation-server-wizard-04.png

Introduction

In this article, I want to introduce a small .NET wrapper class library to you that encapsulates several exposed classed of the client API of Microsoft Team Foundation Server (TFS).

Why Develop a Wrapper Around a Wrapper?

Maybe you ask yourself why I am developing a wrapper library around the already wrapped SOAP interface of TFS.

The original requirement for connecting to and communicating with a TFS was when I developed the TFS integration of our Test Management Environment Zeta Test. The application enables testers and test managers to create and manage test cases and manage black-box tests, white-box tests and regression tests. A customer brought up the need for connecting their existing TFS data base to Zeta Test.

While planning the developed enhancement, I wanted to be 100% sure that other clients that have no TFS Explorer (the client runtime for connecting to TFS) installed are still able to work with our application. So no dependencies between the TFS client libraries and our main applications should exist.

Therefore I created the wrapper, which is the only assembly that references the TFC client API libraries.

Features of the Wrapper

The API wrapper is a small wrapper around several functions of the TFS Client API functions that deal with the work item tracking architecture.

The following main classes are provided:

  • FieldController
  • FieldDefinitionController
  • ProjectController
  • ServerConfiguration
  • ServerController
  • StoredQueryController
  • TfsAllowedValuesCollection
  • TfsAttachment
  • TfsAttachmentCollection
  • TfsField
  • TfsFieldCollection
  • TfsFieldDefinition
  • TfsFieldDefinitionCollection
  • TfsFieldFilter
  • TfsFieldFilterList
  • TfsLink
  • TfsLinkCollection
  • TfsProject
  • TfsProjectCollection
  • TfsRegisteredLinkType
  • TfsRegisteredLinkTypeCollection
  • TfsRevision
  • TfsRevisionCollection
  • TfsServer
  • TfsStoredQuery
  • TfsStoredQueryCollection
  • TfsTeamFoundationServer
  • TfsWorkItem
  • TfsWorkItemCollection
  • TfsWorkItemStore
  • TfsWorkItemType
  • TfsWorkItemTypeCollection
  • WorkItemController
  • WorkItemTypeController

These classes can be used to communicate with the Microsoft TFS. The screenshot at the top of the articles provides an idea of what I used it for. If you are interested, you can see the whole screenshot gallery over at Picasa.

Example Usage of the Classes

An example project is included in the download at the top of the article. Following are some typical usage scenarios.

var config = new ServerConfiguration
{
    ServerUrl = @"http://ukeim-js6hkkfzx:8080/"
};

The code above creates a configuration class. Usually this is your first step when connecting. Specify all the settings that require you to connect. You can even specify impersonation to connect in a different user context (usually with higher privileges).

Next, you would create a class to connect to the server and then a class to connect to a certain project:

var serverController = new ServerController(config);

var projectController = 
    new ProjectController(
        config, 
        serverController.GetAllProjects()[0]);

The example above creates a controller to connect to the server. By using this controller class you could enumerate all projects (via the GetAllProjects() method).

With the project controller class, you could e.g. query for one or multiple work items that match a certain criteria:

var wis1 = projectController.GetWorkItemsByTitle(@"Set up");

foreach (var workItem in wis1)
{
    Console.WriteLine(@" " + workItem.Title)
} 

You could also query for a certain field definition like the following:

var fd1 = projectController.Project.Store.GetFieldDefinition(-3);
var fd2 = projectController.Project.Store.GetFieldDefinition(10004);
var fd3 = projectController.Project.Store.GetFieldDefinition("ID");
var fd4 = projectController.Project.Store.GetFieldDefinition("Issue");

Please see the source files of the test project and the library itself for further examples.

What I Learned

Having no experience with TFS before starting this project, I really loved how easy it was to work with the TFS Client API. The structure is really well documented and easy to understand.

In fact, the hardest part by far was to set up TFS itself. I ended with a working VMware machine that I hopefully will never ever have to configure again.

Summary

In this article, I introduced a library that wraps several Microsoft Team Foundation Server functions. I've also shown you a brief overview of how to use the library.

If you have any questions, suggestions or want to report issues, I would love to hear from you! Please use the discussion section at the bottom of this article.

History

  • 2010-06-23 - First release to CodeProject.com

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Uwe Keim
Chief Technology Officer Zeta Producer Desktop CMS
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.
 
In his free time, he does climbing, running and mountain biking. Recently he became a father of a cute boy.
 
Some cool, free software from us:
 
Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
Homepage erstellen - Intuitive, very easy to use. Download now!  
Send large Files online for free by Email
Offline-Homepage-Baukasten

Comments and Discussions

 
GeneralTeamFoundation version Pinmembersuper_freax16-Dec-10 22:18 
GeneralRe: TeamFoundation version Pinmembermakarand keer10-Nov-11 11:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 24 Jun 2010
Article Copyright 2010 by Uwe Keim
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid