Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Fechando uma User Story ao se fechar todas as tasks
public EventNotificationStatus ProcessEvent(
TeamFoundationRequestContext requestContext,
NotificationType notificationType,
object notificationEventArgs,
out int statusCode,
out string statusMessage,
out ExceptionPropertyCollection properties)
{
statusCode = 0;
statusMessage = string.Empty;
properties = null;
var typeNotification = notificationEventArgs.GetType();
if (notificationType == NotificationType.Notification && notificationEventArgs is WorkItemChangedEvent)
{
var ev = notificationEventArgs as WorkItemChangedEvent;
var id = ev.CoreFields.IntegerFields[0].NewValue;
var store = GetWorkItemStore(requestContext);
var workItem = store.GetWorkItem(id);
if (workItem.Project.Name == TfsTeamProject && workItem.Type.Name == "Task")
{
var parent = (from WorkItemLink workItemLink in workItem.WorkItemLinks
where workItemLink.LinkTypeEnd.Name == "Parent"
select store.GetWorkItem(workItemLink.TargetId))
.FirstOrDefault(wi => wi.Type.Name == "User Story");
if (parent == null) return EventNotificationStatus.ActionPermitted;
var anyTaskActive = (from WorkItemLink workItemLink in parent.WorkItemLinks
where workItemLink.LinkTypeEnd.Name == "Child"
select store.GetWorkItem(workItemLink.TargetId))
.Where(wi => wi.Type.Name == "Task")
.Any(wi => wi.State != "Closed" && wi.State != "Removed");
if (anyTaskActive && parent.State == "Closed")
{
parent.State = "Active";
parent.Save();
}
else if (!anyTaskActive)
{
parent.State = "Closed";
parent.Save();
}
}
}
return EventNotificationStatus.ActionPermitted;
}
private WorkItemStore GetWorkItemStore(TeamFoundationRequestContext requestContext)
{
var uri = GetTfsUri(requestContext);
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(uri);
return tpc.GetService<WorkItemStore>();
}
private Uri GetTfsUri(TeamFoundationRequestContext requestContext)
{
var locationService = requestContext.GetService<TeamFoundationLocationService>();
return new Uri(locationService.GetServerAccessMapping(requestContext).AccessPoint + "/" + requestContext.ServiceHost.Name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment