答案 0 :(得分:1)
您可以使用REST API来获取状态值。请参阅Get a list of subscriptions
例如PowerShell:
Param(
[string]$baseUrl = "https://{account}.visualstudio.com/DefaultCollection/_apis/hooks/subscriptions",
[string]$user = "username",
[string]$token = "password"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$response = (Invoke-RestMethod -Uri $baseUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
$hooks = $response.value
$states = @()
foreach($hook in $hooks){
$customObject = new-object PSObject -property @{
"consumer" = $hook.consumerId
"id" = $hook.id
"eventType" = $hook.eventType
"state" = $hook.status
}
$states += $customObject
}
$states | Select `
consumer,
id,
eventType,
state
要使用C#调用REST API,可以引用以下线程:How do I make calls to a REST api using c#?
您还可以参考以下示例:
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace GetBuildsREST
{
class Program
{
public static void Main()
{
Task t = GetBuildsREST();
Task.WaitAll(new Task[] { t });
}
private static async Task GetBuildsREST()
{
try
{
var username = "domain\\user";
var password = "password";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", username, password))));
using (HttpResponseMessage response = client.GetAsync(
"https://{account}.visualstudio.com/DefaultCollection/_apis/hooks/subscriptions?api-version=2.0").Result)
{
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
//Do somthing to get the vale of the state....
//var obj = JObject.Parse(responseBody);
//var state = (string)obj["value"]["status"];
//or var state = (string)obj.SelectToken("value.status");
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}