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.
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.
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);}
}
}
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.
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'