< Summary

Class:Microsoft.Azure.CognitiveServices.Vision.Face.LargePersonGroupPerson
Assembly:Microsoft.Azure.CognitiveServices.Vision.Face
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\LargePersonGroupPerson.cs
Covered lines:191
Uncovered lines:663
Coverable lines:854
Total lines:2013
Line coverage:22.3% (191 of 854)
Covered branches:95
Total branches:470
Branch coverage:20.2% (95 of 470)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
CreateWithHttpMessagesAsync()-56.04%51.85%
ListWithHttpMessagesAsync()-0%0%
DeleteWithHttpMessagesAsync()-0%0%
GetWithHttpMessagesAsync()-51.28%42.5%
UpdateWithHttpMessagesAsync()-0%0%
DeleteFaceWithHttpMessagesAsync()-0%0%
GetFaceWithHttpMessagesAsync()-51.25%42.5%
UpdateFaceWithHttpMessagesAsync()-0%0%
AddFaceFromUrlWithHttpMessagesAsync()-0%0%
AddFaceFromStreamWithHttpMessagesAsync()-53.47%53.33%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\LargePersonGroupPerson.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    /// LargePersonGroupPerson operations.
 27    /// </summary>
 28    public partial class LargePersonGroupPerson : IServiceOperations<FaceClient>, ILargePersonGroupPerson
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the LargePersonGroupPerson 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 LargePersonGroupPerson(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>
 29251        public FaceClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Create a new person in a specified large person group.
 55        /// </summary>
 56        /// <param name='largePersonGroupId'>
 57        /// Id referencing a particular large person group.
 58        /// </param>
 59        /// <param name='name'>
 60        /// User defined name, maximum length is 128.
 61        /// </param>
 62        /// <param name='userData'>
 63        /// User specified data. Length should not exceed 16KB.
 64        /// </param>
 65        /// <param name='customHeaders'>
 66        /// Headers that will be added to request.
 67        /// </param>
 68        /// <param name='cancellationToken'>
 69        /// The cancellation token.
 70        /// </param>
 71        /// <exception cref="APIErrorException">
 72        /// Thrown when the operation returned an invalid status code
 73        /// </exception>
 74        /// <exception cref="SerializationException">
 75        /// Thrown when unable to deserialize the response
 76        /// </exception>
 77        /// <exception cref="ValidationException">
 78        /// Thrown when a required parameter is null
 79        /// </exception>
 80        /// <exception cref="System.ArgumentNullException">
 81        /// Thrown when a required parameter is null
 82        /// </exception>
 83        /// <return>
 84        /// A response object containing the response body and response headers.
 85        /// </return>
 86        public async Task<HttpOperationResponse<Person>> CreateWithHttpMessagesAsync(string largePersonGroupId, string n
 87        {
 1088            if (Client.Endpoint == null)
 89            {
 090                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 91            }
 1092            if (largePersonGroupId == null)
 93            {
 094                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 95            }
 1096            if (largePersonGroupId != null)
 97            {
 1098                if (largePersonGroupId.Length > 64)
 99                {
 0100                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 101                }
 10102                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 103                {
 0104                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 105                }
 106            }
 10107            if (name != null)
 108            {
 10109                if (name.Length > 128)
 110                {
 0111                    throw new ValidationException(ValidationRules.MaxLength, "name", 128);
 112                }
 113            }
 10114            if (userData != null)
 115            {
 2116                if (userData.Length > 16384)
 117                {
 0118                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 119                }
 120            }
 10121            NameAndUserDataContract body = new NameAndUserDataContract();
 10122            if (name != null || userData != null)
 123            {
 10124                body.Name = name;
 10125                body.UserData = userData;
 126            }
 127            // Tracing
 10128            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 10129            string _invocationId = null;
 10130            if (_shouldTrace)
 131            {
 0132                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0133                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0134                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 0135                tracingParameters.Add("body", body);
 0136                tracingParameters.Add("cancellationToken", cancellationToken);
 0137                ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters);
 138            }
 139            // Construct URL
 10140            var _baseUrl = Client.BaseUri;
 10141            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/persons"
 10142            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 10143            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 144            // Create HTTP transport objects
 10145            var _httpRequest = new HttpRequestMessage();
 10146            HttpResponseMessage _httpResponse = null;
 10147            _httpRequest.Method = new HttpMethod("POST");
 10148            _httpRequest.RequestUri = new System.Uri(_url);
 149            // Set Headers
 150
 151
 10152            if (customHeaders != null)
 153            {
 0154                foreach(var _header in customHeaders)
 155                {
 0156                    if (_httpRequest.Headers.Contains(_header.Key))
 157                    {
 0158                        _httpRequest.Headers.Remove(_header.Key);
 159                    }
 0160                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 161                }
 162            }
 163
 164            // Serialize Request
 10165            string _requestContent = null;
 10166            if(body != null)
 167            {
 10168                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 10169                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 10170                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 171            }
 172            // Set Credentials
 10173            if (Client.Credentials != null)
 174            {
 10175                cancellationToken.ThrowIfCancellationRequested();
 10176                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 177            }
 178            // Send Request
 10179            if (_shouldTrace)
 180            {
 0181                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 182            }
 10183            cancellationToken.ThrowIfCancellationRequested();
 10184            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 10185            if (_shouldTrace)
 186            {
 0187                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 188            }
 10189            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 10190            cancellationToken.ThrowIfCancellationRequested();
 10191            string _responseContent = null;
 10192            if ((int)_statusCode != 200)
 193            {
 0194                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 195                try
 196                {
 0197                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0198                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0199                    if (_errorBody != null)
 200                    {
 0201                        ex.Body = _errorBody;
 202                    }
 0203                }
 0204                catch (JsonException)
 205                {
 206                    // Ignore the exception
 0207                }
 0208                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0209                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0210                if (_shouldTrace)
 211                {
 0212                    ServiceClientTracing.Error(_invocationId, ex);
 213                }
 0214                _httpRequest.Dispose();
 0215                if (_httpResponse != null)
 216                {
 0217                    _httpResponse.Dispose();
 218                }
 0219                throw ex;
 220            }
 221            // Create Result
 10222            var _result = new HttpOperationResponse<Person>();
 10223            _result.Request = _httpRequest;
 10224            _result.Response = _httpResponse;
 225            // Deserialize Response
 10226            if ((int)_statusCode == 200)
 227            {
 10228                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 229                try
 230                {
 10231                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Person>(_responseContent, Client
 10232                }
 0233                catch (JsonException ex)
 234                {
 0235                    _httpRequest.Dispose();
 0236                    if (_httpResponse != null)
 237                    {
 0238                        _httpResponse.Dispose();
 239                    }
 0240                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 241                }
 242            }
 10243            if (_shouldTrace)
 244            {
 0245                ServiceClientTracing.Exit(_invocationId, _result);
 246            }
 10247            return _result;
 10248        }
 249
 250        /// <summary>
 251        /// List all persons in a large person group, and retrieve person information
 252        /// (including personId, name, userData and persistedFaceIds of registered
 253        /// faces of the person).
 254        /// </summary>
 255        /// <param name='largePersonGroupId'>
 256        /// Id referencing a particular large person group.
 257        /// </param>
 258        /// <param name='start'>
 259        /// Starting person id to return (used to list a range of persons).
 260        /// </param>
 261        /// <param name='top'>
 262        /// Number of persons to return starting with the person id indicated by the
 263        /// 'start' parameter.
 264        /// </param>
 265        /// <param name='customHeaders'>
 266        /// Headers that will be added to request.
 267        /// </param>
 268        /// <param name='cancellationToken'>
 269        /// The cancellation token.
 270        /// </param>
 271        /// <exception cref="APIErrorException">
 272        /// Thrown when the operation returned an invalid status code
 273        /// </exception>
 274        /// <exception cref="SerializationException">
 275        /// Thrown when unable to deserialize the response
 276        /// </exception>
 277        /// <exception cref="ValidationException">
 278        /// Thrown when a required parameter is null
 279        /// </exception>
 280        /// <exception cref="System.ArgumentNullException">
 281        /// Thrown when a required parameter is null
 282        /// </exception>
 283        /// <return>
 284        /// A response object containing the response body and response headers.
 285        /// </return>
 286        public async Task<HttpOperationResponse<IList<Person>>> ListWithHttpMessagesAsync(string largePersonGroupId, str
 287        {
 0288            if (Client.Endpoint == null)
 289            {
 0290                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 291            }
 0292            if (largePersonGroupId == null)
 293            {
 0294                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 295            }
 0296            if (largePersonGroupId != null)
 297            {
 0298                if (largePersonGroupId.Length > 64)
 299                {
 0300                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 301                }
 0302                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 303                {
 0304                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 305                }
 306            }
 0307            if (top > 1000)
 308            {
 0309                throw new ValidationException(ValidationRules.InclusiveMaximum, "top", 1000);
 310            }
 0311            if (top < 1)
 312            {
 0313                throw new ValidationException(ValidationRules.InclusiveMinimum, "top", 1);
 314            }
 315            // Tracing
 0316            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0317            string _invocationId = null;
 0318            if (_shouldTrace)
 319            {
 0320                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0321                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0322                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 0323                tracingParameters.Add("start", start);
 0324                tracingParameters.Add("top", top);
 0325                tracingParameters.Add("cancellationToken", cancellationToken);
 0326                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 327            }
 328            // Construct URL
 0329            var _baseUrl = Client.BaseUri;
 0330            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/persons"
 0331            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0332            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 0333            List<string> _queryParameters = new List<string>();
 0334            if (start != null)
 335            {
 0336                _queryParameters.Add(string.Format("start={0}", System.Uri.EscapeDataString(start)));
 337            }
 0338            if (top != null)
 339            {
 0340                _queryParameters.Add(string.Format("top={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon
 341            }
 0342            if (_queryParameters.Count > 0)
 343            {
 0344                _url += "?" + string.Join("&", _queryParameters);
 345            }
 346            // Create HTTP transport objects
 0347            var _httpRequest = new HttpRequestMessage();
 0348            HttpResponseMessage _httpResponse = null;
 0349            _httpRequest.Method = new HttpMethod("GET");
 0350            _httpRequest.RequestUri = new System.Uri(_url);
 351            // Set Headers
 352
 353
 0354            if (customHeaders != null)
 355            {
 0356                foreach(var _header in customHeaders)
 357                {
 0358                    if (_httpRequest.Headers.Contains(_header.Key))
 359                    {
 0360                        _httpRequest.Headers.Remove(_header.Key);
 361                    }
 0362                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 363                }
 364            }
 365
 366            // Serialize Request
 0367            string _requestContent = null;
 368            // Set Credentials
 0369            if (Client.Credentials != null)
 370            {
 0371                cancellationToken.ThrowIfCancellationRequested();
 0372                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 373            }
 374            // Send Request
 0375            if (_shouldTrace)
 376            {
 0377                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 378            }
 0379            cancellationToken.ThrowIfCancellationRequested();
 0380            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0381            if (_shouldTrace)
 382            {
 0383                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 384            }
 0385            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0386            cancellationToken.ThrowIfCancellationRequested();
 0387            string _responseContent = null;
 0388            if ((int)_statusCode != 200)
 389            {
 0390                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 391                try
 392                {
 0393                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0394                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0395                    if (_errorBody != null)
 396                    {
 0397                        ex.Body = _errorBody;
 398                    }
 0399                }
 0400                catch (JsonException)
 401                {
 402                    // Ignore the exception
 0403                }
 0404                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0405                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0406                if (_shouldTrace)
 407                {
 0408                    ServiceClientTracing.Error(_invocationId, ex);
 409                }
 0410                _httpRequest.Dispose();
 0411                if (_httpResponse != null)
 412                {
 0413                    _httpResponse.Dispose();
 414                }
 0415                throw ex;
 416            }
 417            // Create Result
 0418            var _result = new HttpOperationResponse<IList<Person>>();
 0419            _result.Request = _httpRequest;
 0420            _result.Response = _httpResponse;
 421            // Deserialize Response
 0422            if ((int)_statusCode == 200)
 423            {
 0424                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 425                try
 426                {
 0427                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<Person>>(_responseContent,
 0428                }
 0429                catch (JsonException ex)
 430                {
 0431                    _httpRequest.Dispose();
 0432                    if (_httpResponse != null)
 433                    {
 0434                        _httpResponse.Dispose();
 435                    }
 0436                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 437                }
 438            }
 0439            if (_shouldTrace)
 440            {
 0441                ServiceClientTracing.Exit(_invocationId, _result);
 442            }
 0443            return _result;
 0444        }
 445
 446        /// <summary>
 447        /// Delete an existing person from a large person group. The persistedFaceId,
 448        /// userData, person name and face feature in the person entry will all be
 449        /// deleted.
 450        /// </summary>
 451        /// <param name='largePersonGroupId'>
 452        /// Id referencing a particular large person group.
 453        /// </param>
 454        /// <param name='personId'>
 455        /// Id referencing a particular person.
 456        /// </param>
 457        /// <param name='customHeaders'>
 458        /// Headers that will be added to request.
 459        /// </param>
 460        /// <param name='cancellationToken'>
 461        /// The cancellation token.
 462        /// </param>
 463        /// <exception cref="APIErrorException">
 464        /// Thrown when the operation returned an invalid status code
 465        /// </exception>
 466        /// <exception cref="ValidationException">
 467        /// Thrown when a required parameter is null
 468        /// </exception>
 469        /// <exception cref="System.ArgumentNullException">
 470        /// Thrown when a required parameter is null
 471        /// </exception>
 472        /// <return>
 473        /// A response object containing the response body and response headers.
 474        /// </return>
 475        public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(string largePersonGroupId, System.Guid pers
 476        {
 0477            if (Client.Endpoint == null)
 478            {
 0479                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 480            }
 0481            if (largePersonGroupId == null)
 482            {
 0483                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 484            }
 0485            if (largePersonGroupId != null)
 486            {
 0487                if (largePersonGroupId.Length > 64)
 488                {
 0489                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 490                }
 0491                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 492                {
 0493                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 494                }
 495            }
 496            // Tracing
 0497            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0498            string _invocationId = null;
 0499            if (_shouldTrace)
 500            {
 0501                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0502                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0503                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 0504                tracingParameters.Add("personId", personId);
 0505                tracingParameters.Add("cancellationToken", cancellationToken);
 0506                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 507            }
 508            // Construct URL
 0509            var _baseUrl = Client.BaseUri;
 0510            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/persons/
 0511            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0512            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 0513            _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 514            // Create HTTP transport objects
 0515            var _httpRequest = new HttpRequestMessage();
 0516            HttpResponseMessage _httpResponse = null;
 0517            _httpRequest.Method = new HttpMethod("DELETE");
 0518            _httpRequest.RequestUri = new System.Uri(_url);
 519            // Set Headers
 520
 521
 0522            if (customHeaders != null)
 523            {
 0524                foreach(var _header in customHeaders)
 525                {
 0526                    if (_httpRequest.Headers.Contains(_header.Key))
 527                    {
 0528                        _httpRequest.Headers.Remove(_header.Key);
 529                    }
 0530                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 531                }
 532            }
 533
 534            // Serialize Request
 0535            string _requestContent = null;
 536            // Set Credentials
 0537            if (Client.Credentials != null)
 538            {
 0539                cancellationToken.ThrowIfCancellationRequested();
 0540                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 541            }
 542            // Send Request
 0543            if (_shouldTrace)
 544            {
 0545                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 546            }
 0547            cancellationToken.ThrowIfCancellationRequested();
 0548            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0549            if (_shouldTrace)
 550            {
 0551                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 552            }
 0553            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0554            cancellationToken.ThrowIfCancellationRequested();
 0555            string _responseContent = null;
 0556            if ((int)_statusCode != 200)
 557            {
 0558                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 559                try
 560                {
 0561                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0562                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0563                    if (_errorBody != null)
 564                    {
 0565                        ex.Body = _errorBody;
 566                    }
 0567                }
 0568                catch (JsonException)
 569                {
 570                    // Ignore the exception
 0571                }
 0572                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0573                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0574                if (_shouldTrace)
 575                {
 0576                    ServiceClientTracing.Error(_invocationId, ex);
 577                }
 0578                _httpRequest.Dispose();
 0579                if (_httpResponse != null)
 580                {
 0581                    _httpResponse.Dispose();
 582                }
 0583                throw ex;
 584            }
 585            // Create Result
 0586            var _result = new HttpOperationResponse();
 0587            _result.Request = _httpRequest;
 0588            _result.Response = _httpResponse;
 0589            if (_shouldTrace)
 590            {
 0591                ServiceClientTracing.Exit(_invocationId, _result);
 592            }
 0593            return _result;
 0594        }
 595
 596        /// <summary>
 597        /// Retrieve a person's name and userData, and the persisted faceIds
 598        /// representing the registered person face feature.
 599        /// </summary>
 600        /// <param name='largePersonGroupId'>
 601        /// Id referencing a particular large person group.
 602        /// </param>
 603        /// <param name='personId'>
 604        /// Id referencing a particular person.
 605        /// </param>
 606        /// <param name='customHeaders'>
 607        /// Headers that will be added to request.
 608        /// </param>
 609        /// <param name='cancellationToken'>
 610        /// The cancellation token.
 611        /// </param>
 612        /// <exception cref="APIErrorException">
 613        /// Thrown when the operation returned an invalid status code
 614        /// </exception>
 615        /// <exception cref="SerializationException">
 616        /// Thrown when unable to deserialize the response
 617        /// </exception>
 618        /// <exception cref="ValidationException">
 619        /// Thrown when a required parameter is null
 620        /// </exception>
 621        /// <exception cref="System.ArgumentNullException">
 622        /// Thrown when a required parameter is null
 623        /// </exception>
 624        /// <return>
 625        /// A response object containing the response body and response headers.
 626        /// </return>
 627        public async Task<HttpOperationResponse<Person>> GetWithHttpMessagesAsync(string largePersonGroupId, System.Guid
 628        {
 2629            if (Client.Endpoint == null)
 630            {
 0631                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 632            }
 2633            if (largePersonGroupId == null)
 634            {
 0635                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 636            }
 2637            if (largePersonGroupId != null)
 638            {
 2639                if (largePersonGroupId.Length > 64)
 640                {
 0641                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 642                }
 2643                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 644                {
 0645                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 646                }
 647            }
 648            // Tracing
 2649            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2650            string _invocationId = null;
 2651            if (_shouldTrace)
 652            {
 0653                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0654                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0655                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 0656                tracingParameters.Add("personId", personId);
 0657                tracingParameters.Add("cancellationToken", cancellationToken);
 0658                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 659            }
 660            // Construct URL
 2661            var _baseUrl = Client.BaseUri;
 2662            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/persons/
 2663            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 2664            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 2665            _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 666            // Create HTTP transport objects
 2667            var _httpRequest = new HttpRequestMessage();
 2668            HttpResponseMessage _httpResponse = null;
 2669            _httpRequest.Method = new HttpMethod("GET");
 2670            _httpRequest.RequestUri = new System.Uri(_url);
 671            // Set Headers
 672
 673
 2674            if (customHeaders != null)
 675            {
 0676                foreach(var _header in customHeaders)
 677                {
 0678                    if (_httpRequest.Headers.Contains(_header.Key))
 679                    {
 0680                        _httpRequest.Headers.Remove(_header.Key);
 681                    }
 0682                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 683                }
 684            }
 685
 686            // Serialize Request
 2687            string _requestContent = null;
 688            // Set Credentials
 2689            if (Client.Credentials != null)
 690            {
 2691                cancellationToken.ThrowIfCancellationRequested();
 2692                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 693            }
 694            // Send Request
 2695            if (_shouldTrace)
 696            {
 0697                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 698            }
 2699            cancellationToken.ThrowIfCancellationRequested();
 2700            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2701            if (_shouldTrace)
 702            {
 0703                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 704            }
 2705            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2706            cancellationToken.ThrowIfCancellationRequested();
 2707            string _responseContent = null;
 2708            if ((int)_statusCode != 200)
 709            {
 0710                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 711                try
 712                {
 0713                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0714                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0715                    if (_errorBody != null)
 716                    {
 0717                        ex.Body = _errorBody;
 718                    }
 0719                }
 0720                catch (JsonException)
 721                {
 722                    // Ignore the exception
 0723                }
 0724                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0725                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0726                if (_shouldTrace)
 727                {
 0728                    ServiceClientTracing.Error(_invocationId, ex);
 729                }
 0730                _httpRequest.Dispose();
 0731                if (_httpResponse != null)
 732                {
 0733                    _httpResponse.Dispose();
 734                }
 0735                throw ex;
 736            }
 737            // Create Result
 2738            var _result = new HttpOperationResponse<Person>();
 2739            _result.Request = _httpRequest;
 2740            _result.Response = _httpResponse;
 741            // Deserialize Response
 2742            if ((int)_statusCode == 200)
 743            {
 2744                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 745                try
 746                {
 2747                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Person>(_responseContent, Client
 2748                }
 0749                catch (JsonException ex)
 750                {
 0751                    _httpRequest.Dispose();
 0752                    if (_httpResponse != null)
 753                    {
 0754                        _httpResponse.Dispose();
 755                    }
 0756                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 757                }
 758            }
 2759            if (_shouldTrace)
 760            {
 0761                ServiceClientTracing.Exit(_invocationId, _result);
 762            }
 2763            return _result;
 2764        }
 765
 766        /// <summary>
 767        /// Update name or userData of a person.
 768        /// </summary>
 769        /// <param name='largePersonGroupId'>
 770        /// Id referencing a particular large person group.
 771        /// </param>
 772        /// <param name='personId'>
 773        /// Id referencing a particular person.
 774        /// </param>
 775        /// <param name='name'>
 776        /// User defined name, maximum length is 128.
 777        /// </param>
 778        /// <param name='userData'>
 779        /// User specified data. Length should not exceed 16KB.
 780        /// </param>
 781        /// <param name='customHeaders'>
 782        /// Headers that will be added to request.
 783        /// </param>
 784        /// <param name='cancellationToken'>
 785        /// The cancellation token.
 786        /// </param>
 787        /// <exception cref="APIErrorException">
 788        /// Thrown when the operation returned an invalid status code
 789        /// </exception>
 790        /// <exception cref="ValidationException">
 791        /// Thrown when a required parameter is null
 792        /// </exception>
 793        /// <exception cref="System.ArgumentNullException">
 794        /// Thrown when a required parameter is null
 795        /// </exception>
 796        /// <return>
 797        /// A response object containing the response body and response headers.
 798        /// </return>
 799        public async Task<HttpOperationResponse> UpdateWithHttpMessagesAsync(string largePersonGroupId, System.Guid pers
 800        {
 0801            if (Client.Endpoint == null)
 802            {
 0803                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 804            }
 0805            if (largePersonGroupId == null)
 806            {
 0807                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 808            }
 0809            if (largePersonGroupId != null)
 810            {
 0811                if (largePersonGroupId.Length > 64)
 812                {
 0813                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 814                }
 0815                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 816                {
 0817                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 818                }
 819            }
 0820            if (name != null)
 821            {
 0822                if (name.Length > 128)
 823                {
 0824                    throw new ValidationException(ValidationRules.MaxLength, "name", 128);
 825                }
 826            }
 0827            if (userData != null)
 828            {
 0829                if (userData.Length > 16384)
 830                {
 0831                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 832                }
 833            }
 0834            NameAndUserDataContract body = new NameAndUserDataContract();
 0835            if (name != null || userData != null)
 836            {
 0837                body.Name = name;
 0838                body.UserData = userData;
 839            }
 840            // Tracing
 0841            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0842            string _invocationId = null;
 0843            if (_shouldTrace)
 844            {
 0845                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0846                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0847                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 0848                tracingParameters.Add("personId", personId);
 0849                tracingParameters.Add("body", body);
 0850                tracingParameters.Add("cancellationToken", cancellationToken);
 0851                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
 852            }
 853            // Construct URL
 0854            var _baseUrl = Client.BaseUri;
 0855            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/persons/
 0856            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0857            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 0858            _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 859            // Create HTTP transport objects
 0860            var _httpRequest = new HttpRequestMessage();
 0861            HttpResponseMessage _httpResponse = null;
 0862            _httpRequest.Method = new HttpMethod("PATCH");
 0863            _httpRequest.RequestUri = new System.Uri(_url);
 864            // Set Headers
 865
 866
 0867            if (customHeaders != null)
 868            {
 0869                foreach(var _header in customHeaders)
 870                {
 0871                    if (_httpRequest.Headers.Contains(_header.Key))
 872                    {
 0873                        _httpRequest.Headers.Remove(_header.Key);
 874                    }
 0875                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 876                }
 877            }
 878
 879            // Serialize Request
 0880            string _requestContent = null;
 0881            if(body != null)
 882            {
 0883                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 0884                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0885                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 886            }
 887            // Set Credentials
 0888            if (Client.Credentials != null)
 889            {
 0890                cancellationToken.ThrowIfCancellationRequested();
 0891                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 892            }
 893            // Send Request
 0894            if (_shouldTrace)
 895            {
 0896                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 897            }
 0898            cancellationToken.ThrowIfCancellationRequested();
 0899            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0900            if (_shouldTrace)
 901            {
 0902                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 903            }
 0904            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0905            cancellationToken.ThrowIfCancellationRequested();
 0906            string _responseContent = null;
 0907            if ((int)_statusCode != 200)
 908            {
 0909                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 910                try
 911                {
 0912                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0913                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0914                    if (_errorBody != null)
 915                    {
 0916                        ex.Body = _errorBody;
 917                    }
 0918                }
 0919                catch (JsonException)
 920                {
 921                    // Ignore the exception
 0922                }
 0923                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0924                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0925                if (_shouldTrace)
 926                {
 0927                    ServiceClientTracing.Error(_invocationId, ex);
 928                }
 0929                _httpRequest.Dispose();
 0930                if (_httpResponse != null)
 931                {
 0932                    _httpResponse.Dispose();
 933                }
 0934                throw ex;
 935            }
 936            // Create Result
 0937            var _result = new HttpOperationResponse();
 0938            _result.Request = _httpRequest;
 0939            _result.Response = _httpResponse;
 0940            if (_shouldTrace)
 941            {
 0942                ServiceClientTracing.Exit(_invocationId, _result);
 943            }
 0944            return _result;
 0945        }
 946
 947        /// <summary>
 948        /// Delete a face from a person in a large person group by specified
 949        /// largePersonGroupId, personId and persistedFaceId.
 950        /// &lt;br /&gt; Adding/deleting faces to/from a same person will be processed
 951        /// sequentially. Adding/deleting faces to/from different persons are processed
 952        /// in parallel.
 953        /// </summary>
 954        /// <param name='largePersonGroupId'>
 955        /// Id referencing a particular large person group.
 956        /// </param>
 957        /// <param name='personId'>
 958        /// Id referencing a particular person.
 959        /// </param>
 960        /// <param name='persistedFaceId'>
 961        /// Id referencing a particular persistedFaceId of an existing face.
 962        /// </param>
 963        /// <param name='customHeaders'>
 964        /// Headers that will be added to request.
 965        /// </param>
 966        /// <param name='cancellationToken'>
 967        /// The cancellation token.
 968        /// </param>
 969        /// <exception cref="APIErrorException">
 970        /// Thrown when the operation returned an invalid status code
 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> DeleteFaceWithHttpMessagesAsync(string largePersonGroupId, System.Guid 
 982        {
 0983            if (Client.Endpoint == null)
 984            {
 0985                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 986            }
 0987            if (largePersonGroupId == null)
 988            {
 0989                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 990            }
 0991            if (largePersonGroupId != null)
 992            {
 0993                if (largePersonGroupId.Length > 64)
 994                {
 0995                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 996                }
 0997                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 998                {
 0999                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 1000                }
 1001            }
 1002            // Tracing
 01003            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01004            string _invocationId = null;
 01005            if (_shouldTrace)
 1006            {
 01007                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01008                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01009                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 01010                tracingParameters.Add("personId", personId);
 01011                tracingParameters.Add("persistedFaceId", persistedFaceId);
 01012                tracingParameters.Add("cancellationToken", cancellationToken);
 01013                ServiceClientTracing.Enter(_invocationId, this, "DeleteFace", tracingParameters);
 1014            }
 1015            // Construct URL
 01016            var _baseUrl = Client.BaseUri;
 01017            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/persons/
 01018            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01019            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 01020            _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 01021            _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri
 1022            // Create HTTP transport objects
 01023            var _httpRequest = new HttpRequestMessage();
 01024            HttpResponseMessage _httpResponse = null;
 01025            _httpRequest.Method = new HttpMethod("DELETE");
 01026            _httpRequest.RequestUri = new System.Uri(_url);
 1027            // Set Headers
 1028
 1029
 01030            if (customHeaders != null)
 1031            {
 01032                foreach(var _header in customHeaders)
 1033                {
 01034                    if (_httpRequest.Headers.Contains(_header.Key))
 1035                    {
 01036                        _httpRequest.Headers.Remove(_header.Key);
 1037                    }
 01038                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1039                }
 1040            }
 1041
 1042            // Serialize Request
 01043            string _requestContent = null;
 1044            // Set Credentials
 01045            if (Client.Credentials != null)
 1046            {
 01047                cancellationToken.ThrowIfCancellationRequested();
 01048                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1049            }
 1050            // Send Request
 01051            if (_shouldTrace)
 1052            {
 01053                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1054            }
 01055            cancellationToken.ThrowIfCancellationRequested();
 01056            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01057            if (_shouldTrace)
 1058            {
 01059                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1060            }
 01061            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01062            cancellationToken.ThrowIfCancellationRequested();
 01063            string _responseContent = null;
 01064            if ((int)_statusCode != 200)
 1065            {
 01066                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1067                try
 1068                {
 01069                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01070                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01071                    if (_errorBody != null)
 1072                    {
 01073                        ex.Body = _errorBody;
 1074                    }
 01075                }
 01076                catch (JsonException)
 1077                {
 1078                    // Ignore the exception
 01079                }
 01080                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01081                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01082                if (_shouldTrace)
 1083                {
 01084                    ServiceClientTracing.Error(_invocationId, ex);
 1085                }
 01086                _httpRequest.Dispose();
 01087                if (_httpResponse != null)
 1088                {
 01089                    _httpResponse.Dispose();
 1090                }
 01091                throw ex;
 1092            }
 1093            // Create Result
 01094            var _result = new HttpOperationResponse();
 01095            _result.Request = _httpRequest;
 01096            _result.Response = _httpResponse;
 01097            if (_shouldTrace)
 1098            {
 01099                ServiceClientTracing.Exit(_invocationId, _result);
 1100            }
 01101            return _result;
 01102        }
 1103
 1104        /// <summary>
 1105        /// Retrieve information about a persisted face (specified by persistedFaceId,
 1106        /// personId and its belonging largePersonGroupId).
 1107        /// </summary>
 1108        /// <param name='largePersonGroupId'>
 1109        /// Id referencing a particular large person group.
 1110        /// </param>
 1111        /// <param name='personId'>
 1112        /// Id referencing a particular person.
 1113        /// </param>
 1114        /// <param name='persistedFaceId'>
 1115        /// Id referencing a particular persistedFaceId of an existing face.
 1116        /// </param>
 1117        /// <param name='customHeaders'>
 1118        /// Headers that will be added to request.
 1119        /// </param>
 1120        /// <param name='cancellationToken'>
 1121        /// The cancellation token.
 1122        /// </param>
 1123        /// <exception cref="APIErrorException">
 1124        /// Thrown when the operation returned an invalid status code
 1125        /// </exception>
 1126        /// <exception cref="SerializationException">
 1127        /// Thrown when unable to deserialize the response
 1128        /// </exception>
 1129        /// <exception cref="ValidationException">
 1130        /// Thrown when a required parameter is null
 1131        /// </exception>
 1132        /// <exception cref="System.ArgumentNullException">
 1133        /// Thrown when a required parameter is null
 1134        /// </exception>
 1135        /// <return>
 1136        /// A response object containing the response body and response headers.
 1137        /// </return>
 1138        public async Task<HttpOperationResponse<PersistedFace>> GetFaceWithHttpMessagesAsync(string largePersonGroupId, 
 1139        {
 21140            if (Client.Endpoint == null)
 1141            {
 01142                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1143            }
 21144            if (largePersonGroupId == null)
 1145            {
 01146                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 1147            }
 21148            if (largePersonGroupId != null)
 1149            {
 21150                if (largePersonGroupId.Length > 64)
 1151                {
 01152                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 1153                }
 21154                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 1155                {
 01156                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 1157                }
 1158            }
 1159            // Tracing
 21160            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 21161            string _invocationId = null;
 21162            if (_shouldTrace)
 1163            {
 01164                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01165                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01166                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 01167                tracingParameters.Add("personId", personId);
 01168                tracingParameters.Add("persistedFaceId", persistedFaceId);
 01169                tracingParameters.Add("cancellationToken", cancellationToken);
 01170                ServiceClientTracing.Enter(_invocationId, this, "GetFace", tracingParameters);
 1171            }
 1172            // Construct URL
 21173            var _baseUrl = Client.BaseUri;
 21174            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/persons/
 21175            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 21176            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 21177            _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 21178            _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri
 1179            // Create HTTP transport objects
 21180            var _httpRequest = new HttpRequestMessage();
 21181            HttpResponseMessage _httpResponse = null;
 21182            _httpRequest.Method = new HttpMethod("GET");
 21183            _httpRequest.RequestUri = new System.Uri(_url);
 1184            // Set Headers
 1185
 1186
 21187            if (customHeaders != null)
 1188            {
 01189                foreach(var _header in customHeaders)
 1190                {
 01191                    if (_httpRequest.Headers.Contains(_header.Key))
 1192                    {
 01193                        _httpRequest.Headers.Remove(_header.Key);
 1194                    }
 01195                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1196                }
 1197            }
 1198
 1199            // Serialize Request
 21200            string _requestContent = null;
 1201            // Set Credentials
 21202            if (Client.Credentials != null)
 1203            {
 21204                cancellationToken.ThrowIfCancellationRequested();
 21205                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1206            }
 1207            // Send Request
 21208            if (_shouldTrace)
 1209            {
 01210                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1211            }
 21212            cancellationToken.ThrowIfCancellationRequested();
 21213            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 21214            if (_shouldTrace)
 1215            {
 01216                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1217            }
 21218            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 21219            cancellationToken.ThrowIfCancellationRequested();
 21220            string _responseContent = null;
 21221            if ((int)_statusCode != 200)
 1222            {
 01223                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1224                try
 1225                {
 01226                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01227                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01228                    if (_errorBody != null)
 1229                    {
 01230                        ex.Body = _errorBody;
 1231                    }
 01232                }
 01233                catch (JsonException)
 1234                {
 1235                    // Ignore the exception
 01236                }
 01237                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01238                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01239                if (_shouldTrace)
 1240                {
 01241                    ServiceClientTracing.Error(_invocationId, ex);
 1242                }
 01243                _httpRequest.Dispose();
 01244                if (_httpResponse != null)
 1245                {
 01246                    _httpResponse.Dispose();
 1247                }
 01248                throw ex;
 1249            }
 1250            // Create Result
 21251            var _result = new HttpOperationResponse<PersistedFace>();
 21252            _result.Request = _httpRequest;
 21253            _result.Response = _httpResponse;
 1254            // Deserialize Response
 21255            if ((int)_statusCode == 200)
 1256            {
 21257                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1258                try
 1259                {
 21260                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent,
 21261                }
 01262                catch (JsonException ex)
 1263                {
 01264                    _httpRequest.Dispose();
 01265                    if (_httpResponse != null)
 1266                    {
 01267                        _httpResponse.Dispose();
 1268                    }
 01269                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1270                }
 1271            }
 21272            if (_shouldTrace)
 1273            {
 01274                ServiceClientTracing.Exit(_invocationId, _result);
 1275            }
 21276            return _result;
 21277        }
 1278
 1279        /// <summary>
 1280        /// Update a person persisted face's userData field.
 1281        /// </summary>
 1282        /// <param name='largePersonGroupId'>
 1283        /// Id referencing a particular large person group.
 1284        /// </param>
 1285        /// <param name='personId'>
 1286        /// Id referencing a particular person.
 1287        /// </param>
 1288        /// <param name='persistedFaceId'>
 1289        /// Id referencing a particular persistedFaceId of an existing face.
 1290        /// </param>
 1291        /// <param name='userData'>
 1292        /// User-provided data attached to the face. The size limit is 1KB.
 1293        /// </param>
 1294        /// <param name='customHeaders'>
 1295        /// Headers that will be added to request.
 1296        /// </param>
 1297        /// <param name='cancellationToken'>
 1298        /// The cancellation token.
 1299        /// </param>
 1300        /// <exception cref="APIErrorException">
 1301        /// Thrown when the operation returned an invalid status code
 1302        /// </exception>
 1303        /// <exception cref="ValidationException">
 1304        /// Thrown when a required parameter is null
 1305        /// </exception>
 1306        /// <exception cref="System.ArgumentNullException">
 1307        /// Thrown when a required parameter is null
 1308        /// </exception>
 1309        /// <return>
 1310        /// A response object containing the response body and response headers.
 1311        /// </return>
 1312        public async Task<HttpOperationResponse> UpdateFaceWithHttpMessagesAsync(string largePersonGroupId, System.Guid 
 1313        {
 01314            if (Client.Endpoint == null)
 1315            {
 01316                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1317            }
 01318            if (largePersonGroupId == null)
 1319            {
 01320                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 1321            }
 01322            if (largePersonGroupId != null)
 1323            {
 01324                if (largePersonGroupId.Length > 64)
 1325                {
 01326                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 1327                }
 01328                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 1329                {
 01330                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 1331                }
 1332            }
 01333            if (userData != null)
 1334            {
 01335                if (userData.Length > 1024)
 1336                {
 01337                    throw new ValidationException(ValidationRules.MaxLength, "userData", 1024);
 1338                }
 1339            }
 01340            UpdateFaceRequest body = new UpdateFaceRequest();
 01341            if (userData != null)
 1342            {
 01343                body.UserData = userData;
 1344            }
 1345            // Tracing
 01346            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01347            string _invocationId = null;
 01348            if (_shouldTrace)
 1349            {
 01350                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01351                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01352                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 01353                tracingParameters.Add("personId", personId);
 01354                tracingParameters.Add("persistedFaceId", persistedFaceId);
 01355                tracingParameters.Add("body", body);
 01356                tracingParameters.Add("cancellationToken", cancellationToken);
 01357                ServiceClientTracing.Enter(_invocationId, this, "UpdateFace", tracingParameters);
 1358            }
 1359            // Construct URL
 01360            var _baseUrl = Client.BaseUri;
 01361            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/persons/
 01362            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01363            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 01364            _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 01365            _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri
 1366            // Create HTTP transport objects
 01367            var _httpRequest = new HttpRequestMessage();
 01368            HttpResponseMessage _httpResponse = null;
 01369            _httpRequest.Method = new HttpMethod("PATCH");
 01370            _httpRequest.RequestUri = new System.Uri(_url);
 1371            // Set Headers
 1372
 1373
 01374            if (customHeaders != null)
 1375            {
 01376                foreach(var _header in customHeaders)
 1377                {
 01378                    if (_httpRequest.Headers.Contains(_header.Key))
 1379                    {
 01380                        _httpRequest.Headers.Remove(_header.Key);
 1381                    }
 01382                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1383                }
 1384            }
 1385
 1386            // Serialize Request
 01387            string _requestContent = null;
 01388            if(body != null)
 1389            {
 01390                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 01391                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01392                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1393            }
 1394            // Set Credentials
 01395            if (Client.Credentials != null)
 1396            {
 01397                cancellationToken.ThrowIfCancellationRequested();
 01398                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1399            }
 1400            // Send Request
 01401            if (_shouldTrace)
 1402            {
 01403                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1404            }
 01405            cancellationToken.ThrowIfCancellationRequested();
 01406            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01407            if (_shouldTrace)
 1408            {
 01409                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1410            }
 01411            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01412            cancellationToken.ThrowIfCancellationRequested();
 01413            string _responseContent = null;
 01414            if ((int)_statusCode != 200)
 1415            {
 01416                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1417                try
 1418                {
 01419                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01420                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01421                    if (_errorBody != null)
 1422                    {
 01423                        ex.Body = _errorBody;
 1424                    }
 01425                }
 01426                catch (JsonException)
 1427                {
 1428                    // Ignore the exception
 01429                }
 01430                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01431                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01432                if (_shouldTrace)
 1433                {
 01434                    ServiceClientTracing.Error(_invocationId, ex);
 1435                }
 01436                _httpRequest.Dispose();
 01437                if (_httpResponse != null)
 1438                {
 01439                    _httpResponse.Dispose();
 1440                }
 01441                throw ex;
 1442            }
 1443            // Create Result
 01444            var _result = new HttpOperationResponse();
 01445            _result.Request = _httpRequest;
 01446            _result.Response = _httpResponse;
 01447            if (_shouldTrace)
 1448            {
 01449                ServiceClientTracing.Exit(_invocationId, _result);
 1450            }
 01451            return _result;
 01452        }
 1453
 1454        /// <summary>
 1455        /// Add a face to a person into a large person group for face identification or
 1456        /// verification. To deal with an image contains multiple faces, input face can
 1457        /// be specified as an image with a targetFace rectangle. It returns a
 1458        /// persistedFaceId representing the added face. No image will be stored. Only
 1459        /// the extracted face feature will be stored on server until [LargePersonGroup
 1460        /// PersonFace -
 1461        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/599ae2966ac60f11b48b5aa3),
 1462        /// [LargePersonGroup Person -
 1463        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/599ade5c6ac60f11b48b5aa2)
 1464        /// or [LargePersonGroup -
 1465        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/599adc216ac60f11b48b5a9f)
 1466        /// is called.
 1467        /// &lt;br /&gt; Note persistedFaceId is different from faceId generated by
 1468        /// [Face -
 1469        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 1470        /// * Higher face image quality means better recognition precision. Please
 1471        /// consider high-quality faces: frontal, clear, and face size is 200x200
 1472        /// pixels (100 pixels between eyes) or bigger.
 1473        /// * Each person entry can hold up to 248 faces.
 1474        /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The
 1475        /// allowed image file size is from 1KB to 6MB.
 1476        /// * "targetFace" rectangle should contain one face. Zero or multiple faces
 1477        /// will be regarded as an error. If the provided "targetFace" rectangle is not
 1478        /// returned from [Face -
 1479        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
 1480        /// there’s no guarantee to detect and add the face successfully.
 1481        /// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
 1482        /// or large occlusions will cause failures.
 1483        /// * Adding/deleting faces to/from a same person will be processed
 1484        /// sequentially. Adding/deleting faces to/from different persons are processed
 1485        /// in parallel.
 1486        /// * The minimum detectable face size is 36x36 pixels in an image no larger
 1487        /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels
 1488        /// will need a proportionally larger minimum face size.
 1489        /// * Different 'detectionModel' values can be provided. To use and compare
 1490        /// different detection models, please refer to [How to specify a detection
 1491        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti
 1492        /// | Model | Recommended use-case(s) |
 1493        /// | ---------- | -------- |
 1494        /// | 'detection_01': | The default detection model for [LargePersonGroup
 1495        /// Person - Add
 1496        /// Face](/docs/services/563879b61984550e40cbbe8d/operations/599adf2a3a7b9412a4d53f42).
 1497        /// Recommend for near frontal face detection. For scenarios with exceptionally
 1498        /// large angle (head-pose) faces, occluded faces or wrong image orientation,
 1499        /// the faces in such cases may not be detected. |
 1500        /// | 'detection_02': | Detection model released in 2019 May with improved
 1501        /// accuracy especially on small, side and blurry faces. |
 1502        /// </summary>
 1503        /// <param name='largePersonGroupId'>
 1504        /// Id referencing a particular large person group.
 1505        /// </param>
 1506        /// <param name='personId'>
 1507        /// Id referencing a particular person.
 1508        /// </param>
 1509        /// <param name='url'>
 1510        /// Publicly reachable URL of an image
 1511        /// </param>
 1512        /// <param name='userData'>
 1513        /// User-specified data about the face for any purpose. The maximum length is
 1514        /// 1KB.
 1515        /// </param>
 1516        /// <param name='targetFace'>
 1517        /// A face rectangle to specify the target face to be added to a person in the
 1518        /// format of "targetFace=left,top,width,height". E.g.
 1519        /// "targetFace=10,10,100,100". If there is more than one face in the image,
 1520        /// targetFace is required to specify which face to add. No targetFace means
 1521        /// there is only one face detected in the entire image.
 1522        /// </param>
 1523        /// <param name='detectionModel'>
 1524        /// Name of detection model. Detection model is used to detect faces in the
 1525        /// submitted image. A detection model name can be provided when performing
 1526        /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add
 1527        /// Face. The default value is 'detection_01', if another model is needed,
 1528        /// please explicitly specify it. Possible values include: 'detection_01',
 1529        /// 'detection_02'
 1530        /// </param>
 1531        /// <param name='customHeaders'>
 1532        /// Headers that will be added to request.
 1533        /// </param>
 1534        /// <param name='cancellationToken'>
 1535        /// The cancellation token.
 1536        /// </param>
 1537        /// <exception cref="APIErrorException">
 1538        /// Thrown when the operation returned an invalid status code
 1539        /// </exception>
 1540        /// <exception cref="SerializationException">
 1541        /// Thrown when unable to deserialize the response
 1542        /// </exception>
 1543        /// <exception cref="ValidationException">
 1544        /// Thrown when a required parameter is null
 1545        /// </exception>
 1546        /// <exception cref="System.ArgumentNullException">
 1547        /// Thrown when a required parameter is null
 1548        /// </exception>
 1549        /// <return>
 1550        /// A response object containing the response body and response headers.
 1551        /// </return>
 1552        public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromUrlWithHttpMessagesAsync(string largePersonGr
 1553        {
 01554            if (Client.Endpoint == null)
 1555            {
 01556                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1557            }
 01558            if (largePersonGroupId == null)
 1559            {
 01560                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 1561            }
 01562            if (largePersonGroupId != null)
 1563            {
 01564                if (largePersonGroupId.Length > 64)
 1565                {
 01566                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 1567                }
 01568                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 1569                {
 01570                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 1571                }
 1572            }
 01573            if (userData != null)
 1574            {
 01575                if (userData.Length > 1024)
 1576                {
 01577                    throw new ValidationException(ValidationRules.MaxLength, "userData", 1024);
 1578                }
 1579            }
 01580            if (url == null)
 1581            {
 01582                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 1583            }
 01584            ImageUrl imageUrl = new ImageUrl();
 01585            if (url != null)
 1586            {
 01587                imageUrl.Url = url;
 1588            }
 1589            // Tracing
 01590            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01591            string _invocationId = null;
 01592            if (_shouldTrace)
 1593            {
 01594                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01595                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01596                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 01597                tracingParameters.Add("personId", personId);
 01598                tracingParameters.Add("userData", userData);
 01599                tracingParameters.Add("targetFace", targetFace);
 01600                tracingParameters.Add("detectionModel", detectionModel);
 01601                tracingParameters.Add("imageUrl", imageUrl);
 01602                tracingParameters.Add("cancellationToken", cancellationToken);
 01603                ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromUrl", tracingParameters);
 1604            }
 1605            // Construct URL
 01606            var _baseUrl = Client.BaseUri;
 01607            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/persons/
 01608            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01609            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 01610            _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 01611            List<string> _queryParameters = new List<string>();
 01612            if (userData != null)
 1613            {
 01614                _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData)));
 1615            }
 01616            if (targetFace != null)
 1617            {
 01618                _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target
 1619            }
 01620            if (detectionModel != null)
 1621            {
 01622                _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel)));
 1623            }
 01624            if (_queryParameters.Count > 0)
 1625            {
 01626                _url += "?" + string.Join("&", _queryParameters);
 1627            }
 1628            // Create HTTP transport objects
 01629            var _httpRequest = new HttpRequestMessage();
 01630            HttpResponseMessage _httpResponse = null;
 01631            _httpRequest.Method = new HttpMethod("POST");
 01632            _httpRequest.RequestUri = new System.Uri(_url);
 1633            // Set Headers
 1634
 1635
 01636            if (customHeaders != null)
 1637            {
 01638                foreach(var _header in customHeaders)
 1639                {
 01640                    if (_httpRequest.Headers.Contains(_header.Key))
 1641                    {
 01642                        _httpRequest.Headers.Remove(_header.Key);
 1643                    }
 01644                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1645                }
 1646            }
 1647
 1648            // Serialize Request
 01649            string _requestContent = null;
 01650            if(imageUrl != null)
 1651            {
 01652                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti
 01653                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01654                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1655            }
 1656            // Set Credentials
 01657            if (Client.Credentials != null)
 1658            {
 01659                cancellationToken.ThrowIfCancellationRequested();
 01660                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1661            }
 1662            // Send Request
 01663            if (_shouldTrace)
 1664            {
 01665                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1666            }
 01667            cancellationToken.ThrowIfCancellationRequested();
 01668            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01669            if (_shouldTrace)
 1670            {
 01671                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1672            }
 01673            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01674            cancellationToken.ThrowIfCancellationRequested();
 01675            string _responseContent = null;
 01676            if ((int)_statusCode != 200)
 1677            {
 01678                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1679                try
 1680                {
 01681                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01682                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01683                    if (_errorBody != null)
 1684                    {
 01685                        ex.Body = _errorBody;
 1686                    }
 01687                }
 01688                catch (JsonException)
 1689                {
 1690                    // Ignore the exception
 01691                }
 01692                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01693                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01694                if (_shouldTrace)
 1695                {
 01696                    ServiceClientTracing.Error(_invocationId, ex);
 1697                }
 01698                _httpRequest.Dispose();
 01699                if (_httpResponse != null)
 1700                {
 01701                    _httpResponse.Dispose();
 1702                }
 01703                throw ex;
 1704            }
 1705            // Create Result
 01706            var _result = new HttpOperationResponse<PersistedFace>();
 01707            _result.Request = _httpRequest;
 01708            _result.Response = _httpResponse;
 1709            // Deserialize Response
 01710            if ((int)_statusCode == 200)
 1711            {
 01712                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1713                try
 1714                {
 01715                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent,
 01716                }
 01717                catch (JsonException ex)
 1718                {
 01719                    _httpRequest.Dispose();
 01720                    if (_httpResponse != null)
 1721                    {
 01722                        _httpResponse.Dispose();
 1723                    }
 01724                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1725                }
 1726            }
 01727            if (_shouldTrace)
 1728            {
 01729                ServiceClientTracing.Exit(_invocationId, _result);
 1730            }
 01731            return _result;
 01732        }
 1733
 1734        /// <summary>
 1735        /// Add a face to a person into a large person group for face identification or
 1736        /// verification. To deal with an image contains multiple faces, input face can
 1737        /// be specified as an image with a targetFace rectangle. It returns a
 1738        /// persistedFaceId representing the added face. No image will be stored. Only
 1739        /// the extracted face feature will be stored on server until [LargePersonGroup
 1740        /// PersonFace -
 1741        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/599ae2966ac60f11b48b5aa3),
 1742        /// [LargePersonGroup Person -
 1743        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/599ade5c6ac60f11b48b5aa2)
 1744        /// or [LargePersonGroup -
 1745        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/599adc216ac60f11b48b5a9f)
 1746        /// is called.
 1747        /// &lt;br /&gt; Note persistedFaceId is different from faceId generated by
 1748        /// [Face -
 1749        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 1750        /// * Higher face image quality means better recognition precision. Please
 1751        /// consider high-quality faces: frontal, clear, and face size is 200x200
 1752        /// pixels (100 pixels between eyes) or bigger.
 1753        /// * Each person entry can hold up to 248 faces.
 1754        /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The
 1755        /// allowed image file size is from 1KB to 6MB.
 1756        /// * "targetFace" rectangle should contain one face. Zero or multiple faces
 1757        /// will be regarded as an error. If the provided "targetFace" rectangle is not
 1758        /// returned from [Face -
 1759        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
 1760        /// there’s no guarantee to detect and add the face successfully.
 1761        /// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
 1762        /// or large occlusions will cause failures.
 1763        /// * Adding/deleting faces to/from a same person will be processed
 1764        /// sequentially. Adding/deleting faces to/from different persons are processed
 1765        /// in parallel.
 1766        /// * The minimum detectable face size is 36x36 pixels in an image no larger
 1767        /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels
 1768        /// will need a proportionally larger minimum face size.
 1769        /// * Different 'detectionModel' values can be provided. To use and compare
 1770        /// different detection models, please refer to [How to specify a detection
 1771        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti
 1772        /// | Model | Recommended use-case(s) |
 1773        /// | ---------- | -------- |
 1774        /// | 'detection_01': | The default detection model for [LargePersonGroup
 1775        /// Person - Add
 1776        /// Face](/docs/services/563879b61984550e40cbbe8d/operations/599adf2a3a7b9412a4d53f42).
 1777        /// Recommend for near frontal face detection. For scenarios with exceptionally
 1778        /// large angle (head-pose) faces, occluded faces or wrong image orientation,
 1779        /// the faces in such cases may not be detected. |
 1780        /// | 'detection_02': | Detection model released in 2019 May with improved
 1781        /// accuracy especially on small, side and blurry faces. |
 1782        /// </summary>
 1783        /// <param name='largePersonGroupId'>
 1784        /// Id referencing a particular large person group.
 1785        /// </param>
 1786        /// <param name='personId'>
 1787        /// Id referencing a particular person.
 1788        /// </param>
 1789        /// <param name='image'>
 1790        /// An image stream.
 1791        /// </param>
 1792        /// <param name='userData'>
 1793        /// User-specified data about the face for any purpose. The maximum length is
 1794        /// 1KB.
 1795        /// </param>
 1796        /// <param name='targetFace'>
 1797        /// A face rectangle to specify the target face to be added to a person in the
 1798        /// format of "targetFace=left,top,width,height". E.g.
 1799        /// "targetFace=10,10,100,100". If there is more than one face in the image,
 1800        /// targetFace is required to specify which face to add. No targetFace means
 1801        /// there is only one face detected in the entire image.
 1802        /// </param>
 1803        /// <param name='detectionModel'>
 1804        /// Name of detection model. Detection model is used to detect faces in the
 1805        /// submitted image. A detection model name can be provided when performing
 1806        /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add
 1807        /// Face. The default value is 'detection_01', if another model is needed,
 1808        /// please explicitly specify it. Possible values include: 'detection_01',
 1809        /// 'detection_02'
 1810        /// </param>
 1811        /// <param name='customHeaders'>
 1812        /// Headers that will be added to request.
 1813        /// </param>
 1814        /// <param name='cancellationToken'>
 1815        /// The cancellation token.
 1816        /// </param>
 1817        /// <exception cref="APIErrorException">
 1818        /// Thrown when the operation returned an invalid status code
 1819        /// </exception>
 1820        /// <exception cref="SerializationException">
 1821        /// Thrown when unable to deserialize the response
 1822        /// </exception>
 1823        /// <exception cref="ValidationException">
 1824        /// Thrown when a required parameter is null
 1825        /// </exception>
 1826        /// <exception cref="System.ArgumentNullException">
 1827        /// Thrown when a required parameter is null
 1828        /// </exception>
 1829        /// <return>
 1830        /// A response object containing the response body and response headers.
 1831        /// </return>
 1832        public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromStreamWithHttpMessagesAsync(string largePerso
 1833        {
 181834            if (Client.Endpoint == null)
 1835            {
 01836                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1837            }
 181838            if (largePersonGroupId == null)
 1839            {
 01840                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 1841            }
 181842            if (largePersonGroupId != null)
 1843            {
 181844                if (largePersonGroupId.Length > 64)
 1845                {
 01846                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 1847                }
 181848                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 1849                {
 01850                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 1851                }
 1852            }
 181853            if (userData != null)
 1854            {
 01855                if (userData.Length > 1024)
 1856                {
 01857                    throw new ValidationException(ValidationRules.MaxLength, "userData", 1024);
 1858                }
 1859            }
 181860            if (image == null)
 1861            {
 01862                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 1863            }
 1864            // Tracing
 181865            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 181866            string _invocationId = null;
 181867            if (_shouldTrace)
 1868            {
 01869                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01870                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01871                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 01872                tracingParameters.Add("personId", personId);
 01873                tracingParameters.Add("userData", userData);
 01874                tracingParameters.Add("targetFace", targetFace);
 01875                tracingParameters.Add("image", image);
 01876                tracingParameters.Add("detectionModel", detectionModel);
 01877                tracingParameters.Add("cancellationToken", cancellationToken);
 01878                ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromStream", tracingParameters);
 1879            }
 1880            // Construct URL
 181881            var _baseUrl = Client.BaseUri;
 181882            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/persons/
 181883            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 181884            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 181885            _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 181886            List<string> _queryParameters = new List<string>();
 181887            if (userData != null)
 1888            {
 01889                _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData)));
 1890            }
 181891            if (targetFace != null)
 1892            {
 121893                _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target
 1894            }
 181895            if (detectionModel != null)
 1896            {
 181897                _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel)));
 1898            }
 181899            if (_queryParameters.Count > 0)
 1900            {
 181901                _url += "?" + string.Join("&", _queryParameters);
 1902            }
 1903            // Create HTTP transport objects
 181904            var _httpRequest = new HttpRequestMessage();
 181905            HttpResponseMessage _httpResponse = null;
 181906            _httpRequest.Method = new HttpMethod("POST");
 181907            _httpRequest.RequestUri = new System.Uri(_url);
 1908            // Set Headers
 1909
 1910
 181911            if (customHeaders != null)
 1912            {
 01913                foreach(var _header in customHeaders)
 1914                {
 01915                    if (_httpRequest.Headers.Contains(_header.Key))
 1916                    {
 01917                        _httpRequest.Headers.Remove(_header.Key);
 1918                    }
 01919                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1920                }
 1921            }
 1922
 1923            // Serialize Request
 181924            string _requestContent = null;
 181925            if(image == null)
 1926            {
 01927              throw new System.ArgumentNullException("image");
 1928            }
 181929            if (image != null && image != Stream.Null)
 1930            {
 181931                _httpRequest.Content = new StreamContent(image);
 181932                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1933            }
 1934            // Set Credentials
 181935            if (Client.Credentials != null)
 1936            {
 181937                cancellationToken.ThrowIfCancellationRequested();
 181938                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1939            }
 1940            // Send Request
 181941            if (_shouldTrace)
 1942            {
 01943                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1944            }
 181945            cancellationToken.ThrowIfCancellationRequested();
 181946            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 181947            if (_shouldTrace)
 1948            {
 01949                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1950            }
 181951            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 181952            cancellationToken.ThrowIfCancellationRequested();
 181953            string _responseContent = null;
 181954            if ((int)_statusCode != 200)
 1955            {
 01956                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1957                try
 1958                {
 01959                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01960                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01961                    if (_errorBody != null)
 1962                    {
 01963                        ex.Body = _errorBody;
 1964                    }
 01965                }
 01966                catch (JsonException)
 1967                {
 1968                    // Ignore the exception
 01969                }
 01970                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01971                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01972                if (_shouldTrace)
 1973                {
 01974                    ServiceClientTracing.Error(_invocationId, ex);
 1975                }
 01976                _httpRequest.Dispose();
 01977                if (_httpResponse != null)
 1978                {
 01979                    _httpResponse.Dispose();
 1980                }
 01981                throw ex;
 1982            }
 1983            // Create Result
 181984            var _result = new HttpOperationResponse<PersistedFace>();
 181985            _result.Request = _httpRequest;
 181986            _result.Response = _httpResponse;
 1987            // Deserialize Response
 181988            if ((int)_statusCode == 200)
 1989            {
 181990                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1991                try
 1992                {
 181993                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent,
 181994                }
 01995                catch (JsonException ex)
 1996                {
 01997                    _httpRequest.Dispose();
 01998                    if (_httpResponse != null)
 1999                    {
 02000                        _httpResponse.Dispose();
 2001                    }
 02002                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2003                }
 2004            }
 182005            if (_shouldTrace)
 2006            {
 02007                ServiceClientTracing.Exit(_invocationId, _result);
 2008            }
 182009            return _result;
 182010        }
 2011
 2012    }
 2013}