【问题标题】:TFS 2013 Plugin not firingTFS 2013 插件未触发
【发布时间】:2016-09-20 18:05:47
【问题描述】:

我正在尝试编写一个 HelloWorld TFS 插件。我创建了一个类库项目。代码在这里:

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

namespace TFSServerSideHandler
{
    public class WorkItemChangedEventHandler : ISubscriber
    {
        EventLog appLog = new EventLog();

        public string Name
        {
            get { return "WorkItemChangedEventHandler"; }
        }

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

        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
            {
                appLog.Source = "WorkItemChangedEventHandler";
                appLog.WriteEntry("Handled event : " + notificationEventArgs.GetType().Name);
            }
            catch (Exception exception)
            {
                appLog.Source = "WorkItemChangedEventHandler";
                appLog.WriteEntry("Couldn't Handle event : " + notificationEventArgs.GetType().Name + " Exception : " + exception.ToString());
            }
            return EventNotificationStatus.ActionPermitted;
        }

        public Type[] SubscribedTypes()
        {
            return new Type[] { typeof(WorkItemChangedEvent), typeof(CheckinNotification) };
        }
    }
}

我构建项目,然后将所有文件从 \TFSServerSideHandler\bin\Debug 部署到我的 C:\Program Files\Microsoft Team Foundation Server 12.0\Application Tier\Web Services\bin\Plugins TFS 服务器。

我正在使用带有更新 5 (12.0.40629.0 (Tfs2013.Update5)) 的 TFS 2013 的最小安装。 当我将代码签入到此 TFS 服务器或更改工作项时,我应该会看到日志条目,但我的代码中没有看到任何日志条目。谁能指出我在这里缺少的东西?

参考资料:

【问题讨论】:

  • 我还在 TFS 服务器上安装了 Visual Studio 远程调试工具。我尝试将 Visual Studio 调试器附加到 TFS 服务器上的 w3p.exe,但从未遇到过断点,因为发生了签入事件。

标签: tfs


【解决方案1】:

所有日志记录都应通过 TeamFoundationApplication 类完成,该类具有 “Log”“LogException” 方法。这很重要,因为它将使用 TFS 上下文来记录信息并使用为 TFS 进程设置的相同日志记录详细程度。 避免使用Applog.WriteEntry(),因为您的消息不会被记录为来自 TFS。

代码:这显示了响应签入事件的代码示例实现:

namespace Sample.SourceControl.Server.PlugIns
{
    public class CodeCheckInEventHandler : ISubscriber
    {
        public string Name
        {
            get { return "CodeCheckInEventHandler"; }
        }

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

        public EventNotificationStatus ProcessEvent(TeamFoundationRequestContext requestContext, NotificationType notificationType, object notificationEventArgs, out int statusCode, out string statusMessage, out Microsoft.TeamFoundation.Common.ExceptionPropertyCollection properties)
        {
            statusCode = 0;
            properties = null;
            statusMessage = String.Empty;
            try
            {
                if (notificationType == NotificationType.Notification && notificationEventArgs is WorkItemChangedEvent)
                {
                    CheckinNotification ev = notificationEventArgs as CheckinNotification;
                    TeamFoundationApplication.Log(string.Format("New Changeset was checked in by {0}. ID: {1}, comments: {2}", ev.ChangesetOwnerName, ev.Changeset, ev.Comment), 123, System.Diagnostics.EventLogEntryType.Information);
                }
            }
            catch (Exception ex)
            {
                TeamFoundationApplication.LogException("Sample.SourceControl.Server.PlugIns.CodeCheckInEventHandler encountered an exception", ex);
            }
            return EventNotificationStatus.ActionPermitted;
        }

        public Type[] SubscribedTypes()
        {
            return new Type[1] { typeof(CheckinNotification) };
        }
    }
}

更多详细信息,请查看此博客:TFS Server-side event handlers

【讨论】:

    猜你喜欢
    • 2023-03-04
    • 2015-09-18
    • 2014-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    相关资源
    最近更新 更多