Team Foundation Server Object Model


Extensibility starts with the Team Foundation Server Object Model (TFSOM). This object model allows you to create applications that can communicate with the application tier of Team Foundation Server. Think of the TFSOM as an API for working with Team Foundation Server. Utilizing the TFSOM, you can work with the following pieces of Team Foundation Server:

  • Team Foundation Core Services

  • Version Control Object Model

  • Work Item Tracking Object Model

  • Team Build Object Model

  • Team Foundation Data Warehouse Object Model

The Version Control Object Model and the Work Item Tracking Object Model allow you to interact with the version control system and work items, respectively. You will learn more about these in Chapters 11 and 12.

Figure 9-1 shows a visual representation of the extensibility of Team Foundation Server.

image from book
Figure 9-1

The TeamFoundationServer Object

The TeamFoundationServer object is where you start with the TFSOM. It contains the basic attributes of the Team Foundation Server. In addition, it provides access to the Team Foundation Core Services, as well as any other services that have been registered with Team Foundation Server, such as version control and work item tracking.

To get started, open Visual Studio 2005 and create a new C# console application. Before you can begin using the TeamFoundationServer object, you need to add some references to the Team Foundation Server DLLs to your project. In the Solution Explorer, right-click the References folder and select Add Reference. This opens the Add Reference window. Click the Browse tab, and browse to C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies. This directory contains all the Team Foundation Server DLLs. Select the Microsoft.TeamFoundation.dll and the Microsoft .TeamFoundation.Client.dll files, and click OK.

Open the Program.cs file from the Solution Explorer. At the top of the file, add the following two using statements:

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

You can now begin working with the TeamFoundationServer object.

The first thing you need to do is create an instance of the TeamFoundationServer object. You do that using the TeamFoundationServerFactory object. When you use the factory to create the TeamFoundationServer object, the object is cached, so that any future calls to the object use the same instance. This increases the speed of your application, because it does not have to go through the authentication process with the Team Foundation Server with every call. Here is the sample line of code to create a TeamFoundationServer object using the factory:

 TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("MSTFS"); 

When making the call to GetServer() you can pass in either the name of the Team Foundation Server you want to connect to, or the URL, such as http://mstfs:8080. The factory will try to authenticate to the Team Foundation Server using the credentials of the logged on user. You can specify a different user, if you wish.

Once you have created a TeamFoundationServer object, you can access various attributes of the Team Foundation Server. The following table contains a list of the attributes you may be interested in:

Open table as spreadsheet

Attribute Name

Meaning

AuthenticatedUserName

The user that has authenticated to the Team Foundation Server

ClientCacheDirectoryForInstance

The directory that contains cached information for Team Foundation Server

Culture

The culture information for the Team Foundation Server

HasAuthenticated

Tells whether the TeamFoundationServer object has authenticated with the Team Foundation Server

InstanceId

Instance ID information for Team Foundation Server

Name

Name of the Team Foundation Server

TimeZone

The time zone for the Team Foundation Server

URI

The Uniform Resource Identifier (URI) for the Team Foundation Server

In your console application, to write out these attributes, you can use the Console.Writeline() function. Here is an example of writing out the name and URI of the TeamFoundationServer object:

 Console.Writeline("Name = "+ tfs.Name); Console.Writeline("URI = "+ tfs.URI.ToString()); 

The TeamFoundationServer object also has several methods, including methods used to authenticate and ensure authentication against the Team Foundation Server, methods used to add and remove services to Team Foundation Server, and a method, called GetService(), which is used to access the Team Foundation Core Services, version control system, and work item tracking System.

