【问题标题】:Team Foundation Server 2012 subscribe to eventsTeam Foundation Server 2012 订阅事件
【发布时间】:2015-10-29 17:39:43
【问题描述】:

就我而言,我需要订阅 TFS 事件(创建/删除团队项目、工作项、签入、迭代、区域)以实现一些业务逻辑。我基于this manual。现在我只能捕获工作项和签入事件,但我需要更多(团队项目、迭代、区域)。在this list,我没有找到合适的事件。

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;
    }
}

【问题讨论】:

    标签: plugins customization


    【解决方案1】:

    我有一个 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;
            }
         }
    

    【讨论】:

      猜你喜欢
      • 2013-04-15
      • 2013-02-16
      • 2012-08-23
      • 2016-10-04
      • 2014-12-26
      • 2016-01-31
      • 2014-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多