您可以创建一个侦听器来侦听 CheckInEvent,而不是 Checkin 策略。触发事件后,发出通知。那些服务器端插件正在实现ISubscriber 接口,请参阅这篇博客文章如何编写和调试它们。
以下是此博客中的代码,显示了响应签入事件的代码示例实现,您可以参考它:
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) };
}
}
}