Here is the code for the Program.cs file of the console application called chp9TFS, to create a TeamFoundationServer object and write out its attributes. This sample takes the name of your Team Foundation Server as a command-line argument:

 using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; namespace chp9TFS { class Program { static void Main(string[] args) { TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0].ToString()); //Write out information about the Team Foundation Server Console.WriteLine("AuthenticatedUserName = " + tfs.AuthenticatedUserName); Console.WriteLine("ClientCacheDirectoryForInstance = " + tfs.ClientCacheDirectoryForInstance); Console.WriteLine("Culture = " + tfs.Culture.ToString()); Console.WriteLine("HasAuthenticated = " + tfs.HasAuthenticated.ToString()); Console.WriteLine("InstanceId = " + tfs.InstanceId.ToString()); Console.WriteLine("Name = " + tfs.Name); Console.WriteLine("TimeZone = " + tfs.TimeZone.StandardName); Console.WriteLine("Uri = " + tfs.Uri.ToString()); } } } 

If you run this code, you should see output similar to Figure 9-2.

image from book
Figure 9-2

Accessing the Service Interfaces

Using the TeamFoundationServer object, you can access the Team Foundation Core Services, as well as the version control and work item tracking systems. To gain access to these services, you use the GetService() method of the TeamFoundationServer object:

 public object GetService (Type serviceType) 

For example, to return a VersionControlServer object, you would use the following code:

 VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); 

Notice how the GetService() method returns an object. Therefore, you have to cast the object into the appropriate type. Once you have cast the object into the appropriate type, you can begin accessing that service. In the above example, you could now begin interacting with the Team Foundation Server Version Control system.

The following table lists the different service types that can be used with the GetService() method:

Open table as spreadsheet

Service Type

Used To

IAuthorizationService

Interact with the security service

ICommonStructureService

Interact with the classification service

IEventService

Interact with the eventing service

IGroupSecurityService

Interact with the security service

ILinking

Interact with the linking service

IProcessTemplates

Work with Team Foundation Server process templates

IRegistration

Interact with the registration service

IServerStatusService

Access the Team Foundation Server status

VersionControlServer

Interact with the Team Foundation Server version control system

WorkItemStore

Interact with the Team Foundation Server work item tracking system

The following sections cover each of these services in more detail, including sample code.

IAuthorizationService

IAuthorizationService returns an authorization object for interacting with the security service of the Team Foundation Core Services. To access this service type, you need to add the following using statement to your code:

 using Microsoft.TeamFoundation.Server; 

To create an authorization object, you use the following code:

 IAuthorizationService a = (IAuthorizationService)tfs.GetService(typeof(IAuthorizationService)); 

The authorization object allows you to view and make changes to access permissions on objects in Team Foundation Server. While the IGroupSecurityService is responsible for creating the application groups, the IAuthorizationService is responsible for the access permissions on those groups.

The following code shows the Program.cs file for a console application named chp9IAuthorization, which displays, for all the top level objects in the Team Foundation Server, the access control list options for those objects:

 using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Server; namespace chp9IAuthorization { class Program { static void Main(string[] args) { TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0].ToString()); IAuthorizationService a = (IAuthorizationService)tfs.GetService(typeof(IAuthorizationService)); foreach (string s in a.ListObjectClasses()) { Console.WriteLine("Object String = " + s.ToString()); foreach(string s2 in a.ListObjectClassActions(s)) { Console.WriteLine("Object Actions = " + s2.ToString()); } Console.WriteLine("\n"); } Console.ReadLine(); } } } 

Figure 9-3 shows the output from running this sample application.

image from book
Figure 9-3

ICommonStructureService

The ICommonStructureService service type returns a classification object for interacting with the classification service of the Team Foundation Core Services. To access this service type, you need to add the following using statement to your code:

 using Microsoft.TeamFoundation.Server; 

To create a registration object, you use the following code:

 ICommonStructureService r = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService)); 

The classification object allows you to do a variety of things, including modify the Areas and Iterations section of a project, create projects, delete projects, and review project properties. To access the project information for a particular project, you can use the GetProjectFromName() method of the classification object:

 ProjectInfo ICommonStructureService.GetProjectFromName(string projectName) 

This returns a project info object. This object contains the project name, status, and URI, as well as any extended project properties.

