Created
December 19, 2012 20:09
-
-
Save bzbetty/4340032 to your computer and use it in GitHub Desktop.
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
public class AreaCreatedSubscriber : ISubscriber | |
{ | |
public string Name | |
{ | |
get { return "Create Default Queries"; } | |
} | |
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) | |
{ | |
statusMessage = string.Empty; | |
statusCode = 0; | |
properties = null; | |
try | |
{ | |
if (notificationType == NotificationType.Notification) | |
{ | |
var eventArgs = notificationEventArgs as StructureChangedNotification; | |
if (eventArgs != null) | |
{ | |
ICommonStructureService commonStructureService = requestContext.GetService<CommonStructureService>(); | |
var changedNodes = commonStructureService.GetChangedNodes(requestContext, eventArgs.SequenceId - 1); | |
XDocument xml = XDocument.Parse(changedNodes); | |
XElement changedNode = (from XElement n in xml.Descendants("StructureElement") select n).First(); | |
if (changedNode.Attributes("Deleted").First().Value.ToString() == true.ToString()) | |
return EventNotificationStatus.ActionPermitted; | |
string nodeId = changedNode.Attributes("Id").First().Value.ToString(); | |
var node = commonStructureService.GetNode(requestContext, nodeId); | |
if (node.StructureType != StructureType.ProjectModelHierarchy) | |
return EventNotificationStatus.ActionPermitted; | |
var reader = XmlReader.Create(new StringReader("<AreaPath>" + node.Path + "</AreaPath>")); | |
var xmlData = new XmlDocument().ReadNode(reader); | |
// Handle the notification by queueing the information we need for a job | |
var jobService = requestContext.GetService<TeamFoundationJobService>(); | |
jobService.QueueOneTimeJob(requestContext, "Create Default Queries", typeof(CreateDefaultQueriesJob).ToString(), xmlData, false); | |
} | |
} | |
} | |
catch (Exception e) | |
{ | |
statusMessage = e.Message; | |
} | |
return EventNotificationStatus.ActionPermitted; | |
} | |
public Type[] SubscribedTypes() | |
{ | |
return new[] { typeof(StructureChangedNotification) }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment