我为TFS 2015实现了一个简单的WorkItemChangedEventHandler。
在我的TFS 2015 Express测试安装中,事件处理程序实例化两次。第一个实例是在TFS识别出 BinDirChangeOrDirectoryRename 作为新构建的结果之后立即创建的。第二次实例是在第一次访问数据库后立即创建的。
鉴于此源代码(注意,只有构造函数是相关的):
using System;
using System.Diagnostics;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.Framework.Server;
using Microsoft.TeamFoundation.WorkItemTracking.Server;
namespace MyFirstTfsPlugin
{
public class TfsTriggerConfluenceUpdateOnWorkItemChanged : ISubscriber
{
public TfsTriggerConfluenceUpdateOnWorkItemChanged()
{
EventLog.WriteEntry("TFS Services", $"New Plugin Instance Created with Hash {GetHashCode()}");
}
public string Name => "WorkItemChangedEventHandler";
public SubscriberPriority Priority => SubscriberPriority.Normal;
public Type[] SubscribedTypes() => new[] { typeof(WorkItemChangedEvent) };
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;
return EventNotificationStatus.ActionPermitted;
}
}
}
我记录了以下事件:
Information 09.03.2017 17:37:16 TFS Services 9002 None The application is being shutdown for the following reason: BinDirChangeOrDirectoryRename
Information 09.03.2017 17:37:23 TFS Services 0 None New Plugin Instance Created with Hash 44661510
Information 09.03.2017 17:37:24 TFS Services 9001 None Application Request Processing Started
Information 09.03.2017 17:37:58 MSSQL$SQLEXPRESS 17137 Server Starting up database 'Tfs_DefaultCollection'.
Information 09.03.2017 17:37:58 TFS Services 0 None New Plugin Instance Created with Hash 27996961
这是TFS 2015中的错误还是我错过了什么?
答案 0 :(得分:1)
我已经测试了你的代码,并发现事件日志写了"使用Hash xxxxxx创建的新插件实例"不时,不只是两次(对不起,我无法找出为什么会发生这种情况)。
但是如果在ProcessEvent中添加EventLog.WriteEntry,则行为是正确的。更改工作项时,事件日志中只有一个条目:
using System;
using System.Diagnostics;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.Framework.Server;
using Microsoft.TeamFoundation.WorkItemTracking.Server;
namespace MyFirstTfsPlugin
{
public class TfsTriggerConfluenceUpdateOnWorkItemChanged : ISubscriber
{
//public TfsTriggerConfluenceUpdateOnWorkItemChanged()
//{
// EventLog.WriteEntry("TFS Services 1", $"New Plugin Instance Created with Hash {GetHashCode()}");
//}
public string Name => "WorkItemChangedEventHandler";
public SubscriberPriority Priority => SubscriberPriority.Normal;
public Type[] SubscribedTypes() => new[] { typeof(WorkItemChangedEvent) };
public EventNotificationStatus ProcessEvent(
IVssRequestContext requestContext,
NotificationType notificationType,
object notificationEventArgs,
out int statusCode,
out string statusMessage,
out ExceptionPropertyCollection properties)
{
EventLog.WriteEntry("TFS Services 2", $"workitem Created with Hash {GetHashCode()}");
statusCode = 0;
properties = null;
statusMessage = String.Empty;
return EventNotificationStatus.ActionPermitted;
}
}
}