2016-09-19 37 views
0

我正在嘗試編寫一個HelloWorld TFS插件。我創建了一個類庫項目。代碼是在這裏:TFS 2013插件沒有解僱

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 \調試到C:\ Program Files文件\微軟的Team Foundation Server 12.0 \應用層\ Web服務\ BIN \插件我的TFS服務器上的

我正在使用最小安裝TFS 2013與更新5(12.0.40629.0(Tfs2013.Update5))。 當我將代碼簽入到此TFS服務器或更改工作項時,我應該看到日誌條目,但沒有看到我的代碼中有任何日誌條目。任何人都可以指出我在這裏錯過了什麼嗎?

參考文獻: enter image description here

+0

我還安裝了Visual TFS服務器上的Studio遠程調試工具。我試圖將視覺工作室調試器附加到TFS服務器上的w3p.exe,但是從未觸發過中斷點,我們發生了檢入事件。 –

回答

0

所有記錄應通過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