tags:

views:

162

answers:

2

We develop some product using an internal design tool that stores information in XML files. To provide proper integration with TFS we've also coded a provider that tracks, in TFS, checkin and checkout operation from users while they're using the designer, without any need to interact with Team Explorer.

Now the requirement is to add also the related workitem when checking in files, I've googled around and browsed some SDK samples but I was not able to understand if there is a way to show the same windows form that allow user to associate code to workitem from code or do we have to implement the full windows form from code (retrieve and search workitems, associate them, perform the checkin and so on). Any info would be appreciated because between the two solution there is a lot of difference in term of how much code we need to write.

+1  A: 

Here is some code to help with updating workItems. Also, try [this link][1] for more information.

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


namespace WorkItemTrackingSample2
{
    class Program
    {
        static void Main(string[] args)
        {
            // Connect to the server and the store.
            TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("YourTfsServerNameHere");
            WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
            // Get a specific WorkItem from the store.
            //   Replace "12345" with a WorkItem ID appropriate for testing.
            WorkItem workItem = workItemStore.GetWorkItem(12345);

            // Save the existing Priority so we can restore it later.
            int oldPriority = (int)workItem.Fields["Priority"].Value;

            // Set the Priority to an arbitrarily high number.
            workItem.Fields["Priority"].Value = 9999;

            // Display the results of this change.
            if (workItem.IsDirty)
                Console.WriteLine("The workItem has changed, but has not been saved.");

            if (workItem.IsValid() == false)
                Console.WriteLine("The workItem is not valid.");

            if (workItem.Fields["Priority"].IsValid == false)
                Console.WriteLine("The workItem's Priority field is not valid.");

            // Tries to save the invalid WorkItem.
            try
            {
                workItem.Save();
            }
            catch (ValidationException)
            {
                Console.WriteLine("The workItem threw a ValidationException.");
            }

            // Set the priority to a more reasonable number.
            if (oldPriority == 1)
                workItem.Fields["Priority"].Value = 2;
            else
                workItem.Fields["Priority"].Value = 1;

            // If the WorkItem is valid, saves the changed WorkItem.
            if (workItem.IsValid())
            {
                workItem.Save();
                Console.WriteLine("The workItem saved this time.");
            }

            // Restore the WorkItem's Priority to its original value.
            workItem.Fields["Priority"].Value = oldPriority;
            workItem.Save();
        }
    }
}


  [1]: http://msdn.microsoft.com/en-us/library/bb130323(VS.80).aspx
Chris Ballance
Does not seem to apply to me...
massimogentilini
A: 

I've checked with MS consultancy and there is no way to show the checkin window used by TFS or the shell extension without resorting to low level code that is not really safe.

So only possible solution is to use the TFS Api to create a new C# control/project to mimic the TFS checkin window.

Regards Massimo

massimogentilini