2015-10-29 84 views
0

在我的情况下,我需要订阅TFS事件(创建/删除团队项目,工作项目,签入,迭代,区域)以实现某些业务逻辑。我基于this manual。现在我只能捕获工作项目和签入事件,但我需要更多(团队项目,迭代,区域)。在this list,我没有找到正确的事件。Team Foundation Server 2012订阅事件

using System; 
using System.Collections.Generic; 
using System.Diagnostics; 
using Microsoft.TeamFoundation.Common; 
using Microsoft.TeamFoundation.Framework.Server; 
using Microsoft.TeamFoundation.Integration.Server; 
using Microsoft.TeamFoundation.VersionControl.Server; 
using Microsoft.TeamFoundation.WorkItemTracking.Server; 

public class WorkItemChangedEventHandler : ISubscriber 
{ 
    public string Name 
    { 
     get { return "WorkItemChangedEventHandler"; } 
    } 

    public SubscriberPriority Priority 
    { 
     get { return SubscriberPriority.Normal; } 
    } 

    public Type[] SubscribedTypes() 
    { 
     var types = new List<Type> 
     { 
      typeof(Microsoft.TeamFoundation.WorkItemTracking.Server.WorkItemChangedEvent),// working 
      typeof(Microsoft.TeamFoundation.VersionControl.Server.CheckinNotification),// working 
      typeof(Microsoft.TeamFoundation.Integration.Server.ProjectCreatedEvent)// NOT working 

     }; 
     return types.ToArray(); 
    } 

    public EventNotificationStatus ProcessEvent(TeamFoundationRequestContext requestContext, NotificationType notificationType, 
     object notificationEventArgs, out int statusCode, out string statusMessage, out ExceptionPropertyCollection properties) 
    { 
     statusCode = 0; 
     properties = null; 
     statusMessage = String.Empty; 
     try 
     { 
      EventLog.WriteEntry("WorkItemChangedEventHandler", string.Format("Entity: {0} was modified", notificationEventArgs.GetType())); 
     } 
     catch (Exception ex) 
     { 
      EventLog.WriteEntry("WorkItemChangedEventHandler", ex.Message + ex.StackTrace); 
     } 

     return EventNotificationStatus.ActionPermitted; 
    } 
} 

回答

0

我有CheckinNotificationEventHandler一个类:

public class CheckinNotificationEventHandler : ISubscriber 
{ 
     public Type[] SubscribedTypes() 
     { 
      return new Type[1] { typeof(CheckinNotification) }; 
     } 
     public EventNotificationStatus ProcessEvent(TeamFoundationRequestContext requestContext, NotificationType notificationType, object notificationEventArgs, out int statusCode, out string statusMessage, out ExceptionPropertyCollection properties) 
     { 
      if (notificationType == NotificationType.Notification && notificationEventArgs is CheckinNotification) 
      { 
     ... 
      } 
      return EventNotificationStatus.ActionPermitted; 
     } 
} 

和用于WorkItemChangedEventHandler第二类:

public class WorkItemChangedEventHandler : ISubscriber 
    { 

     public Type[] SubscribedTypes() 
     { 
      return new Type[1] { typeof(Microsoft.TeamFoundation.WorkItemTracking.Server.WorkItemChangedEvent) }; 
     } 

     public EventNotificationStatus ProcessEvent(TeamFoundationRequestContext requestContext, NotificationType notificationType, object notificationEventArgs, out int statusCode, out string statusMessage, out ExceptionPropertyCollection properties) 
     { 

      if (notificationType == NotificationType.Notification && notificationEventArgs is WorkItemChangedEvent) 
      { 
      ... 
      } 
     return EventNotificationStatus.ActionPermitted; 
     } 
    }