You can also use the ListStructures() method of the classification object to list the different structures located in the areas and iteration section of the Team Project:

 NodeInfo[] ICommonStructureService.ListStructures(string projectUri) 

This method returns detailed information on the top level structures, including their name, the URI of their parent node, and their own URI, to name a few.

The following code shows the Program.cs file for a console application named chp9ICSS. This application displays the project name, status, and URI for each project in the Team Foundation Server. It also lists the top-level structures in the Areas and Iterations section for each project.

 using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Server; using System.Xml; using System.Collections; namespace chp9ICSS { class Program { static void Main(string[] args) { TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0].ToString()); ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService)); string sName; string sState; int intTemplateId; ProjectProperty[] pp; foreach (ProjectInfo pi in css.ListAllProjects()) { Console.WriteLine("\n"); Console.WriteLine("ProjectInfo Name = " + pi.Name); Console.WriteLine("ProjectInfo Status = " + pi.Status); Console.WriteLine("ProjectInfo Uri= " + pi.Uri); css.GetProjectProperties(pi.Uri, out sName, out sState, out intTemplateId, out pp); Console.WriteLine("GetProjectProperties Name = " + sName); Console.WriteLine("GetProjectProperties State = " + sState); Console.WriteLine("GetProjectProperties TemplateId = " + intTemplateId.ToString()); foreach (ProjectProperty p in pp) { Console.WriteLine("ProjectProperty Name = " + p.Name); Console.WriteLine("ProjectProperty Value = " + p.Value); } foreach (NodeInfo ni in css.ListStructures(pi.Uri)) { Console.WriteLine("NodeInfo Name = " + ni.Name); Console.WriteLine("NodeInfo ParentURI = " + ni.ParentUri); Console.WriteLine("NodeInfo Path = " + ni.Path); Console.WriteLine("NodeInfo ProjectURI = " + ni.ProjectUri); Console.WriteLine("NodeInfo StructureType = " + ni.StructureType); Console.WriteLine("NodeInfo URI = " + ni.Uri); foreach (Property p in ni.Properties) { Console.WriteLine("NodeInfoProperty Name = " + p.Name); Console.WriteLine("NodeInfoProperty Value = " + p.Value); } } } } } } 

Figure 9-4 shows the output from running this sample application.

image from book
Figure 9-4

The XML values you see in the output are the mappings between Team Foundation Server Work Item Tracking fields and Microsoft Project fields. This mapping is what allows you to synchronize information between the two.

IEventService

The IEventService service type returns an event object for interacting with the eventing service of the Team Foundation Core Service. To access this service type, you need to add the following using statement to your code:

 using Microsoft.TeamFoundation.Server; 

To create a reference to the event service, you use the following code:

 IEventService es = (IEventService)tfs.GetService(typeof(IEventService)); 

The event object allows you to subscribe to events using SubscribeEvent(), unsubscribe from events using UnsubscribeEvent(), view the event subscriptions for a given user using EventSubscriptions(), and even trigger an event using FireAsyncEvent().

Several different events are configured by default for Team Foundation Server. You can view these by running the chp9IRegistration program presented later, or by viewing the tbl_event_type in the TfsIntegration database on the data tier. Some of the events are listed as follows:

  • AclChangedEvent

  • BuildCompletionEvent

  • BuildStatusChangedEvent

  • BranchMovedEvent

  • CheckinEvent

  • CommonStructureChangedEvent

  • DataChangedEvent

  • IdentityChangedEvent

  • IdentityCreatedEvent

  • IdentityDeletedEvent

  • MembershipChangedEvent

  • NodeCreatedEvent

  • NodePropertiesChangedEvent

  • NodeRenamedEvent

  • NodeDeletedEvent

  • ProjectCreatedEvent

  • ProjectDeletedEvent

  • WorkItemChangedEvent

  • CheckinEvent

