| | 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 | | /// ApplicationOperations operations. |
| | 28 | | /// </summary> |
| | 29 | | internal partial class ApplicationOperations : IServiceOperations<BatchServiceClient>, IApplicationOperations |
| | 30 | | { |
| | 31 | | /// <summary> |
| | 32 | | /// Initializes a new instance of the ApplicationOperations 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 ApplicationOperations(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> |
| 192 | 52 | | public BatchServiceClient Client { get; private set; } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Lists all of the applications available in the specified Account. |
| | 56 | | /// </summary> |
| | 57 | | /// <remarks> |
| | 58 | | /// This operation returns only Applications and versions that are available |
| | 59 | | /// for use on Compute Nodes; that is, that can be used in an Package |
| | 60 | | /// reference. For administrator information about applications and versions |
| | 61 | | /// that are not yet available to Compute Nodes, use the Azure portal or the |
| | 62 | | /// Azure Resource Manager API. |
| | 63 | | /// </remarks> |
| | 64 | | /// <param name='applicationListOptions'> |
| | 65 | | /// Additional parameters for the operation |
| | 66 | | /// </param> |
| | 67 | | /// <param name='customHeaders'> |
| | 68 | | /// Headers that will be added to request. |
| | 69 | | /// </param> |
| | 70 | | /// <param name='cancellationToken'> |
| | 71 | | /// The cancellation token. |
| | 72 | | /// </param> |
| | 73 | | /// <exception cref="BatchErrorException"> |
| | 74 | | /// Thrown when the operation returned an invalid status code |
| | 75 | | /// </exception> |
| | 76 | | /// <exception cref="SerializationException"> |
| | 77 | | /// Thrown when unable to deserialize the response |
| | 78 | | /// </exception> |
| | 79 | | /// <exception cref="ValidationException"> |
| | 80 | | /// Thrown when a required parameter is null |
| | 81 | | /// </exception> |
| | 82 | | /// <exception cref="System.ArgumentNullException"> |
| | 83 | | /// Thrown when a required parameter is null |
| | 84 | | /// </exception> |
| | 85 | | /// <return> |
| | 86 | | /// A response object containing the response body and response headers. |
| | 87 | | /// </return> |
| | 88 | | public async Task<AzureOperationResponse<IPage<ApplicationSummary>,ApplicationListHeaders>> ListWithHttpMessages |
| | 89 | | { |
| 2 | 90 | | if (Client.BatchUrl == null) |
| | 91 | | { |
| 0 | 92 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 93 | | } |
| 2 | 94 | | if (Client.ApiVersion == null) |
| | 95 | | { |
| 0 | 96 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 97 | | } |
| 2 | 98 | | int? maxResults = default(int?); |
| 2 | 99 | | if (applicationListOptions != null) |
| | 100 | | { |
| 2 | 101 | | maxResults = applicationListOptions.MaxResults; |
| | 102 | | } |
| 2 | 103 | | int? timeout = default(int?); |
| 2 | 104 | | if (applicationListOptions != null) |
| | 105 | | { |
| 2 | 106 | | timeout = applicationListOptions.Timeout; |
| | 107 | | } |
| 2 | 108 | | System.Guid? clientRequestId = default(System.Guid?); |
| 2 | 109 | | if (applicationListOptions != null) |
| | 110 | | { |
| 2 | 111 | | clientRequestId = applicationListOptions.ClientRequestId; |
| | 112 | | } |
| 2 | 113 | | bool? returnClientRequestId = default(bool?); |
| 2 | 114 | | if (applicationListOptions != null) |
| | 115 | | { |
| 2 | 116 | | returnClientRequestId = applicationListOptions.ReturnClientRequestId; |
| | 117 | | } |
| 2 | 118 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 2 | 119 | | if (applicationListOptions != null) |
| | 120 | | { |
| 2 | 121 | | ocpDate = applicationListOptions.OcpDate; |
| | 122 | | } |
| | 123 | | // Tracing |
| 2 | 124 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 125 | | string _invocationId = null; |
| 2 | 126 | | if (_shouldTrace) |
| | 127 | | { |
| 0 | 128 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 129 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 130 | | tracingParameters.Add("maxResults", maxResults); |
| 0 | 131 | | tracingParameters.Add("timeout", timeout); |
| 0 | 132 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 133 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 134 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 135 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 136 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 137 | | } |
| | 138 | | // Construct URL |
| 2 | 139 | | var _baseUrl = Client.BaseUri; |
| 2 | 140 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "applications"; |
| 2 | 141 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 2 | 142 | | List<string> _queryParameters = new List<string>(); |
| 2 | 143 | | if (Client.ApiVersion != null) |
| | 144 | | { |
| 2 | 145 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 146 | | } |
| 2 | 147 | | if (maxResults != null) |
| | 148 | | { |
| 0 | 149 | | _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali |
| | 150 | | } |
| 2 | 151 | | if (timeout != null) |
| | 152 | | { |
| 0 | 153 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 154 | | } |
| 2 | 155 | | if (_queryParameters.Count > 0) |
| | 156 | | { |
| 2 | 157 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 158 | | } |
| | 159 | | // Create HTTP transport objects |
| 2 | 160 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 161 | | HttpResponseMessage _httpResponse = null; |
| 2 | 162 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 163 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 164 | | // Set Headers |
| 2 | 165 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 166 | | { |
| 2 | 167 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 168 | | } |
| 2 | 169 | | if (Client.AcceptLanguage != null) |
| | 170 | | { |
| 2 | 171 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 172 | | { |
| 0 | 173 | | _httpRequest.Headers.Remove("accept-language"); |
| | 174 | | } |
| 2 | 175 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 176 | | } |
| 2 | 177 | | if (clientRequestId != null) |
| | 178 | | { |
| 2 | 179 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 180 | | { |
| 2 | 181 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 182 | | } |
| 2 | 183 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 184 | | } |
| 2 | 185 | | if (returnClientRequestId != null) |
| | 186 | | { |
| 0 | 187 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 188 | | { |
| 0 | 189 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 190 | | } |
| 0 | 191 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 192 | | } |
| 2 | 193 | | if (ocpDate != null) |
| | 194 | | { |
| 0 | 195 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 196 | | { |
| 0 | 197 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 198 | | } |
| 0 | 199 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 200 | | } |
| | 201 | |
|
| | 202 | |
|
| 2 | 203 | | if (customHeaders != null) |
| | 204 | | { |
| 0 | 205 | | foreach(var _header in customHeaders) |
| | 206 | | { |
| 0 | 207 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 208 | | { |
| 0 | 209 | | _httpRequest.Headers.Remove(_header.Key); |
| | 210 | | } |
| 0 | 211 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 212 | | } |
| | 213 | | } |
| | 214 | |
|
| | 215 | | // Serialize Request |
| 2 | 216 | | string _requestContent = null; |
| | 217 | | // Set Credentials |
| 2 | 218 | | if (Client.Credentials != null) |
| | 219 | | { |
| 2 | 220 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 221 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 222 | | } |
| | 223 | | // Send Request |
| 2 | 224 | | if (_shouldTrace) |
| | 225 | | { |
| 0 | 226 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 227 | | } |
| 2 | 228 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 229 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 230 | | if (_shouldTrace) |
| | 231 | | { |
| 0 | 232 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 233 | | } |
| 2 | 234 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 235 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 236 | | string _responseContent = null; |
| 2 | 237 | | if ((int)_statusCode != 200) |
| | 238 | | { |
| 0 | 239 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 240 | | try |
| | 241 | | { |
| 0 | 242 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 243 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 244 | | if (_errorBody != null) |
| | 245 | | { |
| 0 | 246 | | ex.Body = _errorBody; |
| | 247 | | } |
| 0 | 248 | | } |
| 0 | 249 | | catch (JsonException) |
| | 250 | | { |
| | 251 | | // Ignore the exception |
| 0 | 252 | | } |
| 0 | 253 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 254 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 255 | | if (_shouldTrace) |
| | 256 | | { |
| 0 | 257 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 258 | | } |
| 0 | 259 | | _httpRequest.Dispose(); |
| 0 | 260 | | if (_httpResponse != null) |
| | 261 | | { |
| 0 | 262 | | _httpResponse.Dispose(); |
| | 263 | | } |
| 0 | 264 | | throw ex; |
| | 265 | | } |
| | 266 | | // Create Result |
| 2 | 267 | | var _result = new AzureOperationResponse<IPage<ApplicationSummary>,ApplicationListHeaders>(); |
| 2 | 268 | | _result.Request = _httpRequest; |
| 2 | 269 | | _result.Response = _httpResponse; |
| 2 | 270 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 271 | | { |
| 0 | 272 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 273 | | } |
| | 274 | | // Deserialize Response |
| 2 | 275 | | if ((int)_statusCode == 200) |
| | 276 | | { |
| 2 | 277 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 278 | | try |
| | 279 | | { |
| 2 | 280 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<ApplicationSummary>>(_responseContent, Client. |
| 2 | 281 | | } |
| 0 | 282 | | catch (JsonException ex) |
| | 283 | | { |
| 0 | 284 | | _httpRequest.Dispose(); |
| 0 | 285 | | if (_httpResponse != null) |
| | 286 | | { |
| 0 | 287 | | _httpResponse.Dispose(); |
| | 288 | | } |
| 0 | 289 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 290 | | } |
| | 291 | | } |
| | 292 | | try |
| | 293 | | { |
| 2 | 294 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ApplicationListHeaders>(JsonSerializer.Creat |
| 2 | 295 | | } |
| 0 | 296 | | catch (JsonException ex) |
| | 297 | | { |
| 0 | 298 | | _httpRequest.Dispose(); |
| 0 | 299 | | if (_httpResponse != null) |
| | 300 | | { |
| 0 | 301 | | _httpResponse.Dispose(); |
| | 302 | | } |
| 0 | 303 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 304 | | } |
| 2 | 305 | | if (_shouldTrace) |
| | 306 | | { |
| 0 | 307 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 308 | | } |
| 2 | 309 | | return _result; |
| 2 | 310 | | } |
| | 311 | |
|
| | 312 | | /// <summary> |
| | 313 | | /// Gets information about the specified Application. |
| | 314 | | /// </summary> |
| | 315 | | /// <remarks> |
| | 316 | | /// This operation returns only Applications and versions that are available |
| | 317 | | /// for use on Compute Nodes; that is, that can be used in an Package |
| | 318 | | /// reference. For administrator information about Applications and versions |
| | 319 | | /// that are not yet available to Compute Nodes, use the Azure portal or the |
| | 320 | | /// Azure Resource Manager API. |
| | 321 | | /// </remarks> |
| | 322 | | /// <param name='applicationId'> |
| | 323 | | /// The ID of the Application. |
| | 324 | | /// </param> |
| | 325 | | /// <param name='applicationGetOptions'> |
| | 326 | | /// Additional parameters for the operation |
| | 327 | | /// </param> |
| | 328 | | /// <param name='customHeaders'> |
| | 329 | | /// Headers that will be added to request. |
| | 330 | | /// </param> |
| | 331 | | /// <param name='cancellationToken'> |
| | 332 | | /// The cancellation token. |
| | 333 | | /// </param> |
| | 334 | | /// <exception cref="BatchErrorException"> |
| | 335 | | /// Thrown when the operation returned an invalid status code |
| | 336 | | /// </exception> |
| | 337 | | /// <exception cref="SerializationException"> |
| | 338 | | /// Thrown when unable to deserialize the response |
| | 339 | | /// </exception> |
| | 340 | | /// <exception cref="ValidationException"> |
| | 341 | | /// Thrown when a required parameter is null |
| | 342 | | /// </exception> |
| | 343 | | /// <exception cref="System.ArgumentNullException"> |
| | 344 | | /// Thrown when a required parameter is null |
| | 345 | | /// </exception> |
| | 346 | | /// <return> |
| | 347 | | /// A response object containing the response body and response headers. |
| | 348 | | /// </return> |
| | 349 | | public async Task<AzureOperationResponse<ApplicationSummary,ApplicationGetHeaders>> GetWithHttpMessagesAsync(str |
| | 350 | | { |
| 0 | 351 | | if (Client.BatchUrl == null) |
| | 352 | | { |
| 0 | 353 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 354 | | } |
| 0 | 355 | | if (applicationId == null) |
| | 356 | | { |
| 0 | 357 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationId"); |
| | 358 | | } |
| 0 | 359 | | if (Client.ApiVersion == null) |
| | 360 | | { |
| 0 | 361 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 362 | | } |
| 0 | 363 | | int? timeout = default(int?); |
| 0 | 364 | | if (applicationGetOptions != null) |
| | 365 | | { |
| 0 | 366 | | timeout = applicationGetOptions.Timeout; |
| | 367 | | } |
| 0 | 368 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 369 | | if (applicationGetOptions != null) |
| | 370 | | { |
| 0 | 371 | | clientRequestId = applicationGetOptions.ClientRequestId; |
| | 372 | | } |
| 0 | 373 | | bool? returnClientRequestId = default(bool?); |
| 0 | 374 | | if (applicationGetOptions != null) |
| | 375 | | { |
| 0 | 376 | | returnClientRequestId = applicationGetOptions.ReturnClientRequestId; |
| | 377 | | } |
| 0 | 378 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 379 | | if (applicationGetOptions != null) |
| | 380 | | { |
| 0 | 381 | | ocpDate = applicationGetOptions.OcpDate; |
| | 382 | | } |
| | 383 | | // Tracing |
| 0 | 384 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 385 | | string _invocationId = null; |
| 0 | 386 | | if (_shouldTrace) |
| | 387 | | { |
| 0 | 388 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 389 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 390 | | tracingParameters.Add("applicationId", applicationId); |
| 0 | 391 | | tracingParameters.Add("timeout", timeout); |
| 0 | 392 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 393 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 394 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 395 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 396 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 397 | | } |
| | 398 | | // Construct URL |
| 0 | 399 | | var _baseUrl = Client.BaseUri; |
| 0 | 400 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "applications/{applicationId}"; |
| 0 | 401 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 402 | | _url = _url.Replace("{applicationId}", System.Uri.EscapeDataString(applicationId)); |
| 0 | 403 | | List<string> _queryParameters = new List<string>(); |
| 0 | 404 | | if (Client.ApiVersion != null) |
| | 405 | | { |
| 0 | 406 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 407 | | } |
| 0 | 408 | | if (timeout != null) |
| | 409 | | { |
| 0 | 410 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 411 | | } |
| 0 | 412 | | if (_queryParameters.Count > 0) |
| | 413 | | { |
| 0 | 414 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 415 | | } |
| | 416 | | // Create HTTP transport objects |
| 0 | 417 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 418 | | HttpResponseMessage _httpResponse = null; |
| 0 | 419 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 420 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 421 | | // Set Headers |
| 0 | 422 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 423 | | { |
| 0 | 424 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 425 | | } |
| 0 | 426 | | if (Client.AcceptLanguage != null) |
| | 427 | | { |
| 0 | 428 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 429 | | { |
| 0 | 430 | | _httpRequest.Headers.Remove("accept-language"); |
| | 431 | | } |
| 0 | 432 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 433 | | } |
| 0 | 434 | | if (clientRequestId != null) |
| | 435 | | { |
| 0 | 436 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 437 | | { |
| 0 | 438 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 439 | | } |
| 0 | 440 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 441 | | } |
| 0 | 442 | | if (returnClientRequestId != null) |
| | 443 | | { |
| 0 | 444 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 445 | | { |
| 0 | 446 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 447 | | } |
| 0 | 448 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 449 | | } |
| 0 | 450 | | if (ocpDate != null) |
| | 451 | | { |
| 0 | 452 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 453 | | { |
| 0 | 454 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 455 | | } |
| 0 | 456 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 457 | | } |
| | 458 | |
|
| | 459 | |
|
| 0 | 460 | | if (customHeaders != null) |
| | 461 | | { |
| 0 | 462 | | foreach(var _header in customHeaders) |
| | 463 | | { |
| 0 | 464 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 465 | | { |
| 0 | 466 | | _httpRequest.Headers.Remove(_header.Key); |
| | 467 | | } |
| 0 | 468 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 469 | | } |
| | 470 | | } |
| | 471 | |
|
| | 472 | | // Serialize Request |
| 0 | 473 | | string _requestContent = null; |
| | 474 | | // Set Credentials |
| 0 | 475 | | if (Client.Credentials != null) |
| | 476 | | { |
| 0 | 477 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 478 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 479 | | } |
| | 480 | | // Send Request |
| 0 | 481 | | if (_shouldTrace) |
| | 482 | | { |
| 0 | 483 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 484 | | } |
| 0 | 485 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 486 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 487 | | if (_shouldTrace) |
| | 488 | | { |
| 0 | 489 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 490 | | } |
| 0 | 491 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 492 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 493 | | string _responseContent = null; |
| 0 | 494 | | if ((int)_statusCode != 200) |
| | 495 | | { |
| 0 | 496 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 497 | | try |
| | 498 | | { |
| 0 | 499 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 500 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 501 | | if (_errorBody != null) |
| | 502 | | { |
| 0 | 503 | | ex.Body = _errorBody; |
| | 504 | | } |
| 0 | 505 | | } |
| 0 | 506 | | catch (JsonException) |
| | 507 | | { |
| | 508 | | // Ignore the exception |
| 0 | 509 | | } |
| 0 | 510 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 511 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 512 | | if (_shouldTrace) |
| | 513 | | { |
| 0 | 514 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 515 | | } |
| 0 | 516 | | _httpRequest.Dispose(); |
| 0 | 517 | | if (_httpResponse != null) |
| | 518 | | { |
| 0 | 519 | | _httpResponse.Dispose(); |
| | 520 | | } |
| 0 | 521 | | throw ex; |
| | 522 | | } |
| | 523 | | // Create Result |
| 0 | 524 | | var _result = new AzureOperationResponse<ApplicationSummary,ApplicationGetHeaders>(); |
| 0 | 525 | | _result.Request = _httpRequest; |
| 0 | 526 | | _result.Response = _httpResponse; |
| 0 | 527 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 528 | | { |
| 0 | 529 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 530 | | } |
| | 531 | | // Deserialize Response |
| 0 | 532 | | if ((int)_statusCode == 200) |
| | 533 | | { |
| 0 | 534 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 535 | | try |
| | 536 | | { |
| 0 | 537 | | _result.Body = SafeJsonConvert.DeserializeObject<ApplicationSummary>(_responseContent, Client.Deseri |
| 0 | 538 | | } |
| 0 | 539 | | catch (JsonException ex) |
| | 540 | | { |
| 0 | 541 | | _httpRequest.Dispose(); |
| 0 | 542 | | if (_httpResponse != null) |
| | 543 | | { |
| 0 | 544 | | _httpResponse.Dispose(); |
| | 545 | | } |
| 0 | 546 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 547 | | } |
| | 548 | | } |
| | 549 | | try |
| | 550 | | { |
| 0 | 551 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ApplicationGetHeaders>(JsonSerializer.Create |
| 0 | 552 | | } |
| 0 | 553 | | catch (JsonException ex) |
| | 554 | | { |
| 0 | 555 | | _httpRequest.Dispose(); |
| 0 | 556 | | if (_httpResponse != null) |
| | 557 | | { |
| 0 | 558 | | _httpResponse.Dispose(); |
| | 559 | | } |
| 0 | 560 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 561 | | } |
| 0 | 562 | | if (_shouldTrace) |
| | 563 | | { |
| 0 | 564 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 565 | | } |
| 0 | 566 | | return _result; |
| 0 | 567 | | } |
| | 568 | |
|
| | 569 | | /// <summary> |
| | 570 | | /// Lists all of the applications available in the specified Account. |
| | 571 | | /// </summary> |
| | 572 | | /// <remarks> |
| | 573 | | /// This operation returns only Applications and versions that are available |
| | 574 | | /// for use on Compute Nodes; that is, that can be used in an Package |
| | 575 | | /// reference. For administrator information about applications and versions |
| | 576 | | /// that are not yet available to Compute Nodes, use the Azure portal or the |
| | 577 | | /// Azure Resource Manager API. |
| | 578 | | /// </remarks> |
| | 579 | | /// <param name='nextPageLink'> |
| | 580 | | /// The NextLink from the previous successful call to List operation. |
| | 581 | | /// </param> |
| | 582 | | /// <param name='applicationListNextOptions'> |
| | 583 | | /// Additional parameters for the operation |
| | 584 | | /// </param> |
| | 585 | | /// <param name='customHeaders'> |
| | 586 | | /// Headers that will be added to request. |
| | 587 | | /// </param> |
| | 588 | | /// <param name='cancellationToken'> |
| | 589 | | /// The cancellation token. |
| | 590 | | /// </param> |
| | 591 | | /// <exception cref="BatchErrorException"> |
| | 592 | | /// Thrown when the operation returned an invalid status code |
| | 593 | | /// </exception> |
| | 594 | | /// <exception cref="SerializationException"> |
| | 595 | | /// Thrown when unable to deserialize the response |
| | 596 | | /// </exception> |
| | 597 | | /// <exception cref="ValidationException"> |
| | 598 | | /// Thrown when a required parameter is null |
| | 599 | | /// </exception> |
| | 600 | | /// <exception cref="System.ArgumentNullException"> |
| | 601 | | /// Thrown when a required parameter is null |
| | 602 | | /// </exception> |
| | 603 | | /// <return> |
| | 604 | | /// A response object containing the response body and response headers. |
| | 605 | | /// </return> |
| | 606 | | public async Task<AzureOperationResponse<IPage<ApplicationSummary>,ApplicationListHeaders>> ListNextWithHttpMess |
| | 607 | | { |
| 2 | 608 | | if (nextPageLink == null) |
| | 609 | | { |
| 0 | 610 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); |
| | 611 | | } |
| 2 | 612 | | System.Guid? clientRequestId = default(System.Guid?); |
| 2 | 613 | | if (applicationListNextOptions != null) |
| | 614 | | { |
| 2 | 615 | | clientRequestId = applicationListNextOptions.ClientRequestId; |
| | 616 | | } |
| 2 | 617 | | bool? returnClientRequestId = default(bool?); |
| 2 | 618 | | if (applicationListNextOptions != null) |
| | 619 | | { |
| 2 | 620 | | returnClientRequestId = applicationListNextOptions.ReturnClientRequestId; |
| | 621 | | } |
| 2 | 622 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 2 | 623 | | if (applicationListNextOptions != null) |
| | 624 | | { |
| 2 | 625 | | ocpDate = applicationListNextOptions.OcpDate; |
| | 626 | | } |
| | 627 | | // Tracing |
| 2 | 628 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 629 | | string _invocationId = null; |
| 2 | 630 | | if (_shouldTrace) |
| | 631 | | { |
| 0 | 632 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 633 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 634 | | tracingParameters.Add("nextPageLink", nextPageLink); |
| 0 | 635 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 636 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 637 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 638 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 639 | | ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters); |
| | 640 | | } |
| | 641 | | // Construct URL |
| 2 | 642 | | string _url = "{nextLink}"; |
| 2 | 643 | | _url = _url.Replace("{nextLink}", nextPageLink); |
| 2 | 644 | | List<string> _queryParameters = new List<string>(); |
| 2 | 645 | | if (_queryParameters.Count > 0) |
| | 646 | | { |
| 0 | 647 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 648 | | } |
| | 649 | | // Create HTTP transport objects |
| 2 | 650 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 651 | | HttpResponseMessage _httpResponse = null; |
| 2 | 652 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 653 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 654 | | // Set Headers |
| 2 | 655 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 656 | | { |
| 2 | 657 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 658 | | } |
| 2 | 659 | | if (Client.AcceptLanguage != null) |
| | 660 | | { |
| 2 | 661 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 662 | | { |
| 0 | 663 | | _httpRequest.Headers.Remove("accept-language"); |
| | 664 | | } |
| 2 | 665 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 666 | | } |
| 2 | 667 | | if (clientRequestId != null) |
| | 668 | | { |
| 2 | 669 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 670 | | { |
| 2 | 671 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 672 | | } |
| 2 | 673 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 674 | | } |
| 2 | 675 | | if (returnClientRequestId != null) |
| | 676 | | { |
| 0 | 677 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 678 | | { |
| 0 | 679 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 680 | | } |
| 0 | 681 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 682 | | } |
| 2 | 683 | | if (ocpDate != null) |
| | 684 | | { |
| 0 | 685 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 686 | | { |
| 0 | 687 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 688 | | } |
| 0 | 689 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 690 | | } |
| | 691 | |
|
| | 692 | |
|
| 2 | 693 | | if (customHeaders != null) |
| | 694 | | { |
| 0 | 695 | | foreach(var _header in customHeaders) |
| | 696 | | { |
| 0 | 697 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 698 | | { |
| 0 | 699 | | _httpRequest.Headers.Remove(_header.Key); |
| | 700 | | } |
| 0 | 701 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 702 | | } |
| | 703 | | } |
| | 704 | |
|
| | 705 | | // Serialize Request |
| 2 | 706 | | string _requestContent = null; |
| | 707 | | // Set Credentials |
| 2 | 708 | | if (Client.Credentials != null) |
| | 709 | | { |
| 2 | 710 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 711 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 712 | | } |
| | 713 | | // Send Request |
| 2 | 714 | | if (_shouldTrace) |
| | 715 | | { |
| 0 | 716 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 717 | | } |
| 2 | 718 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 719 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 720 | | if (_shouldTrace) |
| | 721 | | { |
| 0 | 722 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 723 | | } |
| 2 | 724 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 725 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 726 | | string _responseContent = null; |
| 2 | 727 | | if ((int)_statusCode != 200) |
| | 728 | | { |
| 0 | 729 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 730 | | try |
| | 731 | | { |
| 0 | 732 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 733 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 734 | | if (_errorBody != null) |
| | 735 | | { |
| 0 | 736 | | ex.Body = _errorBody; |
| | 737 | | } |
| 0 | 738 | | } |
| 0 | 739 | | catch (JsonException) |
| | 740 | | { |
| | 741 | | // Ignore the exception |
| 0 | 742 | | } |
| 0 | 743 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 744 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 745 | | if (_shouldTrace) |
| | 746 | | { |
| 0 | 747 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 748 | | } |
| 0 | 749 | | _httpRequest.Dispose(); |
| 0 | 750 | | if (_httpResponse != null) |
| | 751 | | { |
| 0 | 752 | | _httpResponse.Dispose(); |
| | 753 | | } |
| 0 | 754 | | throw ex; |
| | 755 | | } |
| | 756 | | // Create Result |
| 2 | 757 | | var _result = new AzureOperationResponse<IPage<ApplicationSummary>,ApplicationListHeaders>(); |
| 2 | 758 | | _result.Request = _httpRequest; |
| 2 | 759 | | _result.Response = _httpResponse; |
| 2 | 760 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 761 | | { |
| 0 | 762 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 763 | | } |
| | 764 | | // Deserialize Response |
| 2 | 765 | | if ((int)_statusCode == 200) |
| | 766 | | { |
| 2 | 767 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 768 | | try |
| | 769 | | { |
| 2 | 770 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<ApplicationSummary>>(_responseContent, Client. |
| 2 | 771 | | } |
| 0 | 772 | | catch (JsonException ex) |
| | 773 | | { |
| 0 | 774 | | _httpRequest.Dispose(); |
| 0 | 775 | | if (_httpResponse != null) |
| | 776 | | { |
| 0 | 777 | | _httpResponse.Dispose(); |
| | 778 | | } |
| 0 | 779 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 780 | | } |
| | 781 | | } |
| | 782 | | try |
| | 783 | | { |
| 2 | 784 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ApplicationListHeaders>(JsonSerializer.Creat |
| 2 | 785 | | } |
| 0 | 786 | | catch (JsonException ex) |
| | 787 | | { |
| 0 | 788 | | _httpRequest.Dispose(); |
| 0 | 789 | | if (_httpResponse != null) |
| | 790 | | { |
| 0 | 791 | | _httpResponse.Dispose(); |
| | 792 | | } |
| 0 | 793 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 794 | | } |
| 2 | 795 | | if (_shouldTrace) |
| | 796 | | { |
| 0 | 797 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 798 | | } |
| 2 | 799 | | return _result; |
| 2 | 800 | | } |
| | 801 | |
|
| | 802 | | } |
| | 803 | | } |