|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Globalization; |
| 4 | +using System.IO; |
| 5 | +using System.IO.Compression; |
| 6 | +using System.Linq; |
| 7 | +using System.Net; |
| 8 | +using System.Net.Http; |
| 9 | +using System.Net.Http.Headers; |
| 10 | +using System.Threading; |
| 11 | +using System.Threading.Tasks; |
| 12 | +using GitHub.Services.Common; |
| 13 | +using GitHub.Services.Common.Diagnostics; |
| 14 | +using GitHub.Services.WebApi; |
| 15 | +using Newtonsoft.Json; |
| 16 | + |
| 17 | +namespace GitHub.DistributedTask.WebApi |
| 18 | +{ |
| 19 | + [ResourceArea(TaskResourceIds.AreaId)] |
| 20 | + public class ActionsRunServerHttpClient : TaskAgentHttpClient |
| 21 | + { |
| 22 | + private static readonly JsonSerializerSettings s_serializerSettings; |
| 23 | + |
| 24 | + static ActionsRunServerHttpClient() |
| 25 | + { |
| 26 | + s_serializerSettings = new VssJsonMediaTypeFormatter().SerializerSettings; |
| 27 | + s_serializerSettings.DateParseHandling = DateParseHandling.None; |
| 28 | + s_serializerSettings.FloatParseHandling = FloatParseHandling.Double; |
| 29 | + } |
| 30 | + |
| 31 | + public ActionsRunServerHttpClient( |
| 32 | + Uri baseUrl, |
| 33 | + VssCredentials credentials) |
| 34 | + : base(baseUrl, credentials) |
| 35 | + { |
| 36 | + } |
| 37 | + |
| 38 | + public ActionsRunServerHttpClient( |
| 39 | + Uri baseUrl, |
| 40 | + VssCredentials credentials, |
| 41 | + VssHttpRequestSettings settings) |
| 42 | + : base(baseUrl, credentials, settings) |
| 43 | + { |
| 44 | + } |
| 45 | + |
| 46 | + public ActionsRunServerHttpClient( |
| 47 | + Uri baseUrl, |
| 48 | + VssCredentials credentials, |
| 49 | + params DelegatingHandler[] handlers) |
| 50 | + : base(baseUrl, credentials, handlers) |
| 51 | + { |
| 52 | + } |
| 53 | + |
| 54 | + public ActionsRunServerHttpClient( |
| 55 | + Uri baseUrl, |
| 56 | + VssCredentials credentials, |
| 57 | + VssHttpRequestSettings settings, |
| 58 | + params DelegatingHandler[] handlers) |
| 59 | + : base(baseUrl, credentials, settings, handlers) |
| 60 | + { |
| 61 | + } |
| 62 | + |
| 63 | + public ActionsRunServerHttpClient( |
| 64 | + Uri baseUrl, |
| 65 | + HttpMessageHandler pipeline, |
| 66 | + Boolean disposeHandler) |
| 67 | + : base(baseUrl, pipeline, disposeHandler) |
| 68 | + { |
| 69 | + } |
| 70 | + |
| 71 | + public Task<Pipelines.AgentJobRequestMessage> GetJobMessageAsync( |
| 72 | + string messageId, |
| 73 | + object userState = null, |
| 74 | + CancellationToken cancellationToken = default) |
| 75 | + { |
| 76 | + HttpMethod httpMethod = new HttpMethod("GET"); |
| 77 | + Guid locationId = new Guid("25adab70-1379-4186-be8e-b643061ebe3a"); |
| 78 | + object routeValues = new { messageId = messageId }; |
| 79 | + |
| 80 | + return SendAsync<Pipelines.AgentJobRequestMessage>( |
| 81 | + httpMethod, |
| 82 | + locationId, |
| 83 | + routeValues: routeValues, |
| 84 | + version: new ApiResourceVersion(6.0, 1), |
| 85 | + userState: userState, |
| 86 | + cancellationToken: cancellationToken); |
| 87 | + } |
| 88 | + |
| 89 | + protected override async Task<T> ReadJsonContentAsync<T>(HttpResponseMessage response, CancellationToken cancellationToken = default(CancellationToken)) |
| 90 | + { |
| 91 | + var json = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); |
| 92 | + return JsonConvert.DeserializeObject<T>(json, s_serializerSettings); |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments