subscribe an event using the API

Hi,

Can any one please pass the code how to subscribe an event using the API.

I couldnt find any example of this issue.

Thanks in advance,

Shmulik.

[183 byte] By [shmulik_segal] at [2007-12-20]
# 1

The API you are looking for is in the Microsoft.TeamFoundation.Server namespace in the Microsoft.TeamFoundation.Common assembly.

The interface that allows you to manipulate subscriptions is IEventService. You would do something like this:

using System;

using Microsoft.TeamFoundation.Client;

using Microsoft.TeamFoundation.Server;

namespace SubscriptionTest

{

class Program

{

static void Main(string[] args)

{

TeamFoundationServer tfs = new TeamFoundationServer("myTFSServer");

IEventService eventService = (IEventService)tfs.GetService(typeof(IEventService));

DeliveryPreference prefs = new DeliveryPreference();

prefs.Schedule = DeliverySchedule.Immediate;

prefs.Type = DeliveryType.EmailHtml;

prefs.Address = "myaddress@mydomain.com";

string filter = "myfilter";

string eventName = "WorkItemChangedEvent";

string userName = "myUser";

int sId = eventService.SubscribeEvent(userName, eventName, filter, prefs);

Console.WriteLine("Created Subscription #{0}", sId);

}

}

}

KarthikSubramanyam at 2007-9-10 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server - General...
# 2
Thanks a lot.
shmulik_segal at 2007-9-10 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server - General...
# 3

Hi,

Thanks again for your answer - Karthik,

I have a small problem with my code, I thought maby you can help me with that .

I didnt succeed to subscribe an event with this filter.

My filter string look like this:

String filter = "PortfolioProject = 'Shmil_TP' AND \\ChangedFields/StringFields/Field[ReferenceName='System.AssignedTo']/NewValue\ = 'MyName' AND \\ChangedFields/StringFields/Field[ReferenceName='System.WorkItemType']/NewValue\\ = 'Bug' "

I'm getting syntax error, and I cant figure what is the problem.

By the way, I succeed to subscribe some other events.

Thanks in advance,

Shmulik.

shmulik_segal at 2007-9-10 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server - General...
# 4

1) Remove the "\\" before ChangedFields (both locations) and after the last NewValue.

2) Put double-quotes (escaped) around the XPath expression parts so that the parser is not confused by the equals signs after ReferenceName. For example, change

ChangedFields/StringFields/Field[ReferenceName='System.AssignedTo']/NewValue = 'MyName'

to

\"ChangedFields/StringFields/Field[ReferenceName='System.AssignedTo']/NewValue\" = 'MyName'

PeteSheillMSFT at 2007-9-10 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server - General...

Visual Studio Team System

Site Classified