The following code shows the Program.cs file for a console application named chp9IEventService, which displays the registered event information for a user. This console application takes two arguments: the name of the Team Foundation Server and the domainname\username for the user in question.

 using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Server; namespace chp9IEventService { class Program { static void Main(string[] args) { TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0].ToString()); IEventService es = (IEventService)tfs.GetService(typeof(IEventService)); DeliveryPreference dp = new DeliveryPreference(); foreach (Subscription s in es.EventSubscriptions(args[1].ToString())) { Console.WriteLine("\n"); Console.WriteLine("Subscriber = " + s.Subscriber); Console.WriteLine("Condition String = " + s.ConditionString); Console.WriteLine("Device = " + s.Device); Console.WriteLine("EventType = " + s.EventType); Console.WriteLine("ID = " + s.ID.ToString()); Console.WriteLine("Tag = " + s.Tag); dp = s.DeliveryPreference; Console.WriteLine("Delivery Preference - Address = " + dp.Address); Console.WriteLine("Delivery Preference - Schedule = " + dp.Schedule); Console.WriteLine("Delivery Preference - Type = " + dp.Type); } } } } 

This application retrieves the subscription information for a user. For each subscription, it prints the subscription information, including the delivery preferences.

Figure 9-5 shows the output from running this sample application for the SSBOOK Team Foundation Server and the TFSSERVICE user.

image from book
Figure 9-5

IGroupSecurityService

The IGroupSecurityService type returns a group-security object for interacting with the security service of the Team Foundation Core Services. To access this service type, you need to add the following using statement to your code:

 using Microsoft.TeamFoundation.Server; 

To create a group-security object, you use the following code:

 IGroupSecurityService gss = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService)); 

The group-security object allows you to create and delete application groups, add and remove members from application groups, and list all the groups for a particular project.

The following code shows the Program.cs file for a console application named chp9IGSS, which displays, for every project in the Team Foundation Server, the application groups and related information:

 using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Server; namespace chp9IGSS { class Program { static void Main(string[] args) { TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0].ToString()); IGroupSecurityService gss = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService)); ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService)); foreach (ProjectInfo pi in css.ListAllProjects()) { Console.WriteLine("\n"); Console.WriteLine("Project Name = " + pi.Name); foreach (Identity i in gss.ListApplicationGroups(pi.Uri)) { Console.WriteLine("\n"); Console.WriteLine("Account Name = " + i.AccountName); Console.WriteLine("Deleted = " + i.Deleted.ToString()); Console.WriteLine("Description = " + i.Description); Console.WriteLine("Display Name = " + i.DisplayName); Console.WriteLine("Distinquished Name = " + i.DistinguishedName); Console.WriteLine("Domain = " + i.Domain); Console.WriteLine("Mail Address = " + i.MailAddress); Console.WriteLine("Security Group = " + i.SecurityGroup.ToString()); Console.WriteLine("SID = " + i.Sid); } } } } } 

Notice how this code uses the ICommonStructureService type to retrieve the project URI for each project, and then using this URI, retrieves the application groups using the group-security service object.

Figure 9-6 shows the output from running this sample application.

image from book
Figure 9-6

ILinking

The ILinking service type returns a linking object for interacting with the linking service of the Team Foundation Core Services. To access this service type, you need to add the following using statement to your code:

 using Microsoft.TeamFoundation.Server; 

You also need to add a reference to the Microsoft.TeamFoundation.Common.dll, located at C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies.

To create a linking object, you use the following code:

 ILinking link = (ILinking)tfs.GetService(typeof(ILinking)); 

The linking object allows you to retrieve artifact information, based on artifact URIs, using the GetArtifacts() method. Using the GetArtifactUrl() method, you can retrieve the URL of an artifact, based on its URI. Finally, using the GetReferencingArtifacts() method, you can retrieve a list of referencing artifacts, based on an artifact URI.

Remember that a well-formed URI consists of the following syntax:

 vstfs:///<tooltype>/<artifacttype>/<tool-specific-id> 

