2011-07-15 2 views
2

私は、各ビルドの後にパッケージを取得するNuGetリポジトリを持っています。私は指定されたパッケージよりも低いすべてのパッケージを削除するNuGetサーバーの拡張機能であるRESTサービスを持っています。部屋を結びつける敷物は、ビルドとデプロイ後にこのRESTサービスを呼び出すアクションです。私の質問は、RESTアクティビティは既に存在するのですか、それともビルドする必要がありますか?ビルド、カスタム、または缶詰後にRESTサービスを呼び出すTFSワークフローアクティビティ?

答えて

1

まあ、私は自分自身のRESTクライアントアクティビティを作成しました。私にはいくつかのバグがあると確信していますが、それは私のために働きます。

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()); 
      } 
     } 
    } 
} 
関連する問題