Welcome to Team System Rocks Sign in | Join | Help

Mickey Gousset

My Journey Into Team System
(Add me to your Live Messenger at mickey_gousset@hotmail.com)

<February 2006>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
2627281234
567891011

Post Categories

News

ProTFS Book Cover

Navigation

Awards

Links-O-Interest

Syndication

Simple Team Foundation Server Object Model Application
The Team Foundation Server Object Model (TFSOM) is the public API used for interacting with Team Foundation Server. You can utilize the TFSOM to create your own client applications for interacting with Team Foundation Server. For some detailed documentation on the TFSOM, see the Visual Studio SDK. It includes documentation and sample code, showing you the variety of ways you can extend Team System.

In this post, we are going to create a simple application using the TFSOM. The plan is to then build off this sample application in future posts. For this post, we are going to create a console application, in which we create a Team Foundation Server object, and write out some of it's properties.

To get started, open Visual Studio 2005 and create a new Console application by selecting File->New->Project, and then selecting Console Application in the New Project Window. Name the project TestConsoleApp1 and click OK. If Program.CS is not already open at this point, open it.

Before we begin building the app, we need to add two references to the application:

using Microsoft.TeamFoundation;
using Microsoft.TeamFoundation.Client;

In the Solution Explorer window, right click on References and select Add Reference. This opens the Add Reference window. Click the Browse tab, and browse to the following directory:

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies

Select the Microsoft.TeamFoundation.dll and the Microsoft.TeamFoundation.Client.dll. Now add the above two "using" statements to Program.cs.

To create a new TeamFoundationServer object, you need to use the TeamFoundationServerFactory. When you use the factory, it caches an instance of the object, so that any future calls to the factory will return the same object. This should lead to improved performance for your application. To create a Team Foundation Server object, write the following line of code:

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer()

So, if you Team Foundation Server is named "MSTFS", you would type:

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("MSTFS")

You can also use the URL of the Team Foundation Server:

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://MSTFS:8080")

The Team Foundation Server object has the following methods, attributes, and events:
MethodsAttributesEvents
AddServiceAuthenticatedUserNameCredentialsChanged
AuthenticateClientCacheDirectoryForInstance 
DisposeCredentials 
EnsureAutheticatedCulture 
EqualsHasAuthenticated 
GetHashCodeInstanceId 
GetServiceName 
GetTypeSessionId 
RemoveServiceTimeZone 
ToStringUri 

We will talk about these in detail in later posts. For now, just be aware that they are all there. Now that we have created out Team Foundation Server object, let's write out some of its attributes to the command line. Enter the following lines of code in the Main method of Program.cs:

Console.Writeline("\n" + "AuthenticatedUserName = " + tfs.AuthenticatedUserName);
Console.Writeline("\n" + "ClientCacheDirectoryForInstance = " + tfs.ClientCacheDirectoryForInstance);
Console.Writeline("\n" + "Culture = " + tfs.Culture.ToString());
Console.Writeline("\n" + "HasAuthenticated = " + tfs.HasAuthenticated.ToString());
Console.Writeline("\n" + "InstanceID = " + tfs.InstanceID.ToString());
Console.Writeline("\n" + "Name = " + tfs.Name);
Console.Writeline("\n" + "SessionId = " + tfs.SessionId.ToString());
Console.Writeline("\n" + "TimeZone = " + tfs.TimeZone.StandardName);
Console.Writeline("\n" + "Uri = " + tfs.Uri.ToString());

Save your application and compile it. Open a command prompt, and navigate to the bin/Debug folder of the project, and run TestConsoleApp1.exe. You should see something similar to this picture:

Obviously, it is not going to be exactly the same, because your server name and other attributes will probably be different. But the above image gives you an idea of what to expect.

Congratulations! You have created your first application using the TFSOM.

Here is the full code for Program.cs:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.TeamFoundation;
using Microsoft.TeamFoundation.Client;

namespace TestConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://mstfs:8080");

	Console.WriteLine("\n" + "AuthenticatedUserName = " + tfs.AuthenticatedUserName);
	Console.WriteLine("\n" + "ClientCacheDirectoryForInstance = " + tfs.ClientCacheDirectoryForInstance);
	Console.WriteLine("\n" + "Culture = " + tfs.Culture.ToString());
	Console.WriteLine("\n" + "HasAuthenticated = " + tfs.HasAuthenticated.ToString());
	Console.WriteLine("\n" + "InstanceId = " + tfs.InstanceId.ToString());
	Console.WriteLine("\n" + "Name = " + tfs.Name);
	Console.WriteLine("\n" + "SessionId = " + tfs.SessionId.ToString());
	Console.WriteLine("\n" + "TimeZone = " + tfs.TimeZone.StandardName);
	Console.WriteLine("\n" + "Uri = " + tfs.Uri.ToString());
	
	
		
	}
	}
}

Published Tuesday, February 07, 2006 12:13 AM by mickey_gousset

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Exploring the Team Foundation Object Model @ Wednesday, February 08, 2006 12:21 AM

Mickey Gousset, a Team System MVP, is blogging about his exploration of the Team Foundation object model....

Rob Caron

What do you think?

(required) 
required 
(required) 
Powered by Community Server, by Telligent Systems