If you run the chp9IRegistration application listed earlier, you can see, for the WorkItemTracking linking entry type, there is a tool type called WorkItemTracking, with an artifact type called Workitem. Using the Team Explorer, you can run a report to view all work items for a particular project. Each work item is assigned a specific number, such as 32. So a well-formed URI for a Workitem in the WorkItemTracking tool would be:

 vstfs:///WorkItemTracking/WorkItem/32 

Using the GetArtifactUrl() method of the linking object, you can obtain a URL, which allows you to view this work item in a Web browser:

 string url = link.GetArtifactUrl("vstfs:///WorkItemTracking/WorkItem/32"); 

This returns a URL of :8080//WorkItemTracking/WorkItem.aspx?artifactMoniker=32">http://<your-TFS-Server>:8080//WorkItemTracking/WorkItem.aspx?artifactMoniker=32, which, when you put into your Web browser, returns something similar to Figure 9-7.

image from book
Figure 9-7

The following code shows the Program.cs file for a console application named chp9ILinking, which displays the URL for a given URI:

 using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Server; namespace chp9ILinking { class Program { static void Main(string[] args) { TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0].ToString()); ILinking link = (ILinking)tfs.GetService(typeof(ILinking)); string url = link.GetArtifactUrl("vstfs:///WorkItemTracking/WorkItem/32"); Console.WriteLine("Artifact URL = " + url); } } } 

IProcessTemplates

The IProcessTemplates service type is used to work with Team Foundation Server process templates. To access this service type, you need to add the following using statement to your code:

 using Microsoft.TeamFoundation.Server; 

To create a process template object, you use the following code:

 IProcessTemplates pt = (IProcessTemplates)tfs.GetService(typeof(IProcessTemplates)); 

Using the process template object, you can add, delete, and modify process templates, using a variety of different methods.

The following code shows the Program.cs file for a console application named chp9IProcessTemplates, which calls the GetTemplateNames() method, to display all the process templates currently on the Team Foundation Server:

 using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Server; using System.Xml; namespace chp9IProcessTemplates { class Program { static void Main(string[] args) { TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0].ToString()); IProcessTemplates pt = (IProcessTemplates)tfs.GetService(typeof(IProcessTemplates)); XmlNode xn = pt.GetTemplateNames(); Console.WriteLine("\n"); Console.WriteLine("Template Names Inner XML = " + xn.InnerXml.ToString()); Console.WriteLine("\n"); XmlNodeList nl = xn.SelectNodes("/Template"); Console.WriteLine("Nodelist count = " + nl.Count.ToString()); for (int i = 0; i < nl.Count; i++) { Console.WriteLine("NodeList Item#\t" + i + " "+ nl.Item(i).InnerText); } } } } 

Figure 9-8 shows the output from running this sample application.

image from book
Figure 9-8

IRegistration

The IRegistration service type returns a registration object for interacting with the registration service of the Team Foundation Core Services. This allows you to view registration information for tools already registered with Team Foundation Server, as well as register your own tools. To access this service type, you need to add the following using statement to your code:

 using Microsoft.TeamFoundation.Server; 

To create a registration object, you use the following code:

 IRegistration r = (IRegistration)tfs.GetService(typeof(IRegistration)); 

The registration object contains multiple registration entries. To access those entries, you use the GetRegistrationEntries() method of the registration object:

 RegistrationEntry[] IRegistration.GetRegistrationEntries(string toolId) 

The toolId is the tool you want to retrieve the registration information for, for example VersionControl. If you use an empty string, "", in the method call, it will return registration information for all the tools registered with Team Foundation Server.

This method returns a collection of RegistrationEntry objects. Each of these objects contains a particular tool that has been registered with Team Foundation Server. From these objects, you can list the tool information, including its associated artifacts, databases, events, extended attributes, and service interfaces.

