1

我们有一个自定义服务器端 tfs 插件,它部署在 Azure DevOps Server 2019\Application Tier\Web Services\bin\Plugins 下。插件中有两个订阅者,一个订阅 WorkItemChangedEvent,另一个订阅 ProjectCreatedEvent。

WorkItemChangedEvent 订阅者按预期工作,不幸的是 ProjectCreatedEvent 订阅者没有。附加到 w3wp.exe 进程后尝试调试代码,但从未调用 ProcessEvent 方法。

我正在使用默认的项目创建向导通过浏览器创建一个项目。

我是否为此事件 Microsoft.TeamFoundation.Server.ProjectCreatedEvent 使用了正确的 dll?还是已弃用?

分享下面的示例代码:

任何帮助,将不胜感激。

public class ProjectCreationSubscriber : ISubscriber
    {
        private static ILog _logger = LogManager.GetLogger(typeof(ProjectCreationSubscriber));
        private static readonly string subscriberName = "ProjectCreationSubscriber";
        private static Type[] subscribedTypes = null;
        private static ControlConfiguration controlConfiguration = null;
        private static WorkItemStoreServiceContainer serviceContainer = new WorkItemStoreServiceContainer();


        public string Name
        {
            get
            {
                return subscriberName;
            }
        }


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


        public Type[] SubscribedTypes()
        {
            if (subscribedTypes == null)
            {
                subscribedTypes = new Type[1]
                {
                    typeof(Microsoft.TeamFoundation.Server.ProjectCreatedEvent)
                };
            }
            return subscribedTypes;
        }


        public EventNotificationStatus ProcessEvent(IVssRequestContext requestContext, NotificationType notificationType, object notificationEventArgs, out int statusCode, out string statusMessage, out ExceptionPropertyCollection properties)
        {
            statusCode = 0;
            properties = null;
            statusMessage = String.Empty;


            try
            {

                ProjectCreationSubscriber._logger.InfoFormat("PROCESS EVENT! NotificationType:{0}, NotificationEventArgs:{0}", notificationType, JsonUtilities.Serialize(notificationEventArgs));


                if (notificationType == NotificationType.Notification && notificationEventArgs is Microsoft.TeamFoundation.Server.ProjectCreatedEvent)
                {
                    var notificationEvent = notificationEventArgs as ProjectCreatedEvent;
                    //doing stuff here

            }
            catch (Exception ex)
            {
                var exceptionInfo = string.Format("Error occured in {0}", this.Name);
                ProjectCreationSubscriber._logger.Error(exceptionInfo, ex);


                EventLog.WriteEntry(this.Name, exceptionInfo, EventLogEntryType.Error);


                //TeamFoundationApplicationCore.LogException(exceptionInfo, ex);
            }
            Trace.CorrelationManager.StopLogicalOperation();
            return EventNotificationStatus.ActionPermitted;
        }
4

0 回答 0