TFS Workflow Activity to call REST Service after build, custom or canned?
I have a NuGet repo that gets a package after each build. I have a REST service that is an extension to the NuGet server that will delete all packages lower than the one specified. The rug that will tie the room together would be an action that could call this REST service after the build and deploy. My question is, does开发者_JAVA百科 a REST activity already exist, or do I need to build it?
Well, I created my own REST client activity. I am sure it has some bugs, but it works for me.
using System;
using System.Activities;
using System.Net;
using Microsoft.TeamFoundation.Build.Client;
namespace Custom.BuildActivities
{
[BuildExtension(HostEnvironmentOption.Agent)]
[BuildActivity(HostEnvironmentOption.All)]
public sealed class RESTClient : CodeActivity
{
public InArgument<Uri> Url { get; set; }
public InArgument<string> Verb { get; set; }
public OutArgument<HttpStatusCode> StatusCode { get; set; }
public OutArgument<string> ErrorMessage { get; set; }
protected override void Execute(CodeActivityContext context)
{
try
{
Uri url = context.GetValue(this.Url);
string verb = context.GetValue(this.Verb);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = verb;
HttpWebResponse response = null;
try
{
response = request.GetResponse() as HttpWebResponse;
context.SetValue(this.StatusCode, response.StatusCode);
}
catch (WebException webEx)
{
if (webEx.Response != null)
{
context.SetValue(this.StatusCode, ((HttpWebResponse)webEx.Response).StatusCode);
}
else
{
context.SetValue(this.StatusCode, HttpStatusCode.BadRequest);
}
}
}
catch (Exception ex)
{
context.SetValue(this.ErrorMessage, ex.ToString());
}
}
}
}
精彩评论