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