I'm trying to write some code that monitors the TFS WorkItems on my local workstation but at the moment I'm having problems getting the events to fire.
I have subscribed to FieldChange event of WorkItem but it doesn't fire when I change/update any workitem.
The code below is a console application that I think should work,bu it doesn't . Does anyone know how to successfully subscribe to these events?
Any help in this matter is appreciable .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using System.Net;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.Framework.Client;
namespace TFSEvents
{
class Program
{
static void Main(string[] args)
{
try
{
Uri serverUri = new Uri(@"http://tfs");
string username, password;
Console.WriteLine("Enter Username:");
username = Console.ReadLine();
Console.WriteLine("Enter password:");
password = ReadPassword();
NetworkCredential cred = new NetworkCredential(username, password);
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(serverUri, cred);
tfs.EnsureAuthenticated();
IEventService vs = tfs.GetService<IEventService>();
var wiww = tfs.GetService<WorkItemStore>();
var wi = wiww.GetWorkItem(4671);
wi.FieldChanged += new WorkItemFieldChangeEventHandler(changeHandler);
var x = vs.GetAllEventSubscriptions().ToList();
Console.WriteLine("Press \'q\' to quit.");
while (Console.ReadLine() != "q") ;
}
catch (Exception e)
{
}
}
private static void changeHandler(object o, WorkItemEventArgs e)
{
Console.WriteLine(e.Field);
}
}
}