Skip to content

Instantly share code, notes, and snippets.

@bzbetty
Created December 8, 2012 01:15
Show Gist options
  • Save bzbetty/4238011 to your computer and use it in GitHub Desktop.
Save bzbetty/4238011 to your computer and use it in GitHub Desktop.
using Microsoft.TeamFoundation.Framework.Server;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Client;
public class BuildCreator : ISubscriber
{
public string Name
{
get { return "Automated Build Creator"; }
}
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;
statusMessage = string.Empty;
properties = null;
if (notificationType == NotificationType.Notification && notificationEventArgs is Microsoft.TeamFoundation.VersionControl.Server.CheckinNotification)
{
var checkinNotification = notificationEventArgs as Microsoft.TeamFoundation.VersionControl.Server.CheckinNotification;
TeamFoundationLocationService service = requestContext.GetService<TeamFoundationLocationService>();
Uri selfReferenceUri = service.GetSelfReferenceUri(requestContext, service.GetDefaultAccessMapping(requestContext));
TfsTeamProjectCollection tfsTeamProjectCollection = new TfsTeamProjectCollection(selfReferenceUri);
var versionControl = (VersionControlServer)tfsTeamProjectCollection.GetService(typeof(VersionControlServer));
var changeSet = versionControl.GetChangeset(checkinNotification.Changeset);
foreach (var change in changeSet.Changes)
{
if ((change.ChangeType & (ChangeType.Add | ChangeType.Branch)) == 0)
continue;
if (!Path.GetExtension(change.Item.ServerItem).Equals(".sln"))
continue;
var buildDefinitionHelper = new BuildDefinitionHelper(tfsTeamProjectCollection);
buildDefinitionHelper.CreateBuildDefinition(change.Item.ServerItem);
}
}
return EventNotificationStatus.ActionPermitted;
}
public Type[] SubscribedTypes()
{
return new Type[] { typeof(Microsoft.TeamFoundation.VersionControl.Server.CheckinNotification) };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment