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