< Summary

Class:Microsoft.Azure.ContainerRegistry.BlobOperations
Assembly:Microsoft.Azure.ContainerRegistry
File(s):C:\Git\azure-sdk-for-net\sdk\containerregistry\Microsoft.Azure.ContainerRegistry\src\Generated\BlobOperations.cs
Covered lines:529
Uncovered lines:426
Coverable lines:955
Total lines:2059
Line coverage:55.3% (529 of 955)
Covered branches:284
Total branches:576
Branch coverage:49.3% (284 of 576)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
GetWithHttpMessagesAsync()-52.81%46.3%
CheckWithHttpMessagesAsync()-67.86%58%
DeleteWithHttpMessagesAsync()-52.81%46.15%
MountWithHttpMessagesAsync()-55.56%53.7%
GetStatusWithHttpMessagesAsync()-53.75%45.83%
UploadWithHttpMessagesAsync()-54.55%50%
EndUploadWithHttpMessagesAsync()-53.93%51.79%
CancelUploadWithHttpMessagesAsync()-56.16%47.83%
StartUploadWithHttpMessagesAsync()-53.75%45.65%
GetChunkWithHttpMessagesAsync()-53.13%48.28%
CheckChunkWithHttpMessagesAsync()-53.85%48.15%

File(s)

C:\Git\azure-sdk-for-net\sdk\containerregistry\Microsoft.Azure.ContainerRegistry\src\Generated\BlobOperations.cs

