< Summary

Class:Microsoft.Azure.CognitiveServices.Vision.Face.PersonGroupPerson
Assembly:Microsoft.Azure.CognitiveServices.Vision.Face
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\PersonGroupPerson.cs
Covered lines:191
Uncovered lines:663
Coverable lines:854
Total lines:2043
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\PersonGroupPerson.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    /// PersonGroupPerson operations.
 27    /// </summary>
 28    public partial class PersonGroupPerson : IServiceOperations<FaceClient>, IPersonGroupPerson
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the PersonGroupPerson 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 PersonGroupPerson(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 person group.
 55        /// </summary>
 56        /// <param name='personGroupId'>
 57        /// Id referencing a particular 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 personGroupId, string name =
 87        {
 1088            if (Client.Endpoint == null)
 89            {
 090                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 91            }
 1092            if (personGroupId == null)
 93            {
 094                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 95            }
 1096            if (personGroupId != null)
 97            {
 1098                if (personGroupId.Length > 64)
 99                {
 0100                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 101                }
 10102                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 103                {
 0104                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[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("personGroupId", personGroupId);
 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("/") ? "" : "/") + "persongroups/{personGroupId}/persons";
 10142            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 10143            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 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 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='personGroupId'>
 256        /// Id referencing a particular 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 personGroupId, string s
 287        {
 0288            if (Client.Endpoint == null)
 289            {
 0290                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 291            }
 0292            if (personGroupId == null)
 293            {
 0294                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 295            }
 0296            if (personGroupId != null)
 297            {
 0298                if (personGroupId.Length > 64)
 299                {
 0300                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 301                }
 0302                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 303                {
 0304                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[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("personGroupId", personGroupId);
 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("/") ? "" : "/") + "persongroups/{personGroupId}/persons";
 0331            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0332            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 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 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='personGroupId'>
 452        /// Id referencing a particular 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 personGroupId, System.Guid personId,
 476        {
 0477            if (Client.Endpoint == null)
 478            {
 0479                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 480            }
 0481            if (personGroupId == null)
 482            {
 0483                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 484            }
 0485            if (personGroupId != null)
 486            {
 0487                if (personGroupId.Length > 64)
 488                {
 0489                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 490                }
 0491                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 492                {
 0493                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[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("personGroupId", personGroupId);
 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("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId}
 0511            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0512            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 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 information, including registered persisted faces, name
 598        /// and userData.
 599        /// </summary>
 600        /// <param name='personGroupId'>
 601        /// Id referencing a particular 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 personGroupId, System.Guid pers
 628        {
 2629            if (Client.Endpoint == null)
 630            {
 0631                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 632            }
 2633            if (personGroupId == null)
 634            {
 0635                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 636            }
 2637            if (personGroupId != null)
 638            {
 2639                if (personGroupId.Length > 64)
 640                {
 0641                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 642                }
 2643                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 644                {
 0645                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[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("personGroupId", personGroupId);
 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("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId}
 2663            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 2664            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 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='personGroupId'>
 770        /// Id referencing a particular 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 personGroupId, System.Guid personId,
 800        {
 0801            if (Client.Endpoint == null)
 802            {
 0803                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 804            }
 0805            if (personGroupId == null)
 806            {
 0807                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 808            }
 0809            if (personGroupId != null)
 810            {
 0811                if (personGroupId.Length > 64)
 812                {
 0813                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 814                }
 0815                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 816                {
 0817                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[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("personGroupId", personGroupId);
 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("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId}
 0856            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0857            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 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 person group by specified personGroupId,
 949        /// 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='personGroupId'>
 955        /// Id referencing a particular 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 personGroupId, System.Guid perso
 982        {
 0983            if (Client.Endpoint == null)
 984            {
 0985                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 986            }
 0987            if (personGroupId == null)
 988            {
 0989                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 990            }
 0991            if (personGroupId != null)
 992            {
 0993                if (personGroupId.Length > 64)
 994                {
 0995                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 996                }
 0997                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 998                {
 0999                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[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("personGroupId", personGroupId);
 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("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId}
 01018            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01019            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 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 personGroupId).
 1107        /// </summary>
 1108        /// <param name='personGroupId'>
 1109        /// Id referencing a particular 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 personGroupId, Syste
 1139        {
 21140            if (Client.Endpoint == null)
 1141            {
 01142                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1143            }
 21144            if (personGroupId == null)
 1145            {
 01146                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 1147            }
 21148            if (personGroupId != null)
 1149            {
 21150                if (personGroupId.Length > 64)
 1151                {
 01152                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 1153                }
 21154                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 1155                {
 01156                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[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("personGroupId", personGroupId);
 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("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId}
 21175            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 21176            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 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        /// Add a face to a person into a person group for face identification or
 1281        /// verification. To deal with an image contains multiple faces, input face can
 1282        /// be specified as an image with a targetFace rectangle. It returns a
 1283        /// persistedFaceId representing the added face. No image will be stored. Only
 1284        /// the extracted face feature will be stored on server until [PersonGroup
 1285        /// PersonFace -
 1286        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
 1287        /// [PersonGroup Person -
 1288        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
 1289        /// or [PersonGroup -
 1290        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
 1291        /// is called.
 1292        /// &lt;br /&gt; Note persistedFaceId is different from faceId generated by
 1293        /// [Face -
 1294        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 1295        /// * Higher face image quality means better recognition precision. Please
 1296        /// consider high-quality faces: frontal, clear, and face size is 200x200
 1297        /// pixels (100 pixels between eyes) or bigger.
 1298        /// * Each person entry can hold up to 248 faces.
 1299        /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The
 1300        /// allowed image file size is from 1KB to 6MB.
 1301        /// * "targetFace" rectangle should contain one face. Zero or multiple faces
 1302        /// will be regarded as an error. If the provided "targetFace" rectangle is not
 1303        /// returned from [Face -
 1304        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
 1305        /// there’s no guarantee to detect and add the face successfully.
 1306        /// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
 1307        /// or large occlusions will cause failures.
 1308        /// * Adding/deleting faces to/from a same person will be processed
 1309        /// sequentially. Adding/deleting faces to/from different persons are processed
 1310        /// in parallel.
 1311        /// </summary>
 1312        /// <param name='personGroupId'>
 1313        /// Id referencing a particular person group.
 1314        /// </param>
 1315        /// <param name='personId'>
 1316        /// Id referencing a particular person.
 1317        /// </param>
 1318        /// <param name='persistedFaceId'>
 1319        /// Id referencing a particular persistedFaceId of an existing face.
 1320        /// </param>
 1321        /// <param name='userData'>
 1322        /// User-provided data attached to the face. The size limit is 1KB.
 1323        /// </param>
 1324        /// <param name='customHeaders'>
 1325        /// Headers that will be added to request.
 1326        /// </param>
 1327        /// <param name='cancellationToken'>
 1328        /// The cancellation token.
 1329        /// </param>
 1330        /// <exception cref="APIErrorException">
 1331        /// Thrown when the operation returned an invalid status code
 1332        /// </exception>
 1333        /// <exception cref="ValidationException">
 1334        /// Thrown when a required parameter is null
 1335        /// </exception>
 1336        /// <exception cref="System.ArgumentNullException">
 1337        /// Thrown when a required parameter is null
 1338        /// </exception>
 1339        /// <return>
 1340        /// A response object containing the response body and response headers.
 1341        /// </return>
 1342        public async Task<HttpOperationResponse> UpdateFaceWithHttpMessagesAsync(string personGroupId, System.Guid perso
 1343        {
 01344            if (Client.Endpoint == null)
 1345            {
 01346                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1347            }
 01348            if (personGroupId == null)
 1349            {
 01350                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 1351            }
 01352            if (personGroupId != null)
 1353            {
 01354                if (personGroupId.Length > 64)
 1355                {
 01356                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 1357                }
 01358                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 1359                {
 01360                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$");
 1361                }
 1362            }
 01363            if (userData != null)
 1364            {
 01365                if (userData.Length > 1024)
 1366                {
 01367                    throw new ValidationException(ValidationRules.MaxLength, "userData", 1024);
 1368                }
 1369            }
 01370            UpdateFaceRequest body = new UpdateFaceRequest();
 01371            if (userData != null)
 1372            {
 01373                body.UserData = userData;
 1374            }
 1375            // Tracing
 01376            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01377            string _invocationId = null;
 01378            if (_shouldTrace)
 1379            {
 01380                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01381                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01382                tracingParameters.Add("personGroupId", personGroupId);
 01383                tracingParameters.Add("personId", personId);
 01384                tracingParameters.Add("persistedFaceId", persistedFaceId);
 01385                tracingParameters.Add("body", body);
 01386                tracingParameters.Add("cancellationToken", cancellationToken);
 01387                ServiceClientTracing.Enter(_invocationId, this, "UpdateFace", tracingParameters);
 1388            }
 1389            // Construct URL
 01390            var _baseUrl = Client.BaseUri;
 01391            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId}
 01392            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01393            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 01394            _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 01395            _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri
 1396            // Create HTTP transport objects
 01397            var _httpRequest = new HttpRequestMessage();
 01398            HttpResponseMessage _httpResponse = null;
 01399            _httpRequest.Method = new HttpMethod("PATCH");
 01400            _httpRequest.RequestUri = new System.Uri(_url);
 1401            // Set Headers
 1402
 1403
 01404            if (customHeaders != null)
 1405            {
 01406                foreach(var _header in customHeaders)
 1407                {
 01408                    if (_httpRequest.Headers.Contains(_header.Key))
 1409                    {
 01410                        _httpRequest.Headers.Remove(_header.Key);
 1411                    }
 01412                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1413                }
 1414            }
 1415
 1416            // Serialize Request
 01417            string _requestContent = null;
 01418            if(body != null)
 1419            {
 01420                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 01421                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01422                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1423            }
 1424            // Set Credentials
 01425            if (Client.Credentials != null)
 1426            {
 01427                cancellationToken.ThrowIfCancellationRequested();
 01428                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1429            }
 1430            // Send Request
 01431            if (_shouldTrace)
 1432            {
 01433                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1434            }
 01435            cancellationToken.ThrowIfCancellationRequested();
 01436            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01437            if (_shouldTrace)
 1438            {
 01439                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1440            }
 01441            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01442            cancellationToken.ThrowIfCancellationRequested();
 01443            string _responseContent = null;
 01444            if ((int)_statusCode != 200)
 1445            {
 01446                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1447                try
 1448                {
 01449                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01450                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01451                    if (_errorBody != null)
 1452                    {
 01453                        ex.Body = _errorBody;
 1454                    }
 01455                }
 01456                catch (JsonException)
 1457                {
 1458                    // Ignore the exception
 01459                }
 01460                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01461                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01462                if (_shouldTrace)
 1463                {
 01464                    ServiceClientTracing.Error(_invocationId, ex);
 1465                }
 01466                _httpRequest.Dispose();
 01467                if (_httpResponse != null)
 1468                {
 01469                    _httpResponse.Dispose();
 1470                }
 01471                throw ex;
 1472            }
 1473            // Create Result
 01474            var _result = new HttpOperationResponse();
 01475            _result.Request = _httpRequest;
 01476            _result.Response = _httpResponse;
 01477            if (_shouldTrace)
 1478            {
 01479                ServiceClientTracing.Exit(_invocationId, _result);
 1480            }
 01481            return _result;
 01482        }
 1483
 1484        /// <summary>
 1485        /// Add a face to a person into a person group for face identification or
 1486        /// verification. To deal with an image contains multiple faces, input face can
 1487        /// be specified as an image with a targetFace rectangle. It returns a
 1488        /// persistedFaceId representing the added face. No image will be stored. Only
 1489        /// the extracted face feature will be stored on server until [PersonGroup
 1490        /// PersonFace -
 1491        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
 1492        /// [PersonGroup Person -
 1493        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
 1494        /// or [PersonGroup -
 1495        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
 1496        /// is called.
 1497        /// &lt;br /&gt; Note persistedFaceId is different from faceId generated by
 1498        /// [Face -
 1499        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 1500        /// *   Higher face image quality means better recognition precision. Please
 1501        /// consider high-quality faces: frontal, clear, and face size is 200x200
 1502        /// pixels (100 pixels between eyes) or bigger.
 1503        /// *   Each person entry can hold up to 248 faces.
 1504        /// *   JPEG, PNG, GIF (the first frame), and BMP format are supported. The
 1505        /// allowed image file size is from 1KB to 6MB.
 1506        /// *   "targetFace" rectangle should contain one face. Zero or multiple faces
 1507        /// will be regarded as an error. If the provided "targetFace" rectangle is not
 1508        /// returned from [Face -
 1509        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
 1510        /// there’s no guarantee to detect and add the face successfully.
 1511        /// *   Out of detectable face size (36x36 - 4096x4096 pixels), large
 1512        /// head-pose, or large occlusions will cause failures.
 1513        /// *   Adding/deleting faces to/from a same person will be processed
 1514        /// sequentially. Adding/deleting faces to/from different persons are processed
 1515        /// in parallel.
 1516        /// * The minimum detectable face size is 36x36 pixels in an image no larger
 1517        /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels
 1518        /// will need a proportionally larger minimum face size.
 1519        /// * Different 'detectionModel' values can be provided. To use and compare
 1520        /// different detection models, please refer to [How to specify a detection
 1521        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti
 1522        /// | Model | Recommended use-case(s) |
 1523        /// | ---------- | -------- |
 1524        /// | 'detection_01': | The default detection model for [PersonGroup Person -
 1525        /// Add
 1526        /// Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b).
 1527        /// Recommend for near frontal face detection. For scenarios with exceptionally
 1528        /// large angle (head-pose) faces, occluded faces or wrong image orientation,
 1529        /// the faces in such cases may not be detected. |
 1530        /// | 'detection_02': | Detection model released in 2019 May with improved
 1531        /// accuracy especially on small, side and blurry faces. |
 1532        /// </summary>
 1533        /// <param name='personGroupId'>
 1534        /// Id referencing a particular person group.
 1535        /// </param>
 1536        /// <param name='personId'>
 1537        /// Id referencing a particular person.
 1538        /// </param>
 1539        /// <param name='url'>
 1540        /// Publicly reachable URL of an image
 1541        /// </param>
 1542        /// <param name='userData'>
 1543        /// User-specified data about the face for any purpose. The maximum length is
 1544        /// 1KB.
 1545        /// </param>
 1546        /// <param name='targetFace'>
 1547        /// A face rectangle to specify the target face to be added to a person in the
 1548        /// format of "targetFace=left,top,width,height". E.g.
 1549        /// "targetFace=10,10,100,100". If there is more than one face in the image,
 1550        /// targetFace is required to specify which face to add. No targetFace means
 1551        /// there is only one face detected in the entire image.
 1552        /// </param>
 1553        /// <param name='detectionModel'>
 1554        /// Name of detection model. Detection model is used to detect faces in the
 1555        /// submitted image. A detection model name can be provided when performing
 1556        /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add
 1557        /// Face. The default value is 'detection_01', if another model is needed,
 1558        /// please explicitly specify it. Possible values include: 'detection_01',
 1559        /// 'detection_02'
 1560        /// </param>
 1561        /// <param name='customHeaders'>
 1562        /// Headers that will be added to request.
 1563        /// </param>
 1564        /// <param name='cancellationToken'>
 1565        /// The cancellation token.
 1566        /// </param>
 1567        /// <exception cref="APIErrorException">
 1568        /// Thrown when the operation returned an invalid status code
 1569        /// </exception>
 1570        /// <exception cref="SerializationException">
 1571        /// Thrown when unable to deserialize the response
 1572        /// </exception>
 1573        /// <exception cref="ValidationException">
 1574        /// Thrown when a required parameter is null
 1575        /// </exception>
 1576        /// <exception cref="System.ArgumentNullException">
 1577        /// Thrown when a required parameter is null
 1578        /// </exception>
 1579        /// <return>
 1580        /// A response object containing the response body and response headers.
 1581        /// </return>
 1582        public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromUrlWithHttpMessagesAsync(string personGroupId
 1583        {
 01584            if (Client.Endpoint == null)
 1585            {
 01586                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1587            }
 01588            if (personGroupId == null)
 1589            {
 01590                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 1591            }
 01592            if (personGroupId != null)
 1593            {
 01594                if (personGroupId.Length > 64)
 1595                {
 01596                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 1597                }
 01598                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 1599                {
 01600                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$");
 1601                }
 1602            }
 01603            if (userData != null)
 1604            {
 01605                if (userData.Length > 1024)
 1606                {
 01607                    throw new ValidationException(ValidationRules.MaxLength, "userData", 1024);
 1608                }
 1609            }
 01610            if (url == null)
 1611            {
 01612                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 1613            }
 01614            ImageUrl imageUrl = new ImageUrl();
 01615            if (url != null)
 1616            {
 01617                imageUrl.Url = url;
 1618            }
 1619            // Tracing
 01620            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01621            string _invocationId = null;
 01622            if (_shouldTrace)
 1623            {
 01624                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01625                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01626                tracingParameters.Add("personGroupId", personGroupId);
 01627                tracingParameters.Add("personId", personId);
 01628                tracingParameters.Add("userData", userData);
 01629                tracingParameters.Add("targetFace", targetFace);
 01630                tracingParameters.Add("detectionModel", detectionModel);
 01631                tracingParameters.Add("imageUrl", imageUrl);
 01632                tracingParameters.Add("cancellationToken", cancellationToken);
 01633                ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromUrl", tracingParameters);
 1634            }
 1635            // Construct URL
 01636            var _baseUrl = Client.BaseUri;
 01637            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId}
 01638            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01639            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 01640            _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 01641            List<string> _queryParameters = new List<string>();
 01642            if (userData != null)
 1643            {
 01644                _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData)));
 1645            }
 01646            if (targetFace != null)
 1647            {
 01648                _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target
 1649            }
 01650            if (detectionModel != null)
 1651            {
 01652                _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel)));
 1653            }
 01654            if (_queryParameters.Count > 0)
 1655            {
 01656                _url += "?" + string.Join("&", _queryParameters);
 1657            }
 1658            // Create HTTP transport objects
 01659            var _httpRequest = new HttpRequestMessage();
 01660            HttpResponseMessage _httpResponse = null;
 01661            _httpRequest.Method = new HttpMethod("POST");
 01662            _httpRequest.RequestUri = new System.Uri(_url);
 1663            // Set Headers
 1664
 1665
 01666            if (customHeaders != null)
 1667            {
 01668                foreach(var _header in customHeaders)
 1669                {
 01670                    if (_httpRequest.Headers.Contains(_header.Key))
 1671                    {
 01672                        _httpRequest.Headers.Remove(_header.Key);
 1673                    }
 01674                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1675                }
 1676            }
 1677
 1678            // Serialize Request
 01679            string _requestContent = null;
 01680            if(imageUrl != null)
 1681            {
 01682                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti
 01683                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01684                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1685            }
 1686            // Set Credentials
 01687            if (Client.Credentials != null)
 1688            {
 01689                cancellationToken.ThrowIfCancellationRequested();
 01690                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1691            }
 1692            // Send Request
 01693            if (_shouldTrace)
 1694            {
 01695                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1696            }
 01697            cancellationToken.ThrowIfCancellationRequested();
 01698            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01699            if (_shouldTrace)
 1700            {
 01701                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1702            }
 01703            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01704            cancellationToken.ThrowIfCancellationRequested();
 01705            string _responseContent = null;
 01706            if ((int)_statusCode != 200)
 1707            {
 01708                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1709                try
 1710                {
 01711                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01712                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01713                    if (_errorBody != null)
 1714                    {
 01715                        ex.Body = _errorBody;
 1716                    }
 01717                }
 01718                catch (JsonException)
 1719                {
 1720                    // Ignore the exception
 01721                }
 01722                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01723                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01724                if (_shouldTrace)
 1725                {
 01726                    ServiceClientTracing.Error(_invocationId, ex);
 1727                }
 01728                _httpRequest.Dispose();
 01729                if (_httpResponse != null)
 1730                {
 01731                    _httpResponse.Dispose();
 1732                }
 01733                throw ex;
 1734            }
 1735            // Create Result
 01736            var _result = new HttpOperationResponse<PersistedFace>();
 01737            _result.Request = _httpRequest;
 01738            _result.Response = _httpResponse;
 1739            // Deserialize Response
 01740            if ((int)_statusCode == 200)
 1741            {
 01742                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1743                try
 1744                {
 01745                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent,
 01746                }
 01747                catch (JsonException ex)
 1748                {
 01749                    _httpRequest.Dispose();
 01750                    if (_httpResponse != null)
 1751                    {
 01752                        _httpResponse.Dispose();
 1753                    }
 01754                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1755                }
 1756            }
 01757            if (_shouldTrace)
 1758            {
 01759                ServiceClientTracing.Exit(_invocationId, _result);
 1760            }
 01761            return _result;
 01762        }
 1763
 1764        /// <summary>
 1765        /// Add a face to a person into a person group for face identification or
 1766        /// verification. To deal with an image contains multiple faces, input face can
 1767        /// be specified as an image with a targetFace rectangle. It returns a
 1768        /// persistedFaceId representing the added face. No image will be stored. Only
 1769        /// the extracted face feature will be stored on server until [PersonGroup
 1770        /// PersonFace -
 1771        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
 1772        /// [PersonGroup Person -
 1773        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
 1774        /// or [PersonGroup -
 1775        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
 1776        /// is called.
 1777        /// &lt;br /&gt; Note persistedFaceId is different from faceId generated by
 1778        /// [Face -
 1779        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 1780        /// *   Higher face image quality means better recognition precision. Please
 1781        /// consider high-quality faces: frontal, clear, and face size is 200x200
 1782        /// pixels (100 pixels between eyes) or bigger.
 1783        /// *   Each person entry can hold up to 248 faces.
 1784        /// *   JPEG, PNG, GIF (the first frame), and BMP format are supported. The
 1785        /// allowed image file size is from 1KB to 6MB.
 1786        /// *   "targetFace" rectangle should contain one face. Zero or multiple faces
 1787        /// will be regarded as an error. If the provided "targetFace" rectangle is not
 1788        /// returned from [Face -
 1789        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
 1790        /// there’s no guarantee to detect and add the face successfully.
 1791        /// *   Out of detectable face size (36x36 - 4096x4096 pixels), large
 1792        /// head-pose, or large occlusions will cause failures.
 1793        /// *   Adding/deleting faces to/from a same person will be processed
 1794        /// sequentially. Adding/deleting faces to/from different persons are processed
 1795        /// in parallel.
 1796        /// * The minimum detectable face size is 36x36 pixels in an image no larger
 1797        /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels
 1798        /// will need a proportionally larger minimum face size.
 1799        /// * Different 'detectionModel' values can be provided. To use and compare
 1800        /// different detection models, please refer to [How to specify a detection
 1801        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti
 1802        /// | Model | Recommended use-case(s) |
 1803        /// | ---------- | -------- |
 1804        /// | 'detection_01': | The default detection model for [PersonGroup Person -
 1805        /// Add
 1806        /// Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b).
 1807        /// Recommend for near frontal face detection. For scenarios with exceptionally
 1808        /// large angle (head-pose) faces, occluded faces or wrong image orientation,
 1809        /// the faces in such cases may not be detected. |
 1810        /// | 'detection_02': | Detection model released in 2019 May with improved
 1811        /// accuracy especially on small, side and blurry faces. |
 1812        /// </summary>
 1813        /// <param name='personGroupId'>
 1814        /// Id referencing a particular person group.
 1815        /// </param>
 1816        /// <param name='personId'>
 1817        /// Id referencing a particular person.
 1818        /// </param>
 1819        /// <param name='image'>
 1820        /// An image stream.
 1821        /// </param>
 1822        /// <param name='userData'>
 1823        /// User-specified data about the face for any purpose. The maximum length is
 1824        /// 1KB.
 1825        /// </param>
 1826        /// <param name='targetFace'>
 1827        /// A face rectangle to specify the target face to be added to a person in the
 1828        /// format of "targetFace=left,top,width,height". E.g.
 1829        /// "targetFace=10,10,100,100". If there is more than one face in the image,
 1830        /// targetFace is required to specify which face to add. No targetFace means
 1831        /// there is only one face detected in the entire image.
 1832        /// </param>
 1833        /// <param name='detectionModel'>
 1834        /// Name of detection model. Detection model is used to detect faces in the
 1835        /// submitted image. A detection model name can be provided when performing
 1836        /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add
 1837        /// Face. The default value is 'detection_01', if another model is needed,
 1838        /// please explicitly specify it. Possible values include: 'detection_01',
 1839        /// 'detection_02'
 1840        /// </param>
 1841        /// <param name='customHeaders'>
 1842        /// Headers that will be added to request.
 1843        /// </param>
 1844        /// <param name='cancellationToken'>
 1845        /// The cancellation token.
 1846        /// </param>
 1847        /// <exception cref="APIErrorException">
 1848        /// Thrown when the operation returned an invalid status code
 1849        /// </exception>
 1850        /// <exception cref="SerializationException">
 1851        /// Thrown when unable to deserialize the response
 1852        /// </exception>
 1853        /// <exception cref="ValidationException">
 1854        /// Thrown when a required parameter is null
 1855        /// </exception>
 1856        /// <exception cref="System.ArgumentNullException">
 1857        /// Thrown when a required parameter is null
 1858        /// </exception>
 1859        /// <return>
 1860        /// A response object containing the response body and response headers.
 1861        /// </return>
 1862        public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromStreamWithHttpMessagesAsync(string personGrou
 1863        {
 181864            if (Client.Endpoint == null)
 1865            {
 01866                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1867            }
 181868            if (personGroupId == null)
 1869            {
 01870                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 1871            }
 181872            if (personGroupId != null)
 1873            {
 181874                if (personGroupId.Length > 64)
 1875                {
 01876                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 1877                }
 181878                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 1879                {
 01880                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$");
 1881                }
 1882            }
 181883            if (userData != null)
 1884            {
 01885                if (userData.Length > 1024)
 1886                {
 01887                    throw new ValidationException(ValidationRules.MaxLength, "userData", 1024);
 1888                }
 1889            }
 181890            if (image == null)
 1891            {
 01892                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 1893            }
 1894            // Tracing
 181895            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 181896            string _invocationId = null;
 181897            if (_shouldTrace)
 1898            {
 01899                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01900                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01901                tracingParameters.Add("personGroupId", personGroupId);
 01902                tracingParameters.Add("personId", personId);
 01903                tracingParameters.Add("userData", userData);
 01904                tracingParameters.Add("targetFace", targetFace);
 01905                tracingParameters.Add("image", image);
 01906                tracingParameters.Add("detectionModel", detectionModel);
 01907                tracingParameters.Add("cancellationToken", cancellationToken);
 01908                ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromStream", tracingParameters);
 1909            }
 1910            // Construct URL
 181911            var _baseUrl = Client.BaseUri;
 181912            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId}
 181913            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 181914            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 181915            _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 181916            List<string> _queryParameters = new List<string>();
 181917            if (userData != null)
 1918            {
 01919                _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData)));
 1920            }
 181921            if (targetFace != null)
 1922            {
 121923                _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target
 1924            }
 181925            if (detectionModel != null)
 1926            {
 181927                _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel)));
 1928            }
 181929            if (_queryParameters.Count > 0)
 1930            {
 181931                _url += "?" + string.Join("&", _queryParameters);
 1932            }
 1933            // Create HTTP transport objects
 181934            var _httpRequest = new HttpRequestMessage();
 181935            HttpResponseMessage _httpResponse = null;
 181936            _httpRequest.Method = new HttpMethod("POST");
 181937            _httpRequest.RequestUri = new System.Uri(_url);
 1938            // Set Headers
 1939
 1940
 181941            if (customHeaders != null)
 1942            {
 01943                foreach(var _header in customHeaders)
 1944                {
 01945                    if (_httpRequest.Headers.Contains(_header.Key))
 1946                    {
 01947                        _httpRequest.Headers.Remove(_header.Key);
 1948                    }
 01949                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1950                }
 1951            }
 1952
 1953            // Serialize Request
 181954            string _requestContent = null;
 181955            if(image == null)
 1956            {
 01957              throw new System.ArgumentNullException("image");
 1958            }
 181959            if (image != null && image != Stream.Null)
 1960            {
 181961                _httpRequest.Content = new StreamContent(image);
 181962                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1963            }
 1964            // Set Credentials
 181965            if (Client.Credentials != null)
 1966            {
 181967                cancellationToken.ThrowIfCancellationRequested();
 181968                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1969            }
 1970            // Send Request
 181971            if (_shouldTrace)
 1972            {
 01973                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1974            }
 181975            cancellationToken.ThrowIfCancellationRequested();
 181976            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 181977            if (_shouldTrace)
 1978            {
 01979                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1980            }
 181981            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 181982            cancellationToken.ThrowIfCancellationRequested();
 181983            string _responseContent = null;
 181984            if ((int)_statusCode != 200)
 1985            {
 01986                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1987                try
 1988                {
 01989                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01990                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01991                    if (_errorBody != null)
 1992                    {
 01993                        ex.Body = _errorBody;
 1994                    }
 01995                }
 01996                catch (JsonException)
 1997                {
 1998                    // Ignore the exception
 01999                }
 02000                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02001                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02002                if (_shouldTrace)
 2003                {
 02004                    ServiceClientTracing.Error(_invocationId, ex);
 2005                }
 02006                _httpRequest.Dispose();
 02007                if (_httpResponse != null)
 2008                {
 02009                    _httpResponse.Dispose();
 2010                }
 02011                throw ex;
 2012            }
 2013            // Create Result
 182014            var _result = new HttpOperationResponse<PersistedFace>();
 182015            _result.Request = _httpRequest;
 182016            _result.Response = _httpResponse;
 2017            // Deserialize Response
 182018            if ((int)_statusCode == 200)
 2019            {
 182020                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2021                try
 2022                {
 182023                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent,
 182024                }
 02025                catch (JsonException ex)
 2026                {
 02027                    _httpRequest.Dispose();
 02028                    if (_httpResponse != null)
 2029                    {
 02030                        _httpResponse.Dispose();
 2031                    }
 02032                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2033                }
 2034            }
 182035            if (_shouldTrace)
 2036            {
 02037                ServiceClientTracing.Exit(_invocationId, _result);
 2038            }
 182039            return _result;
 182040        }
 2041
 2042    }
 2043}