< Summary

Class:Microsoft.Azure.CognitiveServices.Vision.Face.FaceListOperations
Assembly:Microsoft.Azure.CognitiveServices.Vision.Face
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\FaceListOperations.cs
Covered lines:185
Uncovered lines:477
Coverable lines:662
Total lines:1619
Line coverage:27.9% (185 of 662)
Covered branches:96
Total branches:374
Branch coverage:25.6% (96 of 374)

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%
ListWithHttpMessagesAsync()-0%0%
DeleteFaceWithHttpMessagesAsync()-0%0%
AddFaceFromUrlWithHttpMessagesAsync()-0%0%
AddFaceFromStreamWithHttpMessagesAsync()-53.54%53.33%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\FaceListOperations.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    /// FaceListOperations operations.
 27    /// </summary>
 28    public partial class FaceListOperations : IServiceOperations<FaceClient>, IFaceListOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the FaceListOperations 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 FaceListOperations(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>
 21251        public FaceClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Create an empty face list with user-specified faceListId, name, an optional
 55        /// userData and recognitionModel. Up to 64 face lists are allowed in one
 56        /// subscription.
 57        /// &lt;br /&gt; Face list is a list of faces, up to 1,000 faces, and used by
 58        /// [Face - Find
 59        /// Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237).
 60        /// &lt;br /&gt; After creation, user should use [FaceList - Add
 61        /// Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395250)
 62        /// to import the faces. No image will be stored. Only the extracted face
 63        /// features are stored on server until [FaceList -
 64        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524f)
 65        /// is called.
 66        /// &lt;br /&gt; Find Similar is used for scenario like finding celebrity-like
 67        /// faces, similar face filtering, or as a light way face identification. But
 68        /// if the actual use is to identify person, please use
 69        /// [PersonGroup](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395244)
 70        /// /
 71        /// [LargePersonGroup](/docs/services/563879b61984550e40cbbe8d/operations/599acdee6ac60f11b48b5a9d)
 72        /// and [Face -
 73        /// Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239).
 74        /// &lt;br /&gt; Please consider
 75        /// [LargeFaceList](/docs/services/563879b61984550e40cbbe8d/operations/5a157b68d2de3616c086f2cc)
 76        /// when the face number is large. It can support up to 1,000,000 faces.
 77        /// &lt;br /&gt;'recognitionModel' should be specified to associate with this
 78        /// face list. The default value for 'recognitionModel' is 'recognition_01', if
 79        /// the latest model needed, please explicitly specify the model you need in
 80        /// this parameter. New faces that are added to an existing face list will use
 81        /// the recognition model that's already associated with the collection.
 82        /// Existing face features in a face list can't be updated to features
 83        /// extracted by another version of recognition model.
 84        /// * 'recognition_01': The default recognition model for [FaceList-
 85        /// Create](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524b).
 86        /// All those 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        /// </summary>
 92        /// <param name='faceListId'>
 93        /// Id referencing a particular face list.
 94        /// </param>
 95        /// <param name='name'>
 96        /// User defined name, maximum length is 128.
 97        /// </param>
 98        /// <param name='userData'>
 99        /// User specified data. Length should not exceed 16KB.
 100        /// </param>
 101        /// <param name='recognitionModel'>
 102        /// Possible values include: 'recognition_01', 'recognition_02'
 103        /// </param>
 104        /// <param name='customHeaders'>
 105        /// Headers that will be added to request.
 106        /// </param>
 107        /// <param name='cancellationToken'>
 108        /// The cancellation token.
 109        /// </param>
 110        /// <exception cref="APIErrorException">
 111        /// Thrown when the operation returned an invalid status code
 112        /// </exception>
 113        /// <exception cref="ValidationException">
 114        /// Thrown when a required parameter is null
 115        /// </exception>
 116        /// <exception cref="System.ArgumentNullException">
 117        /// Thrown when a required parameter is null
 118        /// </exception>
 119        /// <return>
 120        /// A response object containing the response body and response headers.
 121        /// </return>
 122        public async Task<HttpOperationResponse> CreateWithHttpMessagesAsync(string faceListId, string name = default(st
 123        {
 4124            if (Client.Endpoint == null)
 125            {
 0126                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 127            }
 4128            if (faceListId == null)
 129            {
 0130                throw new ValidationException(ValidationRules.CannotBeNull, "faceListId");
 131            }
 4132            if (faceListId != null)
 133            {
 4134                if (faceListId.Length > 64)
 135                {
 0136                    throw new ValidationException(ValidationRules.MaxLength, "faceListId", 64);
 137                }
 4138                if (!System.Text.RegularExpressions.Regex.IsMatch(faceListId, "^[a-z0-9-_]+$"))
 139                {
 0140                    throw new ValidationException(ValidationRules.Pattern, "faceListId", "^[a-z0-9-_]+$");
 141                }
 142            }
 4143            if (name != null)
 144            {
 4145                if (name.Length > 128)
 146                {
 0147                    throw new ValidationException(ValidationRules.MaxLength, "name", 128);
 148                }
 149            }
 4150            if (userData != null)
 151            {
 2152                if (userData.Length > 16384)
 153                {
 0154                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 155                }
 156            }
 4157            MetaDataContract body = new MetaDataContract();
 4158            if (name != null || userData != null || recognitionModel != null)
 159            {
 4160                body.Name = name;
 4161                body.UserData = userData;
 4162                body.RecognitionModel = recognitionModel;
 163            }
 164            // Tracing
 4165            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 4166            string _invocationId = null;
 4167            if (_shouldTrace)
 168            {
 0169                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0170                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0171                tracingParameters.Add("faceListId", faceListId);
 0172                tracingParameters.Add("body", body);
 0173                tracingParameters.Add("cancellationToken", cancellationToken);
 0174                ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters);
 175            }
 176            // Construct URL
 4177            var _baseUrl = Client.BaseUri;
 4178            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "facelists/{faceListId}";
 4179            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 4180            _url = _url.Replace("{faceListId}", System.Uri.EscapeDataString(faceListId));
 181            // Create HTTP transport objects
 4182            var _httpRequest = new HttpRequestMessage();
 4183            HttpResponseMessage _httpResponse = null;
 4184            _httpRequest.Method = new HttpMethod("PUT");
 4185            _httpRequest.RequestUri = new System.Uri(_url);
 186            // Set Headers
 187
 188
 4189            if (customHeaders != null)
 190            {
 0191                foreach(var _header in customHeaders)
 192                {
 0193                    if (_httpRequest.Headers.Contains(_header.Key))
 194                    {
 0195                        _httpRequest.Headers.Remove(_header.Key);
 196                    }
 0197                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 198                }
 199            }
 200
 201            // Serialize Request
 4202            string _requestContent = null;
 4203            if(body != null)
 204            {
 4205                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 4206                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 4207                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 208            }
 209            // Set Credentials
 4210            if (Client.Credentials != null)
 211            {
 4212                cancellationToken.ThrowIfCancellationRequested();
 4213                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 214            }
 215            // Send Request
 4216            if (_shouldTrace)
 217            {
 0218                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 219            }
 4220            cancellationToken.ThrowIfCancellationRequested();
 4221            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4222            if (_shouldTrace)
 223            {
 0224                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 225            }
 4226            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 4227            cancellationToken.ThrowIfCancellationRequested();
 4228            string _responseContent = null;
 4229            if ((int)_statusCode != 200)
 230            {
 0231                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 232                try
 233                {
 0234                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0235                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0236                    if (_errorBody != null)
 237                    {
 0238                        ex.Body = _errorBody;
 239                    }
 0240                }
 0241                catch (JsonException)
 242                {
 243                    // Ignore the exception
 0244                }
 0245                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0246                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0247                if (_shouldTrace)
 248                {
 0249                    ServiceClientTracing.Error(_invocationId, ex);
 250                }
 0251                _httpRequest.Dispose();
 0252                if (_httpResponse != null)
 253                {
 0254                    _httpResponse.Dispose();
 255                }
 0256                throw ex;
 257            }
 258            // Create Result
 4259            var _result = new HttpOperationResponse();
 4260            _result.Request = _httpRequest;
 4261            _result.Response = _httpResponse;
 4262            if (_shouldTrace)
 263            {
 0264                ServiceClientTracing.Exit(_invocationId, _result);
 265            }
 4266            return _result;
 4267        }
 268
 269        /// <summary>
 270        /// Retrieve a face list’s faceListId, name, userData, recognitionModel and
 271        /// faces in the face list.
 272        ///
 273        /// </summary>
 274        /// <param name='faceListId'>
 275        /// Id referencing a particular face list.
 276        /// </param>
 277        /// <param name='returnRecognitionModel'>
 278        /// A value indicating whether the operation should return 'recognitionModel'
 279        /// in response.
 280        /// </param>
 281        /// <param name='customHeaders'>
 282        /// Headers that will be added to request.
 283        /// </param>
 284        /// <param name='cancellationToken'>
 285        /// The cancellation token.
 286        /// </param>
 287        /// <exception cref="APIErrorException">
 288        /// Thrown when the operation returned an invalid status code
 289        /// </exception>
 290        /// <exception cref="SerializationException">
 291        /// Thrown when unable to deserialize the response
 292        /// </exception>
 293        /// <exception cref="ValidationException">
 294        /// Thrown when a required parameter is null
 295        /// </exception>
 296        /// <exception cref="System.ArgumentNullException">
 297        /// Thrown when a required parameter is null
 298        /// </exception>
 299        /// <return>
 300        /// A response object containing the response body and response headers.
 301        /// </return>
 302        public async Task<HttpOperationResponse<FaceList>> GetWithHttpMessagesAsync(string faceListId, bool? returnRecog
 303        {
 2304            if (Client.Endpoint == null)
 305            {
 0306                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 307            }
 2308            if (faceListId == null)
 309            {
 0310                throw new ValidationException(ValidationRules.CannotBeNull, "faceListId");
 311            }
 2312            if (faceListId != null)
 313            {
 2314                if (faceListId.Length > 64)
 315                {
 0316                    throw new ValidationException(ValidationRules.MaxLength, "faceListId", 64);
 317                }
 2318                if (!System.Text.RegularExpressions.Regex.IsMatch(faceListId, "^[a-z0-9-_]+$"))
 319                {
 0320                    throw new ValidationException(ValidationRules.Pattern, "faceListId", "^[a-z0-9-_]+$");
 321                }
 322            }
 323            // Tracing
 2324            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2325            string _invocationId = null;
 2326            if (_shouldTrace)
 327            {
 0328                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0329                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0330                tracingParameters.Add("faceListId", faceListId);
 0331                tracingParameters.Add("returnRecognitionModel", returnRecognitionModel);
 0332                tracingParameters.Add("cancellationToken", cancellationToken);
 0333                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 334            }
 335            // Construct URL
 2336            var _baseUrl = Client.BaseUri;
 2337            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "facelists/{faceListId}";
 2338            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 2339            _url = _url.Replace("{faceListId}", System.Uri.EscapeDataString(faceListId));
 2340            List<string> _queryParameters = new List<string>();
 2341            if (returnRecognitionModel != null)
 342            {
 2343                _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial
 344            }
 2345            if (_queryParameters.Count > 0)
 346            {
 2347                _url += "?" + string.Join("&", _queryParameters);
 348            }
 349            // Create HTTP transport objects
 2350            var _httpRequest = new HttpRequestMessage();
 2351            HttpResponseMessage _httpResponse = null;
 2352            _httpRequest.Method = new HttpMethod("GET");
 2353            _httpRequest.RequestUri = new System.Uri(_url);
 354            // Set Headers
 355
 356
 2357            if (customHeaders != null)
 358            {
 0359                foreach(var _header in customHeaders)
 360                {
 0361                    if (_httpRequest.Headers.Contains(_header.Key))
 362                    {
 0363                        _httpRequest.Headers.Remove(_header.Key);
 364                    }
 0365                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 366                }
 367            }
 368
 369            // Serialize Request
 2370            string _requestContent = null;
 371            // Set Credentials
 2372            if (Client.Credentials != null)
 373            {
 2374                cancellationToken.ThrowIfCancellationRequested();
 2375                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 376            }
 377            // Send Request
 2378            if (_shouldTrace)
 379            {
 0380                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 381            }
 2382            cancellationToken.ThrowIfCancellationRequested();
 2383            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2384            if (_shouldTrace)
 385            {
 0386                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 387            }
 2388            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2389            cancellationToken.ThrowIfCancellationRequested();
 2390            string _responseContent = null;
 2391            if ((int)_statusCode != 200)
 392            {
 0393                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 394                try
 395                {
 0396                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0397                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0398                    if (_errorBody != null)
 399                    {
 0400                        ex.Body = _errorBody;
 401                    }
 0402                }
 0403                catch (JsonException)
 404                {
 405                    // Ignore the exception
 0406                }
 0407                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0408                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0409                if (_shouldTrace)
 410                {
 0411                    ServiceClientTracing.Error(_invocationId, ex);
 412                }
 0413                _httpRequest.Dispose();
 0414                if (_httpResponse != null)
 415                {
 0416                    _httpResponse.Dispose();
 417                }
 0418                throw ex;
 419            }
 420            // Create Result
 2421            var _result = new HttpOperationResponse<FaceList>();
 2422            _result.Request = _httpRequest;
 2423            _result.Response = _httpResponse;
 424            // Deserialize Response
 2425            if ((int)_statusCode == 200)
 426            {
 2427                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 428                try
 429                {
 2430                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<FaceList>(_responseContent, Clie
 2431                }
 0432                catch (JsonException ex)
 433                {
 0434                    _httpRequest.Dispose();
 0435                    if (_httpResponse != null)
 436                    {
 0437                        _httpResponse.Dispose();
 438                    }
 0439                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 440                }
 441            }
 2442            if (_shouldTrace)
 443            {
 0444                ServiceClientTracing.Exit(_invocationId, _result);
 445            }
 2446            return _result;
 2447        }
 448
 449        /// <summary>
 450        /// Update information of a face list.
 451        /// </summary>
 452        /// <param name='faceListId'>
 453        /// Id referencing a particular face list.
 454        /// </param>
 455        /// <param name='name'>
 456        /// User defined name, maximum length is 128.
 457        /// </param>
 458        /// <param name='userData'>
 459        /// User specified data. Length should not exceed 16KB.
 460        /// </param>
 461        /// <param name='customHeaders'>
 462        /// Headers that will be added to request.
 463        /// </param>
 464        /// <param name='cancellationToken'>
 465        /// The cancellation token.
 466        /// </param>
 467        /// <exception cref="APIErrorException">
 468        /// Thrown when the operation returned an invalid status code
 469        /// </exception>
 470        /// <exception cref="ValidationException">
 471        /// Thrown when a required parameter is null
 472        /// </exception>
 473        /// <exception cref="System.ArgumentNullException">
 474        /// Thrown when a required parameter is null
 475        /// </exception>
 476        /// <return>
 477        /// A response object containing the response body and response headers.
 478        /// </return>
 479        public async Task<HttpOperationResponse> UpdateWithHttpMessagesAsync(string faceListId, string name = default(st
 480        {
 0481            if (Client.Endpoint == null)
 482            {
 0483                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 484            }
 0485            if (faceListId == null)
 486            {
 0487                throw new ValidationException(ValidationRules.CannotBeNull, "faceListId");
 488            }
 0489            if (faceListId != null)
 490            {
 0491                if (faceListId.Length > 64)
 492                {
 0493                    throw new ValidationException(ValidationRules.MaxLength, "faceListId", 64);
 494                }
 0495                if (!System.Text.RegularExpressions.Regex.IsMatch(faceListId, "^[a-z0-9-_]+$"))
 496                {
 0497                    throw new ValidationException(ValidationRules.Pattern, "faceListId", "^[a-z0-9-_]+$");
 498                }
 499            }
 0500            if (name != null)
 501            {
 0502                if (name.Length > 128)
 503                {
 0504                    throw new ValidationException(ValidationRules.MaxLength, "name", 128);
 505                }
 506            }
 0507            if (userData != null)
 508            {
 0509                if (userData.Length > 16384)
 510                {
 0511                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 512                }
 513            }
 0514            NameAndUserDataContract body = new NameAndUserDataContract();
 0515            if (name != null || userData != null)
 516            {
 0517                body.Name = name;
 0518                body.UserData = userData;
 519            }
 520            // Tracing
 0521            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0522            string _invocationId = null;
 0523            if (_shouldTrace)
 524            {
 0525                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0526                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0527                tracingParameters.Add("faceListId", faceListId);
 0528                tracingParameters.Add("body", body);
 0529                tracingParameters.Add("cancellationToken", cancellationToken);
 0530                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
 531            }
 532            // Construct URL
 0533            var _baseUrl = Client.BaseUri;
 0534            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "facelists/{faceListId}";
 0535            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0536            _url = _url.Replace("{faceListId}", System.Uri.EscapeDataString(faceListId));
 537            // Create HTTP transport objects
 0538            var _httpRequest = new HttpRequestMessage();
 0539            HttpResponseMessage _httpResponse = null;
 0540            _httpRequest.Method = new HttpMethod("PATCH");
 0541            _httpRequest.RequestUri = new System.Uri(_url);
 542            // Set Headers
 543
 544
 0545            if (customHeaders != null)
 546            {
 0547                foreach(var _header in customHeaders)
 548                {
 0549                    if (_httpRequest.Headers.Contains(_header.Key))
 550                    {
 0551                        _httpRequest.Headers.Remove(_header.Key);
 552                    }
 0553                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 554                }
 555            }
 556
 557            // Serialize Request
 0558            string _requestContent = null;
 0559            if(body != null)
 560            {
 0561                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 0562                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0563                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 564            }
 565            // Set Credentials
 0566            if (Client.Credentials != null)
 567            {
 0568                cancellationToken.ThrowIfCancellationRequested();
 0569                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 570            }
 571            // Send Request
 0572            if (_shouldTrace)
 573            {
 0574                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 575            }
 0576            cancellationToken.ThrowIfCancellationRequested();
 0577            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0578            if (_shouldTrace)
 579            {
 0580                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 581            }
 0582            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0583            cancellationToken.ThrowIfCancellationRequested();
 0584            string _responseContent = null;
 0585            if ((int)_statusCode != 200)
 586            {
 0587                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 588                try
 589                {
 0590                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0591                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0592                    if (_errorBody != null)
 593                    {
 0594                        ex.Body = _errorBody;
 595                    }
 0596                }
 0597                catch (JsonException)
 598                {
 599                    // Ignore the exception
 0600                }
 0601                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0602                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0603                if (_shouldTrace)
 604                {
 0605                    ServiceClientTracing.Error(_invocationId, ex);
 606                }
 0607                _httpRequest.Dispose();
 0608                if (_httpResponse != null)
 609                {
 0610                    _httpResponse.Dispose();
 611                }
 0612                throw ex;
 613            }
 614            // Create Result
 0615            var _result = new HttpOperationResponse();
 0616            _result.Request = _httpRequest;
 0617            _result.Response = _httpResponse;
 0618            if (_shouldTrace)
 619            {
 0620                ServiceClientTracing.Exit(_invocationId, _result);
 621            }
 0622            return _result;
 0623        }
 624
 625        /// <summary>
 626        /// Delete a specified face list.
 627        /// </summary>
 628        /// <param name='faceListId'>
 629        /// Id referencing a particular face list.
 630        /// </param>
 631        /// <param name='customHeaders'>
 632        /// Headers that will be added to request.
 633        /// </param>
 634        /// <param name='cancellationToken'>
 635        /// The cancellation token.
 636        /// </param>
 637        /// <exception cref="APIErrorException">
 638        /// Thrown when the operation returned an invalid status code
 639        /// </exception>
 640        /// <exception cref="ValidationException">
 641        /// Thrown when a required parameter is null
 642        /// </exception>
 643        /// <exception cref="System.ArgumentNullException">
 644        /// Thrown when a required parameter is null
 645        /// </exception>
 646        /// <return>
 647        /// A response object containing the response body and response headers.
 648        /// </return>
 649        public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(string faceListId, Dictionary<string, List<
 650        {
 6651            if (Client.Endpoint == null)
 652            {
 0653                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 654            }
 6655            if (faceListId == null)
 656            {
 0657                throw new ValidationException(ValidationRules.CannotBeNull, "faceListId");
 658            }
 6659            if (faceListId != null)
 660            {
 6661                if (faceListId.Length > 64)
 662                {
 0663                    throw new ValidationException(ValidationRules.MaxLength, "faceListId", 64);
 664                }
 6665                if (!System.Text.RegularExpressions.Regex.IsMatch(faceListId, "^[a-z0-9-_]+$"))
 666                {
 0667                    throw new ValidationException(ValidationRules.Pattern, "faceListId", "^[a-z0-9-_]+$");
 668                }
 669            }
 670            // Tracing
 6671            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 6672            string _invocationId = null;
 6673            if (_shouldTrace)
 674            {
 0675                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0676                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0677                tracingParameters.Add("faceListId", faceListId);
 0678                tracingParameters.Add("cancellationToken", cancellationToken);
 0679                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 680            }
 681            // Construct URL
 6682            var _baseUrl = Client.BaseUri;
 6683            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "facelists/{faceListId}";
 6684            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 6685            _url = _url.Replace("{faceListId}", System.Uri.EscapeDataString(faceListId));
 686            // Create HTTP transport objects
 6687            var _httpRequest = new HttpRequestMessage();
 6688            HttpResponseMessage _httpResponse = null;
 6689            _httpRequest.Method = new HttpMethod("DELETE");
 6690            _httpRequest.RequestUri = new System.Uri(_url);
 691            // Set Headers
 692
 693
 6694            if (customHeaders != null)
 695            {
 0696                foreach(var _header in customHeaders)
 697                {
 0698                    if (_httpRequest.Headers.Contains(_header.Key))
 699                    {
 0700                        _httpRequest.Headers.Remove(_header.Key);
 701                    }
 0702                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 703                }
 704            }
 705
 706            // Serialize Request
 6707            string _requestContent = null;
 708            // Set Credentials
 6709            if (Client.Credentials != null)
 710            {
 6711                cancellationToken.ThrowIfCancellationRequested();
 6712                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 713            }
 714            // Send Request
 6715            if (_shouldTrace)
 716            {
 0717                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 718            }
 6719            cancellationToken.ThrowIfCancellationRequested();
 6720            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 6721            if (_shouldTrace)
 722            {
 0723                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 724            }
 6725            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 6726            cancellationToken.ThrowIfCancellationRequested();
 6727            string _responseContent = null;
 6728            if ((int)_statusCode != 200)
 729            {
 0730                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 731                try
 732                {
 0733                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0734                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0735                    if (_errorBody != null)
 736                    {
 0737                        ex.Body = _errorBody;
 738                    }
 0739                }
 0740                catch (JsonException)
 741                {
 742                    // Ignore the exception
 0743                }
 0744                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0745                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0746                if (_shouldTrace)
 747                {
 0748                    ServiceClientTracing.Error(_invocationId, ex);
 749                }
 0750                _httpRequest.Dispose();
 0751                if (_httpResponse != null)
 752                {
 0753                    _httpResponse.Dispose();
 754                }
 0755                throw ex;
 756            }
 757            // Create Result
 6758            var _result = new HttpOperationResponse();
 6759            _result.Request = _httpRequest;
 6760            _result.Response = _httpResponse;
 6761            if (_shouldTrace)
 762            {
 0763                ServiceClientTracing.Exit(_invocationId, _result);
 764            }
 6765            return _result;
 6766        }
 767
 768        /// <summary>
 769        /// List face lists’ faceListId, name, userData and recognitionModel. &lt;br
 770        /// /&gt;
 771        /// To get face information inside faceList use [FaceList -
 772        /// Get](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524c)
 773        ///
 774        /// </summary>
 775        /// <param name='returnRecognitionModel'>
 776        /// A value indicating whether the operation should return 'recognitionModel'
 777        /// in response.
 778        /// </param>
 779        /// <param name='customHeaders'>
 780        /// Headers that will be added to request.
 781        /// </param>
 782        /// <param name='cancellationToken'>
 783        /// The cancellation token.
 784        /// </param>
 785        /// <exception cref="APIErrorException">
 786        /// Thrown when the operation returned an invalid status code
 787        /// </exception>
 788        /// <exception cref="SerializationException">
 789        /// Thrown when unable to deserialize the response
 790        /// </exception>
 791        /// <exception cref="ValidationException">
 792        /// Thrown when a required parameter is null
 793        /// </exception>
 794        /// <exception cref="System.ArgumentNullException">
 795        /// Thrown when a required parameter is null
 796        /// </exception>
 797        /// <return>
 798        /// A response object containing the response body and response headers.
 799        /// </return>
 800        public async Task<HttpOperationResponse<IList<FaceList>>> ListWithHttpMessagesAsync(bool? returnRecognitionModel
 801        {
 0802            if (Client.Endpoint == null)
 803            {
 0804                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 805            }
 806            // Tracing
 0807            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0808            string _invocationId = null;
 0809            if (_shouldTrace)
 810            {
 0811                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0812                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0813                tracingParameters.Add("returnRecognitionModel", returnRecognitionModel);
 0814                tracingParameters.Add("cancellationToken", cancellationToken);
 0815                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 816            }
 817            // Construct URL
 0818            var _baseUrl = Client.BaseUri;
 0819            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "facelists";
 0820            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0821            List<string> _queryParameters = new List<string>();
 0822            if (returnRecognitionModel != null)
 823            {
 0824                _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial
 825            }
 0826            if (_queryParameters.Count > 0)
 827            {
 0828                _url += "?" + string.Join("&", _queryParameters);
 829            }
 830            // Create HTTP transport objects
 0831            var _httpRequest = new HttpRequestMessage();
 0832            HttpResponseMessage _httpResponse = null;
 0833            _httpRequest.Method = new HttpMethod("GET");
 0834            _httpRequest.RequestUri = new System.Uri(_url);
 835            // Set Headers
 836
 837
 0838            if (customHeaders != null)
 839            {
 0840                foreach(var _header in customHeaders)
 841                {
 0842                    if (_httpRequest.Headers.Contains(_header.Key))
 843                    {
 0844                        _httpRequest.Headers.Remove(_header.Key);
 845                    }
 0846                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 847                }
 848            }
 849
 850            // Serialize Request
 0851            string _requestContent = null;
 852            // Set Credentials
 0853            if (Client.Credentials != null)
 854            {
 0855                cancellationToken.ThrowIfCancellationRequested();
 0856                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 857            }
 858            // Send Request
 0859            if (_shouldTrace)
 860            {
 0861                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 862            }
 0863            cancellationToken.ThrowIfCancellationRequested();
 0864            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0865            if (_shouldTrace)
 866            {
 0867                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 868            }
 0869            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0870            cancellationToken.ThrowIfCancellationRequested();
 0871            string _responseContent = null;
 0872            if ((int)_statusCode != 200)
 873            {
 0874                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 875                try
 876                {
 0877                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0878                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0879                    if (_errorBody != null)
 880                    {
 0881                        ex.Body = _errorBody;
 882                    }
 0883                }
 0884                catch (JsonException)
 885                {
 886                    // Ignore the exception
 0887                }
 0888                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0889                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0890                if (_shouldTrace)
 891                {
 0892                    ServiceClientTracing.Error(_invocationId, ex);
 893                }
 0894                _httpRequest.Dispose();
 0895                if (_httpResponse != null)
 896                {
 0897                    _httpResponse.Dispose();
 898                }
 0899                throw ex;
 900            }
 901            // Create Result
 0902            var _result = new HttpOperationResponse<IList<FaceList>>();
 0903            _result.Request = _httpRequest;
 0904            _result.Response = _httpResponse;
 905            // Deserialize Response
 0906            if ((int)_statusCode == 200)
 907            {
 0908                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 909                try
 910                {
 0911                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<FaceList>>(_responseConten
 0912                }
 0913                catch (JsonException ex)
 914                {
 0915                    _httpRequest.Dispose();
 0916                    if (_httpResponse != null)
 917                    {
 0918                        _httpResponse.Dispose();
 919                    }
 0920                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 921                }
 922            }
 0923            if (_shouldTrace)
 924            {
 0925                ServiceClientTracing.Exit(_invocationId, _result);
 926            }
 0927            return _result;
 0928        }
 929
 930        /// <summary>
 931        /// Delete a face from a face list by specified faceListId and persistedFaceId.
 932        /// &lt;br /&gt; Adding/deleting faces to/from a same face list are processed
 933        /// sequentially and to/from different face lists are in parallel.
 934        /// </summary>
 935        /// <param name='faceListId'>
 936        /// Id referencing a particular face list.
 937        /// </param>
 938        /// <param name='persistedFaceId'>
 939        /// Id referencing a particular persistedFaceId of an existing face.
 940        /// </param>
 941        /// <param name='customHeaders'>
 942        /// Headers that will be added to request.
 943        /// </param>
 944        /// <param name='cancellationToken'>
 945        /// The cancellation token.
 946        /// </param>
 947        /// <exception cref="APIErrorException">
 948        /// Thrown when the operation returned an invalid status code
 949        /// </exception>
 950        /// <exception cref="ValidationException">
 951        /// Thrown when a required parameter is null
 952        /// </exception>
 953        /// <exception cref="System.ArgumentNullException">
 954        /// Thrown when a required parameter is null
 955        /// </exception>
 956        /// <return>
 957        /// A response object containing the response body and response headers.
 958        /// </return>
 959        public async Task<HttpOperationResponse> DeleteFaceWithHttpMessagesAsync(string faceListId, System.Guid persiste
 960        {
 0961            if (Client.Endpoint == null)
 962            {
 0963                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 964            }
 0965            if (faceListId == null)
 966            {
 0967                throw new ValidationException(ValidationRules.CannotBeNull, "faceListId");
 968            }
 0969            if (faceListId != null)
 970            {
 0971                if (faceListId.Length > 64)
 972                {
 0973                    throw new ValidationException(ValidationRules.MaxLength, "faceListId", 64);
 974                }
 0975                if (!System.Text.RegularExpressions.Regex.IsMatch(faceListId, "^[a-z0-9-_]+$"))
 976                {
 0977                    throw new ValidationException(ValidationRules.Pattern, "faceListId", "^[a-z0-9-_]+$");
 978                }
 979            }
 980            // Tracing
 0981            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0982            string _invocationId = null;
 0983            if (_shouldTrace)
 984            {
 0985                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0986                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0987                tracingParameters.Add("faceListId", faceListId);
 0988                tracingParameters.Add("persistedFaceId", persistedFaceId);
 0989                tracingParameters.Add("cancellationToken", cancellationToken);
 0990                ServiceClientTracing.Enter(_invocationId, this, "DeleteFace", tracingParameters);
 991            }
 992            // Construct URL
 0993            var _baseUrl = Client.BaseUri;
 0994            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "facelists/{faceListId}/persistedfaces/{persiste
 0995            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0996            _url = _url.Replace("{faceListId}", System.Uri.EscapeDataString(faceListId));
 0997            _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri
 998            // Create HTTP transport objects
 0999            var _httpRequest = new HttpRequestMessage();
 01000            HttpResponseMessage _httpResponse = null;
 01001            _httpRequest.Method = new HttpMethod("DELETE");
 01002            _httpRequest.RequestUri = new System.Uri(_url);
 1003            // Set Headers
 1004
 1005
 01006            if (customHeaders != null)
 1007            {
 01008                foreach(var _header in customHeaders)
 1009                {
 01010                    if (_httpRequest.Headers.Contains(_header.Key))
 1011                    {
 01012                        _httpRequest.Headers.Remove(_header.Key);
 1013                    }
 01014                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1015                }
 1016            }
 1017
 1018            // Serialize Request
 01019            string _requestContent = null;
 1020            // Set Credentials
 01021            if (Client.Credentials != null)
 1022            {
 01023                cancellationToken.ThrowIfCancellationRequested();
 01024                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1025            }
 1026            // Send Request
 01027            if (_shouldTrace)
 1028            {
 01029                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1030            }
 01031            cancellationToken.ThrowIfCancellationRequested();
 01032            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01033            if (_shouldTrace)
 1034            {
 01035                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1036            }
 01037            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01038            cancellationToken.ThrowIfCancellationRequested();
 01039            string _responseContent = null;
 01040            if ((int)_statusCode != 200)
 1041            {
 01042                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1043                try
 1044                {
 01045                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01046                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01047                    if (_errorBody != null)
 1048                    {
 01049                        ex.Body = _errorBody;
 1050                    }
 01051                }
 01052                catch (JsonException)
 1053                {
 1054                    // Ignore the exception
 01055                }
 01056                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01057                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01058                if (_shouldTrace)
 1059                {
 01060                    ServiceClientTracing.Error(_invocationId, ex);
 1061                }
 01062                _httpRequest.Dispose();
 01063                if (_httpResponse != null)
 1064                {
 01065                    _httpResponse.Dispose();
 1066                }
 01067                throw ex;
 1068            }
 1069            // Create Result
 01070            var _result = new HttpOperationResponse();
 01071            _result.Request = _httpRequest;
 01072            _result.Response = _httpResponse;
 01073            if (_shouldTrace)
 1074            {
 01075                ServiceClientTracing.Exit(_invocationId, _result);
 1076            }
 01077            return _result;
 01078        }
 1079
 1080        /// <summary>
 1081        /// Add a face to a specified face list, up to 1,000 faces.
 1082        /// &lt;br /&gt; To deal with an image contains multiple faces, input face can
 1083        /// be specified as an image with a targetFace rectangle. It returns a
 1084        /// persistedFaceId representing the added face. No image will be stored. Only
 1085        /// the extracted face feature will be stored on server until [FaceList -
 1086        /// Delete
 1087        /// Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395251)
 1088        /// or [FaceList -
 1089        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524f)
 1090        /// is called.
 1091        /// &lt;br /&gt; Note persistedFaceId is different from faceId generated by
 1092        /// [Face -
 1093        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 1094        /// * Higher face image quality means better detection and recognition
 1095        /// precision. Please consider high-quality faces: frontal, clear, and face
 1096        /// size is 200x200 pixels (100 pixels between eyes) or bigger.
 1097        /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The
 1098        /// allowed image file size is from 1KB to 6MB.
 1099        /// * "targetFace" rectangle should contain one face. Zero or multiple faces
 1100        /// will be regarded as an error. If the provided "targetFace" rectangle is not
 1101        /// returned from [Face -
 1102        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
 1103        /// there’s no guarantee to detect and add the face successfully.
 1104        /// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
 1105        /// or large occlusions will cause failures.
 1106        /// * Adding/deleting faces to/from a same face list are processed sequentially
 1107        /// and to/from different face lists are in parallel.
 1108        /// * The minimum detectable face size is 36x36 pixels in an image no larger
 1109        /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels
 1110        /// will need a proportionally larger minimum face size.
 1111        /// * Different 'detectionModel' values can be provided. To use and compare
 1112        /// different detection models, please refer to [How to specify a detection
 1113        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti
 1114        /// | Model | Recommended use-case(s) |
 1115        /// | ---------- | -------- |
 1116        /// | 'detection_01': | The default detection model for [FaceList - Add
 1117        /// Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395250).
 1118        /// Recommend for near frontal face detection. For scenarios with exceptionally
 1119        /// large angle (head-pose) faces, occluded faces or wrong image orientation,
 1120        /// the faces in such cases may not be detected. |
 1121        /// | 'detection_02': | Detection model released in 2019 May with improved
 1122        /// accuracy especially on small, side and blurry faces. |
 1123        /// </summary>
 1124        /// <param name='faceListId'>
 1125        /// Id referencing a particular face list.
 1126        /// </param>
 1127        /// <param name='url'>
 1128        /// Publicly reachable URL of an image
 1129        /// </param>
 1130        /// <param name='userData'>
 1131        /// User-specified data about the face for any purpose. The maximum length is
 1132        /// 1KB.
 1133        /// </param>
 1134        /// <param name='targetFace'>
 1135        /// A face rectangle to specify the target face to be added to a person in the
 1136        /// format of "targetFace=left,top,width,height". E.g.
 1137        /// "targetFace=10,10,100,100". If there is more than one face in the image,
 1138        /// targetFace is required to specify which face to add. No targetFace means
 1139        /// there is only one face detected in the entire image.
 1140        /// </param>
 1141        /// <param name='detectionModel'>
 1142        /// Name of detection model. Detection model is used to detect faces in the
 1143        /// submitted image. A detection model name can be provided when performing
 1144        /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add
 1145        /// Face. The default value is 'detection_01', if another model is needed,
 1146        /// please explicitly specify it. Possible values include: 'detection_01',
 1147        /// 'detection_02'
 1148        /// </param>
 1149        /// <param name='customHeaders'>
 1150        /// Headers that will be added to request.
 1151        /// </param>
 1152        /// <param name='cancellationToken'>
 1153        /// The cancellation token.
 1154        /// </param>
 1155        /// <exception cref="APIErrorException">
 1156        /// Thrown when the operation returned an invalid status code
 1157        /// </exception>
 1158        /// <exception cref="SerializationException">
 1159        /// Thrown when unable to deserialize the response
 1160        /// </exception>
 1161        /// <exception cref="ValidationException">
 1162        /// Thrown when a required parameter is null
 1163        /// </exception>
 1164        /// <exception cref="System.ArgumentNullException">
 1165        /// Thrown when a required parameter is null
 1166        /// </exception>
 1167        /// <return>
 1168        /// A response object containing the response body and response headers.
 1169        /// </return>
 1170        public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromUrlWithHttpMessagesAsync(string faceListId, s
 1171        {
 01172            if (Client.Endpoint == null)
 1173            {
 01174                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1175            }
 01176            if (faceListId == null)
 1177            {
 01178                throw new ValidationException(ValidationRules.CannotBeNull, "faceListId");
 1179            }
 01180            if (faceListId != null)
 1181            {
 01182                if (faceListId.Length > 64)
 1183                {
 01184                    throw new ValidationException(ValidationRules.MaxLength, "faceListId", 64);
 1185                }
 01186                if (!System.Text.RegularExpressions.Regex.IsMatch(faceListId, "^[a-z0-9-_]+$"))
 1187                {
 01188                    throw new ValidationException(ValidationRules.Pattern, "faceListId", "^[a-z0-9-_]+$");
 1189                }
 1190            }
 01191            if (userData != null)
 1192            {
 01193                if (userData.Length > 1024)
 1194                {
 01195                    throw new ValidationException(ValidationRules.MaxLength, "userData", 1024);
 1196                }
 1197            }
 01198            if (url == null)
 1199            {
 01200                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 1201            }
 01202            ImageUrl imageUrl = new ImageUrl();
 01203            if (url != null)
 1204            {
 01205                imageUrl.Url = url;
 1206            }
 1207            // Tracing
 01208            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01209            string _invocationId = null;
 01210            if (_shouldTrace)
 1211            {
 01212                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01213                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01214                tracingParameters.Add("faceListId", faceListId);
 01215                tracingParameters.Add("userData", userData);
 01216                tracingParameters.Add("targetFace", targetFace);
 01217                tracingParameters.Add("detectionModel", detectionModel);
 01218                tracingParameters.Add("imageUrl", imageUrl);
 01219                tracingParameters.Add("cancellationToken", cancellationToken);
 01220                ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromUrl", tracingParameters);
 1221            }
 1222            // Construct URL
 01223            var _baseUrl = Client.BaseUri;
 01224            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "facelists/{faceListId}/persistedfaces";
 01225            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01226            _url = _url.Replace("{faceListId}", System.Uri.EscapeDataString(faceListId));
 01227            List<string> _queryParameters = new List<string>();
 01228            if (userData != null)
 1229            {
 01230                _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData)));
 1231            }
 01232            if (targetFace != null)
 1233            {
 01234                _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target
 1235            }
 01236            if (detectionModel != null)
 1237            {
 01238                _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel)));
 1239            }
 01240            if (_queryParameters.Count > 0)
 1241            {
 01242                _url += "?" + string.Join("&", _queryParameters);
 1243            }
 1244            // Create HTTP transport objects
 01245            var _httpRequest = new HttpRequestMessage();
 01246            HttpResponseMessage _httpResponse = null;
 01247            _httpRequest.Method = new HttpMethod("POST");
 01248            _httpRequest.RequestUri = new System.Uri(_url);
 1249            // Set Headers
 1250
 1251
 01252            if (customHeaders != null)
 1253            {
 01254                foreach(var _header in customHeaders)
 1255                {
 01256                    if (_httpRequest.Headers.Contains(_header.Key))
 1257                    {
 01258                        _httpRequest.Headers.Remove(_header.Key);
 1259                    }
 01260                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1261                }
 1262            }
 1263
 1264            // Serialize Request
 01265            string _requestContent = null;
 01266            if(imageUrl != null)
 1267            {
 01268                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti
 01269                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01270                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1271            }
 1272            // Set Credentials
 01273            if (Client.Credentials != null)
 1274            {
 01275                cancellationToken.ThrowIfCancellationRequested();
 01276                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1277            }
 1278            // Send Request
 01279            if (_shouldTrace)
 1280            {
 01281                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1282            }
 01283            cancellationToken.ThrowIfCancellationRequested();
 01284            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01285            if (_shouldTrace)
 1286            {
 01287                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1288            }
 01289            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01290            cancellationToken.ThrowIfCancellationRequested();
 01291            string _responseContent = null;
 01292            if ((int)_statusCode != 200)
 1293            {
 01294                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1295                try
 1296                {
 01297                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01298                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01299                    if (_errorBody != null)
 1300                    {
 01301                        ex.Body = _errorBody;
 1302                    }
 01303                }
 01304                catch (JsonException)
 1305                {
 1306                    // Ignore the exception
 01307                }
 01308                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01309                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01310                if (_shouldTrace)
 1311                {
 01312                    ServiceClientTracing.Error(_invocationId, ex);
 1313                }
 01314                _httpRequest.Dispose();
 01315                if (_httpResponse != null)
 1316                {
 01317                    _httpResponse.Dispose();
 1318                }
 01319                throw ex;
 1320            }
 1321            // Create Result
 01322            var _result = new HttpOperationResponse<PersistedFace>();
 01323            _result.Request = _httpRequest;
 01324            _result.Response = _httpResponse;
 1325            // Deserialize Response
 01326            if ((int)_statusCode == 200)
 1327            {
 01328                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1329                try
 1330                {
 01331                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent,
 01332                }
 01333                catch (JsonException ex)
 1334                {
 01335                    _httpRequest.Dispose();
 01336                    if (_httpResponse != null)
 1337                    {
 01338                        _httpResponse.Dispose();
 1339                    }
 01340                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1341                }
 1342            }
 01343            if (_shouldTrace)
 1344            {
 01345                ServiceClientTracing.Exit(_invocationId, _result);
 1346            }
 01347            return _result;
 01348        }
 1349
 1350        /// <summary>
 1351        /// Add a face to a specified face list, up to 1,000 faces.
 1352        /// &lt;br /&gt; To deal with an image contains multiple faces, input face can
 1353        /// be specified as an image with a targetFace rectangle. It returns a
 1354        /// persistedFaceId representing the added face. No image will be stored. Only
 1355        /// the extracted face feature will be stored on server until [FaceList -
 1356        /// Delete
 1357        /// Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395251)
 1358        /// or [FaceList -
 1359        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524f)
 1360        /// is called.
 1361        /// &lt;br /&gt; Note persistedFaceId is different from faceId generated by
 1362        /// [Face -
 1363        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 1364        /// * Higher face image quality means better detection and recognition
 1365        /// precision. Please consider high-quality faces: frontal, clear, and face
 1366        /// size is 200x200 pixels (100 pixels between eyes) or bigger.
 1367        /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The
 1368        /// allowed image file size is from 1KB to 6MB.
 1369        /// * "targetFace" rectangle should contain one face. Zero or multiple faces
 1370        /// will be regarded as an error. If the provided "targetFace" rectangle is not
 1371        /// returned from [Face -
 1372        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
 1373        /// there’s no guarantee to detect and add the face successfully.
 1374        /// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
 1375        /// or large occlusions will cause failures.
 1376        /// * Adding/deleting faces to/from a same face list are processed sequentially
 1377        /// and to/from different face lists are in parallel.
 1378        /// * The minimum detectable face size is 36x36 pixels in an image no larger
 1379        /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels
 1380        /// will need a proportionally larger minimum face size.
 1381        /// * Different 'detectionModel' values can be provided. To use and compare
 1382        /// different detection models, please refer to [How to specify a detection
 1383        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti
 1384        /// | Model | Recommended use-case(s) |
 1385        /// | ---------- | -------- |
 1386        /// | 'detection_01': | The default detection model for [FaceList - Add
 1387        /// Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395250).
 1388        /// Recommend for near frontal face detection. For scenarios with exceptionally
 1389        /// large angle (head-pose) faces, occluded faces or wrong image orientation,
 1390        /// the faces in such cases may not be detected. |
 1391        /// | 'detection_02': | Detection model released in 2019 May with improved
 1392        /// accuracy especially on small, side and blurry faces. |
 1393        /// </summary>
 1394        /// <param name='faceListId'>
 1395        /// Id referencing a particular face list.
 1396        /// </param>
 1397        /// <param name='image'>
 1398        /// An image stream.
 1399        /// </param>
 1400        /// <param name='userData'>
 1401        /// User-specified data about the face for any purpose. The maximum length is
 1402        /// 1KB.
 1403        /// </param>
 1404        /// <param name='targetFace'>
 1405        /// A face rectangle to specify the target face to be added to a person in the
 1406        /// format of "targetFace=left,top,width,height". E.g.
 1407        /// "targetFace=10,10,100,100". If there is more than one face in the image,
 1408        /// targetFace is required to specify which face to add. No targetFace means
 1409        /// there is only one face detected in the entire image.
 1410        /// </param>
 1411        /// <param name='detectionModel'>
 1412        /// Name of detection model. Detection model is used to detect faces in the
 1413        /// submitted image. A detection model name can be provided when performing
 1414        /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add
 1415        /// Face. The default value is 'detection_01', if another model is needed,
 1416        /// please explicitly specify it. Possible values include: 'detection_01',
 1417        /// 'detection_02'
 1418        /// </param>
 1419        /// <param name='customHeaders'>
 1420        /// Headers that will be added to request.
 1421        /// </param>
 1422        /// <param name='cancellationToken'>
 1423        /// The cancellation token.
 1424        /// </param>
 1425        /// <exception cref="APIErrorException">
 1426        /// Thrown when the operation returned an invalid status code
 1427        /// </exception>
 1428        /// <exception cref="SerializationException">
 1429        /// Thrown when unable to deserialize the response
 1430        /// </exception>
 1431        /// <exception cref="ValidationException">
 1432        /// Thrown when a required parameter is null
 1433        /// </exception>
 1434        /// <exception cref="System.ArgumentNullException">
 1435        /// Thrown when a required parameter is null
 1436        /// </exception>
 1437        /// <return>
 1438        /// A response object containing the response body and response headers.
 1439        /// </return>
 1440        public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromStreamWithHttpMessagesAsync(string faceListId
 1441        {
 141442            if (Client.Endpoint == null)
 1443            {
 01444                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1445            }
 141446            if (faceListId == null)
 1447            {
 01448                throw new ValidationException(ValidationRules.CannotBeNull, "faceListId");
 1449            }
 141450            if (faceListId != null)
 1451            {
 141452                if (faceListId.Length > 64)
 1453                {
 01454                    throw new ValidationException(ValidationRules.MaxLength, "faceListId", 64);
 1455                }
 141456                if (!System.Text.RegularExpressions.Regex.IsMatch(faceListId, "^[a-z0-9-_]+$"))
 1457                {
 01458                    throw new ValidationException(ValidationRules.Pattern, "faceListId", "^[a-z0-9-_]+$");
 1459                }
 1460            }
 141461            if (userData != null)
 1462            {
 01463                if (userData.Length > 1024)
 1464                {
 01465                    throw new ValidationException(ValidationRules.MaxLength, "userData", 1024);
 1466                }
 1467            }
 141468            if (image == null)
 1469            {
 01470                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 1471            }
 1472            // Tracing
 141473            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 141474            string _invocationId = null;
 141475            if (_shouldTrace)
 1476            {
 01477                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01478                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01479                tracingParameters.Add("faceListId", faceListId);
 01480                tracingParameters.Add("userData", userData);
 01481                tracingParameters.Add("targetFace", targetFace);
 01482                tracingParameters.Add("image", image);
 01483                tracingParameters.Add("detectionModel", detectionModel);
 01484                tracingParameters.Add("cancellationToken", cancellationToken);
 01485                ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromStream", tracingParameters);
 1486            }
 1487            // Construct URL
 141488            var _baseUrl = Client.BaseUri;
 141489            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "facelists/{faceListId}/persistedfaces";
 141490            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 141491            _url = _url.Replace("{faceListId}", System.Uri.EscapeDataString(faceListId));
 141492            List<string> _queryParameters = new List<string>();
 141493            if (userData != null)
 1494            {
 01495                _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData)));
 1496            }
 141497            if (targetFace != null)
 1498            {
 121499                _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target
 1500            }
 141501            if (detectionModel != null)
 1502            {
 141503                _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel)));
 1504            }
 141505            if (_queryParameters.Count > 0)
 1506            {
 141507                _url += "?" + string.Join("&", _queryParameters);
 1508            }
 1509            // Create HTTP transport objects
 141510            var _httpRequest = new HttpRequestMessage();
 141511            HttpResponseMessage _httpResponse = null;
 141512            _httpRequest.Method = new HttpMethod("POST");
 141513            _httpRequest.RequestUri = new System.Uri(_url);
 1514            // Set Headers
 1515
 1516
 141517            if (customHeaders != null)
 1518            {
 01519                foreach(var _header in customHeaders)
 1520                {
 01521                    if (_httpRequest.Headers.Contains(_header.Key))
 1522                    {
 01523                        _httpRequest.Headers.Remove(_header.Key);
 1524                    }
 01525                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1526                }
 1527            }
 1528
 1529            // Serialize Request
 141530            string _requestContent = null;
 141531            if(image == null)
 1532            {
 01533              throw new System.ArgumentNullException("image");
 1534            }
 141535            if (image != null && image != Stream.Null)
 1536            {
 141537                _httpRequest.Content = new StreamContent(image);
 141538                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1539            }
 1540            // Set Credentials
 141541            if (Client.Credentials != null)
 1542            {
 141543                cancellationToken.ThrowIfCancellationRequested();
 141544                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1545            }
 1546            // Send Request
 141547            if (_shouldTrace)
 1548            {
 01549                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1550            }
 141551            cancellationToken.ThrowIfCancellationRequested();
 141552            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 141553            if (_shouldTrace)
 1554            {
 01555                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1556            }
 141557            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 141558            cancellationToken.ThrowIfCancellationRequested();
 141559            string _responseContent = null;
 141560            if ((int)_statusCode != 200)
 1561            {
 01562                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1563                try
 1564                {
 01565                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01566                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01567                    if (_errorBody != null)
 1568                    {
 01569                        ex.Body = _errorBody;
 1570                    }
 01571                }
 01572                catch (JsonException)
 1573                {
 1574                    // Ignore the exception
 01575                }
 01576                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01577                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01578                if (_shouldTrace)
 1579                {
 01580                    ServiceClientTracing.Error(_invocationId, ex);
 1581                }
 01582                _httpRequest.Dispose();
 01583                if (_httpResponse != null)
 1584                {
 01585                    _httpResponse.Dispose();
 1586                }
 01587                throw ex;
 1588            }
 1589            // Create Result
 141590            var _result = new HttpOperationResponse<PersistedFace>();
 141591            _result.Request = _httpRequest;
 141592            _result.Response = _httpResponse;
 1593            // Deserialize Response
 141594            if ((int)_statusCode == 200)
 1595            {
 141596                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1597                try
 1598                {
 141599                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent,
 141600                }
 01601                catch (JsonException ex)
 1602                {
 01603                    _httpRequest.Dispose();
 01604                    if (_httpResponse != null)
 1605                    {
 01606                        _httpResponse.Dispose();
 1607                    }
 01608                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1609                }
 1610            }
 141611            if (_shouldTrace)
 1612            {
 01613                ServiceClientTracing.Exit(_invocationId, _result);
 1614            }
 141615            return _result;
 141616        }
 1617
 1618    }
 1619}