| | 1 | | // <auto-generated> |
| | 2 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 3 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 4 | | // license information. |
| | 5 | | // |
| | 6 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 7 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 8 | | // regenerated. |
| | 9 | | // </auto-generated> |
| | 10 | |
|
| | 11 | | namespace Microsoft.Azure.Batch.Protocol |
| | 12 | | { |
| | 13 | | using Microsoft.Rest; |
| | 14 | | using Microsoft.Rest.Azure; |
| | 15 | | using Microsoft.Rest.Serialization; |
| | 16 | | using Models; |
| | 17 | | using Newtonsoft.Json; |
| | 18 | | using System.Collections; |
| | 19 | | using System.Collections.Generic; |
| | 20 | | using System.Linq; |
| | 21 | | using System.Net; |
| | 22 | | using System.Net.Http; |
| | 23 | | using System.Threading; |
| | 24 | | using System.Threading.Tasks; |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// JobOperations operations. |
| | 28 | | /// </summary> |
| | 29 | | internal partial class JobOperations : IServiceOperations<BatchServiceClient>, IJobOperations |
| | 30 | | { |
| | 31 | | /// <summary> |
| | 32 | | /// Initializes a new instance of the JobOperations class. |
| | 33 | | /// </summary> |
| | 34 | | /// <param name='client'> |
| | 35 | | /// Reference to the service client. |
| | 36 | | /// </param> |
| | 37 | | /// <exception cref="System.ArgumentNullException"> |
| | 38 | | /// Thrown when a required parameter is null |
| | 39 | | /// </exception> |
| 148 | 40 | | internal JobOperations(BatchServiceClient client) |
| | 41 | | { |
| 148 | 42 | | if (client == null) |
| | 43 | | { |
| 0 | 44 | | throw new System.ArgumentNullException("client"); |
| | 45 | | } |
| 148 | 46 | | Client = client; |
| 148 | 47 | | } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Gets a reference to the BatchServiceClient |
| | 51 | | /// </summary> |
| 141 | 52 | | public BatchServiceClient Client { get; private set; } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Gets lifetime summary statistics for all of the Jobs in the specified |
| | 56 | | /// Account. |
| | 57 | | /// </summary> |
| | 58 | | /// <remarks> |
| | 59 | | /// Statistics are aggregated across all Jobs that have ever existed in the |
| | 60 | | /// Account, from Account creation to the last update time of the statistics. |
| | 61 | | /// The statistics may not be immediately available. The Batch service performs |
| | 62 | | /// periodic roll-up of statistics. The typical delay is about 30 minutes. |
| | 63 | | /// </remarks> |
| | 64 | | /// <param name='jobGetAllLifetimeStatisticsOptions'> |
| | 65 | | /// Additional parameters for the operation |
| | 66 | | /// </param> |
| | 67 | | /// <param name='customHeaders'> |
| | 68 | | /// Headers that will be added to request. |
| | 69 | | /// </param> |
| | 70 | | /// <param name='cancellationToken'> |
| | 71 | | /// The cancellation token. |
| | 72 | | /// </param> |
| | 73 | | /// <exception cref="BatchErrorException"> |
| | 74 | | /// Thrown when the operation returned an invalid status code |
| | 75 | | /// </exception> |
| | 76 | | /// <exception cref="SerializationException"> |
| | 77 | | /// Thrown when unable to deserialize the response |
| | 78 | | /// </exception> |
| | 79 | | /// <exception cref="ValidationException"> |
| | 80 | | /// Thrown when a required parameter is null |
| | 81 | | /// </exception> |
| | 82 | | /// <exception cref="System.ArgumentNullException"> |
| | 83 | | /// Thrown when a required parameter is null |
| | 84 | | /// </exception> |
| | 85 | | /// <return> |
| | 86 | | /// A response object containing the response body and response headers. |
| | 87 | | /// </return> |
| | 88 | | public async Task<AzureOperationResponse<JobStatistics,JobGetAllLifetimeStatisticsHeaders>> GetAllLifetimeStatis |
| | 89 | | { |
| 0 | 90 | | if (Client.BatchUrl == null) |
| | 91 | | { |
| 0 | 92 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 93 | | } |
| 0 | 94 | | if (Client.ApiVersion == null) |
| | 95 | | { |
| 0 | 96 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 97 | | } |
| 0 | 98 | | int? timeout = default(int?); |
| 0 | 99 | | if (jobGetAllLifetimeStatisticsOptions != null) |
| | 100 | | { |
| 0 | 101 | | timeout = jobGetAllLifetimeStatisticsOptions.Timeout; |
| | 102 | | } |
| 0 | 103 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 104 | | if (jobGetAllLifetimeStatisticsOptions != null) |
| | 105 | | { |
| 0 | 106 | | clientRequestId = jobGetAllLifetimeStatisticsOptions.ClientRequestId; |
| | 107 | | } |
| 0 | 108 | | bool? returnClientRequestId = default(bool?); |
| 0 | 109 | | if (jobGetAllLifetimeStatisticsOptions != null) |
| | 110 | | { |
| 0 | 111 | | returnClientRequestId = jobGetAllLifetimeStatisticsOptions.ReturnClientRequestId; |
| | 112 | | } |
| 0 | 113 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 114 | | if (jobGetAllLifetimeStatisticsOptions != null) |
| | 115 | | { |
| 0 | 116 | | ocpDate = jobGetAllLifetimeStatisticsOptions.OcpDate; |
| | 117 | | } |
| | 118 | | // Tracing |
| 0 | 119 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 120 | | string _invocationId = null; |
| 0 | 121 | | if (_shouldTrace) |
| | 122 | | { |
| 0 | 123 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 124 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 125 | | tracingParameters.Add("timeout", timeout); |
| 0 | 126 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 127 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 128 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 129 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 130 | | ServiceClientTracing.Enter(_invocationId, this, "GetAllLifetimeStatistics", tracingParameters); |
| | 131 | | } |
| | 132 | | // Construct URL |
| 0 | 133 | | var _baseUrl = Client.BaseUri; |
| 0 | 134 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "lifetimejobstats"; |
| 0 | 135 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 136 | | List<string> _queryParameters = new List<string>(); |
| 0 | 137 | | if (Client.ApiVersion != null) |
| | 138 | | { |
| 0 | 139 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 140 | | } |
| 0 | 141 | | if (timeout != null) |
| | 142 | | { |
| 0 | 143 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 144 | | } |
| 0 | 145 | | if (_queryParameters.Count > 0) |
| | 146 | | { |
| 0 | 147 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 148 | | } |
| | 149 | | // Create HTTP transport objects |
| 0 | 150 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 151 | | HttpResponseMessage _httpResponse = null; |
| 0 | 152 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 153 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 154 | | // Set Headers |
| 0 | 155 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 156 | | { |
| 0 | 157 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 158 | | } |
| 0 | 159 | | if (Client.AcceptLanguage != null) |
| | 160 | | { |
| 0 | 161 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 162 | | { |
| 0 | 163 | | _httpRequest.Headers.Remove("accept-language"); |
| | 164 | | } |
| 0 | 165 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 166 | | } |
| 0 | 167 | | if (clientRequestId != null) |
| | 168 | | { |
| 0 | 169 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 170 | | { |
| 0 | 171 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 172 | | } |
| 0 | 173 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 174 | | } |
| 0 | 175 | | if (returnClientRequestId != null) |
| | 176 | | { |
| 0 | 177 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 178 | | { |
| 0 | 179 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 180 | | } |
| 0 | 181 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 182 | | } |
| 0 | 183 | | if (ocpDate != null) |
| | 184 | | { |
| 0 | 185 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 186 | | { |
| 0 | 187 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 188 | | } |
| 0 | 189 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 190 | | } |
| | 191 | |
|
| | 192 | |
|
| 0 | 193 | | if (customHeaders != null) |
| | 194 | | { |
| 0 | 195 | | foreach(var _header in customHeaders) |
| | 196 | | { |
| 0 | 197 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 198 | | { |
| 0 | 199 | | _httpRequest.Headers.Remove(_header.Key); |
| | 200 | | } |
| 0 | 201 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 202 | | } |
| | 203 | | } |
| | 204 | |
|
| | 205 | | // Serialize Request |
| 0 | 206 | | string _requestContent = null; |
| | 207 | | // Set Credentials |
| 0 | 208 | | if (Client.Credentials != null) |
| | 209 | | { |
| 0 | 210 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 211 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 212 | | } |
| | 213 | | // Send Request |
| 0 | 214 | | if (_shouldTrace) |
| | 215 | | { |
| 0 | 216 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 217 | | } |
| 0 | 218 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 219 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 220 | | if (_shouldTrace) |
| | 221 | | { |
| 0 | 222 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 223 | | } |
| 0 | 224 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 225 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 226 | | string _responseContent = null; |
| 0 | 227 | | if ((int)_statusCode != 200) |
| | 228 | | { |
| 0 | 229 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 230 | | try |
| | 231 | | { |
| 0 | 232 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 233 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 234 | | if (_errorBody != null) |
| | 235 | | { |
| 0 | 236 | | ex.Body = _errorBody; |
| | 237 | | } |
| 0 | 238 | | } |
| 0 | 239 | | catch (JsonException) |
| | 240 | | { |
| | 241 | | // Ignore the exception |
| 0 | 242 | | } |
| 0 | 243 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 244 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 245 | | if (_shouldTrace) |
| | 246 | | { |
| 0 | 247 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 248 | | } |
| 0 | 249 | | _httpRequest.Dispose(); |
| 0 | 250 | | if (_httpResponse != null) |
| | 251 | | { |
| 0 | 252 | | _httpResponse.Dispose(); |
| | 253 | | } |
| 0 | 254 | | throw ex; |
| | 255 | | } |
| | 256 | | // Create Result |
| 0 | 257 | | var _result = new AzureOperationResponse<JobStatistics,JobGetAllLifetimeStatisticsHeaders>(); |
| 0 | 258 | | _result.Request = _httpRequest; |
| 0 | 259 | | _result.Response = _httpResponse; |
| 0 | 260 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 261 | | { |
| 0 | 262 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 263 | | } |
| | 264 | | // Deserialize Response |
| 0 | 265 | | if ((int)_statusCode == 200) |
| | 266 | | { |
| 0 | 267 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 268 | | try |
| | 269 | | { |
| 0 | 270 | | _result.Body = SafeJsonConvert.DeserializeObject<JobStatistics>(_responseContent, Client.Deserializa |
| 0 | 271 | | } |
| 0 | 272 | | catch (JsonException ex) |
| | 273 | | { |
| 0 | 274 | | _httpRequest.Dispose(); |
| 0 | 275 | | if (_httpResponse != null) |
| | 276 | | { |
| 0 | 277 | | _httpResponse.Dispose(); |
| | 278 | | } |
| 0 | 279 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 280 | | } |
| | 281 | | } |
| | 282 | | try |
| | 283 | | { |
| 0 | 284 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobGetAllLifetimeStatisticsHeaders>(JsonSeri |
| 0 | 285 | | } |
| 0 | 286 | | catch (JsonException ex) |
| | 287 | | { |
| 0 | 288 | | _httpRequest.Dispose(); |
| 0 | 289 | | if (_httpResponse != null) |
| | 290 | | { |
| 0 | 291 | | _httpResponse.Dispose(); |
| | 292 | | } |
| 0 | 293 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 294 | | } |
| 0 | 295 | | if (_shouldTrace) |
| | 296 | | { |
| 0 | 297 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 298 | | } |
| 0 | 299 | | return _result; |
| 0 | 300 | | } |
| | 301 | |
|
| | 302 | | /// <summary> |
| | 303 | | /// Deletes a Job. |
| | 304 | | /// </summary> |
| | 305 | | /// <remarks> |
| | 306 | | /// Deleting a Job also deletes all Tasks that are part of that Job, and all |
| | 307 | | /// Job statistics. This also overrides the retention period for Task data; |
| | 308 | | /// that is, if the Job contains Tasks which are still retained on Compute |
| | 309 | | /// Nodes, the Batch services deletes those Tasks' working directories and all |
| | 310 | | /// their contents. When a Delete Job request is received, the Batch service |
| | 311 | | /// sets the Job to the deleting state. All update operations on a Job that is |
| | 312 | | /// in deleting state will fail with status code 409 (Conflict), with |
| | 313 | | /// additional information indicating that the Job is being deleted. |
| | 314 | | /// </remarks> |
| | 315 | | /// <param name='jobId'> |
| | 316 | | /// The ID of the Job to delete. |
| | 317 | | /// </param> |
| | 318 | | /// <param name='jobDeleteOptions'> |
| | 319 | | /// Additional parameters for the operation |
| | 320 | | /// </param> |
| | 321 | | /// <param name='customHeaders'> |
| | 322 | | /// Headers that will be added to request. |
| | 323 | | /// </param> |
| | 324 | | /// <param name='cancellationToken'> |
| | 325 | | /// The cancellation token. |
| | 326 | | /// </param> |
| | 327 | | /// <exception cref="BatchErrorException"> |
| | 328 | | /// Thrown when the operation returned an invalid status code |
| | 329 | | /// </exception> |
| | 330 | | /// <exception cref="ValidationException"> |
| | 331 | | /// Thrown when a required parameter is null |
| | 332 | | /// </exception> |
| | 333 | | /// <exception cref="System.ArgumentNullException"> |
| | 334 | | /// Thrown when a required parameter is null |
| | 335 | | /// </exception> |
| | 336 | | /// <return> |
| | 337 | | /// A response object containing the response body and response headers. |
| | 338 | | /// </return> |
| | 339 | | public async Task<AzureOperationHeaderResponse<JobDeleteHeaders>> DeleteWithHttpMessagesAsync(string jobId, JobD |
| | 340 | | { |
| 0 | 341 | | if (Client.BatchUrl == null) |
| | 342 | | { |
| 0 | 343 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 344 | | } |
| 0 | 345 | | if (jobId == null) |
| | 346 | | { |
| 0 | 347 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobId"); |
| | 348 | | } |
| 0 | 349 | | if (Client.ApiVersion == null) |
| | 350 | | { |
| 0 | 351 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 352 | | } |
| 0 | 353 | | int? timeout = default(int?); |
| 0 | 354 | | if (jobDeleteOptions != null) |
| | 355 | | { |
| 0 | 356 | | timeout = jobDeleteOptions.Timeout; |
| | 357 | | } |
| 0 | 358 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 359 | | if (jobDeleteOptions != null) |
| | 360 | | { |
| 0 | 361 | | clientRequestId = jobDeleteOptions.ClientRequestId; |
| | 362 | | } |
| 0 | 363 | | bool? returnClientRequestId = default(bool?); |
| 0 | 364 | | if (jobDeleteOptions != null) |
| | 365 | | { |
| 0 | 366 | | returnClientRequestId = jobDeleteOptions.ReturnClientRequestId; |
| | 367 | | } |
| 0 | 368 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 369 | | if (jobDeleteOptions != null) |
| | 370 | | { |
| 0 | 371 | | ocpDate = jobDeleteOptions.OcpDate; |
| | 372 | | } |
| 0 | 373 | | string ifMatch = default(string); |
| 0 | 374 | | if (jobDeleteOptions != null) |
| | 375 | | { |
| 0 | 376 | | ifMatch = jobDeleteOptions.IfMatch; |
| | 377 | | } |
| 0 | 378 | | string ifNoneMatch = default(string); |
| 0 | 379 | | if (jobDeleteOptions != null) |
| | 380 | | { |
| 0 | 381 | | ifNoneMatch = jobDeleteOptions.IfNoneMatch; |
| | 382 | | } |
| 0 | 383 | | System.DateTime? ifModifiedSince = default(System.DateTime?); |
| 0 | 384 | | if (jobDeleteOptions != null) |
| | 385 | | { |
| 0 | 386 | | ifModifiedSince = jobDeleteOptions.IfModifiedSince; |
| | 387 | | } |
| 0 | 388 | | System.DateTime? ifUnmodifiedSince = default(System.DateTime?); |
| 0 | 389 | | if (jobDeleteOptions != null) |
| | 390 | | { |
| 0 | 391 | | ifUnmodifiedSince = jobDeleteOptions.IfUnmodifiedSince; |
| | 392 | | } |
| | 393 | | // Tracing |
| 0 | 394 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 395 | | string _invocationId = null; |
| 0 | 396 | | if (_shouldTrace) |
| | 397 | | { |
| 0 | 398 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 399 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 400 | | tracingParameters.Add("jobId", jobId); |
| 0 | 401 | | tracingParameters.Add("timeout", timeout); |
| 0 | 402 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 403 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 404 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 405 | | tracingParameters.Add("ifMatch", ifMatch); |
| 0 | 406 | | tracingParameters.Add("ifNoneMatch", ifNoneMatch); |
| 0 | 407 | | tracingParameters.Add("ifModifiedSince", ifModifiedSince); |
| 0 | 408 | | tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince); |
| 0 | 409 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 410 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 411 | | } |
| | 412 | | // Construct URL |
| 0 | 413 | | var _baseUrl = Client.BaseUri; |
| 0 | 414 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}"; |
| 0 | 415 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 416 | | _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId)); |
| 0 | 417 | | List<string> _queryParameters = new List<string>(); |
| 0 | 418 | | if (Client.ApiVersion != null) |
| | 419 | | { |
| 0 | 420 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 421 | | } |
| 0 | 422 | | if (timeout != null) |
| | 423 | | { |
| 0 | 424 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 425 | | } |
| 0 | 426 | | if (_queryParameters.Count > 0) |
| | 427 | | { |
| 0 | 428 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 429 | | } |
| | 430 | | // Create HTTP transport objects |
| 0 | 431 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 432 | | HttpResponseMessage _httpResponse = null; |
| 0 | 433 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 434 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 435 | | // Set Headers |
| 0 | 436 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 437 | | { |
| 0 | 438 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 439 | | } |
| 0 | 440 | | if (Client.AcceptLanguage != null) |
| | 441 | | { |
| 0 | 442 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 443 | | { |
| 0 | 444 | | _httpRequest.Headers.Remove("accept-language"); |
| | 445 | | } |
| 0 | 446 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 447 | | } |
| 0 | 448 | | if (clientRequestId != null) |
| | 449 | | { |
| 0 | 450 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 451 | | { |
| 0 | 452 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 453 | | } |
| 0 | 454 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 455 | | } |
| 0 | 456 | | if (returnClientRequestId != null) |
| | 457 | | { |
| 0 | 458 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 459 | | { |
| 0 | 460 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 461 | | } |
| 0 | 462 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 463 | | } |
| 0 | 464 | | if (ocpDate != null) |
| | 465 | | { |
| 0 | 466 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 467 | | { |
| 0 | 468 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 469 | | } |
| 0 | 470 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 471 | | } |
| 0 | 472 | | if (ifMatch != null) |
| | 473 | | { |
| 0 | 474 | | if (_httpRequest.Headers.Contains("If-Match")) |
| | 475 | | { |
| 0 | 476 | | _httpRequest.Headers.Remove("If-Match"); |
| | 477 | | } |
| 0 | 478 | | _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch); |
| | 479 | | } |
| 0 | 480 | | if (ifNoneMatch != null) |
| | 481 | | { |
| 0 | 482 | | if (_httpRequest.Headers.Contains("If-None-Match")) |
| | 483 | | { |
| 0 | 484 | | _httpRequest.Headers.Remove("If-None-Match"); |
| | 485 | | } |
| 0 | 486 | | _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch); |
| | 487 | | } |
| 0 | 488 | | if (ifModifiedSince != null) |
| | 489 | | { |
| 0 | 490 | | if (_httpRequest.Headers.Contains("If-Modified-Since")) |
| | 491 | | { |
| 0 | 492 | | _httpRequest.Headers.Remove("If-Modified-Since"); |
| | 493 | | } |
| 0 | 494 | | _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi |
| | 495 | | } |
| 0 | 496 | | if (ifUnmodifiedSince != null) |
| | 497 | | { |
| 0 | 498 | | if (_httpRequest.Headers.Contains("If-Unmodified-Since")) |
| | 499 | | { |
| 0 | 500 | | _httpRequest.Headers.Remove("If-Unmodified-Since"); |
| | 501 | | } |
| 0 | 502 | | _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn |
| | 503 | | } |
| | 504 | |
|
| | 505 | |
|
| 0 | 506 | | if (customHeaders != null) |
| | 507 | | { |
| 0 | 508 | | foreach(var _header in customHeaders) |
| | 509 | | { |
| 0 | 510 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 511 | | { |
| 0 | 512 | | _httpRequest.Headers.Remove(_header.Key); |
| | 513 | | } |
| 0 | 514 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 515 | | } |
| | 516 | | } |
| | 517 | |
|
| | 518 | | // Serialize Request |
| 0 | 519 | | string _requestContent = null; |
| | 520 | | // Set Credentials |
| 0 | 521 | | if (Client.Credentials != null) |
| | 522 | | { |
| 0 | 523 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 524 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 525 | | } |
| | 526 | | // Send Request |
| 0 | 527 | | if (_shouldTrace) |
| | 528 | | { |
| 0 | 529 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 530 | | } |
| 0 | 531 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 532 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 533 | | if (_shouldTrace) |
| | 534 | | { |
| 0 | 535 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 536 | | } |
| 0 | 537 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 538 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 539 | | string _responseContent = null; |
| 0 | 540 | | if ((int)_statusCode != 202) |
| | 541 | | { |
| 0 | 542 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 543 | | try |
| | 544 | | { |
| 0 | 545 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 546 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 547 | | if (_errorBody != null) |
| | 548 | | { |
| 0 | 549 | | ex.Body = _errorBody; |
| | 550 | | } |
| 0 | 551 | | } |
| 0 | 552 | | catch (JsonException) |
| | 553 | | { |
| | 554 | | // Ignore the exception |
| 0 | 555 | | } |
| 0 | 556 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 557 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 558 | | if (_shouldTrace) |
| | 559 | | { |
| 0 | 560 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 561 | | } |
| 0 | 562 | | _httpRequest.Dispose(); |
| 0 | 563 | | if (_httpResponse != null) |
| | 564 | | { |
| 0 | 565 | | _httpResponse.Dispose(); |
| | 566 | | } |
| 0 | 567 | | throw ex; |
| | 568 | | } |
| | 569 | | // Create Result |
| 0 | 570 | | var _result = new AzureOperationHeaderResponse<JobDeleteHeaders>(); |
| 0 | 571 | | _result.Request = _httpRequest; |
| 0 | 572 | | _result.Response = _httpResponse; |
| 0 | 573 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 574 | | { |
| 0 | 575 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 576 | | } |
| | 577 | | try |
| | 578 | | { |
| 0 | 579 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobDeleteHeaders>(JsonSerializer.Create(Clie |
| 0 | 580 | | } |
| 0 | 581 | | catch (JsonException ex) |
| | 582 | | { |
| 0 | 583 | | _httpRequest.Dispose(); |
| 0 | 584 | | if (_httpResponse != null) |
| | 585 | | { |
| 0 | 586 | | _httpResponse.Dispose(); |
| | 587 | | } |
| 0 | 588 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 589 | | } |
| 0 | 590 | | if (_shouldTrace) |
| | 591 | | { |
| 0 | 592 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 593 | | } |
| 0 | 594 | | return _result; |
| 0 | 595 | | } |
| | 596 | |
|
| | 597 | | /// <summary> |
| | 598 | | /// Gets information about the specified Job. |
| | 599 | | /// </summary> |
| | 600 | | /// <param name='jobId'> |
| | 601 | | /// The ID of the Job. |
| | 602 | | /// </param> |
| | 603 | | /// <param name='jobGetOptions'> |
| | 604 | | /// Additional parameters for the operation |
| | 605 | | /// </param> |
| | 606 | | /// <param name='customHeaders'> |
| | 607 | | /// Headers that will be added to request. |
| | 608 | | /// </param> |
| | 609 | | /// <param name='cancellationToken'> |
| | 610 | | /// The cancellation token. |
| | 611 | | /// </param> |
| | 612 | | /// <exception cref="BatchErrorException"> |
| | 613 | | /// Thrown when the operation returned an invalid status code |
| | 614 | | /// </exception> |
| | 615 | | /// <exception cref="SerializationException"> |
| | 616 | | /// Thrown when unable to deserialize the response |
| | 617 | | /// </exception> |
| | 618 | | /// <exception cref="ValidationException"> |
| | 619 | | /// Thrown when a required parameter is null |
| | 620 | | /// </exception> |
| | 621 | | /// <exception cref="System.ArgumentNullException"> |
| | 622 | | /// Thrown when a required parameter is null |
| | 623 | | /// </exception> |
| | 624 | | /// <return> |
| | 625 | | /// A response object containing the response body and response headers. |
| | 626 | | /// </return> |
| | 627 | | public async Task<AzureOperationResponse<CloudJob,JobGetHeaders>> GetWithHttpMessagesAsync(string jobId, JobGetO |
| | 628 | | { |
| 1 | 629 | | if (Client.BatchUrl == null) |
| | 630 | | { |
| 0 | 631 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 632 | | } |
| 1 | 633 | | if (jobId == null) |
| | 634 | | { |
| 1 | 635 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobId"); |
| | 636 | | } |
| 0 | 637 | | if (Client.ApiVersion == null) |
| | 638 | | { |
| 0 | 639 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 640 | | } |
| 0 | 641 | | string select = default(string); |
| 0 | 642 | | if (jobGetOptions != null) |
| | 643 | | { |
| 0 | 644 | | select = jobGetOptions.Select; |
| | 645 | | } |
| 0 | 646 | | string expand = default(string); |
| 0 | 647 | | if (jobGetOptions != null) |
| | 648 | | { |
| 0 | 649 | | expand = jobGetOptions.Expand; |
| | 650 | | } |
| 0 | 651 | | int? timeout = default(int?); |
| 0 | 652 | | if (jobGetOptions != null) |
| | 653 | | { |
| 0 | 654 | | timeout = jobGetOptions.Timeout; |
| | 655 | | } |
| 0 | 656 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 657 | | if (jobGetOptions != null) |
| | 658 | | { |
| 0 | 659 | | clientRequestId = jobGetOptions.ClientRequestId; |
| | 660 | | } |
| 0 | 661 | | bool? returnClientRequestId = default(bool?); |
| 0 | 662 | | if (jobGetOptions != null) |
| | 663 | | { |
| 0 | 664 | | returnClientRequestId = jobGetOptions.ReturnClientRequestId; |
| | 665 | | } |
| 0 | 666 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 667 | | if (jobGetOptions != null) |
| | 668 | | { |
| 0 | 669 | | ocpDate = jobGetOptions.OcpDate; |
| | 670 | | } |
| 0 | 671 | | string ifMatch = default(string); |
| 0 | 672 | | if (jobGetOptions != null) |
| | 673 | | { |
| 0 | 674 | | ifMatch = jobGetOptions.IfMatch; |
| | 675 | | } |
| 0 | 676 | | string ifNoneMatch = default(string); |
| 0 | 677 | | if (jobGetOptions != null) |
| | 678 | | { |
| 0 | 679 | | ifNoneMatch = jobGetOptions.IfNoneMatch; |
| | 680 | | } |
| 0 | 681 | | System.DateTime? ifModifiedSince = default(System.DateTime?); |
| 0 | 682 | | if (jobGetOptions != null) |
| | 683 | | { |
| 0 | 684 | | ifModifiedSince = jobGetOptions.IfModifiedSince; |
| | 685 | | } |
| 0 | 686 | | System.DateTime? ifUnmodifiedSince = default(System.DateTime?); |
| 0 | 687 | | if (jobGetOptions != null) |
| | 688 | | { |
| 0 | 689 | | ifUnmodifiedSince = jobGetOptions.IfUnmodifiedSince; |
| | 690 | | } |
| | 691 | | // Tracing |
| 0 | 692 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 693 | | string _invocationId = null; |
| 0 | 694 | | if (_shouldTrace) |
| | 695 | | { |
| 0 | 696 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 697 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 698 | | tracingParameters.Add("jobId", jobId); |
| 0 | 699 | | tracingParameters.Add("select", select); |
| 0 | 700 | | tracingParameters.Add("expand", expand); |
| 0 | 701 | | tracingParameters.Add("timeout", timeout); |
| 0 | 702 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 703 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 704 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 705 | | tracingParameters.Add("ifMatch", ifMatch); |
| 0 | 706 | | tracingParameters.Add("ifNoneMatch", ifNoneMatch); |
| 0 | 707 | | tracingParameters.Add("ifModifiedSince", ifModifiedSince); |
| 0 | 708 | | tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince); |
| 0 | 709 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 710 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 711 | | } |
| | 712 | | // Construct URL |
| 0 | 713 | | var _baseUrl = Client.BaseUri; |
| 0 | 714 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}"; |
| 0 | 715 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 716 | | _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId)); |
| 0 | 717 | | List<string> _queryParameters = new List<string>(); |
| 0 | 718 | | if (Client.ApiVersion != null) |
| | 719 | | { |
| 0 | 720 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 721 | | } |
| 0 | 722 | | if (select != null) |
| | 723 | | { |
| 0 | 724 | | _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select))); |
| | 725 | | } |
| 0 | 726 | | if (expand != null) |
| | 727 | | { |
| 0 | 728 | | _queryParameters.Add(string.Format("$expand={0}", System.Uri.EscapeDataString(expand))); |
| | 729 | | } |
| 0 | 730 | | if (timeout != null) |
| | 731 | | { |
| 0 | 732 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 733 | | } |
| 0 | 734 | | if (_queryParameters.Count > 0) |
| | 735 | | { |
| 0 | 736 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 737 | | } |
| | 738 | | // Create HTTP transport objects |
| 0 | 739 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 740 | | HttpResponseMessage _httpResponse = null; |
| 0 | 741 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 742 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 743 | | // Set Headers |
| 0 | 744 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 745 | | { |
| 0 | 746 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 747 | | } |
| 0 | 748 | | if (Client.AcceptLanguage != null) |
| | 749 | | { |
| 0 | 750 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 751 | | { |
| 0 | 752 | | _httpRequest.Headers.Remove("accept-language"); |
| | 753 | | } |
| 0 | 754 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 755 | | } |
| 0 | 756 | | if (clientRequestId != null) |
| | 757 | | { |
| 0 | 758 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 759 | | { |
| 0 | 760 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 761 | | } |
| 0 | 762 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 763 | | } |
| 0 | 764 | | if (returnClientRequestId != null) |
| | 765 | | { |
| 0 | 766 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 767 | | { |
| 0 | 768 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 769 | | } |
| 0 | 770 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 771 | | } |
| 0 | 772 | | if (ocpDate != null) |
| | 773 | | { |
| 0 | 774 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 775 | | { |
| 0 | 776 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 777 | | } |
| 0 | 778 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 779 | | } |
| 0 | 780 | | if (ifMatch != null) |
| | 781 | | { |
| 0 | 782 | | if (_httpRequest.Headers.Contains("If-Match")) |
| | 783 | | { |
| 0 | 784 | | _httpRequest.Headers.Remove("If-Match"); |
| | 785 | | } |
| 0 | 786 | | _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch); |
| | 787 | | } |
| 0 | 788 | | if (ifNoneMatch != null) |
| | 789 | | { |
| 0 | 790 | | if (_httpRequest.Headers.Contains("If-None-Match")) |
| | 791 | | { |
| 0 | 792 | | _httpRequest.Headers.Remove("If-None-Match"); |
| | 793 | | } |
| 0 | 794 | | _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch); |
| | 795 | | } |
| 0 | 796 | | if (ifModifiedSince != null) |
| | 797 | | { |
| 0 | 798 | | if (_httpRequest.Headers.Contains("If-Modified-Since")) |
| | 799 | | { |
| 0 | 800 | | _httpRequest.Headers.Remove("If-Modified-Since"); |
| | 801 | | } |
| 0 | 802 | | _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi |
| | 803 | | } |
| 0 | 804 | | if (ifUnmodifiedSince != null) |
| | 805 | | { |
| 0 | 806 | | if (_httpRequest.Headers.Contains("If-Unmodified-Since")) |
| | 807 | | { |
| 0 | 808 | | _httpRequest.Headers.Remove("If-Unmodified-Since"); |
| | 809 | | } |
| 0 | 810 | | _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn |
| | 811 | | } |
| | 812 | |
|
| | 813 | |
|
| 0 | 814 | | if (customHeaders != null) |
| | 815 | | { |
| 0 | 816 | | foreach(var _header in customHeaders) |
| | 817 | | { |
| 0 | 818 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 819 | | { |
| 0 | 820 | | _httpRequest.Headers.Remove(_header.Key); |
| | 821 | | } |
| 0 | 822 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 823 | | } |
| | 824 | | } |
| | 825 | |
|
| | 826 | | // Serialize Request |
| 0 | 827 | | string _requestContent = null; |
| | 828 | | // Set Credentials |
| 0 | 829 | | if (Client.Credentials != null) |
| | 830 | | { |
| 0 | 831 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 832 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 833 | | } |
| | 834 | | // Send Request |
| 0 | 835 | | if (_shouldTrace) |
| | 836 | | { |
| 0 | 837 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 838 | | } |
| 0 | 839 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 840 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 841 | | if (_shouldTrace) |
| | 842 | | { |
| 0 | 843 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 844 | | } |
| 0 | 845 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 846 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 847 | | string _responseContent = null; |
| 0 | 848 | | if ((int)_statusCode != 200) |
| | 849 | | { |
| 0 | 850 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 851 | | try |
| | 852 | | { |
| 0 | 853 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 854 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 855 | | if (_errorBody != null) |
| | 856 | | { |
| 0 | 857 | | ex.Body = _errorBody; |
| | 858 | | } |
| 0 | 859 | | } |
| 0 | 860 | | catch (JsonException) |
| | 861 | | { |
| | 862 | | // Ignore the exception |
| 0 | 863 | | } |
| 0 | 864 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 865 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 866 | | if (_shouldTrace) |
| | 867 | | { |
| 0 | 868 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 869 | | } |
| 0 | 870 | | _httpRequest.Dispose(); |
| 0 | 871 | | if (_httpResponse != null) |
| | 872 | | { |
| 0 | 873 | | _httpResponse.Dispose(); |
| | 874 | | } |
| 0 | 875 | | throw ex; |
| | 876 | | } |
| | 877 | | // Create Result |
| 0 | 878 | | var _result = new AzureOperationResponse<CloudJob,JobGetHeaders>(); |
| 0 | 879 | | _result.Request = _httpRequest; |
| 0 | 880 | | _result.Response = _httpResponse; |
| 0 | 881 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 882 | | { |
| 0 | 883 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 884 | | } |
| | 885 | | // Deserialize Response |
| 0 | 886 | | if ((int)_statusCode == 200) |
| | 887 | | { |
| 0 | 888 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 889 | | try |
| | 890 | | { |
| 0 | 891 | | _result.Body = SafeJsonConvert.DeserializeObject<CloudJob>(_responseContent, Client.DeserializationS |
| 0 | 892 | | } |
| 0 | 893 | | catch (JsonException ex) |
| | 894 | | { |
| 0 | 895 | | _httpRequest.Dispose(); |
| 0 | 896 | | if (_httpResponse != null) |
| | 897 | | { |
| 0 | 898 | | _httpResponse.Dispose(); |
| | 899 | | } |
| 0 | 900 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 901 | | } |
| | 902 | | } |
| | 903 | | try |
| | 904 | | { |
| 0 | 905 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobGetHeaders>(JsonSerializer.Create(Client. |
| 0 | 906 | | } |
| 0 | 907 | | catch (JsonException ex) |
| | 908 | | { |
| 0 | 909 | | _httpRequest.Dispose(); |
| 0 | 910 | | if (_httpResponse != null) |
| | 911 | | { |
| 0 | 912 | | _httpResponse.Dispose(); |
| | 913 | | } |
| 0 | 914 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 915 | | } |
| 0 | 916 | | if (_shouldTrace) |
| | 917 | | { |
| 0 | 918 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 919 | | } |
| 0 | 920 | | return _result; |
| 0 | 921 | | } |
| | 922 | |
|
| | 923 | | /// <summary> |
| | 924 | | /// Updates the properties of the specified Job. |
| | 925 | | /// </summary> |
| | 926 | | /// <remarks> |
| | 927 | | /// This replaces only the Job properties specified in the request. For |
| | 928 | | /// example, if the Job has constraints, and a request does not specify the |
| | 929 | | /// constraints element, then the Job keeps the existing constraints. |
| | 930 | | /// </remarks> |
| | 931 | | /// <param name='jobId'> |
| | 932 | | /// The ID of the Job whose properties you want to update. |
| | 933 | | /// </param> |
| | 934 | | /// <param name='jobPatchParameter'> |
| | 935 | | /// The parameters for the request. |
| | 936 | | /// </param> |
| | 937 | | /// <param name='jobPatchOptions'> |
| | 938 | | /// Additional parameters for the operation |
| | 939 | | /// </param> |
| | 940 | | /// <param name='customHeaders'> |
| | 941 | | /// Headers that will be added to request. |
| | 942 | | /// </param> |
| | 943 | | /// <param name='cancellationToken'> |
| | 944 | | /// The cancellation token. |
| | 945 | | /// </param> |
| | 946 | | /// <exception cref="BatchErrorException"> |
| | 947 | | /// Thrown when the operation returned an invalid status code |
| | 948 | | /// </exception> |
| | 949 | | /// <exception cref="ValidationException"> |
| | 950 | | /// Thrown when a required parameter is null |
| | 951 | | /// </exception> |
| | 952 | | /// <exception cref="System.ArgumentNullException"> |
| | 953 | | /// Thrown when a required parameter is null |
| | 954 | | /// </exception> |
| | 955 | | /// <return> |
| | 956 | | /// A response object containing the response body and response headers. |
| | 957 | | /// </return> |
| | 958 | | public async Task<AzureOperationHeaderResponse<JobPatchHeaders>> PatchWithHttpMessagesAsync(string jobId, JobPat |
| | 959 | | { |
| 0 | 960 | | if (Client.BatchUrl == null) |
| | 961 | | { |
| 0 | 962 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 963 | | } |
| 0 | 964 | | if (jobId == null) |
| | 965 | | { |
| 0 | 966 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobId"); |
| | 967 | | } |
| 0 | 968 | | if (jobPatchParameter == null) |
| | 969 | | { |
| 0 | 970 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobPatchParameter"); |
| | 971 | | } |
| 0 | 972 | | if (Client.ApiVersion == null) |
| | 973 | | { |
| 0 | 974 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 975 | | } |
| 0 | 976 | | int? timeout = default(int?); |
| 0 | 977 | | if (jobPatchOptions != null) |
| | 978 | | { |
| 0 | 979 | | timeout = jobPatchOptions.Timeout; |
| | 980 | | } |
| 0 | 981 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 982 | | if (jobPatchOptions != null) |
| | 983 | | { |
| 0 | 984 | | clientRequestId = jobPatchOptions.ClientRequestId; |
| | 985 | | } |
| 0 | 986 | | bool? returnClientRequestId = default(bool?); |
| 0 | 987 | | if (jobPatchOptions != null) |
| | 988 | | { |
| 0 | 989 | | returnClientRequestId = jobPatchOptions.ReturnClientRequestId; |
| | 990 | | } |
| 0 | 991 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 992 | | if (jobPatchOptions != null) |
| | 993 | | { |
| 0 | 994 | | ocpDate = jobPatchOptions.OcpDate; |
| | 995 | | } |
| 0 | 996 | | string ifMatch = default(string); |
| 0 | 997 | | if (jobPatchOptions != null) |
| | 998 | | { |
| 0 | 999 | | ifMatch = jobPatchOptions.IfMatch; |
| | 1000 | | } |
| 0 | 1001 | | string ifNoneMatch = default(string); |
| 0 | 1002 | | if (jobPatchOptions != null) |
| | 1003 | | { |
| 0 | 1004 | | ifNoneMatch = jobPatchOptions.IfNoneMatch; |
| | 1005 | | } |
| 0 | 1006 | | System.DateTime? ifModifiedSince = default(System.DateTime?); |
| 0 | 1007 | | if (jobPatchOptions != null) |
| | 1008 | | { |
| 0 | 1009 | | ifModifiedSince = jobPatchOptions.IfModifiedSince; |
| | 1010 | | } |
| 0 | 1011 | | System.DateTime? ifUnmodifiedSince = default(System.DateTime?); |
| 0 | 1012 | | if (jobPatchOptions != null) |
| | 1013 | | { |
| 0 | 1014 | | ifUnmodifiedSince = jobPatchOptions.IfUnmodifiedSince; |
| | 1015 | | } |
| | 1016 | | // Tracing |
| 0 | 1017 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1018 | | string _invocationId = null; |
| 0 | 1019 | | if (_shouldTrace) |
| | 1020 | | { |
| 0 | 1021 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1022 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1023 | | tracingParameters.Add("jobId", jobId); |
| 0 | 1024 | | tracingParameters.Add("jobPatchParameter", jobPatchParameter); |
| 0 | 1025 | | tracingParameters.Add("timeout", timeout); |
| 0 | 1026 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1027 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 1028 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 1029 | | tracingParameters.Add("ifMatch", ifMatch); |
| 0 | 1030 | | tracingParameters.Add("ifNoneMatch", ifNoneMatch); |
| 0 | 1031 | | tracingParameters.Add("ifModifiedSince", ifModifiedSince); |
| 0 | 1032 | | tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince); |
| 0 | 1033 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1034 | | ServiceClientTracing.Enter(_invocationId, this, "Patch", tracingParameters); |
| | 1035 | | } |
| | 1036 | | // Construct URL |
| 0 | 1037 | | var _baseUrl = Client.BaseUri; |
| 0 | 1038 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}"; |
| 0 | 1039 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 1040 | | _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId)); |
| 0 | 1041 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1042 | | if (Client.ApiVersion != null) |
| | 1043 | | { |
| 0 | 1044 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1045 | | } |
| 0 | 1046 | | if (timeout != null) |
| | 1047 | | { |
| 0 | 1048 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 1049 | | } |
| 0 | 1050 | | if (_queryParameters.Count > 0) |
| | 1051 | | { |
| 0 | 1052 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1053 | | } |
| | 1054 | | // Create HTTP transport objects |
| 0 | 1055 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1056 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1057 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 1058 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1059 | | // Set Headers |
| 0 | 1060 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1061 | | { |
| 0 | 1062 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1063 | | } |
| 0 | 1064 | | if (Client.AcceptLanguage != null) |
| | 1065 | | { |
| 0 | 1066 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1067 | | { |
| 0 | 1068 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1069 | | } |
| 0 | 1070 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1071 | | } |
| 0 | 1072 | | if (clientRequestId != null) |
| | 1073 | | { |
| 0 | 1074 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1075 | | { |
| 0 | 1076 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1077 | | } |
| 0 | 1078 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 1079 | | } |
| 0 | 1080 | | if (returnClientRequestId != null) |
| | 1081 | | { |
| 0 | 1082 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 1083 | | { |
| 0 | 1084 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 1085 | | } |
| 0 | 1086 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 1087 | | } |
| 0 | 1088 | | if (ocpDate != null) |
| | 1089 | | { |
| 0 | 1090 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 1091 | | { |
| 0 | 1092 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 1093 | | } |
| 0 | 1094 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 1095 | | } |
| 0 | 1096 | | if (ifMatch != null) |
| | 1097 | | { |
| 0 | 1098 | | if (_httpRequest.Headers.Contains("If-Match")) |
| | 1099 | | { |
| 0 | 1100 | | _httpRequest.Headers.Remove("If-Match"); |
| | 1101 | | } |
| 0 | 1102 | | _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch); |
| | 1103 | | } |
| 0 | 1104 | | if (ifNoneMatch != null) |
| | 1105 | | { |
| 0 | 1106 | | if (_httpRequest.Headers.Contains("If-None-Match")) |
| | 1107 | | { |
| 0 | 1108 | | _httpRequest.Headers.Remove("If-None-Match"); |
| | 1109 | | } |
| 0 | 1110 | | _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch); |
| | 1111 | | } |
| 0 | 1112 | | if (ifModifiedSince != null) |
| | 1113 | | { |
| 0 | 1114 | | if (_httpRequest.Headers.Contains("If-Modified-Since")) |
| | 1115 | | { |
| 0 | 1116 | | _httpRequest.Headers.Remove("If-Modified-Since"); |
| | 1117 | | } |
| 0 | 1118 | | _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi |
| | 1119 | | } |
| 0 | 1120 | | if (ifUnmodifiedSince != null) |
| | 1121 | | { |
| 0 | 1122 | | if (_httpRequest.Headers.Contains("If-Unmodified-Since")) |
| | 1123 | | { |
| 0 | 1124 | | _httpRequest.Headers.Remove("If-Unmodified-Since"); |
| | 1125 | | } |
| 0 | 1126 | | _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn |
| | 1127 | | } |
| | 1128 | |
|
| | 1129 | |
|
| 0 | 1130 | | if (customHeaders != null) |
| | 1131 | | { |
| 0 | 1132 | | foreach(var _header in customHeaders) |
| | 1133 | | { |
| 0 | 1134 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1135 | | { |
| 0 | 1136 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1137 | | } |
| 0 | 1138 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1139 | | } |
| | 1140 | | } |
| | 1141 | |
|
| | 1142 | | // Serialize Request |
| 0 | 1143 | | string _requestContent = null; |
| 0 | 1144 | | if(jobPatchParameter != null) |
| | 1145 | | { |
| 0 | 1146 | | _requestContent = SafeJsonConvert.SerializeObject(jobPatchParameter, Client.SerializationSettings); |
| 0 | 1147 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1148 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1149 | | } |
| | 1150 | | // Set Credentials |
| 0 | 1151 | | if (Client.Credentials != null) |
| | 1152 | | { |
| 0 | 1153 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1154 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1155 | | } |
| | 1156 | | // Send Request |
| 0 | 1157 | | if (_shouldTrace) |
| | 1158 | | { |
| 0 | 1159 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1160 | | } |
| 0 | 1161 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1162 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1163 | | if (_shouldTrace) |
| | 1164 | | { |
| 0 | 1165 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1166 | | } |
| 0 | 1167 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1168 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1169 | | string _responseContent = null; |
| 0 | 1170 | | if ((int)_statusCode != 200) |
| | 1171 | | { |
| 0 | 1172 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1173 | | try |
| | 1174 | | { |
| 0 | 1175 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1176 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 1177 | | if (_errorBody != null) |
| | 1178 | | { |
| 0 | 1179 | | ex.Body = _errorBody; |
| | 1180 | | } |
| 0 | 1181 | | } |
| 0 | 1182 | | catch (JsonException) |
| | 1183 | | { |
| | 1184 | | // Ignore the exception |
| 0 | 1185 | | } |
| 0 | 1186 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1187 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1188 | | if (_shouldTrace) |
| | 1189 | | { |
| 0 | 1190 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1191 | | } |
| 0 | 1192 | | _httpRequest.Dispose(); |
| 0 | 1193 | | if (_httpResponse != null) |
| | 1194 | | { |
| 0 | 1195 | | _httpResponse.Dispose(); |
| | 1196 | | } |
| 0 | 1197 | | throw ex; |
| | 1198 | | } |
| | 1199 | | // Create Result |
| 0 | 1200 | | var _result = new AzureOperationHeaderResponse<JobPatchHeaders>(); |
| 0 | 1201 | | _result.Request = _httpRequest; |
| 0 | 1202 | | _result.Response = _httpResponse; |
| 0 | 1203 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1204 | | { |
| 0 | 1205 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1206 | | } |
| | 1207 | | try |
| | 1208 | | { |
| 0 | 1209 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobPatchHeaders>(JsonSerializer.Create(Clien |
| 0 | 1210 | | } |
| 0 | 1211 | | catch (JsonException ex) |
| | 1212 | | { |
| 0 | 1213 | | _httpRequest.Dispose(); |
| 0 | 1214 | | if (_httpResponse != null) |
| | 1215 | | { |
| 0 | 1216 | | _httpResponse.Dispose(); |
| | 1217 | | } |
| 0 | 1218 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1219 | | } |
| 0 | 1220 | | if (_shouldTrace) |
| | 1221 | | { |
| 0 | 1222 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1223 | | } |
| 0 | 1224 | | return _result; |
| 0 | 1225 | | } |
| | 1226 | |
|
| | 1227 | | /// <summary> |
| | 1228 | | /// Updates the properties of the specified Job. |
| | 1229 | | /// </summary> |
| | 1230 | | /// <remarks> |
| | 1231 | | /// This fully replaces all the updatable properties of the Job. For example, |
| | 1232 | | /// if the Job has constraints associated with it and if constraints is not |
| | 1233 | | /// specified with this request, then the Batch service will remove the |
| | 1234 | | /// existing constraints. |
| | 1235 | | /// </remarks> |
| | 1236 | | /// <param name='jobId'> |
| | 1237 | | /// The ID of the Job whose properties you want to update. |
| | 1238 | | /// </param> |
| | 1239 | | /// <param name='jobUpdateParameter'> |
| | 1240 | | /// The parameters for the request. |
| | 1241 | | /// </param> |
| | 1242 | | /// <param name='jobUpdateOptions'> |
| | 1243 | | /// Additional parameters for the operation |
| | 1244 | | /// </param> |
| | 1245 | | /// <param name='customHeaders'> |
| | 1246 | | /// Headers that will be added to request. |
| | 1247 | | /// </param> |
| | 1248 | | /// <param name='cancellationToken'> |
| | 1249 | | /// The cancellation token. |
| | 1250 | | /// </param> |
| | 1251 | | /// <exception cref="BatchErrorException"> |
| | 1252 | | /// Thrown when the operation returned an invalid status code |
| | 1253 | | /// </exception> |
| | 1254 | | /// <exception cref="ValidationException"> |
| | 1255 | | /// Thrown when a required parameter is null |
| | 1256 | | /// </exception> |
| | 1257 | | /// <exception cref="System.ArgumentNullException"> |
| | 1258 | | /// Thrown when a required parameter is null |
| | 1259 | | /// </exception> |
| | 1260 | | /// <return> |
| | 1261 | | /// A response object containing the response body and response headers. |
| | 1262 | | /// </return> |
| | 1263 | | public async Task<AzureOperationHeaderResponse<JobUpdateHeaders>> UpdateWithHttpMessagesAsync(string jobId, JobU |
| | 1264 | | { |
| 0 | 1265 | | if (Client.BatchUrl == null) |
| | 1266 | | { |
| 0 | 1267 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 1268 | | } |
| 0 | 1269 | | if (jobId == null) |
| | 1270 | | { |
| 0 | 1271 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobId"); |
| | 1272 | | } |
| 0 | 1273 | | if (jobUpdateParameter == null) |
| | 1274 | | { |
| 0 | 1275 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobUpdateParameter"); |
| | 1276 | | } |
| 0 | 1277 | | if (Client.ApiVersion == null) |
| | 1278 | | { |
| 0 | 1279 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1280 | | } |
| 0 | 1281 | | int? timeout = default(int?); |
| 0 | 1282 | | if (jobUpdateOptions != null) |
| | 1283 | | { |
| 0 | 1284 | | timeout = jobUpdateOptions.Timeout; |
| | 1285 | | } |
| 0 | 1286 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 1287 | | if (jobUpdateOptions != null) |
| | 1288 | | { |
| 0 | 1289 | | clientRequestId = jobUpdateOptions.ClientRequestId; |
| | 1290 | | } |
| 0 | 1291 | | bool? returnClientRequestId = default(bool?); |
| 0 | 1292 | | if (jobUpdateOptions != null) |
| | 1293 | | { |
| 0 | 1294 | | returnClientRequestId = jobUpdateOptions.ReturnClientRequestId; |
| | 1295 | | } |
| 0 | 1296 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 1297 | | if (jobUpdateOptions != null) |
| | 1298 | | { |
| 0 | 1299 | | ocpDate = jobUpdateOptions.OcpDate; |
| | 1300 | | } |
| 0 | 1301 | | string ifMatch = default(string); |
| 0 | 1302 | | if (jobUpdateOptions != null) |
| | 1303 | | { |
| 0 | 1304 | | ifMatch = jobUpdateOptions.IfMatch; |
| | 1305 | | } |
| 0 | 1306 | | string ifNoneMatch = default(string); |
| 0 | 1307 | | if (jobUpdateOptions != null) |
| | 1308 | | { |
| 0 | 1309 | | ifNoneMatch = jobUpdateOptions.IfNoneMatch; |
| | 1310 | | } |
| 0 | 1311 | | System.DateTime? ifModifiedSince = default(System.DateTime?); |
| 0 | 1312 | | if (jobUpdateOptions != null) |
| | 1313 | | { |
| 0 | 1314 | | ifModifiedSince = jobUpdateOptions.IfModifiedSince; |
| | 1315 | | } |
| 0 | 1316 | | System.DateTime? ifUnmodifiedSince = default(System.DateTime?); |
| 0 | 1317 | | if (jobUpdateOptions != null) |
| | 1318 | | { |
| 0 | 1319 | | ifUnmodifiedSince = jobUpdateOptions.IfUnmodifiedSince; |
| | 1320 | | } |
| | 1321 | | // Tracing |
| 0 | 1322 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1323 | | string _invocationId = null; |
| 0 | 1324 | | if (_shouldTrace) |
| | 1325 | | { |
| 0 | 1326 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1327 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1328 | | tracingParameters.Add("jobId", jobId); |
| 0 | 1329 | | tracingParameters.Add("jobUpdateParameter", jobUpdateParameter); |
| 0 | 1330 | | tracingParameters.Add("timeout", timeout); |
| 0 | 1331 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1332 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 1333 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 1334 | | tracingParameters.Add("ifMatch", ifMatch); |
| 0 | 1335 | | tracingParameters.Add("ifNoneMatch", ifNoneMatch); |
| 0 | 1336 | | tracingParameters.Add("ifModifiedSince", ifModifiedSince); |
| 0 | 1337 | | tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince); |
| 0 | 1338 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1339 | | ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); |
| | 1340 | | } |
| | 1341 | | // Construct URL |
| 0 | 1342 | | var _baseUrl = Client.BaseUri; |
| 0 | 1343 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}"; |
| 0 | 1344 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 1345 | | _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId)); |
| 0 | 1346 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1347 | | if (Client.ApiVersion != null) |
| | 1348 | | { |
| 0 | 1349 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1350 | | } |
| 0 | 1351 | | if (timeout != null) |
| | 1352 | | { |
| 0 | 1353 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 1354 | | } |
| 0 | 1355 | | if (_queryParameters.Count > 0) |
| | 1356 | | { |
| 0 | 1357 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1358 | | } |
| | 1359 | | // Create HTTP transport objects |
| 0 | 1360 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1361 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1362 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 0 | 1363 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1364 | | // Set Headers |
| 0 | 1365 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1366 | | { |
| 0 | 1367 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1368 | | } |
| 0 | 1369 | | if (Client.AcceptLanguage != null) |
| | 1370 | | { |
| 0 | 1371 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1372 | | { |
| 0 | 1373 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1374 | | } |
| 0 | 1375 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1376 | | } |
| 0 | 1377 | | if (clientRequestId != null) |
| | 1378 | | { |
| 0 | 1379 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1380 | | { |
| 0 | 1381 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1382 | | } |
| 0 | 1383 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 1384 | | } |
| 0 | 1385 | | if (returnClientRequestId != null) |
| | 1386 | | { |
| 0 | 1387 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 1388 | | { |
| 0 | 1389 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 1390 | | } |
| 0 | 1391 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 1392 | | } |
| 0 | 1393 | | if (ocpDate != null) |
| | 1394 | | { |
| 0 | 1395 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 1396 | | { |
| 0 | 1397 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 1398 | | } |
| 0 | 1399 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 1400 | | } |
| 0 | 1401 | | if (ifMatch != null) |
| | 1402 | | { |
| 0 | 1403 | | if (_httpRequest.Headers.Contains("If-Match")) |
| | 1404 | | { |
| 0 | 1405 | | _httpRequest.Headers.Remove("If-Match"); |
| | 1406 | | } |
| 0 | 1407 | | _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch); |
| | 1408 | | } |
| 0 | 1409 | | if (ifNoneMatch != null) |
| | 1410 | | { |
| 0 | 1411 | | if (_httpRequest.Headers.Contains("If-None-Match")) |
| | 1412 | | { |
| 0 | 1413 | | _httpRequest.Headers.Remove("If-None-Match"); |
| | 1414 | | } |
| 0 | 1415 | | _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch); |
| | 1416 | | } |
| 0 | 1417 | | if (ifModifiedSince != null) |
| | 1418 | | { |
| 0 | 1419 | | if (_httpRequest.Headers.Contains("If-Modified-Since")) |
| | 1420 | | { |
| 0 | 1421 | | _httpRequest.Headers.Remove("If-Modified-Since"); |
| | 1422 | | } |
| 0 | 1423 | | _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi |
| | 1424 | | } |
| 0 | 1425 | | if (ifUnmodifiedSince != null) |
| | 1426 | | { |
| 0 | 1427 | | if (_httpRequest.Headers.Contains("If-Unmodified-Since")) |
| | 1428 | | { |
| 0 | 1429 | | _httpRequest.Headers.Remove("If-Unmodified-Since"); |
| | 1430 | | } |
| 0 | 1431 | | _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn |
| | 1432 | | } |
| | 1433 | |
|
| | 1434 | |
|
| 0 | 1435 | | if (customHeaders != null) |
| | 1436 | | { |
| 0 | 1437 | | foreach(var _header in customHeaders) |
| | 1438 | | { |
| 0 | 1439 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1440 | | { |
| 0 | 1441 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1442 | | } |
| 0 | 1443 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1444 | | } |
| | 1445 | | } |
| | 1446 | |
|
| | 1447 | | // Serialize Request |
| 0 | 1448 | | string _requestContent = null; |
| 0 | 1449 | | if(jobUpdateParameter != null) |
| | 1450 | | { |
| 0 | 1451 | | _requestContent = SafeJsonConvert.SerializeObject(jobUpdateParameter, Client.SerializationSettings); |
| 0 | 1452 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1453 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1454 | | } |
| | 1455 | | // Set Credentials |
| 0 | 1456 | | if (Client.Credentials != null) |
| | 1457 | | { |
| 0 | 1458 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1459 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1460 | | } |
| | 1461 | | // Send Request |
| 0 | 1462 | | if (_shouldTrace) |
| | 1463 | | { |
| 0 | 1464 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1465 | | } |
| 0 | 1466 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1467 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1468 | | if (_shouldTrace) |
| | 1469 | | { |
| 0 | 1470 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1471 | | } |
| 0 | 1472 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1473 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1474 | | string _responseContent = null; |
| 0 | 1475 | | if ((int)_statusCode != 200) |
| | 1476 | | { |
| 0 | 1477 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1478 | | try |
| | 1479 | | { |
| 0 | 1480 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1481 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 1482 | | if (_errorBody != null) |
| | 1483 | | { |
| 0 | 1484 | | ex.Body = _errorBody; |
| | 1485 | | } |
| 0 | 1486 | | } |
| 0 | 1487 | | catch (JsonException) |
| | 1488 | | { |
| | 1489 | | // Ignore the exception |
| 0 | 1490 | | } |
| 0 | 1491 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1492 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1493 | | if (_shouldTrace) |
| | 1494 | | { |
| 0 | 1495 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1496 | | } |
| 0 | 1497 | | _httpRequest.Dispose(); |
| 0 | 1498 | | if (_httpResponse != null) |
| | 1499 | | { |
| 0 | 1500 | | _httpResponse.Dispose(); |
| | 1501 | | } |
| 0 | 1502 | | throw ex; |
| | 1503 | | } |
| | 1504 | | // Create Result |
| 0 | 1505 | | var _result = new AzureOperationHeaderResponse<JobUpdateHeaders>(); |
| 0 | 1506 | | _result.Request = _httpRequest; |
| 0 | 1507 | | _result.Response = _httpResponse; |
| 0 | 1508 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1509 | | { |
| 0 | 1510 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1511 | | } |
| | 1512 | | try |
| | 1513 | | { |
| 0 | 1514 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobUpdateHeaders>(JsonSerializer.Create(Clie |
| 0 | 1515 | | } |
| 0 | 1516 | | catch (JsonException ex) |
| | 1517 | | { |
| 0 | 1518 | | _httpRequest.Dispose(); |
| 0 | 1519 | | if (_httpResponse != null) |
| | 1520 | | { |
| 0 | 1521 | | _httpResponse.Dispose(); |
| | 1522 | | } |
| 0 | 1523 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1524 | | } |
| 0 | 1525 | | if (_shouldTrace) |
| | 1526 | | { |
| 0 | 1527 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1528 | | } |
| 0 | 1529 | | return _result; |
| 0 | 1530 | | } |
| | 1531 | |
|
| | 1532 | | /// <summary> |
| | 1533 | | /// Disables the specified Job, preventing new Tasks from running. |
| | 1534 | | /// </summary> |
| | 1535 | | /// <remarks> |
| | 1536 | | /// The Batch Service immediately moves the Job to the disabling state. Batch |
| | 1537 | | /// then uses the disableTasks parameter to determine what to do with the |
| | 1538 | | /// currently running Tasks of the Job. The Job remains in the disabling state |
| | 1539 | | /// until the disable operation is completed and all Tasks have been dealt with |
| | 1540 | | /// according to the disableTasks option; the Job then moves to the disabled |
| | 1541 | | /// state. No new Tasks are started under the Job until it moves back to active |
| | 1542 | | /// state. If you try to disable a Job that is in any state other than active, |
| | 1543 | | /// disabling, or disabled, the request fails with status code 409. |
| | 1544 | | /// </remarks> |
| | 1545 | | /// <param name='jobId'> |
| | 1546 | | /// The ID of the Job to disable. |
| | 1547 | | /// </param> |
| | 1548 | | /// <param name='disableTasks'> |
| | 1549 | | /// What to do with active Tasks associated with the Job. Possible values |
| | 1550 | | /// include: 'requeue', 'terminate', 'wait' |
| | 1551 | | /// </param> |
| | 1552 | | /// <param name='jobDisableOptions'> |
| | 1553 | | /// Additional parameters for the operation |
| | 1554 | | /// </param> |
| | 1555 | | /// <param name='customHeaders'> |
| | 1556 | | /// Headers that will be added to request. |
| | 1557 | | /// </param> |
| | 1558 | | /// <param name='cancellationToken'> |
| | 1559 | | /// The cancellation token. |
| | 1560 | | /// </param> |
| | 1561 | | /// <exception cref="BatchErrorException"> |
| | 1562 | | /// Thrown when the operation returned an invalid status code |
| | 1563 | | /// </exception> |
| | 1564 | | /// <exception cref="ValidationException"> |
| | 1565 | | /// Thrown when a required parameter is null |
| | 1566 | | /// </exception> |
| | 1567 | | /// <exception cref="System.ArgumentNullException"> |
| | 1568 | | /// Thrown when a required parameter is null |
| | 1569 | | /// </exception> |
| | 1570 | | /// <return> |
| | 1571 | | /// A response object containing the response body and response headers. |
| | 1572 | | /// </return> |
| | 1573 | | public async Task<AzureOperationHeaderResponse<JobDisableHeaders>> DisableWithHttpMessagesAsync(string jobId, Di |
| | 1574 | | { |
| 0 | 1575 | | if (Client.BatchUrl == null) |
| | 1576 | | { |
| 0 | 1577 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 1578 | | } |
| 0 | 1579 | | if (jobId == null) |
| | 1580 | | { |
| 0 | 1581 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobId"); |
| | 1582 | | } |
| 0 | 1583 | | if (Client.ApiVersion == null) |
| | 1584 | | { |
| 0 | 1585 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1586 | | } |
| 0 | 1587 | | int? timeout = default(int?); |
| 0 | 1588 | | if (jobDisableOptions != null) |
| | 1589 | | { |
| 0 | 1590 | | timeout = jobDisableOptions.Timeout; |
| | 1591 | | } |
| 0 | 1592 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 1593 | | if (jobDisableOptions != null) |
| | 1594 | | { |
| 0 | 1595 | | clientRequestId = jobDisableOptions.ClientRequestId; |
| | 1596 | | } |
| 0 | 1597 | | bool? returnClientRequestId = default(bool?); |
| 0 | 1598 | | if (jobDisableOptions != null) |
| | 1599 | | { |
| 0 | 1600 | | returnClientRequestId = jobDisableOptions.ReturnClientRequestId; |
| | 1601 | | } |
| 0 | 1602 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 1603 | | if (jobDisableOptions != null) |
| | 1604 | | { |
| 0 | 1605 | | ocpDate = jobDisableOptions.OcpDate; |
| | 1606 | | } |
| 0 | 1607 | | string ifMatch = default(string); |
| 0 | 1608 | | if (jobDisableOptions != null) |
| | 1609 | | { |
| 0 | 1610 | | ifMatch = jobDisableOptions.IfMatch; |
| | 1611 | | } |
| 0 | 1612 | | string ifNoneMatch = default(string); |
| 0 | 1613 | | if (jobDisableOptions != null) |
| | 1614 | | { |
| 0 | 1615 | | ifNoneMatch = jobDisableOptions.IfNoneMatch; |
| | 1616 | | } |
| 0 | 1617 | | System.DateTime? ifModifiedSince = default(System.DateTime?); |
| 0 | 1618 | | if (jobDisableOptions != null) |
| | 1619 | | { |
| 0 | 1620 | | ifModifiedSince = jobDisableOptions.IfModifiedSince; |
| | 1621 | | } |
| 0 | 1622 | | System.DateTime? ifUnmodifiedSince = default(System.DateTime?); |
| 0 | 1623 | | if (jobDisableOptions != null) |
| | 1624 | | { |
| 0 | 1625 | | ifUnmodifiedSince = jobDisableOptions.IfUnmodifiedSince; |
| | 1626 | | } |
| 0 | 1627 | | JobDisableParameter jobDisableParameter = new JobDisableParameter(); |
| 0 | 1628 | | jobDisableParameter.DisableTasks = disableTasks; |
| | 1629 | | // Tracing |
| 0 | 1630 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1631 | | string _invocationId = null; |
| 0 | 1632 | | if (_shouldTrace) |
| | 1633 | | { |
| 0 | 1634 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1635 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1636 | | tracingParameters.Add("jobId", jobId); |
| 0 | 1637 | | tracingParameters.Add("timeout", timeout); |
| 0 | 1638 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1639 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 1640 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 1641 | | tracingParameters.Add("ifMatch", ifMatch); |
| 0 | 1642 | | tracingParameters.Add("ifNoneMatch", ifNoneMatch); |
| 0 | 1643 | | tracingParameters.Add("ifModifiedSince", ifModifiedSince); |
| 0 | 1644 | | tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince); |
| 0 | 1645 | | tracingParameters.Add("jobDisableParameter", jobDisableParameter); |
| 0 | 1646 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1647 | | ServiceClientTracing.Enter(_invocationId, this, "Disable", tracingParameters); |
| | 1648 | | } |
| | 1649 | | // Construct URL |
| 0 | 1650 | | var _baseUrl = Client.BaseUri; |
| 0 | 1651 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/disable"; |
| 0 | 1652 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 1653 | | _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId)); |
| 0 | 1654 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1655 | | if (Client.ApiVersion != null) |
| | 1656 | | { |
| 0 | 1657 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1658 | | } |
| 0 | 1659 | | if (timeout != null) |
| | 1660 | | { |
| 0 | 1661 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 1662 | | } |
| 0 | 1663 | | if (_queryParameters.Count > 0) |
| | 1664 | | { |
| 0 | 1665 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1666 | | } |
| | 1667 | | // Create HTTP transport objects |
| 0 | 1668 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1669 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1670 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1671 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1672 | | // Set Headers |
| 0 | 1673 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1674 | | { |
| 0 | 1675 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1676 | | } |
| 0 | 1677 | | if (Client.AcceptLanguage != null) |
| | 1678 | | { |
| 0 | 1679 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1680 | | { |
| 0 | 1681 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1682 | | } |
| 0 | 1683 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1684 | | } |
| 0 | 1685 | | if (clientRequestId != null) |
| | 1686 | | { |
| 0 | 1687 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1688 | | { |
| 0 | 1689 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1690 | | } |
| 0 | 1691 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 1692 | | } |
| 0 | 1693 | | if (returnClientRequestId != null) |
| | 1694 | | { |
| 0 | 1695 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 1696 | | { |
| 0 | 1697 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 1698 | | } |
| 0 | 1699 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 1700 | | } |
| 0 | 1701 | | if (ocpDate != null) |
| | 1702 | | { |
| 0 | 1703 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 1704 | | { |
| 0 | 1705 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 1706 | | } |
| 0 | 1707 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 1708 | | } |
| 0 | 1709 | | if (ifMatch != null) |
| | 1710 | | { |
| 0 | 1711 | | if (_httpRequest.Headers.Contains("If-Match")) |
| | 1712 | | { |
| 0 | 1713 | | _httpRequest.Headers.Remove("If-Match"); |
| | 1714 | | } |
| 0 | 1715 | | _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch); |
| | 1716 | | } |
| 0 | 1717 | | if (ifNoneMatch != null) |
| | 1718 | | { |
| 0 | 1719 | | if (_httpRequest.Headers.Contains("If-None-Match")) |
| | 1720 | | { |
| 0 | 1721 | | _httpRequest.Headers.Remove("If-None-Match"); |
| | 1722 | | } |
| 0 | 1723 | | _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch); |
| | 1724 | | } |
| 0 | 1725 | | if (ifModifiedSince != null) |
| | 1726 | | { |
| 0 | 1727 | | if (_httpRequest.Headers.Contains("If-Modified-Since")) |
| | 1728 | | { |
| 0 | 1729 | | _httpRequest.Headers.Remove("If-Modified-Since"); |
| | 1730 | | } |
| 0 | 1731 | | _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi |
| | 1732 | | } |
| 0 | 1733 | | if (ifUnmodifiedSince != null) |
| | 1734 | | { |
| 0 | 1735 | | if (_httpRequest.Headers.Contains("If-Unmodified-Since")) |
| | 1736 | | { |
| 0 | 1737 | | _httpRequest.Headers.Remove("If-Unmodified-Since"); |
| | 1738 | | } |
| 0 | 1739 | | _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn |
| | 1740 | | } |
| | 1741 | |
|
| | 1742 | |
|
| 0 | 1743 | | if (customHeaders != null) |
| | 1744 | | { |
| 0 | 1745 | | foreach(var _header in customHeaders) |
| | 1746 | | { |
| 0 | 1747 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1748 | | { |
| 0 | 1749 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1750 | | } |
| 0 | 1751 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1752 | | } |
| | 1753 | | } |
| | 1754 | |
|
| | 1755 | | // Serialize Request |
| 0 | 1756 | | string _requestContent = null; |
| 0 | 1757 | | if(jobDisableParameter != null) |
| | 1758 | | { |
| 0 | 1759 | | _requestContent = SafeJsonConvert.SerializeObject(jobDisableParameter, Client.SerializationSettings); |
| 0 | 1760 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1761 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1762 | | } |
| | 1763 | | // Set Credentials |
| 0 | 1764 | | if (Client.Credentials != null) |
| | 1765 | | { |
| 0 | 1766 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1767 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1768 | | } |
| | 1769 | | // Send Request |
| 0 | 1770 | | if (_shouldTrace) |
| | 1771 | | { |
| 0 | 1772 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1773 | | } |
| 0 | 1774 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1775 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1776 | | if (_shouldTrace) |
| | 1777 | | { |
| 0 | 1778 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1779 | | } |
| 0 | 1780 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1781 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1782 | | string _responseContent = null; |
| 0 | 1783 | | if ((int)_statusCode != 202) |
| | 1784 | | { |
| 0 | 1785 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1786 | | try |
| | 1787 | | { |
| 0 | 1788 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1789 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 1790 | | if (_errorBody != null) |
| | 1791 | | { |
| 0 | 1792 | | ex.Body = _errorBody; |
| | 1793 | | } |
| 0 | 1794 | | } |
| 0 | 1795 | | catch (JsonException) |
| | 1796 | | { |
| | 1797 | | // Ignore the exception |
| 0 | 1798 | | } |
| 0 | 1799 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1800 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1801 | | if (_shouldTrace) |
| | 1802 | | { |
| 0 | 1803 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1804 | | } |
| 0 | 1805 | | _httpRequest.Dispose(); |
| 0 | 1806 | | if (_httpResponse != null) |
| | 1807 | | { |
| 0 | 1808 | | _httpResponse.Dispose(); |
| | 1809 | | } |
| 0 | 1810 | | throw ex; |
| | 1811 | | } |
| | 1812 | | // Create Result |
| 0 | 1813 | | var _result = new AzureOperationHeaderResponse<JobDisableHeaders>(); |
| 0 | 1814 | | _result.Request = _httpRequest; |
| 0 | 1815 | | _result.Response = _httpResponse; |
| 0 | 1816 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1817 | | { |
| 0 | 1818 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1819 | | } |
| | 1820 | | try |
| | 1821 | | { |
| 0 | 1822 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobDisableHeaders>(JsonSerializer.Create(Cli |
| 0 | 1823 | | } |
| 0 | 1824 | | catch (JsonException ex) |
| | 1825 | | { |
| 0 | 1826 | | _httpRequest.Dispose(); |
| 0 | 1827 | | if (_httpResponse != null) |
| | 1828 | | { |
| 0 | 1829 | | _httpResponse.Dispose(); |
| | 1830 | | } |
| 0 | 1831 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1832 | | } |
| 0 | 1833 | | if (_shouldTrace) |
| | 1834 | | { |
| 0 | 1835 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1836 | | } |
| 0 | 1837 | | return _result; |
| 0 | 1838 | | } |
| | 1839 | |
|
| | 1840 | | /// <summary> |
| | 1841 | | /// Enables the specified Job, allowing new Tasks to run. |
| | 1842 | | /// </summary> |
| | 1843 | | /// <remarks> |
| | 1844 | | /// When you call this API, the Batch service sets a disabled Job to the |
| | 1845 | | /// enabling state. After the this operation is completed, the Job moves to the |
| | 1846 | | /// active state, and scheduling of new Tasks under the Job resumes. The Batch |
| | 1847 | | /// service does not allow a Task to remain in the active state for more than |
| | 1848 | | /// 180 days. Therefore, if you enable a Job containing active Tasks which were |
| | 1849 | | /// added more than 180 days ago, those Tasks will not run. |
| | 1850 | | /// </remarks> |
| | 1851 | | /// <param name='jobId'> |
| | 1852 | | /// The ID of the Job to enable. |
| | 1853 | | /// </param> |
| | 1854 | | /// <param name='jobEnableOptions'> |
| | 1855 | | /// Additional parameters for the operation |
| | 1856 | | /// </param> |
| | 1857 | | /// <param name='customHeaders'> |
| | 1858 | | /// Headers that will be added to request. |
| | 1859 | | /// </param> |
| | 1860 | | /// <param name='cancellationToken'> |
| | 1861 | | /// The cancellation token. |
| | 1862 | | /// </param> |
| | 1863 | | /// <exception cref="BatchErrorException"> |
| | 1864 | | /// Thrown when the operation returned an invalid status code |
| | 1865 | | /// </exception> |
| | 1866 | | /// <exception cref="ValidationException"> |
| | 1867 | | /// Thrown when a required parameter is null |
| | 1868 | | /// </exception> |
| | 1869 | | /// <exception cref="System.ArgumentNullException"> |
| | 1870 | | /// Thrown when a required parameter is null |
| | 1871 | | /// </exception> |
| | 1872 | | /// <return> |
| | 1873 | | /// A response object containing the response body and response headers. |
| | 1874 | | /// </return> |
| | 1875 | | public async Task<AzureOperationHeaderResponse<JobEnableHeaders>> EnableWithHttpMessagesAsync(string jobId, JobE |
| | 1876 | | { |
| 0 | 1877 | | if (Client.BatchUrl == null) |
| | 1878 | | { |
| 0 | 1879 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 1880 | | } |
| 0 | 1881 | | if (jobId == null) |
| | 1882 | | { |
| 0 | 1883 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobId"); |
| | 1884 | | } |
| 0 | 1885 | | if (Client.ApiVersion == null) |
| | 1886 | | { |
| 0 | 1887 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1888 | | } |
| 0 | 1889 | | int? timeout = default(int?); |
| 0 | 1890 | | if (jobEnableOptions != null) |
| | 1891 | | { |
| 0 | 1892 | | timeout = jobEnableOptions.Timeout; |
| | 1893 | | } |
| 0 | 1894 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 1895 | | if (jobEnableOptions != null) |
| | 1896 | | { |
| 0 | 1897 | | clientRequestId = jobEnableOptions.ClientRequestId; |
| | 1898 | | } |
| 0 | 1899 | | bool? returnClientRequestId = default(bool?); |
| 0 | 1900 | | if (jobEnableOptions != null) |
| | 1901 | | { |
| 0 | 1902 | | returnClientRequestId = jobEnableOptions.ReturnClientRequestId; |
| | 1903 | | } |
| 0 | 1904 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 1905 | | if (jobEnableOptions != null) |
| | 1906 | | { |
| 0 | 1907 | | ocpDate = jobEnableOptions.OcpDate; |
| | 1908 | | } |
| 0 | 1909 | | string ifMatch = default(string); |
| 0 | 1910 | | if (jobEnableOptions != null) |
| | 1911 | | { |
| 0 | 1912 | | ifMatch = jobEnableOptions.IfMatch; |
| | 1913 | | } |
| 0 | 1914 | | string ifNoneMatch = default(string); |
| 0 | 1915 | | if (jobEnableOptions != null) |
| | 1916 | | { |
| 0 | 1917 | | ifNoneMatch = jobEnableOptions.IfNoneMatch; |
| | 1918 | | } |
| 0 | 1919 | | System.DateTime? ifModifiedSince = default(System.DateTime?); |
| 0 | 1920 | | if (jobEnableOptions != null) |
| | 1921 | | { |
| 0 | 1922 | | ifModifiedSince = jobEnableOptions.IfModifiedSince; |
| | 1923 | | } |
| 0 | 1924 | | System.DateTime? ifUnmodifiedSince = default(System.DateTime?); |
| 0 | 1925 | | if (jobEnableOptions != null) |
| | 1926 | | { |
| 0 | 1927 | | ifUnmodifiedSince = jobEnableOptions.IfUnmodifiedSince; |
| | 1928 | | } |
| | 1929 | | // Tracing |
| 0 | 1930 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1931 | | string _invocationId = null; |
| 0 | 1932 | | if (_shouldTrace) |
| | 1933 | | { |
| 0 | 1934 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1935 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1936 | | tracingParameters.Add("jobId", jobId); |
| 0 | 1937 | | tracingParameters.Add("timeout", timeout); |
| 0 | 1938 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1939 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 1940 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 1941 | | tracingParameters.Add("ifMatch", ifMatch); |
| 0 | 1942 | | tracingParameters.Add("ifNoneMatch", ifNoneMatch); |
| 0 | 1943 | | tracingParameters.Add("ifModifiedSince", ifModifiedSince); |
| 0 | 1944 | | tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince); |
| 0 | 1945 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1946 | | ServiceClientTracing.Enter(_invocationId, this, "Enable", tracingParameters); |
| | 1947 | | } |
| | 1948 | | // Construct URL |
| 0 | 1949 | | var _baseUrl = Client.BaseUri; |
| 0 | 1950 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/enable"; |
| 0 | 1951 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 1952 | | _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId)); |
| 0 | 1953 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1954 | | if (Client.ApiVersion != null) |
| | 1955 | | { |
| 0 | 1956 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1957 | | } |
| 0 | 1958 | | if (timeout != null) |
| | 1959 | | { |
| 0 | 1960 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 1961 | | } |
| 0 | 1962 | | if (_queryParameters.Count > 0) |
| | 1963 | | { |
| 0 | 1964 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1965 | | } |
| | 1966 | | // Create HTTP transport objects |
| 0 | 1967 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1968 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1969 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1970 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1971 | | // Set Headers |
| 0 | 1972 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1973 | | { |
| 0 | 1974 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1975 | | } |
| 0 | 1976 | | if (Client.AcceptLanguage != null) |
| | 1977 | | { |
| 0 | 1978 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1979 | | { |
| 0 | 1980 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1981 | | } |
| 0 | 1982 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1983 | | } |
| 0 | 1984 | | if (clientRequestId != null) |
| | 1985 | | { |
| 0 | 1986 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1987 | | { |
| 0 | 1988 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1989 | | } |
| 0 | 1990 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 1991 | | } |
| 0 | 1992 | | if (returnClientRequestId != null) |
| | 1993 | | { |
| 0 | 1994 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 1995 | | { |
| 0 | 1996 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 1997 | | } |
| 0 | 1998 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 1999 | | } |
| 0 | 2000 | | if (ocpDate != null) |
| | 2001 | | { |
| 0 | 2002 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 2003 | | { |
| 0 | 2004 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 2005 | | } |
| 0 | 2006 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 2007 | | } |
| 0 | 2008 | | if (ifMatch != null) |
| | 2009 | | { |
| 0 | 2010 | | if (_httpRequest.Headers.Contains("If-Match")) |
| | 2011 | | { |
| 0 | 2012 | | _httpRequest.Headers.Remove("If-Match"); |
| | 2013 | | } |
| 0 | 2014 | | _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch); |
| | 2015 | | } |
| 0 | 2016 | | if (ifNoneMatch != null) |
| | 2017 | | { |
| 0 | 2018 | | if (_httpRequest.Headers.Contains("If-None-Match")) |
| | 2019 | | { |
| 0 | 2020 | | _httpRequest.Headers.Remove("If-None-Match"); |
| | 2021 | | } |
| 0 | 2022 | | _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch); |
| | 2023 | | } |
| 0 | 2024 | | if (ifModifiedSince != null) |
| | 2025 | | { |
| 0 | 2026 | | if (_httpRequest.Headers.Contains("If-Modified-Since")) |
| | 2027 | | { |
| 0 | 2028 | | _httpRequest.Headers.Remove("If-Modified-Since"); |
| | 2029 | | } |
| 0 | 2030 | | _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi |
| | 2031 | | } |
| 0 | 2032 | | if (ifUnmodifiedSince != null) |
| | 2033 | | { |
| 0 | 2034 | | if (_httpRequest.Headers.Contains("If-Unmodified-Since")) |
| | 2035 | | { |
| 0 | 2036 | | _httpRequest.Headers.Remove("If-Unmodified-Since"); |
| | 2037 | | } |
| 0 | 2038 | | _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn |
| | 2039 | | } |
| | 2040 | |
|
| | 2041 | |
|
| 0 | 2042 | | if (customHeaders != null) |
| | 2043 | | { |
| 0 | 2044 | | foreach(var _header in customHeaders) |
| | 2045 | | { |
| 0 | 2046 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2047 | | { |
| 0 | 2048 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2049 | | } |
| 0 | 2050 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2051 | | } |
| | 2052 | | } |
| | 2053 | |
|
| | 2054 | | // Serialize Request |
| 0 | 2055 | | string _requestContent = null; |
| | 2056 | | // Set Credentials |
| 0 | 2057 | | if (Client.Credentials != null) |
| | 2058 | | { |
| 0 | 2059 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2060 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2061 | | } |
| | 2062 | | // Send Request |
| 0 | 2063 | | if (_shouldTrace) |
| | 2064 | | { |
| 0 | 2065 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2066 | | } |
| 0 | 2067 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2068 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2069 | | if (_shouldTrace) |
| | 2070 | | { |
| 0 | 2071 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2072 | | } |
| 0 | 2073 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2074 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2075 | | string _responseContent = null; |
| 0 | 2076 | | if ((int)_statusCode != 202) |
| | 2077 | | { |
| 0 | 2078 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2079 | | try |
| | 2080 | | { |
| 0 | 2081 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2082 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 2083 | | if (_errorBody != null) |
| | 2084 | | { |
| 0 | 2085 | | ex.Body = _errorBody; |
| | 2086 | | } |
| 0 | 2087 | | } |
| 0 | 2088 | | catch (JsonException) |
| | 2089 | | { |
| | 2090 | | // Ignore the exception |
| 0 | 2091 | | } |
| 0 | 2092 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2093 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2094 | | if (_shouldTrace) |
| | 2095 | | { |
| 0 | 2096 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2097 | | } |
| 0 | 2098 | | _httpRequest.Dispose(); |
| 0 | 2099 | | if (_httpResponse != null) |
| | 2100 | | { |
| 0 | 2101 | | _httpResponse.Dispose(); |
| | 2102 | | } |
| 0 | 2103 | | throw ex; |
| | 2104 | | } |
| | 2105 | | // Create Result |
| 0 | 2106 | | var _result = new AzureOperationHeaderResponse<JobEnableHeaders>(); |
| 0 | 2107 | | _result.Request = _httpRequest; |
| 0 | 2108 | | _result.Response = _httpResponse; |
| 0 | 2109 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 2110 | | { |
| 0 | 2111 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 2112 | | } |
| | 2113 | | try |
| | 2114 | | { |
| 0 | 2115 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobEnableHeaders>(JsonSerializer.Create(Clie |
| 0 | 2116 | | } |
| 0 | 2117 | | catch (JsonException ex) |
| | 2118 | | { |
| 0 | 2119 | | _httpRequest.Dispose(); |
| 0 | 2120 | | if (_httpResponse != null) |
| | 2121 | | { |
| 0 | 2122 | | _httpResponse.Dispose(); |
| | 2123 | | } |
| 0 | 2124 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 2125 | | } |
| 0 | 2126 | | if (_shouldTrace) |
| | 2127 | | { |
| 0 | 2128 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2129 | | } |
| 0 | 2130 | | return _result; |
| 0 | 2131 | | } |
| | 2132 | |
|
| | 2133 | | /// <summary> |
| | 2134 | | /// Terminates the specified Job, marking it as completed. |
| | 2135 | | /// </summary> |
| | 2136 | | /// <remarks> |
| | 2137 | | /// When a Terminate Job request is received, the Batch service sets the Job to |
| | 2138 | | /// the terminating state. The Batch service then terminates any running Tasks |
| | 2139 | | /// associated with the Job and runs any required Job release Tasks. Then the |
| | 2140 | | /// Job moves into the completed state. If there are any Tasks in the Job in |
| | 2141 | | /// the active state, they will remain in the active state. Once a Job is |
| | 2142 | | /// terminated, new Tasks cannot be added and any remaining active Tasks will |
| | 2143 | | /// not be scheduled. |
| | 2144 | | /// </remarks> |
| | 2145 | | /// <param name='jobId'> |
| | 2146 | | /// The ID of the Job to terminate. |
| | 2147 | | /// </param> |
| | 2148 | | /// <param name='terminateReason'> |
| | 2149 | | /// The text you want to appear as the Job's TerminateReason. The default is |
| | 2150 | | /// 'UserTerminate'. |
| | 2151 | | /// </param> |
| | 2152 | | /// <param name='jobTerminateOptions'> |
| | 2153 | | /// Additional parameters for the operation |
| | 2154 | | /// </param> |
| | 2155 | | /// <param name='customHeaders'> |
| | 2156 | | /// Headers that will be added to request. |
| | 2157 | | /// </param> |
| | 2158 | | /// <param name='cancellationToken'> |
| | 2159 | | /// The cancellation token. |
| | 2160 | | /// </param> |
| | 2161 | | /// <exception cref="BatchErrorException"> |
| | 2162 | | /// Thrown when the operation returned an invalid status code |
| | 2163 | | /// </exception> |
| | 2164 | | /// <exception cref="ValidationException"> |
| | 2165 | | /// Thrown when a required parameter is null |
| | 2166 | | /// </exception> |
| | 2167 | | /// <exception cref="System.ArgumentNullException"> |
| | 2168 | | /// Thrown when a required parameter is null |
| | 2169 | | /// </exception> |
| | 2170 | | /// <return> |
| | 2171 | | /// A response object containing the response body and response headers. |
| | 2172 | | /// </return> |
| | 2173 | | public async Task<AzureOperationHeaderResponse<JobTerminateHeaders>> TerminateWithHttpMessagesAsync(string jobId |
| | 2174 | | { |
| 0 | 2175 | | if (Client.BatchUrl == null) |
| | 2176 | | { |
| 0 | 2177 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 2178 | | } |
| 0 | 2179 | | if (jobId == null) |
| | 2180 | | { |
| 0 | 2181 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobId"); |
| | 2182 | | } |
| 0 | 2183 | | if (Client.ApiVersion == null) |
| | 2184 | | { |
| 0 | 2185 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 2186 | | } |
| 0 | 2187 | | int? timeout = default(int?); |
| 0 | 2188 | | if (jobTerminateOptions != null) |
| | 2189 | | { |
| 0 | 2190 | | timeout = jobTerminateOptions.Timeout; |
| | 2191 | | } |
| 0 | 2192 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 2193 | | if (jobTerminateOptions != null) |
| | 2194 | | { |
| 0 | 2195 | | clientRequestId = jobTerminateOptions.ClientRequestId; |
| | 2196 | | } |
| 0 | 2197 | | bool? returnClientRequestId = default(bool?); |
| 0 | 2198 | | if (jobTerminateOptions != null) |
| | 2199 | | { |
| 0 | 2200 | | returnClientRequestId = jobTerminateOptions.ReturnClientRequestId; |
| | 2201 | | } |
| 0 | 2202 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 2203 | | if (jobTerminateOptions != null) |
| | 2204 | | { |
| 0 | 2205 | | ocpDate = jobTerminateOptions.OcpDate; |
| | 2206 | | } |
| 0 | 2207 | | string ifMatch = default(string); |
| 0 | 2208 | | if (jobTerminateOptions != null) |
| | 2209 | | { |
| 0 | 2210 | | ifMatch = jobTerminateOptions.IfMatch; |
| | 2211 | | } |
| 0 | 2212 | | string ifNoneMatch = default(string); |
| 0 | 2213 | | if (jobTerminateOptions != null) |
| | 2214 | | { |
| 0 | 2215 | | ifNoneMatch = jobTerminateOptions.IfNoneMatch; |
| | 2216 | | } |
| 0 | 2217 | | System.DateTime? ifModifiedSince = default(System.DateTime?); |
| 0 | 2218 | | if (jobTerminateOptions != null) |
| | 2219 | | { |
| 0 | 2220 | | ifModifiedSince = jobTerminateOptions.IfModifiedSince; |
| | 2221 | | } |
| 0 | 2222 | | System.DateTime? ifUnmodifiedSince = default(System.DateTime?); |
| 0 | 2223 | | if (jobTerminateOptions != null) |
| | 2224 | | { |
| 0 | 2225 | | ifUnmodifiedSince = jobTerminateOptions.IfUnmodifiedSince; |
| | 2226 | | } |
| 0 | 2227 | | JobTerminateParameter jobTerminateParameter = default(JobTerminateParameter); |
| 0 | 2228 | | if (terminateReason != null) |
| | 2229 | | { |
| 0 | 2230 | | jobTerminateParameter = new JobTerminateParameter(); |
| 0 | 2231 | | jobTerminateParameter.TerminateReason = terminateReason; |
| | 2232 | | } |
| | 2233 | | // Tracing |
| 0 | 2234 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2235 | | string _invocationId = null; |
| 0 | 2236 | | if (_shouldTrace) |
| | 2237 | | { |
| 0 | 2238 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2239 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2240 | | tracingParameters.Add("jobId", jobId); |
| 0 | 2241 | | tracingParameters.Add("timeout", timeout); |
| 0 | 2242 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 2243 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 2244 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 2245 | | tracingParameters.Add("ifMatch", ifMatch); |
| 0 | 2246 | | tracingParameters.Add("ifNoneMatch", ifNoneMatch); |
| 0 | 2247 | | tracingParameters.Add("ifModifiedSince", ifModifiedSince); |
| 0 | 2248 | | tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince); |
| 0 | 2249 | | tracingParameters.Add("jobTerminateParameter", jobTerminateParameter); |
| 0 | 2250 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2251 | | ServiceClientTracing.Enter(_invocationId, this, "Terminate", tracingParameters); |
| | 2252 | | } |
| | 2253 | | // Construct URL |
| 0 | 2254 | | var _baseUrl = Client.BaseUri; |
| 0 | 2255 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/terminate"; |
| 0 | 2256 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 2257 | | _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId)); |
| 0 | 2258 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2259 | | if (Client.ApiVersion != null) |
| | 2260 | | { |
| 0 | 2261 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 2262 | | } |
| 0 | 2263 | | if (timeout != null) |
| | 2264 | | { |
| 0 | 2265 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 2266 | | } |
| 0 | 2267 | | if (_queryParameters.Count > 0) |
| | 2268 | | { |
| 0 | 2269 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2270 | | } |
| | 2271 | | // Create HTTP transport objects |
| 0 | 2272 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2273 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2274 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 2275 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2276 | | // Set Headers |
| 0 | 2277 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2278 | | { |
| 0 | 2279 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 2280 | | } |
| 0 | 2281 | | if (Client.AcceptLanguage != null) |
| | 2282 | | { |
| 0 | 2283 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2284 | | { |
| 0 | 2285 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2286 | | } |
| 0 | 2287 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2288 | | } |
| 0 | 2289 | | if (clientRequestId != null) |
| | 2290 | | { |
| 0 | 2291 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 2292 | | { |
| 0 | 2293 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 2294 | | } |
| 0 | 2295 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 2296 | | } |
| 0 | 2297 | | if (returnClientRequestId != null) |
| | 2298 | | { |
| 0 | 2299 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 2300 | | { |
| 0 | 2301 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 2302 | | } |
| 0 | 2303 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 2304 | | } |
| 0 | 2305 | | if (ocpDate != null) |
| | 2306 | | { |
| 0 | 2307 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 2308 | | { |
| 0 | 2309 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 2310 | | } |
| 0 | 2311 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 2312 | | } |
| 0 | 2313 | | if (ifMatch != null) |
| | 2314 | | { |
| 0 | 2315 | | if (_httpRequest.Headers.Contains("If-Match")) |
| | 2316 | | { |
| 0 | 2317 | | _httpRequest.Headers.Remove("If-Match"); |
| | 2318 | | } |
| 0 | 2319 | | _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch); |
| | 2320 | | } |
| 0 | 2321 | | if (ifNoneMatch != null) |
| | 2322 | | { |
| 0 | 2323 | | if (_httpRequest.Headers.Contains("If-None-Match")) |
| | 2324 | | { |
| 0 | 2325 | | _httpRequest.Headers.Remove("If-None-Match"); |
| | 2326 | | } |
| 0 | 2327 | | _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch); |
| | 2328 | | } |
| 0 | 2329 | | if (ifModifiedSince != null) |
| | 2330 | | { |
| 0 | 2331 | | if (_httpRequest.Headers.Contains("If-Modified-Since")) |
| | 2332 | | { |
| 0 | 2333 | | _httpRequest.Headers.Remove("If-Modified-Since"); |
| | 2334 | | } |
| 0 | 2335 | | _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi |
| | 2336 | | } |
| 0 | 2337 | | if (ifUnmodifiedSince != null) |
| | 2338 | | { |
| 0 | 2339 | | if (_httpRequest.Headers.Contains("If-Unmodified-Since")) |
| | 2340 | | { |
| 0 | 2341 | | _httpRequest.Headers.Remove("If-Unmodified-Since"); |
| | 2342 | | } |
| 0 | 2343 | | _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn |
| | 2344 | | } |
| | 2345 | |
|
| | 2346 | |
|
| 0 | 2347 | | if (customHeaders != null) |
| | 2348 | | { |
| 0 | 2349 | | foreach(var _header in customHeaders) |
| | 2350 | | { |
| 0 | 2351 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2352 | | { |
| 0 | 2353 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2354 | | } |
| 0 | 2355 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2356 | | } |
| | 2357 | | } |
| | 2358 | |
|
| | 2359 | | // Serialize Request |
| 0 | 2360 | | string _requestContent = null; |
| 0 | 2361 | | if(jobTerminateParameter != null) |
| | 2362 | | { |
| 0 | 2363 | | _requestContent = SafeJsonConvert.SerializeObject(jobTerminateParameter, Client.SerializationSettings); |
| 0 | 2364 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 2365 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 2366 | | } |
| | 2367 | | // Set Credentials |
| 0 | 2368 | | if (Client.Credentials != null) |
| | 2369 | | { |
| 0 | 2370 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2371 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2372 | | } |
| | 2373 | | // Send Request |
| 0 | 2374 | | if (_shouldTrace) |
| | 2375 | | { |
| 0 | 2376 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2377 | | } |
| 0 | 2378 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2379 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2380 | | if (_shouldTrace) |
| | 2381 | | { |
| 0 | 2382 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2383 | | } |
| 0 | 2384 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2385 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2386 | | string _responseContent = null; |
| 0 | 2387 | | if ((int)_statusCode != 202) |
| | 2388 | | { |
| 0 | 2389 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2390 | | try |
| | 2391 | | { |
| 0 | 2392 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2393 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 2394 | | if (_errorBody != null) |
| | 2395 | | { |
| 0 | 2396 | | ex.Body = _errorBody; |
| | 2397 | | } |
| 0 | 2398 | | } |
| 0 | 2399 | | catch (JsonException) |
| | 2400 | | { |
| | 2401 | | // Ignore the exception |
| 0 | 2402 | | } |
| 0 | 2403 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2404 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2405 | | if (_shouldTrace) |
| | 2406 | | { |
| 0 | 2407 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2408 | | } |
| 0 | 2409 | | _httpRequest.Dispose(); |
| 0 | 2410 | | if (_httpResponse != null) |
| | 2411 | | { |
| 0 | 2412 | | _httpResponse.Dispose(); |
| | 2413 | | } |
| 0 | 2414 | | throw ex; |
| | 2415 | | } |
| | 2416 | | // Create Result |
| 0 | 2417 | | var _result = new AzureOperationHeaderResponse<JobTerminateHeaders>(); |
| 0 | 2418 | | _result.Request = _httpRequest; |
| 0 | 2419 | | _result.Response = _httpResponse; |
| 0 | 2420 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 2421 | | { |
| 0 | 2422 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 2423 | | } |
| | 2424 | | try |
| | 2425 | | { |
| 0 | 2426 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobTerminateHeaders>(JsonSerializer.Create(C |
| 0 | 2427 | | } |
| 0 | 2428 | | catch (JsonException ex) |
| | 2429 | | { |
| 0 | 2430 | | _httpRequest.Dispose(); |
| 0 | 2431 | | if (_httpResponse != null) |
| | 2432 | | { |
| 0 | 2433 | | _httpResponse.Dispose(); |
| | 2434 | | } |
| 0 | 2435 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 2436 | | } |
| 0 | 2437 | | if (_shouldTrace) |
| | 2438 | | { |
| 0 | 2439 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2440 | | } |
| 0 | 2441 | | return _result; |
| 0 | 2442 | | } |
| | 2443 | |
|
| | 2444 | | /// <summary> |
| | 2445 | | /// Adds a Job to the specified Account. |
| | 2446 | | /// </summary> |
| | 2447 | | /// <remarks> |
| | 2448 | | /// The Batch service supports two ways to control the work done as part of a |
| | 2449 | | /// Job. In the first approach, the user specifies a Job Manager Task. The |
| | 2450 | | /// Batch service launches this Task when it is ready to start the Job. The Job |
| | 2451 | | /// Manager Task controls all other Tasks that run under this Job, by using the |
| | 2452 | | /// Task APIs. In the second approach, the user directly controls the execution |
| | 2453 | | /// of Tasks under an active Job, by using the Task APIs. Also note: when |
| | 2454 | | /// naming Jobs, avoid including sensitive information such as user names or |
| | 2455 | | /// secret project names. This information may appear in telemetry logs |
| | 2456 | | /// accessible to Microsoft Support engineers. |
| | 2457 | | /// </remarks> |
| | 2458 | | /// <param name='job'> |
| | 2459 | | /// The Job to be added. |
| | 2460 | | /// </param> |
| | 2461 | | /// <param name='jobAddOptions'> |
| | 2462 | | /// Additional parameters for the operation |
| | 2463 | | /// </param> |
| | 2464 | | /// <param name='customHeaders'> |
| | 2465 | | /// Headers that will be added to request. |
| | 2466 | | /// </param> |
| | 2467 | | /// <param name='cancellationToken'> |
| | 2468 | | /// The cancellation token. |
| | 2469 | | /// </param> |
| | 2470 | | /// <exception cref="BatchErrorException"> |
| | 2471 | | /// Thrown when the operation returned an invalid status code |
| | 2472 | | /// </exception> |
| | 2473 | | /// <exception cref="ValidationException"> |
| | 2474 | | /// Thrown when a required parameter is null |
| | 2475 | | /// </exception> |
| | 2476 | | /// <exception cref="System.ArgumentNullException"> |
| | 2477 | | /// Thrown when a required parameter is null |
| | 2478 | | /// </exception> |
| | 2479 | | /// <return> |
| | 2480 | | /// A response object containing the response body and response headers. |
| | 2481 | | /// </return> |
| | 2482 | | public async Task<AzureOperationHeaderResponse<JobAddHeaders>> AddWithHttpMessagesAsync(JobAddParameter job, Job |
| | 2483 | | { |
| 0 | 2484 | | if (Client.BatchUrl == null) |
| | 2485 | | { |
| 0 | 2486 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 2487 | | } |
| 0 | 2488 | | if (job == null) |
| | 2489 | | { |
| 0 | 2490 | | throw new ValidationException(ValidationRules.CannotBeNull, "job"); |
| | 2491 | | } |
| 0 | 2492 | | if (Client.ApiVersion == null) |
| | 2493 | | { |
| 0 | 2494 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 2495 | | } |
| 0 | 2496 | | int? timeout = default(int?); |
| 0 | 2497 | | if (jobAddOptions != null) |
| | 2498 | | { |
| 0 | 2499 | | timeout = jobAddOptions.Timeout; |
| | 2500 | | } |
| 0 | 2501 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 2502 | | if (jobAddOptions != null) |
| | 2503 | | { |
| 0 | 2504 | | clientRequestId = jobAddOptions.ClientRequestId; |
| | 2505 | | } |
| 0 | 2506 | | bool? returnClientRequestId = default(bool?); |
| 0 | 2507 | | if (jobAddOptions != null) |
| | 2508 | | { |
| 0 | 2509 | | returnClientRequestId = jobAddOptions.ReturnClientRequestId; |
| | 2510 | | } |
| 0 | 2511 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 2512 | | if (jobAddOptions != null) |
| | 2513 | | { |
| 0 | 2514 | | ocpDate = jobAddOptions.OcpDate; |
| | 2515 | | } |
| | 2516 | | // Tracing |
| 0 | 2517 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2518 | | string _invocationId = null; |
| 0 | 2519 | | if (_shouldTrace) |
| | 2520 | | { |
| 0 | 2521 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2522 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2523 | | tracingParameters.Add("job", job); |
| 0 | 2524 | | tracingParameters.Add("timeout", timeout); |
| 0 | 2525 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 2526 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 2527 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 2528 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2529 | | ServiceClientTracing.Enter(_invocationId, this, "Add", tracingParameters); |
| | 2530 | | } |
| | 2531 | | // Construct URL |
| 0 | 2532 | | var _baseUrl = Client.BaseUri; |
| 0 | 2533 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs"; |
| 0 | 2534 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 2535 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2536 | | if (Client.ApiVersion != null) |
| | 2537 | | { |
| 0 | 2538 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 2539 | | } |
| 0 | 2540 | | if (timeout != null) |
| | 2541 | | { |
| 0 | 2542 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 2543 | | } |
| 0 | 2544 | | if (_queryParameters.Count > 0) |
| | 2545 | | { |
| 0 | 2546 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2547 | | } |
| | 2548 | | // Create HTTP transport objects |
| 0 | 2549 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2550 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2551 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 2552 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2553 | | // Set Headers |
| 0 | 2554 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2555 | | { |
| 0 | 2556 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 2557 | | } |
| 0 | 2558 | | if (Client.AcceptLanguage != null) |
| | 2559 | | { |
| 0 | 2560 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2561 | | { |
| 0 | 2562 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2563 | | } |
| 0 | 2564 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2565 | | } |
| 0 | 2566 | | if (clientRequestId != null) |
| | 2567 | | { |
| 0 | 2568 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 2569 | | { |
| 0 | 2570 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 2571 | | } |
| 0 | 2572 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 2573 | | } |
| 0 | 2574 | | if (returnClientRequestId != null) |
| | 2575 | | { |
| 0 | 2576 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 2577 | | { |
| 0 | 2578 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 2579 | | } |
| 0 | 2580 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 2581 | | } |
| 0 | 2582 | | if (ocpDate != null) |
| | 2583 | | { |
| 0 | 2584 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 2585 | | { |
| 0 | 2586 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 2587 | | } |
| 0 | 2588 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 2589 | | } |
| | 2590 | |
|
| | 2591 | |
|
| 0 | 2592 | | if (customHeaders != null) |
| | 2593 | | { |
| 0 | 2594 | | foreach(var _header in customHeaders) |
| | 2595 | | { |
| 0 | 2596 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2597 | | { |
| 0 | 2598 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2599 | | } |
| 0 | 2600 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2601 | | } |
| | 2602 | | } |
| | 2603 | |
|
| | 2604 | | // Serialize Request |
| 0 | 2605 | | string _requestContent = null; |
| 0 | 2606 | | if(job != null) |
| | 2607 | | { |
| 0 | 2608 | | _requestContent = SafeJsonConvert.SerializeObject(job, Client.SerializationSettings); |
| 0 | 2609 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 2610 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 2611 | | } |
| | 2612 | | // Set Credentials |
| 0 | 2613 | | if (Client.Credentials != null) |
| | 2614 | | { |
| 0 | 2615 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2616 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2617 | | } |
| | 2618 | | // Send Request |
| 0 | 2619 | | if (_shouldTrace) |
| | 2620 | | { |
| 0 | 2621 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2622 | | } |
| 0 | 2623 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2624 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2625 | | if (_shouldTrace) |
| | 2626 | | { |
| 0 | 2627 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2628 | | } |
| 0 | 2629 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2630 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2631 | | string _responseContent = null; |
| 0 | 2632 | | if ((int)_statusCode != 201) |
| | 2633 | | { |
| 0 | 2634 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2635 | | try |
| | 2636 | | { |
| 0 | 2637 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2638 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 2639 | | if (_errorBody != null) |
| | 2640 | | { |
| 0 | 2641 | | ex.Body = _errorBody; |
| | 2642 | | } |
| 0 | 2643 | | } |
| 0 | 2644 | | catch (JsonException) |
| | 2645 | | { |
| | 2646 | | // Ignore the exception |
| 0 | 2647 | | } |
| 0 | 2648 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2649 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2650 | | if (_shouldTrace) |
| | 2651 | | { |
| 0 | 2652 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2653 | | } |
| 0 | 2654 | | _httpRequest.Dispose(); |
| 0 | 2655 | | if (_httpResponse != null) |
| | 2656 | | { |
| 0 | 2657 | | _httpResponse.Dispose(); |
| | 2658 | | } |
| 0 | 2659 | | throw ex; |
| | 2660 | | } |
| | 2661 | | // Create Result |
| 0 | 2662 | | var _result = new AzureOperationHeaderResponse<JobAddHeaders>(); |
| 0 | 2663 | | _result.Request = _httpRequest; |
| 0 | 2664 | | _result.Response = _httpResponse; |
| 0 | 2665 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 2666 | | { |
| 0 | 2667 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 2668 | | } |
| | 2669 | | try |
| | 2670 | | { |
| 0 | 2671 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobAddHeaders>(JsonSerializer.Create(Client. |
| 0 | 2672 | | } |
| 0 | 2673 | | catch (JsonException ex) |
| | 2674 | | { |
| 0 | 2675 | | _httpRequest.Dispose(); |
| 0 | 2676 | | if (_httpResponse != null) |
| | 2677 | | { |
| 0 | 2678 | | _httpResponse.Dispose(); |
| | 2679 | | } |
| 0 | 2680 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 2681 | | } |
| 0 | 2682 | | if (_shouldTrace) |
| | 2683 | | { |
| 0 | 2684 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2685 | | } |
| 0 | 2686 | | return _result; |
| 0 | 2687 | | } |
| | 2688 | |
|
| | 2689 | | /// <summary> |
| | 2690 | | /// Lists all of the Jobs in the specified Account. |
| | 2691 | | /// </summary> |
| | 2692 | | /// <param name='jobListOptions'> |
| | 2693 | | /// Additional parameters for the operation |
| | 2694 | | /// </param> |
| | 2695 | | /// <param name='customHeaders'> |
| | 2696 | | /// Headers that will be added to request. |
| | 2697 | | /// </param> |
| | 2698 | | /// <param name='cancellationToken'> |
| | 2699 | | /// The cancellation token. |
| | 2700 | | /// </param> |
| | 2701 | | /// <exception cref="BatchErrorException"> |
| | 2702 | | /// Thrown when the operation returned an invalid status code |
| | 2703 | | /// </exception> |
| | 2704 | | /// <exception cref="SerializationException"> |
| | 2705 | | /// Thrown when unable to deserialize the response |
| | 2706 | | /// </exception> |
| | 2707 | | /// <exception cref="ValidationException"> |
| | 2708 | | /// Thrown when a required parameter is null |
| | 2709 | | /// </exception> |
| | 2710 | | /// <exception cref="System.ArgumentNullException"> |
| | 2711 | | /// Thrown when a required parameter is null |
| | 2712 | | /// </exception> |
| | 2713 | | /// <return> |
| | 2714 | | /// A response object containing the response body and response headers. |
| | 2715 | | /// </return> |
| | 2716 | | public async Task<AzureOperationResponse<IPage<CloudJob>,JobListHeaders>> ListWithHttpMessagesAsync(JobListOptio |
| | 2717 | | { |
| 0 | 2718 | | if (Client.BatchUrl == null) |
| | 2719 | | { |
| 0 | 2720 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 2721 | | } |
| 0 | 2722 | | if (Client.ApiVersion == null) |
| | 2723 | | { |
| 0 | 2724 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 2725 | | } |
| 0 | 2726 | | string filter = default(string); |
| 0 | 2727 | | if (jobListOptions != null) |
| | 2728 | | { |
| 0 | 2729 | | filter = jobListOptions.Filter; |
| | 2730 | | } |
| 0 | 2731 | | string select = default(string); |
| 0 | 2732 | | if (jobListOptions != null) |
| | 2733 | | { |
| 0 | 2734 | | select = jobListOptions.Select; |
| | 2735 | | } |
| 0 | 2736 | | string expand = default(string); |
| 0 | 2737 | | if (jobListOptions != null) |
| | 2738 | | { |
| 0 | 2739 | | expand = jobListOptions.Expand; |
| | 2740 | | } |
| 0 | 2741 | | int? maxResults = default(int?); |
| 0 | 2742 | | if (jobListOptions != null) |
| | 2743 | | { |
| 0 | 2744 | | maxResults = jobListOptions.MaxResults; |
| | 2745 | | } |
| 0 | 2746 | | int? timeout = default(int?); |
| 0 | 2747 | | if (jobListOptions != null) |
| | 2748 | | { |
| 0 | 2749 | | timeout = jobListOptions.Timeout; |
| | 2750 | | } |
| 0 | 2751 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 2752 | | if (jobListOptions != null) |
| | 2753 | | { |
| 0 | 2754 | | clientRequestId = jobListOptions.ClientRequestId; |
| | 2755 | | } |
| 0 | 2756 | | bool? returnClientRequestId = default(bool?); |
| 0 | 2757 | | if (jobListOptions != null) |
| | 2758 | | { |
| 0 | 2759 | | returnClientRequestId = jobListOptions.ReturnClientRequestId; |
| | 2760 | | } |
| 0 | 2761 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 2762 | | if (jobListOptions != null) |
| | 2763 | | { |
| 0 | 2764 | | ocpDate = jobListOptions.OcpDate; |
| | 2765 | | } |
| | 2766 | | // Tracing |
| 0 | 2767 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2768 | | string _invocationId = null; |
| 0 | 2769 | | if (_shouldTrace) |
| | 2770 | | { |
| 0 | 2771 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2772 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2773 | | tracingParameters.Add("filter", filter); |
| 0 | 2774 | | tracingParameters.Add("select", select); |
| 0 | 2775 | | tracingParameters.Add("expand", expand); |
| 0 | 2776 | | tracingParameters.Add("maxResults", maxResults); |
| 0 | 2777 | | tracingParameters.Add("timeout", timeout); |
| 0 | 2778 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 2779 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 2780 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 2781 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2782 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 2783 | | } |
| | 2784 | | // Construct URL |
| 0 | 2785 | | var _baseUrl = Client.BaseUri; |
| 0 | 2786 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs"; |
| 0 | 2787 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 2788 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2789 | | if (Client.ApiVersion != null) |
| | 2790 | | { |
| 0 | 2791 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 2792 | | } |
| 0 | 2793 | | if (filter != null) |
| | 2794 | | { |
| 0 | 2795 | | _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter))); |
| | 2796 | | } |
| 0 | 2797 | | if (select != null) |
| | 2798 | | { |
| 0 | 2799 | | _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select))); |
| | 2800 | | } |
| 0 | 2801 | | if (expand != null) |
| | 2802 | | { |
| 0 | 2803 | | _queryParameters.Add(string.Format("$expand={0}", System.Uri.EscapeDataString(expand))); |
| | 2804 | | } |
| 0 | 2805 | | if (maxResults != null) |
| | 2806 | | { |
| 0 | 2807 | | _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali |
| | 2808 | | } |
| 0 | 2809 | | if (timeout != null) |
| | 2810 | | { |
| 0 | 2811 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 2812 | | } |
| 0 | 2813 | | if (_queryParameters.Count > 0) |
| | 2814 | | { |
| 0 | 2815 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2816 | | } |
| | 2817 | | // Create HTTP transport objects |
| 0 | 2818 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2819 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2820 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 2821 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2822 | | // Set Headers |
| 0 | 2823 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2824 | | { |
| 0 | 2825 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 2826 | | } |
| 0 | 2827 | | if (Client.AcceptLanguage != null) |
| | 2828 | | { |
| 0 | 2829 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2830 | | { |
| 0 | 2831 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2832 | | } |
| 0 | 2833 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2834 | | } |
| 0 | 2835 | | if (clientRequestId != null) |
| | 2836 | | { |
| 0 | 2837 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 2838 | | { |
| 0 | 2839 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 2840 | | } |
| 0 | 2841 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 2842 | | } |
| 0 | 2843 | | if (returnClientRequestId != null) |
| | 2844 | | { |
| 0 | 2845 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 2846 | | { |
| 0 | 2847 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 2848 | | } |
| 0 | 2849 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 2850 | | } |
| 0 | 2851 | | if (ocpDate != null) |
| | 2852 | | { |
| 0 | 2853 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 2854 | | { |
| 0 | 2855 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 2856 | | } |
| 0 | 2857 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 2858 | | } |
| | 2859 | |
|
| | 2860 | |
|
| 0 | 2861 | | if (customHeaders != null) |
| | 2862 | | { |
| 0 | 2863 | | foreach(var _header in customHeaders) |
| | 2864 | | { |
| 0 | 2865 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2866 | | { |
| 0 | 2867 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2868 | | } |
| 0 | 2869 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2870 | | } |
| | 2871 | | } |
| | 2872 | |
|
| | 2873 | | // Serialize Request |
| 0 | 2874 | | string _requestContent = null; |
| | 2875 | | // Set Credentials |
| 0 | 2876 | | if (Client.Credentials != null) |
| | 2877 | | { |
| 0 | 2878 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2879 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2880 | | } |
| | 2881 | | // Send Request |
| 0 | 2882 | | if (_shouldTrace) |
| | 2883 | | { |
| 0 | 2884 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2885 | | } |
| 0 | 2886 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2887 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2888 | | if (_shouldTrace) |
| | 2889 | | { |
| 0 | 2890 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2891 | | } |
| 0 | 2892 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2893 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2894 | | string _responseContent = null; |
| 0 | 2895 | | if ((int)_statusCode != 200) |
| | 2896 | | { |
| 0 | 2897 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2898 | | try |
| | 2899 | | { |
| 0 | 2900 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2901 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 2902 | | if (_errorBody != null) |
| | 2903 | | { |
| 0 | 2904 | | ex.Body = _errorBody; |
| | 2905 | | } |
| 0 | 2906 | | } |
| 0 | 2907 | | catch (JsonException) |
| | 2908 | | { |
| | 2909 | | // Ignore the exception |
| 0 | 2910 | | } |
| 0 | 2911 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2912 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2913 | | if (_shouldTrace) |
| | 2914 | | { |
| 0 | 2915 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2916 | | } |
| 0 | 2917 | | _httpRequest.Dispose(); |
| 0 | 2918 | | if (_httpResponse != null) |
| | 2919 | | { |
| 0 | 2920 | | _httpResponse.Dispose(); |
| | 2921 | | } |
| 0 | 2922 | | throw ex; |
| | 2923 | | } |
| | 2924 | | // Create Result |
| 0 | 2925 | | var _result = new AzureOperationResponse<IPage<CloudJob>,JobListHeaders>(); |
| 0 | 2926 | | _result.Request = _httpRequest; |
| 0 | 2927 | | _result.Response = _httpResponse; |
| 0 | 2928 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 2929 | | { |
| 0 | 2930 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 2931 | | } |
| | 2932 | | // Deserialize Response |
| 0 | 2933 | | if ((int)_statusCode == 200) |
| | 2934 | | { |
| 0 | 2935 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2936 | | try |
| | 2937 | | { |
| 0 | 2938 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<CloudJob>>(_responseContent, Client.Deserializ |
| 0 | 2939 | | } |
| 0 | 2940 | | catch (JsonException ex) |
| | 2941 | | { |
| 0 | 2942 | | _httpRequest.Dispose(); |
| 0 | 2943 | | if (_httpResponse != null) |
| | 2944 | | { |
| 0 | 2945 | | _httpResponse.Dispose(); |
| | 2946 | | } |
| 0 | 2947 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2948 | | } |
| | 2949 | | } |
| | 2950 | | try |
| | 2951 | | { |
| 0 | 2952 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobListHeaders>(JsonSerializer.Create(Client |
| 0 | 2953 | | } |
| 0 | 2954 | | catch (JsonException ex) |
| | 2955 | | { |
| 0 | 2956 | | _httpRequest.Dispose(); |
| 0 | 2957 | | if (_httpResponse != null) |
| | 2958 | | { |
| 0 | 2959 | | _httpResponse.Dispose(); |
| | 2960 | | } |
| 0 | 2961 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 2962 | | } |
| 0 | 2963 | | if (_shouldTrace) |
| | 2964 | | { |
| 0 | 2965 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2966 | | } |
| 0 | 2967 | | return _result; |
| 0 | 2968 | | } |
| | 2969 | |
|
| | 2970 | | /// <summary> |
| | 2971 | | /// Lists the Jobs that have been created under the specified Job Schedule. |
| | 2972 | | /// </summary> |
| | 2973 | | /// <param name='jobScheduleId'> |
| | 2974 | | /// The ID of the Job Schedule from which you want to get a list of Jobs. |
| | 2975 | | /// </param> |
| | 2976 | | /// <param name='jobListFromJobScheduleOptions'> |
| | 2977 | | /// Additional parameters for the operation |
| | 2978 | | /// </param> |
| | 2979 | | /// <param name='customHeaders'> |
| | 2980 | | /// Headers that will be added to request. |
| | 2981 | | /// </param> |
| | 2982 | | /// <param name='cancellationToken'> |
| | 2983 | | /// The cancellation token. |
| | 2984 | | /// </param> |
| | 2985 | | /// <exception cref="BatchErrorException"> |
| | 2986 | | /// Thrown when the operation returned an invalid status code |
| | 2987 | | /// </exception> |
| | 2988 | | /// <exception cref="SerializationException"> |
| | 2989 | | /// Thrown when unable to deserialize the response |
| | 2990 | | /// </exception> |
| | 2991 | | /// <exception cref="ValidationException"> |
| | 2992 | | /// Thrown when a required parameter is null |
| | 2993 | | /// </exception> |
| | 2994 | | /// <exception cref="System.ArgumentNullException"> |
| | 2995 | | /// Thrown when a required parameter is null |
| | 2996 | | /// </exception> |
| | 2997 | | /// <return> |
| | 2998 | | /// A response object containing the response body and response headers. |
| | 2999 | | /// </return> |
| | 3000 | | public async Task<AzureOperationResponse<IPage<CloudJob>,JobListFromJobScheduleHeaders>> ListFromJobScheduleWith |
| | 3001 | | { |
| 0 | 3002 | | if (Client.BatchUrl == null) |
| | 3003 | | { |
| 0 | 3004 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 3005 | | } |
| 0 | 3006 | | if (jobScheduleId == null) |
| | 3007 | | { |
| 0 | 3008 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobScheduleId"); |
| | 3009 | | } |
| 0 | 3010 | | if (Client.ApiVersion == null) |
| | 3011 | | { |
| 0 | 3012 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 3013 | | } |
| 0 | 3014 | | string filter = default(string); |
| 0 | 3015 | | if (jobListFromJobScheduleOptions != null) |
| | 3016 | | { |
| 0 | 3017 | | filter = jobListFromJobScheduleOptions.Filter; |
| | 3018 | | } |
| 0 | 3019 | | string select = default(string); |
| 0 | 3020 | | if (jobListFromJobScheduleOptions != null) |
| | 3021 | | { |
| 0 | 3022 | | select = jobListFromJobScheduleOptions.Select; |
| | 3023 | | } |
| 0 | 3024 | | string expand = default(string); |
| 0 | 3025 | | if (jobListFromJobScheduleOptions != null) |
| | 3026 | | { |
| 0 | 3027 | | expand = jobListFromJobScheduleOptions.Expand; |
| | 3028 | | } |
| 0 | 3029 | | int? maxResults = default(int?); |
| 0 | 3030 | | if (jobListFromJobScheduleOptions != null) |
| | 3031 | | { |
| 0 | 3032 | | maxResults = jobListFromJobScheduleOptions.MaxResults; |
| | 3033 | | } |
| 0 | 3034 | | int? timeout = default(int?); |
| 0 | 3035 | | if (jobListFromJobScheduleOptions != null) |
| | 3036 | | { |
| 0 | 3037 | | timeout = jobListFromJobScheduleOptions.Timeout; |
| | 3038 | | } |
| 0 | 3039 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 3040 | | if (jobListFromJobScheduleOptions != null) |
| | 3041 | | { |
| 0 | 3042 | | clientRequestId = jobListFromJobScheduleOptions.ClientRequestId; |
| | 3043 | | } |
| 0 | 3044 | | bool? returnClientRequestId = default(bool?); |
| 0 | 3045 | | if (jobListFromJobScheduleOptions != null) |
| | 3046 | | { |
| 0 | 3047 | | returnClientRequestId = jobListFromJobScheduleOptions.ReturnClientRequestId; |
| | 3048 | | } |
| 0 | 3049 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 3050 | | if (jobListFromJobScheduleOptions != null) |
| | 3051 | | { |
| 0 | 3052 | | ocpDate = jobListFromJobScheduleOptions.OcpDate; |
| | 3053 | | } |
| | 3054 | | // Tracing |
| 0 | 3055 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 3056 | | string _invocationId = null; |
| 0 | 3057 | | if (_shouldTrace) |
| | 3058 | | { |
| 0 | 3059 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3060 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3061 | | tracingParameters.Add("jobScheduleId", jobScheduleId); |
| 0 | 3062 | | tracingParameters.Add("filter", filter); |
| 0 | 3063 | | tracingParameters.Add("select", select); |
| 0 | 3064 | | tracingParameters.Add("expand", expand); |
| 0 | 3065 | | tracingParameters.Add("maxResults", maxResults); |
| 0 | 3066 | | tracingParameters.Add("timeout", timeout); |
| 0 | 3067 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 3068 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 3069 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 3070 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3071 | | ServiceClientTracing.Enter(_invocationId, this, "ListFromJobSchedule", tracingParameters); |
| | 3072 | | } |
| | 3073 | | // Construct URL |
| 0 | 3074 | | var _baseUrl = Client.BaseUri; |
| 0 | 3075 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobschedules/{jobScheduleId}/jobs"; |
| 0 | 3076 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 3077 | | _url = _url.Replace("{jobScheduleId}", System.Uri.EscapeDataString(jobScheduleId)); |
| 0 | 3078 | | List<string> _queryParameters = new List<string>(); |
| 0 | 3079 | | if (Client.ApiVersion != null) |
| | 3080 | | { |
| 0 | 3081 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 3082 | | } |
| 0 | 3083 | | if (filter != null) |
| | 3084 | | { |
| 0 | 3085 | | _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter))); |
| | 3086 | | } |
| 0 | 3087 | | if (select != null) |
| | 3088 | | { |
| 0 | 3089 | | _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select))); |
| | 3090 | | } |
| 0 | 3091 | | if (expand != null) |
| | 3092 | | { |
| 0 | 3093 | | _queryParameters.Add(string.Format("$expand={0}", System.Uri.EscapeDataString(expand))); |
| | 3094 | | } |
| 0 | 3095 | | if (maxResults != null) |
| | 3096 | | { |
| 0 | 3097 | | _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali |
| | 3098 | | } |
| 0 | 3099 | | if (timeout != null) |
| | 3100 | | { |
| 0 | 3101 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 3102 | | } |
| 0 | 3103 | | if (_queryParameters.Count > 0) |
| | 3104 | | { |
| 0 | 3105 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 3106 | | } |
| | 3107 | | // Create HTTP transport objects |
| 0 | 3108 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 3109 | | HttpResponseMessage _httpResponse = null; |
| 0 | 3110 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 3111 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3112 | | // Set Headers |
| 0 | 3113 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 3114 | | { |
| 0 | 3115 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 3116 | | } |
| 0 | 3117 | | if (Client.AcceptLanguage != null) |
| | 3118 | | { |
| 0 | 3119 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 3120 | | { |
| 0 | 3121 | | _httpRequest.Headers.Remove("accept-language"); |
| | 3122 | | } |
| 0 | 3123 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 3124 | | } |
| 0 | 3125 | | if (clientRequestId != null) |
| | 3126 | | { |
| 0 | 3127 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 3128 | | { |
| 0 | 3129 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 3130 | | } |
| 0 | 3131 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 3132 | | } |
| 0 | 3133 | | if (returnClientRequestId != null) |
| | 3134 | | { |
| 0 | 3135 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 3136 | | { |
| 0 | 3137 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 3138 | | } |
| 0 | 3139 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 3140 | | } |
| 0 | 3141 | | if (ocpDate != null) |
| | 3142 | | { |
| 0 | 3143 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 3144 | | { |
| 0 | 3145 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 3146 | | } |
| 0 | 3147 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 3148 | | } |
| | 3149 | |
|
| | 3150 | |
|
| 0 | 3151 | | if (customHeaders != null) |
| | 3152 | | { |
| 0 | 3153 | | foreach(var _header in customHeaders) |
| | 3154 | | { |
| 0 | 3155 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3156 | | { |
| 0 | 3157 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3158 | | } |
| 0 | 3159 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3160 | | } |
| | 3161 | | } |
| | 3162 | |
|
| | 3163 | | // Serialize Request |
| 0 | 3164 | | string _requestContent = null; |
| | 3165 | | // Set Credentials |
| 0 | 3166 | | if (Client.Credentials != null) |
| | 3167 | | { |
| 0 | 3168 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3169 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3170 | | } |
| | 3171 | | // Send Request |
| 0 | 3172 | | if (_shouldTrace) |
| | 3173 | | { |
| 0 | 3174 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3175 | | } |
| 0 | 3176 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3177 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 3178 | | if (_shouldTrace) |
| | 3179 | | { |
| 0 | 3180 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3181 | | } |
| 0 | 3182 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 3183 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3184 | | string _responseContent = null; |
| 0 | 3185 | | if ((int)_statusCode != 200) |
| | 3186 | | { |
| 0 | 3187 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 3188 | | try |
| | 3189 | | { |
| 0 | 3190 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3191 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 3192 | | if (_errorBody != null) |
| | 3193 | | { |
| 0 | 3194 | | ex.Body = _errorBody; |
| | 3195 | | } |
| 0 | 3196 | | } |
| 0 | 3197 | | catch (JsonException) |
| | 3198 | | { |
| | 3199 | | // Ignore the exception |
| 0 | 3200 | | } |
| 0 | 3201 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3202 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3203 | | if (_shouldTrace) |
| | 3204 | | { |
| 0 | 3205 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3206 | | } |
| 0 | 3207 | | _httpRequest.Dispose(); |
| 0 | 3208 | | if (_httpResponse != null) |
| | 3209 | | { |
| 0 | 3210 | | _httpResponse.Dispose(); |
| | 3211 | | } |
| 0 | 3212 | | throw ex; |
| | 3213 | | } |
| | 3214 | | // Create Result |
| 0 | 3215 | | var _result = new AzureOperationResponse<IPage<CloudJob>,JobListFromJobScheduleHeaders>(); |
| 0 | 3216 | | _result.Request = _httpRequest; |
| 0 | 3217 | | _result.Response = _httpResponse; |
| 0 | 3218 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 3219 | | { |
| 0 | 3220 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 3221 | | } |
| | 3222 | | // Deserialize Response |
| 0 | 3223 | | if ((int)_statusCode == 200) |
| | 3224 | | { |
| 0 | 3225 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3226 | | try |
| | 3227 | | { |
| 0 | 3228 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<CloudJob>>(_responseContent, Client.Deserializ |
| 0 | 3229 | | } |
| 0 | 3230 | | catch (JsonException ex) |
| | 3231 | | { |
| 0 | 3232 | | _httpRequest.Dispose(); |
| 0 | 3233 | | if (_httpResponse != null) |
| | 3234 | | { |
| 0 | 3235 | | _httpResponse.Dispose(); |
| | 3236 | | } |
| 0 | 3237 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3238 | | } |
| | 3239 | | } |
| | 3240 | | try |
| | 3241 | | { |
| 0 | 3242 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobListFromJobScheduleHeaders>(JsonSerialize |
| 0 | 3243 | | } |
| 0 | 3244 | | catch (JsonException ex) |
| | 3245 | | { |
| 0 | 3246 | | _httpRequest.Dispose(); |
| 0 | 3247 | | if (_httpResponse != null) |
| | 3248 | | { |
| 0 | 3249 | | _httpResponse.Dispose(); |
| | 3250 | | } |
| 0 | 3251 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 3252 | | } |
| 0 | 3253 | | if (_shouldTrace) |
| | 3254 | | { |
| 0 | 3255 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3256 | | } |
| 0 | 3257 | | return _result; |
| 0 | 3258 | | } |
| | 3259 | |
|
| | 3260 | | /// <summary> |
| | 3261 | | /// Lists the execution status of the Job Preparation and Job Release Task for |
| | 3262 | | /// the specified Job across the Compute Nodes where the Job has run. |
| | 3263 | | /// </summary> |
| | 3264 | | /// <remarks> |
| | 3265 | | /// This API returns the Job Preparation and Job Release Task status on all |
| | 3266 | | /// Compute Nodes that have run the Job Preparation or Job Release Task. This |
| | 3267 | | /// includes Compute Nodes which have since been removed from the Pool. If this |
| | 3268 | | /// API is invoked on a Job which has no Job Preparation or Job Release Task, |
| | 3269 | | /// the Batch service returns HTTP status code 409 (Conflict) with an error |
| | 3270 | | /// code of JobPreparationTaskNotSpecified. |
| | 3271 | | /// </remarks> |
| | 3272 | | /// <param name='jobId'> |
| | 3273 | | /// The ID of the Job. |
| | 3274 | | /// </param> |
| | 3275 | | /// <param name='jobListPreparationAndReleaseTaskStatusOptions'> |
| | 3276 | | /// Additional parameters for the operation |
| | 3277 | | /// </param> |
| | 3278 | | /// <param name='customHeaders'> |
| | 3279 | | /// Headers that will be added to request. |
| | 3280 | | /// </param> |
| | 3281 | | /// <param name='cancellationToken'> |
| | 3282 | | /// The cancellation token. |
| | 3283 | | /// </param> |
| | 3284 | | /// <exception cref="BatchErrorException"> |
| | 3285 | | /// Thrown when the operation returned an invalid status code |
| | 3286 | | /// </exception> |
| | 3287 | | /// <exception cref="SerializationException"> |
| | 3288 | | /// Thrown when unable to deserialize the response |
| | 3289 | | /// </exception> |
| | 3290 | | /// <exception cref="ValidationException"> |
| | 3291 | | /// Thrown when a required parameter is null |
| | 3292 | | /// </exception> |
| | 3293 | | /// <exception cref="System.ArgumentNullException"> |
| | 3294 | | /// Thrown when a required parameter is null |
| | 3295 | | /// </exception> |
| | 3296 | | /// <return> |
| | 3297 | | /// A response object containing the response body and response headers. |
| | 3298 | | /// </return> |
| | 3299 | | public async Task<AzureOperationResponse<IPage<JobPreparationAndReleaseTaskExecutionInformation>,JobListPreparat |
| | 3300 | | { |
| 0 | 3301 | | if (Client.BatchUrl == null) |
| | 3302 | | { |
| 0 | 3303 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 3304 | | } |
| 0 | 3305 | | if (jobId == null) |
| | 3306 | | { |
| 0 | 3307 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobId"); |
| | 3308 | | } |
| 0 | 3309 | | if (Client.ApiVersion == null) |
| | 3310 | | { |
| 0 | 3311 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 3312 | | } |
| 0 | 3313 | | string filter = default(string); |
| 0 | 3314 | | if (jobListPreparationAndReleaseTaskStatusOptions != null) |
| | 3315 | | { |
| 0 | 3316 | | filter = jobListPreparationAndReleaseTaskStatusOptions.Filter; |
| | 3317 | | } |
| 0 | 3318 | | string select = default(string); |
| 0 | 3319 | | if (jobListPreparationAndReleaseTaskStatusOptions != null) |
| | 3320 | | { |
| 0 | 3321 | | select = jobListPreparationAndReleaseTaskStatusOptions.Select; |
| | 3322 | | } |
| 0 | 3323 | | int? maxResults = default(int?); |
| 0 | 3324 | | if (jobListPreparationAndReleaseTaskStatusOptions != null) |
| | 3325 | | { |
| 0 | 3326 | | maxResults = jobListPreparationAndReleaseTaskStatusOptions.MaxResults; |
| | 3327 | | } |
| 0 | 3328 | | int? timeout = default(int?); |
| 0 | 3329 | | if (jobListPreparationAndReleaseTaskStatusOptions != null) |
| | 3330 | | { |
| 0 | 3331 | | timeout = jobListPreparationAndReleaseTaskStatusOptions.Timeout; |
| | 3332 | | } |
| 0 | 3333 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 3334 | | if (jobListPreparationAndReleaseTaskStatusOptions != null) |
| | 3335 | | { |
| 0 | 3336 | | clientRequestId = jobListPreparationAndReleaseTaskStatusOptions.ClientRequestId; |
| | 3337 | | } |
| 0 | 3338 | | bool? returnClientRequestId = default(bool?); |
| 0 | 3339 | | if (jobListPreparationAndReleaseTaskStatusOptions != null) |
| | 3340 | | { |
| 0 | 3341 | | returnClientRequestId = jobListPreparationAndReleaseTaskStatusOptions.ReturnClientRequestId; |
| | 3342 | | } |
| 0 | 3343 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 3344 | | if (jobListPreparationAndReleaseTaskStatusOptions != null) |
| | 3345 | | { |
| 0 | 3346 | | ocpDate = jobListPreparationAndReleaseTaskStatusOptions.OcpDate; |
| | 3347 | | } |
| | 3348 | | // Tracing |
| 0 | 3349 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 3350 | | string _invocationId = null; |
| 0 | 3351 | | if (_shouldTrace) |
| | 3352 | | { |
| 0 | 3353 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3354 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3355 | | tracingParameters.Add("jobId", jobId); |
| 0 | 3356 | | tracingParameters.Add("filter", filter); |
| 0 | 3357 | | tracingParameters.Add("select", select); |
| 0 | 3358 | | tracingParameters.Add("maxResults", maxResults); |
| 0 | 3359 | | tracingParameters.Add("timeout", timeout); |
| 0 | 3360 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 3361 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 3362 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 3363 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3364 | | ServiceClientTracing.Enter(_invocationId, this, "ListPreparationAndReleaseTaskStatus", tracingParameters |
| | 3365 | | } |
| | 3366 | | // Construct URL |
| 0 | 3367 | | var _baseUrl = Client.BaseUri; |
| 0 | 3368 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/jobpreparationandreleasetaskstatus |
| 0 | 3369 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 3370 | | _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId)); |
| 0 | 3371 | | List<string> _queryParameters = new List<string>(); |
| 0 | 3372 | | if (Client.ApiVersion != null) |
| | 3373 | | { |
| 0 | 3374 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 3375 | | } |
| 0 | 3376 | | if (filter != null) |
| | 3377 | | { |
| 0 | 3378 | | _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter))); |
| | 3379 | | } |
| 0 | 3380 | | if (select != null) |
| | 3381 | | { |
| 0 | 3382 | | _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select))); |
| | 3383 | | } |
| 0 | 3384 | | if (maxResults != null) |
| | 3385 | | { |
| 0 | 3386 | | _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali |
| | 3387 | | } |
| 0 | 3388 | | if (timeout != null) |
| | 3389 | | { |
| 0 | 3390 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 3391 | | } |
| 0 | 3392 | | if (_queryParameters.Count > 0) |
| | 3393 | | { |
| 0 | 3394 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 3395 | | } |
| | 3396 | | // Create HTTP transport objects |
| 0 | 3397 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 3398 | | HttpResponseMessage _httpResponse = null; |
| 0 | 3399 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 3400 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3401 | | // Set Headers |
| 0 | 3402 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 3403 | | { |
| 0 | 3404 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 3405 | | } |
| 0 | 3406 | | if (Client.AcceptLanguage != null) |
| | 3407 | | { |
| 0 | 3408 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 3409 | | { |
| 0 | 3410 | | _httpRequest.Headers.Remove("accept-language"); |
| | 3411 | | } |
| 0 | 3412 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 3413 | | } |
| 0 | 3414 | | if (clientRequestId != null) |
| | 3415 | | { |
| 0 | 3416 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 3417 | | { |
| 0 | 3418 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 3419 | | } |
| 0 | 3420 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 3421 | | } |
| 0 | 3422 | | if (returnClientRequestId != null) |
| | 3423 | | { |
| 0 | 3424 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 3425 | | { |
| 0 | 3426 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 3427 | | } |
| 0 | 3428 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 3429 | | } |
| 0 | 3430 | | if (ocpDate != null) |
| | 3431 | | { |
| 0 | 3432 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 3433 | | { |
| 0 | 3434 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 3435 | | } |
| 0 | 3436 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 3437 | | } |
| | 3438 | |
|
| | 3439 | |
|
| 0 | 3440 | | if (customHeaders != null) |
| | 3441 | | { |
| 0 | 3442 | | foreach(var _header in customHeaders) |
| | 3443 | | { |
| 0 | 3444 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3445 | | { |
| 0 | 3446 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3447 | | } |
| 0 | 3448 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3449 | | } |
| | 3450 | | } |
| | 3451 | |
|
| | 3452 | | // Serialize Request |
| 0 | 3453 | | string _requestContent = null; |
| | 3454 | | // Set Credentials |
| 0 | 3455 | | if (Client.Credentials != null) |
| | 3456 | | { |
| 0 | 3457 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3458 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3459 | | } |
| | 3460 | | // Send Request |
| 0 | 3461 | | if (_shouldTrace) |
| | 3462 | | { |
| 0 | 3463 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3464 | | } |
| 0 | 3465 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3466 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 3467 | | if (_shouldTrace) |
| | 3468 | | { |
| 0 | 3469 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3470 | | } |
| 0 | 3471 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 3472 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3473 | | string _responseContent = null; |
| 0 | 3474 | | if ((int)_statusCode != 200) |
| | 3475 | | { |
| 0 | 3476 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 3477 | | try |
| | 3478 | | { |
| 0 | 3479 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3480 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 3481 | | if (_errorBody != null) |
| | 3482 | | { |
| 0 | 3483 | | ex.Body = _errorBody; |
| | 3484 | | } |
| 0 | 3485 | | } |
| 0 | 3486 | | catch (JsonException) |
| | 3487 | | { |
| | 3488 | | // Ignore the exception |
| 0 | 3489 | | } |
| 0 | 3490 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3491 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3492 | | if (_shouldTrace) |
| | 3493 | | { |
| 0 | 3494 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3495 | | } |
| 0 | 3496 | | _httpRequest.Dispose(); |
| 0 | 3497 | | if (_httpResponse != null) |
| | 3498 | | { |
| 0 | 3499 | | _httpResponse.Dispose(); |
| | 3500 | | } |
| 0 | 3501 | | throw ex; |
| | 3502 | | } |
| | 3503 | | // Create Result |
| 0 | 3504 | | var _result = new AzureOperationResponse<IPage<JobPreparationAndReleaseTaskExecutionInformation>,JobListPrep |
| 0 | 3505 | | _result.Request = _httpRequest; |
| 0 | 3506 | | _result.Response = _httpResponse; |
| 0 | 3507 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 3508 | | { |
| 0 | 3509 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 3510 | | } |
| | 3511 | | // Deserialize Response |
| 0 | 3512 | | if ((int)_statusCode == 200) |
| | 3513 | | { |
| 0 | 3514 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3515 | | try |
| | 3516 | | { |
| 0 | 3517 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<JobPreparationAndReleaseTaskExecutionInformati |
| 0 | 3518 | | } |
| 0 | 3519 | | catch (JsonException ex) |
| | 3520 | | { |
| 0 | 3521 | | _httpRequest.Dispose(); |
| 0 | 3522 | | if (_httpResponse != null) |
| | 3523 | | { |
| 0 | 3524 | | _httpResponse.Dispose(); |
| | 3525 | | } |
| 0 | 3526 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3527 | | } |
| | 3528 | | } |
| | 3529 | | try |
| | 3530 | | { |
| 0 | 3531 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobListPreparationAndReleaseTaskStatusHeader |
| 0 | 3532 | | } |
| 0 | 3533 | | catch (JsonException ex) |
| | 3534 | | { |
| 0 | 3535 | | _httpRequest.Dispose(); |
| 0 | 3536 | | if (_httpResponse != null) |
| | 3537 | | { |
| 0 | 3538 | | _httpResponse.Dispose(); |
| | 3539 | | } |
| 0 | 3540 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 3541 | | } |
| 0 | 3542 | | if (_shouldTrace) |
| | 3543 | | { |
| 0 | 3544 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3545 | | } |
| 0 | 3546 | | return _result; |
| 0 | 3547 | | } |
| | 3548 | |
|
| | 3549 | | /// <summary> |
| | 3550 | | /// Gets the Task counts for the specified Job. |
| | 3551 | | /// </summary> |
| | 3552 | | /// <remarks> |
| | 3553 | | /// Task counts provide a count of the Tasks by active, running or completed |
| | 3554 | | /// Task state, and a count of Tasks which succeeded or failed. Tasks in the |
| | 3555 | | /// preparing state are counted as running. |
| | 3556 | | /// </remarks> |
| | 3557 | | /// <param name='jobId'> |
| | 3558 | | /// The ID of the Job. |
| | 3559 | | /// </param> |
| | 3560 | | /// <param name='jobGetTaskCountsOptions'> |
| | 3561 | | /// Additional parameters for the operation |
| | 3562 | | /// </param> |
| | 3563 | | /// <param name='customHeaders'> |
| | 3564 | | /// Headers that will be added to request. |
| | 3565 | | /// </param> |
| | 3566 | | /// <param name='cancellationToken'> |
| | 3567 | | /// The cancellation token. |
| | 3568 | | /// </param> |
| | 3569 | | /// <exception cref="BatchErrorException"> |
| | 3570 | | /// Thrown when the operation returned an invalid status code |
| | 3571 | | /// </exception> |
| | 3572 | | /// <exception cref="SerializationException"> |
| | 3573 | | /// Thrown when unable to deserialize the response |
| | 3574 | | /// </exception> |
| | 3575 | | /// <exception cref="ValidationException"> |
| | 3576 | | /// Thrown when a required parameter is null |
| | 3577 | | /// </exception> |
| | 3578 | | /// <exception cref="System.ArgumentNullException"> |
| | 3579 | | /// Thrown when a required parameter is null |
| | 3580 | | /// </exception> |
| | 3581 | | /// <return> |
| | 3582 | | /// A response object containing the response body and response headers. |
| | 3583 | | /// </return> |
| | 3584 | | public async Task<AzureOperationResponse<TaskCounts,JobGetTaskCountsHeaders>> GetTaskCountsWithHttpMessagesAsync |
| | 3585 | | { |
| 0 | 3586 | | if (Client.BatchUrl == null) |
| | 3587 | | { |
| 0 | 3588 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 3589 | | } |
| 0 | 3590 | | if (jobId == null) |
| | 3591 | | { |
| 0 | 3592 | | throw new ValidationException(ValidationRules.CannotBeNull, "jobId"); |
| | 3593 | | } |
| 0 | 3594 | | if (Client.ApiVersion == null) |
| | 3595 | | { |
| 0 | 3596 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 3597 | | } |
| 0 | 3598 | | int? timeout = default(int?); |
| 0 | 3599 | | if (jobGetTaskCountsOptions != null) |
| | 3600 | | { |
| 0 | 3601 | | timeout = jobGetTaskCountsOptions.Timeout; |
| | 3602 | | } |
| 0 | 3603 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 3604 | | if (jobGetTaskCountsOptions != null) |
| | 3605 | | { |
| 0 | 3606 | | clientRequestId = jobGetTaskCountsOptions.ClientRequestId; |
| | 3607 | | } |
| 0 | 3608 | | bool? returnClientRequestId = default(bool?); |
| 0 | 3609 | | if (jobGetTaskCountsOptions != null) |
| | 3610 | | { |
| 0 | 3611 | | returnClientRequestId = jobGetTaskCountsOptions.ReturnClientRequestId; |
| | 3612 | | } |
| 0 | 3613 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 3614 | | if (jobGetTaskCountsOptions != null) |
| | 3615 | | { |
| 0 | 3616 | | ocpDate = jobGetTaskCountsOptions.OcpDate; |
| | 3617 | | } |
| | 3618 | | // Tracing |
| 0 | 3619 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 3620 | | string _invocationId = null; |
| 0 | 3621 | | if (_shouldTrace) |
| | 3622 | | { |
| 0 | 3623 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3624 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3625 | | tracingParameters.Add("jobId", jobId); |
| 0 | 3626 | | tracingParameters.Add("timeout", timeout); |
| 0 | 3627 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 3628 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 3629 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 3630 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3631 | | ServiceClientTracing.Enter(_invocationId, this, "GetTaskCounts", tracingParameters); |
| | 3632 | | } |
| | 3633 | | // Construct URL |
| 0 | 3634 | | var _baseUrl = Client.BaseUri; |
| 0 | 3635 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/taskcounts"; |
| 0 | 3636 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 3637 | | _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId)); |
| 0 | 3638 | | List<string> _queryParameters = new List<string>(); |
| 0 | 3639 | | if (Client.ApiVersion != null) |
| | 3640 | | { |
| 0 | 3641 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 3642 | | } |
| 0 | 3643 | | if (timeout != null) |
| | 3644 | | { |
| 0 | 3645 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 3646 | | } |
| 0 | 3647 | | if (_queryParameters.Count > 0) |
| | 3648 | | { |
| 0 | 3649 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 3650 | | } |
| | 3651 | | // Create HTTP transport objects |
| 0 | 3652 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 3653 | | HttpResponseMessage _httpResponse = null; |
| 0 | 3654 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 3655 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3656 | | // Set Headers |
| 0 | 3657 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 3658 | | { |
| 0 | 3659 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 3660 | | } |
| 0 | 3661 | | if (Client.AcceptLanguage != null) |
| | 3662 | | { |
| 0 | 3663 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 3664 | | { |
| 0 | 3665 | | _httpRequest.Headers.Remove("accept-language"); |
| | 3666 | | } |
| 0 | 3667 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 3668 | | } |
| 0 | 3669 | | if (clientRequestId != null) |
| | 3670 | | { |
| 0 | 3671 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 3672 | | { |
| 0 | 3673 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 3674 | | } |
| 0 | 3675 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 3676 | | } |
| 0 | 3677 | | if (returnClientRequestId != null) |
| | 3678 | | { |
| 0 | 3679 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 3680 | | { |
| 0 | 3681 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 3682 | | } |
| 0 | 3683 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 3684 | | } |
| 0 | 3685 | | if (ocpDate != null) |
| | 3686 | | { |
| 0 | 3687 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 3688 | | { |
| 0 | 3689 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 3690 | | } |
| 0 | 3691 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 3692 | | } |
| | 3693 | |
|
| | 3694 | |
|
| 0 | 3695 | | if (customHeaders != null) |
| | 3696 | | { |
| 0 | 3697 | | foreach(var _header in customHeaders) |
| | 3698 | | { |
| 0 | 3699 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3700 | | { |
| 0 | 3701 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3702 | | } |
| 0 | 3703 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3704 | | } |
| | 3705 | | } |
| | 3706 | |
|
| | 3707 | | // Serialize Request |
| 0 | 3708 | | string _requestContent = null; |
| | 3709 | | // Set Credentials |
| 0 | 3710 | | if (Client.Credentials != null) |
| | 3711 | | { |
| 0 | 3712 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3713 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3714 | | } |
| | 3715 | | // Send Request |
| 0 | 3716 | | if (_shouldTrace) |
| | 3717 | | { |
| 0 | 3718 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3719 | | } |
| 0 | 3720 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3721 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 3722 | | if (_shouldTrace) |
| | 3723 | | { |
| 0 | 3724 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3725 | | } |
| 0 | 3726 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 3727 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3728 | | string _responseContent = null; |
| 0 | 3729 | | if ((int)_statusCode != 200) |
| | 3730 | | { |
| 0 | 3731 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 3732 | | try |
| | 3733 | | { |
| 0 | 3734 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3735 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 3736 | | if (_errorBody != null) |
| | 3737 | | { |
| 0 | 3738 | | ex.Body = _errorBody; |
| | 3739 | | } |
| 0 | 3740 | | } |
| 0 | 3741 | | catch (JsonException) |
| | 3742 | | { |
| | 3743 | | // Ignore the exception |
| 0 | 3744 | | } |
| 0 | 3745 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3746 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3747 | | if (_shouldTrace) |
| | 3748 | | { |
| 0 | 3749 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3750 | | } |
| 0 | 3751 | | _httpRequest.Dispose(); |
| 0 | 3752 | | if (_httpResponse != null) |
| | 3753 | | { |
| 0 | 3754 | | _httpResponse.Dispose(); |
| | 3755 | | } |
| 0 | 3756 | | throw ex; |
| | 3757 | | } |
| | 3758 | | // Create Result |
| 0 | 3759 | | var _result = new AzureOperationResponse<TaskCounts,JobGetTaskCountsHeaders>(); |
| 0 | 3760 | | _result.Request = _httpRequest; |
| 0 | 3761 | | _result.Response = _httpResponse; |
| 0 | 3762 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 3763 | | { |
| 0 | 3764 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 3765 | | } |
| | 3766 | | // Deserialize Response |
| 0 | 3767 | | if ((int)_statusCode == 200) |
| | 3768 | | { |
| 0 | 3769 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3770 | | try |
| | 3771 | | { |
| 0 | 3772 | | _result.Body = SafeJsonConvert.DeserializeObject<TaskCounts>(_responseContent, Client.Deserializatio |
| 0 | 3773 | | } |
| 0 | 3774 | | catch (JsonException ex) |
| | 3775 | | { |
| 0 | 3776 | | _httpRequest.Dispose(); |
| 0 | 3777 | | if (_httpResponse != null) |
| | 3778 | | { |
| 0 | 3779 | | _httpResponse.Dispose(); |
| | 3780 | | } |
| 0 | 3781 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3782 | | } |
| | 3783 | | } |
| | 3784 | | try |
| | 3785 | | { |
| 0 | 3786 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobGetTaskCountsHeaders>(JsonSerializer.Crea |
| 0 | 3787 | | } |
| 0 | 3788 | | catch (JsonException ex) |
| | 3789 | | { |
| 0 | 3790 | | _httpRequest.Dispose(); |
| 0 | 3791 | | if (_httpResponse != null) |
| | 3792 | | { |
| 0 | 3793 | | _httpResponse.Dispose(); |
| | 3794 | | } |
| 0 | 3795 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 3796 | | } |
| 0 | 3797 | | if (_shouldTrace) |
| | 3798 | | { |
| 0 | 3799 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3800 | | } |
| 0 | 3801 | | return _result; |
| 0 | 3802 | | } |
| | 3803 | |
|
| | 3804 | | /// <summary> |
| | 3805 | | /// Lists all of the Jobs in the specified Account. |
| | 3806 | | /// </summary> |
| | 3807 | | /// <param name='nextPageLink'> |
| | 3808 | | /// The NextLink from the previous successful call to List operation. |
| | 3809 | | /// </param> |
| | 3810 | | /// <param name='jobListNextOptions'> |
| | 3811 | | /// Additional parameters for the operation |
| | 3812 | | /// </param> |
| | 3813 | | /// <param name='customHeaders'> |
| | 3814 | | /// Headers that will be added to request. |
| | 3815 | | /// </param> |
| | 3816 | | /// <param name='cancellationToken'> |
| | 3817 | | /// The cancellation token. |
| | 3818 | | /// </param> |
| | 3819 | | /// <exception cref="BatchErrorException"> |
| | 3820 | | /// Thrown when the operation returned an invalid status code |
| | 3821 | | /// </exception> |
| | 3822 | | /// <exception cref="SerializationException"> |
| | 3823 | | /// Thrown when unable to deserialize the response |
| | 3824 | | /// </exception> |
| | 3825 | | /// <exception cref="ValidationException"> |
| | 3826 | | /// Thrown when a required parameter is null |
| | 3827 | | /// </exception> |
| | 3828 | | /// <exception cref="System.ArgumentNullException"> |
| | 3829 | | /// Thrown when a required parameter is null |
| | 3830 | | /// </exception> |
| | 3831 | | /// <return> |
| | 3832 | | /// A response object containing the response body and response headers. |
| | 3833 | | /// </return> |
| | 3834 | | public async Task<AzureOperationResponse<IPage<CloudJob>,JobListHeaders>> ListNextWithHttpMessagesAsync(string n |
| | 3835 | | { |
| 0 | 3836 | | if (nextPageLink == null) |
| | 3837 | | { |
| 0 | 3838 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); |
| | 3839 | | } |
| 0 | 3840 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 3841 | | if (jobListNextOptions != null) |
| | 3842 | | { |
| 0 | 3843 | | clientRequestId = jobListNextOptions.ClientRequestId; |
| | 3844 | | } |
| 0 | 3845 | | bool? returnClientRequestId = default(bool?); |
| 0 | 3846 | | if (jobListNextOptions != null) |
| | 3847 | | { |
| 0 | 3848 | | returnClientRequestId = jobListNextOptions.ReturnClientRequestId; |
| | 3849 | | } |
| 0 | 3850 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 3851 | | if (jobListNextOptions != null) |
| | 3852 | | { |
| 0 | 3853 | | ocpDate = jobListNextOptions.OcpDate; |
| | 3854 | | } |
| | 3855 | | // Tracing |
| 0 | 3856 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 3857 | | string _invocationId = null; |
| 0 | 3858 | | if (_shouldTrace) |
| | 3859 | | { |
| 0 | 3860 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3861 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3862 | | tracingParameters.Add("nextPageLink", nextPageLink); |
| 0 | 3863 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 3864 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 3865 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 3866 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3867 | | ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters); |
| | 3868 | | } |
| | 3869 | | // Construct URL |
| 0 | 3870 | | string _url = "{nextLink}"; |
| 0 | 3871 | | _url = _url.Replace("{nextLink}", nextPageLink); |
| 0 | 3872 | | List<string> _queryParameters = new List<string>(); |
| 0 | 3873 | | if (_queryParameters.Count > 0) |
| | 3874 | | { |
| 0 | 3875 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 3876 | | } |
| | 3877 | | // Create HTTP transport objects |
| 0 | 3878 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 3879 | | HttpResponseMessage _httpResponse = null; |
| 0 | 3880 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 3881 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3882 | | // Set Headers |
| 0 | 3883 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 3884 | | { |
| 0 | 3885 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 3886 | | } |
| 0 | 3887 | | if (Client.AcceptLanguage != null) |
| | 3888 | | { |
| 0 | 3889 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 3890 | | { |
| 0 | 3891 | | _httpRequest.Headers.Remove("accept-language"); |
| | 3892 | | } |
| 0 | 3893 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 3894 | | } |
| 0 | 3895 | | if (clientRequestId != null) |
| | 3896 | | { |
| 0 | 3897 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 3898 | | { |
| 0 | 3899 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 3900 | | } |
| 0 | 3901 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 3902 | | } |
| 0 | 3903 | | if (returnClientRequestId != null) |
| | 3904 | | { |
| 0 | 3905 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 3906 | | { |
| 0 | 3907 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 3908 | | } |
| 0 | 3909 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 3910 | | } |
| 0 | 3911 | | if (ocpDate != null) |
| | 3912 | | { |
| 0 | 3913 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 3914 | | { |
| 0 | 3915 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 3916 | | } |
| 0 | 3917 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 3918 | | } |
| | 3919 | |
|
| | 3920 | |
|
| 0 | 3921 | | if (customHeaders != null) |
| | 3922 | | { |
| 0 | 3923 | | foreach(var _header in customHeaders) |
| | 3924 | | { |
| 0 | 3925 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3926 | | { |
| 0 | 3927 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3928 | | } |
| 0 | 3929 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3930 | | } |
| | 3931 | | } |
| | 3932 | |
|
| | 3933 | | // Serialize Request |
| 0 | 3934 | | string _requestContent = null; |
| | 3935 | | // Set Credentials |
| 0 | 3936 | | if (Client.Credentials != null) |
| | 3937 | | { |
| 0 | 3938 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3939 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3940 | | } |
| | 3941 | | // Send Request |
| 0 | 3942 | | if (_shouldTrace) |
| | 3943 | | { |
| 0 | 3944 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3945 | | } |
| 0 | 3946 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3947 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 3948 | | if (_shouldTrace) |
| | 3949 | | { |
| 0 | 3950 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3951 | | } |
| 0 | 3952 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 3953 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3954 | | string _responseContent = null; |
| 0 | 3955 | | if ((int)_statusCode != 200) |
| | 3956 | | { |
| 0 | 3957 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 3958 | | try |
| | 3959 | | { |
| 0 | 3960 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3961 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 3962 | | if (_errorBody != null) |
| | 3963 | | { |
| 0 | 3964 | | ex.Body = _errorBody; |
| | 3965 | | } |
| 0 | 3966 | | } |
| 0 | 3967 | | catch (JsonException) |
| | 3968 | | { |
| | 3969 | | // Ignore the exception |
| 0 | 3970 | | } |
| 0 | 3971 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3972 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3973 | | if (_shouldTrace) |
| | 3974 | | { |
| 0 | 3975 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3976 | | } |
| 0 | 3977 | | _httpRequest.Dispose(); |
| 0 | 3978 | | if (_httpResponse != null) |
| | 3979 | | { |
| 0 | 3980 | | _httpResponse.Dispose(); |
| | 3981 | | } |
| 0 | 3982 | | throw ex; |
| | 3983 | | } |
| | 3984 | | // Create Result |
| 0 | 3985 | | var _result = new AzureOperationResponse<IPage<CloudJob>,JobListHeaders>(); |
| 0 | 3986 | | _result.Request = _httpRequest; |
| 0 | 3987 | | _result.Response = _httpResponse; |
| 0 | 3988 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 3989 | | { |
| 0 | 3990 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 3991 | | } |
| | 3992 | | // Deserialize Response |
| 0 | 3993 | | if ((int)_statusCode == 200) |
| | 3994 | | { |
| 0 | 3995 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3996 | | try |
| | 3997 | | { |
| 0 | 3998 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<CloudJob>>(_responseContent, Client.Deserializ |
| 0 | 3999 | | } |
| 0 | 4000 | | catch (JsonException ex) |
| | 4001 | | { |
| 0 | 4002 | | _httpRequest.Dispose(); |
| 0 | 4003 | | if (_httpResponse != null) |
| | 4004 | | { |
| 0 | 4005 | | _httpResponse.Dispose(); |
| | 4006 | | } |
| 0 | 4007 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4008 | | } |
| | 4009 | | } |
| | 4010 | | try |
| | 4011 | | { |
| 0 | 4012 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobListHeaders>(JsonSerializer.Create(Client |
| 0 | 4013 | | } |
| 0 | 4014 | | catch (JsonException ex) |
| | 4015 | | { |
| 0 | 4016 | | _httpRequest.Dispose(); |
| 0 | 4017 | | if (_httpResponse != null) |
| | 4018 | | { |
| 0 | 4019 | | _httpResponse.Dispose(); |
| | 4020 | | } |
| 0 | 4021 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 4022 | | } |
| 0 | 4023 | | if (_shouldTrace) |
| | 4024 | | { |
| 0 | 4025 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4026 | | } |
| 0 | 4027 | | return _result; |
| 0 | 4028 | | } |
| | 4029 | |
|
| | 4030 | | /// <summary> |
| | 4031 | | /// Lists the Jobs that have been created under the specified Job Schedule. |
| | 4032 | | /// </summary> |
| | 4033 | | /// <param name='nextPageLink'> |
| | 4034 | | /// The NextLink from the previous successful call to List operation. |
| | 4035 | | /// </param> |
| | 4036 | | /// <param name='jobListFromJobScheduleNextOptions'> |
| | 4037 | | /// Additional parameters for the operation |
| | 4038 | | /// </param> |
| | 4039 | | /// <param name='customHeaders'> |
| | 4040 | | /// Headers that will be added to request. |
| | 4041 | | /// </param> |
| | 4042 | | /// <param name='cancellationToken'> |
| | 4043 | | /// The cancellation token. |
| | 4044 | | /// </param> |
| | 4045 | | /// <exception cref="BatchErrorException"> |
| | 4046 | | /// Thrown when the operation returned an invalid status code |
| | 4047 | | /// </exception> |
| | 4048 | | /// <exception cref="SerializationException"> |
| | 4049 | | /// Thrown when unable to deserialize the response |
| | 4050 | | /// </exception> |
| | 4051 | | /// <exception cref="ValidationException"> |
| | 4052 | | /// Thrown when a required parameter is null |
| | 4053 | | /// </exception> |
| | 4054 | | /// <exception cref="System.ArgumentNullException"> |
| | 4055 | | /// Thrown when a required parameter is null |
| | 4056 | | /// </exception> |
| | 4057 | | /// <return> |
| | 4058 | | /// A response object containing the response body and response headers. |
| | 4059 | | /// </return> |
| | 4060 | | public async Task<AzureOperationResponse<IPage<CloudJob>,JobListFromJobScheduleHeaders>> ListFromJobScheduleNext |
| | 4061 | | { |
| 0 | 4062 | | if (nextPageLink == null) |
| | 4063 | | { |
| 0 | 4064 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); |
| | 4065 | | } |
| 0 | 4066 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 4067 | | if (jobListFromJobScheduleNextOptions != null) |
| | 4068 | | { |
| 0 | 4069 | | clientRequestId = jobListFromJobScheduleNextOptions.ClientRequestId; |
| | 4070 | | } |
| 0 | 4071 | | bool? returnClientRequestId = default(bool?); |
| 0 | 4072 | | if (jobListFromJobScheduleNextOptions != null) |
| | 4073 | | { |
| 0 | 4074 | | returnClientRequestId = jobListFromJobScheduleNextOptions.ReturnClientRequestId; |
| | 4075 | | } |
| 0 | 4076 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 4077 | | if (jobListFromJobScheduleNextOptions != null) |
| | 4078 | | { |
| 0 | 4079 | | ocpDate = jobListFromJobScheduleNextOptions.OcpDate; |
| | 4080 | | } |
| | 4081 | | // Tracing |
| 0 | 4082 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 4083 | | string _invocationId = null; |
| 0 | 4084 | | if (_shouldTrace) |
| | 4085 | | { |
| 0 | 4086 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4087 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4088 | | tracingParameters.Add("nextPageLink", nextPageLink); |
| 0 | 4089 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 4090 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 4091 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 4092 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4093 | | ServiceClientTracing.Enter(_invocationId, this, "ListFromJobScheduleNext", tracingParameters); |
| | 4094 | | } |
| | 4095 | | // Construct URL |
| 0 | 4096 | | string _url = "{nextLink}"; |
| 0 | 4097 | | _url = _url.Replace("{nextLink}", nextPageLink); |
| 0 | 4098 | | List<string> _queryParameters = new List<string>(); |
| 0 | 4099 | | if (_queryParameters.Count > 0) |
| | 4100 | | { |
| 0 | 4101 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 4102 | | } |
| | 4103 | | // Create HTTP transport objects |
| 0 | 4104 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 4105 | | HttpResponseMessage _httpResponse = null; |
| 0 | 4106 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 4107 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4108 | | // Set Headers |
| 0 | 4109 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 4110 | | { |
| 0 | 4111 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 4112 | | } |
| 0 | 4113 | | if (Client.AcceptLanguage != null) |
| | 4114 | | { |
| 0 | 4115 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 4116 | | { |
| 0 | 4117 | | _httpRequest.Headers.Remove("accept-language"); |
| | 4118 | | } |
| 0 | 4119 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 4120 | | } |
| 0 | 4121 | | if (clientRequestId != null) |
| | 4122 | | { |
| 0 | 4123 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 4124 | | { |
| 0 | 4125 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 4126 | | } |
| 0 | 4127 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 4128 | | } |
| 0 | 4129 | | if (returnClientRequestId != null) |
| | 4130 | | { |
| 0 | 4131 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 4132 | | { |
| 0 | 4133 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 4134 | | } |
| 0 | 4135 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 4136 | | } |
| 0 | 4137 | | if (ocpDate != null) |
| | 4138 | | { |
| 0 | 4139 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 4140 | | { |
| 0 | 4141 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 4142 | | } |
| 0 | 4143 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 4144 | | } |
| | 4145 | |
|
| | 4146 | |
|
| 0 | 4147 | | if (customHeaders != null) |
| | 4148 | | { |
| 0 | 4149 | | foreach(var _header in customHeaders) |
| | 4150 | | { |
| 0 | 4151 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4152 | | { |
| 0 | 4153 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4154 | | } |
| 0 | 4155 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4156 | | } |
| | 4157 | | } |
| | 4158 | |
|
| | 4159 | | // Serialize Request |
| 0 | 4160 | | string _requestContent = null; |
| | 4161 | | // Set Credentials |
| 0 | 4162 | | if (Client.Credentials != null) |
| | 4163 | | { |
| 0 | 4164 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4165 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4166 | | } |
| | 4167 | | // Send Request |
| 0 | 4168 | | if (_shouldTrace) |
| | 4169 | | { |
| 0 | 4170 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4171 | | } |
| 0 | 4172 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4173 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 4174 | | if (_shouldTrace) |
| | 4175 | | { |
| 0 | 4176 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4177 | | } |
| 0 | 4178 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 4179 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4180 | | string _responseContent = null; |
| 0 | 4181 | | if ((int)_statusCode != 200) |
| | 4182 | | { |
| 0 | 4183 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 4184 | | try |
| | 4185 | | { |
| 0 | 4186 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4187 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 4188 | | if (_errorBody != null) |
| | 4189 | | { |
| 0 | 4190 | | ex.Body = _errorBody; |
| | 4191 | | } |
| 0 | 4192 | | } |
| 0 | 4193 | | catch (JsonException) |
| | 4194 | | { |
| | 4195 | | // Ignore the exception |
| 0 | 4196 | | } |
| 0 | 4197 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4198 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4199 | | if (_shouldTrace) |
| | 4200 | | { |
| 0 | 4201 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4202 | | } |
| 0 | 4203 | | _httpRequest.Dispose(); |
| 0 | 4204 | | if (_httpResponse != null) |
| | 4205 | | { |
| 0 | 4206 | | _httpResponse.Dispose(); |
| | 4207 | | } |
| 0 | 4208 | | throw ex; |
| | 4209 | | } |
| | 4210 | | // Create Result |
| 0 | 4211 | | var _result = new AzureOperationResponse<IPage<CloudJob>,JobListFromJobScheduleHeaders>(); |
| 0 | 4212 | | _result.Request = _httpRequest; |
| 0 | 4213 | | _result.Response = _httpResponse; |
| 0 | 4214 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 4215 | | { |
| 0 | 4216 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 4217 | | } |
| | 4218 | | // Deserialize Response |
| 0 | 4219 | | if ((int)_statusCode == 200) |
| | 4220 | | { |
| 0 | 4221 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4222 | | try |
| | 4223 | | { |
| 0 | 4224 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<CloudJob>>(_responseContent, Client.Deserializ |
| 0 | 4225 | | } |
| 0 | 4226 | | catch (JsonException ex) |
| | 4227 | | { |
| 0 | 4228 | | _httpRequest.Dispose(); |
| 0 | 4229 | | if (_httpResponse != null) |
| | 4230 | | { |
| 0 | 4231 | | _httpResponse.Dispose(); |
| | 4232 | | } |
| 0 | 4233 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4234 | | } |
| | 4235 | | } |
| | 4236 | | try |
| | 4237 | | { |
| 0 | 4238 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobListFromJobScheduleHeaders>(JsonSerialize |
| 0 | 4239 | | } |
| 0 | 4240 | | catch (JsonException ex) |
| | 4241 | | { |
| 0 | 4242 | | _httpRequest.Dispose(); |
| 0 | 4243 | | if (_httpResponse != null) |
| | 4244 | | { |
| 0 | 4245 | | _httpResponse.Dispose(); |
| | 4246 | | } |
| 0 | 4247 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 4248 | | } |
| 0 | 4249 | | if (_shouldTrace) |
| | 4250 | | { |
| 0 | 4251 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4252 | | } |
| 0 | 4253 | | return _result; |
| 0 | 4254 | | } |
| | 4255 | |
|
| | 4256 | | /// <summary> |
| | 4257 | | /// Lists the execution status of the Job Preparation and Job Release Task for |
| | 4258 | | /// the specified Job across the Compute Nodes where the Job has run. |
| | 4259 | | /// </summary> |
| | 4260 | | /// <remarks> |
| | 4261 | | /// This API returns the Job Preparation and Job Release Task status on all |
| | 4262 | | /// Compute Nodes that have run the Job Preparation or Job Release Task. This |
| | 4263 | | /// includes Compute Nodes which have since been removed from the Pool. If this |
| | 4264 | | /// API is invoked on a Job which has no Job Preparation or Job Release Task, |
| | 4265 | | /// the Batch service returns HTTP status code 409 (Conflict) with an error |
| | 4266 | | /// code of JobPreparationTaskNotSpecified. |
| | 4267 | | /// </remarks> |
| | 4268 | | /// <param name='nextPageLink'> |
| | 4269 | | /// The NextLink from the previous successful call to List operation. |
| | 4270 | | /// </param> |
| | 4271 | | /// <param name='jobListPreparationAndReleaseTaskStatusNextOptions'> |
| | 4272 | | /// Additional parameters for the operation |
| | 4273 | | /// </param> |
| | 4274 | | /// <param name='customHeaders'> |
| | 4275 | | /// Headers that will be added to request. |
| | 4276 | | /// </param> |
| | 4277 | | /// <param name='cancellationToken'> |
| | 4278 | | /// The cancellation token. |
| | 4279 | | /// </param> |
| | 4280 | | /// <exception cref="BatchErrorException"> |
| | 4281 | | /// Thrown when the operation returned an invalid status code |
| | 4282 | | /// </exception> |
| | 4283 | | /// <exception cref="SerializationException"> |
| | 4284 | | /// Thrown when unable to deserialize the response |
| | 4285 | | /// </exception> |
| | 4286 | | /// <exception cref="ValidationException"> |
| | 4287 | | /// Thrown when a required parameter is null |
| | 4288 | | /// </exception> |
| | 4289 | | /// <exception cref="System.ArgumentNullException"> |
| | 4290 | | /// Thrown when a required parameter is null |
| | 4291 | | /// </exception> |
| | 4292 | | /// <return> |
| | 4293 | | /// A response object containing the response body and response headers. |
| | 4294 | | /// </return> |
| | 4295 | | public async Task<AzureOperationResponse<IPage<JobPreparationAndReleaseTaskExecutionInformation>,JobListPreparat |
| | 4296 | | { |
| 0 | 4297 | | if (nextPageLink == null) |
| | 4298 | | { |
| 0 | 4299 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); |
| | 4300 | | } |
| 0 | 4301 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 4302 | | if (jobListPreparationAndReleaseTaskStatusNextOptions != null) |
| | 4303 | | { |
| 0 | 4304 | | clientRequestId = jobListPreparationAndReleaseTaskStatusNextOptions.ClientRequestId; |
| | 4305 | | } |
| 0 | 4306 | | bool? returnClientRequestId = default(bool?); |
| 0 | 4307 | | if (jobListPreparationAndReleaseTaskStatusNextOptions != null) |
| | 4308 | | { |
| 0 | 4309 | | returnClientRequestId = jobListPreparationAndReleaseTaskStatusNextOptions.ReturnClientRequestId; |
| | 4310 | | } |
| 0 | 4311 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 4312 | | if (jobListPreparationAndReleaseTaskStatusNextOptions != null) |
| | 4313 | | { |
| 0 | 4314 | | ocpDate = jobListPreparationAndReleaseTaskStatusNextOptions.OcpDate; |
| | 4315 | | } |
| | 4316 | | // Tracing |
| 0 | 4317 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 4318 | | string _invocationId = null; |
| 0 | 4319 | | if (_shouldTrace) |
| | 4320 | | { |
| 0 | 4321 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4322 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4323 | | tracingParameters.Add("nextPageLink", nextPageLink); |
| 0 | 4324 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 4325 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 4326 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 4327 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4328 | | ServiceClientTracing.Enter(_invocationId, this, "ListPreparationAndReleaseTaskStatusNext", tracingParame |
| | 4329 | | } |
| | 4330 | | // Construct URL |
| 0 | 4331 | | string _url = "{nextLink}"; |
| 0 | 4332 | | _url = _url.Replace("{nextLink}", nextPageLink); |
| 0 | 4333 | | List<string> _queryParameters = new List<string>(); |
| 0 | 4334 | | if (_queryParameters.Count > 0) |
| | 4335 | | { |
| 0 | 4336 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 4337 | | } |
| | 4338 | | // Create HTTP transport objects |
| 0 | 4339 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 4340 | | HttpResponseMessage _httpResponse = null; |
| 0 | 4341 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 4342 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4343 | | // Set Headers |
| 0 | 4344 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 4345 | | { |
| 0 | 4346 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 4347 | | } |
| 0 | 4348 | | if (Client.AcceptLanguage != null) |
| | 4349 | | { |
| 0 | 4350 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 4351 | | { |
| 0 | 4352 | | _httpRequest.Headers.Remove("accept-language"); |
| | 4353 | | } |
| 0 | 4354 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 4355 | | } |
| 0 | 4356 | | if (clientRequestId != null) |
| | 4357 | | { |
| 0 | 4358 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 4359 | | { |
| 0 | 4360 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 4361 | | } |
| 0 | 4362 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 4363 | | } |
| 0 | 4364 | | if (returnClientRequestId != null) |
| | 4365 | | { |
| 0 | 4366 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 4367 | | { |
| 0 | 4368 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 4369 | | } |
| 0 | 4370 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 4371 | | } |
| 0 | 4372 | | if (ocpDate != null) |
| | 4373 | | { |
| 0 | 4374 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 4375 | | { |
| 0 | 4376 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 4377 | | } |
| 0 | 4378 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 4379 | | } |
| | 4380 | |
|
| | 4381 | |
|
| 0 | 4382 | | if (customHeaders != null) |
| | 4383 | | { |
| 0 | 4384 | | foreach(var _header in customHeaders) |
| | 4385 | | { |
| 0 | 4386 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4387 | | { |
| 0 | 4388 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4389 | | } |
| 0 | 4390 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4391 | | } |
| | 4392 | | } |
| | 4393 | |
|
| | 4394 | | // Serialize Request |
| 0 | 4395 | | string _requestContent = null; |
| | 4396 | | // Set Credentials |
| 0 | 4397 | | if (Client.Credentials != null) |
| | 4398 | | { |
| 0 | 4399 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4400 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4401 | | } |
| | 4402 | | // Send Request |
| 0 | 4403 | | if (_shouldTrace) |
| | 4404 | | { |
| 0 | 4405 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4406 | | } |
| 0 | 4407 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4408 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 4409 | | if (_shouldTrace) |
| | 4410 | | { |
| 0 | 4411 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4412 | | } |
| 0 | 4413 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 4414 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 4415 | | string _responseContent = null; |
| 0 | 4416 | | if ((int)_statusCode != 200) |
| | 4417 | | { |
| 0 | 4418 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 4419 | | try |
| | 4420 | | { |
| 0 | 4421 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4422 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 4423 | | if (_errorBody != null) |
| | 4424 | | { |
| 0 | 4425 | | ex.Body = _errorBody; |
| | 4426 | | } |
| 0 | 4427 | | } |
| 0 | 4428 | | catch (JsonException) |
| | 4429 | | { |
| | 4430 | | // Ignore the exception |
| 0 | 4431 | | } |
| 0 | 4432 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4433 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4434 | | if (_shouldTrace) |
| | 4435 | | { |
| 0 | 4436 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4437 | | } |
| 0 | 4438 | | _httpRequest.Dispose(); |
| 0 | 4439 | | if (_httpResponse != null) |
| | 4440 | | { |
| 0 | 4441 | | _httpResponse.Dispose(); |
| | 4442 | | } |
| 0 | 4443 | | throw ex; |
| | 4444 | | } |
| | 4445 | | // Create Result |
| 0 | 4446 | | var _result = new AzureOperationResponse<IPage<JobPreparationAndReleaseTaskExecutionInformation>,JobListPrep |
| 0 | 4447 | | _result.Request = _httpRequest; |
| 0 | 4448 | | _result.Response = _httpResponse; |
| 0 | 4449 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 4450 | | { |
| 0 | 4451 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 4452 | | } |
| | 4453 | | // Deserialize Response |
| 0 | 4454 | | if ((int)_statusCode == 200) |
| | 4455 | | { |
| 0 | 4456 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4457 | | try |
| | 4458 | | { |
| 0 | 4459 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<JobPreparationAndReleaseTaskExecutionInformati |
| 0 | 4460 | | } |
| 0 | 4461 | | catch (JsonException ex) |
| | 4462 | | { |
| 0 | 4463 | | _httpRequest.Dispose(); |
| 0 | 4464 | | if (_httpResponse != null) |
| | 4465 | | { |
| 0 | 4466 | | _httpResponse.Dispose(); |
| | 4467 | | } |
| 0 | 4468 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4469 | | } |
| | 4470 | | } |
| | 4471 | | try |
| | 4472 | | { |
| 0 | 4473 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<JobListPreparationAndReleaseTaskStatusHeader |
| 0 | 4474 | | } |
| 0 | 4475 | | catch (JsonException ex) |
| | 4476 | | { |
| 0 | 4477 | | _httpRequest.Dispose(); |
| 0 | 4478 | | if (_httpResponse != null) |
| | 4479 | | { |
| 0 | 4480 | | _httpResponse.Dispose(); |
| | 4481 | | } |
| 0 | 4482 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 4483 | | } |
| 0 | 4484 | | if (_shouldTrace) |
| | 4485 | | { |
| 0 | 4486 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4487 | | } |
| 0 | 4488 | | return _result; |
| 0 | 4489 | | } |
| | 4490 | |
|
| | 4491 | | } |
| | 4492 | | } |