#LineLine coverage
 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
 11namespace 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>
 6040        internal BlobOperations(AzureContainerRegistryClient client)
 41        {
 6042            if (client == null)
 43            {
 044                throw new System.ArgumentNullException("client");
 45            }
 6046            Client = client;
 6047        }
 48
 49        /// <summary>
 50        /// Gets a reference to the AzureContainerRegistryClient
 51        /// </summary>
 49652        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        {
 686            if (Client.LoginUri == null)
 87            {
 088                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 89            }
 690            if (name == null)
 91            {
 092                throw new ValidationException(ValidationRules.CannotBeNull, "name");
 93            }
 694            if (digest == null)
 95            {
 096                throw new ValidationException(ValidationRules.CannotBeNull, "digest");
 97            }
 98            // Tracing
 699            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 6100            string _invocationId = null;
 6101            if (_shouldTrace)
 102            {
 0103                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0104                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0105                tracingParameters.Add("name", name);
 0106                tracingParameters.Add("digest", digest);
 0107                tracingParameters.Add("cancellationToken", cancellationToken);
 0108                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 109            }
 110            // Construct URL
 6111            var _baseUrl = Client.BaseUri;
 6112            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/{digest}";
 6113            _url = _url.Replace("{url}", Client.LoginUri);
 6114            _url = _url.Replace("{name}", System.Uri.EscapeDataString(name));
 6115            _url = _url.Replace("{digest}", System.Uri.EscapeDataString(digest));
 6116            List<string> _queryParameters = new List<string>();
 6117            if (_queryParameters.Count > 0)
 118            {
 0119                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 120            }
 121            // Create HTTP transport objects
 6122            var _httpRequest = new HttpRequestMessage();
 6123            HttpResponseMessage _httpResponse = null;
 6124            _httpRequest.Method = new HttpMethod("GET");
 6125            _httpRequest.RequestUri = new System.Uri(_url);
 126            // Set Headers
 6127            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 128            {
 6129                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 130            }
 6131            if (Client.AcceptLanguage != null)
 132            {
 6133                if (_httpRequest.Headers.Contains("accept-language"))
 134                {
 0135                    _httpRequest.Headers.Remove("accept-language");
 136                }
 6137                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 138            }
 139
 140
 6141            if (customHeaders != null)
 142            {
 0143                foreach(var _header in customHeaders)
 144                {
 0145                    if (_httpRequest.Headers.Contains(_header.Key))
 146                    {
 0147                        _httpRequest.Headers.Remove(_header.Key);
 148                    }
 0149                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 150                }
 151            }
 152
 153            // Serialize Request
 6154            string _requestContent = null;
 155            // Set Credentials
 6156            if (Client.Credentials != null)
 157            {
 6158                cancellationToken.ThrowIfCancellationRequested();
 6159                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 160            }
 161            // Send Request
 6162            if (_shouldTrace)
 163            {
 0164                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 165            }
 6166            cancellationToken.ThrowIfCancellationRequested();
 6167            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons
 6168            if (_shouldTrace)
 169            {
 0170                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 171            }
 6172            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 6173            cancellationToken.ThrowIfCancellationRequested();
 6174            string _responseContent = null;
 6175            if ((int)_statusCode != 200 && (int)_statusCode != 307)
 176            {
 0177                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 178                try
 179                {
 0180                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0181                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0182                    if (_errorBody != null)
 183                    {
 0184                        ex = new CloudException(_errorBody.Message);
 0185                        ex.Body = _errorBody;
 186                    }
 0187                }
 0188                catch (JsonException)
 189                {
 190                    // Ignore the exception
 0191                }
 0192                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0193                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0194                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 195                {
 0196                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 197                }
 0198                if (_shouldTrace)
 199                {
 0200                    ServiceClientTracing.Error(_invocationId, ex);
 201                }
 0202                _httpRequest.Dispose();
 0203                if (_httpResponse != null)
 204                {
 0205                    _httpResponse.Dispose();
 206                }
 0207                throw ex;
 208            }
 209            // Create Result
 6210            var _result = new AzureOperationResponse<Stream,BlobGetHeaders>();
 6211            _result.Request = _httpRequest;
 6212            _result.Response = _httpResponse;
 6213            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 214            {
 6215                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 216            }
 217            // Deserialize Response
 6218            if ((int)_statusCode == 200)
 219            {
 6220                _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
 221            }
 222            try
 223            {
 6224                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobGetHeaders>(JsonSerializer.Create(Client
 6225            }
 0226            catch (JsonException ex)
 227            {
 0228                _httpRequest.Dispose();
 0229                if (_httpResponse != null)
 230                {
 0231                    _httpResponse.Dispose();
 232                }
 0233                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 234            }
 6235            if (_shouldTrace)
 236            {
 0237                ServiceClientTracing.Exit(_invocationId, _result);
 238            }
 6239            return _result;
 6240        }
 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        {
 4271            if (Client.LoginUri == null)
 272            {
 0273                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 274            }
 4275            if (name == null)
 276            {
 0277                throw new ValidationException(ValidationRules.CannotBeNull, "name");
 278            }
 4279            if (digest == null)
 280            {
 0281                throw new ValidationException(ValidationRules.CannotBeNull, "digest");
 282            }
 283            // Tracing
 4284            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 4285            string _invocationId = null;
 4286            if (_shouldTrace)
 287            {
 0288                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0289                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0290                tracingParameters.Add("name", name);
 0291                tracingParameters.Add("digest", digest);
 0292                tracingParameters.Add("cancellationToken", cancellationToken);
 0293                ServiceClientTracing.Enter(_invocationId, this, "Check", tracingParameters);
 294            }
 295            // Construct URL
 4296            var _baseUrl = Client.BaseUri;
 4297            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/{digest}";
 4298            _url = _url.Replace("{url}", Client.LoginUri);
 4299            _url = _url.Replace("{name}", System.Uri.EscapeDataString(name));
 4300            _url = _url.Replace("{digest}", System.Uri.EscapeDataString(digest));
 4301            List<string> _queryParameters = new List<string>();
 4302            if (_queryParameters.Count > 0)
 303            {
 0304                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 305            }
 306            // Create HTTP transport objects
 4307            var _httpRequest = new HttpRequestMessage();
 4308            HttpResponseMessage _httpResponse = null;
 4309            _httpRequest.Method = new HttpMethod("HEAD");
 4310            _httpRequest.RequestUri = new System.Uri(_url);
 311            // Set Headers
 4312            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 313            {
 4314                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 315            }
 4316            if (Client.AcceptLanguage != null)
 317            {
 4318                if (_httpRequest.Headers.Contains("accept-language"))
 319                {
 0320                    _httpRequest.Headers.Remove("accept-language");
 321                }
 4322                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 323            }
 324
 325
 4326            if (customHeaders != null)
 327            {
 0328                foreach(var _header in customHeaders)
 329                {
 0330                    if (_httpRequest.Headers.Contains(_header.Key))
 331                    {
 0332                        _httpRequest.Headers.Remove(_header.Key);
 333                    }
 0334                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 335                }
 336            }
 337
 338            // Serialize Request
 4339            string _requestContent = null;
 340            // Set Credentials
 4341            if (Client.Credentials != null)
 342            {
 4343                cancellationToken.ThrowIfCancellationRequested();
 4344                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 345            }
 346            // Send Request
 4347            if (_shouldTrace)
 348            {
 0349                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 350            }
 4351            cancellationToken.ThrowIfCancellationRequested();
 4352            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons
 4353            if (_shouldTrace)
 354            {
 0355                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 356            }
 4357            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 4358            cancellationToken.ThrowIfCancellationRequested();
 4359            string _responseContent = null;
 4360            if ((int)_statusCode != 200 && (int)_statusCode != 307)
 361            {
 2362                var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status
 363                try
 364                {
 2365                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2366                    AcrErrors _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon
 2367                    if (_errorBody != null)
 368                    {
 0369                        ex.Body = _errorBody;
 370                    }
 2371                }
 0372                catch (JsonException)
 373                {
 374                    // Ignore the exception
 0375                }
 2376                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 2377                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 2378                if (_shouldTrace)
 379                {
 0380                    ServiceClientTracing.Error(_invocationId, ex);
 381                }
 2382                _httpRequest.Dispose();
 2383                if (_httpResponse != null)
 384                {
 2385                    _httpResponse.Dispose();
 386                }
 2387                throw ex;
 388            }
 389            // Create Result
 2390            var _result = new AzureOperationHeaderResponse<BlobCheckHeaders>();
 2391            _result.Request = _httpRequest;
 2392            _result.Response = _httpResponse;
 2393            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 394            {
 2395                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 396            }
 397            try
 398            {
 2399                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobCheckHeaders>(JsonSerializer.Create(Clie
 2400            }
 0401            catch (JsonException ex)
 402            {
 0403                _httpRequest.Dispose();
 0404                if (_httpResponse != null)
 405                {
 0406                    _httpResponse.Dispose();
 407                }
 0408                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 409            }
 2410            if (_shouldTrace)
 411            {
 0412                ServiceClientTracing.Exit(_invocationId, _result);
 413            }
 2414            return _result;
 2415        }
 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        {
 2449            if (Client.LoginUri == null)
 450            {
 0451                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 452            }
 2453            if (name == null)
 454            {
 0455                throw new ValidationException(ValidationRules.CannotBeNull, "name");
 456            }
 2457            if (digest == null)
 458            {
 0459                throw new ValidationException(ValidationRules.CannotBeNull, "digest");
 460            }
 461            // Tracing
 2462            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2463            string _invocationId = null;
 2464            if (_shouldTrace)
 465            {
 0466                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0467                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0468                tracingParameters.Add("name", name);
 0469                tracingParameters.Add("digest", digest);
 0470                tracingParameters.Add("cancellationToken", cancellationToken);
 0471                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 472            }
 473            // Construct URL
 2474            var _baseUrl = Client.BaseUri;
 2475            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/{digest}";
 2476            _url = _url.Replace("{url}", Client.LoginUri);
 2477            _url = _url.Replace("{name}", System.Uri.EscapeDataString(name));
 2478            _url = _url.Replace("{digest}", System.Uri.EscapeDataString(digest));
 2479            List<string> _queryParameters = new List<string>();
 2480            if (_queryParameters.Count > 0)
 481            {
 0482                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 483            }
 484            // Create HTTP transport objects
 2485            var _httpRequest = new HttpRequestMessage();
 2486            HttpResponseMessage _httpResponse = null;
 2487            _httpRequest.Method = new HttpMethod("DELETE");
 2488            _httpRequest.RequestUri = new System.Uri(_url);
 489            // Set Headers
 2490            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 491            {
 2492                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 493            }
 2494            if (Client.AcceptLanguage != null)
 495            {
 2496                if (_httpRequest.Headers.Contains("accept-language"))
 497                {
 0498                    _httpRequest.Headers.Remove("accept-language");
 499                }
 2500                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 501            }
 502
 503
 2504            if (customHeaders != null)
 505            {
 0506                foreach(var _header in customHeaders)
 507                {
 0508                    if (_httpRequest.Headers.Contains(_header.Key))
 509                    {
 0510                        _httpRequest.Headers.Remove(_header.Key);
 511                    }
 0512                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 513                }
 514            }
 515
 516            // Serialize Request
 2517            string _requestContent = null;
 518            // Set Credentials
 2519            if (Client.Credentials != null)
 520            {
 2521                cancellationToken.ThrowIfCancellationRequested();
 2522                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 523            }
 524            // Send Request
 2525            if (_shouldTrace)
 526            {
 0527                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 528            }
 2529            cancellationToken.ThrowIfCancellationRequested();
 2530            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons
 2531            if (_shouldTrace)
 532            {
 0533                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 534            }
 2535            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2536            cancellationToken.ThrowIfCancellationRequested();
 2537            string _responseContent = null;
 2538            if ((int)_statusCode != 202)
 539            {
 0540                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 541                try
 542                {
 0543                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0544                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0545                    if (_errorBody != null)
 546                    {
 0547                        ex = new CloudException(_errorBody.Message);
 0548                        ex.Body = _errorBody;
 549                    }
 0550                }
 0551                catch (JsonException)
 552                {
 553                    // Ignore the exception
 0554                }
 0555                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0556                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0557                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 558                {
 0559                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 560                }
 0561                if (_shouldTrace)
 562                {
 0563                    ServiceClientTracing.Error(_invocationId, ex);
 564                }
 0565                _httpRequest.Dispose();
 0566                if (_httpResponse != null)
 567                {
 0568                    _httpResponse.Dispose();
 569                }
 0570                throw ex;
 571            }
 572            // Create Result
 2573            var _result = new AzureOperationResponse<Stream,BlobDeleteHeaders>();
 2574            _result.Request = _httpRequest;
 2575            _result.Response = _httpResponse;
 2576            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 577            {
 2578                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 579            }
 580            // Deserialize Response
 2581            if ((int)_statusCode == 202)
 582            {
 2583                _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
 584            }
 585            try
 586            {
 2587                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobDeleteHeaders>(JsonSerializer.Create(Cli
 2588            }
 0589            catch (JsonException ex)
 590            {
 0591                _httpRequest.Dispose();
 0592                if (_httpResponse != null)
 593                {
 0594                    _httpResponse.Dispose();
 595                }
 0596                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 597            }
 2598            if (_shouldTrace)
 599            {
 0600                ServiceClientTracing.Exit(_invocationId, _result);
 601            }
 2602            return _result;
 2603        }
 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        {
 2637            if (Client.LoginUri == null)
 638            {
 0639                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 640            }
 2641            if (name == null)
 642            {
 0643                throw new ValidationException(ValidationRules.CannotBeNull, "name");
 644            }
 2645            if (fromParameter == null)
 646            {
 0647                throw new ValidationException(ValidationRules.CannotBeNull, "fromParameter");
 648            }
 2649            if (mount == null)
 650            {
 0651                throw new ValidationException(ValidationRules.CannotBeNull, "mount");
 652            }
 653            // Tracing
 2654            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2655            string _invocationId = null;
 2656            if (_shouldTrace)
 657            {
 0658                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0659                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0660                tracingParameters.Add("name", name);
 0661                tracingParameters.Add("fromParameter", fromParameter);
 0662                tracingParameters.Add("mount", mount);
 0663                tracingParameters.Add("cancellationToken", cancellationToken);
 0664                ServiceClientTracing.Enter(_invocationId, this, "Mount", tracingParameters);
 665            }
 666            // Construct URL
 2667            var _baseUrl = Client.BaseUri;
 2668            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/uploads/";
 2669            _url = _url.Replace("{url}", Client.LoginUri);
 2670            _url = _url.Replace("{name}", System.Uri.EscapeDataString(name));
 2671            List<string> _queryParameters = new List<string>();
 2672            if (fromParameter != null)
 673            {
 2674                _queryParameters.Add(string.Format("from={0}", System.Uri.EscapeDataString(fromParameter)));
 675            }
 2676            if (mount != null)
 677            {
 2678                _queryParameters.Add(string.Format("mount={0}", System.Uri.EscapeDataString(mount)));
 679            }
 2680            if (_queryParameters.Count > 0)
 681            {
 2682                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 683            }
 684            // Create HTTP transport objects
 2685            var _httpRequest = new HttpRequestMessage();
 2686            HttpResponseMessage _httpResponse = null;
 2687            _httpRequest.Method = new HttpMethod("POST");
 2688            _httpRequest.RequestUri = new System.Uri(_url);
 689            // Set Headers
 2690            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 691            {
 2692                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 693            }
 2694            if (Client.AcceptLanguage != null)
 695            {
 2696                if (_httpRequest.Headers.Contains("accept-language"))
 697                {
 0698                    _httpRequest.Headers.Remove("accept-language");
 699                }
 2700                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 701            }
 702
 703
 2704            if (customHeaders != null)
 705            {
 0706                foreach(var _header in customHeaders)
 707                {
 0708                    if (_httpRequest.Headers.Contains(_header.Key))
 709                    {
 0710                        _httpRequest.Headers.Remove(_header.Key);
 711                    }
 0712                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 713                }
 714            }
 715
 716            // Serialize Request
 2717            string _requestContent = null;
 718            // Set Credentials
 2719            if (Client.Credentials != null)
 720            {
 2721                cancellationToken.ThrowIfCancellationRequested();
 2722                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 723            }
 724            // Send Request
 2725            if (_shouldTrace)
 726            {
 0727                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 728            }
 2729            cancellationToken.ThrowIfCancellationRequested();
 2730            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2731            if (_shouldTrace)
 732            {
 0733                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 734            }
 2735            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2736            cancellationToken.ThrowIfCancellationRequested();
 2737            string _responseContent = null;
 2738            if ((int)_statusCode != 201)
 739            {
 0740                var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status
 741                try
 742                {
 0743                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0744                    AcrErrors _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon
 0745                    if (_errorBody != null)
 746                    {
 0747                        ex.Body = _errorBody;
 748                    }
 0749                }
 0750                catch (JsonException)
 751                {
 752                    // Ignore the exception
 0753                }
 0754                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0755                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0756                if (_shouldTrace)
 757                {
 0758                    ServiceClientTracing.Error(_invocationId, ex);
 759                }
 0760                _httpRequest.Dispose();
 0761                if (_httpResponse != null)
 762                {
 0763                    _httpResponse.Dispose();
 764                }
 0765                throw ex;
 766            }
 767            // Create Result
 2768            var _result = new AzureOperationHeaderResponse<BlobMountHeaders>();
 2769            _result.Request = _httpRequest;
 2770            _result.Response = _httpResponse;
 2771            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 772            {
 2773                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 774            }
 775            try
 776            {
 2777                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobMountHeaders>(JsonSerializer.Create(Clie
 2778            }
 0779            catch (JsonException ex)
 780            {
 0781                _httpRequest.Dispose();
 0782                if (_httpResponse != null)
 783                {
 0784                    _httpResponse.Dispose();
 785                }
 0786                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 787            }
 2788            if (_shouldTrace)
 789            {
 0790                ServiceClientTracing.Exit(_invocationId, _result);
 791            }
 2792            return _result;
 2793        }
 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        {
 2823            if (Client.LoginUri == null)
 824            {
 0825                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 826            }
 2827            if (location == null)
 828            {
 0829                throw new ValidationException(ValidationRules.CannotBeNull, "location");
 830            }
 831            // Tracing
 2832            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2833            string _invocationId = null;
 2834            if (_shouldTrace)
 835            {
 0836                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0837                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0838                tracingParameters.Add("location", location);
 0839                tracingParameters.Add("cancellationToken", cancellationToken);
 0840                ServiceClientTracing.Enter(_invocationId, this, "GetStatus", tracingParameters);
 841            }
 842            // Construct URL
 2843            var _baseUrl = Client.BaseUri;
 2844            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{nextBlobUuidLink}";
 2845            _url = _url.Replace("{url}", Client.LoginUri);
 2846            _url = _url.Replace(location.StartsWith("/") ? "/{nextBlobUuidLink}" : "{nextBlobUuidLink}", location);
 2847            List<string> _queryParameters = new List<string>();
 2848            if (_queryParameters.Count > 0)
 849            {
 0850                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 851            }
 852            // Create HTTP transport objects
 2853            var _httpRequest = new HttpRequestMessage();
 2854            HttpResponseMessage _httpResponse = null;
 2855            _httpRequest.Method = new HttpMethod("GET");
 2856            _httpRequest.RequestUri = new System.Uri(_url);
 857            // Set Headers
 2858            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 859            {
 2860                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 861            }
 2862            if (Client.AcceptLanguage != null)
 863            {
 2864                if (_httpRequest.Headers.Contains("accept-language"))
 865                {
 0866                    _httpRequest.Headers.Remove("accept-language");
 867                }
 2868                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 869            }
 870
 871
 2872            if (customHeaders != null)
 873            {
 0874                foreach(var _header in customHeaders)
 875                {
 0876                    if (_httpRequest.Headers.Contains(_header.Key))
 877                    {
 0878                        _httpRequest.Headers.Remove(_header.Key);
 879                    }
 0880                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 881                }
 882            }
 883
 884            // Serialize Request
 2885            string _requestContent = null;
 886            // Set Credentials
 2887            if (Client.Credentials != null)
 888            {
 2889                cancellationToken.ThrowIfCancellationRequested();
 2890                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 891            }
 892            // Send Request
 2893            if (_shouldTrace)
 894            {
 0895                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 896            }
 2897            cancellationToken.ThrowIfCancellationRequested();
 2898            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2899            if (_shouldTrace)
 900            {
 0901                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 902            }
 2903            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2904            cancellationToken.ThrowIfCancellationRequested();
 2905            string _responseContent = null;
 2906            if ((int)_statusCode != 204)
 907            {
 0908                var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status
 909                try
 910                {
 0911                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0912                    AcrErrors _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon
 0913                    if (_errorBody != null)
 914                    {
 0915                        ex.Body = _errorBody;
 916                    }
 0917                }
 0918                catch (JsonException)
 919                {
 920                    // Ignore the exception
 0921                }
 0922                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0923                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0924                if (_shouldTrace)
 925                {
 0926                    ServiceClientTracing.Error(_invocationId, ex);
 927                }
 0928                _httpRequest.Dispose();
 0929                if (_httpResponse != null)
 930                {
 0931                    _httpResponse.Dispose();
 932                }
 0933                throw ex;
 934            }
 935            // Create Result
 2936            var _result = new AzureOperationHeaderResponse<BlobGetStatusHeaders>();
 2937            _result.Request = _httpRequest;
 2938            _result.Response = _httpResponse;
 2939            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 940            {
 2941                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 942            }
 943            try
 944            {
 2945                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobGetStatusHeaders>(JsonSerializer.Create(
 2946            }
 0947            catch (JsonException ex)
 948            {
 0949                _httpRequest.Dispose();
 0950                if (_httpResponse != null)
 951                {
 0952                    _httpResponse.Dispose();
 953                }
 0954                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 955            }
 2956            if (_shouldTrace)
 957            {
 0958                ServiceClientTracing.Exit(_invocationId, _result);
 959            }
 2960            return _result;
 2961        }
 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        {
 4993            if (Client.LoginUri == null)
 994            {
 0995                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 996            }
 4997            if (value == null)
 998            {
 0999                throw new ValidationException(ValidationRules.CannotBeNull, "value");
 1000            }
 41001            if (location == null)
 1002            {
 01003                throw new ValidationException(ValidationRules.CannotBeNull, "location");
 1004            }
 1005            // Tracing
 41006            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 41007            string _invocationId = null;
 41008            if (_shouldTrace)
 1009            {
 01010                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01011                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01012                tracingParameters.Add("value", value);
 01013                tracingParameters.Add("location", location);
 01014                tracingParameters.Add("cancellationToken", cancellationToken);
 01015                ServiceClientTracing.Enter(_invocationId, this, "Upload", tracingParameters);
 1016            }
 1017            // Construct URL
 41018            var _baseUrl = Client.BaseUri;
 41019            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{nextBlobUuidLink}";
 41020            _url = _url.Replace("{url}", Client.LoginUri);
 41021            _url = _url.Replace(location.StartsWith("/") ? "/{nextBlobUuidLink}" : "{nextBlobUuidLink}", location);
 41022            List<string> _queryParameters = new List<string>();
 41023            if (_queryParameters.Count > 0)
 1024            {
 01025                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1026            }
 1027            // Create HTTP transport objects
 41028            var _httpRequest = new HttpRequestMessage();
 41029            HttpResponseMessage _httpResponse = null;
 41030            _httpRequest.Method = new HttpMethod("PATCH");
 41031            _httpRequest.RequestUri = new System.Uri(_url);
 1032            // Set Headers
 41033            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1034            {
 41035                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1036            }
 41037            if (Client.AcceptLanguage != null)
 1038            {
 41039                if (_httpRequest.Headers.Contains("accept-language"))
 1040                {
 01041                    _httpRequest.Headers.Remove("accept-language");
 1042                }
 41043                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1044            }
 1045
 1046
 41047            if (customHeaders != null)
 1048            {
 01049                foreach(var _header in customHeaders)
 1050                {
 01051                    if (_httpRequest.Headers.Contains(_header.Key))
 1052                    {
 01053                        _httpRequest.Headers.Remove(_header.Key);
 1054                    }
 01055                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1056                }
 1057            }
 1058
 1059            // Serialize Request
 41060            string _requestContent = null;
 41061            if(value == null)
 1062            {
 01063              throw new System.ArgumentNullException("value");
 1064            }
 41065            if (value != null && value != Stream.Null)
 1066            {
 41067                _httpRequest.Content = new StreamContent(value);
 41068                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1069            }
 1070            // Set Credentials
 41071            if (Client.Credentials != null)
 1072            {
 41073                cancellationToken.ThrowIfCancellationRequested();
 41074                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1075            }
 1076            // Send Request
 41077            if (_shouldTrace)
 1078            {
 01079                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1080            }
 41081            cancellationToken.ThrowIfCancellationRequested();
 41082            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 41083            if (_shouldTrace)
 1084            {
 01085                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1086            }
 41087            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 41088            cancellationToken.ThrowIfCancellationRequested();
 41089            string _responseContent = null;
 41090            if ((int)_statusCode != 202)
 1091            {
 01092                var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status
 1093                try
 1094                {
 01095                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01096                    AcrErrors _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon
 01097                    if (_errorBody != null)
 1098                    {
 01099                        ex.Body = _errorBody;
 1100                    }
 01101                }
 01102                catch (JsonException)
 1103                {
 1104                    // Ignore the exception
 01105                }
 01106                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01107                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01108                if (_shouldTrace)
 1109                {
 01110                    ServiceClientTracing.Error(_invocationId, ex);
 1111                }
 01112                _httpRequest.Dispose();
 01113                if (_httpResponse != null)
 1114                {
 01115                    _httpResponse.Dispose();
 1116                }
 01117                throw ex;
 1118            }
 1119            // Create Result
 41120            var _result = new AzureOperationHeaderResponse<BlobUploadHeaders>();
 41121            _result.Request = _httpRequest;
 41122            _result.Response = _httpResponse;
 41123            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1124            {
 41125                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1126            }
 1127            try
 1128            {
 41129                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobUploadHeaders>(JsonSerializer.Create(Cli
 41130            }
 01131            catch (JsonException ex)
 1132            {
 01133                _httpRequest.Dispose();
 01134                if (_httpResponse != null)
 1135                {
 01136                    _httpResponse.Dispose();
 1137                }
 01138                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1139            }
 41140            if (_shouldTrace)
 1141            {
 01142                ServiceClientTracing.Exit(_invocationId, _result);
 1143            }
 41144            return _result;
 41145        }
 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        {
 41182            if (Client.LoginUri == null)
 1183            {
 01184                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 1185            }
 41186            if (digest == null)
 1187            {
 01188                throw new ValidationException(ValidationRules.CannotBeNull, "digest");
 1189            }
 41190            if (location == null)
 1191            {
 01192                throw new ValidationException(ValidationRules.CannotBeNull, "location");
 1193            }
 1194            // Tracing
 41195            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 41196            string _invocationId = null;
 41197            if (_shouldTrace)
 1198            {
 01199                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01200                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01201                tracingParameters.Add("digest", digest);
 01202                tracingParameters.Add("value", value);
 01203                tracingParameters.Add("location", location);
 01204                tracingParameters.Add("cancellationToken", cancellationToken);
 01205                ServiceClientTracing.Enter(_invocationId, this, "EndUpload", tracingParameters);
 1206            }
 1207            // Construct URL
 41208            var _baseUrl = Client.BaseUri;
 41209            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{nextBlobUuidLink}";
 41210            _url = _url.Replace("{url}", Client.LoginUri);
 41211            _url = _url.Replace(location.StartsWith("/") ? "/{nextBlobUuidLink}" : "{nextBlobUuidLink}", location);
 41212            List<string> _queryParameters = new List<string>();
 41213            if (digest != null)
 1214            {
 41215                _queryParameters.Add(string.Format("digest={0}", System.Uri.EscapeDataString(digest)));
 1216            }
 41217            if (_queryParameters.Count > 0)
 1218            {
 41219                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1220            }
 1221            // Create HTTP transport objects
 41222            var _httpRequest = new HttpRequestMessage();
 41223            HttpResponseMessage _httpResponse = null;
 41224            _httpRequest.Method = new HttpMethod("PUT");
 41225            _httpRequest.RequestUri = new System.Uri(_url);
 1226            // Set Headers
 41227            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1228            {
 41229                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1230            }
 41231            if (Client.AcceptLanguage != null)
 1232            {
 41233                if (_httpRequest.Headers.Contains("accept-language"))
 1234                {
 01235                    _httpRequest.Headers.Remove("accept-language");
 1236                }
 41237                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1238            }
 1239
 1240
 41241            if (customHeaders != null)
 1242            {
 01243                foreach(var _header in customHeaders)
 1244                {
 01245                    if (_httpRequest.Headers.Contains(_header.Key))
 1246                    {
 01247                        _httpRequest.Headers.Remove(_header.Key);
 1248                    }
 01249                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1250                }
 1251            }
 1252
 1253            // Serialize Request
 41254            string _requestContent = null;
 41255            if (value != null && value != Stream.Null)
 1256            {
 01257                _httpRequest.Content = new StreamContent(value);
 01258                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1259            }
 1260            // Set Credentials
 41261            if (Client.Credentials != null)
 1262            {
 41263                cancellationToken.ThrowIfCancellationRequested();
 41264                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1265            }
 1266            // Send Request
 41267            if (_shouldTrace)
 1268            {
 01269                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1270            }
 41271            cancellationToken.ThrowIfCancellationRequested();
 41272            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 41273            if (_shouldTrace)
 1274            {
 01275                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1276            }
 41277            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 41278            cancellationToken.ThrowIfCancellationRequested();
 41279            string _responseContent = null;
 41280            if ((int)_statusCode != 201)
 1281            {
 01282                var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status
 1283                try
 1284                {
 01285                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01286                    AcrErrors _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon
 01287                    if (_errorBody != null)
 1288                    {
 01289                        ex.Body = _errorBody;
 1290                    }
 01291                }
 01292                catch (JsonException)
 1293                {
 1294                    // Ignore the exception
 01295                }
 01296                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01297                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01298                if (_shouldTrace)
 1299                {
 01300                    ServiceClientTracing.Error(_invocationId, ex);
 1301                }
 01302                _httpRequest.Dispose();
 01303                if (_httpResponse != null)
 1304                {
 01305                    _httpResponse.Dispose();
 1306                }
 01307                throw ex;
 1308            }
 1309            // Create Result
 41310            var _result = new AzureOperationHeaderResponse<BlobEndUploadHeaders>();
 41311            _result.Request = _httpRequest;
 41312            _result.Response = _httpResponse;
 41313            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1314            {
 41315                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1316            }
 1317            try
 1318            {
 41319                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobEndUploadHeaders>(JsonSerializer.Create(
 41320            }
 01321            catch (JsonException ex)
 1322            {
 01323                _httpRequest.Dispose();
 01324                if (_httpResponse != null)
 1325                {
 01326                    _httpResponse.Dispose();
 1327                }
 01328                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1329            }
 41330            if (_shouldTrace)
 1331            {
 01332                ServiceClientTracing.Exit(_invocationId, _result);
 1333            }
 41334            return _result;
 41335        }
 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        {
 41365            if (Client.LoginUri == null)
 1366            {
 01367                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 1368            }
 41369            if (location == null)
 1370            {
 01371                throw new ValidationException(ValidationRules.CannotBeNull, "location");
 1372            }
 1373            // Tracing
 41374            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 41375            string _invocationId = null;
 41376            if (_shouldTrace)
 1377            {
 01378                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01379                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01380                tracingParameters.Add("location", location);
 01381                tracingParameters.Add("cancellationToken", cancellationToken);
 01382                ServiceClientTracing.Enter(_invocationId, this, "CancelUpload", tracingParameters);
 1383            }
 1384            // Construct URL
 41385            var _baseUrl = Client.BaseUri;
 41386            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{nextBlobUuidLink}";
 41387            _url = _url.Replace("{url}", Client.LoginUri);
 41388            _url = _url.Replace(location.StartsWith("/") ? "/{nextBlobUuidLink}" : "{nextBlobUuidLink}", location);
 41389            List<string> _queryParameters = new List<string>();
 41390            if (_queryParameters.Count > 0)
 1391            {
 01392                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1393            }
 1394            // Create HTTP transport objects
 41395            var _httpRequest = new HttpRequestMessage();
 41396            HttpResponseMessage _httpResponse = null;
 41397            _httpRequest.Method = new HttpMethod("DELETE");
 41398            _httpRequest.RequestUri = new System.Uri(_url);
 1399            // Set Headers
 41400            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1401            {
 41402                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1403            }
 41404            if (Client.AcceptLanguage != null)
 1405            {
 41406                if (_httpRequest.Headers.Contains("accept-language"))
 1407                {
 01408                    _httpRequest.Headers.Remove("accept-language");
 1409                }
 41410                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1411            }
 1412
 1413
 41414            if (customHeaders != null)
 1415            {
 01416                foreach(var _header in customHeaders)
 1417                {
 01418                    if (_httpRequest.Headers.Contains(_header.Key))
 1419                    {
 01420                        _httpRequest.Headers.Remove(_header.Key);
 1421                    }
 01422                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1423                }
 1424            }
 1425
 1426            // Serialize Request
 41427            string _requestContent = null;
 1428            // Set Credentials
 41429            if (Client.Credentials != null)
 1430            {
 41431                cancellationToken.ThrowIfCancellationRequested();
 41432                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1433            }
 1434            // Send Request
 41435            if (_shouldTrace)
 1436            {
 01437                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1438            }
 41439            cancellationToken.ThrowIfCancellationRequested();
 41440            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 41441            if (_shouldTrace)
 1442            {
 01443                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1444            }
 41445            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 41446            cancellationToken.ThrowIfCancellationRequested();
 41447            string _responseContent = null;
 41448            if ((int)_statusCode != 204)
 1449            {
 01450                var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status
 1451                try
 1452                {
 01453                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01454                    AcrErrors _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon
 01455                    if (_errorBody != null)
 1456                    {
 01457                        ex.Body = _errorBody;
 1458                    }
 01459                }
 01460                catch (JsonException)
 1461                {
 1462                    // Ignore the exception
 01463                }
 01464                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01465                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01466                if (_shouldTrace)
 1467                {
 01468                    ServiceClientTracing.Error(_invocationId, ex);
 1469                }
 01470                _httpRequest.Dispose();
 01471                if (_httpResponse != null)
 1472                {
 01473                    _httpResponse.Dispose();
 1474                }
 01475                throw ex;
 1476            }
 1477            // Create Result
 41478            var _result = new AzureOperationResponse();
 41479            _result.Request = _httpRequest;
 41480            _result.Response = _httpResponse;
 41481            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1482            {
 41483                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1484            }
 41485            if (_shouldTrace)
 1486            {
 01487                ServiceClientTracing.Exit(_invocationId, _result);
 1488            }
 41489            return _result;
 41490        }
 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        {
 81518            if (Client.LoginUri == null)
 1519            {
 01520                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 1521            }
 81522            if (name == null)
 1523            {
 01524                throw new ValidationException(ValidationRules.CannotBeNull, "name");
 1525            }
 1526            // Tracing
 81527            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 81528            string _invocationId = null;
 81529            if (_shouldTrace)
 1530            {
 01531                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01532                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01533                tracingParameters.Add("name", name);
 01534                tracingParameters.Add("cancellationToken", cancellationToken);
 01535                ServiceClientTracing.Enter(_invocationId, this, "StartUpload", tracingParameters);
 1536            }
 1537            // Construct URL
 81538            var _baseUrl = Client.BaseUri;
 81539            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/uploads/";
 81540            _url = _url.Replace("{url}", Client.LoginUri);
 81541            _url = _url.Replace("{name}", System.Uri.EscapeDataString(name));
 81542            List<string> _queryParameters = new List<string>();
 81543            if (_queryParameters.Count > 0)
 1544            {
 01545                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1546            }
 1547            // Create HTTP transport objects
 81548            var _httpRequest = new HttpRequestMessage();
 81549            HttpResponseMessage _httpResponse = null;
 81550            _httpRequest.Method = new HttpMethod("POST");
 81551            _httpRequest.RequestUri = new System.Uri(_url);
 1552            // Set Headers
 81553            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1554            {
 81555                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1556            }
 81557            if (Client.AcceptLanguage != null)
 1558            {
 81559                if (_httpRequest.Headers.Contains("accept-language"))
 1560                {
 01561                    _httpRequest.Headers.Remove("accept-language");
 1562                }
 81563                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1564            }
 1565
 1566
 81567            if (customHeaders != null)
 1568            {
 01569                foreach(var _header in customHeaders)
 1570                {
 01571                    if (_httpRequest.Headers.Contains(_header.Key))
 1572                    {
 01573                        _httpRequest.Headers.Remove(_header.Key);
 1574                    }
 01575                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1576                }
 1577            }
 1578
 1579            // Serialize Request
 81580            string _requestContent = null;
 1581            // Set Credentials
 81582            if (Client.Credentials != null)
 1583            {
 81584                cancellationToken.ThrowIfCancellationRequested();
 81585                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1586            }
 1587            // Send Request
 81588            if (_shouldTrace)
 1589            {
 01590                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1591            }
 81592            cancellationToken.ThrowIfCancellationRequested();
 81593            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 81594            if (_shouldTrace)
 1595            {
 01596                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1597            }
 81598            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 81599            cancellationToken.ThrowIfCancellationRequested();
 81600            string _responseContent = null;
 81601            if ((int)_statusCode != 202)
 1602            {
 01603                var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status
 1604                try
 1605                {
 01606                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01607                    AcrErrors _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon
 01608                    if (_errorBody != null)
 1609                    {
 01610                        ex.Body = _errorBody;
 1611                    }
 01612                }
 01613                catch (JsonException)
 1614                {
 1615                    // Ignore the exception
 01616                }
 01617                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01618                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01619                if (_shouldTrace)
 1620                {
 01621                    ServiceClientTracing.Error(_invocationId, ex);
 1622                }
 01623                _httpRequest.Dispose();
 01624                if (_httpResponse != null)
 1625                {
 01626                    _httpResponse.Dispose();
 1627                }
 01628                throw ex;
 1629            }
 1630            // Create Result
 81631            var _result = new AzureOperationHeaderResponse<BlobStartUploadHeaders>();
 81632            _result.Request = _httpRequest;
 81633            _result.Response = _httpResponse;
 81634            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1635            {
 81636                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1637            }
 1638            try
 1639            {
 81640                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobStartUploadHeaders>(JsonSerializer.Creat
 81641            }
 01642            catch (JsonException ex)
 1643            {
 01644                _httpRequest.Dispose();
 01645                if (_httpResponse != null)
 1646                {
 01647                    _httpResponse.Dispose();
 1648                }
 01649                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1650            }
 81651            if (_shouldTrace)
 1652            {
 01653                ServiceClientTracing.Exit(_invocationId, _result);
 1654            }
 81655            return _result;
 81656        }
 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=&lt;start&gt;-&lt;end&gt;,  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        {
 21697            if (Client.LoginUri == null)
 1698            {
 01699                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 1700            }
 21701            if (name == null)
 1702            {
 01703                throw new ValidationException(ValidationRules.CannotBeNull, "name");
 1704            }
 21705            if (digest == null)
 1706            {
 01707                throw new ValidationException(ValidationRules.CannotBeNull, "digest");
 1708            }
 21709            if (range == null)
 1710            {
 01711                throw new ValidationException(ValidationRules.CannotBeNull, "range");
 1712            }
 1713            // Tracing
 21714            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 21715            string _invocationId = null;
 21716            if (_shouldTrace)
 1717            {
 01718                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01719                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01720                tracingParameters.Add("name", name);
 01721                tracingParameters.Add("digest", digest);
 01722                tracingParameters.Add("range", range);
 01723                tracingParameters.Add("cancellationToken", cancellationToken);
 01724                ServiceClientTracing.Enter(_invocationId, this, "GetChunk", tracingParameters);
 1725            }
 1726            // Construct URL
 21727            var _baseUrl = Client.BaseUri;
 21728            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/{digest}";
 21729            _url = _url.Replace("{url}", Client.LoginUri);
 21730            _url = _url.Replace("{name}", System.Uri.EscapeDataString(name));
 21731            _url = _url.Replace("{digest}", System.Uri.EscapeDataString(digest));
 21732            List<string> _queryParameters = new List<string>();
 21733            if (_queryParameters.Count > 0)
 1734            {
 01735                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1736            }
 1737            // Create HTTP transport objects
 21738            var _httpRequest = new HttpRequestMessage();
 21739            HttpResponseMessage _httpResponse = null;
 21740            _httpRequest.Method = new HttpMethod("GET");
 21741            _httpRequest.RequestUri = new System.Uri(_url);
 1742            // Set Headers
 21743            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1744            {
 21745                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1746            }
 21747            if (range != null)
 1748            {
 21749                if (_httpRequest.Headers.Contains("Range"))
 1750                {
 01751                    _httpRequest.Headers.Remove("Range");
 1752                }
 21753                _httpRequest.Headers.TryAddWithoutValidation("Range", range);
 1754            }
 21755            if (Client.AcceptLanguage != null)
 1756            {
 21757                if (_httpRequest.Headers.Contains("accept-language"))
 1758                {
 01759                    _httpRequest.Headers.Remove("accept-language");
 1760                }
 21761                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1762            }
 1763
 1764
 21765            if (customHeaders != null)
 1766            {
 01767                foreach(var _header in customHeaders)
 1768                {
 01769                    if (_httpRequest.Headers.Contains(_header.Key))
 1770                    {
 01771                        _httpRequest.Headers.Remove(_header.Key);
 1772                    }
 01773                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1774                }
 1775            }
 1776
 1777            // Serialize Request
 21778            string _requestContent = null;
 1779            // Set Credentials
 21780            if (Client.Credentials != null)
 1781            {
 21782                cancellationToken.ThrowIfCancellationRequested();
 21783                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1784            }
 1785            // Send Request
 21786            if (_shouldTrace)
 1787            {
 01788                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1789            }
 21790            cancellationToken.ThrowIfCancellationRequested();
 21791            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons
 21792            if (_shouldTrace)
 1793            {
 01794                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1795            }
 21796            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 21797            cancellationToken.ThrowIfCancellationRequested();
 21798            string _responseContent = null;
 21799            if ((int)_statusCode != 206)
 1800            {
 01801                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 1802                try
 1803                {
 01804                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01805                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 01806                    if (_errorBody != null)
 1807                    {
 01808                        ex = new CloudException(_errorBody.Message);
 01809                        ex.Body = _errorBody;
 1810                    }
 01811                }
 01812                catch (JsonException)
 1813                {
 1814                    // Ignore the exception
 01815                }
 01816                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01817                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01818                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1819                {
 01820                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1821                }
 01822                if (_shouldTrace)
 1823                {
 01824                    ServiceClientTracing.Error(_invocationId, ex);
 1825                }
 01826                _httpRequest.Dispose();
 01827                if (_httpResponse != null)
 1828                {
 01829                    _httpResponse.Dispose();
 1830                }
 01831                throw ex;
 1832            }
 1833            // Create Result
 21834            var _result = new AzureOperationResponse<Stream,BlobGetChunkHeaders>();
 21835            _result.Request = _httpRequest;
 21836            _result.Response = _httpResponse;
 21837            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1838            {
 21839                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1840            }
 1841            // Deserialize Response
 21842            if ((int)_statusCode == 206)
 1843            {
 21844                _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
 1845            }
 1846            try
 1847            {
 21848                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobGetChunkHeaders>(JsonSerializer.Create(C
 21849            }
 01850            catch (JsonException ex)
 1851            {
 01852                _httpRequest.Dispose();
 01853                if (_httpResponse != null)
 1854                {
 01855                    _httpResponse.Dispose();
 1856                }
 01857                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1858            }
 21859            if (_shouldTrace)
 1860            {
 01861                ServiceClientTracing.Exit(_invocationId, _result);
 1862            }
 21863            return _result;
 21864        }
 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=&lt;start&gt;-&lt;end&gt;,  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        {
 21899            if (Client.LoginUri == null)
 1900            {
 01901                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
 1902            }
 21903            if (name == null)
 1904            {
 01905                throw new ValidationException(ValidationRules.CannotBeNull, "name");
 1906            }
 21907            if (digest == null)
 1908            {
 01909                throw new ValidationException(ValidationRules.CannotBeNull, "digest");
 1910            }
 21911            if (range == null)
 1912            {
 01913                throw new ValidationException(ValidationRules.CannotBeNull, "range");
 1914            }
 1915            // Tracing
 21916            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 21917            string _invocationId = null;
 21918            if (_shouldTrace)
 1919            {
 01920                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01921                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01922                tracingParameters.Add("name", name);
 01923                tracingParameters.Add("digest", digest);
 01924                tracingParameters.Add("range", range);
 01925                tracingParameters.Add("cancellationToken", cancellationToken);
 01926                ServiceClientTracing.Enter(_invocationId, this, "CheckChunk", tracingParameters);
 1927            }
 1928            // Construct URL
 21929            var _baseUrl = Client.BaseUri;
 21930            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/{name}/blobs/{digest}";
 21931            _url = _url.Replace("{url}", Client.LoginUri);
 21932            _url = _url.Replace("{name}", System.Uri.EscapeDataString(name));
 21933            _url = _url.Replace("{digest}", System.Uri.EscapeDataString(digest));
 21934            List<string> _queryParameters = new List<string>();
 21935            if (_queryParameters.Count > 0)
 1936            {
 01937                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1938            }
 1939            // Create HTTP transport objects
 21940            var _httpRequest = new HttpRequestMessage();
 21941            HttpResponseMessage _httpResponse = null;
 21942            _httpRequest.Method = new HttpMethod("HEAD");
 21943            _httpRequest.RequestUri = new System.Uri(_url);
 1944            // Set Headers
 21945            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1946            {
 21947                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1948            }
 21949            if (range != null)
 1950            {
 21951                if (_httpRequest.Headers.Contains("Range"))
 1952                {
 01953                    _httpRequest.Headers.Remove("Range");
 1954                }
 21955                _httpRequest.Headers.TryAddWithoutValidation("Range", range);
 1956            }
 21957            if (Client.AcceptLanguage != null)
 1958            {
 21959                if (_httpRequest.Headers.Contains("accept-language"))
 1960                {
 01961                    _httpRequest.Headers.Remove("accept-language");
 1962                }
 21963                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1964            }
 1965
 1966
 21967            if (customHeaders != null)
 1968            {
 01969                foreach(var _header in customHeaders)
 1970                {
 01971                    if (_httpRequest.Headers.Contains(_header.Key))
 1972                    {
 01973                        _httpRequest.Headers.Remove(_header.Key);
 1974                    }
 01975                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1976                }
 1977            }
 1978
 1979            // Serialize Request
 21980            string _requestContent = null;
 1981            // Set Credentials
 21982            if (Client.Credentials != null)
 1983            {
 21984                cancellationToken.ThrowIfCancellationRequested();
 21985                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1986            }
 1987            // Send Request
 21988            if (_shouldTrace)
 1989            {
 01990                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1991            }
 21992            cancellationToken.ThrowIfCancellationRequested();
 21993            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons
 21994            if (_shouldTrace)
 1995            {
 01996                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1997            }
 21998            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 21999            cancellationToken.ThrowIfCancellationRequested();
 22000            string _responseContent = null;
 22001            if ((int)_statusCode != 200)
 2002            {
 02003                var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status
 2004                try
 2005                {
 02006                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02007                    AcrErrors _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon
 02008                    if (_errorBody != null)
 2009                    {
 02010                        ex.Body = _errorBody;
 2011                    }
 02012                }
 02013                catch (JsonException)
 2014                {
 2015                    // Ignore the exception
 02016                }
 02017                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02018                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02019                if (_shouldTrace)
 2020                {
 02021                    ServiceClientTracing.Error(_invocationId, ex);
 2022                }
 02023                _httpRequest.Dispose();
 02024                if (_httpResponse != null)
 2025                {
 02026                    _httpResponse.Dispose();
 2027                }
 02028                throw ex;
 2029            }
 2030            // Create Result
 22031            var _result = new AzureOperationHeaderResponse<BlobCheckChunkHeaders>();
 22032            _result.Request = _httpRequest;
 22033            _result.Response = _httpResponse;
 22034            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2035            {
 22036                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2037            }
 2038            try
 2039            {
 22040                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BlobCheckChunkHeaders>(JsonSerializer.Create
 22041            }
 02042            catch (JsonException ex)
 2043            {
 02044                _httpRequest.Dispose();
 02045                if (_httpResponse != null)
 2046                {
 02047                    _httpResponse.Dispose();
 2048                }
 02049                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 2050            }
 22051            if (_shouldTrace)
 2052            {
 02053                ServiceClientTracing.Exit(_invocationId, _result);
 2054            }
 22055            return _result;
 22056        }
 2057
 2058    }
 2059}