TFS API Part 8: Subscribe/Unsubscribe Events Using IEventService

28/01/2009

TFS API Part 8: Subscribe/Unsubscribe Events Using IEventService

In the last post I wrote about TFS API Part 7: Use IEventService To Get User Event Subscriptions.

In this post I’ll show you have to user IEventService to Subscribe new Events and Unsubscribe existingEvents.

First add reference for Microsoft.TeamFoundation, Microsoft.TeamFoundation.Client, Microsoft.TeamFoundation.Common.dll,Microsoft.TeamFoundation.WorkItemTracking.Client.dll
located in – C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\

Download Demo

Add using for:

using Microsoft.TeamFoundation.Proxy;

using Microsoft.TeamFoundation.Server;

using Microsoft.TeamFoundation.Client;

image

I add the Event Type to the SubscriptionItem class

Here is available type for TFS:

BranchMovedEvent
BuildCompletionEvent
BuildStatusChangedEvent
CheckinEvent
CommonStructureChangedEvent
DataChangedEvent
IdentityChangedEvent
NodeCreatedEvent
NodePropertiesChangedEvent
NodeRenamedEvent
NodesDeletedEvent
ProjectCreatedEvent
ProjectDeletedEvent
WorkItemChangedEvent

 

Subscribe Event

You can add a Combo for picking the right Delivery preference.

DeliveryPreference delPrev = new DeliveryPreference();

switch (lbl_sch.Content.ToString())

{

    case "Daily":

          delPrev.Schedule = DeliverySchedule.Daily;

    break;

    case "Weekly":

          delPrev.Schedule = DeliverySchedule.Weekly;

    break;

    default:

          delPrev.Schedule = DeliverySchedule.Immediate;

    break;

}

switch (lbl_type.Content.ToString())

{

    case "EmailPlaintext":

          delPrev.Type = DeliveryType.EmailPlaintext;

    break;

    case "Soap":

          delPrev.Type = DeliveryType.Soap;

    break;

    default:

          delPrev.Type = DeliveryType.EmailHtml;

    break;

}

 

User u = (User)listBox1.SelectedItem;

//Adding user email to DeliveryPreference.

delPrev.Address = u.Email;

string userId = Environment.UserDomainName + @"\" + u.UserName;

 

try

{

  //userid,event type,subscription expresstion,delivery preference

  int event_id = EventService.SubscribeEvent(userId,

  lbl_eventtype.Content.ToString(),

  txt_sub.Text, delPrev);

 

 MessageBox.Show("Subscribe Complete, Your SubscribeID is: " + event_id, "TFS", MessageBoxButton.OK, MessageBoxImage.Information);

}

catch (Exception ex)

{

   MessageBox.Show("Error:" + ex.Message, "TFS Error", MessageBoxButton.OK, MessageBoxImage.Error);

}

 

image

 

UnSubscribe Event

//Events list

if (listBox2.SelectedItem != null)

{

    EventService.UnsubscribeEvent(Convert.ToInt32(listBox2.SelectedValue.ToString()));

    MessageBox.Show("UnSubscribe Complete", "TFS", MessageBoxButton.OK, MessageBoxImage.Information);

}

else

{

     MessageBox.Show("Please select Subscribe from the list.", "TFS", MessageBoxButton.OK, MessageBoxImage.Error);

}

 image

Download Demo

Add comment
facebook linkedin twitter email

Leave a Reply