| | 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.ContainerRegistry |
| | 12 | | { |
| | 13 | | using Microsoft.Rest; |
| | 14 | | using Microsoft.Rest.Azure; |
| | 15 | | using Models; |
| | 16 | | using Newtonsoft.Json; |
| | 17 | | using System.Collections; |
| | 18 | | using System.Collections.Generic; |
| | 19 | | using System.IO; |
| | 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 | | /// BlobOperations operations. |
| | 28 | | /// </summary> |
| | 29 | | internal partial class BlobOperations : IServiceOperations<AzureContainerRegistryClient>, IBlobOperations |
| | 30 | | { |
| | 31 | | /// <summary> |
| | 32 | | /// Initializes a new instance of the BlobOperations 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> |
| 60 | 40 | | internal BlobOperations(AzureContainerRegistryClient client) |
| | 41 | | { |
| 60 | 42 | | if (client == null) |
| | 43 | | { |
| 0 | 44 | | throw new System.ArgumentNullException("client"); |
| | 45 | | } |
| 60 | 46 | | Client = client; |
| 60 | 47 | | } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Gets a reference to the AzureContainerRegistryClient |
| | 51 | | /// </summary> |
| 496 | 52 | | public AzureContainerRegistryClient Client { get; private set; } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Retrieve the blob from the registry identified by digest. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name='name'> |
| | 58 | | /// Name of the image (including the namespace) |
| | 59 | | /// </param> |
| | 60 | | /// <param name='digest'> |
| | 61 | | /// Digest of a BLOB |
| | 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="CloudException"> |
| | 70 | | /// Thrown when the operation returned an invalid status code |
| | 71 | | /// </exception> |
| | 72 | | /// <exception cref="SerializationException"> |
| | 73 | | /// Thrown when unable to deserialize the response |
| | 74 | | /// </exception> |
| | 75 | | /// <exception cref="ValidationException"> |
| | 76 | | /// Thrown when a required parameter is null |
| | 77 | | /// </exception> |
| | 78 | | /// <exception cref="System.ArgumentNullException"> |
| | 79 | | /// Thrown when a required parameter is null |
| | 80 | | /// </exception> |
| | 81 | | /// <return> |
| | 82 | | /// A response object containing the response body and response headers. |
| | 83 | | /// </return> |
| | 84 | | public async Task<AzureOperationResponse<Stream,BlobGetHeaders>> GetWithHttpMessagesAsync(string name, string di |
| | 85 | | { |
| 6 | 86 | | if (Client.LoginUri == null) |
| | 87 | | { |
| 0 | 88 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 89 | | } |
| 6 | 90 | | if (name == null) |
| | 91 | | { |
| 0 | 92 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 93 | | } |
| 6 | 94 | | if (digest == null) |
| | 95 | | { |
| 0 | 96 | | throw new ValidationException(ValidationRules.CannotBeNull, "digest"); |
| | 97 | | } |
| | 98 | | // Tracing |
| 6 | 99 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 100 | | string _invocationId = null; |
| 6 | 101 | | if (_shouldTrace) |
| | 102 | | { |
| 0 | 103 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 104 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 105 | | tracingParameters.Add("name", name); |
| 0 | 106 | | tracingParameters.Add("digest", digest); |
| 0 | 107 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 108 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 109 | | } |
| | 110 | | // Construct URL |
| 6 | 111 | | var _baseUrl = Client.BaseUri; |
| 6 | 112 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/{digest}"; |
| 6 | 113 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 6 | 114 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 6 | 115 | | _url = _url.Replace("{digest}", System.Uri.EscapeDataString(digest)); |
| 6 | 116 | | List<string> _queryParameters = new List<string>(); |
| 6 | 117 | | if (_queryParameters.Count > 0) |
| | 118 | | { |
| 0 | 119 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 120 | | } |
| | 121 | | // Create HTTP transport objects |
| 6 | 122 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 123 | | HttpResponseMessage _httpResponse = null; |
| 6 | 124 | | _httpRequest.Method = new HttpMethod("GET"); |
| 6 | 125 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 126 | | // Set Headers |
| 6 | 127 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 128 | | { |
| 6 | 129 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 130 | | } |
| 6 | 131 | | if (Client.AcceptLanguage != null) |
| | 132 | | { |
| 6 | 133 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 134 | | { |
| 0 | 135 | | _httpRequest.Headers.Remove("accept-language"); |
| | 136 | | } |
| 6 | 137 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 138 | | } |
| | 139 | |
|
| | 140 | |
|
| 6 | 141 | | if (customHeaders != null) |
| | 142 | | { |
| 0 | 143 | | foreach(var _header in customHeaders) |
| | 144 | | { |
| 0 | 145 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 146 | | { |
| 0 | 147 | | _httpRequest.Headers.Remove(_header.Key); |
| | 148 | | } |
| 0 | 149 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 150 | | } |
| | 151 | | } |
| | 152 | |
|
| | 153 | | // Serialize Request |
| 6 | 154 | | string _requestContent = null; |
| | 155 | | // Set Credentials |
| 6 | 156 | | if (Client.Credentials != null) |
| | 157 | | { |
| 6 | 158 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 159 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 160 | | } |
| | 161 | | // Send Request |
| 6 | 162 | | if (_shouldTrace) |
| | 163 | | { |
| 0 | 164 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 165 | | } |
| 6 | 166 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 167 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons |
| 6 | 168 | | if (_shouldTrace) |
| | 169 | | { |
| 0 | 170 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 171 | | } |
| 6 | 172 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 173 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 174 | | string _responseContent = null; |
| 6 | 175 | | if ((int)_statusCode != 200 && (int)_statusCode != 307) |
| | 176 | | { |
| 0 | 177 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 178 | | try |
| | 179 | | { |
| 0 | 180 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 181 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 182 | | if (_errorBody != null) |
| | 183 | | { |
| 0 | 184 | | ex = new CloudException(_errorBody.Message); |
| 0 | 185 | | ex.Body = _errorBody; |
| | 186 | | } |
| 0 | 187 | | } |
| 0 | 188 | | catch (JsonException) |
| | 189 | | { |
| | 190 | | // Ignore the exception |
| 0 | 191 | | } |
| 0 | 192 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 193 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 194 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 195 | | { |
| 0 | 196 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 197 | | } |
| 0 | 198 | | if (_shouldTrace) |
| | 199 | | { |
| 0 | 200 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 201 | | } |
| 0 | 202 | | _httpRequest.Dispose(); |
| 0 | 203 | | if (_httpResponse != null) |
| | 204 | | { |
| 0 | 205 | | _httpResponse.Dispose(); |
| | 206 | | } |
| 0 | 207 | | throw ex; |
| | 208 | | } |
| | 209 | | // Create Result |
| 6 | 210 | | var _result = new AzureOperationResponse<Stream,BlobGetHeaders>(); |
| 6 | 211 | | _result.Request = _httpRequest; |
| 6 | 212 | | _result.Response = _httpResponse; |
| 6 | 213 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 214 | | { |
| 6 | 215 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 216 | | } |
| | 217 | | // Deserialize Response |
| 6 | 218 | | if ((int)_statusCode == 200) |
| | 219 | | { |
| 6 | 220 | | _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); |
| | 221 | | } |
| | 222 | | try |
| | 223 | | { |
| 6 | 224 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobGetHeaders>(JsonSerializer.Create(Client |
| 6 | 225 | | } |
| 0 | 226 | | catch (JsonException ex) |
| | 227 | | { |
| 0 | 228 | | _httpRequest.Dispose(); |
| 0 | 229 | | if (_httpResponse != null) |
| | 230 | | { |
| 0 | 231 | | _httpResponse.Dispose(); |
| | 232 | | } |
| 0 | 233 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 234 | | } |
| 6 | 235 | | if (_shouldTrace) |
| | 236 | | { |
| 0 | 237 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 238 | | } |
| 6 | 239 | | return _result; |
| 6 | 240 | | } |
| | 241 | |
|
| | 242 | | /// <summary> |
| | 243 | | /// Same as GET, except only the headers are returned. |
| | 244 | | /// </summary> |
| | 245 | | /// <param name='name'> |
| | 246 | | /// Name of the image (including the namespace) |
| | 247 | | /// </param> |
| | 248 | | /// <param name='digest'> |
| | 249 | | /// Digest of a BLOB |
| | 250 | | /// </param> |
| | 251 | | /// <param name='customHeaders'> |
| | 252 | | /// Headers that will be added to request. |
| | 253 | | /// </param> |
| | 254 | | /// <param name='cancellationToken'> |
| | 255 | | /// The cancellation token. |
| | 256 | | /// </param> |
| | 257 | | /// <exception cref="AcrErrorsException"> |
| | 258 | | /// Thrown when the operation returned an invalid status code |
| | 259 | | /// </exception> |
| | 260 | | /// <exception cref="ValidationException"> |
| | 261 | | /// Thrown when a required parameter is null |
| | 262 | | /// </exception> |
| | 263 | | /// <exception cref="System.ArgumentNullException"> |
| | 264 | | /// Thrown when a required parameter is null |
| | 265 | | /// </exception> |
| | 266 | | /// <return> |
| | 267 | | /// A response object containing the response body and response headers. |
| | 268 | | /// </return> |
| | 269 | | public async Task<AzureOperationHeaderResponse<BlobCheckHeaders>> CheckWithHttpMessagesAsync(string name, string |
| | 270 | | { |
| 4 | 271 | | if (Client.LoginUri == null) |
| | 272 | | { |
| 0 | 273 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 274 | | } |
| 4 | 275 | | if (name == null) |
| | 276 | | { |
| 0 | 277 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 278 | | } |
| 4 | 279 | | if (digest == null) |
| | 280 | | { |
| 0 | 281 | | throw new ValidationException(ValidationRules.CannotBeNull, "digest"); |
| | 282 | | } |
| | 283 | | // Tracing |
| 4 | 284 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 285 | | string _invocationId = null; |
| 4 | 286 | | if (_shouldTrace) |
| | 287 | | { |
| 0 | 288 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 289 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 290 | | tracingParameters.Add("name", name); |
| 0 | 291 | | tracingParameters.Add("digest", digest); |
| 0 | 292 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 293 | | ServiceClientTracing.Enter(_invocationId, this, "Check", tracingParameters); |
| | 294 | | } |
| | 295 | | // Construct URL |
| 4 | 296 | | var _baseUrl = Client.BaseUri; |
| 4 | 297 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/{digest}"; |
| 4 | 298 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 4 | 299 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 4 | 300 | | _url = _url.Replace("{digest}", System.Uri.EscapeDataString(digest)); |
| 4 | 301 | | List<string> _queryParameters = new List<string>(); |
| 4 | 302 | | if (_queryParameters.Count > 0) |
| | 303 | | { |
| 0 | 304 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 305 | | } |
| | 306 | | // Create HTTP transport objects |
| 4 | 307 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 308 | | HttpResponseMessage _httpResponse = null; |
| 4 | 309 | | _httpRequest.Method = new HttpMethod("HEAD"); |
| 4 | 310 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 311 | | // Set Headers |
| 4 | 312 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 313 | | { |
| 4 | 314 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 315 | | } |
| 4 | 316 | | if (Client.AcceptLanguage != null) |
| | 317 | | { |
| 4 | 318 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 319 | | { |
| 0 | 320 | | _httpRequest.Headers.Remove("accept-language"); |
| | 321 | | } |
| 4 | 322 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 323 | | } |
| | 324 | |
|
| | 325 | |
|
| 4 | 326 | | if (customHeaders != null) |
| | 327 | | { |
| 0 | 328 | | foreach(var _header in customHeaders) |
| | 329 | | { |
| 0 | 330 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 331 | | { |
| 0 | 332 | | _httpRequest.Headers.Remove(_header.Key); |
| | 333 | | } |
| 0 | 334 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 335 | | } |
| | 336 | | } |
| | 337 | |
|
| | 338 | | // Serialize Request |
| 4 | 339 | | string _requestContent = null; |
| | 340 | | // Set Credentials |
| 4 | 341 | | if (Client.Credentials != null) |
| | 342 | | { |
| 4 | 343 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 344 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 345 | | } |
| | 346 | | // Send Request |
| 4 | 347 | | if (_shouldTrace) |
| | 348 | | { |
| 0 | 349 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 350 | | } |
| 4 | 351 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 352 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons |
| 4 | 353 | | if (_shouldTrace) |
| | 354 | | { |
| 0 | 355 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 356 | | } |
| 4 | 357 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 358 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 359 | | string _responseContent = null; |
| 4 | 360 | | if ((int)_statusCode != 200 && (int)_statusCode != 307) |
| | 361 | | { |
| 2 | 362 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 363 | | try |
| | 364 | | { |
| 2 | 365 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 2 | 366 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 2 | 367 | | if (_errorBody != null) |
| | 368 | | { |
| 0 | 369 | | ex.Body = _errorBody; |
| | 370 | | } |
| 2 | 371 | | } |
| 0 | 372 | | catch (JsonException) |
| | 373 | | { |
| | 374 | | // Ignore the exception |
| 0 | 375 | | } |
| 2 | 376 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 2 | 377 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 2 | 378 | | if (_shouldTrace) |
| | 379 | | { |
| 0 | 380 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 381 | | } |
| 2 | 382 | | _httpRequest.Dispose(); |
| 2 | 383 | | if (_httpResponse != null) |
| | 384 | | { |
| 2 | 385 | | _httpResponse.Dispose(); |
| | 386 | | } |
| 2 | 387 | | throw ex; |
| | 388 | | } |
| | 389 | | // Create Result |
| 2 | 390 | | var _result = new AzureOperationHeaderResponse<BlobCheckHeaders>(); |
| 2 | 391 | | _result.Request = _httpRequest; |
| 2 | 392 | | _result.Response = _httpResponse; |
| 2 | 393 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 394 | | { |
| 2 | 395 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 396 | | } |
| | 397 | | try |
| | 398 | | { |
| 2 | 399 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobCheckHeaders>(JsonSerializer.Create(Clie |
| 2 | 400 | | } |
| 0 | 401 | | catch (JsonException ex) |
| | 402 | | { |
| 0 | 403 | | _httpRequest.Dispose(); |
| 0 | 404 | | if (_httpResponse != null) |
| | 405 | | { |
| 0 | 406 | | _httpResponse.Dispose(); |
| | 407 | | } |
| 0 | 408 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 409 | | } |
| 2 | 410 | | if (_shouldTrace) |
| | 411 | | { |
| 0 | 412 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 413 | | } |
| 2 | 414 | | return _result; |
| 2 | 415 | | } |
| | 416 | |
|
| | 417 | | /// <summary> |
| | 418 | | /// Removes an already uploaded blob. |
| | 419 | | /// </summary> |
| | 420 | | /// <param name='name'> |
| | 421 | | /// Name of the image (including the namespace) |
| | 422 | | /// </param> |
| | 423 | | /// <param name='digest'> |
| | 424 | | /// Digest of a BLOB |
| | 425 | | /// </param> |
| | 426 | | /// <param name='customHeaders'> |
| | 427 | | /// Headers that will be added to request. |
| | 428 | | /// </param> |
| | 429 | | /// <param name='cancellationToken'> |
| | 430 | | /// The cancellation token. |
| | 431 | | /// </param> |
| | 432 | | /// <exception cref="CloudException"> |
| | 433 | | /// Thrown when the operation returned an invalid status code |
| | 434 | | /// </exception> |
| | 435 | | /// <exception cref="SerializationException"> |
| | 436 | | /// Thrown when unable to deserialize the response |
| | 437 | | /// </exception> |
| | 438 | | /// <exception cref="ValidationException"> |
| | 439 | | /// Thrown when a required parameter is null |
| | 440 | | /// </exception> |
| | 441 | | /// <exception cref="System.ArgumentNullException"> |
| | 442 | | /// Thrown when a required parameter is null |
| | 443 | | /// </exception> |
| | 444 | | /// <return> |
| | 445 | | /// A response object containing the response body and response headers. |
| | 446 | | /// </return> |
| | 447 | | public async Task<AzureOperationResponse<Stream,BlobDeleteHeaders>> DeleteWithHttpMessagesAsync(string name, str |
| | 448 | | { |
| 2 | 449 | | if (Client.LoginUri == null) |
| | 450 | | { |
| 0 | 451 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 452 | | } |
| 2 | 453 | | if (name == null) |
| | 454 | | { |
| 0 | 455 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 456 | | } |
| 2 | 457 | | if (digest == null) |
| | 458 | | { |
| 0 | 459 | | throw new ValidationException(ValidationRules.CannotBeNull, "digest"); |
| | 460 | | } |
| | 461 | | // Tracing |
| 2 | 462 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 463 | | string _invocationId = null; |
| 2 | 464 | | if (_shouldTrace) |
| | 465 | | { |
| 0 | 466 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 467 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 468 | | tracingParameters.Add("name", name); |
| 0 | 469 | | tracingParameters.Add("digest", digest); |
| 0 | 470 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 471 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 472 | | } |
| | 473 | | // Construct URL |
| 2 | 474 | | var _baseUrl = Client.BaseUri; |
| 2 | 475 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/{digest}"; |
| 2 | 476 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 2 | 477 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 2 | 478 | | _url = _url.Replace("{digest}", System.Uri.EscapeDataString(digest)); |
| 2 | 479 | | List<string> _queryParameters = new List<string>(); |
| 2 | 480 | | if (_queryParameters.Count > 0) |
| | 481 | | { |
| 0 | 482 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 483 | | } |
| | 484 | | // Create HTTP transport objects |
| 2 | 485 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 486 | | HttpResponseMessage _httpResponse = null; |
| 2 | 487 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 488 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 489 | | // Set Headers |
| 2 | 490 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 491 | | { |
| 2 | 492 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 493 | | } |
| 2 | 494 | | if (Client.AcceptLanguage != null) |
| | 495 | | { |
| 2 | 496 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 497 | | { |
| 0 | 498 | | _httpRequest.Headers.Remove("accept-language"); |
| | 499 | | } |
| 2 | 500 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 501 | | } |
| | 502 | |
|
| | 503 | |
|
| 2 | 504 | | if (customHeaders != null) |
| | 505 | | { |
| 0 | 506 | | foreach(var _header in customHeaders) |
| | 507 | | { |
| 0 | 508 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 509 | | { |
| 0 | 510 | | _httpRequest.Headers.Remove(_header.Key); |
| | 511 | | } |
| 0 | 512 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 513 | | } |
| | 514 | | } |
| | 515 | |
|
| | 516 | | // Serialize Request |
| 2 | 517 | | string _requestContent = null; |
| | 518 | | // Set Credentials |
| 2 | 519 | | if (Client.Credentials != null) |
| | 520 | | { |
| 2 | 521 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 522 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 523 | | } |
| | 524 | | // Send Request |
| 2 | 525 | | if (_shouldTrace) |
| | 526 | | { |
| 0 | 527 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 528 | | } |
| 2 | 529 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 530 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons |
| 2 | 531 | | if (_shouldTrace) |
| | 532 | | { |
| 0 | 533 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 534 | | } |
| 2 | 535 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 536 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 537 | | string _responseContent = null; |
| 2 | 538 | | if ((int)_statusCode != 202) |
| | 539 | | { |
| 0 | 540 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 541 | | try |
| | 542 | | { |
| 0 | 543 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 544 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 545 | | if (_errorBody != null) |
| | 546 | | { |
| 0 | 547 | | ex = new CloudException(_errorBody.Message); |
| 0 | 548 | | ex.Body = _errorBody; |
| | 549 | | } |
| 0 | 550 | | } |
| 0 | 551 | | catch (JsonException) |
| | 552 | | { |
| | 553 | | // Ignore the exception |
| 0 | 554 | | } |
| 0 | 555 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 556 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 557 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 558 | | { |
| 0 | 559 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 560 | | } |
| 0 | 561 | | if (_shouldTrace) |
| | 562 | | { |
| 0 | 563 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 564 | | } |
| 0 | 565 | | _httpRequest.Dispose(); |
| 0 | 566 | | if (_httpResponse != null) |
| | 567 | | { |
| 0 | 568 | | _httpResponse.Dispose(); |
| | 569 | | } |
| 0 | 570 | | throw ex; |
| | 571 | | } |
| | 572 | | // Create Result |
| 2 | 573 | | var _result = new AzureOperationResponse<Stream,BlobDeleteHeaders>(); |
| 2 | 574 | | _result.Request = _httpRequest; |
| 2 | 575 | | _result.Response = _httpResponse; |
| 2 | 576 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 577 | | { |
| 2 | 578 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 579 | | } |
| | 580 | | // Deserialize Response |
| 2 | 581 | | if ((int)_statusCode == 202) |
| | 582 | | { |
| 2 | 583 | | _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); |
| | 584 | | } |
| | 585 | | try |
| | 586 | | { |
| 2 | 587 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobDeleteHeaders>(JsonSerializer.Create(Cli |
| 2 | 588 | | } |
| 0 | 589 | | catch (JsonException ex) |
| | 590 | | { |
| 0 | 591 | | _httpRequest.Dispose(); |
| 0 | 592 | | if (_httpResponse != null) |
| | 593 | | { |
| 0 | 594 | | _httpResponse.Dispose(); |
| | 595 | | } |
| 0 | 596 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 597 | | } |
| 2 | 598 | | if (_shouldTrace) |
| | 599 | | { |
| 0 | 600 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 601 | | } |
| 2 | 602 | | return _result; |
| 2 | 603 | | } |
| | 604 | |
|
| | 605 | | /// <summary> |
| | 606 | | /// Mount a blob identified by the `mount` parameter from another repository. |
| | 607 | | /// </summary> |
| | 608 | | /// <param name='name'> |
| | 609 | | /// Name of the image (including the namespace) |
| | 610 | | /// </param> |
| | 611 | | /// <param name='fromParameter'> |
| | 612 | | /// Name of the source repository. |
| | 613 | | /// </param> |
| | 614 | | /// <param name='mount'> |
| | 615 | | /// Digest of blob to mount from the source repository. |
| | 616 | | /// </param> |
| | 617 | | /// <param name='customHeaders'> |
| | 618 | | /// Headers that will be added to request. |
| | 619 | | /// </param> |
| | 620 | | /// <param name='cancellationToken'> |
| | 621 | | /// The cancellation token. |
| | 622 | | /// </param> |
| | 623 | | /// <exception cref="AcrErrorsException"> |
| | 624 | | /// Thrown when the operation returned an invalid status code |
| | 625 | | /// </exception> |
| | 626 | | /// <exception cref="ValidationException"> |
| | 627 | | /// Thrown when a required parameter is null |
| | 628 | | /// </exception> |
| | 629 | | /// <exception cref="System.ArgumentNullException"> |
| | 630 | | /// Thrown when a required parameter is null |
| | 631 | | /// </exception> |
| | 632 | | /// <return> |
| | 633 | | /// A response object containing the response body and response headers. |
| | 634 | | /// </return> |
| | 635 | | public async Task<AzureOperationHeaderResponse<BlobMountHeaders>> MountWithHttpMessagesAsync(string name, string |
| | 636 | | { |
| 2 | 637 | | if (Client.LoginUri == null) |
| | 638 | | { |
| 0 | 639 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 640 | | } |
| 2 | 641 | | if (name == null) |
| | 642 | | { |
| 0 | 643 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 644 | | } |
| 2 | 645 | | if (fromParameter == null) |
| | 646 | | { |
| 0 | 647 | | throw new ValidationException(ValidationRules.CannotBeNull, "fromParameter"); |
| | 648 | | } |
| 2 | 649 | | if (mount == null) |
| | 650 | | { |
| 0 | 651 | | throw new ValidationException(ValidationRules.CannotBeNull, "mount"); |
| | 652 | | } |
| | 653 | | // Tracing |
| 2 | 654 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 655 | | string _invocationId = null; |
| 2 | 656 | | if (_shouldTrace) |
| | 657 | | { |
| 0 | 658 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 659 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 660 | | tracingParameters.Add("name", name); |
| 0 | 661 | | tracingParameters.Add("fromParameter", fromParameter); |
| 0 | 662 | | tracingParameters.Add("mount", mount); |
| 0 | 663 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 664 | | ServiceClientTracing.Enter(_invocationId, this, "Mount", tracingParameters); |
| | 665 | | } |
| | 666 | | // Construct URL |
| 2 | 667 | | var _baseUrl = Client.BaseUri; |
| 2 | 668 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/uploads/"; |
| 2 | 669 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 2 | 670 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 2 | 671 | | List<string> _queryParameters = new List<string>(); |
| 2 | 672 | | if (fromParameter != null) |
| | 673 | | { |
| 2 | 674 | | _queryParameters.Add(string.Format("from={0}", System.Uri.EscapeDataString(fromParameter))); |
| | 675 | | } |
| 2 | 676 | | if (mount != null) |
| | 677 | | { |
| 2 | 678 | | _queryParameters.Add(string.Format("mount={0}", System.Uri.EscapeDataString(mount))); |
| | 679 | | } |
| 2 | 680 | | if (_queryParameters.Count > 0) |
| | 681 | | { |
| 2 | 682 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 683 | | } |
| | 684 | | // Create HTTP transport objects |
| 2 | 685 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 686 | | HttpResponseMessage _httpResponse = null; |
| 2 | 687 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 688 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 689 | | // Set Headers |
| 2 | 690 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 691 | | { |
| 2 | 692 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 693 | | } |
| 2 | 694 | | if (Client.AcceptLanguage != null) |
| | 695 | | { |
| 2 | 696 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 697 | | { |
| 0 | 698 | | _httpRequest.Headers.Remove("accept-language"); |
| | 699 | | } |
| 2 | 700 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 701 | | } |
| | 702 | |
|
| | 703 | |
|
| 2 | 704 | | if (customHeaders != null) |
| | 705 | | { |
| 0 | 706 | | foreach(var _header in customHeaders) |
| | 707 | | { |
| 0 | 708 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 709 | | { |
| 0 | 710 | | _httpRequest.Headers.Remove(_header.Key); |
| | 711 | | } |
| 0 | 712 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 713 | | } |
| | 714 | | } |
| | 715 | |
|
| | 716 | | // Serialize Request |
| 2 | 717 | | string _requestContent = null; |
| | 718 | | // Set Credentials |
| 2 | 719 | | if (Client.Credentials != null) |
| | 720 | | { |
| 2 | 721 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 722 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 723 | | } |
| | 724 | | // Send Request |
| 2 | 725 | | if (_shouldTrace) |
| | 726 | | { |
| 0 | 727 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 728 | | } |
| 2 | 729 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 730 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 731 | | if (_shouldTrace) |
| | 732 | | { |
| 0 | 733 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 734 | | } |
| 2 | 735 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 736 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 737 | | string _responseContent = null; |
| 2 | 738 | | if ((int)_statusCode != 201) |
| | 739 | | { |
| 0 | 740 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 741 | | try |
| | 742 | | { |
| 0 | 743 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 744 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 745 | | if (_errorBody != null) |
| | 746 | | { |
| 0 | 747 | | ex.Body = _errorBody; |
| | 748 | | } |
| 0 | 749 | | } |
| 0 | 750 | | catch (JsonException) |
| | 751 | | { |
| | 752 | | // Ignore the exception |
| 0 | 753 | | } |
| 0 | 754 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 755 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 756 | | if (_shouldTrace) |
| | 757 | | { |
| 0 | 758 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 759 | | } |
| 0 | 760 | | _httpRequest.Dispose(); |
| 0 | 761 | | if (_httpResponse != null) |
| | 762 | | { |
| 0 | 763 | | _httpResponse.Dispose(); |
| | 764 | | } |
| 0 | 765 | | throw ex; |
| | 766 | | } |
| | 767 | | // Create Result |
| 2 | 768 | | var _result = new AzureOperationHeaderResponse<BlobMountHeaders>(); |
| 2 | 769 | | _result.Request = _httpRequest; |
| 2 | 770 | | _result.Response = _httpResponse; |
| 2 | 771 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 772 | | { |
| 2 | 773 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 774 | | } |
| | 775 | | try |
| | 776 | | { |
| 2 | 777 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobMountHeaders>(JsonSerializer.Create(Clie |
| 2 | 778 | | } |
| 0 | 779 | | catch (JsonException ex) |
| | 780 | | { |
| 0 | 781 | | _httpRequest.Dispose(); |
| 0 | 782 | | if (_httpResponse != null) |
| | 783 | | { |
| 0 | 784 | | _httpResponse.Dispose(); |
| | 785 | | } |
| 0 | 786 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 787 | | } |
| 2 | 788 | | if (_shouldTrace) |
| | 789 | | { |
| 0 | 790 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 791 | | } |
| 2 | 792 | | return _result; |
| 2 | 793 | | } |
| | 794 | |
|
| | 795 | | /// <summary> |
| | 796 | | /// Retrieve status of upload identified by uuid. The primary purpose of this |
| | 797 | | /// endpoint is to resolve the current status of a resumable upload. |
| | 798 | | /// </summary> |
| | 799 | | /// <param name='location'> |
| | 800 | | /// Link acquired from upload start or previous chunk. Note, do not include |
| | 801 | | /// initial / (must do substring(1) ) |
| | 802 | | /// </param> |
| | 803 | | /// <param name='customHeaders'> |
| | 804 | | /// Headers that will be added to request. |
| | 805 | | /// </param> |
| | 806 | | /// <param name='cancellationToken'> |
| | 807 | | /// The cancellation token. |
| | 808 | | /// </param> |
| | 809 | | /// <exception cref="AcrErrorsException"> |
| | 810 | | /// Thrown when the operation returned an invalid status code |
| | 811 | | /// </exception> |
| | 812 | | /// <exception cref="ValidationException"> |
| | 813 | | /// Thrown when a required parameter is null |
| | 814 | | /// </exception> |
| | 815 | | /// <exception cref="System.ArgumentNullException"> |
| | 816 | | /// Thrown when a required parameter is null |
| | 817 | | /// </exception> |
| | 818 | | /// <return> |
| | 819 | | /// A response object containing the response body and response headers. |
| | 820 | | /// </return> |
| | 821 | | public async Task<AzureOperationHeaderResponse<BlobGetStatusHeaders>> GetStatusWithHttpMessagesAsync(string loca |
| | 822 | | { |
| 2 | 823 | | if (Client.LoginUri == null) |
| | 824 | | { |
| 0 | 825 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 826 | | } |
| 2 | 827 | | if (location == null) |
| | 828 | | { |
| 0 | 829 | | throw new ValidationException(ValidationRules.CannotBeNull, "location"); |
| | 830 | | } |
| | 831 | | // Tracing |
| 2 | 832 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 833 | | string _invocationId = null; |
| 2 | 834 | | if (_shouldTrace) |
| | 835 | | { |
| 0 | 836 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 837 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 838 | | tracingParameters.Add("location", location); |
| 0 | 839 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 840 | | ServiceClientTracing.Enter(_invocationId, this, "GetStatus", tracingParameters); |
| | 841 | | } |
| | 842 | | // Construct URL |
| 2 | 843 | | var _baseUrl = Client.BaseUri; |
| 2 | 844 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{nextBlobUuidLink}"; |
| 2 | 845 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 2 | 846 | | _url = _url.Replace(location.StartsWith("/") ? "/{nextBlobUuidLink}" : "{nextBlobUuidLink}", location); |
| 2 | 847 | | List<string> _queryParameters = new List<string>(); |
| 2 | 848 | | if (_queryParameters.Count > 0) |
| | 849 | | { |
| 0 | 850 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 851 | | } |
| | 852 | | // Create HTTP transport objects |
| 2 | 853 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 854 | | HttpResponseMessage _httpResponse = null; |
| 2 | 855 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 856 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 857 | | // Set Headers |
| 2 | 858 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 859 | | { |
| 2 | 860 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 861 | | } |
| 2 | 862 | | if (Client.AcceptLanguage != null) |
| | 863 | | { |
| 2 | 864 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 865 | | { |
| 0 | 866 | | _httpRequest.Headers.Remove("accept-language"); |
| | 867 | | } |
| 2 | 868 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 869 | | } |
| | 870 | |
|
| | 871 | |
|
| 2 | 872 | | if (customHeaders != null) |
| | 873 | | { |
| 0 | 874 | | foreach(var _header in customHeaders) |
| | 875 | | { |
| 0 | 876 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 877 | | { |
| 0 | 878 | | _httpRequest.Headers.Remove(_header.Key); |
| | 879 | | } |
| 0 | 880 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 881 | | } |
| | 882 | | } |
| | 883 | |
|
| | 884 | | // Serialize Request |
| 2 | 885 | | string _requestContent = null; |
| | 886 | | // Set Credentials |
| 2 | 887 | | if (Client.Credentials != null) |
| | 888 | | { |
| 2 | 889 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 890 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 891 | | } |
| | 892 | | // Send Request |
| 2 | 893 | | if (_shouldTrace) |
| | 894 | | { |
| 0 | 895 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 896 | | } |
| 2 | 897 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 898 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 899 | | if (_shouldTrace) |
| | 900 | | { |
| 0 | 901 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 902 | | } |
| 2 | 903 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 904 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 905 | | string _responseContent = null; |
| 2 | 906 | | if ((int)_statusCode != 204) |
| | 907 | | { |
| 0 | 908 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 909 | | try |
| | 910 | | { |
| 0 | 911 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 912 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 913 | | if (_errorBody != null) |
| | 914 | | { |
| 0 | 915 | | ex.Body = _errorBody; |
| | 916 | | } |
| 0 | 917 | | } |
| 0 | 918 | | catch (JsonException) |
| | 919 | | { |
| | 920 | | // Ignore the exception |
| 0 | 921 | | } |
| 0 | 922 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 923 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 924 | | if (_shouldTrace) |
| | 925 | | { |
| 0 | 926 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 927 | | } |
| 0 | 928 | | _httpRequest.Dispose(); |
| 0 | 929 | | if (_httpResponse != null) |
| | 930 | | { |
| 0 | 931 | | _httpResponse.Dispose(); |
| | 932 | | } |
| 0 | 933 | | throw ex; |
| | 934 | | } |
| | 935 | | // Create Result |
| 2 | 936 | | var _result = new AzureOperationHeaderResponse<BlobGetStatusHeaders>(); |
| 2 | 937 | | _result.Request = _httpRequest; |
| 2 | 938 | | _result.Response = _httpResponse; |
| 2 | 939 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 940 | | { |
| 2 | 941 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 942 | | } |
| | 943 | | try |
| | 944 | | { |
| 2 | 945 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobGetStatusHeaders>(JsonSerializer.Create( |
| 2 | 946 | | } |
| 0 | 947 | | catch (JsonException ex) |
| | 948 | | { |
| 0 | 949 | | _httpRequest.Dispose(); |
| 0 | 950 | | if (_httpResponse != null) |
| | 951 | | { |
| 0 | 952 | | _httpResponse.Dispose(); |
| | 953 | | } |
| 0 | 954 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 955 | | } |
| 2 | 956 | | if (_shouldTrace) |
| | 957 | | { |
| 0 | 958 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 959 | | } |
| 2 | 960 | | return _result; |
| 2 | 961 | | } |
| | 962 | |
|
| | 963 | | /// <summary> |
| | 964 | | /// Upload a stream of data without completing the upload. |
| | 965 | | /// </summary> |
| | 966 | | /// <param name='value'> |
| | 967 | | /// Raw data of blob |
| | 968 | | /// </param> |
| | 969 | | /// <param name='location'> |
| | 970 | | /// Link acquired from upload start or previous chunk. Note, do not include |
| | 971 | | /// initial / (must do substring(1) ) |
| | 972 | | /// </param> |
| | 973 | | /// <param name='customHeaders'> |
| | 974 | | /// Headers that will be added to request. |
| | 975 | | /// </param> |
| | 976 | | /// <param name='cancellationToken'> |
| | 977 | | /// The cancellation token. |
| | 978 | | /// </param> |
| | 979 | | /// <exception cref="AcrErrorsException"> |
| | 980 | | /// Thrown when the operation returned an invalid status code |
| | 981 | | /// </exception> |
| | 982 | | /// <exception cref="ValidationException"> |
| | 983 | | /// Thrown when a required parameter is null |
| | 984 | | /// </exception> |
| | 985 | | /// <exception cref="System.ArgumentNullException"> |
| | 986 | | /// Thrown when a required parameter is null |
| | 987 | | /// </exception> |
| | 988 | | /// <return> |
| | 989 | | /// A response object containing the response body and response headers. |
| | 990 | | /// </return> |
| | 991 | | public async Task<AzureOperationHeaderResponse<BlobUploadHeaders>> UploadWithHttpMessagesAsync(Stream value, str |
| | 992 | | { |
| 4 | 993 | | if (Client.LoginUri == null) |
| | 994 | | { |
| 0 | 995 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 996 | | } |
| 4 | 997 | | if (value == null) |
| | 998 | | { |
| 0 | 999 | | throw new ValidationException(ValidationRules.CannotBeNull, "value"); |
| | 1000 | | } |
| 4 | 1001 | | if (location == null) |
| | 1002 | | { |
| 0 | 1003 | | throw new ValidationException(ValidationRules.CannotBeNull, "location"); |
| | 1004 | | } |
| | 1005 | | // Tracing |
| 4 | 1006 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 1007 | | string _invocationId = null; |
| 4 | 1008 | | if (_shouldTrace) |
| | 1009 | | { |
| 0 | 1010 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1011 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1012 | | tracingParameters.Add("value", value); |
| 0 | 1013 | | tracingParameters.Add("location", location); |
| 0 | 1014 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1015 | | ServiceClientTracing.Enter(_invocationId, this, "Upload", tracingParameters); |
| | 1016 | | } |
| | 1017 | | // Construct URL |
| 4 | 1018 | | var _baseUrl = Client.BaseUri; |
| 4 | 1019 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{nextBlobUuidLink}"; |
| 4 | 1020 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 4 | 1021 | | _url = _url.Replace(location.StartsWith("/") ? "/{nextBlobUuidLink}" : "{nextBlobUuidLink}", location); |
| 4 | 1022 | | List<string> _queryParameters = new List<string>(); |
| 4 | 1023 | | if (_queryParameters.Count > 0) |
| | 1024 | | { |
| 0 | 1025 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1026 | | } |
| | 1027 | | // Create HTTP transport objects |
| 4 | 1028 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 1029 | | HttpResponseMessage _httpResponse = null; |
| 4 | 1030 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 4 | 1031 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1032 | | // Set Headers |
| 4 | 1033 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1034 | | { |
| 4 | 1035 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1036 | | } |
| 4 | 1037 | | if (Client.AcceptLanguage != null) |
| | 1038 | | { |
| 4 | 1039 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1040 | | { |
| 0 | 1041 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1042 | | } |
| 4 | 1043 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1044 | | } |
| | 1045 | |
|
| | 1046 | |
|
| 4 | 1047 | | if (customHeaders != null) |
| | 1048 | | { |
| 0 | 1049 | | foreach(var _header in customHeaders) |
| | 1050 | | { |
| 0 | 1051 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1052 | | { |
| 0 | 1053 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1054 | | } |
| 0 | 1055 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1056 | | } |
| | 1057 | | } |
| | 1058 | |
|
| | 1059 | | // Serialize Request |
| 4 | 1060 | | string _requestContent = null; |
| 4 | 1061 | | if(value == null) |
| | 1062 | | { |
| 0 | 1063 | | throw new System.ArgumentNullException("value"); |
| | 1064 | | } |
| 4 | 1065 | | if (value != null && value != Stream.Null) |
| | 1066 | | { |
| 4 | 1067 | | _httpRequest.Content = new StreamContent(value); |
| 4 | 1068 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1069 | | } |
| | 1070 | | // Set Credentials |
| 4 | 1071 | | if (Client.Credentials != null) |
| | 1072 | | { |
| 4 | 1073 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1074 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1075 | | } |
| | 1076 | | // Send Request |
| 4 | 1077 | | if (_shouldTrace) |
| | 1078 | | { |
| 0 | 1079 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1080 | | } |
| 4 | 1081 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1082 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 1083 | | if (_shouldTrace) |
| | 1084 | | { |
| 0 | 1085 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1086 | | } |
| 4 | 1087 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 1088 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1089 | | string _responseContent = null; |
| 4 | 1090 | | if ((int)_statusCode != 202) |
| | 1091 | | { |
| 0 | 1092 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 1093 | | try |
| | 1094 | | { |
| 0 | 1095 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1096 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 1097 | | if (_errorBody != null) |
| | 1098 | | { |
| 0 | 1099 | | ex.Body = _errorBody; |
| | 1100 | | } |
| 0 | 1101 | | } |
| 0 | 1102 | | catch (JsonException) |
| | 1103 | | { |
| | 1104 | | // Ignore the exception |
| 0 | 1105 | | } |
| 0 | 1106 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1107 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1108 | | if (_shouldTrace) |
| | 1109 | | { |
| 0 | 1110 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1111 | | } |
| 0 | 1112 | | _httpRequest.Dispose(); |
| 0 | 1113 | | if (_httpResponse != null) |
| | 1114 | | { |
| 0 | 1115 | | _httpResponse.Dispose(); |
| | 1116 | | } |
| 0 | 1117 | | throw ex; |
| | 1118 | | } |
| | 1119 | | // Create Result |
| 4 | 1120 | | var _result = new AzureOperationHeaderResponse<BlobUploadHeaders>(); |
| 4 | 1121 | | _result.Request = _httpRequest; |
| 4 | 1122 | | _result.Response = _httpResponse; |
| 4 | 1123 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1124 | | { |
| 4 | 1125 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1126 | | } |
| | 1127 | | try |
| | 1128 | | { |
| 4 | 1129 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobUploadHeaders>(JsonSerializer.Create(Cli |
| 4 | 1130 | | } |
| 0 | 1131 | | catch (JsonException ex) |
| | 1132 | | { |
| 0 | 1133 | | _httpRequest.Dispose(); |
| 0 | 1134 | | if (_httpResponse != null) |
| | 1135 | | { |
| 0 | 1136 | | _httpResponse.Dispose(); |
| | 1137 | | } |
| 0 | 1138 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1139 | | } |
| 4 | 1140 | | if (_shouldTrace) |
| | 1141 | | { |
| 0 | 1142 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1143 | | } |
| 4 | 1144 | | return _result; |
| 4 | 1145 | | } |
| | 1146 | |
|
| | 1147 | | /// <summary> |
| | 1148 | | /// Complete the upload, providing all the data in the body, if necessary. A |
| | 1149 | | /// request without a body will just complete the upload with previously |
| | 1150 | | /// uploaded content. |
| | 1151 | | /// </summary> |
| | 1152 | | /// <param name='digest'> |
| | 1153 | | /// Digest of a BLOB |
| | 1154 | | /// </param> |
| | 1155 | | /// <param name='location'> |
| | 1156 | | /// Link acquired from upload start or previous chunk. Note, do not include |
| | 1157 | | /// initial / (must do substring(1) ) |
| | 1158 | | /// </param> |
| | 1159 | | /// <param name='value'> |
| | 1160 | | /// Optional raw data of blob |
| | 1161 | | /// </param> |
| | 1162 | | /// <param name='customHeaders'> |
| | 1163 | | /// Headers that will be added to request. |
| | 1164 | | /// </param> |
| | 1165 | | /// <param name='cancellationToken'> |
| | 1166 | | /// The cancellation token. |
| | 1167 | | /// </param> |
| | 1168 | | /// <exception cref="AcrErrorsException"> |
| | 1169 | | /// Thrown when the operation returned an invalid status code |
| | 1170 | | /// </exception> |
| | 1171 | | /// <exception cref="ValidationException"> |
| | 1172 | | /// Thrown when a required parameter is null |
| | 1173 | | /// </exception> |
| | 1174 | | /// <exception cref="System.ArgumentNullException"> |
| | 1175 | | /// Thrown when a required parameter is null |
| | 1176 | | /// </exception> |
| | 1177 | | /// <return> |
| | 1178 | | /// A response object containing the response body and response headers. |
| | 1179 | | /// </return> |
| | 1180 | | public async Task<AzureOperationHeaderResponse<BlobEndUploadHeaders>> EndUploadWithHttpMessagesAsync(string dige |
| | 1181 | | { |
| 4 | 1182 | | if (Client.LoginUri == null) |
| | 1183 | | { |
| 0 | 1184 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 1185 | | } |
| 4 | 1186 | | if (digest == null) |
| | 1187 | | { |
| 0 | 1188 | | throw new ValidationException(ValidationRules.CannotBeNull, "digest"); |
| | 1189 | | } |
| 4 | 1190 | | if (location == null) |
| | 1191 | | { |
| 0 | 1192 | | throw new ValidationException(ValidationRules.CannotBeNull, "location"); |
| | 1193 | | } |
| | 1194 | | // Tracing |
| 4 | 1195 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 1196 | | string _invocationId = null; |
| 4 | 1197 | | if (_shouldTrace) |
| | 1198 | | { |
| 0 | 1199 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1200 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1201 | | tracingParameters.Add("digest", digest); |
| 0 | 1202 | | tracingParameters.Add("value", value); |
| 0 | 1203 | | tracingParameters.Add("location", location); |
| 0 | 1204 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1205 | | ServiceClientTracing.Enter(_invocationId, this, "EndUpload", tracingParameters); |
| | 1206 | | } |
| | 1207 | | // Construct URL |
| 4 | 1208 | | var _baseUrl = Client.BaseUri; |
| 4 | 1209 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{nextBlobUuidLink}"; |
| 4 | 1210 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 4 | 1211 | | _url = _url.Replace(location.StartsWith("/") ? "/{nextBlobUuidLink}" : "{nextBlobUuidLink}", location); |
| 4 | 1212 | | List<string> _queryParameters = new List<string>(); |
| 4 | 1213 | | if (digest != null) |
| | 1214 | | { |
| 4 | 1215 | | _queryParameters.Add(string.Format("digest={0}", System.Uri.EscapeDataString(digest))); |
| | 1216 | | } |
| 4 | 1217 | | if (_queryParameters.Count > 0) |
| | 1218 | | { |
| 4 | 1219 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1220 | | } |
| | 1221 | | // Create HTTP transport objects |
| 4 | 1222 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 1223 | | HttpResponseMessage _httpResponse = null; |
| 4 | 1224 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 4 | 1225 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1226 | | // Set Headers |
| 4 | 1227 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1228 | | { |
| 4 | 1229 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1230 | | } |
| 4 | 1231 | | if (Client.AcceptLanguage != null) |
| | 1232 | | { |
| 4 | 1233 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1234 | | { |
| 0 | 1235 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1236 | | } |
| 4 | 1237 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1238 | | } |
| | 1239 | |
|
| | 1240 | |
|
| 4 | 1241 | | if (customHeaders != null) |
| | 1242 | | { |
| 0 | 1243 | | foreach(var _header in customHeaders) |
| | 1244 | | { |
| 0 | 1245 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1246 | | { |
| 0 | 1247 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1248 | | } |
| 0 | 1249 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1250 | | } |
| | 1251 | | } |
| | 1252 | |
|
| | 1253 | | // Serialize Request |
| 4 | 1254 | | string _requestContent = null; |
| 4 | 1255 | | if (value != null && value != Stream.Null) |
| | 1256 | | { |
| 0 | 1257 | | _httpRequest.Content = new StreamContent(value); |
| 0 | 1258 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1259 | | } |
| | 1260 | | // Set Credentials |
| 4 | 1261 | | if (Client.Credentials != null) |
| | 1262 | | { |
| 4 | 1263 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1264 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1265 | | } |
| | 1266 | | // Send Request |
| 4 | 1267 | | if (_shouldTrace) |
| | 1268 | | { |
| 0 | 1269 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1270 | | } |
| 4 | 1271 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1272 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 1273 | | if (_shouldTrace) |
| | 1274 | | { |
| 0 | 1275 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1276 | | } |
| 4 | 1277 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 1278 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1279 | | string _responseContent = null; |
| 4 | 1280 | | if ((int)_statusCode != 201) |
| | 1281 | | { |
| 0 | 1282 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 1283 | | try |
| | 1284 | | { |
| 0 | 1285 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1286 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 1287 | | if (_errorBody != null) |
| | 1288 | | { |
| 0 | 1289 | | ex.Body = _errorBody; |
| | 1290 | | } |
| 0 | 1291 | | } |
| 0 | 1292 | | catch (JsonException) |
| | 1293 | | { |
| | 1294 | | // Ignore the exception |
| 0 | 1295 | | } |
| 0 | 1296 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1297 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1298 | | if (_shouldTrace) |
| | 1299 | | { |
| 0 | 1300 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1301 | | } |
| 0 | 1302 | | _httpRequest.Dispose(); |
| 0 | 1303 | | if (_httpResponse != null) |
| | 1304 | | { |
| 0 | 1305 | | _httpResponse.Dispose(); |
| | 1306 | | } |
| 0 | 1307 | | throw ex; |
| | 1308 | | } |
| | 1309 | | // Create Result |
| 4 | 1310 | | var _result = new AzureOperationHeaderResponse<BlobEndUploadHeaders>(); |
| 4 | 1311 | | _result.Request = _httpRequest; |
| 4 | 1312 | | _result.Response = _httpResponse; |
| 4 | 1313 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1314 | | { |
| 4 | 1315 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1316 | | } |
| | 1317 | | try |
| | 1318 | | { |
| 4 | 1319 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobEndUploadHeaders>(JsonSerializer.Create( |
| 4 | 1320 | | } |
| 0 | 1321 | | catch (JsonException ex) |
| | 1322 | | { |
| 0 | 1323 | | _httpRequest.Dispose(); |
| 0 | 1324 | | if (_httpResponse != null) |
| | 1325 | | { |
| 0 | 1326 | | _httpResponse.Dispose(); |
| | 1327 | | } |
| 0 | 1328 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1329 | | } |
| 4 | 1330 | | if (_shouldTrace) |
| | 1331 | | { |
| 0 | 1332 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1333 | | } |
| 4 | 1334 | | return _result; |
| 4 | 1335 | | } |
| | 1336 | |
|
| | 1337 | | /// <summary> |
| | 1338 | | /// Cancel outstanding upload processes, releasing associated resources. If |
| | 1339 | | /// this is not called, the unfinished uploads will eventually timeout. |
| | 1340 | | /// </summary> |
| | 1341 | | /// <param name='location'> |
| | 1342 | | /// Link acquired from upload start or previous chunk. Note, do not include |
| | 1343 | | /// initial / (must do substring(1) ) |
| | 1344 | | /// </param> |
| | 1345 | | /// <param name='customHeaders'> |
| | 1346 | | /// Headers that will be added to request. |
| | 1347 | | /// </param> |
| | 1348 | | /// <param name='cancellationToken'> |
| | 1349 | | /// The cancellation token. |
| | 1350 | | /// </param> |
| | 1351 | | /// <exception cref="AcrErrorsException"> |
| | 1352 | | /// Thrown when the operation returned an invalid status code |
| | 1353 | | /// </exception> |
| | 1354 | | /// <exception cref="ValidationException"> |
| | 1355 | | /// Thrown when a required parameter is null |
| | 1356 | | /// </exception> |
| | 1357 | | /// <exception cref="System.ArgumentNullException"> |
| | 1358 | | /// Thrown when a required parameter is null |
| | 1359 | | /// </exception> |
| | 1360 | | /// <return> |
| | 1361 | | /// A response object containing the response body and response headers. |
| | 1362 | | /// </return> |
| | 1363 | | public async Task<AzureOperationResponse> CancelUploadWithHttpMessagesAsync(string location, Dictionary<string, |
| | 1364 | | { |
| 4 | 1365 | | if (Client.LoginUri == null) |
| | 1366 | | { |
| 0 | 1367 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 1368 | | } |
| 4 | 1369 | | if (location == null) |
| | 1370 | | { |
| 0 | 1371 | | throw new ValidationException(ValidationRules.CannotBeNull, "location"); |
| | 1372 | | } |
| | 1373 | | // Tracing |
| 4 | 1374 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 1375 | | string _invocationId = null; |
| 4 | 1376 | | if (_shouldTrace) |
| | 1377 | | { |
| 0 | 1378 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1379 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1380 | | tracingParameters.Add("location", location); |
| 0 | 1381 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1382 | | ServiceClientTracing.Enter(_invocationId, this, "CancelUpload", tracingParameters); |
| | 1383 | | } |
| | 1384 | | // Construct URL |
| 4 | 1385 | | var _baseUrl = Client.BaseUri; |
| 4 | 1386 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{nextBlobUuidLink}"; |
| 4 | 1387 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 4 | 1388 | | _url = _url.Replace(location.StartsWith("/") ? "/{nextBlobUuidLink}" : "{nextBlobUuidLink}", location); |
| 4 | 1389 | | List<string> _queryParameters = new List<string>(); |
| 4 | 1390 | | if (_queryParameters.Count > 0) |
| | 1391 | | { |
| 0 | 1392 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1393 | | } |
| | 1394 | | // Create HTTP transport objects |
| 4 | 1395 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 1396 | | HttpResponseMessage _httpResponse = null; |
| 4 | 1397 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 4 | 1398 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1399 | | // Set Headers |
| 4 | 1400 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1401 | | { |
| 4 | 1402 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1403 | | } |
| 4 | 1404 | | if (Client.AcceptLanguage != null) |
| | 1405 | | { |
| 4 | 1406 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1407 | | { |
| 0 | 1408 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1409 | | } |
| 4 | 1410 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1411 | | } |
| | 1412 | |
|
| | 1413 | |
|
| 4 | 1414 | | if (customHeaders != null) |
| | 1415 | | { |
| 0 | 1416 | | foreach(var _header in customHeaders) |
| | 1417 | | { |
| 0 | 1418 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1419 | | { |
| 0 | 1420 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1421 | | } |
| 0 | 1422 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1423 | | } |
| | 1424 | | } |
| | 1425 | |
|
| | 1426 | | // Serialize Request |
| 4 | 1427 | | string _requestContent = null; |
| | 1428 | | // Set Credentials |
| 4 | 1429 | | if (Client.Credentials != null) |
| | 1430 | | { |
| 4 | 1431 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1432 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1433 | | } |
| | 1434 | | // Send Request |
| 4 | 1435 | | if (_shouldTrace) |
| | 1436 | | { |
| 0 | 1437 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1438 | | } |
| 4 | 1439 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1440 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 1441 | | if (_shouldTrace) |
| | 1442 | | { |
| 0 | 1443 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1444 | | } |
| 4 | 1445 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 1446 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1447 | | string _responseContent = null; |
| 4 | 1448 | | if ((int)_statusCode != 204) |
| | 1449 | | { |
| 0 | 1450 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 1451 | | try |
| | 1452 | | { |
| 0 | 1453 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1454 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 1455 | | if (_errorBody != null) |
| | 1456 | | { |
| 0 | 1457 | | ex.Body = _errorBody; |
| | 1458 | | } |
| 0 | 1459 | | } |
| 0 | 1460 | | catch (JsonException) |
| | 1461 | | { |
| | 1462 | | // Ignore the exception |
| 0 | 1463 | | } |
| 0 | 1464 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1465 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1466 | | if (_shouldTrace) |
| | 1467 | | { |
| 0 | 1468 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1469 | | } |
| 0 | 1470 | | _httpRequest.Dispose(); |
| 0 | 1471 | | if (_httpResponse != null) |
| | 1472 | | { |
| 0 | 1473 | | _httpResponse.Dispose(); |
| | 1474 | | } |
| 0 | 1475 | | throw ex; |
| | 1476 | | } |
| | 1477 | | // Create Result |
| 4 | 1478 | | var _result = new AzureOperationResponse(); |
| 4 | 1479 | | _result.Request = _httpRequest; |
| 4 | 1480 | | _result.Response = _httpResponse; |
| 4 | 1481 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1482 | | { |
| 4 | 1483 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1484 | | } |
| 4 | 1485 | | if (_shouldTrace) |
| | 1486 | | { |
| 0 | 1487 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1488 | | } |
| 4 | 1489 | | return _result; |
| 4 | 1490 | | } |
| | 1491 | |
|
| | 1492 | | /// <summary> |
| | 1493 | | /// Initiate a resumable blob upload with an empty request body. |
| | 1494 | | /// </summary> |
| | 1495 | | /// <param name='name'> |
| | 1496 | | /// Name of the image (including the namespace) |
| | 1497 | | /// </param> |
| | 1498 | | /// <param name='customHeaders'> |
| | 1499 | | /// Headers that will be added to request. |
| | 1500 | | /// </param> |
| | 1501 | | /// <param name='cancellationToken'> |
| | 1502 | | /// The cancellation token. |
| | 1503 | | /// </param> |
| | 1504 | | /// <exception cref="AcrErrorsException"> |
| | 1505 | | /// Thrown when the operation returned an invalid status code |
| | 1506 | | /// </exception> |
| | 1507 | | /// <exception cref="ValidationException"> |
| | 1508 | | /// Thrown when a required parameter is null |
| | 1509 | | /// </exception> |
| | 1510 | | /// <exception cref="System.ArgumentNullException"> |
| | 1511 | | /// Thrown when a required parameter is null |
| | 1512 | | /// </exception> |
| | 1513 | | /// <return> |
| | 1514 | | /// A response object containing the response body and response headers. |
| | 1515 | | /// </return> |
| | 1516 | | public async Task<AzureOperationHeaderResponse<BlobStartUploadHeaders>> StartUploadWithHttpMessagesAsync(string |
| | 1517 | | { |
| 8 | 1518 | | if (Client.LoginUri == null) |
| | 1519 | | { |
| 0 | 1520 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 1521 | | } |
| 8 | 1522 | | if (name == null) |
| | 1523 | | { |
| 0 | 1524 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 1525 | | } |
| | 1526 | | // Tracing |
| 8 | 1527 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 8 | 1528 | | string _invocationId = null; |
| 8 | 1529 | | if (_shouldTrace) |
| | 1530 | | { |
| 0 | 1531 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1532 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1533 | | tracingParameters.Add("name", name); |
| 0 | 1534 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1535 | | ServiceClientTracing.Enter(_invocationId, this, "StartUpload", tracingParameters); |
| | 1536 | | } |
| | 1537 | | // Construct URL |
| 8 | 1538 | | var _baseUrl = Client.BaseUri; |
| 8 | 1539 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/uploads/"; |
| 8 | 1540 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 8 | 1541 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 8 | 1542 | | List<string> _queryParameters = new List<string>(); |
| 8 | 1543 | | if (_queryParameters.Count > 0) |
| | 1544 | | { |
| 0 | 1545 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1546 | | } |
| | 1547 | | // Create HTTP transport objects |
| 8 | 1548 | | var _httpRequest = new HttpRequestMessage(); |
| 8 | 1549 | | HttpResponseMessage _httpResponse = null; |
| 8 | 1550 | | _httpRequest.Method = new HttpMethod("POST"); |
| 8 | 1551 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1552 | | // Set Headers |
| 8 | 1553 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1554 | | { |
| 8 | 1555 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1556 | | } |
| 8 | 1557 | | if (Client.AcceptLanguage != null) |
| | 1558 | | { |
| 8 | 1559 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1560 | | { |
| 0 | 1561 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1562 | | } |
| 8 | 1563 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1564 | | } |
| | 1565 | |
|
| | 1566 | |
|
| 8 | 1567 | | if (customHeaders != null) |
| | 1568 | | { |
| 0 | 1569 | | foreach(var _header in customHeaders) |
| | 1570 | | { |
| 0 | 1571 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1572 | | { |
| 0 | 1573 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1574 | | } |
| 0 | 1575 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1576 | | } |
| | 1577 | | } |
| | 1578 | |
|
| | 1579 | | // Serialize Request |
| 8 | 1580 | | string _requestContent = null; |
| | 1581 | | // Set Credentials |
| 8 | 1582 | | if (Client.Credentials != null) |
| | 1583 | | { |
| 8 | 1584 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 1585 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1586 | | } |
| | 1587 | | // Send Request |
| 8 | 1588 | | if (_shouldTrace) |
| | 1589 | | { |
| 0 | 1590 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1591 | | } |
| 8 | 1592 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 1593 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 8 | 1594 | | if (_shouldTrace) |
| | 1595 | | { |
| 0 | 1596 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1597 | | } |
| 8 | 1598 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 8 | 1599 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 1600 | | string _responseContent = null; |
| 8 | 1601 | | if ((int)_statusCode != 202) |
| | 1602 | | { |
| 0 | 1603 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 1604 | | try |
| | 1605 | | { |
| 0 | 1606 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1607 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 1608 | | if (_errorBody != null) |
| | 1609 | | { |
| 0 | 1610 | | ex.Body = _errorBody; |
| | 1611 | | } |
| 0 | 1612 | | } |
| 0 | 1613 | | catch (JsonException) |
| | 1614 | | { |
| | 1615 | | // Ignore the exception |
| 0 | 1616 | | } |
| 0 | 1617 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1618 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1619 | | if (_shouldTrace) |
| | 1620 | | { |
| 0 | 1621 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1622 | | } |
| 0 | 1623 | | _httpRequest.Dispose(); |
| 0 | 1624 | | if (_httpResponse != null) |
| | 1625 | | { |
| 0 | 1626 | | _httpResponse.Dispose(); |
| | 1627 | | } |
| 0 | 1628 | | throw ex; |
| | 1629 | | } |
| | 1630 | | // Create Result |
| 8 | 1631 | | var _result = new AzureOperationHeaderResponse<BlobStartUploadHeaders>(); |
| 8 | 1632 | | _result.Request = _httpRequest; |
| 8 | 1633 | | _result.Response = _httpResponse; |
| 8 | 1634 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1635 | | { |
| 8 | 1636 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1637 | | } |
| | 1638 | | try |
| | 1639 | | { |
| 8 | 1640 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobStartUploadHeaders>(JsonSerializer.Creat |
| 8 | 1641 | | } |
| 0 | 1642 | | catch (JsonException ex) |
| | 1643 | | { |
| 0 | 1644 | | _httpRequest.Dispose(); |
| 0 | 1645 | | if (_httpResponse != null) |
| | 1646 | | { |
| 0 | 1647 | | _httpResponse.Dispose(); |
| | 1648 | | } |
| 0 | 1649 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1650 | | } |
| 8 | 1651 | | if (_shouldTrace) |
| | 1652 | | { |
| 0 | 1653 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1654 | | } |
| 8 | 1655 | | return _result; |
| 8 | 1656 | | } |
| | 1657 | |
|
| | 1658 | | /// <summary> |
| | 1659 | | /// Retrieve the blob from the registry identified by `digest`. This endpoint |
| | 1660 | | /// may also support RFC7233 compliant range requests. Support can be detected |
| | 1661 | | /// by issuing a HEAD request. If the header `Accept-Range: bytes` is returned, |
| | 1662 | | /// range requests can be used to fetch partial content. |
| | 1663 | | /// </summary> |
| | 1664 | | /// <param name='name'> |
| | 1665 | | /// Name of the image (including the namespace) |
| | 1666 | | /// </param> |
| | 1667 | | /// <param name='digest'> |
| | 1668 | | /// Digest of a BLOB |
| | 1669 | | /// </param> |
| | 1670 | | /// <param name='range'> |
| | 1671 | | /// Format : bytes=<start>-<end>, HTTP Range header specifying |
| | 1672 | | /// blob chunk. |
| | 1673 | | /// </param> |
| | 1674 | | /// <param name='customHeaders'> |
| | 1675 | | /// Headers that will be added to request. |
| | 1676 | | /// </param> |
| | 1677 | | /// <param name='cancellationToken'> |
| | 1678 | | /// The cancellation token. |
| | 1679 | | /// </param> |
| | 1680 | | /// <exception cref="CloudException"> |
| | 1681 | | /// Thrown when the operation returned an invalid status code |
| | 1682 | | /// </exception> |
| | 1683 | | /// <exception cref="SerializationException"> |
| | 1684 | | /// Thrown when unable to deserialize the response |
| | 1685 | | /// </exception> |
| | 1686 | | /// <exception cref="ValidationException"> |
| | 1687 | | /// Thrown when a required parameter is null |
| | 1688 | | /// </exception> |
| | 1689 | | /// <exception cref="System.ArgumentNullException"> |
| | 1690 | | /// Thrown when a required parameter is null |
| | 1691 | | /// </exception> |
| | 1692 | | /// <return> |
| | 1693 | | /// A response object containing the response body and response headers. |
| | 1694 | | /// </return> |
| | 1695 | | public async Task<AzureOperationResponse<Stream,BlobGetChunkHeaders>> GetChunkWithHttpMessagesAsync(string name, |
| | 1696 | | { |
| 2 | 1697 | | if (Client.LoginUri == null) |
| | 1698 | | { |
| 0 | 1699 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 1700 | | } |
| 2 | 1701 | | if (name == null) |
| | 1702 | | { |
| 0 | 1703 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 1704 | | } |
| 2 | 1705 | | if (digest == null) |
| | 1706 | | { |
| 0 | 1707 | | throw new ValidationException(ValidationRules.CannotBeNull, "digest"); |
| | 1708 | | } |
| 2 | 1709 | | if (range == null) |
| | 1710 | | { |
| 0 | 1711 | | throw new ValidationException(ValidationRules.CannotBeNull, "range"); |
| | 1712 | | } |
| | 1713 | | // Tracing |
| 2 | 1714 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 1715 | | string _invocationId = null; |
| 2 | 1716 | | if (_shouldTrace) |
| | 1717 | | { |
| 0 | 1718 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1719 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1720 | | tracingParameters.Add("name", name); |
| 0 | 1721 | | tracingParameters.Add("digest", digest); |
| 0 | 1722 | | tracingParameters.Add("range", range); |
| 0 | 1723 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1724 | | ServiceClientTracing.Enter(_invocationId, this, "GetChunk", tracingParameters); |
| | 1725 | | } |
| | 1726 | | // Construct URL |
| 2 | 1727 | | var _baseUrl = Client.BaseUri; |
| 2 | 1728 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/{digest}"; |
| 2 | 1729 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 2 | 1730 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 2 | 1731 | | _url = _url.Replace("{digest}", System.Uri.EscapeDataString(digest)); |
| 2 | 1732 | | List<string> _queryParameters = new List<string>(); |
| 2 | 1733 | | if (_queryParameters.Count > 0) |
| | 1734 | | { |
| 0 | 1735 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1736 | | } |
| | 1737 | | // Create HTTP transport objects |
| 2 | 1738 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 1739 | | HttpResponseMessage _httpResponse = null; |
| 2 | 1740 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 1741 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1742 | | // Set Headers |
| 2 | 1743 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1744 | | { |
| 2 | 1745 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1746 | | } |
| 2 | 1747 | | if (range != null) |
| | 1748 | | { |
| 2 | 1749 | | if (_httpRequest.Headers.Contains("Range")) |
| | 1750 | | { |
| 0 | 1751 | | _httpRequest.Headers.Remove("Range"); |
| | 1752 | | } |
| 2 | 1753 | | _httpRequest.Headers.TryAddWithoutValidation("Range", range); |
| | 1754 | | } |
| 2 | 1755 | | if (Client.AcceptLanguage != null) |
| | 1756 | | { |
| 2 | 1757 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1758 | | { |
| 0 | 1759 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1760 | | } |
| 2 | 1761 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1762 | | } |
| | 1763 | |
|
| | 1764 | |
|
| 2 | 1765 | | if (customHeaders != null) |
| | 1766 | | { |
| 0 | 1767 | | foreach(var _header in customHeaders) |
| | 1768 | | { |
| 0 | 1769 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1770 | | { |
| 0 | 1771 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1772 | | } |
| 0 | 1773 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1774 | | } |
| | 1775 | | } |
| | 1776 | |
|
| | 1777 | | // Serialize Request |
| 2 | 1778 | | string _requestContent = null; |
| | 1779 | | // Set Credentials |
| 2 | 1780 | | if (Client.Credentials != null) |
| | 1781 | | { |
| 2 | 1782 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1783 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1784 | | } |
| | 1785 | | // Send Request |
| 2 | 1786 | | if (_shouldTrace) |
| | 1787 | | { |
| 0 | 1788 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1789 | | } |
| 2 | 1790 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1791 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons |
| 2 | 1792 | | if (_shouldTrace) |
| | 1793 | | { |
| 0 | 1794 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1795 | | } |
| 2 | 1796 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 1797 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1798 | | string _responseContent = null; |
| 2 | 1799 | | if ((int)_statusCode != 206) |
| | 1800 | | { |
| 0 | 1801 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 1802 | | try |
| | 1803 | | { |
| 0 | 1804 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1805 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 1806 | | if (_errorBody != null) |
| | 1807 | | { |
| 0 | 1808 | | ex = new CloudException(_errorBody.Message); |
| 0 | 1809 | | ex.Body = _errorBody; |
| | 1810 | | } |
| 0 | 1811 | | } |
| 0 | 1812 | | catch (JsonException) |
| | 1813 | | { |
| | 1814 | | // Ignore the exception |
| 0 | 1815 | | } |
| 0 | 1816 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1817 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1818 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1819 | | { |
| 0 | 1820 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1821 | | } |
| 0 | 1822 | | if (_shouldTrace) |
| | 1823 | | { |
| 0 | 1824 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1825 | | } |
| 0 | 1826 | | _httpRequest.Dispose(); |
| 0 | 1827 | | if (_httpResponse != null) |
| | 1828 | | { |
| 0 | 1829 | | _httpResponse.Dispose(); |
| | 1830 | | } |
| 0 | 1831 | | throw ex; |
| | 1832 | | } |
| | 1833 | | // Create Result |
| 2 | 1834 | | var _result = new AzureOperationResponse<Stream,BlobGetChunkHeaders>(); |
| 2 | 1835 | | _result.Request = _httpRequest; |
| 2 | 1836 | | _result.Response = _httpResponse; |
| 2 | 1837 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1838 | | { |
| 2 | 1839 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1840 | | } |
| | 1841 | | // Deserialize Response |
| 2 | 1842 | | if ((int)_statusCode == 206) |
| | 1843 | | { |
| 2 | 1844 | | _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); |
| | 1845 | | } |
| | 1846 | | try |
| | 1847 | | { |
| 2 | 1848 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobGetChunkHeaders>(JsonSerializer.Create(C |
| 2 | 1849 | | } |
| 0 | 1850 | | catch (JsonException ex) |
| | 1851 | | { |
| 0 | 1852 | | _httpRequest.Dispose(); |
| 0 | 1853 | | if (_httpResponse != null) |
| | 1854 | | { |
| 0 | 1855 | | _httpResponse.Dispose(); |
| | 1856 | | } |
| 0 | 1857 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1858 | | } |
| 2 | 1859 | | if (_shouldTrace) |
| | 1860 | | { |
| 0 | 1861 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1862 | | } |
| 2 | 1863 | | return _result; |
| 2 | 1864 | | } |
| | 1865 | |
|
| | 1866 | | /// <summary> |
| | 1867 | | /// Same as GET, except only the headers are returned. |
| | 1868 | | /// </summary> |
| | 1869 | | /// <param name='name'> |
| | 1870 | | /// Name of the image (including the namespace) |
| | 1871 | | /// </param> |
| | 1872 | | /// <param name='digest'> |
| | 1873 | | /// Digest of a BLOB |
| | 1874 | | /// </param> |
| | 1875 | | /// <param name='range'> |
| | 1876 | | /// Format : bytes=<start>-<end>, HTTP Range header specifying |
| | 1877 | | /// blob chunk. |
| | 1878 | | /// </param> |
| | 1879 | | /// <param name='customHeaders'> |
| | 1880 | | /// Headers that will be added to request. |
| | 1881 | | /// </param> |
| | 1882 | | /// <param name='cancellationToken'> |
| | 1883 | | /// The cancellation token. |
| | 1884 | | /// </param> |
| | 1885 | | /// <exception cref="AcrErrorsException"> |
| | 1886 | | /// Thrown when the operation returned an invalid status code |
| | 1887 | | /// </exception> |
| | 1888 | | /// <exception cref="ValidationException"> |
| | 1889 | | /// Thrown when a required parameter is null |
| | 1890 | | /// </exception> |
| | 1891 | | /// <exception cref="System.ArgumentNullException"> |
| | 1892 | | /// Thrown when a required parameter is null |
| | 1893 | | /// </exception> |
| | 1894 | | /// <return> |
| | 1895 | | /// A response object containing the response body and response headers. |
| | 1896 | | /// </return> |
| | 1897 | | public async Task<AzureOperationHeaderResponse<BlobCheckChunkHeaders>> CheckChunkWithHttpMessagesAsync(string na |
| | 1898 | | { |
| 2 | 1899 | | if (Client.LoginUri == null) |
| | 1900 | | { |
| 0 | 1901 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 1902 | | } |
| 2 | 1903 | | if (name == null) |
| | 1904 | | { |
| 0 | 1905 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 1906 | | } |
| 2 | 1907 | | if (digest == null) |
| | 1908 | | { |
| 0 | 1909 | | throw new ValidationException(ValidationRules.CannotBeNull, "digest"); |
| | 1910 | | } |
| 2 | 1911 | | if (range == null) |
| | 1912 | | { |
| 0 | 1913 | | throw new ValidationException(ValidationRules.CannotBeNull, "range"); |
| | 1914 | | } |
| | 1915 | | // Tracing |
| 2 | 1916 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 1917 | | string _invocationId = null; |
| 2 | 1918 | | if (_shouldTrace) |
| | 1919 | | { |
| 0 | 1920 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1921 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1922 | | tracingParameters.Add("name", name); |
| 0 | 1923 | | tracingParameters.Add("digest", digest); |
| 0 | 1924 | | tracingParameters.Add("range", range); |
| 0 | 1925 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1926 | | ServiceClientTracing.Enter(_invocationId, this, "CheckChunk", tracingParameters); |
| | 1927 | | } |
| | 1928 | | // Construct URL |
| 2 | 1929 | | var _baseUrl = Client.BaseUri; |
| 2 | 1930 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/{digest}"; |
| 2 | 1931 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 2 | 1932 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| 2 | 1933 | | _url = _url.Replace("{digest}", System.Uri.EscapeDataString(digest)); |
| 2 | 1934 | | List<string> _queryParameters = new List<string>(); |
| 2 | 1935 | | if (_queryParameters.Count > 0) |
| | 1936 | | { |
| 0 | 1937 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1938 | | } |
| | 1939 | | // Create HTTP transport objects |
| 2 | 1940 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 1941 | | HttpResponseMessage _httpResponse = null; |
| 2 | 1942 | | _httpRequest.Method = new HttpMethod("HEAD"); |
| 2 | 1943 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1944 | | // Set Headers |
| 2 | 1945 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1946 | | { |
| 2 | 1947 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1948 | | } |
| 2 | 1949 | | if (range != null) |
| | 1950 | | { |
| 2 | 1951 | | if (_httpRequest.Headers.Contains("Range")) |
| | 1952 | | { |
| 0 | 1953 | | _httpRequest.Headers.Remove("Range"); |
| | 1954 | | } |
| 2 | 1955 | | _httpRequest.Headers.TryAddWithoutValidation("Range", range); |
| | 1956 | | } |
| 2 | 1957 | | if (Client.AcceptLanguage != null) |
| | 1958 | | { |
| 2 | 1959 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1960 | | { |
| 0 | 1961 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1962 | | } |
| 2 | 1963 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1964 | | } |
| | 1965 | |
|
| | 1966 | |
|
| 2 | 1967 | | if (customHeaders != null) |
| | 1968 | | { |
| 0 | 1969 | | foreach(var _header in customHeaders) |
| | 1970 | | { |
| 0 | 1971 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1972 | | { |
| 0 | 1973 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1974 | | } |
| 0 | 1975 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1976 | | } |
| | 1977 | | } |
| | 1978 | |
|
| | 1979 | | // Serialize Request |
| 2 | 1980 | | string _requestContent = null; |
| | 1981 | | // Set Credentials |
| 2 | 1982 | | if (Client.Credentials != null) |
| | 1983 | | { |
| 2 | 1984 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1985 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1986 | | } |
| | 1987 | | // Send Request |
| 2 | 1988 | | if (_shouldTrace) |
| | 1989 | | { |
| 0 | 1990 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1991 | | } |
| 2 | 1992 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1993 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons |
| 2 | 1994 | | if (_shouldTrace) |
| | 1995 | | { |
| 0 | 1996 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1997 | | } |
| 2 | 1998 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 1999 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2000 | | string _responseContent = null; |
| 2 | 2001 | | if ((int)_statusCode != 200) |
| | 2002 | | { |
| 0 | 2003 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 2004 | | try |
| | 2005 | | { |
| 0 | 2006 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2007 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 2008 | | if (_errorBody != null) |
| | 2009 | | { |
| 0 | 2010 | | ex.Body = _errorBody; |
| | 2011 | | } |
| 0 | 2012 | | } |
| 0 | 2013 | | catch (JsonException) |
| | 2014 | | { |
| | 2015 | | // Ignore the exception |
| 0 | 2016 | | } |
| 0 | 2017 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2018 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2019 | | if (_shouldTrace) |
| | 2020 | | { |
| 0 | 2021 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2022 | | } |
| 0 | 2023 | | _httpRequest.Dispose(); |
| 0 | 2024 | | if (_httpResponse != null) |
| | 2025 | | { |
| 0 | 2026 | | _httpResponse.Dispose(); |
| | 2027 | | } |
| 0 | 2028 | | throw ex; |
| | 2029 | | } |
| | 2030 | | // Create Result |
| 2 | 2031 | | var _result = new AzureOperationHeaderResponse<BlobCheckChunkHeaders>(); |
| 2 | 2032 | | _result.Request = _httpRequest; |
| 2 | 2033 | | _result.Response = _httpResponse; |
| 2 | 2034 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2035 | | { |
| 2 | 2036 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2037 | | } |
| | 2038 | | try |
| | 2039 | | { |
| 2 | 2040 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobCheckChunkHeaders>(JsonSerializer.Create |
| 2 | 2041 | | } |
| 0 | 2042 | | catch (JsonException ex) |
| | 2043 | | { |
| 0 | 2044 | | _httpRequest.Dispose(); |
| 0 | 2045 | | if (_httpResponse != null) |
| | 2046 | | { |
| 0 | 2047 | | _httpResponse.Dispose(); |
| | 2048 | | } |
| 0 | 2049 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 2050 | | } |
| 2 | 2051 | | if (_shouldTrace) |
| | 2052 | | { |
| 0 | 2053 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2054 | | } |
| 2 | 2055 | | return _result; |
| 2 | 2056 | | } |
| | 2057 | |
|
| | 2058 | | } |
| | 2059 | | } |