| | 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 | | /// CertificateOperations operations. |
| | 28 | | /// </summary> |
| | 29 | | internal partial class CertificateOperations : IServiceOperations<BatchServiceClient>, ICertificateOperations |
| | 30 | | { |
| | 31 | | /// <summary> |
| | 32 | | /// Initializes a new instance of the CertificateOperations 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 CertificateOperations(BatchServiceClient client) |
| | 41 | | { |
| 148 | 42 | | if (client == null) |
| | 43 | | { |
| 0 | 44 | | throw new System.ArgumentNullException("client"); |
| | 45 | | } |
| 148 | 46 | | Client = client; |
| 148 | 47 | | } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Gets a reference to the BatchServiceClient |
| | 51 | | /// </summary> |
| 141 | 52 | | public BatchServiceClient Client { get; private set; } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Adds a Certificate to the specified Account. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name='certificate'> |
| | 58 | | /// The Certificate to be added. |
| | 59 | | /// </param> |
| | 60 | | /// <param name='certificateAddOptions'> |
| | 61 | | /// Additional parameters for the operation |
| | 62 | | /// </param> |
| | 63 | | /// <param name='customHeaders'> |
| | 64 | | /// Headers that will be added to request. |
| | 65 | | /// </param> |
| | 66 | | /// <param name='cancellationToken'> |
| | 67 | | /// The cancellation token. |
| | 68 | | /// </param> |
| | 69 | | /// <exception cref="BatchErrorException"> |
| | 70 | | /// Thrown when the operation returned an invalid status code |
| | 71 | | /// </exception> |
| | 72 | | /// <exception cref="ValidationException"> |
| | 73 | | /// Thrown when a required parameter is null |
| | 74 | | /// </exception> |
| | 75 | | /// <exception cref="System.ArgumentNullException"> |
| | 76 | | /// Thrown when a required parameter is null |
| | 77 | | /// </exception> |
| | 78 | | /// <return> |
| | 79 | | /// A response object containing the response body and response headers. |
| | 80 | | /// </return> |
| | 81 | | public async Task<AzureOperationHeaderResponse<CertificateAddHeaders>> AddWithHttpMessagesAsync(CertificateAddPa |
| | 82 | | { |
| 0 | 83 | | if (Client.BatchUrl == null) |
| | 84 | | { |
| 0 | 85 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 86 | | } |
| 0 | 87 | | if (certificate == null) |
| | 88 | | { |
| 0 | 89 | | throw new ValidationException(ValidationRules.CannotBeNull, "certificate"); |
| | 90 | | } |
| 0 | 91 | | if (Client.ApiVersion == null) |
| | 92 | | { |
| 0 | 93 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 94 | | } |
| 0 | 95 | | int? timeout = default(int?); |
| 0 | 96 | | if (certificateAddOptions != null) |
| | 97 | | { |
| 0 | 98 | | timeout = certificateAddOptions.Timeout; |
| | 99 | | } |
| 0 | 100 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 101 | | if (certificateAddOptions != null) |
| | 102 | | { |
| 0 | 103 | | clientRequestId = certificateAddOptions.ClientRequestId; |
| | 104 | | } |
| 0 | 105 | | bool? returnClientRequestId = default(bool?); |
| 0 | 106 | | if (certificateAddOptions != null) |
| | 107 | | { |
| 0 | 108 | | returnClientRequestId = certificateAddOptions.ReturnClientRequestId; |
| | 109 | | } |
| 0 | 110 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 111 | | if (certificateAddOptions != null) |
| | 112 | | { |
| 0 | 113 | | ocpDate = certificateAddOptions.OcpDate; |
| | 114 | | } |
| | 115 | | // Tracing |
| 0 | 116 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 117 | | string _invocationId = null; |
| 0 | 118 | | if (_shouldTrace) |
| | 119 | | { |
| 0 | 120 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 121 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 122 | | tracingParameters.Add("certificate", certificate); |
| 0 | 123 | | tracingParameters.Add("timeout", timeout); |
| 0 | 124 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 125 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 126 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 127 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 128 | | ServiceClientTracing.Enter(_invocationId, this, "Add", tracingParameters); |
| | 129 | | } |
| | 130 | | // Construct URL |
| 0 | 131 | | var _baseUrl = Client.BaseUri; |
| 0 | 132 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "certificates"; |
| 0 | 133 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 134 | | List<string> _queryParameters = new List<string>(); |
| 0 | 135 | | if (Client.ApiVersion != null) |
| | 136 | | { |
| 0 | 137 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 138 | | } |
| 0 | 139 | | if (timeout != null) |
| | 140 | | { |
| 0 | 141 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 142 | | } |
| 0 | 143 | | if (_queryParameters.Count > 0) |
| | 144 | | { |
| 0 | 145 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 146 | | } |
| | 147 | | // Create HTTP transport objects |
| 0 | 148 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 149 | | HttpResponseMessage _httpResponse = null; |
| 0 | 150 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 151 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 152 | | // Set Headers |
| 0 | 153 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 154 | | { |
| 0 | 155 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 156 | | } |
| 0 | 157 | | if (Client.AcceptLanguage != null) |
| | 158 | | { |
| 0 | 159 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 160 | | { |
| 0 | 161 | | _httpRequest.Headers.Remove("accept-language"); |
| | 162 | | } |
| 0 | 163 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 164 | | } |
| 0 | 165 | | if (clientRequestId != null) |
| | 166 | | { |
| 0 | 167 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 168 | | { |
| 0 | 169 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 170 | | } |
| 0 | 171 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 172 | | } |
| 0 | 173 | | if (returnClientRequestId != null) |
| | 174 | | { |
| 0 | 175 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 176 | | { |
| 0 | 177 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 178 | | } |
| 0 | 179 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 180 | | } |
| 0 | 181 | | if (ocpDate != null) |
| | 182 | | { |
| 0 | 183 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 184 | | { |
| 0 | 185 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 186 | | } |
| 0 | 187 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 188 | | } |
| | 189 | |
|
| | 190 | |
|
| 0 | 191 | | if (customHeaders != null) |
| | 192 | | { |
| 0 | 193 | | foreach(var _header in customHeaders) |
| | 194 | | { |
| 0 | 195 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 196 | | { |
| 0 | 197 | | _httpRequest.Headers.Remove(_header.Key); |
| | 198 | | } |
| 0 | 199 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 200 | | } |
| | 201 | | } |
| | 202 | |
|
| | 203 | | // Serialize Request |
| 0 | 204 | | string _requestContent = null; |
| 0 | 205 | | if(certificate != null) |
| | 206 | | { |
| 0 | 207 | | _requestContent = SafeJsonConvert.SerializeObject(certificate, Client.SerializationSettings); |
| 0 | 208 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 209 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 210 | | } |
| | 211 | | // Set Credentials |
| 0 | 212 | | if (Client.Credentials != null) |
| | 213 | | { |
| 0 | 214 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 215 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 216 | | } |
| | 217 | | // Send Request |
| 0 | 218 | | if (_shouldTrace) |
| | 219 | | { |
| 0 | 220 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 221 | | } |
| 0 | 222 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 223 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 224 | | if (_shouldTrace) |
| | 225 | | { |
| 0 | 226 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 227 | | } |
| 0 | 228 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 229 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 230 | | string _responseContent = null; |
| 0 | 231 | | if ((int)_statusCode != 201) |
| | 232 | | { |
| 0 | 233 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 234 | | try |
| | 235 | | { |
| 0 | 236 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 237 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 238 | | if (_errorBody != null) |
| | 239 | | { |
| 0 | 240 | | ex.Body = _errorBody; |
| | 241 | | } |
| 0 | 242 | | } |
| 0 | 243 | | catch (JsonException) |
| | 244 | | { |
| | 245 | | // Ignore the exception |
| 0 | 246 | | } |
| 0 | 247 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 248 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 249 | | if (_shouldTrace) |
| | 250 | | { |
| 0 | 251 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 252 | | } |
| 0 | 253 | | _httpRequest.Dispose(); |
| 0 | 254 | | if (_httpResponse != null) |
| | 255 | | { |
| 0 | 256 | | _httpResponse.Dispose(); |
| | 257 | | } |
| 0 | 258 | | throw ex; |
| | 259 | | } |
| | 260 | | // Create Result |
| 0 | 261 | | var _result = new AzureOperationHeaderResponse<CertificateAddHeaders>(); |
| 0 | 262 | | _result.Request = _httpRequest; |
| 0 | 263 | | _result.Response = _httpResponse; |
| 0 | 264 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 265 | | { |
| 0 | 266 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 267 | | } |
| | 268 | | try |
| | 269 | | { |
| 0 | 270 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<CertificateAddHeaders>(JsonSerializer.Create |
| 0 | 271 | | } |
| 0 | 272 | | catch (JsonException ex) |
| | 273 | | { |
| 0 | 274 | | _httpRequest.Dispose(); |
| 0 | 275 | | if (_httpResponse != null) |
| | 276 | | { |
| 0 | 277 | | _httpResponse.Dispose(); |
| | 278 | | } |
| 0 | 279 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 280 | | } |
| 0 | 281 | | if (_shouldTrace) |
| | 282 | | { |
| 0 | 283 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 284 | | } |
| 0 | 285 | | return _result; |
| 0 | 286 | | } |
| | 287 | |
|
| | 288 | | /// <summary> |
| | 289 | | /// Lists all of the Certificates that have been added to the specified |
| | 290 | | /// Account. |
| | 291 | | /// </summary> |
| | 292 | | /// <param name='certificateListOptions'> |
| | 293 | | /// Additional parameters for the operation |
| | 294 | | /// </param> |
| | 295 | | /// <param name='customHeaders'> |
| | 296 | | /// Headers that will be added to request. |
| | 297 | | /// </param> |
| | 298 | | /// <param name='cancellationToken'> |
| | 299 | | /// The cancellation token. |
| | 300 | | /// </param> |
| | 301 | | /// <exception cref="BatchErrorException"> |
| | 302 | | /// Thrown when the operation returned an invalid status code |
| | 303 | | /// </exception> |
| | 304 | | /// <exception cref="SerializationException"> |
| | 305 | | /// Thrown when unable to deserialize the response |
| | 306 | | /// </exception> |
| | 307 | | /// <exception cref="ValidationException"> |
| | 308 | | /// Thrown when a required parameter is null |
| | 309 | | /// </exception> |
| | 310 | | /// <exception cref="System.ArgumentNullException"> |
| | 311 | | /// Thrown when a required parameter is null |
| | 312 | | /// </exception> |
| | 313 | | /// <return> |
| | 314 | | /// A response object containing the response body and response headers. |
| | 315 | | /// </return> |
| | 316 | | public async Task<AzureOperationResponse<IPage<Certificate>,CertificateListHeaders>> ListWithHttpMessagesAsync(C |
| | 317 | | { |
| 0 | 318 | | if (Client.BatchUrl == null) |
| | 319 | | { |
| 0 | 320 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 321 | | } |
| 0 | 322 | | if (Client.ApiVersion == null) |
| | 323 | | { |
| 0 | 324 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 325 | | } |
| 0 | 326 | | string filter = default(string); |
| 0 | 327 | | if (certificateListOptions != null) |
| | 328 | | { |
| 0 | 329 | | filter = certificateListOptions.Filter; |
| | 330 | | } |
| 0 | 331 | | string select = default(string); |
| 0 | 332 | | if (certificateListOptions != null) |
| | 333 | | { |
| 0 | 334 | | select = certificateListOptions.Select; |
| | 335 | | } |
| 0 | 336 | | int? maxResults = default(int?); |
| 0 | 337 | | if (certificateListOptions != null) |
| | 338 | | { |
| 0 | 339 | | maxResults = certificateListOptions.MaxResults; |
| | 340 | | } |
| 0 | 341 | | int? timeout = default(int?); |
| 0 | 342 | | if (certificateListOptions != null) |
| | 343 | | { |
| 0 | 344 | | timeout = certificateListOptions.Timeout; |
| | 345 | | } |
| 0 | 346 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 347 | | if (certificateListOptions != null) |
| | 348 | | { |
| 0 | 349 | | clientRequestId = certificateListOptions.ClientRequestId; |
| | 350 | | } |
| 0 | 351 | | bool? returnClientRequestId = default(bool?); |
| 0 | 352 | | if (certificateListOptions != null) |
| | 353 | | { |
| 0 | 354 | | returnClientRequestId = certificateListOptions.ReturnClientRequestId; |
| | 355 | | } |
| 0 | 356 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 357 | | if (certificateListOptions != null) |
| | 358 | | { |
| 0 | 359 | | ocpDate = certificateListOptions.OcpDate; |
| | 360 | | } |
| | 361 | | // Tracing |
| 0 | 362 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 363 | | string _invocationId = null; |
| 0 | 364 | | if (_shouldTrace) |
| | 365 | | { |
| 0 | 366 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 367 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 368 | | tracingParameters.Add("filter", filter); |
| 0 | 369 | | tracingParameters.Add("select", select); |
| 0 | 370 | | tracingParameters.Add("maxResults", maxResults); |
| 0 | 371 | | tracingParameters.Add("timeout", timeout); |
| 0 | 372 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 373 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 374 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 375 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 376 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 377 | | } |
| | 378 | | // Construct URL |
| 0 | 379 | | var _baseUrl = Client.BaseUri; |
| 0 | 380 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "certificates"; |
| 0 | 381 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 382 | | List<string> _queryParameters = new List<string>(); |
| 0 | 383 | | if (Client.ApiVersion != null) |
| | 384 | | { |
| 0 | 385 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 386 | | } |
| 0 | 387 | | if (filter != null) |
| | 388 | | { |
| 0 | 389 | | _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter))); |
| | 390 | | } |
| 0 | 391 | | if (select != null) |
| | 392 | | { |
| 0 | 393 | | _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select))); |
| | 394 | | } |
| 0 | 395 | | if (maxResults != null) |
| | 396 | | { |
| 0 | 397 | | _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali |
| | 398 | | } |
| 0 | 399 | | if (timeout != null) |
| | 400 | | { |
| 0 | 401 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 402 | | } |
| 0 | 403 | | if (_queryParameters.Count > 0) |
| | 404 | | { |
| 0 | 405 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 406 | | } |
| | 407 | | // Create HTTP transport objects |
| 0 | 408 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 409 | | HttpResponseMessage _httpResponse = null; |
| 0 | 410 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 411 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 412 | | // Set Headers |
| 0 | 413 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 414 | | { |
| 0 | 415 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 416 | | } |
| 0 | 417 | | if (Client.AcceptLanguage != null) |
| | 418 | | { |
| 0 | 419 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 420 | | { |
| 0 | 421 | | _httpRequest.Headers.Remove("accept-language"); |
| | 422 | | } |
| 0 | 423 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 424 | | } |
| 0 | 425 | | if (clientRequestId != null) |
| | 426 | | { |
| 0 | 427 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 428 | | { |
| 0 | 429 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 430 | | } |
| 0 | 431 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 432 | | } |
| 0 | 433 | | if (returnClientRequestId != null) |
| | 434 | | { |
| 0 | 435 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 436 | | { |
| 0 | 437 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 438 | | } |
| 0 | 439 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 440 | | } |
| 0 | 441 | | if (ocpDate != null) |
| | 442 | | { |
| 0 | 443 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 444 | | { |
| 0 | 445 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 446 | | } |
| 0 | 447 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 448 | | } |
| | 449 | |
|
| | 450 | |
|
| 0 | 451 | | if (customHeaders != null) |
| | 452 | | { |
| 0 | 453 | | foreach(var _header in customHeaders) |
| | 454 | | { |
| 0 | 455 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 456 | | { |
| 0 | 457 | | _httpRequest.Headers.Remove(_header.Key); |
| | 458 | | } |
| 0 | 459 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 460 | | } |
| | 461 | | } |
| | 462 | |
|
| | 463 | | // Serialize Request |
| 0 | 464 | | string _requestContent = null; |
| | 465 | | // Set Credentials |
| 0 | 466 | | if (Client.Credentials != null) |
| | 467 | | { |
| 0 | 468 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 469 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 470 | | } |
| | 471 | | // Send Request |
| 0 | 472 | | if (_shouldTrace) |
| | 473 | | { |
| 0 | 474 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 475 | | } |
| 0 | 476 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 477 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 478 | | if (_shouldTrace) |
| | 479 | | { |
| 0 | 480 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 481 | | } |
| 0 | 482 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 483 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 484 | | string _responseContent = null; |
| 0 | 485 | | if ((int)_statusCode != 200) |
| | 486 | | { |
| 0 | 487 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 488 | | try |
| | 489 | | { |
| 0 | 490 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 491 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 492 | | if (_errorBody != null) |
| | 493 | | { |
| 0 | 494 | | ex.Body = _errorBody; |
| | 495 | | } |
| 0 | 496 | | } |
| 0 | 497 | | catch (JsonException) |
| | 498 | | { |
| | 499 | | // Ignore the exception |
| 0 | 500 | | } |
| 0 | 501 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 502 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 503 | | if (_shouldTrace) |
| | 504 | | { |
| 0 | 505 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 506 | | } |
| 0 | 507 | | _httpRequest.Dispose(); |
| 0 | 508 | | if (_httpResponse != null) |
| | 509 | | { |
| 0 | 510 | | _httpResponse.Dispose(); |
| | 511 | | } |
| 0 | 512 | | throw ex; |
| | 513 | | } |
| | 514 | | // Create Result |
| 0 | 515 | | var _result = new AzureOperationResponse<IPage<Certificate>,CertificateListHeaders>(); |
| 0 | 516 | | _result.Request = _httpRequest; |
| 0 | 517 | | _result.Response = _httpResponse; |
| 0 | 518 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 519 | | { |
| 0 | 520 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 521 | | } |
| | 522 | | // Deserialize Response |
| 0 | 523 | | if ((int)_statusCode == 200) |
| | 524 | | { |
| 0 | 525 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 526 | | try |
| | 527 | | { |
| 0 | 528 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<Certificate>>(_responseContent, Client.Deseria |
| 0 | 529 | | } |
| 0 | 530 | | catch (JsonException ex) |
| | 531 | | { |
| 0 | 532 | | _httpRequest.Dispose(); |
| 0 | 533 | | if (_httpResponse != null) |
| | 534 | | { |
| 0 | 535 | | _httpResponse.Dispose(); |
| | 536 | | } |
| 0 | 537 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 538 | | } |
| | 539 | | } |
| | 540 | | try |
| | 541 | | { |
| 0 | 542 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<CertificateListHeaders>(JsonSerializer.Creat |
| 0 | 543 | | } |
| 0 | 544 | | catch (JsonException ex) |
| | 545 | | { |
| 0 | 546 | | _httpRequest.Dispose(); |
| 0 | 547 | | if (_httpResponse != null) |
| | 548 | | { |
| 0 | 549 | | _httpResponse.Dispose(); |
| | 550 | | } |
| 0 | 551 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 552 | | } |
| 0 | 553 | | if (_shouldTrace) |
| | 554 | | { |
| 0 | 555 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 556 | | } |
| 0 | 557 | | return _result; |
| 0 | 558 | | } |
| | 559 | |
|
| | 560 | | /// <summary> |
| | 561 | | /// Cancels a failed deletion of a Certificate from the specified Account. |
| | 562 | | /// </summary> |
| | 563 | | /// <remarks> |
| | 564 | | /// If you try to delete a Certificate that is being used by a Pool or Compute |
| | 565 | | /// Node, the status of the Certificate changes to deleteFailed. If you decide |
| | 566 | | /// that you want to continue using the Certificate, you can use this operation |
| | 567 | | /// to set the status of the Certificate back to active. If you intend to |
| | 568 | | /// delete the Certificate, you do not need to run this operation after the |
| | 569 | | /// deletion failed. You must make sure that the Certificate is not being used |
| | 570 | | /// by any resources, and then you can try again to delete the Certificate. |
| | 571 | | /// </remarks> |
| | 572 | | /// <param name='thumbprintAlgorithm'> |
| | 573 | | /// The algorithm used to derive the thumbprint parameter. This must be sha1. |
| | 574 | | /// </param> |
| | 575 | | /// <param name='thumbprint'> |
| | 576 | | /// The thumbprint of the Certificate being deleted. |
| | 577 | | /// </param> |
| | 578 | | /// <param name='certificateCancelDeletionOptions'> |
| | 579 | | /// Additional parameters for the operation |
| | 580 | | /// </param> |
| | 581 | | /// <param name='customHeaders'> |
| | 582 | | /// Headers that will be added to request. |
| | 583 | | /// </param> |
| | 584 | | /// <param name='cancellationToken'> |
| | 585 | | /// The cancellation token. |
| | 586 | | /// </param> |
| | 587 | | /// <exception cref="BatchErrorException"> |
| | 588 | | /// Thrown when the operation returned an invalid status code |
| | 589 | | /// </exception> |
| | 590 | | /// <exception cref="ValidationException"> |
| | 591 | | /// Thrown when a required parameter is null |
| | 592 | | /// </exception> |
| | 593 | | /// <exception cref="System.ArgumentNullException"> |
| | 594 | | /// Thrown when a required parameter is null |
| | 595 | | /// </exception> |
| | 596 | | /// <return> |
| | 597 | | /// A response object containing the response body and response headers. |
| | 598 | | /// </return> |
| | 599 | | public async Task<AzureOperationHeaderResponse<CertificateCancelDeletionHeaders>> CancelDeletionWithHttpMessages |
| | 600 | | { |
| 0 | 601 | | if (Client.BatchUrl == null) |
| | 602 | | { |
| 0 | 603 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 604 | | } |
| 0 | 605 | | if (thumbprintAlgorithm == null) |
| | 606 | | { |
| 0 | 607 | | throw new ValidationException(ValidationRules.CannotBeNull, "thumbprintAlgorithm"); |
| | 608 | | } |
| 0 | 609 | | if (thumbprint == null) |
| | 610 | | { |
| 0 | 611 | | throw new ValidationException(ValidationRules.CannotBeNull, "thumbprint"); |
| | 612 | | } |
| 0 | 613 | | if (Client.ApiVersion == null) |
| | 614 | | { |
| 0 | 615 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 616 | | } |
| 0 | 617 | | int? timeout = default(int?); |
| 0 | 618 | | if (certificateCancelDeletionOptions != null) |
| | 619 | | { |
| 0 | 620 | | timeout = certificateCancelDeletionOptions.Timeout; |
| | 621 | | } |
| 0 | 622 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 623 | | if (certificateCancelDeletionOptions != null) |
| | 624 | | { |
| 0 | 625 | | clientRequestId = certificateCancelDeletionOptions.ClientRequestId; |
| | 626 | | } |
| 0 | 627 | | bool? returnClientRequestId = default(bool?); |
| 0 | 628 | | if (certificateCancelDeletionOptions != null) |
| | 629 | | { |
| 0 | 630 | | returnClientRequestId = certificateCancelDeletionOptions.ReturnClientRequestId; |
| | 631 | | } |
| 0 | 632 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 633 | | if (certificateCancelDeletionOptions != null) |
| | 634 | | { |
| 0 | 635 | | ocpDate = certificateCancelDeletionOptions.OcpDate; |
| | 636 | | } |
| | 637 | | // Tracing |
| 0 | 638 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 639 | | string _invocationId = null; |
| 0 | 640 | | if (_shouldTrace) |
| | 641 | | { |
| 0 | 642 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 643 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 644 | | tracingParameters.Add("thumbprintAlgorithm", thumbprintAlgorithm); |
| 0 | 645 | | tracingParameters.Add("thumbprint", thumbprint); |
| 0 | 646 | | tracingParameters.Add("timeout", timeout); |
| 0 | 647 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 648 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 649 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 650 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 651 | | ServiceClientTracing.Enter(_invocationId, this, "CancelDeletion", tracingParameters); |
| | 652 | | } |
| | 653 | | // Construct URL |
| 0 | 654 | | var _baseUrl = Client.BaseUri; |
| 0 | 655 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "certificates(thumbprintAlgorithm={thumbprintAlg |
| 0 | 656 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 657 | | _url = _url.Replace("{thumbprintAlgorithm}", System.Uri.EscapeDataString(thumbprintAlgorithm)); |
| 0 | 658 | | _url = _url.Replace("{thumbprint}", System.Uri.EscapeDataString(thumbprint)); |
| 0 | 659 | | List<string> _queryParameters = new List<string>(); |
| 0 | 660 | | if (Client.ApiVersion != null) |
| | 661 | | { |
| 0 | 662 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 663 | | } |
| 0 | 664 | | if (timeout != null) |
| | 665 | | { |
| 0 | 666 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 667 | | } |
| 0 | 668 | | if (_queryParameters.Count > 0) |
| | 669 | | { |
| 0 | 670 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 671 | | } |
| | 672 | | // Create HTTP transport objects |
| 0 | 673 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 674 | | HttpResponseMessage _httpResponse = null; |
| 0 | 675 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 676 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 677 | | // Set Headers |
| 0 | 678 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 679 | | { |
| 0 | 680 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 681 | | } |
| 0 | 682 | | if (Client.AcceptLanguage != null) |
| | 683 | | { |
| 0 | 684 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 685 | | { |
| 0 | 686 | | _httpRequest.Headers.Remove("accept-language"); |
| | 687 | | } |
| 0 | 688 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 689 | | } |
| 0 | 690 | | if (clientRequestId != null) |
| | 691 | | { |
| 0 | 692 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 693 | | { |
| 0 | 694 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 695 | | } |
| 0 | 696 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 697 | | } |
| 0 | 698 | | if (returnClientRequestId != null) |
| | 699 | | { |
| 0 | 700 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 701 | | { |
| 0 | 702 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 703 | | } |
| 0 | 704 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 705 | | } |
| 0 | 706 | | if (ocpDate != null) |
| | 707 | | { |
| 0 | 708 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 709 | | { |
| 0 | 710 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 711 | | } |
| 0 | 712 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 713 | | } |
| | 714 | |
|
| | 715 | |
|
| 0 | 716 | | if (customHeaders != null) |
| | 717 | | { |
| 0 | 718 | | foreach(var _header in customHeaders) |
| | 719 | | { |
| 0 | 720 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 721 | | { |
| 0 | 722 | | _httpRequest.Headers.Remove(_header.Key); |
| | 723 | | } |
| 0 | 724 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 725 | | } |
| | 726 | | } |
| | 727 | |
|
| | 728 | | // Serialize Request |
| 0 | 729 | | string _requestContent = null; |
| | 730 | | // Set Credentials |
| 0 | 731 | | if (Client.Credentials != null) |
| | 732 | | { |
| 0 | 733 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 734 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 735 | | } |
| | 736 | | // Send Request |
| 0 | 737 | | if (_shouldTrace) |
| | 738 | | { |
| 0 | 739 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 740 | | } |
| 0 | 741 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 742 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 743 | | if (_shouldTrace) |
| | 744 | | { |
| 0 | 745 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 746 | | } |
| 0 | 747 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 748 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 749 | | string _responseContent = null; |
| 0 | 750 | | if ((int)_statusCode != 204) |
| | 751 | | { |
| 0 | 752 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 753 | | try |
| | 754 | | { |
| 0 | 755 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 756 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 757 | | if (_errorBody != null) |
| | 758 | | { |
| 0 | 759 | | ex.Body = _errorBody; |
| | 760 | | } |
| 0 | 761 | | } |
| 0 | 762 | | catch (JsonException) |
| | 763 | | { |
| | 764 | | // Ignore the exception |
| 0 | 765 | | } |
| 0 | 766 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 767 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 768 | | if (_shouldTrace) |
| | 769 | | { |
| 0 | 770 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 771 | | } |
| 0 | 772 | | _httpRequest.Dispose(); |
| 0 | 773 | | if (_httpResponse != null) |
| | 774 | | { |
| 0 | 775 | | _httpResponse.Dispose(); |
| | 776 | | } |
| 0 | 777 | | throw ex; |
| | 778 | | } |
| | 779 | | // Create Result |
| 0 | 780 | | var _result = new AzureOperationHeaderResponse<CertificateCancelDeletionHeaders>(); |
| 0 | 781 | | _result.Request = _httpRequest; |
| 0 | 782 | | _result.Response = _httpResponse; |
| 0 | 783 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 784 | | { |
| 0 | 785 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 786 | | } |
| | 787 | | try |
| | 788 | | { |
| 0 | 789 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<CertificateCancelDeletionHeaders>(JsonSerial |
| 0 | 790 | | } |
| 0 | 791 | | catch (JsonException ex) |
| | 792 | | { |
| 0 | 793 | | _httpRequest.Dispose(); |
| 0 | 794 | | if (_httpResponse != null) |
| | 795 | | { |
| 0 | 796 | | _httpResponse.Dispose(); |
| | 797 | | } |
| 0 | 798 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 799 | | } |
| 0 | 800 | | if (_shouldTrace) |
| | 801 | | { |
| 0 | 802 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 803 | | } |
| 0 | 804 | | return _result; |
| 0 | 805 | | } |
| | 806 | |
|
| | 807 | | /// <summary> |
| | 808 | | /// Deletes a Certificate from the specified Account. |
| | 809 | | /// </summary> |
| | 810 | | /// <remarks> |
| | 811 | | /// You cannot delete a Certificate if a resource (Pool or Compute Node) is |
| | 812 | | /// using it. Before you can delete a Certificate, you must therefore make sure |
| | 813 | | /// that the Certificate is not associated with any existing Pools, the |
| | 814 | | /// Certificate is not installed on any Nodes (even if you remove a Certificate |
| | 815 | | /// from a Pool, it is not removed from existing Compute Nodes in that Pool |
| | 816 | | /// until they restart), and no running Tasks depend on the Certificate. If you |
| | 817 | | /// try to delete a Certificate that is in use, the deletion fails. The |
| | 818 | | /// Certificate status changes to deleteFailed. You can use Cancel Delete |
| | 819 | | /// Certificate to set the status back to active if you decide that you want to |
| | 820 | | /// continue using the Certificate. |
| | 821 | | /// </remarks> |
| | 822 | | /// <param name='thumbprintAlgorithm'> |
| | 823 | | /// The algorithm used to derive the thumbprint parameter. This must be sha1. |
| | 824 | | /// </param> |
| | 825 | | /// <param name='thumbprint'> |
| | 826 | | /// The thumbprint of the Certificate to be deleted. |
| | 827 | | /// </param> |
| | 828 | | /// <param name='certificateDeleteOptions'> |
| | 829 | | /// Additional parameters for the operation |
| | 830 | | /// </param> |
| | 831 | | /// <param name='customHeaders'> |
| | 832 | | /// Headers that will be added to request. |
| | 833 | | /// </param> |
| | 834 | | /// <param name='cancellationToken'> |
| | 835 | | /// The cancellation token. |
| | 836 | | /// </param> |
| | 837 | | /// <exception cref="BatchErrorException"> |
| | 838 | | /// Thrown when the operation returned an invalid status code |
| | 839 | | /// </exception> |
| | 840 | | /// <exception cref="ValidationException"> |
| | 841 | | /// Thrown when a required parameter is null |
| | 842 | | /// </exception> |
| | 843 | | /// <exception cref="System.ArgumentNullException"> |
| | 844 | | /// Thrown when a required parameter is null |
| | 845 | | /// </exception> |
| | 846 | | /// <return> |
| | 847 | | /// A response object containing the response body and response headers. |
| | 848 | | /// </return> |
| | 849 | | public async Task<AzureOperationHeaderResponse<CertificateDeleteHeaders>> DeleteWithHttpMessagesAsync(string thu |
| | 850 | | { |
| 0 | 851 | | if (Client.BatchUrl == null) |
| | 852 | | { |
| 0 | 853 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 854 | | } |
| 0 | 855 | | if (thumbprintAlgorithm == null) |
| | 856 | | { |
| 0 | 857 | | throw new ValidationException(ValidationRules.CannotBeNull, "thumbprintAlgorithm"); |
| | 858 | | } |
| 0 | 859 | | if (thumbprint == null) |
| | 860 | | { |
| 0 | 861 | | throw new ValidationException(ValidationRules.CannotBeNull, "thumbprint"); |
| | 862 | | } |
| 0 | 863 | | if (Client.ApiVersion == null) |
| | 864 | | { |
| 0 | 865 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 866 | | } |
| 0 | 867 | | int? timeout = default(int?); |
| 0 | 868 | | if (certificateDeleteOptions != null) |
| | 869 | | { |
| 0 | 870 | | timeout = certificateDeleteOptions.Timeout; |
| | 871 | | } |
| 0 | 872 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 873 | | if (certificateDeleteOptions != null) |
| | 874 | | { |
| 0 | 875 | | clientRequestId = certificateDeleteOptions.ClientRequestId; |
| | 876 | | } |
| 0 | 877 | | bool? returnClientRequestId = default(bool?); |
| 0 | 878 | | if (certificateDeleteOptions != null) |
| | 879 | | { |
| 0 | 880 | | returnClientRequestId = certificateDeleteOptions.ReturnClientRequestId; |
| | 881 | | } |
| 0 | 882 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 883 | | if (certificateDeleteOptions != null) |
| | 884 | | { |
| 0 | 885 | | ocpDate = certificateDeleteOptions.OcpDate; |
| | 886 | | } |
| | 887 | | // Tracing |
| 0 | 888 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 889 | | string _invocationId = null; |
| 0 | 890 | | if (_shouldTrace) |
| | 891 | | { |
| 0 | 892 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 893 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 894 | | tracingParameters.Add("thumbprintAlgorithm", thumbprintAlgorithm); |
| 0 | 895 | | tracingParameters.Add("thumbprint", thumbprint); |
| 0 | 896 | | tracingParameters.Add("timeout", timeout); |
| 0 | 897 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 898 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 899 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 900 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 901 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 902 | | } |
| | 903 | | // Construct URL |
| 0 | 904 | | var _baseUrl = Client.BaseUri; |
| 0 | 905 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "certificates(thumbprintAlgorithm={thumbprintAlg |
| 0 | 906 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 907 | | _url = _url.Replace("{thumbprintAlgorithm}", System.Uri.EscapeDataString(thumbprintAlgorithm)); |
| 0 | 908 | | _url = _url.Replace("{thumbprint}", System.Uri.EscapeDataString(thumbprint)); |
| 0 | 909 | | List<string> _queryParameters = new List<string>(); |
| 0 | 910 | | if (Client.ApiVersion != null) |
| | 911 | | { |
| 0 | 912 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 913 | | } |
| 0 | 914 | | if (timeout != null) |
| | 915 | | { |
| 0 | 916 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 917 | | } |
| 0 | 918 | | if (_queryParameters.Count > 0) |
| | 919 | | { |
| 0 | 920 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 921 | | } |
| | 922 | | // Create HTTP transport objects |
| 0 | 923 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 924 | | HttpResponseMessage _httpResponse = null; |
| 0 | 925 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 926 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 927 | | // Set Headers |
| 0 | 928 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 929 | | { |
| 0 | 930 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 931 | | } |
| 0 | 932 | | if (Client.AcceptLanguage != null) |
| | 933 | | { |
| 0 | 934 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 935 | | { |
| 0 | 936 | | _httpRequest.Headers.Remove("accept-language"); |
| | 937 | | } |
| 0 | 938 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 939 | | } |
| 0 | 940 | | if (clientRequestId != null) |
| | 941 | | { |
| 0 | 942 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 943 | | { |
| 0 | 944 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 945 | | } |
| 0 | 946 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 947 | | } |
| 0 | 948 | | if (returnClientRequestId != null) |
| | 949 | | { |
| 0 | 950 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 951 | | { |
| 0 | 952 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 953 | | } |
| 0 | 954 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 955 | | } |
| 0 | 956 | | if (ocpDate != null) |
| | 957 | | { |
| 0 | 958 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 959 | | { |
| 0 | 960 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 961 | | } |
| 0 | 962 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 963 | | } |
| | 964 | |
|
| | 965 | |
|
| 0 | 966 | | if (customHeaders != null) |
| | 967 | | { |
| 0 | 968 | | foreach(var _header in customHeaders) |
| | 969 | | { |
| 0 | 970 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 971 | | { |
| 0 | 972 | | _httpRequest.Headers.Remove(_header.Key); |
| | 973 | | } |
| 0 | 974 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 975 | | } |
| | 976 | | } |
| | 977 | |
|
| | 978 | | // Serialize Request |
| 0 | 979 | | string _requestContent = null; |
| | 980 | | // Set Credentials |
| 0 | 981 | | if (Client.Credentials != null) |
| | 982 | | { |
| 0 | 983 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 984 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 985 | | } |
| | 986 | | // Send Request |
| 0 | 987 | | if (_shouldTrace) |
| | 988 | | { |
| 0 | 989 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 990 | | } |
| 0 | 991 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 992 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 993 | | if (_shouldTrace) |
| | 994 | | { |
| 0 | 995 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 996 | | } |
| 0 | 997 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 998 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 999 | | string _responseContent = null; |
| 0 | 1000 | | if ((int)_statusCode != 202) |
| | 1001 | | { |
| 0 | 1002 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1003 | | try |
| | 1004 | | { |
| 0 | 1005 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1006 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 1007 | | if (_errorBody != null) |
| | 1008 | | { |
| 0 | 1009 | | ex.Body = _errorBody; |
| | 1010 | | } |
| 0 | 1011 | | } |
| 0 | 1012 | | catch (JsonException) |
| | 1013 | | { |
| | 1014 | | // Ignore the exception |
| 0 | 1015 | | } |
| 0 | 1016 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1017 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1018 | | if (_shouldTrace) |
| | 1019 | | { |
| 0 | 1020 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1021 | | } |
| 0 | 1022 | | _httpRequest.Dispose(); |
| 0 | 1023 | | if (_httpResponse != null) |
| | 1024 | | { |
| 0 | 1025 | | _httpResponse.Dispose(); |
| | 1026 | | } |
| 0 | 1027 | | throw ex; |
| | 1028 | | } |
| | 1029 | | // Create Result |
| 0 | 1030 | | var _result = new AzureOperationHeaderResponse<CertificateDeleteHeaders>(); |
| 0 | 1031 | | _result.Request = _httpRequest; |
| 0 | 1032 | | _result.Response = _httpResponse; |
| 0 | 1033 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1034 | | { |
| 0 | 1035 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1036 | | } |
| | 1037 | | try |
| | 1038 | | { |
| 0 | 1039 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<CertificateDeleteHeaders>(JsonSerializer.Cre |
| 0 | 1040 | | } |
| 0 | 1041 | | catch (JsonException ex) |
| | 1042 | | { |
| 0 | 1043 | | _httpRequest.Dispose(); |
| 0 | 1044 | | if (_httpResponse != null) |
| | 1045 | | { |
| 0 | 1046 | | _httpResponse.Dispose(); |
| | 1047 | | } |
| 0 | 1048 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1049 | | } |
| 0 | 1050 | | if (_shouldTrace) |
| | 1051 | | { |
| 0 | 1052 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1053 | | } |
| 0 | 1054 | | return _result; |
| 0 | 1055 | | } |
| | 1056 | |
|
| | 1057 | | /// <summary> |
| | 1058 | | /// Gets information about the specified Certificate. |
| | 1059 | | /// </summary> |
| | 1060 | | /// <param name='thumbprintAlgorithm'> |
| | 1061 | | /// The algorithm used to derive the thumbprint parameter. This must be sha1. |
| | 1062 | | /// </param> |
| | 1063 | | /// <param name='thumbprint'> |
| | 1064 | | /// The thumbprint of the Certificate to get. |
| | 1065 | | /// </param> |
| | 1066 | | /// <param name='certificateGetOptions'> |
| | 1067 | | /// Additional parameters for the operation |
| | 1068 | | /// </param> |
| | 1069 | | /// <param name='customHeaders'> |
| | 1070 | | /// Headers that will be added to request. |
| | 1071 | | /// </param> |
| | 1072 | | /// <param name='cancellationToken'> |
| | 1073 | | /// The cancellation token. |
| | 1074 | | /// </param> |
| | 1075 | | /// <exception cref="BatchErrorException"> |
| | 1076 | | /// Thrown when the operation returned an invalid status code |
| | 1077 | | /// </exception> |
| | 1078 | | /// <exception cref="SerializationException"> |
| | 1079 | | /// Thrown when unable to deserialize the response |
| | 1080 | | /// </exception> |
| | 1081 | | /// <exception cref="ValidationException"> |
| | 1082 | | /// Thrown when a required parameter is null |
| | 1083 | | /// </exception> |
| | 1084 | | /// <exception cref="System.ArgumentNullException"> |
| | 1085 | | /// Thrown when a required parameter is null |
| | 1086 | | /// </exception> |
| | 1087 | | /// <return> |
| | 1088 | | /// A response object containing the response body and response headers. |
| | 1089 | | /// </return> |
| | 1090 | | public async Task<AzureOperationResponse<Certificate,CertificateGetHeaders>> GetWithHttpMessagesAsync(string thu |
| | 1091 | | { |
| 1 | 1092 | | if (Client.BatchUrl == null) |
| | 1093 | | { |
| 0 | 1094 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 1095 | | } |
| 1 | 1096 | | if (thumbprintAlgorithm == null) |
| | 1097 | | { |
| 1 | 1098 | | throw new ValidationException(ValidationRules.CannotBeNull, "thumbprintAlgorithm"); |
| | 1099 | | } |
| 0 | 1100 | | if (thumbprint == null) |
| | 1101 | | { |
| 0 | 1102 | | throw new ValidationException(ValidationRules.CannotBeNull, "thumbprint"); |
| | 1103 | | } |
| 0 | 1104 | | if (Client.ApiVersion == null) |
| | 1105 | | { |
| 0 | 1106 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1107 | | } |
| 0 | 1108 | | string select = default(string); |
| 0 | 1109 | | if (certificateGetOptions != null) |
| | 1110 | | { |
| 0 | 1111 | | select = certificateGetOptions.Select; |
| | 1112 | | } |
| 0 | 1113 | | int? timeout = default(int?); |
| 0 | 1114 | | if (certificateGetOptions != null) |
| | 1115 | | { |
| 0 | 1116 | | timeout = certificateGetOptions.Timeout; |
| | 1117 | | } |
| 0 | 1118 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 1119 | | if (certificateGetOptions != null) |
| | 1120 | | { |
| 0 | 1121 | | clientRequestId = certificateGetOptions.ClientRequestId; |
| | 1122 | | } |
| 0 | 1123 | | bool? returnClientRequestId = default(bool?); |
| 0 | 1124 | | if (certificateGetOptions != null) |
| | 1125 | | { |
| 0 | 1126 | | returnClientRequestId = certificateGetOptions.ReturnClientRequestId; |
| | 1127 | | } |
| 0 | 1128 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 1129 | | if (certificateGetOptions != null) |
| | 1130 | | { |
| 0 | 1131 | | ocpDate = certificateGetOptions.OcpDate; |
| | 1132 | | } |
| | 1133 | | // Tracing |
| 0 | 1134 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1135 | | string _invocationId = null; |
| 0 | 1136 | | if (_shouldTrace) |
| | 1137 | | { |
| 0 | 1138 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1139 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1140 | | tracingParameters.Add("thumbprintAlgorithm", thumbprintAlgorithm); |
| 0 | 1141 | | tracingParameters.Add("thumbprint", thumbprint); |
| 0 | 1142 | | tracingParameters.Add("select", select); |
| 0 | 1143 | | tracingParameters.Add("timeout", timeout); |
| 0 | 1144 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1145 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 1146 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 1147 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1148 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 1149 | | } |
| | 1150 | | // Construct URL |
| 0 | 1151 | | var _baseUrl = Client.BaseUri; |
| 0 | 1152 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "certificates(thumbprintAlgorithm={thumbprintAlg |
| 0 | 1153 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 1154 | | _url = _url.Replace("{thumbprintAlgorithm}", System.Uri.EscapeDataString(thumbprintAlgorithm)); |
| 0 | 1155 | | _url = _url.Replace("{thumbprint}", System.Uri.EscapeDataString(thumbprint)); |
| 0 | 1156 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1157 | | if (Client.ApiVersion != null) |
| | 1158 | | { |
| 0 | 1159 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1160 | | } |
| 0 | 1161 | | if (select != null) |
| | 1162 | | { |
| 0 | 1163 | | _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select))); |
| | 1164 | | } |
| 0 | 1165 | | if (timeout != null) |
| | 1166 | | { |
| 0 | 1167 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 1168 | | } |
| 0 | 1169 | | if (_queryParameters.Count > 0) |
| | 1170 | | { |
| 0 | 1171 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1172 | | } |
| | 1173 | | // Create HTTP transport objects |
| 0 | 1174 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1175 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1176 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1177 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1178 | | // Set Headers |
| 0 | 1179 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1180 | | { |
| 0 | 1181 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1182 | | } |
| 0 | 1183 | | if (Client.AcceptLanguage != null) |
| | 1184 | | { |
| 0 | 1185 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1186 | | { |
| 0 | 1187 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1188 | | } |
| 0 | 1189 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1190 | | } |
| 0 | 1191 | | if (clientRequestId != null) |
| | 1192 | | { |
| 0 | 1193 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1194 | | { |
| 0 | 1195 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1196 | | } |
| 0 | 1197 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 1198 | | } |
| 0 | 1199 | | if (returnClientRequestId != null) |
| | 1200 | | { |
| 0 | 1201 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 1202 | | { |
| 0 | 1203 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 1204 | | } |
| 0 | 1205 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 1206 | | } |
| 0 | 1207 | | if (ocpDate != null) |
| | 1208 | | { |
| 0 | 1209 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 1210 | | { |
| 0 | 1211 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 1212 | | } |
| 0 | 1213 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 1214 | | } |
| | 1215 | |
|
| | 1216 | |
|
| 0 | 1217 | | if (customHeaders != null) |
| | 1218 | | { |
| 0 | 1219 | | foreach(var _header in customHeaders) |
| | 1220 | | { |
| 0 | 1221 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1222 | | { |
| 0 | 1223 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1224 | | } |
| 0 | 1225 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1226 | | } |
| | 1227 | | } |
| | 1228 | |
|
| | 1229 | | // Serialize Request |
| 0 | 1230 | | string _requestContent = null; |
| | 1231 | | // Set Credentials |
| 0 | 1232 | | if (Client.Credentials != null) |
| | 1233 | | { |
| 0 | 1234 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1235 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1236 | | } |
| | 1237 | | // Send Request |
| 0 | 1238 | | if (_shouldTrace) |
| | 1239 | | { |
| 0 | 1240 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1241 | | } |
| 0 | 1242 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1243 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1244 | | if (_shouldTrace) |
| | 1245 | | { |
| 0 | 1246 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1247 | | } |
| 0 | 1248 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1249 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1250 | | string _responseContent = null; |
| 0 | 1251 | | if ((int)_statusCode != 200) |
| | 1252 | | { |
| 0 | 1253 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1254 | | try |
| | 1255 | | { |
| 0 | 1256 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1257 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 1258 | | if (_errorBody != null) |
| | 1259 | | { |
| 0 | 1260 | | ex.Body = _errorBody; |
| | 1261 | | } |
| 0 | 1262 | | } |
| 0 | 1263 | | catch (JsonException) |
| | 1264 | | { |
| | 1265 | | // Ignore the exception |
| 0 | 1266 | | } |
| 0 | 1267 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1268 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1269 | | if (_shouldTrace) |
| | 1270 | | { |
| 0 | 1271 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1272 | | } |
| 0 | 1273 | | _httpRequest.Dispose(); |
| 0 | 1274 | | if (_httpResponse != null) |
| | 1275 | | { |
| 0 | 1276 | | _httpResponse.Dispose(); |
| | 1277 | | } |
| 0 | 1278 | | throw ex; |
| | 1279 | | } |
| | 1280 | | // Create Result |
| 0 | 1281 | | var _result = new AzureOperationResponse<Certificate,CertificateGetHeaders>(); |
| 0 | 1282 | | _result.Request = _httpRequest; |
| 0 | 1283 | | _result.Response = _httpResponse; |
| 0 | 1284 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1285 | | { |
| 0 | 1286 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1287 | | } |
| | 1288 | | // Deserialize Response |
| 0 | 1289 | | if ((int)_statusCode == 200) |
| | 1290 | | { |
| 0 | 1291 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1292 | | try |
| | 1293 | | { |
| 0 | 1294 | | _result.Body = SafeJsonConvert.DeserializeObject<Certificate>(_responseContent, Client.Deserializati |
| 0 | 1295 | | } |
| 0 | 1296 | | catch (JsonException ex) |
| | 1297 | | { |
| 0 | 1298 | | _httpRequest.Dispose(); |
| 0 | 1299 | | if (_httpResponse != null) |
| | 1300 | | { |
| 0 | 1301 | | _httpResponse.Dispose(); |
| | 1302 | | } |
| 0 | 1303 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1304 | | } |
| | 1305 | | } |
| | 1306 | | try |
| | 1307 | | { |
| 0 | 1308 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<CertificateGetHeaders>(JsonSerializer.Create |
| 0 | 1309 | | } |
| 0 | 1310 | | catch (JsonException ex) |
| | 1311 | | { |
| 0 | 1312 | | _httpRequest.Dispose(); |
| 0 | 1313 | | if (_httpResponse != null) |
| | 1314 | | { |
| 0 | 1315 | | _httpResponse.Dispose(); |
| | 1316 | | } |
| 0 | 1317 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1318 | | } |
| 0 | 1319 | | if (_shouldTrace) |
| | 1320 | | { |
| 0 | 1321 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1322 | | } |
| 0 | 1323 | | return _result; |
| 0 | 1324 | | } |
| | 1325 | |
|
| | 1326 | | /// <summary> |
| | 1327 | | /// Lists all of the Certificates that have been added to the specified |
| | 1328 | | /// Account. |
| | 1329 | | /// </summary> |
| | 1330 | | /// <param name='nextPageLink'> |
| | 1331 | | /// The NextLink from the previous successful call to List operation. |
| | 1332 | | /// </param> |
| | 1333 | | /// <param name='certificateListNextOptions'> |
| | 1334 | | /// Additional parameters for the operation |
| | 1335 | | /// </param> |
| | 1336 | | /// <param name='customHeaders'> |
| | 1337 | | /// Headers that will be added to request. |
| | 1338 | | /// </param> |
| | 1339 | | /// <param name='cancellationToken'> |
| | 1340 | | /// The cancellation token. |
| | 1341 | | /// </param> |
| | 1342 | | /// <exception cref="BatchErrorException"> |
| | 1343 | | /// Thrown when the operation returned an invalid status code |
| | 1344 | | /// </exception> |
| | 1345 | | /// <exception cref="SerializationException"> |
| | 1346 | | /// Thrown when unable to deserialize the response |
| | 1347 | | /// </exception> |
| | 1348 | | /// <exception cref="ValidationException"> |
| | 1349 | | /// Thrown when a required parameter is null |
| | 1350 | | /// </exception> |
| | 1351 | | /// <exception cref="System.ArgumentNullException"> |
| | 1352 | | /// Thrown when a required parameter is null |
| | 1353 | | /// </exception> |
| | 1354 | | /// <return> |
| | 1355 | | /// A response object containing the response body and response headers. |
| | 1356 | | /// </return> |
| | 1357 | | public async Task<AzureOperationResponse<IPage<Certificate>,CertificateListHeaders>> ListNextWithHttpMessagesAsy |
| | 1358 | | { |
| 0 | 1359 | | if (nextPageLink == null) |
| | 1360 | | { |
| 0 | 1361 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); |
| | 1362 | | } |
| 0 | 1363 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 1364 | | if (certificateListNextOptions != null) |
| | 1365 | | { |
| 0 | 1366 | | clientRequestId = certificateListNextOptions.ClientRequestId; |
| | 1367 | | } |
| 0 | 1368 | | bool? returnClientRequestId = default(bool?); |
| 0 | 1369 | | if (certificateListNextOptions != null) |
| | 1370 | | { |
| 0 | 1371 | | returnClientRequestId = certificateListNextOptions.ReturnClientRequestId; |
| | 1372 | | } |
| 0 | 1373 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 1374 | | if (certificateListNextOptions != null) |
| | 1375 | | { |
| 0 | 1376 | | ocpDate = certificateListNextOptions.OcpDate; |
| | 1377 | | } |
| | 1378 | | // Tracing |
| 0 | 1379 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1380 | | string _invocationId = null; |
| 0 | 1381 | | if (_shouldTrace) |
| | 1382 | | { |
| 0 | 1383 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1384 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1385 | | tracingParameters.Add("nextPageLink", nextPageLink); |
| 0 | 1386 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1387 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 1388 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 1389 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1390 | | ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters); |
| | 1391 | | } |
| | 1392 | | // Construct URL |
| 0 | 1393 | | string _url = "{nextLink}"; |
| 0 | 1394 | | _url = _url.Replace("{nextLink}", nextPageLink); |
| 0 | 1395 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1396 | | if (_queryParameters.Count > 0) |
| | 1397 | | { |
| 0 | 1398 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1399 | | } |
| | 1400 | | // Create HTTP transport objects |
| 0 | 1401 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1402 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1403 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1404 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1405 | | // Set Headers |
| 0 | 1406 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1407 | | { |
| 0 | 1408 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1409 | | } |
| 0 | 1410 | | if (Client.AcceptLanguage != null) |
| | 1411 | | { |
| 0 | 1412 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1413 | | { |
| 0 | 1414 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1415 | | } |
| 0 | 1416 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1417 | | } |
| 0 | 1418 | | if (clientRequestId != null) |
| | 1419 | | { |
| 0 | 1420 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1421 | | { |
| 0 | 1422 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1423 | | } |
| 0 | 1424 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 1425 | | } |
| 0 | 1426 | | if (returnClientRequestId != null) |
| | 1427 | | { |
| 0 | 1428 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 1429 | | { |
| 0 | 1430 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 1431 | | } |
| 0 | 1432 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 1433 | | } |
| 0 | 1434 | | if (ocpDate != null) |
| | 1435 | | { |
| 0 | 1436 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 1437 | | { |
| 0 | 1438 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 1439 | | } |
| 0 | 1440 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 1441 | | } |
| | 1442 | |
|
| | 1443 | |
|
| 0 | 1444 | | if (customHeaders != null) |
| | 1445 | | { |
| 0 | 1446 | | foreach(var _header in customHeaders) |
| | 1447 | | { |
| 0 | 1448 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1449 | | { |
| 0 | 1450 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1451 | | } |
| 0 | 1452 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1453 | | } |
| | 1454 | | } |
| | 1455 | |
|
| | 1456 | | // Serialize Request |
| 0 | 1457 | | string _requestContent = null; |
| | 1458 | | // Set Credentials |
| 0 | 1459 | | if (Client.Credentials != null) |
| | 1460 | | { |
| 0 | 1461 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1462 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1463 | | } |
| | 1464 | | // Send Request |
| 0 | 1465 | | if (_shouldTrace) |
| | 1466 | | { |
| 0 | 1467 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1468 | | } |
| 0 | 1469 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1470 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1471 | | if (_shouldTrace) |
| | 1472 | | { |
| 0 | 1473 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1474 | | } |
| 0 | 1475 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1476 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1477 | | string _responseContent = null; |
| 0 | 1478 | | if ((int)_statusCode != 200) |
| | 1479 | | { |
| 0 | 1480 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1481 | | try |
| | 1482 | | { |
| 0 | 1483 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1484 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 1485 | | if (_errorBody != null) |
| | 1486 | | { |
| 0 | 1487 | | ex.Body = _errorBody; |
| | 1488 | | } |
| 0 | 1489 | | } |
| 0 | 1490 | | catch (JsonException) |
| | 1491 | | { |
| | 1492 | | // Ignore the exception |
| 0 | 1493 | | } |
| 0 | 1494 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1495 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1496 | | if (_shouldTrace) |
| | 1497 | | { |
| 0 | 1498 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1499 | | } |
| 0 | 1500 | | _httpRequest.Dispose(); |
| 0 | 1501 | | if (_httpResponse != null) |
| | 1502 | | { |
| 0 | 1503 | | _httpResponse.Dispose(); |
| | 1504 | | } |
| 0 | 1505 | | throw ex; |
| | 1506 | | } |
| | 1507 | | // Create Result |
| 0 | 1508 | | var _result = new AzureOperationResponse<IPage<Certificate>,CertificateListHeaders>(); |
| 0 | 1509 | | _result.Request = _httpRequest; |
| 0 | 1510 | | _result.Response = _httpResponse; |
| 0 | 1511 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1512 | | { |
| 0 | 1513 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1514 | | } |
| | 1515 | | // Deserialize Response |
| 0 | 1516 | | if ((int)_statusCode == 200) |
| | 1517 | | { |
| 0 | 1518 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1519 | | try |
| | 1520 | | { |
| 0 | 1521 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<Certificate>>(_responseContent, Client.Deseria |
| 0 | 1522 | | } |
| 0 | 1523 | | catch (JsonException ex) |
| | 1524 | | { |
| 0 | 1525 | | _httpRequest.Dispose(); |
| 0 | 1526 | | if (_httpResponse != null) |
| | 1527 | | { |
| 0 | 1528 | | _httpResponse.Dispose(); |
| | 1529 | | } |
| 0 | 1530 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1531 | | } |
| | 1532 | | } |
| | 1533 | | try |
| | 1534 | | { |
| 0 | 1535 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<CertificateListHeaders>(JsonSerializer.Creat |
| 0 | 1536 | | } |
| 0 | 1537 | | catch (JsonException ex) |
| | 1538 | | { |
| 0 | 1539 | | _httpRequest.Dispose(); |
| 0 | 1540 | | if (_httpResponse != null) |
| | 1541 | | { |
| 0 | 1542 | | _httpResponse.Dispose(); |
| | 1543 | | } |
| 0 | 1544 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1545 | | } |
| 0 | 1546 | | if (_shouldTrace) |
| | 1547 | | { |
| 0 | 1548 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1549 | | } |
| 0 | 1550 | | return _result; |
| 0 | 1551 | | } |
| | 1552 | |
|
| | 1553 | | } |
| | 1554 | | } |