This post will continue my exploration of programming Outlook 2007, by showing how to get information from Team System Foundation Server (TFS). The idea is that in the option page (I bloged about it
here) you set up projects that you want to keep track of your time for. At least some of these projects will also exists in TFS (if you use TFS), and you have different tasks in TFS that you want to track the time for. To enable this scenario, you need to choose TFS project for the project in Outlook and when you open an appointment item in Outlook you should be able to pick one of the tasks from the TFS project.
Part of the Outlook option dialog, where you can choose TFS project. The dialog is in Swedish.
The rest of this post will show some code that I use to make calls to TFS. It is recommended that you use the client libraries and not calling the web services direct.
The first step is to set two references to Microsoft.TeamFoundation.Client and Microsoft.TeamFoundation.WorkItemTracking.Client assemblies. This assemblies are part of the
Visual Studio 2005 SDK.
With the references in place, I will start with connecting to the server. There is a TeamFoundationServerFactory class that will help you with this.
TeamFoundationServer server = TeamFoundationServerFactory.GetServer(serverName);
The server exposes different services, and one of them is the WorkItemStore from which you can get the projects and the tasks (WorkItems).
return server.GetService(typeof(WorkItemStore)) asWorkItemStore;
The projects are exposed through the Projects property, and in my case I simply bind this collection to my combo box.
The last step is to get the current user's work items from the Work Item store.
WorkItemStore store = GetWorkItemStore();
if (store != null)
{
string wiql = "SELECT Id, [Work Item Type], Title FROM [WorkItems] WHERE [System.TeamProject] = '{0}' AND State <> 'Closed' AND [Assigned To] = '{1}'";
Project proj = store.Projects.GetById(projectId);
return store.Query(string.Format(wiql, proj.Name, userDisplayName));
}
The rows above shows how to use Work Item Query Language (SQL) to query the work item store for the current user's work items. The variable userDisplayName is set to server.AuthenticatedUserDisplayName.
In an upcoming post I will show you how to create a form region for the appointment item in Outlook and fill a combo box in that region with the work items.