14.01.2015 Views

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Many more such customizations are possible. A Team Foundation<br />

Server Power Tool (http://www.microsoft.com/en-in/download/<br />

details.aspxid=35775) makes it easy to customize processes as<br />

you need.<br />

TFS 2012 is a set of WCF services. These services are exposed for<br />

extension by a well published object model. This object model is<br />

encapsulated in components i.e. TFS APIs. The structure of these<br />

APIs is:<br />

One of the most popular use of this object model is to write an<br />

event handler that executes when a certain event is raised by<br />

TFS. For example, when someone creates a new work item, we<br />

may want to check if the work item type of that newly created<br />

work item is a ‘User Story’ and spawns a set of work items of the<br />

type ‘Task’ to implement that user story. In this case, we can<br />

create an event handler for the event of ‘WorkItemChanged’.<br />

For this, we can write a class that implements Microsoft.<br />

TeamFoundation.Framework.Server.ISubscriber interface. In the<br />

ProcessEvent method, we can write the code that will execute<br />

when the event happens. Snippet of boilerplate code is as<br />

follows:<br />

WorkItemChangedEvent)<br />

{<br />

string machineName = System.Environment.MachineName;<br />

TfsTeamProjectCollection tpc = new<br />

TfsTeamProjectCollection(new Uri(“http://” +<br />

machineName + “:8080/tfs/DefaultCollection”));<br />

WorkItemChangedEvent ev = notificationEventArgs as<br />

WorkItemChangedEvent;<br />

WorkItemStore ws = tpc.GetService();<br />

Microsoft.TeamFoundation.WorkItemTracking.<br />

Client.WorkItem wi = ws.GetWorkItem(ev.<br />

CoreFields.IntegerFields[0].NewValue);<br />

Project project = ws.Projects[ev.PortfolioProject];<br />

if (wi.Type == project.WorkItemTypes[“User Story”]<br />

&& wi.RelatedLinkCount == 0)<br />

{<br />

Microsoft.TeamFoundation.WorkItemTracking.<br />

Client.WorkItem NewTask = new Microsoft.<br />

TeamFoundation.WorkItemTracking.Client.<br />

WorkItem(project.WorkItemTypes[“Task”]);<br />

NewTask.Title = “Create architecture diagrams<br />

for user story “ + wi.Id;<br />

WorkItemLinkTypeEnd linkTypeEnd =<br />

ws.WorkItemLinkTypes.<br />

LinkTypeEnds[“Parent”];<br />

NewTask.Links.Add(new<br />

RelatedLink(linkTypeEnd,wi.Id));<br />

NewTask.Save();<br />

}<br />

}<br />

return EventNotificationStatus.ActionApproved;<br />

}<br />

Similar to ‘WorkItemChanged’ event, TFS raises following events<br />

for which we can write various event handlers:<br />

public EventNotificationStatus ProcessEvent(TeamFound<br />

ationRequestContext requestContext, NotificationType<br />

notificationType, object notificationEventArgs, out int<br />

statusCode, out string statusMessage, out Microsoft.<br />

TeamFoundation.Common.ExceptionPropertyCollection properties)<br />

{<br />

statusCode = 0;<br />

statusMessage = string.Empty;<br />

properties = null;<br />

if (notificationType == NotificationType.<br />

Notification && notificationEventArgs is<br />

DNcmagazine www.dotnetcurry.com | 59

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!