The following code shows the Program.cs file for a console application named chp9IRegistration, which displays some the registration information for the WorkItemTracking system:

 using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Server; namespace chp9IRegistration { class Program { static void Main(string[] args) { TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0].ToString()); IRegistration r = (IRegistration)tfs.GetService(typeof(IRegistration)); foreach (RegistrationEntry re in r.GetRegistrationEntries("WorkItemTracking")) { Console.WriteLine("\n"); Console.WriteLine("Registration Entry Type = " + re.Type); Console.WriteLine("Registration Entry Change Type = " + re.ChangeType.ToString()); foreach (ArtifactType at in re.ArtifactTypes) { Console.WriteLine("ArtifactTypeName = " + at.Name); foreach (OutboundLinkType olt in at.OutboundLinkTypes) { Console.WriteLine("OutboundLinkTypeName = " + olt.Name); Console.WriteLine("OutboundLinkTypeTargetArtifactTypeName = " + olt.TargetArtifactTypeName); Console.WriteLine("OutboundLinkTypeTargetArtifactTypeTool = " + olt.TargetArtifactTypeTool); } } foreach (Database db in re.Databases) { Console.WriteLine("DbConnectionString = " + db.ConnectionString); Console.WriteLine("DbDatabaseName = " + db.DatabaseName); Console.WriteLine("DbExludeBackup = " + db.ExcludeFromBackup); Console.WriteLine("DbName = " + db.Name); Console.WriteLine("DbSQLServerName = " + db.SQLServerName); } foreach (EventType et in re.EventTypes) { Console.WriteLine("Event Type Name = " + et.Name); //Console.WriteLine("\n" + "Event Type Schema = " + et.Schema + "\n"); } foreach (RegistrationExtendedAttribute rea in re.RegistrationExtendedAttributes) { Console.WriteLine("Reg Extended Att. Name = " + rea.Name); Console.WriteLine("Reg Extended Att. Value = " + rea.Value); } foreach (ServiceInterface si in re.ServiceInterfaces) { Console.WriteLine("Service Interface Name = " + si.Name); Console.WriteLine("Service Interface URL = " + si.Url); } } } } } 

This code retrieves the list of registration objects. For each object, it writes out the artifact, database, event, and extended attribute information.

Figure 9-9 shows the output from running this sample application.

image from book
Figure 9-9

To view the registration information for all registered items, change this line of code:

 foreach (RegistrationEntry re in r.GetRegistrationEntries("WorkItemTracking")) 

to

 foreach (RegistrationEntry re in r.GetRegistrationEntries("")) 

IServerStatusService

The IServerStatusService service type is used to access the Team Foundation Server status. To access this service type, you need to add the following using statement to your code:

 using Microsoft.TeamFoundation.Server; 

To create a server status object, you use the following code:

 IServerStatusType a = (IServerStatusType)tfs.GetService(typeof(IServerStatusType)); 

The primary method of the server status object is the GetServerStatus() method. This method returns a collection of DataChanged objects, containing two objects. These two objects shows the last time an access control list was changed on the server, and the last time an identity was changed on the server. You might be interested in the access control list change if you were conducting a security audit, and wanted to know the last time someone had modified security on the Team Foundation Server.,

The following code shows the Program.cs file for a console application named chp9IServerStatus, which calls the GetServerStatus() method:

 using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Server; namespace chp9IServerStatus { class Program { static void Main(string[] args) { TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0].ToString()); IServerStatusService s = (IServerStatusService)tfs.GetService(typeof(IServerStatusService)); foreach (DataChanged dc in s.GetServerStatus()) { Console.WriteLine("DC DataType = " + dc.DataType); Console.WriteLine("DC Last Modified = " + dc.LastModified.ToShortDateString()); Console.WriteLine("DC ToString() = " + dc.ToString()); Console.WriteLine("\n"); } } } } 

This application retrieves the server status information into DataChanged objects, and then outputs the contents of those objects to the screen.

Figure 9-10 shows the output from running this sample application.

image from book
Figure 9-10

VersionControlServer

The VersionControlServer service type is used to interact with the Team Foundation Server version control system. To access this service type, you need to add a reference to the Microsoft.TeamFoundation.VersionControl.Client.dll. You also need the following using statements to your code:

 using Microsoft.TeamFoundation.Server; using Microsoft.TeamFoundation.VersionControl; using Microsoft.TeamFoundation.VersionControl.Client; 

To create a version-control server object, you use the following code:

 VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); 

