Created
August 6, 2011 00:33
-
-
Save igoravl/1128841 to your computer and use it in GitHub Desktop.
Exemplo de event handler para o TFS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: Microsoft.TeamFoundation | |
// Reference: Microsoft.TeamFoudnation.Client | |
// Reference: Microsoft.TeamFoundation.Common | |
// Reference: Microsoft.TeamFoundation.Framework.Server | |
// Reference: Microsoft.TeamFoundation.Server | |
// Reference: Microsoft.TeamFoundation.WorkItemTracking.Client | |
// Reference: Microsoft.TeamFoundation.WorkItemTracking.Server.Dataaccesslayer | |
// Reference: Microsoft.TeamFoundation.WorkItemTracking.Server.DataServices | |
// Copy resulting DLL to %PROGRAMFILES%\Microsoft Team Foundation Server 2010\Application Tier\Web Services\Bin\Plugins | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Microsoft.TeamFoundation.Framework.Server; | |
using Microsoft.TeamFoundation.WorkItemTracking.Server; | |
using Microsoft.TeamFoundation.Client; | |
using Microsoft.TeamFoundation.WorkItemTracking.Client; | |
using System.Net; | |
namespace TfsEventHandler | |
{ | |
public class EventListener: ISubscriber | |
{ | |
public string Name | |
{ | |
get { return "Event Listener de Exemplo"; } | |
} | |
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) | |
{ | |
WorkItemChangedEvent eventData = notificationEventArgs as WorkItemChangedEvent; | |
statusCode = 0; | |
statusMessage = string.Empty; | |
properties = null; | |
if (eventData == null) | |
{ | |
return EventNotificationStatus.ActionPermitted; | |
} | |
var field = eventData.ChangedFields.StringFields.FirstOrDefault(fld => fld.ReferenceName == "System.State" && fld.NewValue == "Resolved" && fld.OldValue == "Closed"); | |
if (field == null) | |
{ | |
return EventNotificationStatus.ActionPermitted; | |
} | |
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("http://localhost:8080/tfs/defaultcollection"), new NetworkCredential("abuobe", "P2ssw0rd")); | |
tpc.EnsureAuthenticated(); | |
WorkItemStore store = tpc.GetService<WorkItemStore>(); | |
var project = store.Projects[eventData.PortfolioProject]; | |
var wi = project.WorkItemTypes["Issue"].NewWorkItem(); | |
wi.Title = "Novo impedimento"; | |
wi.Save(); | |
return EventNotificationStatus.ActionPermitted; | |
} | |
public Type[] SubscribedTypes() | |
{ | |
return new Type[] { typeof(WorkItemChangedEvent) } ; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment