2017-03-09 34 views
0

我实现了一个简单的WorkItemChangedEventHandler的TFS 2015年TFS服务器端插件启动两次

在我的TFS 2015年快速测试安装,事件处理程序获取实例化两次。第一个实例是在TFS识别出由于新构建而导致的BinDirChangeOrDirectoryRename后立即创建的。第二个实例是在第一次访问数据库之后创建的。

鉴于此源代码(注意,只有构造函数相关的):

​​

我碰到下面的事件记录:

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年或错误我想念什么?

+1

当一个事件来通过调用两次你的代码? –

+0

事件只发射一次。感谢提示。但是,我必须重新设计我的事件处理程序,因为它需要创建后台线程来触发延迟更新过程。没有必要同时运行两个这样的线程。 – freefall

+0

为什么不把它作为服务钩子而不是服务器端插件来实现? –

回答

1

我测试过在我的身边你的代码,并发现事件日志中写道:“新的插件实例创建与哈希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; 
     } 
    } 
} 

enter image description here