Using the version-control server object, you have full control over the version control system. You can query information, and add, edit, or delete information from the version control system. You learn more about the version control system and using the Team Foundation Object Model with it in Chapter 12.

The following code shows the Program.cs file for a console application named chp9VersionControlServer, which displays some of the information related to the latest changeset in the system.

 using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Server; using Microsoft.TeamFoundation.VersionControl; using Microsoft.TeamFoundation.VersionControl.Client; namespace chp9VersionControlServer { class Program { static void Main(string[] args) { TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0].ToString()); VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); Changeset cs = vcs.GetChangeset(vcs.GetLatestChangesetId()); Console.WriteLine("\n"); Console.WriteLine("ChangeSet ID = " + cs.ChangesetId.ToString()); Console.WriteLine("Comment = " + cs.Comment); Console.WriteLine("Committer = " + cs.Committer); Console.WriteLine("Creation Date = " + cs.CreationDate.ToShortDateString()); Console.WriteLine("Owner = " + cs.Owner); } } } 

This application uses the GetLatestChangeset() method to retrieve the latest changeset from the version control system, and then outputs the contents of that changeset to the screen.

Figure 9-11 shows the output from running this sample application.

image from book
Figure 9-11

WorkItemStore

The WorkItemStore service type is used to interact with the Team Foundation Server work item tracking system. To access this service type, you need to add a reference to the Microsoft.TeamFoundation.WorkItemTracking.Client.dll. You also need the following using statements to your code:

 using Microsoft.TeamFoundation.Server; using Microsoft.TeamFoundation.WorkItemTracking; using Microsoft.TeamFoundation.WorkItemTracking.Client; 

To create a work-item store object, you use the following code:

 WorkItemStore wis = (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); 

Using the work-item store object, you can query and retrieve work items from the work item tracking system. You learn more about work items and using the Team Foundation Object Model with the work item tracking system in Chapter 11.

The following code shows the Program.cs file for a console application named chp9WorkItemStore, which uses the Diagnostics attribute of the work item store to display the round-trip time between your application and the work item tracking system in Team Foundation Serve. This time is shown in milliseconds.

 using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Server; using Microsoft.TeamFoundation.WorkItemTracking; using Microsoft.TeamFoundation.WorkItemTracking.Client; namespace chp9WorkItemStore { class Program { static void Main(string[] args) { TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0].ToString()); WorkItemStore wis = (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); WorkItemStoreDiagnostics d = wis.Diagnostics; Console.WriteLine("\n"); Console.WriteLine("Round Trip Time = " + d.RoundTripTime); } } } 

Figure 9-12 shows the output from running this sample application.

image from book
Figure 9-12



Professional Team Foundation Server
Professional Team Foundation Server
ISBN: 0471919306
EAN: 2147483647
Year: 2004
Pages: 168

Similar book on Amazon
Professional Team Foundation Server 2010 (Wrox Programmer to Programmer)
Professional Team Foundation Server 2010 (Wrox Programmer to Programmer)
Professional Application Lifecycle Management with Visual Studio 2010 (Wrox Programmer to Programmer)
Professional Application Lifecycle Management with Visual Studio 2010 (Wrox Programmer to Programmer)
Professional Scrum with Team Foundation Server 2010 (Wrox Programmer to Programmer)
Professional Scrum with Team Foundation Server 2010 (Wrox Programmer to Programmer)
Team Foundation Server 2008 in Action
Team Foundation Server 2008 in Action

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net