< Summary

Class:Microsoft.Azure.CognitiveServices.Vision.Face.SnapshotOperations
Assembly:Microsoft.Azure.CognitiveServices.Vision.Face
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\SnapshotOperations.cs
Covered lines:165
Uncovered lines:358
Coverable lines:523
Total lines:1258
Line coverage:31.5% (165 of 523)
Covered branches:67
Total branches:264
Branch coverage:25.3% (67 of 264)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
TakeWithHttpMessagesAsync()-55.68%48.08%
ListWithHttpMessagesAsync()-0%0%
GetWithHttpMessagesAsync()-0%0%
UpdateWithHttpMessagesAsync()-0%0%
DeleteWithHttpMessagesAsync()-51.67%35.71%
ApplyWithHttpMessagesAsync()-54.22%45.24%
GetOperationStatusWithHttpMessagesAsync()-50.72%37.5%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\SnapshotOperations.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.CognitiveServices.Vision.Face
 12{
 13    using Microsoft.Rest;
 14    using Models;
 15    using Newtonsoft.Json;
 16    using System.Collections;
 17    using System.Collections.Generic;
 18    using System.IO;
 19    using System.Linq;
 20    using System.Net;
 21    using System.Net.Http;
 22    using System.Threading;
 23    using System.Threading.Tasks;
 24
 25    /// <summary>
 26    /// SnapshotOperations operations.
 27    /// </summary>
 28    public partial class SnapshotOperations : IServiceOperations<FaceClient>, ISnapshotOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the SnapshotOperations class.
 32        /// </summary>
 33        /// <param name='client'>
 34        /// Reference to the service client.
 35        /// </param>
 36        /// <exception cref="System.ArgumentNullException">
 37        /// Thrown when a required parameter is null
 38        /// </exception>
 3439        public SnapshotOperations(FaceClient client)
 40        {
 3441            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 3445            Client = client;
 3446        }
 47
 48        /// <summary>
 49        /// Gets a reference to the FaceClient
 50        /// </summary>
 48251        public FaceClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Submit an operation to take a snapshot of face list, large face list,
 55        /// person group or large person group, with user-specified snapshot type,
 56        /// source object id, apply scope and an optional user data.&lt;br /&gt;
 57        /// The snapshot interfaces are for users to backup and restore their face data
 58        /// from one face subscription to another, inside same region or across
 59        /// regions. The workflow contains two phases, user first calls Snapshot - Take
 60        /// to create a copy of the source object and store it as a snapshot, then
 61        /// calls Snapshot - Apply to paste the snapshot to target subscription. The
 62        /// snapshots are stored in a centralized location (per Azure instance), so
 63        /// that they can be applied cross accounts and regions.&lt;br /&gt;
 64        /// Taking snapshot is an asynchronous operation. An operation id can be
 65        /// obtained from the "Operation-Location" field in response header, to be used
 66        /// in OperationStatus - Get for tracking the progress of creating the
 67        /// snapshot. The snapshot id will be included in the "resourceLocation" field
 68        /// in OperationStatus - Get response when the operation status is
 69        /// "succeeded".&lt;br /&gt;
 70        /// Snapshot taking time depends on the number of person and face entries in
 71        /// the source object. It could be in seconds, or up to several hours for
 72        /// 1,000,000 persons with multiple faces.&lt;br /&gt;
 73        /// Snapshots will be automatically expired and cleaned in 48 hours after it is
 74        /// created by Snapshot - Take. User can delete the snapshot using Snapshot -
 75        /// Delete by themselves any time before expiration.&lt;br /&gt;
 76        /// Taking snapshot for a certain object will not block any other operations
 77        /// against the object. All read-only operations (Get/List and
 78        /// Identify/FindSimilar/Verify) can be conducted as usual. For all writable
 79        /// operations, including Add/Update/Delete the source object or its
 80        /// persons/faces and Train, they are not blocked but not recommended because
 81        /// writable updates may not be reflected on the snapshot during its taking.
 82        /// After snapshot taking is completed, all readable and writable operations
 83        /// can work as normal. Snapshot will also include the training results of the
 84        /// source object, which means target subscription the snapshot applied to does
 85        /// not need re-train the target object before calling
 86        /// Identify/FindSimilar.&lt;br /&gt;
 87        /// * Free-tier subscription quota: 100 take operations per month.
 88        /// * S0-tier subscription quota: 100 take operations per day.
 89        /// </summary>
 90        /// <param name='type'>
 91        /// User specified type for the source object to take snapshot from. Currently
 92        /// FaceList, PersonGroup, LargeFaceList and LargePersonGroup are supported.
 93        /// Possible values include: 'FaceList', 'LargeFaceList', 'LargePersonGroup',
 94        /// 'PersonGroup'
 95        /// </param>
 96        /// <param name='objectId'>
 97        /// User specified source object id to take snapshot from.
 98        /// </param>
 99        /// <param name='applyScope'>
 100        /// User specified array of target Face subscription ids for the snapshot. For
 101        /// each snapshot, only subscriptions included in the applyScope of Snapshot -
 102        /// Take can apply it.
 103        /// </param>
 104        /// <param name='userData'>
 105        /// User specified data about the snapshot for any purpose. Length should not
 106        /// exceed 16KB.
 107        /// </param>
 108        /// <param name='customHeaders'>
 109        /// Headers that will be added to request.
 110        /// </param>
 111        /// <param name='cancellationToken'>
 112        /// The cancellation token.
 113        /// </param>
 114        /// <exception cref="APIErrorException">
 115        /// Thrown when the operation returned an invalid status code
 116        /// </exception>
 117        /// <exception cref="ValidationException">
 118        /// Thrown when a required parameter is null
 119        /// </exception>
 120        /// <exception cref="System.ArgumentNullException">
 121        /// Thrown when a required parameter is null
 122        /// </exception>
 123        /// <return>
 124        /// A response object containing the response body and response headers.
 125        /// </return>
 126        public async Task<HttpOperationHeaderResponse<SnapshotTakeHeaders>> TakeWithHttpMessagesAsync(SnapshotObjectType
 127        {
 8128            if (Client.Endpoint == null)
 129            {
 0130                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 131            }
 8132            if (objectId == null)
 133            {
 0134                throw new ValidationException(ValidationRules.CannotBeNull, "objectId");
 135            }
 8136            if (objectId != null)
 137            {
 8138                if (objectId.Length > 64)
 139                {
 0140                    throw new ValidationException(ValidationRules.MaxLength, "objectId", 64);
 141                }
 8142                if (!System.Text.RegularExpressions.Regex.IsMatch(objectId, "^[a-z0-9-_]+$"))
 143                {
 0144                    throw new ValidationException(ValidationRules.Pattern, "objectId", "^[a-z0-9-_]+$");
 145                }
 146            }
 8147            if (applyScope == null)
 148            {
 0149                throw new ValidationException(ValidationRules.CannotBeNull, "applyScope");
 150            }
 8151            if (userData != null)
 152            {
 8153                if (userData.Length > 16384)
 154                {
 0155                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 156                }
 157            }
 8158            TakeSnapshotRequest body = new TakeSnapshotRequest();
 8159            if (objectId != null || applyScope != null || userData != null)
 160            {
 8161                body.Type = type;
 8162                body.ObjectId = objectId;
 8163                body.ApplyScope = applyScope;
 8164                body.UserData = userData;
 165            }
 166            // Tracing
 8167            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 8168            string _invocationId = null;
 8169            if (_shouldTrace)
 170            {
 0171                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0172                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0173                tracingParameters.Add("body", body);
 0174                tracingParameters.Add("cancellationToken", cancellationToken);
 0175                ServiceClientTracing.Enter(_invocationId, this, "Take", tracingParameters);
 176            }
 177            // Construct URL
 8178            var _baseUrl = Client.BaseUri;
 8179            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "snapshots";
 8180            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 181            // Create HTTP transport objects
 8182            var _httpRequest = new HttpRequestMessage();
 8183            HttpResponseMessage _httpResponse = null;
 8184            _httpRequest.Method = new HttpMethod("POST");
 8185            _httpRequest.RequestUri = new System.Uri(_url);
 186            // Set Headers
 187
 188
 8189            if (customHeaders != null)
 190            {
 0191                foreach(var _header in customHeaders)
 192                {
 0193                    if (_httpRequest.Headers.Contains(_header.Key))
 194                    {
 0195                        _httpRequest.Headers.Remove(_header.Key);
 196                    }
 0197                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 198                }
 199            }
 200
 201            // Serialize Request
 8202            string _requestContent = null;
 8203            if(body != null)
 204            {
 8205                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 8206                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 8207                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 208            }
 209            // Set Credentials
 8210            if (Client.Credentials != null)
 211            {
 8212                cancellationToken.ThrowIfCancellationRequested();
 8213                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 214            }
 215            // Send Request
 8216            if (_shouldTrace)
 217            {
 0218                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 219            }
 8220            cancellationToken.ThrowIfCancellationRequested();
 8221            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 8222            if (_shouldTrace)
 223            {
 0224                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 225            }
 8226            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 8227            cancellationToken.ThrowIfCancellationRequested();
 8228            string _responseContent = null;
 8229            if ((int)_statusCode != 202)
 230            {
 0231                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 232                try
 233                {
 0234                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0235                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0236                    if (_errorBody != null)
 237                    {
 0238                        ex.Body = _errorBody;
 239                    }
 0240                }
 0241                catch (JsonException)
 242                {
 243                    // Ignore the exception
 0244                }
 0245                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0246                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0247                if (_shouldTrace)
 248                {
 0249                    ServiceClientTracing.Error(_invocationId, ex);
 250                }
 0251                _httpRequest.Dispose();
 0252                if (_httpResponse != null)
 253                {
 0254                    _httpResponse.Dispose();
 255                }
 0256                throw ex;
 257            }
 258            // Create Result
 8259            var _result = new HttpOperationHeaderResponse<SnapshotTakeHeaders>();
 8260            _result.Request = _httpRequest;
 8261            _result.Response = _httpResponse;
 262            try
 263            {
 8264                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<SnapshotTakeHeaders>(JsonSerializer.Create(C
 8265            }
 0266            catch (JsonException ex)
 267            {
 0268                _httpRequest.Dispose();
 0269                if (_httpResponse != null)
 270                {
 0271                    _httpResponse.Dispose();
 272                }
 0273                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 274            }
 8275            if (_shouldTrace)
 276            {
 0277                ServiceClientTracing.Exit(_invocationId, _result);
 278            }
 8279            return _result;
 8280        }
 281
 282        /// <summary>
 283        /// List all accessible snapshots with related information, including snapshots
 284        /// that were taken by the user, or snapshots to be applied to the user
 285        /// (subscription id was included in the applyScope in Snapshot - Take).
 286        /// </summary>
 287        /// <param name='type'>
 288        /// User specified object type as a search filter. Possible values include:
 289        /// 'FaceList', 'LargeFaceList', 'LargePersonGroup', 'PersonGroup'
 290        /// </param>
 291        /// <param name='applyScope'>
 292        /// User specified snapshot apply scopes as a search filter. ApplyScope is an
 293        /// array of the target Azure subscription ids for the snapshot, specified by
 294        /// the user who created the snapshot by Snapshot - Take.
 295        /// </param>
 296        /// <param name='customHeaders'>
 297        /// Headers that will be added to request.
 298        /// </param>
 299        /// <param name='cancellationToken'>
 300        /// The cancellation token.
 301        /// </param>
 302        /// <exception cref="APIErrorException">
 303        /// Thrown when the operation returned an invalid status code
 304        /// </exception>
 305        /// <exception cref="SerializationException">
 306        /// Thrown when unable to deserialize the response
 307        /// </exception>
 308        /// <exception cref="ValidationException">
 309        /// Thrown when a required parameter is null
 310        /// </exception>
 311        /// <exception cref="System.ArgumentNullException">
 312        /// Thrown when a required parameter is null
 313        /// </exception>
 314        /// <return>
 315        /// A response object containing the response body and response headers.
 316        /// </return>
 317        public async Task<HttpOperationResponse<IList<Snapshot>>> ListWithHttpMessagesAsync(SnapshotObjectType? type = d
 318        {
 0319            if (Client.Endpoint == null)
 320            {
 0321                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 322            }
 323            // Tracing
 0324            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0325            string _invocationId = null;
 0326            if (_shouldTrace)
 327            {
 0328                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0329                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0330                tracingParameters.Add("type", type);
 0331                tracingParameters.Add("applyScope", applyScope);
 0332                tracingParameters.Add("cancellationToken", cancellationToken);
 0333                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 334            }
 335            // Construct URL
 0336            var _baseUrl = Client.BaseUri;
 0337            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "snapshots";
 0338            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0339            List<string> _queryParameters = new List<string>();
 0340            if (type != null)
 341            {
 0342                _queryParameters.Add(string.Format("type={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 343            }
 0344            if (applyScope != null)
 345            {
 0346                _queryParameters.Add(string.Format("applyScope={0}", System.Uri.EscapeDataString(string.Join(",", applyS
 347            }
 0348            if (_queryParameters.Count > 0)
 349            {
 0350                _url += "?" + string.Join("&", _queryParameters);
 351            }
 352            // Create HTTP transport objects
 0353            var _httpRequest = new HttpRequestMessage();
 0354            HttpResponseMessage _httpResponse = null;
 0355            _httpRequest.Method = new HttpMethod("GET");
 0356            _httpRequest.RequestUri = new System.Uri(_url);
 357            // Set Headers
 358
 359
 0360            if (customHeaders != null)
 361            {
 0362                foreach(var _header in customHeaders)
 363                {
 0364                    if (_httpRequest.Headers.Contains(_header.Key))
 365                    {
 0366                        _httpRequest.Headers.Remove(_header.Key);
 367                    }
 0368                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 369                }
 370            }
 371
 372            // Serialize Request
 0373            string _requestContent = null;
 374            // Set Credentials
 0375            if (Client.Credentials != null)
 376            {
 0377                cancellationToken.ThrowIfCancellationRequested();
 0378                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 379            }
 380            // Send Request
 0381            if (_shouldTrace)
 382            {
 0383                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 384            }
 0385            cancellationToken.ThrowIfCancellationRequested();
 0386            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0387            if (_shouldTrace)
 388            {
 0389                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 390            }
 0391            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0392            cancellationToken.ThrowIfCancellationRequested();
 0393            string _responseContent = null;
 0394            if ((int)_statusCode != 200)
 395            {
 0396                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 397                try
 398                {
 0399                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0400                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0401                    if (_errorBody != null)
 402                    {
 0403                        ex.Body = _errorBody;
 404                    }
 0405                }
 0406                catch (JsonException)
 407                {
 408                    // Ignore the exception
 0409                }
 0410                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0411                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0412                if (_shouldTrace)
 413                {
 0414                    ServiceClientTracing.Error(_invocationId, ex);
 415                }
 0416                _httpRequest.Dispose();
 0417                if (_httpResponse != null)
 418                {
 0419                    _httpResponse.Dispose();
 420                }
 0421                throw ex;
 422            }
 423            // Create Result
 0424            var _result = new HttpOperationResponse<IList<Snapshot>>();
 0425            _result.Request = _httpRequest;
 0426            _result.Response = _httpResponse;
 427            // Deserialize Response
 0428            if ((int)_statusCode == 200)
 429            {
 0430                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 431                try
 432                {
 0433                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<Snapshot>>(_responseConten
 0434                }
 0435                catch (JsonException ex)
 436                {
 0437                    _httpRequest.Dispose();
 0438                    if (_httpResponse != null)
 439                    {
 0440                        _httpResponse.Dispose();
 441                    }
 0442                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 443                }
 444            }
 0445            if (_shouldTrace)
 446            {
 0447                ServiceClientTracing.Exit(_invocationId, _result);
 448            }
 0449            return _result;
 0450        }
 451
 452        /// <summary>
 453        /// Retrieve information about a snapshot. Snapshot is only accessible to the
 454        /// source subscription who took it, and target subscriptions included in the
 455        /// applyScope in Snapshot - Take.
 456        /// </summary>
 457        /// <param name='snapshotId'>
 458        /// Id referencing a particular snapshot.
 459        /// </param>
 460        /// <param name='customHeaders'>
 461        /// Headers that will be added to request.
 462        /// </param>
 463        /// <param name='cancellationToken'>
 464        /// The cancellation token.
 465        /// </param>
 466        /// <exception cref="APIErrorException">
 467        /// Thrown when the operation returned an invalid status code
 468        /// </exception>
 469        /// <exception cref="SerializationException">
 470        /// Thrown when unable to deserialize the response
 471        /// </exception>
 472        /// <exception cref="ValidationException">
 473        /// Thrown when a required parameter is null
 474        /// </exception>
 475        /// <exception cref="System.ArgumentNullException">
 476        /// Thrown when a required parameter is null
 477        /// </exception>
 478        /// <return>
 479        /// A response object containing the response body and response headers.
 480        /// </return>
 481        public async Task<HttpOperationResponse<Snapshot>> GetWithHttpMessagesAsync(System.Guid snapshotId, Dictionary<s
 482        {
 0483            if (Client.Endpoint == null)
 484            {
 0485                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 486            }
 487            // Tracing
 0488            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0489            string _invocationId = null;
 0490            if (_shouldTrace)
 491            {
 0492                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0493                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0494                tracingParameters.Add("snapshotId", snapshotId);
 0495                tracingParameters.Add("cancellationToken", cancellationToken);
 0496                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 497            }
 498            // Construct URL
 0499            var _baseUrl = Client.BaseUri;
 0500            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "snapshots/{snapshotId}";
 0501            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0502            _url = _url.Replace("{snapshotId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Serialize
 503            // Create HTTP transport objects
 0504            var _httpRequest = new HttpRequestMessage();
 0505            HttpResponseMessage _httpResponse = null;
 0506            _httpRequest.Method = new HttpMethod("GET");
 0507            _httpRequest.RequestUri = new System.Uri(_url);
 508            // Set Headers
 509
 510
 0511            if (customHeaders != null)
 512            {
 0513                foreach(var _header in customHeaders)
 514                {
 0515                    if (_httpRequest.Headers.Contains(_header.Key))
 516                    {
 0517                        _httpRequest.Headers.Remove(_header.Key);
 518                    }
 0519                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 520                }
 521            }
 522
 523            // Serialize Request
 0524            string _requestContent = null;
 525            // Set Credentials
 0526            if (Client.Credentials != null)
 527            {
 0528                cancellationToken.ThrowIfCancellationRequested();
 0529                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 530            }
 531            // Send Request
 0532            if (_shouldTrace)
 533            {
 0534                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 535            }
 0536            cancellationToken.ThrowIfCancellationRequested();
 0537            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0538            if (_shouldTrace)
 539            {
 0540                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 541            }
 0542            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0543            cancellationToken.ThrowIfCancellationRequested();
 0544            string _responseContent = null;
 0545            if ((int)_statusCode != 200)
 546            {
 0547                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 548                try
 549                {
 0550                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0551                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0552                    if (_errorBody != null)
 553                    {
 0554                        ex.Body = _errorBody;
 555                    }
 0556                }
 0557                catch (JsonException)
 558                {
 559                    // Ignore the exception
 0560                }
 0561                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0562                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0563                if (_shouldTrace)
 564                {
 0565                    ServiceClientTracing.Error(_invocationId, ex);
 566                }
 0567                _httpRequest.Dispose();
 0568                if (_httpResponse != null)
 569                {
 0570                    _httpResponse.Dispose();
 571                }
 0572                throw ex;
 573            }
 574            // Create Result
 0575            var _result = new HttpOperationResponse<Snapshot>();
 0576            _result.Request = _httpRequest;
 0577            _result.Response = _httpResponse;
 578            // Deserialize Response
 0579            if ((int)_statusCode == 200)
 580            {
 0581                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 582                try
 583                {
 0584                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Snapshot>(_responseContent, Clie
 0585                }
 0586                catch (JsonException ex)
 587                {
 0588                    _httpRequest.Dispose();
 0589                    if (_httpResponse != null)
 590                    {
 0591                        _httpResponse.Dispose();
 592                    }
 0593                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 594                }
 595            }
 0596            if (_shouldTrace)
 597            {
 0598                ServiceClientTracing.Exit(_invocationId, _result);
 599            }
 0600            return _result;
 0601        }
 602
 603        /// <summary>
 604        /// Update the information of a snapshot. Only the source subscription who took
 605        /// the snapshot can update the snapshot.
 606        /// </summary>
 607        /// <param name='snapshotId'>
 608        /// Id referencing a particular snapshot.
 609        /// </param>
 610        /// <param name='applyScope'>
 611        /// Array of the target Face subscription ids for the snapshot, specified by
 612        /// the user who created the snapshot when calling Snapshot - Take. For each
 613        /// snapshot, only subscriptions included in the applyScope of Snapshot - Take
 614        /// can apply it.
 615        /// </param>
 616        /// <param name='userData'>
 617        /// User specified data about the snapshot for any purpose. Length should not
 618        /// exceed 16KB.
 619        /// </param>
 620        /// <param name='customHeaders'>
 621        /// Headers that will be added to request.
 622        /// </param>
 623        /// <param name='cancellationToken'>
 624        /// The cancellation token.
 625        /// </param>
 626        /// <exception cref="APIErrorException">
 627        /// Thrown when the operation returned an invalid status code
 628        /// </exception>
 629        /// <exception cref="ValidationException">
 630        /// Thrown when a required parameter is null
 631        /// </exception>
 632        /// <exception cref="System.ArgumentNullException">
 633        /// Thrown when a required parameter is null
 634        /// </exception>
 635        /// <return>
 636        /// A response object containing the response body and response headers.
 637        /// </return>
 638        public async Task<HttpOperationResponse> UpdateWithHttpMessagesAsync(System.Guid snapshotId, IList<System.Guid> 
 639        {
 0640            if (Client.Endpoint == null)
 641            {
 0642                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 643            }
 0644            if (userData != null)
 645            {
 0646                if (userData.Length > 16384)
 647                {
 0648                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 649                }
 650            }
 0651            UpdateSnapshotRequest body = new UpdateSnapshotRequest();
 0652            if (applyScope != null || userData != null)
 653            {
 0654                body.ApplyScope = applyScope;
 0655                body.UserData = userData;
 656            }
 657            // Tracing
 0658            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0659            string _invocationId = null;
 0660            if (_shouldTrace)
 661            {
 0662                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0663                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0664                tracingParameters.Add("snapshotId", snapshotId);
 0665                tracingParameters.Add("body", body);
 0666                tracingParameters.Add("cancellationToken", cancellationToken);
 0667                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
 668            }
 669            // Construct URL
 0670            var _baseUrl = Client.BaseUri;
 0671            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "snapshots/{snapshotId}";
 0672            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0673            _url = _url.Replace("{snapshotId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Serialize
 674            // Create HTTP transport objects
 0675            var _httpRequest = new HttpRequestMessage();
 0676            HttpResponseMessage _httpResponse = null;
 0677            _httpRequest.Method = new HttpMethod("PATCH");
 0678            _httpRequest.RequestUri = new System.Uri(_url);
 679            // Set Headers
 680
 681
 0682            if (customHeaders != null)
 683            {
 0684                foreach(var _header in customHeaders)
 685                {
 0686                    if (_httpRequest.Headers.Contains(_header.Key))
 687                    {
 0688                        _httpRequest.Headers.Remove(_header.Key);
 689                    }
 0690                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 691                }
 692            }
 693
 694            // Serialize Request
 0695            string _requestContent = null;
 0696            if(body != null)
 697            {
 0698                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 0699                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0700                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 701            }
 702            // Set Credentials
 0703            if (Client.Credentials != null)
 704            {
 0705                cancellationToken.ThrowIfCancellationRequested();
 0706                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 707            }
 708            // Send Request
 0709            if (_shouldTrace)
 710            {
 0711                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 712            }
 0713            cancellationToken.ThrowIfCancellationRequested();
 0714            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0715            if (_shouldTrace)
 716            {
 0717                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 718            }
 0719            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0720            cancellationToken.ThrowIfCancellationRequested();
 0721            string _responseContent = null;
 0722            if ((int)_statusCode != 200)
 723            {
 0724                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 725                try
 726                {
 0727                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0728                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0729                    if (_errorBody != null)
 730                    {
 0731                        ex.Body = _errorBody;
 732                    }
 0733                }
 0734                catch (JsonException)
 735                {
 736                    // Ignore the exception
 0737                }
 0738                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0739                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0740                if (_shouldTrace)
 741                {
 0742                    ServiceClientTracing.Error(_invocationId, ex);
 743                }
 0744                _httpRequest.Dispose();
 0745                if (_httpResponse != null)
 746                {
 0747                    _httpResponse.Dispose();
 748                }
 0749                throw ex;
 750            }
 751            // Create Result
 0752            var _result = new HttpOperationResponse();
 0753            _result.Request = _httpRequest;
 0754            _result.Response = _httpResponse;
 0755            if (_shouldTrace)
 756            {
 0757                ServiceClientTracing.Exit(_invocationId, _result);
 758            }
 0759            return _result;
 0760        }
 761
 762        /// <summary>
 763        /// Delete an existing snapshot according to the snapshotId. All object data
 764        /// and information in the snapshot will also be deleted. Only the source
 765        /// subscription who took the snapshot can delete the snapshot. If the user
 766        /// does not delete a snapshot with this API, the snapshot will still be
 767        /// automatically deleted in 48 hours after creation.
 768        /// </summary>
 769        /// <param name='snapshotId'>
 770        /// Id referencing a particular snapshot.
 771        /// </param>
 772        /// <param name='customHeaders'>
 773        /// Headers that will be added to request.
 774        /// </param>
 775        /// <param name='cancellationToken'>
 776        /// The cancellation token.
 777        /// </param>
 778        /// <exception cref="APIErrorException">
 779        /// Thrown when the operation returned an invalid status code
 780        /// </exception>
 781        /// <exception cref="ValidationException">
 782        /// Thrown when a required parameter is null
 783        /// </exception>
 784        /// <exception cref="System.ArgumentNullException">
 785        /// Thrown when a required parameter is null
 786        /// </exception>
 787        /// <return>
 788        /// A response object containing the response body and response headers.
 789        /// </return>
 790        public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(System.Guid snapshotId, Dictionary<string, 
 791        {
 8792            if (Client.Endpoint == null)
 793            {
 0794                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 795            }
 796            // Tracing
 8797            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 8798            string _invocationId = null;
 8799            if (_shouldTrace)
 800            {
 0801                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0802                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0803                tracingParameters.Add("snapshotId", snapshotId);
 0804                tracingParameters.Add("cancellationToken", cancellationToken);
 0805                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 806            }
 807            // Construct URL
 8808            var _baseUrl = Client.BaseUri;
 8809            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "snapshots/{snapshotId}";
 8810            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 8811            _url = _url.Replace("{snapshotId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Serialize
 812            // Create HTTP transport objects
 8813            var _httpRequest = new HttpRequestMessage();
 8814            HttpResponseMessage _httpResponse = null;
 8815            _httpRequest.Method = new HttpMethod("DELETE");
 8816            _httpRequest.RequestUri = new System.Uri(_url);
 817            // Set Headers
 818
 819
 8820            if (customHeaders != null)
 821            {
 0822                foreach(var _header in customHeaders)
 823                {
 0824                    if (_httpRequest.Headers.Contains(_header.Key))
 825                    {
 0826                        _httpRequest.Headers.Remove(_header.Key);
 827                    }
 0828                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 829                }
 830            }
 831
 832            // Serialize Request
 8833            string _requestContent = null;
 834            // Set Credentials
 8835            if (Client.Credentials != null)
 836            {
 8837                cancellationToken.ThrowIfCancellationRequested();
 8838                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 839            }
 840            // Send Request
 8841            if (_shouldTrace)
 842            {
 0843                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 844            }
 8845            cancellationToken.ThrowIfCancellationRequested();
 8846            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 8847            if (_shouldTrace)
 848            {
 0849                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 850            }
 8851            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 8852            cancellationToken.ThrowIfCancellationRequested();
 8853            string _responseContent = null;
 8854            if ((int)_statusCode != 200)
 855            {
 0856                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 857                try
 858                {
 0859                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0860                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0861                    if (_errorBody != null)
 862                    {
 0863                        ex.Body = _errorBody;
 864                    }
 0865                }
 0866                catch (JsonException)
 867                {
 868                    // Ignore the exception
 0869                }
 0870                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0871                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0872                if (_shouldTrace)
 873                {
 0874                    ServiceClientTracing.Error(_invocationId, ex);
 875                }
 0876                _httpRequest.Dispose();
 0877                if (_httpResponse != null)
 878                {
 0879                    _httpResponse.Dispose();
 880                }
 0881                throw ex;
 882            }
 883            // Create Result
 8884            var _result = new HttpOperationResponse();
 8885            _result.Request = _httpRequest;
 8886            _result.Response = _httpResponse;
 8887            if (_shouldTrace)
 888            {
 0889                ServiceClientTracing.Exit(_invocationId, _result);
 890            }
 8891            return _result;
 8892        }
 893
 894        /// <summary>
 895        /// Submit an operation to apply a snapshot to current subscription. For each
 896        /// snapshot, only subscriptions included in the applyScope of Snapshot - Take
 897        /// can apply it.&lt;br /&gt;
 898        /// The snapshot interfaces are for users to backup and restore their face data
 899        /// from one face subscription to another, inside same region or across
 900        /// regions. The workflow contains two phases, user first calls Snapshot - Take
 901        /// to create a copy of the source object and store it as a snapshot, then
 902        /// calls Snapshot - Apply to paste the snapshot to target subscription. The
 903        /// snapshots are stored in a centralized location (per Azure instance), so
 904        /// that they can be applied cross accounts and regions.&lt;br /&gt;
 905        /// Applying snapshot is an asynchronous operation. An operation id can be
 906        /// obtained from the "Operation-Location" field in response header, to be used
 907        /// in OperationStatus - Get for tracking the progress of applying the
 908        /// snapshot. The target object id will be included in the "resourceLocation"
 909        /// field in OperationStatus - Get response when the operation status is
 910        /// "succeeded".&lt;br /&gt;
 911        /// Snapshot applying time depends on the number of person and face entries in
 912        /// the snapshot object. It could be in seconds, or up to 1 hour for 1,000,000
 913        /// persons with multiple faces.&lt;br /&gt;
 914        /// Snapshots will be automatically expired and cleaned in 48 hours after it is
 915        /// created by Snapshot - Take. So the target subscription is required to apply
 916        /// the snapshot in 48 hours since its creation.&lt;br /&gt;
 917        /// Applying a snapshot will not block any other operations against the target
 918        /// object, however it is not recommended because the correctness cannot be
 919        /// guaranteed during snapshot applying. After snapshot applying is completed,
 920        /// all operations towards the target object can work as normal. Snapshot also
 921        /// includes the training results of the source object, which means target
 922        /// subscription the snapshot applied to does not need re-train the target
 923        /// object before calling Identify/FindSimilar.&lt;br /&gt;
 924        /// One snapshot can be applied multiple times in parallel, while currently
 925        /// only CreateNew apply mode is supported, which means the apply operation
 926        /// will fail if target subscription already contains an object of same type
 927        /// and using the same objectId. Users can specify the "objectId" in request
 928        /// body to avoid such conflicts.&lt;br /&gt;
 929        /// * Free-tier subscription quota: 100 apply operations per month.
 930        /// * S0-tier subscription quota: 100 apply operations per day.
 931        /// </summary>
 932        /// <param name='snapshotId'>
 933        /// Id referencing a particular snapshot.
 934        /// </param>
 935        /// <param name='objectId'>
 936        /// User specified target object id to be created from the snapshot.
 937        /// </param>
 938        /// <param name='mode'>
 939        /// Snapshot applying mode. Currently only CreateNew is supported, which means
 940        /// the apply operation will fail if target subscription already contains an
 941        /// object of same type and using the same objectId. Users can specify the
 942        /// "objectId" in request body to avoid such conflicts. Possible values
 943        /// include: 'CreateNew'
 944        /// </param>
 945        /// <param name='customHeaders'>
 946        /// Headers that will be added to request.
 947        /// </param>
 948        /// <param name='cancellationToken'>
 949        /// The cancellation token.
 950        /// </param>
 951        /// <exception cref="APIErrorException">
 952        /// Thrown when the operation returned an invalid status code
 953        /// </exception>
 954        /// <exception cref="ValidationException">
 955        /// Thrown when a required parameter is null
 956        /// </exception>
 957        /// <exception cref="System.ArgumentNullException">
 958        /// Thrown when a required parameter is null
 959        /// </exception>
 960        /// <return>
 961        /// A response object containing the response body and response headers.
 962        /// </return>
 963        public async Task<HttpOperationHeaderResponse<SnapshotApplyHeaders>> ApplyWithHttpMessagesAsync(System.Guid snap
 964        {
 8965            if (Client.Endpoint == null)
 966            {
 0967                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 968            }
 8969            if (objectId == null)
 970            {
 0971                throw new ValidationException(ValidationRules.CannotBeNull, "objectId");
 972            }
 8973            if (objectId != null)
 974            {
 8975                if (objectId.Length > 64)
 976                {
 0977                    throw new ValidationException(ValidationRules.MaxLength, "objectId", 64);
 978                }
 8979                if (!System.Text.RegularExpressions.Regex.IsMatch(objectId, "^[a-z0-9-_]+$"))
 980                {
 0981                    throw new ValidationException(ValidationRules.Pattern, "objectId", "^[a-z0-9-_]+$");
 982                }
 983            }
 8984            ApplySnapshotRequest body = new ApplySnapshotRequest();
 8985            if (objectId != null)
 986            {
 8987                body.ObjectId = objectId;
 8988                body.Mode = mode;
 989            }
 990            // Tracing
 8991            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 8992            string _invocationId = null;
 8993            if (_shouldTrace)
 994            {
 0995                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0996                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0997                tracingParameters.Add("snapshotId", snapshotId);
 0998                tracingParameters.Add("body", body);
 0999                tracingParameters.Add("cancellationToken", cancellationToken);
 01000                ServiceClientTracing.Enter(_invocationId, this, "Apply", tracingParameters);
 1001            }
 1002            // Construct URL
 81003            var _baseUrl = Client.BaseUri;
 81004            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "snapshots/{snapshotId}/apply";
 81005            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 81006            _url = _url.Replace("{snapshotId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Serialize
 1007            // Create HTTP transport objects
 81008            var _httpRequest = new HttpRequestMessage();
 81009            HttpResponseMessage _httpResponse = null;
 81010            _httpRequest.Method = new HttpMethod("POST");
 81011            _httpRequest.RequestUri = new System.Uri(_url);
 1012            // Set Headers
 1013
 1014
 81015            if (customHeaders != null)
 1016            {
 01017                foreach(var _header in customHeaders)
 1018                {
 01019                    if (_httpRequest.Headers.Contains(_header.Key))
 1020                    {
 01021                        _httpRequest.Headers.Remove(_header.Key);
 1022                    }
 01023                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1024                }
 1025            }
 1026
 1027            // Serialize Request
 81028            string _requestContent = null;
 81029            if(body != null)
 1030            {
 81031                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 81032                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 81033                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1034            }
 1035            // Set Credentials
 81036            if (Client.Credentials != null)
 1037            {
 81038                cancellationToken.ThrowIfCancellationRequested();
 81039                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1040            }
 1041            // Send Request
 81042            if (_shouldTrace)
 1043            {
 01044                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1045            }
 81046            cancellationToken.ThrowIfCancellationRequested();
 81047            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 81048            if (_shouldTrace)
 1049            {
 01050                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1051            }
 81052            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 81053            cancellationToken.ThrowIfCancellationRequested();
 81054            string _responseContent = null;
 81055            if ((int)_statusCode != 202)
 1056            {
 01057                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1058                try
 1059                {
 01060                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01061                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01062                    if (_errorBody != null)
 1063                    {
 01064                        ex.Body = _errorBody;
 1065                    }
 01066                }
 01067                catch (JsonException)
 1068                {
 1069                    // Ignore the exception
 01070                }
 01071                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01072                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01073                if (_shouldTrace)
 1074                {
 01075                    ServiceClientTracing.Error(_invocationId, ex);
 1076                }
 01077                _httpRequest.Dispose();
 01078                if (_httpResponse != null)
 1079                {
 01080                    _httpResponse.Dispose();
 1081                }
 01082                throw ex;
 1083            }
 1084            // Create Result
 81085            var _result = new HttpOperationHeaderResponse<SnapshotApplyHeaders>();
 81086            _result.Request = _httpRequest;
 81087            _result.Response = _httpResponse;
 1088            try
 1089            {
 81090                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<SnapshotApplyHeaders>(JsonSerializer.Create(
 81091            }
 01092            catch (JsonException ex)
 1093            {
 01094                _httpRequest.Dispose();
 01095                if (_httpResponse != null)
 1096                {
 01097                    _httpResponse.Dispose();
 1098                }
 01099                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1100            }
 81101            if (_shouldTrace)
 1102            {
 01103                ServiceClientTracing.Exit(_invocationId, _result);
 1104            }
 81105            return _result;
 81106        }
 1107
 1108        /// <summary>
 1109        /// Retrieve the status of a take/apply snapshot operation.
 1110        /// </summary>
 1111        /// <param name='operationId'>
 1112        /// Id referencing a particular take/apply snapshot operation.
 1113        /// </param>
 1114        /// <param name='customHeaders'>
 1115        /// Headers that will be added to request.
 1116        /// </param>
 1117        /// <param name='cancellationToken'>
 1118        /// The cancellation token.
 1119        /// </param>
 1120        /// <exception cref="APIErrorException">
 1121        /// Thrown when the operation returned an invalid status code
 1122        /// </exception>
 1123        /// <exception cref="SerializationException">
 1124        /// Thrown when unable to deserialize the response
 1125        /// </exception>
 1126        /// <exception cref="ValidationException">
 1127        /// Thrown when a required parameter is null
 1128        /// </exception>
 1129        /// <exception cref="System.ArgumentNullException">
 1130        /// Thrown when a required parameter is null
 1131        /// </exception>
 1132        /// <return>
 1133        /// A response object containing the response body and response headers.
 1134        /// </return>
 1135        public async Task<HttpOperationResponse<OperationStatus>> GetOperationStatusWithHttpMessagesAsync(System.Guid op
 1136        {
 321137            if (Client.Endpoint == null)
 1138            {
 01139                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1140            }
 1141            // Tracing
 321142            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 321143            string _invocationId = null;
 321144            if (_shouldTrace)
 1145            {
 01146                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01147                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01148                tracingParameters.Add("operationId", operationId);
 01149                tracingParameters.Add("cancellationToken", cancellationToken);
 01150                ServiceClientTracing.Enter(_invocationId, this, "GetOperationStatus", tracingParameters);
 1151            }
 1152            // Construct URL
 321153            var _baseUrl = Client.BaseUri;
 321154            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "operations/{operationId}";
 321155            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 321156            _url = _url.Replace("{operationId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Serializ
 1157            // Create HTTP transport objects
 321158            var _httpRequest = new HttpRequestMessage();
 321159            HttpResponseMessage _httpResponse = null;
 321160            _httpRequest.Method = new HttpMethod("GET");
 321161            _httpRequest.RequestUri = new System.Uri(_url);
 1162            // Set Headers
 1163
 1164
 321165            if (customHeaders != null)
 1166            {
 01167                foreach(var _header in customHeaders)
 1168                {
 01169                    if (_httpRequest.Headers.Contains(_header.Key))
 1170                    {
 01171                        _httpRequest.Headers.Remove(_header.Key);
 1172                    }
 01173                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1174                }
 1175            }
 1176
 1177            // Serialize Request
 321178            string _requestContent = null;
 1179            // Set Credentials
 321180            if (Client.Credentials != null)
 1181            {
 321182                cancellationToken.ThrowIfCancellationRequested();
 321183                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1184            }
 1185            // Send Request
 321186            if (_shouldTrace)
 1187            {
 01188                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1189            }
 321190            cancellationToken.ThrowIfCancellationRequested();
 321191            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 321192            if (_shouldTrace)
 1193            {
 01194                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1195            }
 321196            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 321197            cancellationToken.ThrowIfCancellationRequested();
 321198            string _responseContent = null;
 321199            if ((int)_statusCode != 200)
 1200            {
 01201                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1202                try
 1203                {
 01204                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01205                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01206                    if (_errorBody != null)
 1207                    {
 01208                        ex.Body = _errorBody;
 1209                    }
 01210                }
 01211                catch (JsonException)
 1212                {
 1213                    // Ignore the exception
 01214                }
 01215                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01216                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01217                if (_shouldTrace)
 1218                {
 01219                    ServiceClientTracing.Error(_invocationId, ex);
 1220                }
 01221                _httpRequest.Dispose();
 01222                if (_httpResponse != null)
 1223                {
 01224                    _httpResponse.Dispose();
 1225                }
 01226                throw ex;
 1227            }
 1228            // Create Result
 321229            var _result = new HttpOperationResponse<OperationStatus>();
 321230            _result.Request = _httpRequest;
 321231            _result.Response = _httpResponse;
 1232            // Deserialize Response
 321233            if ((int)_statusCode == 200)
 1234            {
 321235                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1236                try
 1237                {
 321238                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten
 321239                }
 01240                catch (JsonException ex)
 1241                {
 01242                    _httpRequest.Dispose();
 01243                    if (_httpResponse != null)
 1244                    {
 01245                        _httpResponse.Dispose();
 1246                    }
 01247                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1248                }
 1249            }
 321250            if (_shouldTrace)
 1251            {
 01252                ServiceClientTracing.Exit(_invocationId, _result);
 1253            }
 321254            return _result;
 321255        }
 1256
 1257    }
 1258}