The IRegistration Service Type
All code in this post is running against TFS Beta3 Refresh. See these posts for background information:
Now that we have talked about the GetService() method, let's look at some of the different service types. The Iregistration service type provides a registration object which allows you to interact with the Registration Service of the Team Foundation Core Services. To retrieve a registration object, you use this code:
IRegistration r = (IRegistration)tfs.GetService(typeof(IRegistration));
The registration object has one method, GetRegistrationEntries(). If you pass in a registered tooltype as a parameter, it will return the Registration Entry for that tooltype. If you pass in a empty string, "", it will return a Registration Entry for every tool type.
Once you have these Registration Entries, you can drill down into the details of each registered tool. You can view the Artifacts related to the tool, including the linking information for each artifact. You can see details on which databases the tool uses. You can see any events the tool can raise, and can also see any extended attributes for the tool.
This following is the Program.cs file from a console application named IRegExample, which displays all the information mentioned above for the WorkItemTracking Tool:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.TeamFoundation;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;
namespace IRegExample
{
class Program
{
static void Main(string[] args)
{
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("mstfs");
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);
}
}
}
}
}
Here is an example of the output of the above application: