| | 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 | | /// AccountOperations operations. |
| | 28 | | /// </summary> |
| | 29 | | internal partial class AccountOperations : IServiceOperations<BatchServiceClient>, IAccountOperations |
| | 30 | | { |
| | 31 | | /// <summary> |
| | 32 | | /// Initializes a new instance of the AccountOperations 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 AccountOperations(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> |
| 0 | 52 | | public BatchServiceClient Client { get; private set; } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Lists all Virtual Machine Images supported by the Azure Batch service. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name='accountListSupportedImagesOptions'> |
| | 58 | | /// Additional parameters for the operation |
| | 59 | | /// </param> |
| | 60 | | /// <param name='customHeaders'> |
| | 61 | | /// Headers that will be added to request. |
| | 62 | | /// </param> |
| | 63 | | /// <param name='cancellationToken'> |
| | 64 | | /// The cancellation token. |
| | 65 | | /// </param> |
| | 66 | | /// <exception cref="BatchErrorException"> |
| | 67 | | /// Thrown when the operation returned an invalid status code |
| | 68 | | /// </exception> |
| | 69 | | /// <exception cref="SerializationException"> |
| | 70 | | /// Thrown when unable to deserialize the response |
| | 71 | | /// </exception> |
| | 72 | | /// <exception cref="ValidationException"> |
| | 73 | | /// Thrown when a required parameter is null |
| | 74 | | /// </exception> |
| | 75 | | /// <exception cref="System.ArgumentNullException"> |
| | 76 | | /// Thrown when a required parameter is null |
| | 77 | | /// </exception> |
| | 78 | | /// <return> |
| | 79 | | /// A response object containing the response body and response headers. |
| | 80 | | /// </return> |
| | 81 | | public async Task<AzureOperationResponse<IPage<ImageInformation>,AccountListSupportedImagesHeaders>> ListSupport |
| | 82 | | { |
| 0 | 83 | | if (Client.BatchUrl == null) |
| | 84 | | { |
| 0 | 85 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 86 | | } |
| 0 | 87 | | if (Client.ApiVersion == null) |
| | 88 | | { |
| 0 | 89 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 90 | | } |
| 0 | 91 | | string filter = default(string); |
| 0 | 92 | | if (accountListSupportedImagesOptions != null) |
| | 93 | | { |
| 0 | 94 | | filter = accountListSupportedImagesOptions.Filter; |
| | 95 | | } |
| 0 | 96 | | int? maxResults = default(int?); |
| 0 | 97 | | if (accountListSupportedImagesOptions != null) |
| | 98 | | { |
| 0 | 99 | | maxResults = accountListSupportedImagesOptions.MaxResults; |
| | 100 | | } |
| 0 | 101 | | int? timeout = default(int?); |
| 0 | 102 | | if (accountListSupportedImagesOptions != null) |
| | 103 | | { |
| 0 | 104 | | timeout = accountListSupportedImagesOptions.Timeout; |
| | 105 | | } |
| 0 | 106 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 107 | | if (accountListSupportedImagesOptions != null) |
| | 108 | | { |
| 0 | 109 | | clientRequestId = accountListSupportedImagesOptions.ClientRequestId; |
| | 110 | | } |
| 0 | 111 | | bool? returnClientRequestId = default(bool?); |
| 0 | 112 | | if (accountListSupportedImagesOptions != null) |
| | 113 | | { |
| 0 | 114 | | returnClientRequestId = accountListSupportedImagesOptions.ReturnClientRequestId; |
| | 115 | | } |
| 0 | 116 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 117 | | if (accountListSupportedImagesOptions != null) |
| | 118 | | { |
| 0 | 119 | | ocpDate = accountListSupportedImagesOptions.OcpDate; |
| | 120 | | } |
| | 121 | | // Tracing |
| 0 | 122 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 123 | | string _invocationId = null; |
| 0 | 124 | | if (_shouldTrace) |
| | 125 | | { |
| 0 | 126 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 127 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 128 | | tracingParameters.Add("filter", filter); |
| 0 | 129 | | tracingParameters.Add("maxResults", maxResults); |
| 0 | 130 | | tracingParameters.Add("timeout", timeout); |
| 0 | 131 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 132 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 133 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 134 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 135 | | ServiceClientTracing.Enter(_invocationId, this, "ListSupportedImages", tracingParameters); |
| | 136 | | } |
| | 137 | | // Construct URL |
| 0 | 138 | | var _baseUrl = Client.BaseUri; |
| 0 | 139 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "supportedimages"; |
| 0 | 140 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 141 | | List<string> _queryParameters = new List<string>(); |
| 0 | 142 | | if (Client.ApiVersion != null) |
| | 143 | | { |
| 0 | 144 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 145 | | } |
| 0 | 146 | | if (filter != null) |
| | 147 | | { |
| 0 | 148 | | _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter))); |
| | 149 | | } |
| 0 | 150 | | if (maxResults != null) |
| | 151 | | { |
| 0 | 152 | | _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali |
| | 153 | | } |
| 0 | 154 | | if (timeout != null) |
| | 155 | | { |
| 0 | 156 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 157 | | } |
| 0 | 158 | | if (_queryParameters.Count > 0) |
| | 159 | | { |
| 0 | 160 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 161 | | } |
| | 162 | | // Create HTTP transport objects |
| 0 | 163 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 164 | | HttpResponseMessage _httpResponse = null; |
| 0 | 165 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 166 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 167 | | // Set Headers |
| 0 | 168 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 169 | | { |
| 0 | 170 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 171 | | } |
| 0 | 172 | | if (Client.AcceptLanguage != null) |
| | 173 | | { |
| 0 | 174 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 175 | | { |
| 0 | 176 | | _httpRequest.Headers.Remove("accept-language"); |
| | 177 | | } |
| 0 | 178 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 179 | | } |
| 0 | 180 | | if (clientRequestId != null) |
| | 181 | | { |
| 0 | 182 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 183 | | { |
| 0 | 184 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 185 | | } |
| 0 | 186 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 187 | | } |
| 0 | 188 | | if (returnClientRequestId != null) |
| | 189 | | { |
| 0 | 190 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 191 | | { |
| 0 | 192 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 193 | | } |
| 0 | 194 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 195 | | } |
| 0 | 196 | | if (ocpDate != null) |
| | 197 | | { |
| 0 | 198 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 199 | | { |
| 0 | 200 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 201 | | } |
| 0 | 202 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 203 | | } |
| | 204 | |
|
| | 205 | |
|
| 0 | 206 | | if (customHeaders != null) |
| | 207 | | { |
| 0 | 208 | | foreach(var _header in customHeaders) |
| | 209 | | { |
| 0 | 210 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 211 | | { |
| 0 | 212 | | _httpRequest.Headers.Remove(_header.Key); |
| | 213 | | } |
| 0 | 214 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 215 | | } |
| | 216 | | } |
| | 217 | |
|
| | 218 | | // Serialize Request |
| 0 | 219 | | string _requestContent = null; |
| | 220 | | // Set Credentials |
| 0 | 221 | | if (Client.Credentials != null) |
| | 222 | | { |
| 0 | 223 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 224 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 225 | | } |
| | 226 | | // Send Request |
| 0 | 227 | | if (_shouldTrace) |
| | 228 | | { |
| 0 | 229 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 230 | | } |
| 0 | 231 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 232 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 233 | | if (_shouldTrace) |
| | 234 | | { |
| 0 | 235 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 236 | | } |
| 0 | 237 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 238 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 239 | | string _responseContent = null; |
| 0 | 240 | | if ((int)_statusCode != 200) |
| | 241 | | { |
| 0 | 242 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 243 | | try |
| | 244 | | { |
| 0 | 245 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 246 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 247 | | if (_errorBody != null) |
| | 248 | | { |
| 0 | 249 | | ex.Body = _errorBody; |
| | 250 | | } |
| 0 | 251 | | } |
| 0 | 252 | | catch (JsonException) |
| | 253 | | { |
| | 254 | | // Ignore the exception |
| 0 | 255 | | } |
| 0 | 256 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 257 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 258 | | if (_shouldTrace) |
| | 259 | | { |
| 0 | 260 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 261 | | } |
| 0 | 262 | | _httpRequest.Dispose(); |
| 0 | 263 | | if (_httpResponse != null) |
| | 264 | | { |
| 0 | 265 | | _httpResponse.Dispose(); |
| | 266 | | } |
| 0 | 267 | | throw ex; |
| | 268 | | } |
| | 269 | | // Create Result |
| 0 | 270 | | var _result = new AzureOperationResponse<IPage<ImageInformation>,AccountListSupportedImagesHeaders>(); |
| 0 | 271 | | _result.Request = _httpRequest; |
| 0 | 272 | | _result.Response = _httpResponse; |
| 0 | 273 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 274 | | { |
| 0 | 275 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 276 | | } |
| | 277 | | // Deserialize Response |
| 0 | 278 | | if ((int)_statusCode == 200) |
| | 279 | | { |
| 0 | 280 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 281 | | try |
| | 282 | | { |
| 0 | 283 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<ImageInformation>>(_responseContent, Client.De |
| 0 | 284 | | } |
| 0 | 285 | | catch (JsonException ex) |
| | 286 | | { |
| 0 | 287 | | _httpRequest.Dispose(); |
| 0 | 288 | | if (_httpResponse != null) |
| | 289 | | { |
| 0 | 290 | | _httpResponse.Dispose(); |
| | 291 | | } |
| 0 | 292 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 293 | | } |
| | 294 | | } |
| | 295 | | try |
| | 296 | | { |
| 0 | 297 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<AccountListSupportedImagesHeaders>(JsonSeria |
| 0 | 298 | | } |
| 0 | 299 | | catch (JsonException ex) |
| | 300 | | { |
| 0 | 301 | | _httpRequest.Dispose(); |
| 0 | 302 | | if (_httpResponse != null) |
| | 303 | | { |
| 0 | 304 | | _httpResponse.Dispose(); |
| | 305 | | } |
| 0 | 306 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 307 | | } |
| 0 | 308 | | if (_shouldTrace) |
| | 309 | | { |
| 0 | 310 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 311 | | } |
| 0 | 312 | | return _result; |
| 0 | 313 | | } |
| | 314 | |
|
| | 315 | | /// <summary> |
| | 316 | | /// Gets the number of Compute Nodes in each state, grouped by Pool. |
| | 317 | | /// </summary> |
| | 318 | | /// <param name='accountListPoolNodeCountsOptions'> |
| | 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="SerializationException"> |
| | 331 | | /// Thrown when unable to deserialize the response |
| | 332 | | /// </exception> |
| | 333 | | /// <exception cref="ValidationException"> |
| | 334 | | /// Thrown when a required parameter is null |
| | 335 | | /// </exception> |
| | 336 | | /// <exception cref="System.ArgumentNullException"> |
| | 337 | | /// Thrown when a required parameter is null |
| | 338 | | /// </exception> |
| | 339 | | /// <return> |
| | 340 | | /// A response object containing the response body and response headers. |
| | 341 | | /// </return> |
| | 342 | | public async Task<AzureOperationResponse<IPage<PoolNodeCounts>,AccountListPoolNodeCountsHeaders>> ListPoolNodeCo |
| | 343 | | { |
| 0 | 344 | | if (Client.BatchUrl == null) |
| | 345 | | { |
| 0 | 346 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 347 | | } |
| 0 | 348 | | if (Client.ApiVersion == null) |
| | 349 | | { |
| 0 | 350 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 351 | | } |
| 0 | 352 | | string filter = default(string); |
| 0 | 353 | | if (accountListPoolNodeCountsOptions != null) |
| | 354 | | { |
| 0 | 355 | | filter = accountListPoolNodeCountsOptions.Filter; |
| | 356 | | } |
| 0 | 357 | | int? maxResults = default(int?); |
| 0 | 358 | | if (accountListPoolNodeCountsOptions != null) |
| | 359 | | { |
| 0 | 360 | | maxResults = accountListPoolNodeCountsOptions.MaxResults; |
| | 361 | | } |
| 0 | 362 | | int? timeout = default(int?); |
| 0 | 363 | | if (accountListPoolNodeCountsOptions != null) |
| | 364 | | { |
| 0 | 365 | | timeout = accountListPoolNodeCountsOptions.Timeout; |
| | 366 | | } |
| 0 | 367 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 368 | | if (accountListPoolNodeCountsOptions != null) |
| | 369 | | { |
| 0 | 370 | | clientRequestId = accountListPoolNodeCountsOptions.ClientRequestId; |
| | 371 | | } |
| 0 | 372 | | bool? returnClientRequestId = default(bool?); |
| 0 | 373 | | if (accountListPoolNodeCountsOptions != null) |
| | 374 | | { |
| 0 | 375 | | returnClientRequestId = accountListPoolNodeCountsOptions.ReturnClientRequestId; |
| | 376 | | } |
| 0 | 377 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 378 | | if (accountListPoolNodeCountsOptions != null) |
| | 379 | | { |
| 0 | 380 | | ocpDate = accountListPoolNodeCountsOptions.OcpDate; |
| | 381 | | } |
| | 382 | | // Tracing |
| 0 | 383 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 384 | | string _invocationId = null; |
| 0 | 385 | | if (_shouldTrace) |
| | 386 | | { |
| 0 | 387 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 388 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 389 | | tracingParameters.Add("filter", filter); |
| 0 | 390 | | tracingParameters.Add("maxResults", maxResults); |
| 0 | 391 | | tracingParameters.Add("timeout", timeout); |
| 0 | 392 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 393 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 394 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 395 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 396 | | ServiceClientTracing.Enter(_invocationId, this, "ListPoolNodeCounts", tracingParameters); |
| | 397 | | } |
| | 398 | | // Construct URL |
| 0 | 399 | | var _baseUrl = Client.BaseUri; |
| 0 | 400 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "nodecounts"; |
| 0 | 401 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 402 | | List<string> _queryParameters = new List<string>(); |
| 0 | 403 | | if (Client.ApiVersion != null) |
| | 404 | | { |
| 0 | 405 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 406 | | } |
| 0 | 407 | | if (filter != null) |
| | 408 | | { |
| 0 | 409 | | _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter))); |
| | 410 | | } |
| 0 | 411 | | if (maxResults != null) |
| | 412 | | { |
| 0 | 413 | | _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali |
| | 414 | | } |
| 0 | 415 | | if (timeout != null) |
| | 416 | | { |
| 0 | 417 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 418 | | } |
| 0 | 419 | | if (_queryParameters.Count > 0) |
| | 420 | | { |
| 0 | 421 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 422 | | } |
| | 423 | | // Create HTTP transport objects |
| 0 | 424 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 425 | | HttpResponseMessage _httpResponse = null; |
| 0 | 426 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 427 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 428 | | // Set Headers |
| 0 | 429 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 430 | | { |
| 0 | 431 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 432 | | } |
| 0 | 433 | | if (Client.AcceptLanguage != null) |
| | 434 | | { |
| 0 | 435 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 436 | | { |
| 0 | 437 | | _httpRequest.Headers.Remove("accept-language"); |
| | 438 | | } |
| 0 | 439 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 440 | | } |
| 0 | 441 | | if (clientRequestId != null) |
| | 442 | | { |
| 0 | 443 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 444 | | { |
| 0 | 445 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 446 | | } |
| 0 | 447 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 448 | | } |
| 0 | 449 | | if (returnClientRequestId != null) |
| | 450 | | { |
| 0 | 451 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 452 | | { |
| 0 | 453 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 454 | | } |
| 0 | 455 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 456 | | } |
| 0 | 457 | | if (ocpDate != null) |
| | 458 | | { |
| 0 | 459 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 460 | | { |
| 0 | 461 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 462 | | } |
| 0 | 463 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 464 | | } |
| | 465 | |
|
| | 466 | |
|
| 0 | 467 | | if (customHeaders != null) |
| | 468 | | { |
| 0 | 469 | | foreach(var _header in customHeaders) |
| | 470 | | { |
| 0 | 471 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 472 | | { |
| 0 | 473 | | _httpRequest.Headers.Remove(_header.Key); |
| | 474 | | } |
| 0 | 475 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 476 | | } |
| | 477 | | } |
| | 478 | |
|
| | 479 | | // Serialize Request |
| 0 | 480 | | string _requestContent = null; |
| | 481 | | // Set Credentials |
| 0 | 482 | | if (Client.Credentials != null) |
| | 483 | | { |
| 0 | 484 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 485 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 486 | | } |
| | 487 | | // Send Request |
| 0 | 488 | | if (_shouldTrace) |
| | 489 | | { |
| 0 | 490 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 491 | | } |
| 0 | 492 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 493 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 494 | | if (_shouldTrace) |
| | 495 | | { |
| 0 | 496 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 497 | | } |
| 0 | 498 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 499 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 500 | | string _responseContent = null; |
| 0 | 501 | | if ((int)_statusCode != 200) |
| | 502 | | { |
| 0 | 503 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 504 | | try |
| | 505 | | { |
| 0 | 506 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 507 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 508 | | if (_errorBody != null) |
| | 509 | | { |
| 0 | 510 | | ex.Body = _errorBody; |
| | 511 | | } |
| 0 | 512 | | } |
| 0 | 513 | | catch (JsonException) |
| | 514 | | { |
| | 515 | | // Ignore the exception |
| 0 | 516 | | } |
| 0 | 517 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 518 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 519 | | if (_shouldTrace) |
| | 520 | | { |
| 0 | 521 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 522 | | } |
| 0 | 523 | | _httpRequest.Dispose(); |
| 0 | 524 | | if (_httpResponse != null) |
| | 525 | | { |
| 0 | 526 | | _httpResponse.Dispose(); |
| | 527 | | } |
| 0 | 528 | | throw ex; |
| | 529 | | } |
| | 530 | | // Create Result |
| 0 | 531 | | var _result = new AzureOperationResponse<IPage<PoolNodeCounts>,AccountListPoolNodeCountsHeaders>(); |
| 0 | 532 | | _result.Request = _httpRequest; |
| 0 | 533 | | _result.Response = _httpResponse; |
| 0 | 534 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 535 | | { |
| 0 | 536 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 537 | | } |
| | 538 | | // Deserialize Response |
| 0 | 539 | | if ((int)_statusCode == 200) |
| | 540 | | { |
| 0 | 541 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 542 | | try |
| | 543 | | { |
| 0 | 544 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<PoolNodeCounts>>(_responseContent, Client.Dese |
| 0 | 545 | | } |
| 0 | 546 | | catch (JsonException ex) |
| | 547 | | { |
| 0 | 548 | | _httpRequest.Dispose(); |
| 0 | 549 | | if (_httpResponse != null) |
| | 550 | | { |
| 0 | 551 | | _httpResponse.Dispose(); |
| | 552 | | } |
| 0 | 553 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 554 | | } |
| | 555 | | } |
| | 556 | | try |
| | 557 | | { |
| 0 | 558 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<AccountListPoolNodeCountsHeaders>(JsonSerial |
| 0 | 559 | | } |
| 0 | 560 | | catch (JsonException ex) |
| | 561 | | { |
| 0 | 562 | | _httpRequest.Dispose(); |
| 0 | 563 | | if (_httpResponse != null) |
| | 564 | | { |
| 0 | 565 | | _httpResponse.Dispose(); |
| | 566 | | } |
| 0 | 567 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 568 | | } |
| 0 | 569 | | if (_shouldTrace) |
| | 570 | | { |
| 0 | 571 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 572 | | } |
| 0 | 573 | | return _result; |
| 0 | 574 | | } |
| | 575 | |
|
| | 576 | | /// <summary> |
| | 577 | | /// Lists all Virtual Machine Images supported by the Azure Batch service. |
| | 578 | | /// </summary> |
| | 579 | | /// <param name='nextPageLink'> |
| | 580 | | /// The NextLink from the previous successful call to List operation. |
| | 581 | | /// </param> |
| | 582 | | /// <param name='accountListSupportedImagesNextOptions'> |
| | 583 | | /// Additional parameters for the operation |
| | 584 | | /// </param> |
| | 585 | | /// <param name='customHeaders'> |
| | 586 | | /// Headers that will be added to request. |
| | 587 | | /// </param> |
| | 588 | | /// <param name='cancellationToken'> |
| | 589 | | /// The cancellation token. |
| | 590 | | /// </param> |
| | 591 | | /// <exception cref="BatchErrorException"> |
| | 592 | | /// Thrown when the operation returned an invalid status code |
| | 593 | | /// </exception> |
| | 594 | | /// <exception cref="SerializationException"> |
| | 595 | | /// Thrown when unable to deserialize the response |
| | 596 | | /// </exception> |
| | 597 | | /// <exception cref="ValidationException"> |
| | 598 | | /// Thrown when a required parameter is null |
| | 599 | | /// </exception> |
| | 600 | | /// <exception cref="System.ArgumentNullException"> |
| | 601 | | /// Thrown when a required parameter is null |
| | 602 | | /// </exception> |
| | 603 | | /// <return> |
| | 604 | | /// A response object containing the response body and response headers. |
| | 605 | | /// </return> |
| | 606 | | public async Task<AzureOperationResponse<IPage<ImageInformation>,AccountListSupportedImagesHeaders>> ListSupport |
| | 607 | | { |
| 0 | 608 | | if (nextPageLink == null) |
| | 609 | | { |
| 0 | 610 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); |
| | 611 | | } |
| 0 | 612 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 613 | | if (accountListSupportedImagesNextOptions != null) |
| | 614 | | { |
| 0 | 615 | | clientRequestId = accountListSupportedImagesNextOptions.ClientRequestId; |
| | 616 | | } |
| 0 | 617 | | bool? returnClientRequestId = default(bool?); |
| 0 | 618 | | if (accountListSupportedImagesNextOptions != null) |
| | 619 | | { |
| 0 | 620 | | returnClientRequestId = accountListSupportedImagesNextOptions.ReturnClientRequestId; |
| | 621 | | } |
| 0 | 622 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 623 | | if (accountListSupportedImagesNextOptions != null) |
| | 624 | | { |
| 0 | 625 | | ocpDate = accountListSupportedImagesNextOptions.OcpDate; |
| | 626 | | } |
| | 627 | | // Tracing |
| 0 | 628 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 629 | | string _invocationId = null; |
| 0 | 630 | | if (_shouldTrace) |
| | 631 | | { |
| 0 | 632 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 633 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 634 | | tracingParameters.Add("nextPageLink", nextPageLink); |
| 0 | 635 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 636 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 637 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 638 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 639 | | ServiceClientTracing.Enter(_invocationId, this, "ListSupportedImagesNext", tracingParameters); |
| | 640 | | } |
| | 641 | | // Construct URL |
| 0 | 642 | | string _url = "{nextLink}"; |
| 0 | 643 | | _url = _url.Replace("{nextLink}", nextPageLink); |
| 0 | 644 | | List<string> _queryParameters = new List<string>(); |
| 0 | 645 | | if (_queryParameters.Count > 0) |
| | 646 | | { |
| 0 | 647 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 648 | | } |
| | 649 | | // Create HTTP transport objects |
| 0 | 650 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 651 | | HttpResponseMessage _httpResponse = null; |
| 0 | 652 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 653 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 654 | | // Set Headers |
| 0 | 655 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 656 | | { |
| 0 | 657 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 658 | | } |
| 0 | 659 | | if (Client.AcceptLanguage != null) |
| | 660 | | { |
| 0 | 661 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 662 | | { |
| 0 | 663 | | _httpRequest.Headers.Remove("accept-language"); |
| | 664 | | } |
| 0 | 665 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 666 | | } |
| 0 | 667 | | if (clientRequestId != null) |
| | 668 | | { |
| 0 | 669 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 670 | | { |
| 0 | 671 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 672 | | } |
| 0 | 673 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 674 | | } |
| 0 | 675 | | if (returnClientRequestId != null) |
| | 676 | | { |
| 0 | 677 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 678 | | { |
| 0 | 679 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 680 | | } |
| 0 | 681 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 682 | | } |
| 0 | 683 | | if (ocpDate != null) |
| | 684 | | { |
| 0 | 685 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 686 | | { |
| 0 | 687 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 688 | | } |
| 0 | 689 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 690 | | } |
| | 691 | |
|
| | 692 | |
|
| 0 | 693 | | if (customHeaders != null) |
| | 694 | | { |
| 0 | 695 | | foreach(var _header in customHeaders) |
| | 696 | | { |
| 0 | 697 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 698 | | { |
| 0 | 699 | | _httpRequest.Headers.Remove(_header.Key); |
| | 700 | | } |
| 0 | 701 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 702 | | } |
| | 703 | | } |
| | 704 | |
|
| | 705 | | // Serialize Request |
| 0 | 706 | | string _requestContent = null; |
| | 707 | | // Set Credentials |
| 0 | 708 | | if (Client.Credentials != null) |
| | 709 | | { |
| 0 | 710 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 711 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 712 | | } |
| | 713 | | // Send Request |
| 0 | 714 | | if (_shouldTrace) |
| | 715 | | { |
| 0 | 716 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 717 | | } |
| 0 | 718 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 719 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 720 | | if (_shouldTrace) |
| | 721 | | { |
| 0 | 722 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 723 | | } |
| 0 | 724 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 725 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 726 | | string _responseContent = null; |
| 0 | 727 | | if ((int)_statusCode != 200) |
| | 728 | | { |
| 0 | 729 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 730 | | try |
| | 731 | | { |
| 0 | 732 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 733 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 734 | | if (_errorBody != null) |
| | 735 | | { |
| 0 | 736 | | ex.Body = _errorBody; |
| | 737 | | } |
| 0 | 738 | | } |
| 0 | 739 | | catch (JsonException) |
| | 740 | | { |
| | 741 | | // Ignore the exception |
| 0 | 742 | | } |
| 0 | 743 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 744 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 745 | | if (_shouldTrace) |
| | 746 | | { |
| 0 | 747 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 748 | | } |
| 0 | 749 | | _httpRequest.Dispose(); |
| 0 | 750 | | if (_httpResponse != null) |
| | 751 | | { |
| 0 | 752 | | _httpResponse.Dispose(); |
| | 753 | | } |
| 0 | 754 | | throw ex; |
| | 755 | | } |
| | 756 | | // Create Result |
| 0 | 757 | | var _result = new AzureOperationResponse<IPage<ImageInformation>,AccountListSupportedImagesHeaders>(); |
| 0 | 758 | | _result.Request = _httpRequest; |
| 0 | 759 | | _result.Response = _httpResponse; |
| 0 | 760 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 761 | | { |
| 0 | 762 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 763 | | } |
| | 764 | | // Deserialize Response |
| 0 | 765 | | if ((int)_statusCode == 200) |
| | 766 | | { |
| 0 | 767 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 768 | | try |
| | 769 | | { |
| 0 | 770 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<ImageInformation>>(_responseContent, Client.De |
| 0 | 771 | | } |
| 0 | 772 | | catch (JsonException ex) |
| | 773 | | { |
| 0 | 774 | | _httpRequest.Dispose(); |
| 0 | 775 | | if (_httpResponse != null) |
| | 776 | | { |
| 0 | 777 | | _httpResponse.Dispose(); |
| | 778 | | } |
| 0 | 779 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 780 | | } |
| | 781 | | } |
| | 782 | | try |
| | 783 | | { |
| 0 | 784 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<AccountListSupportedImagesHeaders>(JsonSeria |
| 0 | 785 | | } |
| 0 | 786 | | catch (JsonException ex) |
| | 787 | | { |
| 0 | 788 | | _httpRequest.Dispose(); |
| 0 | 789 | | if (_httpResponse != null) |
| | 790 | | { |
| 0 | 791 | | _httpResponse.Dispose(); |
| | 792 | | } |
| 0 | 793 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 794 | | } |
| 0 | 795 | | if (_shouldTrace) |
| | 796 | | { |
| 0 | 797 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 798 | | } |
| 0 | 799 | | return _result; |
| 0 | 800 | | } |
| | 801 | |
|
| | 802 | | /// <summary> |
| | 803 | | /// Gets the number of Compute Nodes in each state, grouped by Pool. |
| | 804 | | /// </summary> |
| | 805 | | /// <param name='nextPageLink'> |
| | 806 | | /// The NextLink from the previous successful call to List operation. |
| | 807 | | /// </param> |
| | 808 | | /// <param name='accountListPoolNodeCountsNextOptions'> |
| | 809 | | /// Additional parameters for the operation |
| | 810 | | /// </param> |
| | 811 | | /// <param name='customHeaders'> |
| | 812 | | /// Headers that will be added to request. |
| | 813 | | /// </param> |
| | 814 | | /// <param name='cancellationToken'> |
| | 815 | | /// The cancellation token. |
| | 816 | | /// </param> |
| | 817 | | /// <exception cref="BatchErrorException"> |
| | 818 | | /// Thrown when the operation returned an invalid status code |
| | 819 | | /// </exception> |
| | 820 | | /// <exception cref="SerializationException"> |
| | 821 | | /// Thrown when unable to deserialize the response |
| | 822 | | /// </exception> |
| | 823 | | /// <exception cref="ValidationException"> |
| | 824 | | /// Thrown when a required parameter is null |
| | 825 | | /// </exception> |
| | 826 | | /// <exception cref="System.ArgumentNullException"> |
| | 827 | | /// Thrown when a required parameter is null |
| | 828 | | /// </exception> |
| | 829 | | /// <return> |
| | 830 | | /// A response object containing the response body and response headers. |
| | 831 | | /// </return> |
| | 832 | | public async Task<AzureOperationResponse<IPage<PoolNodeCounts>,AccountListPoolNodeCountsHeaders>> ListPoolNodeCo |
| | 833 | | { |
| 0 | 834 | | if (nextPageLink == null) |
| | 835 | | { |
| 0 | 836 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); |
| | 837 | | } |
| 0 | 838 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 839 | | if (accountListPoolNodeCountsNextOptions != null) |
| | 840 | | { |
| 0 | 841 | | clientRequestId = accountListPoolNodeCountsNextOptions.ClientRequestId; |
| | 842 | | } |
| 0 | 843 | | bool? returnClientRequestId = default(bool?); |
| 0 | 844 | | if (accountListPoolNodeCountsNextOptions != null) |
| | 845 | | { |
| 0 | 846 | | returnClientRequestId = accountListPoolNodeCountsNextOptions.ReturnClientRequestId; |
| | 847 | | } |
| 0 | 848 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 849 | | if (accountListPoolNodeCountsNextOptions != null) |
| | 850 | | { |
| 0 | 851 | | ocpDate = accountListPoolNodeCountsNextOptions.OcpDate; |
| | 852 | | } |
| | 853 | | // Tracing |
| 0 | 854 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 855 | | string _invocationId = null; |
| 0 | 856 | | if (_shouldTrace) |
| | 857 | | { |
| 0 | 858 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 859 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 860 | | tracingParameters.Add("nextPageLink", nextPageLink); |
| 0 | 861 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 862 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 863 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 864 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 865 | | ServiceClientTracing.Enter(_invocationId, this, "ListPoolNodeCountsNext", tracingParameters); |
| | 866 | | } |
| | 867 | | // Construct URL |
| 0 | 868 | | string _url = "{nextLink}"; |
| 0 | 869 | | _url = _url.Replace("{nextLink}", nextPageLink); |
| 0 | 870 | | List<string> _queryParameters = new List<string>(); |
| 0 | 871 | | if (_queryParameters.Count > 0) |
| | 872 | | { |
| 0 | 873 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 874 | | } |
| | 875 | | // Create HTTP transport objects |
| 0 | 876 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 877 | | HttpResponseMessage _httpResponse = null; |
| 0 | 878 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 879 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 880 | | // Set Headers |
| 0 | 881 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 882 | | { |
| 0 | 883 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 884 | | } |
| 0 | 885 | | if (Client.AcceptLanguage != null) |
| | 886 | | { |
| 0 | 887 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 888 | | { |
| 0 | 889 | | _httpRequest.Headers.Remove("accept-language"); |
| | 890 | | } |
| 0 | 891 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 892 | | } |
| 0 | 893 | | if (clientRequestId != null) |
| | 894 | | { |
| 0 | 895 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 896 | | { |
| 0 | 897 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 898 | | } |
| 0 | 899 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 900 | | } |
| 0 | 901 | | if (returnClientRequestId != null) |
| | 902 | | { |
| 0 | 903 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 904 | | { |
| 0 | 905 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 906 | | } |
| 0 | 907 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 908 | | } |
| 0 | 909 | | if (ocpDate != null) |
| | 910 | | { |
| 0 | 911 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 912 | | { |
| 0 | 913 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 914 | | } |
| 0 | 915 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 916 | | } |
| | 917 | |
|
| | 918 | |
|
| 0 | 919 | | if (customHeaders != null) |
| | 920 | | { |
| 0 | 921 | | foreach(var _header in customHeaders) |
| | 922 | | { |
| 0 | 923 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 924 | | { |
| 0 | 925 | | _httpRequest.Headers.Remove(_header.Key); |
| | 926 | | } |
| 0 | 927 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 928 | | } |
| | 929 | | } |
| | 930 | |
|
| | 931 | | // Serialize Request |
| 0 | 932 | | string _requestContent = null; |
| | 933 | | // Set Credentials |
| 0 | 934 | | if (Client.Credentials != null) |
| | 935 | | { |
| 0 | 936 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 937 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 938 | | } |
| | 939 | | // Send Request |
| 0 | 940 | | if (_shouldTrace) |
| | 941 | | { |
| 0 | 942 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 943 | | } |
| 0 | 944 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 945 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 946 | | if (_shouldTrace) |
| | 947 | | { |
| 0 | 948 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 949 | | } |
| 0 | 950 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 951 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 952 | | string _responseContent = null; |
| 0 | 953 | | if ((int)_statusCode != 200) |
| | 954 | | { |
| 0 | 955 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 956 | | try |
| | 957 | | { |
| 0 | 958 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 959 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 960 | | if (_errorBody != null) |
| | 961 | | { |
| 0 | 962 | | ex.Body = _errorBody; |
| | 963 | | } |
| 0 | 964 | | } |
| 0 | 965 | | catch (JsonException) |
| | 966 | | { |
| | 967 | | // Ignore the exception |
| 0 | 968 | | } |
| 0 | 969 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 970 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 971 | | if (_shouldTrace) |
| | 972 | | { |
| 0 | 973 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 974 | | } |
| 0 | 975 | | _httpRequest.Dispose(); |
| 0 | 976 | | if (_httpResponse != null) |
| | 977 | | { |
| 0 | 978 | | _httpResponse.Dispose(); |
| | 979 | | } |
| 0 | 980 | | throw ex; |
| | 981 | | } |
| | 982 | | // Create Result |
| 0 | 983 | | var _result = new AzureOperationResponse<IPage<PoolNodeCounts>,AccountListPoolNodeCountsHeaders>(); |
| 0 | 984 | | _result.Request = _httpRequest; |
| 0 | 985 | | _result.Response = _httpResponse; |
| 0 | 986 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 987 | | { |
| 0 | 988 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 989 | | } |
| | 990 | | // Deserialize Response |
| 0 | 991 | | if ((int)_statusCode == 200) |
| | 992 | | { |
| 0 | 993 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 994 | | try |
| | 995 | | { |
| 0 | 996 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<PoolNodeCounts>>(_responseContent, Client.Dese |
| 0 | 997 | | } |
| 0 | 998 | | catch (JsonException ex) |
| | 999 | | { |
| 0 | 1000 | | _httpRequest.Dispose(); |
| 0 | 1001 | | if (_httpResponse != null) |
| | 1002 | | { |
| 0 | 1003 | | _httpResponse.Dispose(); |
| | 1004 | | } |
| 0 | 1005 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1006 | | } |
| | 1007 | | } |
| | 1008 | | try |
| | 1009 | | { |
| 0 | 1010 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<AccountListPoolNodeCountsHeaders>(JsonSerial |
| 0 | 1011 | | } |
| 0 | 1012 | | catch (JsonException ex) |
| | 1013 | | { |
| 0 | 1014 | | _httpRequest.Dispose(); |
| 0 | 1015 | | if (_httpResponse != null) |
| | 1016 | | { |
| 0 | 1017 | | _httpResponse.Dispose(); |
| | 1018 | | } |
| 0 | 1019 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1020 | | } |
| 0 | 1021 | | if (_shouldTrace) |
| | 1022 | | { |
| 0 | 1023 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1024 | | } |
| 0 | 1025 | | return _result; |
| 0 | 1026 | | } |
| | 1027 | |
|
| | 1028 | | } |
| | 1029 | | } |