< Summary

Class:Microsoft.Azure.CognitiveServices.Vision.Face.LargeFaceListOperations
Assembly:Microsoft.Azure.CognitiveServices.Vision.Face
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\LargeFaceListOperations.cs
Covered lines:304
Uncovered lines:748
Coverable lines:1052
Total lines:2489
Line coverage:28.8% (304 of 1052)
Covered branches:150
Total branches:584
Branch coverage:25.6% (150 of 584)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
CreateWithHttpMessagesAsync()-57.83%51.92%
GetWithHttpMessagesAsync()-53.66%47.73%
UpdateWithHttpMessagesAsync()-0%0%
DeleteWithHttpMessagesAsync()-52.24%41.67%
GetTrainingStatusWithHttpMessagesAsync()-51.32%42.5%
ListWithHttpMessagesAsync()-0%0%
TrainWithHttpMessagesAsync()-52.24%41.67%
DeleteFaceWithHttpMessagesAsync()-0%0%
GetFaceWithHttpMessagesAsync()-0%0%
UpdateFaceWithHttpMessagesAsync()-0%0%
AddFaceFromUrlWithHttpMessagesAsync()-0%0%
ListFacesWithHttpMessagesAsync()-50.56%44%
AddFaceFromStreamWithHttpMessagesAsync()-53.54%53.33%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\LargeFaceListOperations.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    /// LargeFaceListOperations operations.
 27    /// </summary>
 28    public partial class LargeFaceListOperations : IServiceOperations<FaceClient>, ILargeFaceListOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the LargeFaceListOperations 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 LargeFaceListOperations(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>
 30651        public FaceClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Create an empty large face list with user-specified largeFaceListId, name,
 55        /// an optional userData and recognitionModel.
 56        /// &lt;br /&gt; Large face list is a list of faces, up to 1,000,000 faces, and
 57        /// used by [Face - Find
 58        /// Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237).
 59        /// &lt;br /&gt; After creation, user should use [LargeFaceList Face -
 60        /// Add](/docs/services/563879b61984550e40cbbe8d/operations/5a158c10d2de3616c086f2d3)
 61        /// to import the faces and [LargeFaceList -
 62        /// Train](/docs/services/563879b61984550e40cbbe8d/operations/5a158422d2de3616c086f2d1)
 63        /// to make it ready for [Face - Find
 64        /// Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237).
 65        /// No image will be stored. Only the extracted face features are stored on
 66        /// server until [LargeFaceList -
 67        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/5a1580d5d2de3616c086f2cd)
 68        /// is called.
 69        /// &lt;br /&gt; Find Similar is used for scenario like finding celebrity-like
 70        /// faces, similar face filtering, or as a light way face identification. But
 71        /// if the actual use is to identify person, please use
 72        /// [PersonGroup](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395244)
 73        /// /
 74        /// [LargePersonGroup](/docs/services/563879b61984550e40cbbe8d/operations/599acdee6ac60f11b48b5a9d)
 75        /// and [Face -
 76        /// Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239).
 77        /// &lt;br/&gt;'recognitionModel' should be specified to associate with this
 78        /// large face list. The default value for 'recognitionModel' is
 79        /// 'recognition_01', if the latest model needed, please explicitly specify the
 80        /// model you need in this parameter. New faces that are added to an existing
 81        /// large face list will use the recognition model that's already associated
 82        /// with the collection. Existing face features in a large face list can't be
 83        /// updated to features extracted by another version of recognition model.
 84        /// * 'recognition_01': The default recognition model for [LargeFaceList-
 85        /// Create](/docs/services/563879b61984550e40cbbe8d/operations/5a157b68d2de3616c086f2cc).
 86        /// All those large face lists created before 2019 March are bonded with this
 87        /// recognition model.
 88        /// * 'recognition_02': Recognition model released in 2019 March.
 89        /// 'recognition_02' is recommended since its overall accuracy is improved
 90        /// compared with 'recognition_01'.
 91        ///
 92        /// Large face list quota:
 93        /// * Free-tier subscription quota: 64 large face lists.
 94        /// * S0-tier subscription quota: 1,000,000 large face lists.
 95        /// </summary>
 96        /// <param name='largeFaceListId'>
 97        /// Id referencing a particular large face list.
 98        /// </param>
 99        /// <param name='name'>
 100        /// User defined name, maximum length is 128.
 101        /// </param>
 102        /// <param name='userData'>
 103        /// User specified data. Length should not exceed 16KB.
 104        /// </param>
 105        /// <param name='recognitionModel'>
 106        /// Possible values include: 'recognition_01', 'recognition_02'
 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<HttpOperationResponse> CreateWithHttpMessagesAsync(string largeFaceListId, string name = defau
 127        {
 4128            if (Client.Endpoint == null)
 129            {
 0130                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 131            }
 4132            if (largeFaceListId == null)
 133            {
 0134                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 135            }
 4136            if (largeFaceListId != null)
 137            {
 4138                if (largeFaceListId.Length > 64)
 139                {
 0140                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 141                }
 4142                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 143                {
 0144                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 145                }
 146            }
 4147            if (name != null)
 148            {
 4149                if (name.Length > 128)
 150                {
 0151                    throw new ValidationException(ValidationRules.MaxLength, "name", 128);
 152                }
 153            }
 4154            if (userData != null)
 155            {
 2156                if (userData.Length > 16384)
 157                {
 0158                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 159                }
 160            }
 4161            MetaDataContract body = new MetaDataContract();
 4162            if (name != null || userData != null || recognitionModel != null)
 163            {
 4164                body.Name = name;
 4165                body.UserData = userData;
 4166                body.RecognitionModel = recognitionModel;
 167            }
 168            // Tracing
 4169            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 4170            string _invocationId = null;
 4171            if (_shouldTrace)
 172            {
 0173                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0174                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0175                tracingParameters.Add("largeFaceListId", largeFaceListId);
 0176                tracingParameters.Add("body", body);
 0177                tracingParameters.Add("cancellationToken", cancellationToken);
 0178                ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters);
 179            }
 180            // Construct URL
 4181            var _baseUrl = Client.BaseUri;
 4182            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}";
 4183            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 4184            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 185            // Create HTTP transport objects
 4186            var _httpRequest = new HttpRequestMessage();
 4187            HttpResponseMessage _httpResponse = null;
 4188            _httpRequest.Method = new HttpMethod("PUT");
 4189            _httpRequest.RequestUri = new System.Uri(_url);
 190            // Set Headers
 191
 192
 4193            if (customHeaders != null)
 194            {
 0195                foreach(var _header in customHeaders)
 196                {
 0197                    if (_httpRequest.Headers.Contains(_header.Key))
 198                    {
 0199                        _httpRequest.Headers.Remove(_header.Key);
 200                    }
 0201                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 202                }
 203            }
 204
 205            // Serialize Request
 4206            string _requestContent = null;
 4207            if(body != null)
 208            {
 4209                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 4210                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 4211                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 212            }
 213            // Set Credentials
 4214            if (Client.Credentials != null)
 215            {
 4216                cancellationToken.ThrowIfCancellationRequested();
 4217                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 218            }
 219            // Send Request
 4220            if (_shouldTrace)
 221            {
 0222                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 223            }
 4224            cancellationToken.ThrowIfCancellationRequested();
 4225            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4226            if (_shouldTrace)
 227            {
 0228                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 229            }
 4230            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 4231            cancellationToken.ThrowIfCancellationRequested();
 4232            string _responseContent = null;
 4233            if ((int)_statusCode != 200)
 234            {
 0235                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 236                try
 237                {
 0238                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0239                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0240                    if (_errorBody != null)
 241                    {
 0242                        ex.Body = _errorBody;
 243                    }
 0244                }
 0245                catch (JsonException)
 246                {
 247                    // Ignore the exception
 0248                }
 0249                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0250                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0251                if (_shouldTrace)
 252                {
 0253                    ServiceClientTracing.Error(_invocationId, ex);
 254                }
 0255                _httpRequest.Dispose();
 0256                if (_httpResponse != null)
 257                {
 0258                    _httpResponse.Dispose();
 259                }
 0260                throw ex;
 261            }
 262            // Create Result
 4263            var _result = new HttpOperationResponse();
 4264            _result.Request = _httpRequest;
 4265            _result.Response = _httpResponse;
 4266            if (_shouldTrace)
 267            {
 0268                ServiceClientTracing.Exit(_invocationId, _result);
 269            }
 4270            return _result;
 4271        }
 272
 273        /// <summary>
 274        /// Retrieve a large face list’s largeFaceListId, name, userData and
 275        /// recognitionModel.
 276        /// </summary>
 277        /// <param name='largeFaceListId'>
 278        /// Id referencing a particular large face list.
 279        /// </param>
 280        /// <param name='returnRecognitionModel'>
 281        /// A value indicating whether the operation should return 'recognitionModel'
 282        /// in response.
 283        /// </param>
 284        /// <param name='customHeaders'>
 285        /// Headers that will be added to request.
 286        /// </param>
 287        /// <param name='cancellationToken'>
 288        /// The cancellation token.
 289        /// </param>
 290        /// <exception cref="APIErrorException">
 291        /// Thrown when the operation returned an invalid status code
 292        /// </exception>
 293        /// <exception cref="SerializationException">
 294        /// Thrown when unable to deserialize the response
 295        /// </exception>
 296        /// <exception cref="ValidationException">
 297        /// Thrown when a required parameter is null
 298        /// </exception>
 299        /// <exception cref="System.ArgumentNullException">
 300        /// Thrown when a required parameter is null
 301        /// </exception>
 302        /// <return>
 303        /// A response object containing the response body and response headers.
 304        /// </return>
 305        public async Task<HttpOperationResponse<LargeFaceList>> GetWithHttpMessagesAsync(string largeFaceListId, bool? r
 306        {
 2307            if (Client.Endpoint == null)
 308            {
 0309                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 310            }
 2311            if (largeFaceListId == null)
 312            {
 0313                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 314            }
 2315            if (largeFaceListId != null)
 316            {
 2317                if (largeFaceListId.Length > 64)
 318                {
 0319                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 320                }
 2321                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 322                {
 0323                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 324                }
 325            }
 326            // Tracing
 2327            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2328            string _invocationId = null;
 2329            if (_shouldTrace)
 330            {
 0331                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0332                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0333                tracingParameters.Add("largeFaceListId", largeFaceListId);
 0334                tracingParameters.Add("returnRecognitionModel", returnRecognitionModel);
 0335                tracingParameters.Add("cancellationToken", cancellationToken);
 0336                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 337            }
 338            // Construct URL
 2339            var _baseUrl = Client.BaseUri;
 2340            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}";
 2341            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 2342            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 2343            List<string> _queryParameters = new List<string>();
 2344            if (returnRecognitionModel != null)
 345            {
 2346                _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial
 347            }
 2348            if (_queryParameters.Count > 0)
 349            {
 2350                _url += "?" + string.Join("&", _queryParameters);
 351            }
 352            // Create HTTP transport objects
 2353            var _httpRequest = new HttpRequestMessage();
 2354            HttpResponseMessage _httpResponse = null;
 2355            _httpRequest.Method = new HttpMethod("GET");
 2356            _httpRequest.RequestUri = new System.Uri(_url);
 357            // Set Headers
 358
 359
 2360            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
 2373            string _requestContent = null;
 374            // Set Credentials
 2375            if (Client.Credentials != null)
 376            {
 2377                cancellationToken.ThrowIfCancellationRequested();
 2378                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 379            }
 380            // Send Request
 2381            if (_shouldTrace)
 382            {
 0383                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 384            }
 2385            cancellationToken.ThrowIfCancellationRequested();
 2386            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2387            if (_shouldTrace)
 388            {
 0389                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 390            }
 2391            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2392            cancellationToken.ThrowIfCancellationRequested();
 2393            string _responseContent = null;
 2394            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
 2424            var _result = new HttpOperationResponse<LargeFaceList>();
 2425            _result.Request = _httpRequest;
 2426            _result.Response = _httpResponse;
 427            // Deserialize Response
 2428            if ((int)_statusCode == 200)
 429            {
 2430                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 431                try
 432                {
 2433                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<LargeFaceList>(_responseContent,
 2434                }
 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            }
 2445            if (_shouldTrace)
 446            {
 0447                ServiceClientTracing.Exit(_invocationId, _result);
 448            }
 2449            return _result;
 2450        }
 451
 452        /// <summary>
 453        /// Update information of a large face list.
 454        /// </summary>
 455        /// <param name='largeFaceListId'>
 456        /// Id referencing a particular large face list.
 457        /// </param>
 458        /// <param name='name'>
 459        /// User defined name, maximum length is 128.
 460        /// </param>
 461        /// <param name='userData'>
 462        /// User specified data. Length should not exceed 16KB.
 463        /// </param>
 464        /// <param name='customHeaders'>
 465        /// Headers that will be added to request.
 466        /// </param>
 467        /// <param name='cancellationToken'>
 468        /// The cancellation token.
 469        /// </param>
 470        /// <exception cref="APIErrorException">
 471        /// Thrown when the operation returned an invalid status code
 472        /// </exception>
 473        /// <exception cref="ValidationException">
 474        /// Thrown when a required parameter is null
 475        /// </exception>
 476        /// <exception cref="System.ArgumentNullException">
 477        /// Thrown when a required parameter is null
 478        /// </exception>
 479        /// <return>
 480        /// A response object containing the response body and response headers.
 481        /// </return>
 482        public async Task<HttpOperationResponse> UpdateWithHttpMessagesAsync(string largeFaceListId, string name = defau
 483        {
 0484            if (Client.Endpoint == null)
 485            {
 0486                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 487            }
 0488            if (largeFaceListId == null)
 489            {
 0490                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 491            }
 0492            if (largeFaceListId != null)
 493            {
 0494                if (largeFaceListId.Length > 64)
 495                {
 0496                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 497                }
 0498                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 499                {
 0500                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 501                }
 502            }
 0503            if (name != null)
 504            {
 0505                if (name.Length > 128)
 506                {
 0507                    throw new ValidationException(ValidationRules.MaxLength, "name", 128);
 508                }
 509            }
 0510            if (userData != null)
 511            {
 0512                if (userData.Length > 16384)
 513                {
 0514                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 515                }
 516            }
 0517            NameAndUserDataContract body = new NameAndUserDataContract();
 0518            if (name != null || userData != null)
 519            {
 0520                body.Name = name;
 0521                body.UserData = userData;
 522            }
 523            // Tracing
 0524            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0525            string _invocationId = null;
 0526            if (_shouldTrace)
 527            {
 0528                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0529                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0530                tracingParameters.Add("largeFaceListId", largeFaceListId);
 0531                tracingParameters.Add("body", body);
 0532                tracingParameters.Add("cancellationToken", cancellationToken);
 0533                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
 534            }
 535            // Construct URL
 0536            var _baseUrl = Client.BaseUri;
 0537            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}";
 0538            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0539            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 540            // Create HTTP transport objects
 0541            var _httpRequest = new HttpRequestMessage();
 0542            HttpResponseMessage _httpResponse = null;
 0543            _httpRequest.Method = new HttpMethod("PATCH");
 0544            _httpRequest.RequestUri = new System.Uri(_url);
 545            // Set Headers
 546
 547
 0548            if (customHeaders != null)
 549            {
 0550                foreach(var _header in customHeaders)
 551                {
 0552                    if (_httpRequest.Headers.Contains(_header.Key))
 553                    {
 0554                        _httpRequest.Headers.Remove(_header.Key);
 555                    }
 0556                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 557                }
 558            }
 559
 560            // Serialize Request
 0561            string _requestContent = null;
 0562            if(body != null)
 563            {
 0564                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 0565                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0566                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 567            }
 568            // Set Credentials
 0569            if (Client.Credentials != null)
 570            {
 0571                cancellationToken.ThrowIfCancellationRequested();
 0572                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 573            }
 574            // Send Request
 0575            if (_shouldTrace)
 576            {
 0577                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 578            }
 0579            cancellationToken.ThrowIfCancellationRequested();
 0580            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0581            if (_shouldTrace)
 582            {
 0583                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 584            }
 0585            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0586            cancellationToken.ThrowIfCancellationRequested();
 0587            string _responseContent = null;
 0588            if ((int)_statusCode != 200)
 589            {
 0590                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 591                try
 592                {
 0593                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0594                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0595                    if (_errorBody != null)
 596                    {
 0597                        ex.Body = _errorBody;
 598                    }
 0599                }
 0600                catch (JsonException)
 601                {
 602                    // Ignore the exception
 0603                }
 0604                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0605                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0606                if (_shouldTrace)
 607                {
 0608                    ServiceClientTracing.Error(_invocationId, ex);
 609                }
 0610                _httpRequest.Dispose();
 0611                if (_httpResponse != null)
 612                {
 0613                    _httpResponse.Dispose();
 614                }
 0615                throw ex;
 616            }
 617            // Create Result
 0618            var _result = new HttpOperationResponse();
 0619            _result.Request = _httpRequest;
 0620            _result.Response = _httpResponse;
 0621            if (_shouldTrace)
 622            {
 0623                ServiceClientTracing.Exit(_invocationId, _result);
 624            }
 0625            return _result;
 0626        }
 627
 628        /// <summary>
 629        /// Delete a specified large face list.
 630        /// </summary>
 631        /// <param name='largeFaceListId'>
 632        /// Id referencing a particular large face list.
 633        /// </param>
 634        /// <param name='customHeaders'>
 635        /// Headers that will be added to request.
 636        /// </param>
 637        /// <param name='cancellationToken'>
 638        /// The cancellation token.
 639        /// </param>
 640        /// <exception cref="APIErrorException">
 641        /// Thrown when the operation returned an invalid status code
 642        /// </exception>
 643        /// <exception cref="ValidationException">
 644        /// Thrown when a required parameter is null
 645        /// </exception>
 646        /// <exception cref="System.ArgumentNullException">
 647        /// Thrown when a required parameter is null
 648        /// </exception>
 649        /// <return>
 650        /// A response object containing the response body and response headers.
 651        /// </return>
 652        public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(string largeFaceListId, Dictionary<string, 
 653        {
 6654            if (Client.Endpoint == null)
 655            {
 0656                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 657            }
 6658            if (largeFaceListId == null)
 659            {
 0660                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 661            }
 6662            if (largeFaceListId != null)
 663            {
 6664                if (largeFaceListId.Length > 64)
 665                {
 0666                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 667                }
 6668                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 669                {
 0670                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 671                }
 672            }
 673            // Tracing
 6674            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 6675            string _invocationId = null;
 6676            if (_shouldTrace)
 677            {
 0678                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0679                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0680                tracingParameters.Add("largeFaceListId", largeFaceListId);
 0681                tracingParameters.Add("cancellationToken", cancellationToken);
 0682                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 683            }
 684            // Construct URL
 6685            var _baseUrl = Client.BaseUri;
 6686            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}";
 6687            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 6688            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 689            // Create HTTP transport objects
 6690            var _httpRequest = new HttpRequestMessage();
 6691            HttpResponseMessage _httpResponse = null;
 6692            _httpRequest.Method = new HttpMethod("DELETE");
 6693            _httpRequest.RequestUri = new System.Uri(_url);
 694            // Set Headers
 695
 696
 6697            if (customHeaders != null)
 698            {
 0699                foreach(var _header in customHeaders)
 700                {
 0701                    if (_httpRequest.Headers.Contains(_header.Key))
 702                    {
 0703                        _httpRequest.Headers.Remove(_header.Key);
 704                    }
 0705                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 706                }
 707            }
 708
 709            // Serialize Request
 6710            string _requestContent = null;
 711            // Set Credentials
 6712            if (Client.Credentials != null)
 713            {
 6714                cancellationToken.ThrowIfCancellationRequested();
 6715                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 716            }
 717            // Send Request
 6718            if (_shouldTrace)
 719            {
 0720                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 721            }
 6722            cancellationToken.ThrowIfCancellationRequested();
 6723            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 6724            if (_shouldTrace)
 725            {
 0726                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 727            }
 6728            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 6729            cancellationToken.ThrowIfCancellationRequested();
 6730            string _responseContent = null;
 6731            if ((int)_statusCode != 200)
 732            {
 0733                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 734                try
 735                {
 0736                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0737                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0738                    if (_errorBody != null)
 739                    {
 0740                        ex.Body = _errorBody;
 741                    }
 0742                }
 0743                catch (JsonException)
 744                {
 745                    // Ignore the exception
 0746                }
 0747                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0748                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0749                if (_shouldTrace)
 750                {
 0751                    ServiceClientTracing.Error(_invocationId, ex);
 752                }
 0753                _httpRequest.Dispose();
 0754                if (_httpResponse != null)
 755                {
 0756                    _httpResponse.Dispose();
 757                }
 0758                throw ex;
 759            }
 760            // Create Result
 6761            var _result = new HttpOperationResponse();
 6762            _result.Request = _httpRequest;
 6763            _result.Response = _httpResponse;
 6764            if (_shouldTrace)
 765            {
 0766                ServiceClientTracing.Exit(_invocationId, _result);
 767            }
 6768            return _result;
 6769        }
 770
 771        /// <summary>
 772        /// Retrieve the training status of a large face list (completed or ongoing).
 773        /// </summary>
 774        /// <param name='largeFaceListId'>
 775        /// Id referencing a particular large face list.
 776        /// </param>
 777        /// <param name='customHeaders'>
 778        /// Headers that will be added to request.
 779        /// </param>
 780        /// <param name='cancellationToken'>
 781        /// The cancellation token.
 782        /// </param>
 783        /// <exception cref="APIErrorException">
 784        /// Thrown when the operation returned an invalid status code
 785        /// </exception>
 786        /// <exception cref="SerializationException">
 787        /// Thrown when unable to deserialize the response
 788        /// </exception>
 789        /// <exception cref="ValidationException">
 790        /// Thrown when a required parameter is null
 791        /// </exception>
 792        /// <exception cref="System.ArgumentNullException">
 793        /// Thrown when a required parameter is null
 794        /// </exception>
 795        /// <return>
 796        /// A response object containing the response body and response headers.
 797        /// </return>
 798        public async Task<HttpOperationResponse<TrainingStatus>> GetTrainingStatusWithHttpMessagesAsync(string largeFace
 799        {
 8800            if (Client.Endpoint == null)
 801            {
 0802                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 803            }
 8804            if (largeFaceListId == null)
 805            {
 0806                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 807            }
 8808            if (largeFaceListId != null)
 809            {
 8810                if (largeFaceListId.Length > 64)
 811                {
 0812                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 813                }
 8814                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 815                {
 0816                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 817                }
 818            }
 819            // Tracing
 8820            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 8821            string _invocationId = null;
 8822            if (_shouldTrace)
 823            {
 0824                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0825                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0826                tracingParameters.Add("largeFaceListId", largeFaceListId);
 0827                tracingParameters.Add("cancellationToken", cancellationToken);
 0828                ServiceClientTracing.Enter(_invocationId, this, "GetTrainingStatus", tracingParameters);
 829            }
 830            // Construct URL
 8831            var _baseUrl = Client.BaseUri;
 8832            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/training";
 8833            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 8834            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 835            // Create HTTP transport objects
 8836            var _httpRequest = new HttpRequestMessage();
 8837            HttpResponseMessage _httpResponse = null;
 8838            _httpRequest.Method = new HttpMethod("GET");
 8839            _httpRequest.RequestUri = new System.Uri(_url);
 840            // Set Headers
 841
 842
 8843            if (customHeaders != null)
 844            {
 0845                foreach(var _header in customHeaders)
 846                {
 0847                    if (_httpRequest.Headers.Contains(_header.Key))
 848                    {
 0849                        _httpRequest.Headers.Remove(_header.Key);
 850                    }
 0851                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 852                }
 853            }
 854
 855            // Serialize Request
 8856            string _requestContent = null;
 857            // Set Credentials
 8858            if (Client.Credentials != null)
 859            {
 8860                cancellationToken.ThrowIfCancellationRequested();
 8861                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 862            }
 863            // Send Request
 8864            if (_shouldTrace)
 865            {
 0866                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 867            }
 8868            cancellationToken.ThrowIfCancellationRequested();
 8869            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 8870            if (_shouldTrace)
 871            {
 0872                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 873            }
 8874            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 8875            cancellationToken.ThrowIfCancellationRequested();
 8876            string _responseContent = null;
 8877            if ((int)_statusCode != 200)
 878            {
 0879                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 880                try
 881                {
 0882                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0883                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0884                    if (_errorBody != null)
 885                    {
 0886                        ex.Body = _errorBody;
 887                    }
 0888                }
 0889                catch (JsonException)
 890                {
 891                    // Ignore the exception
 0892                }
 0893                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0894                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0895                if (_shouldTrace)
 896                {
 0897                    ServiceClientTracing.Error(_invocationId, ex);
 898                }
 0899                _httpRequest.Dispose();
 0900                if (_httpResponse != null)
 901                {
 0902                    _httpResponse.Dispose();
 903                }
 0904                throw ex;
 905            }
 906            // Create Result
 8907            var _result = new HttpOperationResponse<TrainingStatus>();
 8908            _result.Request = _httpRequest;
 8909            _result.Response = _httpResponse;
 910            // Deserialize Response
 8911            if ((int)_statusCode == 200)
 912            {
 8913                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 914                try
 915                {
 8916                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<TrainingStatus>(_responseContent
 8917                }
 0918                catch (JsonException ex)
 919                {
 0920                    _httpRequest.Dispose();
 0921                    if (_httpResponse != null)
 922                    {
 0923                        _httpResponse.Dispose();
 924                    }
 0925                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 926                }
 927            }
 8928            if (_shouldTrace)
 929            {
 0930                ServiceClientTracing.Exit(_invocationId, _result);
 931            }
 8932            return _result;
 8933        }
 934
 935        /// <summary>
 936        /// List large face lists’ information of largeFaceListId, name, userData and
 937        /// recognitionModel. &lt;br /&gt;
 938        /// To get face information inside largeFaceList use [LargeFaceList Face -
 939        /// Get](/docs/services/563879b61984550e40cbbe8d/operations/5a158cf2d2de3616c086f2d5)&lt;br
 940        /// /&gt;
 941        /// * Large face lists are stored in alphabetical order of largeFaceListId.
 942        /// * "start" parameter (string, optional) is a user-provided largeFaceListId
 943        /// value that returned entries have larger ids by string comparison. "start"
 944        /// set to empty to indicate return from the first item.
 945        /// * "top" parameter (int, optional) specifies the number of entries to
 946        /// return. A maximal of 1000 entries can be returned in one call. To fetch
 947        /// more, you can specify "start" with the last returned entry’s Id of the
 948        /// current call.
 949        /// &lt;br /&gt;
 950        /// For example, total 5 large person lists: "list1", ..., "list5".
 951        /// &lt;br /&gt; "start=&amp;top=" will return all 5 lists.
 952        /// &lt;br /&gt; "start=&amp;top=2" will return "list1", "list2".
 953        /// &lt;br /&gt; "start=list2&amp;top=3" will return "list3", "list4", "list5".
 954        ///
 955        /// </summary>
 956        /// <param name='returnRecognitionModel'>
 957        /// A value indicating whether the operation should return 'recognitionModel'
 958        /// in response.
 959        /// </param>
 960        /// <param name='customHeaders'>
 961        /// Headers that will be added to request.
 962        /// </param>
 963        /// <param name='cancellationToken'>
 964        /// The cancellation token.
 965        /// </param>
 966        /// <exception cref="APIErrorException">
 967        /// Thrown when the operation returned an invalid status code
 968        /// </exception>
 969        /// <exception cref="SerializationException">
 970        /// Thrown when unable to deserialize the response
 971        /// </exception>
 972        /// <exception cref="ValidationException">
 973        /// Thrown when a required parameter is null
 974        /// </exception>
 975        /// <exception cref="System.ArgumentNullException">
 976        /// Thrown when a required parameter is null
 977        /// </exception>
 978        /// <return>
 979        /// A response object containing the response body and response headers.
 980        /// </return>
 981        public async Task<HttpOperationResponse<IList<LargeFaceList>>> ListWithHttpMessagesAsync(bool? returnRecognition
 982        {
 0983            if (Client.Endpoint == null)
 984            {
 0985                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 986            }
 987            // Tracing
 0988            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0989            string _invocationId = null;
 0990            if (_shouldTrace)
 991            {
 0992                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0993                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0994                tracingParameters.Add("returnRecognitionModel", returnRecognitionModel);
 0995                tracingParameters.Add("cancellationToken", cancellationToken);
 0996                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 997            }
 998            // Construct URL
 0999            var _baseUrl = Client.BaseUri;
 01000            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists";
 01001            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01002            List<string> _queryParameters = new List<string>();
 01003            if (returnRecognitionModel != null)
 1004            {
 01005                _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial
 1006            }
 01007            if (_queryParameters.Count > 0)
 1008            {
 01009                _url += "?" + string.Join("&", _queryParameters);
 1010            }
 1011            // Create HTTP transport objects
 01012            var _httpRequest = new HttpRequestMessage();
 01013            HttpResponseMessage _httpResponse = null;
 01014            _httpRequest.Method = new HttpMethod("GET");
 01015            _httpRequest.RequestUri = new System.Uri(_url);
 1016            // Set Headers
 1017
 1018
 01019            if (customHeaders != null)
 1020            {
 01021                foreach(var _header in customHeaders)
 1022                {
 01023                    if (_httpRequest.Headers.Contains(_header.Key))
 1024                    {
 01025                        _httpRequest.Headers.Remove(_header.Key);
 1026                    }
 01027                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1028                }
 1029            }
 1030
 1031            // Serialize Request
 01032            string _requestContent = null;
 1033            // Set Credentials
 01034            if (Client.Credentials != null)
 1035            {
 01036                cancellationToken.ThrowIfCancellationRequested();
 01037                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1038            }
 1039            // Send Request
 01040            if (_shouldTrace)
 1041            {
 01042                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1043            }
 01044            cancellationToken.ThrowIfCancellationRequested();
 01045            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01046            if (_shouldTrace)
 1047            {
 01048                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1049            }
 01050            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01051            cancellationToken.ThrowIfCancellationRequested();
 01052            string _responseContent = null;
 01053            if ((int)_statusCode != 200)
 1054            {
 01055                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1056                try
 1057                {
 01058                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01059                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01060                    if (_errorBody != null)
 1061                    {
 01062                        ex.Body = _errorBody;
 1063                    }
 01064                }
 01065                catch (JsonException)
 1066                {
 1067                    // Ignore the exception
 01068                }
 01069                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01070                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01071                if (_shouldTrace)
 1072                {
 01073                    ServiceClientTracing.Error(_invocationId, ex);
 1074                }
 01075                _httpRequest.Dispose();
 01076                if (_httpResponse != null)
 1077                {
 01078                    _httpResponse.Dispose();
 1079                }
 01080                throw ex;
 1081            }
 1082            // Create Result
 01083            var _result = new HttpOperationResponse<IList<LargeFaceList>>();
 01084            _result.Request = _httpRequest;
 01085            _result.Response = _httpResponse;
 1086            // Deserialize Response
 01087            if ((int)_statusCode == 200)
 1088            {
 01089                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1090                try
 1091                {
 01092                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<LargeFaceList>>(_responseC
 01093                }
 01094                catch (JsonException ex)
 1095                {
 01096                    _httpRequest.Dispose();
 01097                    if (_httpResponse != null)
 1098                    {
 01099                        _httpResponse.Dispose();
 1100                    }
 01101                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1102                }
 1103            }
 01104            if (_shouldTrace)
 1105            {
 01106                ServiceClientTracing.Exit(_invocationId, _result);
 1107            }
 01108            return _result;
 01109        }
 1110
 1111        /// <summary>
 1112        /// Queue a large face list training task, the training task may not be started
 1113        /// immediately.
 1114        /// </summary>
 1115        /// <param name='largeFaceListId'>
 1116        /// Id referencing a particular large face list.
 1117        /// </param>
 1118        /// <param name='customHeaders'>
 1119        /// Headers that will be added to request.
 1120        /// </param>
 1121        /// <param name='cancellationToken'>
 1122        /// The cancellation token.
 1123        /// </param>
 1124        /// <exception cref="APIErrorException">
 1125        /// Thrown when the operation returned an invalid status code
 1126        /// </exception>
 1127        /// <exception cref="ValidationException">
 1128        /// Thrown when a required parameter is null
 1129        /// </exception>
 1130        /// <exception cref="System.ArgumentNullException">
 1131        /// Thrown when a required parameter is null
 1132        /// </exception>
 1133        /// <return>
 1134        /// A response object containing the response body and response headers.
 1135        /// </return>
 1136        public async Task<HttpOperationResponse> TrainWithHttpMessagesAsync(string largeFaceListId, Dictionary<string, L
 1137        {
 41138            if (Client.Endpoint == null)
 1139            {
 01140                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1141            }
 41142            if (largeFaceListId == null)
 1143            {
 01144                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 1145            }
 41146            if (largeFaceListId != null)
 1147            {
 41148                if (largeFaceListId.Length > 64)
 1149                {
 01150                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 1151                }
 41152                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 1153                {
 01154                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 1155                }
 1156            }
 1157            // Tracing
 41158            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 41159            string _invocationId = null;
 41160            if (_shouldTrace)
 1161            {
 01162                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01163                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01164                tracingParameters.Add("largeFaceListId", largeFaceListId);
 01165                tracingParameters.Add("cancellationToken", cancellationToken);
 01166                ServiceClientTracing.Enter(_invocationId, this, "Train", tracingParameters);
 1167            }
 1168            // Construct URL
 41169            var _baseUrl = Client.BaseUri;
 41170            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/train";
 41171            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 41172            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 1173            // Create HTTP transport objects
 41174            var _httpRequest = new HttpRequestMessage();
 41175            HttpResponseMessage _httpResponse = null;
 41176            _httpRequest.Method = new HttpMethod("POST");
 41177            _httpRequest.RequestUri = new System.Uri(_url);
 1178            // Set Headers
 1179
 1180
 41181            if (customHeaders != null)
 1182            {
 01183                foreach(var _header in customHeaders)
 1184                {
 01185                    if (_httpRequest.Headers.Contains(_header.Key))
 1186                    {
 01187                        _httpRequest.Headers.Remove(_header.Key);
 1188                    }
 01189                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1190                }
 1191            }
 1192
 1193            // Serialize Request
 41194            string _requestContent = null;
 1195            // Set Credentials
 41196            if (Client.Credentials != null)
 1197            {
 41198                cancellationToken.ThrowIfCancellationRequested();
 41199                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1200            }
 1201            // Send Request
 41202            if (_shouldTrace)
 1203            {
 01204                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1205            }
 41206            cancellationToken.ThrowIfCancellationRequested();
 41207            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 41208            if (_shouldTrace)
 1209            {
 01210                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1211            }
 41212            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 41213            cancellationToken.ThrowIfCancellationRequested();
 41214            string _responseContent = null;
 41215            if ((int)_statusCode != 202)
 1216            {
 01217                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1218                try
 1219                {
 01220                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01221                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01222                    if (_errorBody != null)
 1223                    {
 01224                        ex.Body = _errorBody;
 1225                    }
 01226                }
 01227                catch (JsonException)
 1228                {
 1229                    // Ignore the exception
 01230                }
 01231                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01232                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01233                if (_shouldTrace)
 1234                {
 01235                    ServiceClientTracing.Error(_invocationId, ex);
 1236                }
 01237                _httpRequest.Dispose();
 01238                if (_httpResponse != null)
 1239                {
 01240                    _httpResponse.Dispose();
 1241                }
 01242                throw ex;
 1243            }
 1244            // Create Result
 41245            var _result = new HttpOperationResponse();
 41246            _result.Request = _httpRequest;
 41247            _result.Response = _httpResponse;
 41248            if (_shouldTrace)
 1249            {
 01250                ServiceClientTracing.Exit(_invocationId, _result);
 1251            }
 41252            return _result;
 41253        }
 1254
 1255        /// <summary>
 1256        /// Delete a face from a large face list by specified largeFaceListId and
 1257        /// persistedFaceId.
 1258        /// &lt;br /&gt; Adding/deleting faces to/from a same large face list are
 1259        /// processed sequentially and to/from different large face lists are in
 1260        /// parallel.
 1261        /// </summary>
 1262        /// <param name='largeFaceListId'>
 1263        /// Id referencing a particular large face list.
 1264        /// </param>
 1265        /// <param name='persistedFaceId'>
 1266        /// Id referencing a particular persistedFaceId of an existing face.
 1267        /// </param>
 1268        /// <param name='customHeaders'>
 1269        /// Headers that will be added to request.
 1270        /// </param>
 1271        /// <param name='cancellationToken'>
 1272        /// The cancellation token.
 1273        /// </param>
 1274        /// <exception cref="APIErrorException">
 1275        /// Thrown when the operation returned an invalid status code
 1276        /// </exception>
 1277        /// <exception cref="ValidationException">
 1278        /// Thrown when a required parameter is null
 1279        /// </exception>
 1280        /// <exception cref="System.ArgumentNullException">
 1281        /// Thrown when a required parameter is null
 1282        /// </exception>
 1283        /// <return>
 1284        /// A response object containing the response body and response headers.
 1285        /// </return>
 1286        public async Task<HttpOperationResponse> DeleteFaceWithHttpMessagesAsync(string largeFaceListId, System.Guid per
 1287        {
 01288            if (Client.Endpoint == null)
 1289            {
 01290                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1291            }
 01292            if (largeFaceListId == null)
 1293            {
 01294                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 1295            }
 01296            if (largeFaceListId != null)
 1297            {
 01298                if (largeFaceListId.Length > 64)
 1299                {
 01300                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 1301                }
 01302                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 1303                {
 01304                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 1305                }
 1306            }
 1307            // Tracing
 01308            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01309            string _invocationId = null;
 01310            if (_shouldTrace)
 1311            {
 01312                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01313                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01314                tracingParameters.Add("largeFaceListId", largeFaceListId);
 01315                tracingParameters.Add("persistedFaceId", persistedFaceId);
 01316                tracingParameters.Add("cancellationToken", cancellationToken);
 01317                ServiceClientTracing.Enter(_invocationId, this, "DeleteFace", tracingParameters);
 1318            }
 1319            // Construct URL
 01320            var _baseUrl = Client.BaseUri;
 01321            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces
 01322            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01323            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 01324            _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri
 1325            // Create HTTP transport objects
 01326            var _httpRequest = new HttpRequestMessage();
 01327            HttpResponseMessage _httpResponse = null;
 01328            _httpRequest.Method = new HttpMethod("DELETE");
 01329            _httpRequest.RequestUri = new System.Uri(_url);
 1330            // Set Headers
 1331
 1332
 01333            if (customHeaders != null)
 1334            {
 01335                foreach(var _header in customHeaders)
 1336                {
 01337                    if (_httpRequest.Headers.Contains(_header.Key))
 1338                    {
 01339                        _httpRequest.Headers.Remove(_header.Key);
 1340                    }
 01341                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1342                }
 1343            }
 1344
 1345            // Serialize Request
 01346            string _requestContent = null;
 1347            // Set Credentials
 01348            if (Client.Credentials != null)
 1349            {
 01350                cancellationToken.ThrowIfCancellationRequested();
 01351                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1352            }
 1353            // Send Request
 01354            if (_shouldTrace)
 1355            {
 01356                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1357            }
 01358            cancellationToken.ThrowIfCancellationRequested();
 01359            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01360            if (_shouldTrace)
 1361            {
 01362                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1363            }
 01364            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01365            cancellationToken.ThrowIfCancellationRequested();
 01366            string _responseContent = null;
 01367            if ((int)_statusCode != 200)
 1368            {
 01369                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1370                try
 1371                {
 01372                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01373                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01374                    if (_errorBody != null)
 1375                    {
 01376                        ex.Body = _errorBody;
 1377                    }
 01378                }
 01379                catch (JsonException)
 1380                {
 1381                    // Ignore the exception
 01382                }
 01383                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01384                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01385                if (_shouldTrace)
 1386                {
 01387                    ServiceClientTracing.Error(_invocationId, ex);
 1388                }
 01389                _httpRequest.Dispose();
 01390                if (_httpResponse != null)
 1391                {
 01392                    _httpResponse.Dispose();
 1393                }
 01394                throw ex;
 1395            }
 1396            // Create Result
 01397            var _result = new HttpOperationResponse();
 01398            _result.Request = _httpRequest;
 01399            _result.Response = _httpResponse;
 01400            if (_shouldTrace)
 1401            {
 01402                ServiceClientTracing.Exit(_invocationId, _result);
 1403            }
 01404            return _result;
 01405        }
 1406
 1407        /// <summary>
 1408        /// Retrieve information about a persisted face (specified by persistedFaceId
 1409        /// and its belonging largeFaceListId).
 1410        /// </summary>
 1411        /// <param name='largeFaceListId'>
 1412        /// Id referencing a particular large face list.
 1413        /// </param>
 1414        /// <param name='persistedFaceId'>
 1415        /// Id referencing a particular persistedFaceId of an existing face.
 1416        /// </param>
 1417        /// <param name='customHeaders'>
 1418        /// Headers that will be added to request.
 1419        /// </param>
 1420        /// <param name='cancellationToken'>
 1421        /// The cancellation token.
 1422        /// </param>
 1423        /// <exception cref="APIErrorException">
 1424        /// Thrown when the operation returned an invalid status code
 1425        /// </exception>
 1426        /// <exception cref="SerializationException">
 1427        /// Thrown when unable to deserialize the response
 1428        /// </exception>
 1429        /// <exception cref="ValidationException">
 1430        /// Thrown when a required parameter is null
 1431        /// </exception>
 1432        /// <exception cref="System.ArgumentNullException">
 1433        /// Thrown when a required parameter is null
 1434        /// </exception>
 1435        /// <return>
 1436        /// A response object containing the response body and response headers.
 1437        /// </return>
 1438        public async Task<HttpOperationResponse<PersistedFace>> GetFaceWithHttpMessagesAsync(string largeFaceListId, Sys
 1439        {
 01440            if (Client.Endpoint == null)
 1441            {
 01442                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1443            }
 01444            if (largeFaceListId == null)
 1445            {
 01446                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 1447            }
 01448            if (largeFaceListId != null)
 1449            {
 01450                if (largeFaceListId.Length > 64)
 1451                {
 01452                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 1453                }
 01454                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 1455                {
 01456                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 1457                }
 1458            }
 1459            // Tracing
 01460            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01461            string _invocationId = null;
 01462            if (_shouldTrace)
 1463            {
 01464                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01465                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01466                tracingParameters.Add("largeFaceListId", largeFaceListId);
 01467                tracingParameters.Add("persistedFaceId", persistedFaceId);
 01468                tracingParameters.Add("cancellationToken", cancellationToken);
 01469                ServiceClientTracing.Enter(_invocationId, this, "GetFace", tracingParameters);
 1470            }
 1471            // Construct URL
 01472            var _baseUrl = Client.BaseUri;
 01473            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces
 01474            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01475            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 01476            _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri
 1477            // Create HTTP transport objects
 01478            var _httpRequest = new HttpRequestMessage();
 01479            HttpResponseMessage _httpResponse = null;
 01480            _httpRequest.Method = new HttpMethod("GET");
 01481            _httpRequest.RequestUri = new System.Uri(_url);
 1482            // Set Headers
 1483
 1484
 01485            if (customHeaders != null)
 1486            {
 01487                foreach(var _header in customHeaders)
 1488                {
 01489                    if (_httpRequest.Headers.Contains(_header.Key))
 1490                    {
 01491                        _httpRequest.Headers.Remove(_header.Key);
 1492                    }
 01493                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1494                }
 1495            }
 1496
 1497            // Serialize Request
 01498            string _requestContent = null;
 1499            // Set Credentials
 01500            if (Client.Credentials != null)
 1501            {
 01502                cancellationToken.ThrowIfCancellationRequested();
 01503                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1504            }
 1505            // Send Request
 01506            if (_shouldTrace)
 1507            {
 01508                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1509            }
 01510            cancellationToken.ThrowIfCancellationRequested();
 01511            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01512            if (_shouldTrace)
 1513            {
 01514                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1515            }
 01516            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01517            cancellationToken.ThrowIfCancellationRequested();
 01518            string _responseContent = null;
 01519            if ((int)_statusCode != 200)
 1520            {
 01521                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1522                try
 1523                {
 01524                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01525                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01526                    if (_errorBody != null)
 1527                    {
 01528                        ex.Body = _errorBody;
 1529                    }
 01530                }
 01531                catch (JsonException)
 1532                {
 1533                    // Ignore the exception
 01534                }
 01535                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01536                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01537                if (_shouldTrace)
 1538                {
 01539                    ServiceClientTracing.Error(_invocationId, ex);
 1540                }
 01541                _httpRequest.Dispose();
 01542                if (_httpResponse != null)
 1543                {
 01544                    _httpResponse.Dispose();
 1545                }
 01546                throw ex;
 1547            }
 1548            // Create Result
 01549            var _result = new HttpOperationResponse<PersistedFace>();
 01550            _result.Request = _httpRequest;
 01551            _result.Response = _httpResponse;
 1552            // Deserialize Response
 01553            if ((int)_statusCode == 200)
 1554            {
 01555                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1556                try
 1557                {
 01558                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent,
 01559                }
 01560                catch (JsonException ex)
 1561                {
 01562                    _httpRequest.Dispose();
 01563                    if (_httpResponse != null)
 1564                    {
 01565                        _httpResponse.Dispose();
 1566                    }
 01567                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1568                }
 1569            }
 01570            if (_shouldTrace)
 1571            {
 01572                ServiceClientTracing.Exit(_invocationId, _result);
 1573            }
 01574            return _result;
 01575        }
 1576
 1577        /// <summary>
 1578        /// Update a persisted face's userData field.
 1579        /// </summary>
 1580        /// <param name='largeFaceListId'>
 1581        /// Id referencing a particular large face list.
 1582        /// </param>
 1583        /// <param name='persistedFaceId'>
 1584        /// Id referencing a particular persistedFaceId of an existing face.
 1585        /// </param>
 1586        /// <param name='userData'>
 1587        /// User-provided data attached to the face. The size limit is 1KB.
 1588        /// </param>
 1589        /// <param name='customHeaders'>
 1590        /// Headers that will be added to request.
 1591        /// </param>
 1592        /// <param name='cancellationToken'>
 1593        /// The cancellation token.
 1594        /// </param>
 1595        /// <exception cref="APIErrorException">
 1596        /// Thrown when the operation returned an invalid status code
 1597        /// </exception>
 1598        /// <exception cref="ValidationException">
 1599        /// Thrown when a required parameter is null
 1600        /// </exception>
 1601        /// <exception cref="System.ArgumentNullException">
 1602        /// Thrown when a required parameter is null
 1603        /// </exception>
 1604        /// <return>
 1605        /// A response object containing the response body and response headers.
 1606        /// </return>
 1607        public async Task<HttpOperationResponse> UpdateFaceWithHttpMessagesAsync(string largeFaceListId, System.Guid per
 1608        {
 01609            if (Client.Endpoint == null)
 1610            {
 01611                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1612            }
 01613            if (largeFaceListId == null)
 1614            {
 01615                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 1616            }
 01617            if (largeFaceListId != null)
 1618            {
 01619                if (largeFaceListId.Length > 64)
 1620                {
 01621                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 1622                }
 01623                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 1624                {
 01625                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 1626                }
 1627            }
 01628            if (userData != null)
 1629            {
 01630                if (userData.Length > 1024)
 1631                {
 01632                    throw new ValidationException(ValidationRules.MaxLength, "userData", 1024);
 1633                }
 1634            }
 01635            UpdateFaceRequest body = new UpdateFaceRequest();
 01636            if (userData != null)
 1637            {
 01638                body.UserData = userData;
 1639            }
 1640            // Tracing
 01641            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01642            string _invocationId = null;
 01643            if (_shouldTrace)
 1644            {
 01645                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01646                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01647                tracingParameters.Add("largeFaceListId", largeFaceListId);
 01648                tracingParameters.Add("persistedFaceId", persistedFaceId);
 01649                tracingParameters.Add("body", body);
 01650                tracingParameters.Add("cancellationToken", cancellationToken);
 01651                ServiceClientTracing.Enter(_invocationId, this, "UpdateFace", tracingParameters);
 1652            }
 1653            // Construct URL
 01654            var _baseUrl = Client.BaseUri;
 01655            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces
 01656            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01657            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 01658            _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri
 1659            // Create HTTP transport objects
 01660            var _httpRequest = new HttpRequestMessage();
 01661            HttpResponseMessage _httpResponse = null;
 01662            _httpRequest.Method = new HttpMethod("PATCH");
 01663            _httpRequest.RequestUri = new System.Uri(_url);
 1664            // Set Headers
 1665
 1666
 01667            if (customHeaders != null)
 1668            {
 01669                foreach(var _header in customHeaders)
 1670                {
 01671                    if (_httpRequest.Headers.Contains(_header.Key))
 1672                    {
 01673                        _httpRequest.Headers.Remove(_header.Key);
 1674                    }
 01675                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1676                }
 1677            }
 1678
 1679            // Serialize Request
 01680            string _requestContent = null;
 01681            if(body != null)
 1682            {
 01683                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 01684                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01685                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1686            }
 1687            // Set Credentials
 01688            if (Client.Credentials != null)
 1689            {
 01690                cancellationToken.ThrowIfCancellationRequested();
 01691                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1692            }
 1693            // Send Request
 01694            if (_shouldTrace)
 1695            {
 01696                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1697            }
 01698            cancellationToken.ThrowIfCancellationRequested();
 01699            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01700            if (_shouldTrace)
 1701            {
 01702                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1703            }
 01704            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01705            cancellationToken.ThrowIfCancellationRequested();
 01706            string _responseContent = null;
 01707            if ((int)_statusCode != 200)
 1708            {
 01709                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1710                try
 1711                {
 01712                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01713                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01714                    if (_errorBody != null)
 1715                    {
 01716                        ex.Body = _errorBody;
 1717                    }
 01718                }
 01719                catch (JsonException)
 1720                {
 1721                    // Ignore the exception
 01722                }
 01723                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01724                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01725                if (_shouldTrace)
 1726                {
 01727                    ServiceClientTracing.Error(_invocationId, ex);
 1728                }
 01729                _httpRequest.Dispose();
 01730                if (_httpResponse != null)
 1731                {
 01732                    _httpResponse.Dispose();
 1733                }
 01734                throw ex;
 1735            }
 1736            // Create Result
 01737            var _result = new HttpOperationResponse();
 01738            _result.Request = _httpRequest;
 01739            _result.Response = _httpResponse;
 01740            if (_shouldTrace)
 1741            {
 01742                ServiceClientTracing.Exit(_invocationId, _result);
 1743            }
 01744            return _result;
 01745        }
 1746
 1747        /// <summary>
 1748        /// Add a face to a specified large face list, up to 1,000,000 faces.
 1749        /// &lt;br /&gt; To deal with an image contains multiple faces, input face can
 1750        /// be specified as an image with a targetFace rectangle. It returns a
 1751        /// persistedFaceId representing the added face. No image will be stored. Only
 1752        /// the extracted face feature will be stored on server until [LargeFaceList
 1753        /// Face -
 1754        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/5a158c8ad2de3616c086f2d4)
 1755        /// or [LargeFaceList -
 1756        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/5a1580d5d2de3616c086f2cd)
 1757        /// is called.
 1758        /// &lt;br /&gt; Note persistedFaceId is different from faceId generated by
 1759        /// [Face -
 1760        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 1761        /// * Higher face image quality means better recognition precision. Please
 1762        /// consider high-quality faces: frontal, clear, and face size is 200x200
 1763        /// pixels (100 pixels between eyes) or bigger.
 1764        /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The
 1765        /// allowed image file size is from 1KB to 6MB.
 1766        /// * "targetFace" rectangle should contain one face. Zero or multiple faces
 1767        /// will be regarded as an error. If the provided "targetFace" rectangle is not
 1768        /// returned from [Face -
 1769        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
 1770        /// there’s no guarantee to detect and add the face successfully.
 1771        /// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
 1772        /// or large occlusions will cause failures.
 1773        /// * Adding/deleting faces to/from a same face list are processed sequentially
 1774        /// and to/from different face lists are in parallel.
 1775        /// * The minimum detectable face size is 36x36 pixels in an image no larger
 1776        /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels
 1777        /// will need a proportionally larger minimum face size.
 1778        /// * Different 'detectionModel' values can be provided. To use and compare
 1779        /// different detection models, please refer to [How to specify a detection
 1780        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti
 1781        /// | Model | Recommended use-case(s) |
 1782        /// | ---------- | -------- |
 1783        /// | 'detection_01': | The default detection model for [LargeFaceList - Add
 1784        /// Face](/docs/services/563879b61984550e40cbbe8d/operations/5a158c10d2de3616c086f2d3).
 1785        /// Recommend for near frontal face detection. For scenarios with exceptionally
 1786        /// large angle (head-pose) faces, occluded faces or wrong image orientation,
 1787        /// the faces in such cases may not be detected. |
 1788        /// | 'detection_02': | Detection model released in 2019 May with improved
 1789        /// accuracy especially on small, side and blurry faces. |
 1790        ///
 1791        /// Quota:
 1792        /// * Free-tier subscription quota: 1,000 faces per large face list.
 1793        /// * S0-tier subscription quota: 1,000,000 faces per large face list.
 1794        /// </summary>
 1795        /// <param name='largeFaceListId'>
 1796        /// Id referencing a particular large face list.
 1797        /// </param>
 1798        /// <param name='url'>
 1799        /// Publicly reachable URL of an image
 1800        /// </param>
 1801        /// <param name='userData'>
 1802        /// User-specified data about the face for any purpose. The maximum length is
 1803        /// 1KB.
 1804        /// </param>
 1805        /// <param name='targetFace'>
 1806        /// A face rectangle to specify the target face to be added to a person in the
 1807        /// format of "targetFace=left,top,width,height". E.g.
 1808        /// "targetFace=10,10,100,100". If there is more than one face in the image,
 1809        /// targetFace is required to specify which face to add. No targetFace means
 1810        /// there is only one face detected in the entire image.
 1811        /// </param>
 1812        /// <param name='detectionModel'>
 1813        /// Name of detection model. Detection model is used to detect faces in the
 1814        /// submitted image. A detection model name can be provided when performing
 1815        /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add
 1816        /// Face. The default value is 'detection_01', if another model is needed,
 1817        /// please explicitly specify it. Possible values include: 'detection_01',
 1818        /// 'detection_02'
 1819        /// </param>
 1820        /// <param name='customHeaders'>
 1821        /// Headers that will be added to request.
 1822        /// </param>
 1823        /// <param name='cancellationToken'>
 1824        /// The cancellation token.
 1825        /// </param>
 1826        /// <exception cref="APIErrorException">
 1827        /// Thrown when the operation returned an invalid status code
 1828        /// </exception>
 1829        /// <exception cref="SerializationException">
 1830        /// Thrown when unable to deserialize the response
 1831        /// </exception>
 1832        /// <exception cref="ValidationException">
 1833        /// Thrown when a required parameter is null
 1834        /// </exception>
 1835        /// <exception cref="System.ArgumentNullException">
 1836        /// Thrown when a required parameter is null
 1837        /// </exception>
 1838        /// <return>
 1839        /// A response object containing the response body and response headers.
 1840        /// </return>
 1841        public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromUrlWithHttpMessagesAsync(string largeFaceList
 1842        {
 01843            if (Client.Endpoint == null)
 1844            {
 01845                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1846            }
 01847            if (largeFaceListId == null)
 1848            {
 01849                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 1850            }
 01851            if (largeFaceListId != null)
 1852            {
 01853                if (largeFaceListId.Length > 64)
 1854                {
 01855                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 1856                }
 01857                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 1858                {
 01859                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 1860                }
 1861            }
 01862            if (userData != null)
 1863            {
 01864                if (userData.Length > 1024)
 1865                {
 01866                    throw new ValidationException(ValidationRules.MaxLength, "userData", 1024);
 1867                }
 1868            }
 01869            if (url == null)
 1870            {
 01871                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 1872            }
 01873            ImageUrl imageUrl = new ImageUrl();
 01874            if (url != null)
 1875            {
 01876                imageUrl.Url = url;
 1877            }
 1878            // Tracing
 01879            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01880            string _invocationId = null;
 01881            if (_shouldTrace)
 1882            {
 01883                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01884                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01885                tracingParameters.Add("largeFaceListId", largeFaceListId);
 01886                tracingParameters.Add("userData", userData);
 01887                tracingParameters.Add("targetFace", targetFace);
 01888                tracingParameters.Add("detectionModel", detectionModel);
 01889                tracingParameters.Add("imageUrl", imageUrl);
 01890                tracingParameters.Add("cancellationToken", cancellationToken);
 01891                ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromUrl", tracingParameters);
 1892            }
 1893            // Construct URL
 01894            var _baseUrl = Client.BaseUri;
 01895            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces
 01896            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01897            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 01898            List<string> _queryParameters = new List<string>();
 01899            if (userData != null)
 1900            {
 01901                _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData)));
 1902            }
 01903            if (targetFace != null)
 1904            {
 01905                _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target
 1906            }
 01907            if (detectionModel != null)
 1908            {
 01909                _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel)));
 1910            }
 01911            if (_queryParameters.Count > 0)
 1912            {
 01913                _url += "?" + string.Join("&", _queryParameters);
 1914            }
 1915            // Create HTTP transport objects
 01916            var _httpRequest = new HttpRequestMessage();
 01917            HttpResponseMessage _httpResponse = null;
 01918            _httpRequest.Method = new HttpMethod("POST");
 01919            _httpRequest.RequestUri = new System.Uri(_url);
 1920            // Set Headers
 1921
 1922
 01923            if (customHeaders != null)
 1924            {
 01925                foreach(var _header in customHeaders)
 1926                {
 01927                    if (_httpRequest.Headers.Contains(_header.Key))
 1928                    {
 01929                        _httpRequest.Headers.Remove(_header.Key);
 1930                    }
 01931                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1932                }
 1933            }
 1934
 1935            // Serialize Request
 01936            string _requestContent = null;
 01937            if(imageUrl != null)
 1938            {
 01939                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti
 01940                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01941                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1942            }
 1943            // Set Credentials
 01944            if (Client.Credentials != null)
 1945            {
 01946                cancellationToken.ThrowIfCancellationRequested();
 01947                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1948            }
 1949            // Send Request
 01950            if (_shouldTrace)
 1951            {
 01952                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1953            }
 01954            cancellationToken.ThrowIfCancellationRequested();
 01955            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01956            if (_shouldTrace)
 1957            {
 01958                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1959            }
 01960            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01961            cancellationToken.ThrowIfCancellationRequested();
 01962            string _responseContent = null;
 01963            if ((int)_statusCode != 200)
 1964            {
 01965                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1966                try
 1967                {
 01968                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01969                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01970                    if (_errorBody != null)
 1971                    {
 01972                        ex.Body = _errorBody;
 1973                    }
 01974                }
 01975                catch (JsonException)
 1976                {
 1977                    // Ignore the exception
 01978                }
 01979                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01980                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01981                if (_shouldTrace)
 1982                {
 01983                    ServiceClientTracing.Error(_invocationId, ex);
 1984                }
 01985                _httpRequest.Dispose();
 01986                if (_httpResponse != null)
 1987                {
 01988                    _httpResponse.Dispose();
 1989                }
 01990                throw ex;
 1991            }
 1992            // Create Result
 01993            var _result = new HttpOperationResponse<PersistedFace>();
 01994            _result.Request = _httpRequest;
 01995            _result.Response = _httpResponse;
 1996            // Deserialize Response
 01997            if ((int)_statusCode == 200)
 1998            {
 01999                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2000                try
 2001                {
 02002                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent,
 02003                }
 02004                catch (JsonException ex)
 2005                {
 02006                    _httpRequest.Dispose();
 02007                    if (_httpResponse != null)
 2008                    {
 02009                        _httpResponse.Dispose();
 2010                    }
 02011                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2012                }
 2013            }
 02014            if (_shouldTrace)
 2015            {
 02016                ServiceClientTracing.Exit(_invocationId, _result);
 2017            }
 02018            return _result;
 02019        }
 2020
 2021        /// <summary>
 2022        /// List all faces in a large face list, and retrieve face information
 2023        /// (including userData and persistedFaceIds of registered faces of the face).
 2024        /// </summary>
 2025        /// <param name='largeFaceListId'>
 2026        /// Id referencing a particular large face list.
 2027        /// </param>
 2028        /// <param name='start'>
 2029        /// Starting face id to return (used to list a range of faces).
 2030        /// </param>
 2031        /// <param name='top'>
 2032        /// Number of faces to return starting with the face id indicated by the
 2033        /// 'start' parameter.
 2034        /// </param>
 2035        /// <param name='customHeaders'>
 2036        /// Headers that will be added to request.
 2037        /// </param>
 2038        /// <param name='cancellationToken'>
 2039        /// The cancellation token.
 2040        /// </param>
 2041        /// <exception cref="APIErrorException">
 2042        /// Thrown when the operation returned an invalid status code
 2043        /// </exception>
 2044        /// <exception cref="SerializationException">
 2045        /// Thrown when unable to deserialize the response
 2046        /// </exception>
 2047        /// <exception cref="ValidationException">
 2048        /// Thrown when a required parameter is null
 2049        /// </exception>
 2050        /// <exception cref="System.ArgumentNullException">
 2051        /// Thrown when a required parameter is null
 2052        /// </exception>
 2053        /// <return>
 2054        /// A response object containing the response body and response headers.
 2055        /// </return>
 2056        public async Task<HttpOperationResponse<IList<PersistedFace>>> ListFacesWithHttpMessagesAsync(string largeFaceLi
 2057        {
 22058            if (Client.Endpoint == null)
 2059            {
 02060                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 2061            }
 22062            if (largeFaceListId == null)
 2063            {
 02064                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 2065            }
 22066            if (largeFaceListId != null)
 2067            {
 22068                if (largeFaceListId.Length > 64)
 2069                {
 02070                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 2071                }
 22072                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 2073                {
 02074                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 2075                }
 2076            }
 22077            if (top > 1000)
 2078            {
 02079                throw new ValidationException(ValidationRules.InclusiveMaximum, "top", 1000);
 2080            }
 22081            if (top < 1)
 2082            {
 02083                throw new ValidationException(ValidationRules.InclusiveMinimum, "top", 1);
 2084            }
 2085            // Tracing
 22086            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 22087            string _invocationId = null;
 22088            if (_shouldTrace)
 2089            {
 02090                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02091                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02092                tracingParameters.Add("largeFaceListId", largeFaceListId);
 02093                tracingParameters.Add("start", start);
 02094                tracingParameters.Add("top", top);
 02095                tracingParameters.Add("cancellationToken", cancellationToken);
 02096                ServiceClientTracing.Enter(_invocationId, this, "ListFaces", tracingParameters);
 2097            }
 2098            // Construct URL
 22099            var _baseUrl = Client.BaseUri;
 22100            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces
 22101            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 22102            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 22103            List<string> _queryParameters = new List<string>();
 22104            if (start != null)
 2105            {
 02106                _queryParameters.Add(string.Format("start={0}", System.Uri.EscapeDataString(start)));
 2107            }
 22108            if (top != null)
 2109            {
 02110                _queryParameters.Add(string.Format("top={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon
 2111            }
 22112            if (_queryParameters.Count > 0)
 2113            {
 02114                _url += "?" + string.Join("&", _queryParameters);
 2115            }
 2116            // Create HTTP transport objects
 22117            var _httpRequest = new HttpRequestMessage();
 22118            HttpResponseMessage _httpResponse = null;
 22119            _httpRequest.Method = new HttpMethod("GET");
 22120            _httpRequest.RequestUri = new System.Uri(_url);
 2121            // Set Headers
 2122
 2123
 22124            if (customHeaders != null)
 2125            {
 02126                foreach(var _header in customHeaders)
 2127                {
 02128                    if (_httpRequest.Headers.Contains(_header.Key))
 2129                    {
 02130                        _httpRequest.Headers.Remove(_header.Key);
 2131                    }
 02132                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2133                }
 2134            }
 2135
 2136            // Serialize Request
 22137            string _requestContent = null;
 2138            // Set Credentials
 22139            if (Client.Credentials != null)
 2140            {
 22141                cancellationToken.ThrowIfCancellationRequested();
 22142                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2143            }
 2144            // Send Request
 22145            if (_shouldTrace)
 2146            {
 02147                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2148            }
 22149            cancellationToken.ThrowIfCancellationRequested();
 22150            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 22151            if (_shouldTrace)
 2152            {
 02153                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2154            }
 22155            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 22156            cancellationToken.ThrowIfCancellationRequested();
 22157            string _responseContent = null;
 22158            if ((int)_statusCode != 200)
 2159            {
 02160                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 2161                try
 2162                {
 02163                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02164                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 02165                    if (_errorBody != null)
 2166                    {
 02167                        ex.Body = _errorBody;
 2168                    }
 02169                }
 02170                catch (JsonException)
 2171                {
 2172                    // Ignore the exception
 02173                }
 02174                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02175                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02176                if (_shouldTrace)
 2177                {
 02178                    ServiceClientTracing.Error(_invocationId, ex);
 2179                }
 02180                _httpRequest.Dispose();
 02181                if (_httpResponse != null)
 2182                {
 02183                    _httpResponse.Dispose();
 2184                }
 02185                throw ex;
 2186            }
 2187            // Create Result
 22188            var _result = new HttpOperationResponse<IList<PersistedFace>>();
 22189            _result.Request = _httpRequest;
 22190            _result.Response = _httpResponse;
 2191            // Deserialize Response
 22192            if ((int)_statusCode == 200)
 2193            {
 22194                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2195                try
 2196                {
 22197                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PersistedFace>>(_responseC
 22198                }
 02199                catch (JsonException ex)
 2200                {
 02201                    _httpRequest.Dispose();
 02202                    if (_httpResponse != null)
 2203                    {
 02204                        _httpResponse.Dispose();
 2205                    }
 02206                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2207                }
 2208            }
 22209            if (_shouldTrace)
 2210            {
 02211                ServiceClientTracing.Exit(_invocationId, _result);
 2212            }
 22213            return _result;
 22214        }
 2215
 2216        /// <summary>
 2217        /// Add a face to a specified large face list, up to 1,000,000 faces.
 2218        /// &lt;br /&gt; To deal with an image contains multiple faces, input face can
 2219        /// be specified as an image with a targetFace rectangle. It returns a
 2220        /// persistedFaceId representing the added face. No image will be stored. Only
 2221        /// the extracted face feature will be stored on server until [LargeFaceList
 2222        /// Face -
 2223        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/5a158c8ad2de3616c086f2d4)
 2224        /// or [LargeFaceList -
 2225        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/5a1580d5d2de3616c086f2cd)
 2226        /// is called.
 2227        /// &lt;br /&gt; Note persistedFaceId is different from faceId generated by
 2228        /// [Face -
 2229        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 2230        /// * Higher face image quality means better recognition precision. Please
 2231        /// consider high-quality faces: frontal, clear, and face size is 200x200
 2232        /// pixels (100 pixels between eyes) or bigger.
 2233        /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The
 2234        /// allowed image file size is from 1KB to 6MB.
 2235        /// * "targetFace" rectangle should contain one face. Zero or multiple faces
 2236        /// will be regarded as an error. If the provided "targetFace" rectangle is not
 2237        /// returned from [Face -
 2238        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
 2239        /// there’s no guarantee to detect and add the face successfully.
 2240        /// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
 2241        /// or large occlusions will cause failures.
 2242        /// * Adding/deleting faces to/from a same face list are processed sequentially
 2243        /// and to/from different face lists are in parallel.
 2244        /// * The minimum detectable face size is 36x36 pixels in an image no larger
 2245        /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels
 2246        /// will need a proportionally larger minimum face size.
 2247        /// * Different 'detectionModel' values can be provided. To use and compare
 2248        /// different detection models, please refer to [How to specify a detection
 2249        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti
 2250        /// | Model | Recommended use-case(s) |
 2251        /// | ---------- | -------- |
 2252        /// | 'detection_01': | The default detection model for [LargeFaceList - Add
 2253        /// Face](/docs/services/563879b61984550e40cbbe8d/operations/5a158c10d2de3616c086f2d3).
 2254        /// Recommend for near frontal face detection. For scenarios with exceptionally
 2255        /// large angle (head-pose) faces, occluded faces or wrong image orientation,
 2256        /// the faces in such cases may not be detected. |
 2257        /// | 'detection_02': | Detection model released in 2019 May with improved
 2258        /// accuracy especially on small, side and blurry faces. |
 2259        ///
 2260        /// Quota:
 2261        /// * Free-tier subscription quota: 1,000 faces per large face list.
 2262        /// * S0-tier subscription quota: 1,000,000 faces per large face list.
 2263        /// </summary>
 2264        /// <param name='largeFaceListId'>
 2265        /// Id referencing a particular large face list.
 2266        /// </param>
 2267        /// <param name='image'>
 2268        /// An image stream.
 2269        /// </param>
 2270        /// <param name='userData'>
 2271        /// User-specified data about the face for any purpose. The maximum length is
 2272        /// 1KB.
 2273        /// </param>
 2274        /// <param name='targetFace'>
 2275        /// A face rectangle to specify the target face to be added to a person in the
 2276        /// format of "targetFace=left,top,width,height". E.g.
 2277        /// "targetFace=10,10,100,100". If there is more than one face in the image,
 2278        /// targetFace is required to specify which face to add. No targetFace means
 2279        /// there is only one face detected in the entire image.
 2280        /// </param>
 2281        /// <param name='detectionModel'>
 2282        /// Name of detection model. Detection model is used to detect faces in the
 2283        /// submitted image. A detection model name can be provided when performing
 2284        /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add
 2285        /// Face. The default value is 'detection_01', if another model is needed,
 2286        /// please explicitly specify it. Possible values include: 'detection_01',
 2287        /// 'detection_02'
 2288        /// </param>
 2289        /// <param name='customHeaders'>
 2290        /// Headers that will be added to request.
 2291        /// </param>
 2292        /// <param name='cancellationToken'>
 2293        /// The cancellation token.
 2294        /// </param>
 2295        /// <exception cref="APIErrorException">
 2296        /// Thrown when the operation returned an invalid status code
 2297        /// </exception>
 2298        /// <exception cref="SerializationException">
 2299        /// Thrown when unable to deserialize the response
 2300        /// </exception>
 2301        /// <exception cref="ValidationException">
 2302        /// Thrown when a required parameter is null
 2303        /// </exception>
 2304        /// <exception cref="System.ArgumentNullException">
 2305        /// Thrown when a required parameter is null
 2306        /// </exception>
 2307        /// <return>
 2308        /// A response object containing the response body and response headers.
 2309        /// </return>
 2310        public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromStreamWithHttpMessagesAsync(string largeFaceL
 2311        {
 142312            if (Client.Endpoint == null)
 2313            {
 02314                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 2315            }
 142316            if (largeFaceListId == null)
 2317            {
 02318                throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId");
 2319            }
 142320            if (largeFaceListId != null)
 2321            {
 142322                if (largeFaceListId.Length > 64)
 2323                {
 02324                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 2325                }
 142326                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 2327                {
 02328                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 2329                }
 2330            }
 142331            if (userData != null)
 2332            {
 02333                if (userData.Length > 1024)
 2334                {
 02335                    throw new ValidationException(ValidationRules.MaxLength, "userData", 1024);
 2336                }
 2337            }
 142338            if (image == null)
 2339            {
 02340                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 2341            }
 2342            // Tracing
 142343            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 142344            string _invocationId = null;
 142345            if (_shouldTrace)
 2346            {
 02347                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02348                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02349                tracingParameters.Add("largeFaceListId", largeFaceListId);
 02350                tracingParameters.Add("userData", userData);
 02351                tracingParameters.Add("targetFace", targetFace);
 02352                tracingParameters.Add("image", image);
 02353                tracingParameters.Add("detectionModel", detectionModel);
 02354                tracingParameters.Add("cancellationToken", cancellationToken);
 02355                ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromStream", tracingParameters);
 2356            }
 2357            // Construct URL
 142358            var _baseUrl = Client.BaseUri;
 142359            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces
 142360            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 142361            _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId));
 142362            List<string> _queryParameters = new List<string>();
 142363            if (userData != null)
 2364            {
 02365                _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData)));
 2366            }
 142367            if (targetFace != null)
 2368            {
 122369                _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target
 2370            }
 142371            if (detectionModel != null)
 2372            {
 142373                _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel)));
 2374            }
 142375            if (_queryParameters.Count > 0)
 2376            {
 142377                _url += "?" + string.Join("&", _queryParameters);
 2378            }
 2379            // Create HTTP transport objects
 142380            var _httpRequest = new HttpRequestMessage();
 142381            HttpResponseMessage _httpResponse = null;
 142382            _httpRequest.Method = new HttpMethod("POST");
 142383            _httpRequest.RequestUri = new System.Uri(_url);
 2384            // Set Headers
 2385
 2386
 142387            if (customHeaders != null)
 2388            {
 02389                foreach(var _header in customHeaders)
 2390                {
 02391                    if (_httpRequest.Headers.Contains(_header.Key))
 2392                    {
 02393                        _httpRequest.Headers.Remove(_header.Key);
 2394                    }
 02395                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2396                }
 2397            }
 2398
 2399            // Serialize Request
 142400            string _requestContent = null;
 142401            if(image == null)
 2402            {
 02403              throw new System.ArgumentNullException("image");
 2404            }
 142405            if (image != null && image != Stream.Null)
 2406            {
 142407                _httpRequest.Content = new StreamContent(image);
 142408                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 2409            }
 2410            // Set Credentials
 142411            if (Client.Credentials != null)
 2412            {
 142413                cancellationToken.ThrowIfCancellationRequested();
 142414                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2415            }
 2416            // Send Request
 142417            if (_shouldTrace)
 2418            {
 02419                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2420            }
 142421            cancellationToken.ThrowIfCancellationRequested();
 142422            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 142423            if (_shouldTrace)
 2424            {
 02425                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2426            }
 142427            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 142428            cancellationToken.ThrowIfCancellationRequested();
 142429            string _responseContent = null;
 142430            if ((int)_statusCode != 200)
 2431            {
 02432                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 2433                try
 2434                {
 02435                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02436                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 02437                    if (_errorBody != null)
 2438                    {
 02439                        ex.Body = _errorBody;
 2440                    }
 02441                }
 02442                catch (JsonException)
 2443                {
 2444                    // Ignore the exception
 02445                }
 02446                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02447                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02448                if (_shouldTrace)
 2449                {
 02450                    ServiceClientTracing.Error(_invocationId, ex);
 2451                }
 02452                _httpRequest.Dispose();
 02453                if (_httpResponse != null)
 2454                {
 02455                    _httpResponse.Dispose();
 2456                }
 02457                throw ex;
 2458            }
 2459            // Create Result
 142460            var _result = new HttpOperationResponse<PersistedFace>();
 142461            _result.Request = _httpRequest;
 142462            _result.Response = _httpResponse;
 2463            // Deserialize Response
 142464            if ((int)_statusCode == 200)
 2465            {
 142466                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2467                try
 2468                {
 142469                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent,
 142470                }
 02471                catch (JsonException ex)
 2472                {
 02473                    _httpRequest.Dispose();
 02474                    if (_httpResponse != null)
 2475                    {
 02476                        _httpResponse.Dispose();
 2477                    }
 02478                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2479                }
 2480            }
 142481            if (_shouldTrace)
 2482            {
 02483                ServiceClientTracing.Exit(_invocationId, _result);
 2484            }
 142485            return _result;
 142486        }
 2487
 2488    }
 2489}