Monday, August 28, 2006
One question I get a lot when teaching the VSTS course is "How can I move tasks or bugs from our existing system into TFS?"

The answer is quite simple: write a program that utilizes the Team Systems Object Model.

The Object Model is documented partially in the VSIP SDK -- if you intend to work with it, I highly recommend you go and grab that SDK from Microsoft, but here is a simple example of creating a bug in the first Team Project available on the server named TFSServer (you can imagine the rest which uses ADO.NET to pull your existing tracking tickets from whatever system you have):

   1:  using System;
   2:  using System.Collections;
   3:  using System.Collections.Generic;
   4:  using System.Text;
   5:  using Microsoft.TeamFoundation.Client;
   6:  using Microsoft.TeamFoundation.WorkItemTracking.Client;
   7:   
   8:  namespace EnterWorkItems
   9:  {
  10:      class Program
  11:      {
  12:          static void Main(string[] args)
  13:          {
  14:              TeamFoundationServer tfs = new TeamFoundationServer("TFSServer");
  15:              WorkItemStore wis = (WorkItemStore) tfs.GetService(typeof(WorkItemStore));
  16:   
  17:              Project teamProject = wis.Projects[0];
  18:              foreach (WorkItemType wit in teamProject.WorkItemTypes)
  19:                  Console.WriteLine(wit.Name);
  20:   
  21:              WorkItemCollection wic = wis.Query("Project='Test' AND Type='Bug'");
  22:              foreach (WorkItem wiEntry in wic)
  23:              {
  24:              }
  25:   
  26:              WorkItemType witBug = teamProject.WorkItemTypes["Bug"];
  27:              if (witBug != null)
  28:              {
  29:                  Console.WriteLine("Adding new bug to Team Project {0}", teamProject.Name);
  30:   
  31:                  WorkItem wi = new WorkItem(witBug);
  32:                  wi.Description = "This is a sample bug which was added through the object model";
  33:                  wi.Reason = "New";
  34:                  wi.Title = "You have Bugs! [Ding]";
  35:   
  36:                  wi.Save();
  37:                  Console.WriteLine("Added Work Item # {0} created by {1}", wi.Id, wi.CreatedBy);
  38:              }
  39:          }
  40:      }
  41:  }


Breaking this down a bit, the first main piece of code is the connection to the Team Server itself. This is accomplished on line 14 by creating a new TeamFoundationServer object. An optional constructor allows for credentials to be provided, otherwise it logs on as the current principle.

Next, we retrieve the WorkItemStore. Almost everything in the object model is accessed through the IServiceProvider interface which provides a GetService method where you pass in the System.Type object you want to work with. This is a nice versioning technique that is utilized in many other Microsoft technologies as well.

With the WorkItemStore, you can then query work item type definitions, one of which is necessary to create a WorkItem. You fill in the details for the Work Item you want to create and call the Save method (line 36) to commit the changes to the TFS store. The WorkItem id will then be valid and could be added to the existing bug tracking system as a forward link to the new information if you wanted.
posted on 8/28/2006 5:45:13 AM (Central Standard Time, UTC-06:00)  #   

Related Posts:
Demos + Labs for the WPF+LINQ class this week
Implementing Drag/Drop with TabControl
ATAPI assembly updated!
Adding ILDasm to VS.NET with a keyboard shortcut
Creating Extensible Applications with MAF (System.AddIn)
Creating popup windows in XBAP applications

Tracked by:
"lined wicker laundry baskets" (lined wicker laundry baskets) [Trackback]
"Alberta Incorporation" (Alberta Incorporation) [Trackback]
"moving companies quotes" (moving companies quotes) [Trackback]
"dvd xcopy platinum" (dvd xcopy platinum) [Trackback]
"What%27s a Jewish Matchmaker" (What%27s a Jewish Matchmaker) [Trackback]
"real audio player" (real audio player) [Trackback]
"dawn of war mod" (dawn of war mod) [Trackback]
"broker dealer information" (broker dealer information) [Trackback]
"2005 ford expedition" (2005 ford expedition) [Trackback]
"exotic canopy beds" (exotic canopy beds) [Trackback]
"mangosteen ORAC ounce" (mangosteen ORAC ounce) [Trackback]
"Camouflage Wetsuits" (Camouflage Wetsuits) [Trackback]
"first compound microscope" (first compound microscope) [Trackback]
"Flagyl and diverticulitis" (Flagyl and diverticulitis) [Trackback]
"hookah diving with out tanks" (hookah diving with out tanks) [Trackback]
"hud property" (hud property) [Trackback]
"compromises of the constitution" (compromises of the constitution) [Trackback]
"vulnerability scanner" (vulnerability scanner) [Trackback]
"protonix in surgery use" (protonix in surgery use) [Trackback]
"No Deposit Bonus" (No Deposit Bonus) [Trackback]
"cervical disc problems" (cervical disc problems) [Trackback]
"residence inn seaworld" (residence inn seaworld) [Trackback]
"kayak rod holder" (kayak rod holder) [Trackback]
"SAGUARO CACTUS DERMATITIS" (SAGUARO CACTUS DERMATITIS) [Trackback]
"excel communications" (excel communications) [Trackback]
"personal injury lawyer virginia" (personal injury lawyer virginia) [Trackback]
"open response questions" (open response questions) [Trackback]
"body aches and persistent fever" (body aches and persistent fever) [Trackback]
"baby photo contest" (baby photo contest) [Trackback]
"vacation rentals massachusetts" (vacation rentals massachusetts) [Trackback]
"banner graphic, greencastle" (banner graphic, greencastle) [Trackback]
"white pages perth" (white pages perth) [Trackback]
"actonel d" (actonel d) [Trackback]
"mineral make-up" (mineral make-up) [Trackback]
"don gabriel cigar shop" (don gabriel cigar shop) [Trackback]
"jagg oil cooler" (jagg oil cooler) [Trackback]
"soft serve ice cream" (soft serve ice cream) [Trackback]
"used car buying guide quebec" (used car buying guide quebec) [Trackback]
"on off on round rocker switch" (on off on round rocker switch) [Trackback]
"Cheddars Restaurant in Texas" (Cheddars Restaurant in Texas) [Trackback]
"landhotel mallorca" (landhotel mallorca) [Trackback]
"pornomotore" (pornomotore) [Trackback]
"money money health health go2clickbank.com" (money money health health go2click... [Trackback]
"pictures of space" (pictures of space) [Trackback]
"omega psi phi fraternity songs" (omega psi phi fraternity songs) [Trackback]
"aggiungi sito" (aggiungi sito) [Trackback]
"DMAE Cream" (DMAE Cream) [Trackback]
"quilt hanger" (quilt hanger) [Trackback]