DCSIMG
TFS API Part 7: Use IEventService To Get User Event Subscriptions - Shai Raiten's Blog

Shai Raiten's Blog

It's all about code...

TFS API Part 7: Use IEventService To Get User Event Subscriptions

TFS API Part 7: Use IEventService To Get User Event Subscriptions

Over the previous posts I talked about Connecting TFS and Working with WorkItemStore.

The following posts will about about more advanced and interesting subjects

In this post I’ll show how to use IEventService to get user subscription from tfs.

We going to build a WPF application that will collect all users in TFS and show Event Subscriptions for each user.

Download Demo

image

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\

Add using for:

using Microsoft.TeamFoundation.Proxy;

using Microsoft.TeamFoundation.Server;

using Microsoft.TeamFoundation.Client;

Connecting to TFS - TFS API Part 1: Domain Picker

DomainProjectPicker dp = new DomainProjectPicker(DomainProjectPickerMode.None);

 

dp.ShowDialog();

tfs = dp.SelectedServer;

 

if (dp.SelectedServer != null)

{

     //Get IEventService interface using Tfs server.

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

     GetUsersList();

}

Get User List - TFS API Part 4: Get TFS User List (Mail, Sid, Account, Domain)

private void GetUsersList()

{

   IGroupSecurityService gss = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService));

   Identity idSID = gss.ReadIdentity(SearchFactor.AccountName, "Team Foundation Valid Users", QueryMembership.Expanded);

   Identity[] idUserName = gss.ReadIdentities(SearchFactor.Sid, idSID.Members, QueryMembership.None);

   foreach (Identity id in idUserName)

   {

      if (id != null && id.Type == IdentityType.WindowsUser)

      {

         User u = new User(id.AccountName, id.MailAddress);

         listBox1.Items.Add(u);

      }

   }

}

User Class

 

public class User

{

 public string Email { get; set; }

 public string UserName { get; set; }

 public List<SubscriptionItem> SubList { get; set; }

 

 public User(string username,string email)

{

  this.UserName = username;

  this.Email = email;

  SubList = new List<SubscriptionItem>();

 

  //Make sure you enter the Domain Name & User Name!

  foreach (Subscription s in Window1.EventService.EventSubscriptions(Environment.UserDomainName + @"\" + this.UserName))

  {

    SubList.Add(new SubscriptionItem(s));

  }

}

 

 public override string ToString()

{

   return UserName;

}

}

Subscription Item

public class SubscriptionItem

    {

        public int ID { get; set; }

        public string ConditionString { get; set; }

        public DeliverySchedule Schedule { get; set; }

        public DeliveryType Type { get; set; }

        public string Tag { get; set; }

 

        public SubscriptionItem(Subscription s)

        {       

            this.ID = s.ID;

            this.Schedule = s.DeliveryPreference.Schedule;

            this.Type = s.DeliveryPreference.Type;

            this.ConditionString = s.ConditionString;

        }

 

        public override string ToString()

        {

            //In 2008 you can Tag you Subscription

            if (string.IsNullOrEmpty(Tag))

                return ID.ToString();

            else

                return Tag;

        }

    }

Download Demo

Comments

Team System News said:

Shai Raiten on TFS API Part 7: Use IEventService To Get User Event Subscriptions and Q: Work Item Definition

# January 22, 2009 1:45 PM

Shai Raiten said:

TFS API Part 8: Subscribe/Unsubscribe Events Using IEventService In the last post I wrote about TFS API

# January 28, 2009 9:50 PM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# January 31, 2009 1:26 AM

Oleg said:

Error 8 The type or namespace name 'DeliverySchedule' could not be found (are you missing a using directive or an assembly reference?)

# July 3, 2010 6:07 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: