< Summary

Class:Microsoft.Azure.CognitiveServices.Vision.Face.FaceOperations
Assembly:Microsoft.Azure.CognitiveServices.Vision.Face
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\FaceOperations.cs
Covered lines:262
Uncovered lines:376
Coverable lines:638
Total lines:1707
Line coverage:41% (262 of 638)
Covered branches:141
Total branches:362
Branch coverage:38.9% (141 of 362)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
FindSimilarWithHttpMessagesAsync()-57.73%54.84%
GroupWithHttpMessagesAsync()-0%0%
IdentifyWithHttpMessagesAsync()-57.14%51.52%
VerifyFaceToFaceWithHttpMessagesAsync()-54.67%41.18%
DetectWithUrlWithHttpMessagesAsync()-0%0%
VerifyFaceToPersonWithHttpMessagesAsync()-56.82%52%
DetectWithStreamWithHttpMessagesAsync()-56.25%59.26%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\FaceOperations.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    /// FaceOperations operations.
 27    /// </summary>
 28    public partial class FaceOperations : IServiceOperations<FaceClient>, IFaceOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the FaceOperations 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 FaceOperations(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>
 111051        public FaceClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Given query face's faceId, to search the similar-looking faces from a
 55        /// faceId array, a face list or a large face list. faceId array contains the
 56        /// faces created by [Face -
 57        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
 58        /// which will expire 24 hours after creation. A "faceListId" is created by
 59        /// [FaceList -
 60        /// Create](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524b)
 61        /// containing persistedFaceIds that will not expire. And a "largeFaceListId"
 62        /// is created by [LargeFaceList -
 63        /// Create](/docs/services/563879b61984550e40cbbe8d/operations/5a157b68d2de3616c086f2cc)
 64        /// containing persistedFaceIds that will also not expire. Depending on the
 65        /// input the returned similar faces list contains faceIds or persistedFaceIds
 66        /// ranked by similarity.
 67        /// &lt;br/&gt;Find similar has two working modes, "matchPerson" and
 68        /// "matchFace". "matchPerson" is the default mode that it tries to find faces
 69        /// of the same person as possible by using internal same-person thresholds. It
 70        /// is useful to find a known person's other photos. Note that an empty list
 71        /// will be returned if no faces pass the internal thresholds. "matchFace" mode
 72        /// ignores same-person thresholds and returns ranked similar faces anyway,
 73        /// even the similarity is low. It can be used in the cases like searching
 74        /// celebrity-looking faces.
 75        /// &lt;br/&gt;The 'recognitionModel' associated with the query face's faceId
 76        /// should be the same as the 'recognitionModel' used by the target faceId
 77        /// array, face list or large face list.
 78        ///
 79        /// </summary>
 80        /// <param name='faceId'>
 81        /// FaceId of the query face. User needs to call Face - Detect first to get a
 82        /// valid faceId. Note that this faceId is not persisted and will expire 24
 83        /// hours after the detection call
 84        /// </param>
 85        /// <param name='faceListId'>
 86        /// An existing user-specified unique candidate face list, created in Face List
 87        /// - Create a Face List. Face list contains a set of persistedFaceIds which
 88        /// are persisted and will never expire. Parameter faceListId, largeFaceListId
 89        /// and faceIds should not be provided at the same time.
 90        /// </param>
 91        /// <param name='largeFaceListId'>
 92        /// An existing user-specified unique candidate large face list, created in
 93        /// LargeFaceList - Create. Large face list contains a set of persistedFaceIds
 94        /// which are persisted and will never expire. Parameter faceListId,
 95        /// largeFaceListId and faceIds should not be provided at the same time.
 96        /// </param>
 97        /// <param name='faceIds'>
 98        /// An array of candidate faceIds. All of them are created by Face - Detect and
 99        /// the faceIds will expire 24 hours after the detection call. The number of
 100        /// faceIds is limited to 1000. Parameter faceListId, largeFaceListId and
 101        /// faceIds should not be provided at the same time.
 102        /// </param>
 103        /// <param name='maxNumOfCandidatesReturned'>
 104        /// The number of top similar faces returned. The valid range is [1, 1000].
 105        /// </param>
 106        /// <param name='mode'>
 107        /// Similar face searching mode. It can be "matchPerson" or "matchFace".
 108        /// Possible values include: 'matchPerson', 'matchFace'
 109        /// </param>
 110        /// <param name='customHeaders'>
 111        /// Headers that will be added to request.
 112        /// </param>
 113        /// <param name='cancellationToken'>
 114        /// The cancellation token.
 115        /// </param>
 116        /// <exception cref="APIErrorException">
 117        /// Thrown when the operation returned an invalid status code
 118        /// </exception>
 119        /// <exception cref="SerializationException">
 120        /// Thrown when unable to deserialize the response
 121        /// </exception>
 122        /// <exception cref="ValidationException">
 123        /// Thrown when a required parameter is null
 124        /// </exception>
 125        /// <exception cref="System.ArgumentNullException">
 126        /// Thrown when a required parameter is null
 127        /// </exception>
 128        /// <return>
 129        /// A response object containing the response body and response headers.
 130        /// </return>
 131        public async Task<HttpOperationResponse<IList<SimilarFace>>> FindSimilarWithHttpMessagesAsync(System.Guid faceId
 132        {
 6133            if (Client.Endpoint == null)
 134            {
 0135                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 136            }
 6137            if (faceListId != null)
 138            {
 2139                if (faceListId.Length > 64)
 140                {
 0141                    throw new ValidationException(ValidationRules.MaxLength, "faceListId", 64);
 142                }
 2143                if (!System.Text.RegularExpressions.Regex.IsMatch(faceListId, "^[a-z0-9-_]+$"))
 144                {
 0145                    throw new ValidationException(ValidationRules.Pattern, "faceListId", "^[a-z0-9-_]+$");
 146                }
 147            }
 6148            if (largeFaceListId != null)
 149            {
 2150                if (largeFaceListId.Length > 64)
 151                {
 0152                    throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64);
 153                }
 2154                if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$"))
 155                {
 0156                    throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$");
 157                }
 158            }
 6159            if (faceIds != null)
 160            {
 2161                if (faceIds.Count > 1000)
 162                {
 0163                    throw new ValidationException(ValidationRules.MaxItems, "faceIds", 1000);
 164                }
 165            }
 6166            if (maxNumOfCandidatesReturned > 1000)
 167            {
 0168                throw new ValidationException(ValidationRules.InclusiveMaximum, "maxNumOfCandidatesReturned", 1000);
 169            }
 6170            if (maxNumOfCandidatesReturned < 1)
 171            {
 0172                throw new ValidationException(ValidationRules.InclusiveMinimum, "maxNumOfCandidatesReturned", 1);
 173            }
 6174            FindSimilarRequest body = new FindSimilarRequest();
 6175            if (faceListId != null || largeFaceListId != null || faceIds != null || maxNumOfCandidatesReturned != null)
 176            {
 6177                body.FaceId = faceId;
 6178                body.FaceListId = faceListId;
 6179                body.LargeFaceListId = largeFaceListId;
 6180                body.FaceIds = faceIds;
 6181                body.MaxNumOfCandidatesReturned = maxNumOfCandidatesReturned;
 6182                body.Mode = mode;
 183            }
 184            // Tracing
 6185            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 6186            string _invocationId = null;
 6187            if (_shouldTrace)
 188            {
 0189                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0190                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0191                tracingParameters.Add("body", body);
 0192                tracingParameters.Add("cancellationToken", cancellationToken);
 0193                ServiceClientTracing.Enter(_invocationId, this, "FindSimilar", tracingParameters);
 194            }
 195            // Construct URL
 6196            var _baseUrl = Client.BaseUri;
 6197            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "findsimilars";
 6198            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 199            // Create HTTP transport objects
 6200            var _httpRequest = new HttpRequestMessage();
 6201            HttpResponseMessage _httpResponse = null;
 6202            _httpRequest.Method = new HttpMethod("POST");
 6203            _httpRequest.RequestUri = new System.Uri(_url);
 204            // Set Headers
 205
 206
 6207            if (customHeaders != null)
 208            {
 0209                foreach(var _header in customHeaders)
 210                {
 0211                    if (_httpRequest.Headers.Contains(_header.Key))
 212                    {
 0213                        _httpRequest.Headers.Remove(_header.Key);
 214                    }
 0215                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 216                }
 217            }
 218
 219            // Serialize Request
 6220            string _requestContent = null;
 6221            if(body != null)
 222            {
 6223                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 6224                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 6225                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 226            }
 227            // Set Credentials
 6228            if (Client.Credentials != null)
 229            {
 6230                cancellationToken.ThrowIfCancellationRequested();
 6231                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 232            }
 233            // Send Request
 6234            if (_shouldTrace)
 235            {
 0236                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 237            }
 6238            cancellationToken.ThrowIfCancellationRequested();
 6239            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 6240            if (_shouldTrace)
 241            {
 0242                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 243            }
 6244            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 6245            cancellationToken.ThrowIfCancellationRequested();
 6246            string _responseContent = null;
 6247            if ((int)_statusCode != 200)
 248            {
 0249                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 250                try
 251                {
 0252                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0253                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0254                    if (_errorBody != null)
 255                    {
 0256                        ex.Body = _errorBody;
 257                    }
 0258                }
 0259                catch (JsonException)
 260                {
 261                    // Ignore the exception
 0262                }
 0263                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0264                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0265                if (_shouldTrace)
 266                {
 0267                    ServiceClientTracing.Error(_invocationId, ex);
 268                }
 0269                _httpRequest.Dispose();
 0270                if (_httpResponse != null)
 271                {
 0272                    _httpResponse.Dispose();
 273                }
 0274                throw ex;
 275            }
 276            // Create Result
 6277            var _result = new HttpOperationResponse<IList<SimilarFace>>();
 6278            _result.Request = _httpRequest;
 6279            _result.Response = _httpResponse;
 280            // Deserialize Response
 6281            if ((int)_statusCode == 200)
 282            {
 6283                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 284                try
 285                {
 6286                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<SimilarFace>>(_responseCon
 6287                }
 0288                catch (JsonException ex)
 289                {
 0290                    _httpRequest.Dispose();
 0291                    if (_httpResponse != null)
 292                    {
 0293                        _httpResponse.Dispose();
 294                    }
 0295                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 296                }
 297            }
 6298            if (_shouldTrace)
 299            {
 0300                ServiceClientTracing.Exit(_invocationId, _result);
 301            }
 6302            return _result;
 6303        }
 304
 305        /// <summary>
 306        /// Divide candidate faces into groups based on face similarity.&lt;br /&gt;
 307        /// * The output is one or more disjointed face groups and a messyGroup. A face
 308        /// group contains faces that have similar looking, often of the same person.
 309        /// Face groups are ranked by group size, i.e. number of faces. Notice that
 310        /// faces belonging to a same person might be split into several groups in the
 311        /// result.
 312        /// * MessyGroup is a special face group containing faces that cannot find any
 313        /// similar counterpart face from original faces. The messyGroup will not
 314        /// appear in the result if all faces found their counterparts.
 315        /// * Group API needs at least 2 candidate faces and 1000 at most. We suggest
 316        /// to try [Face -
 317        /// Verify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a)
 318        /// when you only have 2 candidate faces.
 319        /// * The 'recognitionModel' associated with the query faces' faceIds should be
 320        /// the same.
 321        ///
 322        /// </summary>
 323        /// <param name='faceIds'>
 324        /// Array of candidate faceId created by Face - Detect. The maximum is 1000
 325        /// faces
 326        /// </param>
 327        /// <param name='customHeaders'>
 328        /// Headers that will be added to request.
 329        /// </param>
 330        /// <param name='cancellationToken'>
 331        /// The cancellation token.
 332        /// </param>
 333        /// <exception cref="APIErrorException">
 334        /// Thrown when the operation returned an invalid status code
 335        /// </exception>
 336        /// <exception cref="SerializationException">
 337        /// Thrown when unable to deserialize the response
 338        /// </exception>
 339        /// <exception cref="ValidationException">
 340        /// Thrown when a required parameter is null
 341        /// </exception>
 342        /// <exception cref="System.ArgumentNullException">
 343        /// Thrown when a required parameter is null
 344        /// </exception>
 345        /// <return>
 346        /// A response object containing the response body and response headers.
 347        /// </return>
 348        public async Task<HttpOperationResponse<GroupResult>> GroupWithHttpMessagesAsync(IList<System.Guid> faceIds, Dic
 349        {
 0350            if (Client.Endpoint == null)
 351            {
 0352                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 353            }
 0354            if (faceIds == null)
 355            {
 0356                throw new ValidationException(ValidationRules.CannotBeNull, "faceIds");
 357            }
 0358            if (faceIds != null)
 359            {
 0360                if (faceIds.Count > 1000)
 361                {
 0362                    throw new ValidationException(ValidationRules.MaxItems, "faceIds", 1000);
 363                }
 364            }
 0365            GroupRequest body = new GroupRequest();
 0366            if (faceIds != null)
 367            {
 0368                body.FaceIds = faceIds;
 369            }
 370            // Tracing
 0371            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0372            string _invocationId = null;
 0373            if (_shouldTrace)
 374            {
 0375                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0376                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0377                tracingParameters.Add("body", body);
 0378                tracingParameters.Add("cancellationToken", cancellationToken);
 0379                ServiceClientTracing.Enter(_invocationId, this, "Group", tracingParameters);
 380            }
 381            // Construct URL
 0382            var _baseUrl = Client.BaseUri;
 0383            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "group";
 0384            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 385            // Create HTTP transport objects
 0386            var _httpRequest = new HttpRequestMessage();
 0387            HttpResponseMessage _httpResponse = null;
 0388            _httpRequest.Method = new HttpMethod("POST");
 0389            _httpRequest.RequestUri = new System.Uri(_url);
 390            // Set Headers
 391
 392
 0393            if (customHeaders != null)
 394            {
 0395                foreach(var _header in customHeaders)
 396                {
 0397                    if (_httpRequest.Headers.Contains(_header.Key))
 398                    {
 0399                        _httpRequest.Headers.Remove(_header.Key);
 400                    }
 0401                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 402                }
 403            }
 404
 405            // Serialize Request
 0406            string _requestContent = null;
 0407            if(body != null)
 408            {
 0409                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 0410                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0411                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 412            }
 413            // Set Credentials
 0414            if (Client.Credentials != null)
 415            {
 0416                cancellationToken.ThrowIfCancellationRequested();
 0417                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 418            }
 419            // Send Request
 0420            if (_shouldTrace)
 421            {
 0422                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 423            }
 0424            cancellationToken.ThrowIfCancellationRequested();
 0425            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0426            if (_shouldTrace)
 427            {
 0428                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 429            }
 0430            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0431            cancellationToken.ThrowIfCancellationRequested();
 0432            string _responseContent = null;
 0433            if ((int)_statusCode != 200)
 434            {
 0435                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 436                try
 437                {
 0438                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0439                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0440                    if (_errorBody != null)
 441                    {
 0442                        ex.Body = _errorBody;
 443                    }
 0444                }
 0445                catch (JsonException)
 446                {
 447                    // Ignore the exception
 0448                }
 0449                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0450                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0451                if (_shouldTrace)
 452                {
 0453                    ServiceClientTracing.Error(_invocationId, ex);
 454                }
 0455                _httpRequest.Dispose();
 0456                if (_httpResponse != null)
 457                {
 0458                    _httpResponse.Dispose();
 459                }
 0460                throw ex;
 461            }
 462            // Create Result
 0463            var _result = new HttpOperationResponse<GroupResult>();
 0464            _result.Request = _httpRequest;
 0465            _result.Response = _httpResponse;
 466            // Deserialize Response
 0467            if ((int)_statusCode == 200)
 468            {
 0469                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 470                try
 471                {
 0472                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<GroupResult>(_responseContent, C
 0473                }
 0474                catch (JsonException ex)
 475                {
 0476                    _httpRequest.Dispose();
 0477                    if (_httpResponse != null)
 478                    {
 0479                        _httpResponse.Dispose();
 480                    }
 0481                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 482                }
 483            }
 0484            if (_shouldTrace)
 485            {
 0486                ServiceClientTracing.Exit(_invocationId, _result);
 487            }
 0488            return _result;
 0489        }
 490
 491        /// <summary>
 492        /// 1-to-many identification to find the closest matches of the specific query
 493        /// person face from a person group or large person group.
 494        /// &lt;br/&gt; For each face in the faceIds array, Face Identify will compute
 495        /// similarities between the query face and all the faces in the person group
 496        /// (given by personGroupId) or large person group (given by
 497        /// largePersonGroupId), and return candidate person(s) for that face ranked by
 498        /// similarity confidence. The person group/large person group should be
 499        /// trained to make it ready for identification. See more in [PersonGroup -
 500        /// Train](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395249)
 501        /// and [LargePersonGroup -
 502        /// Train](/docs/services/563879b61984550e40cbbe8d/operations/599ae2d16ac60f11b48b5aa4).
 503        /// &lt;br/&gt;
 504        ///
 505        /// Remarks:&lt;br /&gt;
 506        /// * The algorithm allows more than one face to be identified independently at
 507        /// the same request, but no more than 10 faces.
 508        /// * Each person in the person group/large person group could have more than
 509        /// one face, but no more than 248 faces.
 510        /// * Higher face image quality means better identification precision. Please
 511        /// consider high-quality faces: frontal, clear, and face size is 200x200
 512        /// pixels (100 pixels between eyes) or bigger.
 513        /// * Number of candidates returned is restricted by maxNumOfCandidatesReturned
 514        /// and confidenceThreshold. If no person is identified, the returned
 515        /// candidates will be an empty array.
 516        /// * Try [Face - Find
 517        /// Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237)
 518        /// when you need to find similar faces from a face list/large face list
 519        /// instead of a person group/large person group.
 520        /// * The 'recognitionModel' associated with the query faces' faceIds should be
 521        /// the same as the 'recognitionModel' used by the target person group or large
 522        /// person group.
 523        ///
 524        /// </summary>
 525        /// <param name='faceIds'>
 526        /// Array of query faces faceIds, created by the Face - Detect. Each of the
 527        /// faces are identified independently. The valid number of faceIds is between
 528        /// [1, 10].
 529        /// </param>
 530        /// <param name='personGroupId'>
 531        /// PersonGroupId of the target person group, created by PersonGroup - Create.
 532        /// Parameter personGroupId and largePersonGroupId should not be provided at
 533        /// the same time.
 534        /// </param>
 535        /// <param name='largePersonGroupId'>
 536        /// LargePersonGroupId of the target large person group, created by
 537        /// LargePersonGroup - Create. Parameter personGroupId and largePersonGroupId
 538        /// should not be provided at the same time.
 539        /// </param>
 540        /// <param name='maxNumOfCandidatesReturned'>
 541        /// The range of maxNumOfCandidatesReturned is between 1 and 5 (default is 1).
 542        /// </param>
 543        /// <param name='confidenceThreshold'>
 544        /// Confidence threshold of identification, used to judge whether one face
 545        /// belong to one person. The range of confidenceThreshold is [0, 1] (default
 546        /// specified by algorithm).
 547        /// </param>
 548        /// <param name='customHeaders'>
 549        /// Headers that will be added to request.
 550        /// </param>
 551        /// <param name='cancellationToken'>
 552        /// The cancellation token.
 553        /// </param>
 554        /// <exception cref="APIErrorException">
 555        /// Thrown when the operation returned an invalid status code
 556        /// </exception>
 557        /// <exception cref="SerializationException">
 558        /// Thrown when unable to deserialize the response
 559        /// </exception>
 560        /// <exception cref="ValidationException">
 561        /// Thrown when a required parameter is null
 562        /// </exception>
 563        /// <exception cref="System.ArgumentNullException">
 564        /// Thrown when a required parameter is null
 565        /// </exception>
 566        /// <return>
 567        /// A response object containing the response body and response headers.
 568        /// </return>
 569        public async Task<HttpOperationResponse<IList<IdentifyResult>>> IdentifyWithHttpMessagesAsync(IList<System.Guid>
 570        {
 4571            if (Client.Endpoint == null)
 572            {
 0573                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 574            }
 4575            if (faceIds == null)
 576            {
 0577                throw new ValidationException(ValidationRules.CannotBeNull, "faceIds");
 578            }
 4579            if (faceIds != null)
 580            {
 4581                if (faceIds.Count > 10)
 582                {
 0583                    throw new ValidationException(ValidationRules.MaxItems, "faceIds", 10);
 584                }
 585            }
 4586            if (personGroupId != null)
 587            {
 2588                if (personGroupId.Length > 64)
 589                {
 0590                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 591                }
 2592                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 593                {
 0594                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$");
 595                }
 596            }
 4597            if (largePersonGroupId != null)
 598            {
 2599                if (largePersonGroupId.Length > 64)
 600                {
 0601                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 602                }
 2603                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 604                {
 0605                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 606                }
 607            }
 4608            if (maxNumOfCandidatesReturned > 5)
 609            {
 0610                throw new ValidationException(ValidationRules.InclusiveMaximum, "maxNumOfCandidatesReturned", 5);
 611            }
 4612            if (maxNumOfCandidatesReturned < 1)
 613            {
 0614                throw new ValidationException(ValidationRules.InclusiveMinimum, "maxNumOfCandidatesReturned", 1);
 615            }
 4616            IdentifyRequest body = new IdentifyRequest();
 4617            if (faceIds != null || personGroupId != null || largePersonGroupId != null || maxNumOfCandidatesReturned != 
 618            {
 4619                body.FaceIds = faceIds;
 4620                body.PersonGroupId = personGroupId;
 4621                body.LargePersonGroupId = largePersonGroupId;
 4622                body.MaxNumOfCandidatesReturned = maxNumOfCandidatesReturned;
 4623                body.ConfidenceThreshold = confidenceThreshold;
 624            }
 625            // Tracing
 4626            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 4627            string _invocationId = null;
 4628            if (_shouldTrace)
 629            {
 0630                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0631                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0632                tracingParameters.Add("body", body);
 0633                tracingParameters.Add("cancellationToken", cancellationToken);
 0634                ServiceClientTracing.Enter(_invocationId, this, "Identify", tracingParameters);
 635            }
 636            // Construct URL
 4637            var _baseUrl = Client.BaseUri;
 4638            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "identify";
 4639            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 640            // Create HTTP transport objects
 4641            var _httpRequest = new HttpRequestMessage();
 4642            HttpResponseMessage _httpResponse = null;
 4643            _httpRequest.Method = new HttpMethod("POST");
 4644            _httpRequest.RequestUri = new System.Uri(_url);
 645            // Set Headers
 646
 647
 4648            if (customHeaders != null)
 649            {
 0650                foreach(var _header in customHeaders)
 651                {
 0652                    if (_httpRequest.Headers.Contains(_header.Key))
 653                    {
 0654                        _httpRequest.Headers.Remove(_header.Key);
 655                    }
 0656                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 657                }
 658            }
 659
 660            // Serialize Request
 4661            string _requestContent = null;
 4662            if(body != null)
 663            {
 4664                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 4665                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 4666                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 667            }
 668            // Set Credentials
 4669            if (Client.Credentials != null)
 670            {
 4671                cancellationToken.ThrowIfCancellationRequested();
 4672                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 673            }
 674            // Send Request
 4675            if (_shouldTrace)
 676            {
 0677                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 678            }
 4679            cancellationToken.ThrowIfCancellationRequested();
 4680            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4681            if (_shouldTrace)
 682            {
 0683                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 684            }
 4685            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 4686            cancellationToken.ThrowIfCancellationRequested();
 4687            string _responseContent = null;
 4688            if ((int)_statusCode != 200)
 689            {
 0690                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 691                try
 692                {
 0693                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0694                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0695                    if (_errorBody != null)
 696                    {
 0697                        ex.Body = _errorBody;
 698                    }
 0699                }
 0700                catch (JsonException)
 701                {
 702                    // Ignore the exception
 0703                }
 0704                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0705                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0706                if (_shouldTrace)
 707                {
 0708                    ServiceClientTracing.Error(_invocationId, ex);
 709                }
 0710                _httpRequest.Dispose();
 0711                if (_httpResponse != null)
 712                {
 0713                    _httpResponse.Dispose();
 714                }
 0715                throw ex;
 716            }
 717            // Create Result
 4718            var _result = new HttpOperationResponse<IList<IdentifyResult>>();
 4719            _result.Request = _httpRequest;
 4720            _result.Response = _httpResponse;
 721            // Deserialize Response
 4722            if ((int)_statusCode == 200)
 723            {
 4724                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 725                try
 726                {
 4727                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<IdentifyResult>>(_response
 4728                }
 0729                catch (JsonException ex)
 730                {
 0731                    _httpRequest.Dispose();
 0732                    if (_httpResponse != null)
 733                    {
 0734                        _httpResponse.Dispose();
 735                    }
 0736                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 737                }
 738            }
 4739            if (_shouldTrace)
 740            {
 0741                ServiceClientTracing.Exit(_invocationId, _result);
 742            }
 4743            return _result;
 4744        }
 745
 746        /// <summary>
 747        /// Verify whether two faces belong to a same person or whether one face
 748        /// belongs to a person.
 749        /// &lt;br/&gt;
 750        /// Remarks:&lt;br /&gt;
 751        /// * Higher face image quality means better identification precision. Please
 752        /// consider high-quality faces: frontal, clear, and face size is 200x200
 753        /// pixels (100 pixels between eyes) or bigger.
 754        /// * For the scenarios that are sensitive to accuracy please make your own
 755        /// judgment.
 756        /// * The 'recognitionModel' associated with the query faces' faceIds should be
 757        /// the same as the 'recognitionModel' used by the target face, person group or
 758        /// large person group.
 759        ///
 760        /// </summary>
 761        /// <param name='faceId1'>
 762        /// FaceId of the first face, comes from Face - Detect
 763        /// </param>
 764        /// <param name='faceId2'>
 765        /// FaceId of the second face, comes from Face - Detect
 766        /// </param>
 767        /// <param name='customHeaders'>
 768        /// Headers that will be added to request.
 769        /// </param>
 770        /// <param name='cancellationToken'>
 771        /// The cancellation token.
 772        /// </param>
 773        /// <exception cref="APIErrorException">
 774        /// Thrown when the operation returned an invalid status code
 775        /// </exception>
 776        /// <exception cref="SerializationException">
 777        /// Thrown when unable to deserialize the response
 778        /// </exception>
 779        /// <exception cref="ValidationException">
 780        /// Thrown when a required parameter is null
 781        /// </exception>
 782        /// <exception cref="System.ArgumentNullException">
 783        /// Thrown when a required parameter is null
 784        /// </exception>
 785        /// <return>
 786        /// A response object containing the response body and response headers.
 787        /// </return>
 788        public async Task<HttpOperationResponse<VerifyResult>> VerifyFaceToFaceWithHttpMessagesAsync(System.Guid faceId1
 789        {
 4790            if (Client.Endpoint == null)
 791            {
 0792                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 793            }
 4794            VerifyFaceToFaceRequest body = new VerifyFaceToFaceRequest();
 4795            body.FaceId1 = faceId1;
 4796            body.FaceId2 = faceId2;
 797            // Tracing
 4798            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 4799            string _invocationId = null;
 4800            if (_shouldTrace)
 801            {
 0802                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0803                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0804                tracingParameters.Add("body", body);
 0805                tracingParameters.Add("cancellationToken", cancellationToken);
 0806                ServiceClientTracing.Enter(_invocationId, this, "VerifyFaceToFace", tracingParameters);
 807            }
 808            // Construct URL
 4809            var _baseUrl = Client.BaseUri;
 4810            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "verify";
 4811            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 812            // Create HTTP transport objects
 4813            var _httpRequest = new HttpRequestMessage();
 4814            HttpResponseMessage _httpResponse = null;
 4815            _httpRequest.Method = new HttpMethod("POST");
 4816            _httpRequest.RequestUri = new System.Uri(_url);
 817            // Set Headers
 818
 819
 4820            if (customHeaders != null)
 821            {
 0822                foreach(var _header in customHeaders)
 823                {
 0824                    if (_httpRequest.Headers.Contains(_header.Key))
 825                    {
 0826                        _httpRequest.Headers.Remove(_header.Key);
 827                    }
 0828                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 829                }
 830            }
 831
 832            // Serialize Request
 4833            string _requestContent = null;
 4834            if(body != null)
 835            {
 4836                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 4837                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 4838                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 839            }
 840            // Set Credentials
 4841            if (Client.Credentials != null)
 842            {
 4843                cancellationToken.ThrowIfCancellationRequested();
 4844                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 845            }
 846            // Send Request
 4847            if (_shouldTrace)
 848            {
 0849                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 850            }
 4851            cancellationToken.ThrowIfCancellationRequested();
 4852            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4853            if (_shouldTrace)
 854            {
 0855                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 856            }
 4857            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 4858            cancellationToken.ThrowIfCancellationRequested();
 4859            string _responseContent = null;
 4860            if ((int)_statusCode != 200)
 861            {
 0862                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 863                try
 864                {
 0865                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0866                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0867                    if (_errorBody != null)
 868                    {
 0869                        ex.Body = _errorBody;
 870                    }
 0871                }
 0872                catch (JsonException)
 873                {
 874                    // Ignore the exception
 0875                }
 0876                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0877                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0878                if (_shouldTrace)
 879                {
 0880                    ServiceClientTracing.Error(_invocationId, ex);
 881                }
 0882                _httpRequest.Dispose();
 0883                if (_httpResponse != null)
 884                {
 0885                    _httpResponse.Dispose();
 886                }
 0887                throw ex;
 888            }
 889            // Create Result
 4890            var _result = new HttpOperationResponse<VerifyResult>();
 4891            _result.Request = _httpRequest;
 4892            _result.Response = _httpResponse;
 893            // Deserialize Response
 4894            if ((int)_statusCode == 200)
 895            {
 4896                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 897                try
 898                {
 4899                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<VerifyResult>(_responseContent, 
 4900                }
 0901                catch (JsonException ex)
 902                {
 0903                    _httpRequest.Dispose();
 0904                    if (_httpResponse != null)
 905                    {
 0906                        _httpResponse.Dispose();
 907                    }
 0908                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 909                }
 910            }
 4911            if (_shouldTrace)
 912            {
 0913                ServiceClientTracing.Exit(_invocationId, _result);
 914            }
 4915            return _result;
 4916        }
 917
 918        /// <summary>
 919        /// Detect human faces in an image, return face rectangles, and optionally with
 920        /// faceIds, landmarks, and attributes.&lt;br /&gt;
 921        /// * No image will be stored. Only the extracted face feature will be stored
 922        /// on server. The faceId is an identifier of the face feature and will be used
 923        /// in [Face -
 924        /// Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239),
 925        /// [Face -
 926        /// Verify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a),
 927        /// and [Face - Find
 928        /// Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237).
 929        /// The stored face feature(s) will expire and be deleted 24 hours after the
 930        /// original detection call.
 931        /// * Optional parameters include faceId, landmarks, and attributes. Attributes
 932        /// include age, gender, headPose, smile, facialHair, glasses, emotion, hair,
 933        /// makeup, occlusion, accessories, blur, exposure and noise. Some of the
 934        /// results returned for specific attributes may not be highly accurate.
 935        /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The
 936        /// allowed image file size is from 1KB to 6MB.
 937        /// * Up to 100 faces can be returned for an image. Faces are ranked by face
 938        /// rectangle size from large to small.
 939        /// * For optimal results when querying [Face -
 940        /// Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239),
 941        /// [Face -
 942        /// Verify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a),
 943        /// and [Face - Find
 944        /// Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237)
 945        /// ('returnFaceId' is true), please use faces that are: frontal, clear, and
 946        /// with a minimum size of 200x200 pixels (100 pixels between eyes).
 947        /// * The minimum detectable face size is 36x36 pixels in an image no larger
 948        /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels
 949        /// will need a proportionally larger minimum face size.
 950        /// * Different 'detectionModel' values can be provided. To use and compare
 951        /// different detection models, please refer to [How to specify a detection
 952        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti
 953        /// | Model | Recommended use-case(s) |
 954        /// | ---------- | -------- |
 955        /// | 'detection_01': | The default detection model for [Face -
 956        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 957        /// Recommend for near frontal face detection. For scenarios with exceptionally
 958        /// large angle (head-pose) faces, occluded faces or wrong image orientation,
 959        /// the faces in such cases may not be detected. |
 960        /// | 'detection_02': | Detection model released in 2019 May with improved
 961        /// accuracy especially on small, side and blurry faces. |
 962        ///
 963        /// * Different 'recognitionModel' values are provided. If follow-up operations
 964        /// like Verify, Identify, Find Similar are needed, please specify the
 965        /// recognition model with 'recognitionModel' parameter. The default value for
 966        /// 'recognitionModel' is 'recognition_01', if latest model needed, please
 967        /// explicitly specify the model you need in this parameter. Once specified,
 968        /// the detected faceIds will be associated with the specified recognition
 969        /// model. More details, please refer to [How to specify a recognition
 970        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-recogni
 971        /// | Model | Recommended use-case(s) |
 972        /// | ---------- | -------- |
 973        /// | 'recognition_01': | The default recognition model for [Face -
 974        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 975        /// All those faceIds created before 2019 March are bonded with this
 976        /// recognition model. |
 977        /// | 'recognition_02': | Recognition model released in 2019 March.
 978        /// 'recognition_02' is recommended since its overall accuracy is improved
 979        /// compared with 'recognition_01'. |
 980        /// </summary>
 981        /// <param name='url'>
 982        /// Publicly reachable URL of an image
 983        /// </param>
 984        /// <param name='returnFaceId'>
 985        /// A value indicating whether the operation should return faceIds of detected
 986        /// faces.
 987        /// </param>
 988        /// <param name='returnFaceLandmarks'>
 989        /// A value indicating whether the operation should return landmarks of the
 990        /// detected faces.
 991        /// </param>
 992        /// <param name='returnFaceAttributes'>
 993        /// Analyze and return the one or more specified face attributes in the
 994        /// comma-separated string like "returnFaceAttributes=age,gender". Supported
 995        /// face attributes include age, gender, headPose, smile, facialHair, glasses
 996        /// and emotion. Note that each face attribute analysis has additional
 997        /// computational and time cost.
 998        /// </param>
 999        /// <param name='recognitionModel'>
 1000        /// Name of recognition model. Recognition model is used when the face features
 1001        /// are extracted and associated with detected faceIds, (Large)FaceList or
 1002        /// (Large)PersonGroup. A recognition model name can be provided when
 1003        /// performing Face - Detect or (Large)FaceList - Create or (Large)PersonGroup
 1004        /// - Create. The default value is 'recognition_01', if latest model needed,
 1005        /// please explicitly specify the model you need. Possible values include:
 1006        /// 'recognition_01', 'recognition_02'
 1007        /// </param>
 1008        /// <param name='returnRecognitionModel'>
 1009        /// A value indicating whether the operation should return 'recognitionModel'
 1010        /// in response.
 1011        /// </param>
 1012        /// <param name='detectionModel'>
 1013        /// Name of detection model. Detection model is used to detect faces in the
 1014        /// submitted image. A detection model name can be provided when performing
 1015        /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add
 1016        /// Face. The default value is 'detection_01', if another model is needed,
 1017        /// please explicitly specify it. Possible values include: 'detection_01',
 1018        /// 'detection_02'
 1019        /// </param>
 1020        /// <param name='customHeaders'>
 1021        /// Headers that will be added to request.
 1022        /// </param>
 1023        /// <param name='cancellationToken'>
 1024        /// The cancellation token.
 1025        /// </param>
 1026        /// <exception cref="APIErrorException">
 1027        /// Thrown when the operation returned an invalid status code
 1028        /// </exception>
 1029        /// <exception cref="SerializationException">
 1030        /// Thrown when unable to deserialize the response
 1031        /// </exception>
 1032        /// <exception cref="ValidationException">
 1033        /// Thrown when a required parameter is null
 1034        /// </exception>
 1035        /// <exception cref="System.ArgumentNullException">
 1036        /// Thrown when a required parameter is null
 1037        /// </exception>
 1038        /// <return>
 1039        /// A response object containing the response body and response headers.
 1040        /// </return>
 1041        public async Task<HttpOperationResponse<IList<DetectedFace>>> DetectWithUrlWithHttpMessagesAsync(string url, boo
 1042        {
 01043            if (Client.Endpoint == null)
 1044            {
 01045                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1046            }
 01047            if (url == null)
 1048            {
 01049                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 1050            }
 01051            ImageUrl imageUrl = new ImageUrl();
 01052            if (url != null)
 1053            {
 01054                imageUrl.Url = url;
 1055            }
 1056            // Tracing
 01057            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01058            string _invocationId = null;
 01059            if (_shouldTrace)
 1060            {
 01061                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01062                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01063                tracingParameters.Add("returnFaceId", returnFaceId);
 01064                tracingParameters.Add("returnFaceLandmarks", returnFaceLandmarks);
 01065                tracingParameters.Add("returnFaceAttributes", returnFaceAttributes);
 01066                tracingParameters.Add("recognitionModel", recognitionModel);
 01067                tracingParameters.Add("returnRecognitionModel", returnRecognitionModel);
 01068                tracingParameters.Add("detectionModel", detectionModel);
 01069                tracingParameters.Add("imageUrl", imageUrl);
 01070                tracingParameters.Add("cancellationToken", cancellationToken);
 01071                ServiceClientTracing.Enter(_invocationId, this, "DetectWithUrl", tracingParameters);
 1072            }
 1073            // Construct URL
 01074            var _baseUrl = Client.BaseUri;
 01075            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "detect";
 01076            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01077            List<string> _queryParameters = new List<string>();
 01078            if (returnFaceId != null)
 1079            {
 01080                _queryParameters.Add(string.Format("returnFaceId={0}", System.Uri.EscapeDataString(Rest.Serialization.Sa
 1081            }
 01082            if (returnFaceLandmarks != null)
 1083            {
 01084                _queryParameters.Add(string.Format("returnFaceLandmarks={0}", System.Uri.EscapeDataString(Rest.Serializa
 1085            }
 01086            if (returnFaceAttributes != null)
 1087            {
 01088                _queryParameters.Add(string.Format("returnFaceAttributes={0}", System.Uri.EscapeDataString(string.Join("
 1089            }
 01090            if (recognitionModel != null)
 1091            {
 01092                _queryParameters.Add(string.Format("recognitionModel={0}", System.Uri.EscapeDataString(recognitionModel)
 1093            }
 01094            if (returnRecognitionModel != null)
 1095            {
 01096                _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial
 1097            }
 01098            if (detectionModel != null)
 1099            {
 01100                _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel)));
 1101            }
 01102            if (_queryParameters.Count > 0)
 1103            {
 01104                _url += "?" + string.Join("&", _queryParameters);
 1105            }
 1106            // Create HTTP transport objects
 01107            var _httpRequest = new HttpRequestMessage();
 01108            HttpResponseMessage _httpResponse = null;
 01109            _httpRequest.Method = new HttpMethod("POST");
 01110            _httpRequest.RequestUri = new System.Uri(_url);
 1111            // Set Headers
 1112
 1113
 01114            if (customHeaders != null)
 1115            {
 01116                foreach(var _header in customHeaders)
 1117                {
 01118                    if (_httpRequest.Headers.Contains(_header.Key))
 1119                    {
 01120                        _httpRequest.Headers.Remove(_header.Key);
 1121                    }
 01122                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1123                }
 1124            }
 1125
 1126            // Serialize Request
 01127            string _requestContent = null;
 01128            if(imageUrl != null)
 1129            {
 01130                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti
 01131                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01132                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1133            }
 1134            // Set Credentials
 01135            if (Client.Credentials != null)
 1136            {
 01137                cancellationToken.ThrowIfCancellationRequested();
 01138                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1139            }
 1140            // Send Request
 01141            if (_shouldTrace)
 1142            {
 01143                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1144            }
 01145            cancellationToken.ThrowIfCancellationRequested();
 01146            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01147            if (_shouldTrace)
 1148            {
 01149                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1150            }
 01151            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01152            cancellationToken.ThrowIfCancellationRequested();
 01153            string _responseContent = null;
 01154            if ((int)_statusCode != 200)
 1155            {
 01156                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1157                try
 1158                {
 01159                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01160                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01161                    if (_errorBody != null)
 1162                    {
 01163                        ex.Body = _errorBody;
 1164                    }
 01165                }
 01166                catch (JsonException)
 1167                {
 1168                    // Ignore the exception
 01169                }
 01170                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01171                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01172                if (_shouldTrace)
 1173                {
 01174                    ServiceClientTracing.Error(_invocationId, ex);
 1175                }
 01176                _httpRequest.Dispose();
 01177                if (_httpResponse != null)
 1178                {
 01179                    _httpResponse.Dispose();
 1180                }
 01181                throw ex;
 1182            }
 1183            // Create Result
 01184            var _result = new HttpOperationResponse<IList<DetectedFace>>();
 01185            _result.Request = _httpRequest;
 01186            _result.Response = _httpResponse;
 1187            // Deserialize Response
 01188            if ((int)_statusCode == 200)
 1189            {
 01190                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1191                try
 1192                {
 01193                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<DetectedFace>>(_responseCo
 01194                }
 01195                catch (JsonException ex)
 1196                {
 01197                    _httpRequest.Dispose();
 01198                    if (_httpResponse != null)
 1199                    {
 01200                        _httpResponse.Dispose();
 1201                    }
 01202                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1203                }
 1204            }
 01205            if (_shouldTrace)
 1206            {
 01207                ServiceClientTracing.Exit(_invocationId, _result);
 1208            }
 01209            return _result;
 01210        }
 1211
 1212        /// <summary>
 1213        /// Verify whether two faces belong to a same person. Compares a face Id with a
 1214        /// Person Id
 1215        /// </summary>
 1216        /// <param name='faceId'>
 1217        /// FaceId of the face, comes from Face - Detect
 1218        /// </param>
 1219        /// <param name='personId'>
 1220        /// Specify a certain person in a person group or a large person group.
 1221        /// personId is created in PersonGroup Person - Create or LargePersonGroup
 1222        /// Person - Create.
 1223        /// </param>
 1224        /// <param name='personGroupId'>
 1225        /// Using existing personGroupId and personId for fast loading a specified
 1226        /// person. personGroupId is created in PersonGroup - Create. Parameter
 1227        /// personGroupId and largePersonGroupId should not be provided at the same
 1228        /// time.
 1229        /// </param>
 1230        /// <param name='largePersonGroupId'>
 1231        /// Using existing largePersonGroupId and personId for fast loading a specified
 1232        /// person. largePersonGroupId is created in LargePersonGroup - Create.
 1233        /// Parameter personGroupId and largePersonGroupId should not be provided at
 1234        /// the same time.
 1235        /// </param>
 1236        /// <param name='customHeaders'>
 1237        /// Headers that will be added to request.
 1238        /// </param>
 1239        /// <param name='cancellationToken'>
 1240        /// The cancellation token.
 1241        /// </param>
 1242        /// <exception cref="APIErrorException">
 1243        /// Thrown when the operation returned an invalid status code
 1244        /// </exception>
 1245        /// <exception cref="SerializationException">
 1246        /// Thrown when unable to deserialize the response
 1247        /// </exception>
 1248        /// <exception cref="ValidationException">
 1249        /// Thrown when a required parameter is null
 1250        /// </exception>
 1251        /// <exception cref="System.ArgumentNullException">
 1252        /// Thrown when a required parameter is null
 1253        /// </exception>
 1254        /// <return>
 1255        /// A response object containing the response body and response headers.
 1256        /// </return>
 1257        public async Task<HttpOperationResponse<VerifyResult>> VerifyFaceToPersonWithHttpMessagesAsync(System.Guid faceI
 1258        {
 81259            if (Client.Endpoint == null)
 1260            {
 01261                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1262            }
 81263            if (personGroupId != null)
 1264            {
 41265                if (personGroupId.Length > 64)
 1266                {
 01267                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 1268                }
 41269                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 1270                {
 01271                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$");
 1272                }
 1273            }
 81274            if (largePersonGroupId != null)
 1275            {
 41276                if (largePersonGroupId.Length > 64)
 1277                {
 01278                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 1279                }
 41280                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 1281                {
 01282                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 1283                }
 1284            }
 81285            VerifyFaceToPersonRequest body = new VerifyFaceToPersonRequest();
 81286            if (personGroupId != null || largePersonGroupId != null)
 1287            {
 81288                body.FaceId = faceId;
 81289                body.PersonGroupId = personGroupId;
 81290                body.LargePersonGroupId = largePersonGroupId;
 81291                body.PersonId = personId;
 1292            }
 1293            // Tracing
 81294            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 81295            string _invocationId = null;
 81296            if (_shouldTrace)
 1297            {
 01298                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01299                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01300                tracingParameters.Add("body", body);
 01301                tracingParameters.Add("cancellationToken", cancellationToken);
 01302                ServiceClientTracing.Enter(_invocationId, this, "VerifyFaceToPerson", tracingParameters);
 1303            }
 1304            // Construct URL
 81305            var _baseUrl = Client.BaseUri;
 81306            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "verify";
 81307            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 1308            // Create HTTP transport objects
 81309            var _httpRequest = new HttpRequestMessage();
 81310            HttpResponseMessage _httpResponse = null;
 81311            _httpRequest.Method = new HttpMethod("POST");
 81312            _httpRequest.RequestUri = new System.Uri(_url);
 1313            // Set Headers
 1314
 1315
 81316            if (customHeaders != null)
 1317            {
 01318                foreach(var _header in customHeaders)
 1319                {
 01320                    if (_httpRequest.Headers.Contains(_header.Key))
 1321                    {
 01322                        _httpRequest.Headers.Remove(_header.Key);
 1323                    }
 01324                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1325                }
 1326            }
 1327
 1328            // Serialize Request
 81329            string _requestContent = null;
 81330            if(body != null)
 1331            {
 81332                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 81333                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 81334                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1335            }
 1336            // Set Credentials
 81337            if (Client.Credentials != null)
 1338            {
 81339                cancellationToken.ThrowIfCancellationRequested();
 81340                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1341            }
 1342            // Send Request
 81343            if (_shouldTrace)
 1344            {
 01345                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1346            }
 81347            cancellationToken.ThrowIfCancellationRequested();
 81348            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 81349            if (_shouldTrace)
 1350            {
 01351                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1352            }
 81353            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 81354            cancellationToken.ThrowIfCancellationRequested();
 81355            string _responseContent = null;
 81356            if ((int)_statusCode != 200)
 1357            {
 01358                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1359                try
 1360                {
 01361                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01362                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01363                    if (_errorBody != null)
 1364                    {
 01365                        ex.Body = _errorBody;
 1366                    }
 01367                }
 01368                catch (JsonException)
 1369                {
 1370                    // Ignore the exception
 01371                }
 01372                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01373                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01374                if (_shouldTrace)
 1375                {
 01376                    ServiceClientTracing.Error(_invocationId, ex);
 1377                }
 01378                _httpRequest.Dispose();
 01379                if (_httpResponse != null)
 1380                {
 01381                    _httpResponse.Dispose();
 1382                }
 01383                throw ex;
 1384            }
 1385            // Create Result
 81386            var _result = new HttpOperationResponse<VerifyResult>();
 81387            _result.Request = _httpRequest;
 81388            _result.Response = _httpResponse;
 1389            // Deserialize Response
 81390            if ((int)_statusCode == 200)
 1391            {
 81392                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1393                try
 1394                {
 81395                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<VerifyResult>(_responseContent, 
 81396                }
 01397                catch (JsonException ex)
 1398                {
 01399                    _httpRequest.Dispose();
 01400                    if (_httpResponse != null)
 1401                    {
 01402                        _httpResponse.Dispose();
 1403                    }
 01404                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1405                }
 1406            }
 81407            if (_shouldTrace)
 1408            {
 01409                ServiceClientTracing.Exit(_invocationId, _result);
 1410            }
 81411            return _result;
 81412        }
 1413
 1414        /// <summary>
 1415        /// Detect human faces in an image, return face rectangles, and optionally with
 1416        /// faceIds, landmarks, and attributes.&lt;br /&gt;
 1417        /// * No image will be stored. Only the extracted face feature will be stored
 1418        /// on server. The faceId is an identifier of the face feature and will be used
 1419        /// in [Face -
 1420        /// Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239),
 1421        /// [Face -
 1422        /// Verify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a),
 1423        /// and [Face - Find
 1424        /// Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237).
 1425        /// The stored face feature(s) will expire and be deleted 24 hours after the
 1426        /// original detection call.
 1427        /// * Optional parameters include faceId, landmarks, and attributes. Attributes
 1428        /// include age, gender, headPose, smile, facialHair, glasses, emotion, hair,
 1429        /// makeup, occlusion, accessories, blur, exposure and noise. Some of the
 1430        /// results returned for specific attributes may not be highly accurate.
 1431        /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The
 1432        /// allowed image file size is from 1KB to 6MB.
 1433        /// * Up to 100 faces can be returned for an image. Faces are ranked by face
 1434        /// rectangle size from large to small.
 1435        /// * For optimal results when querying [Face -
 1436        /// Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239),
 1437        /// [Face -
 1438        /// Verify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a),
 1439        /// and [Face - Find
 1440        /// Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237)
 1441        /// ('returnFaceId' is true), please use faces that are: frontal, clear, and
 1442        /// with a minimum size of 200x200 pixels (100 pixels between eyes).
 1443        /// * The minimum detectable face size is 36x36 pixels in an image no larger
 1444        /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels
 1445        /// will need a proportionally larger minimum face size.
 1446        /// * Different 'detectionModel' values can be provided. To use and compare
 1447        /// different detection models, please refer to [How to specify a detection
 1448        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti
 1449        /// | Model | Recommended use-case(s) |
 1450        /// | ---------- | -------- |
 1451        /// | 'detection_01': | The default detection model for [Face -
 1452        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 1453        /// Recommend for near frontal face detection. For scenarios with exceptionally
 1454        /// large angle (head-pose) faces, occluded faces or wrong image orientation,
 1455        /// the faces in such cases may not be detected. |
 1456        /// | 'detection_02': | Detection model released in 2019 May with improved
 1457        /// accuracy especially on small, side and blurry faces. |
 1458        ///
 1459        /// * Different 'recognitionModel' values are provided. If follow-up operations
 1460        /// like Verify, Identify, Find Similar are needed, please specify the
 1461        /// recognition model with 'recognitionModel' parameter. The default value for
 1462        /// 'recognitionModel' is 'recognition_01', if latest model needed, please
 1463        /// explicitly specify the model you need in this parameter. Once specified,
 1464        /// the detected faceIds will be associated with the specified recognition
 1465        /// model. More details, please refer to [How to specify a recognition
 1466        /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-recogni
 1467        /// | Model | Recommended use-case(s) |
 1468        /// | ---------- | -------- |
 1469        /// | 'recognition_01': | The default recognition model for [Face -
 1470        /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
 1471        /// All those faceIds created before 2019 March are bonded with this
 1472        /// recognition model. |
 1473        /// | 'recognition_02': | Recognition model released in 2019 March.
 1474        /// 'recognition_02' is recommended since its overall accuracy is improved
 1475        /// compared with 'recognition_01'. |
 1476        /// </summary>
 1477        /// <param name='image'>
 1478        /// An image stream.
 1479        /// </param>
 1480        /// <param name='returnFaceId'>
 1481        /// A value indicating whether the operation should return faceIds of detected
 1482        /// faces.
 1483        /// </param>
 1484        /// <param name='returnFaceLandmarks'>
 1485        /// A value indicating whether the operation should return landmarks of the
 1486        /// detected faces.
 1487        /// </param>
 1488        /// <param name='returnFaceAttributes'>
 1489        /// Analyze and return the one or more specified face attributes in the
 1490        /// comma-separated string like "returnFaceAttributes=age,gender". Supported
 1491        /// face attributes include age, gender, headPose, smile, facialHair, glasses
 1492        /// and emotion. Note that each face attribute analysis has additional
 1493        /// computational and time cost.
 1494        /// </param>
 1495        /// <param name='recognitionModel'>
 1496        /// Name of recognition model. Recognition model is used when the face features
 1497        /// are extracted and associated with detected faceIds, (Large)FaceList or
 1498        /// (Large)PersonGroup. A recognition model name can be provided when
 1499        /// performing Face - Detect or (Large)FaceList - Create or (Large)PersonGroup
 1500        /// - Create. The default value is 'recognition_01', if latest model needed,
 1501        /// please explicitly specify the model you need. Possible values include:
 1502        /// 'recognition_01', 'recognition_02'
 1503        /// </param>
 1504        /// <param name='returnRecognitionModel'>
 1505        /// A value indicating whether the operation should return 'recognitionModel'
 1506        /// in response.
 1507        /// </param>
 1508        /// <param name='detectionModel'>
 1509        /// Name of detection model. Detection model is used to detect faces in the
 1510        /// submitted image. A detection model name can be provided when performing
 1511        /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add
 1512        /// Face. The default value is 'detection_01', if another model is needed,
 1513        /// please explicitly specify it. Possible values include: 'detection_01',
 1514        /// 'detection_02'
 1515        /// </param>
 1516        /// <param name='customHeaders'>
 1517        /// Headers that will be added to request.
 1518        /// </param>
 1519        /// <param name='cancellationToken'>
 1520        /// The cancellation token.
 1521        /// </param>
 1522        /// <exception cref="APIErrorException">
 1523        /// Thrown when the operation returned an invalid status code
 1524        /// </exception>
 1525        /// <exception cref="SerializationException">
 1526        /// Thrown when unable to deserialize the response
 1527        /// </exception>
 1528        /// <exception cref="ValidationException">
 1529        /// Thrown when a required parameter is null
 1530        /// </exception>
 1531        /// <exception cref="System.ArgumentNullException">
 1532        /// Thrown when a required parameter is null
 1533        /// </exception>
 1534        /// <return>
 1535        /// A response object containing the response body and response headers.
 1536        /// </return>
 1537        public async Task<HttpOperationResponse<IList<DetectedFace>>> DetectWithStreamWithHttpMessagesAsync(Stream image
 1538        {
 901539            if (Client.Endpoint == null)
 1540            {
 01541                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1542            }
 901543            if (image == null)
 1544            {
 01545                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 1546            }
 1547            // Tracing
 901548            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 901549            string _invocationId = null;
 901550            if (_shouldTrace)
 1551            {
 01552                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01553                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01554                tracingParameters.Add("returnFaceId", returnFaceId);
 01555                tracingParameters.Add("returnFaceLandmarks", returnFaceLandmarks);
 01556                tracingParameters.Add("returnFaceAttributes", returnFaceAttributes);
 01557                tracingParameters.Add("image", image);
 01558                tracingParameters.Add("recognitionModel", recognitionModel);
 01559                tracingParameters.Add("returnRecognitionModel", returnRecognitionModel);
 01560                tracingParameters.Add("detectionModel", detectionModel);
 01561                tracingParameters.Add("cancellationToken", cancellationToken);
 01562                ServiceClientTracing.Enter(_invocationId, this, "DetectWithStream", tracingParameters);
 1563            }
 1564            // Construct URL
 901565            var _baseUrl = Client.BaseUri;
 901566            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "detect";
 901567            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 901568            List<string> _queryParameters = new List<string>();
 901569            if (returnFaceId != null)
 1570            {
 901571                _queryParameters.Add(string.Format("returnFaceId={0}", System.Uri.EscapeDataString(Rest.Serialization.Sa
 1572            }
 901573            if (returnFaceLandmarks != null)
 1574            {
 901575                _queryParameters.Add(string.Format("returnFaceLandmarks={0}", System.Uri.EscapeDataString(Rest.Serializa
 1576            }
 901577            if (returnFaceAttributes != null)
 1578            {
 21579                _queryParameters.Add(string.Format("returnFaceAttributes={0}", System.Uri.EscapeDataString(string.Join("
 1580            }
 901581            if (recognitionModel != null)
 1582            {
 901583                _queryParameters.Add(string.Format("recognitionModel={0}", System.Uri.EscapeDataString(recognitionModel)
 1584            }
 901585            if (returnRecognitionModel != null)
 1586            {
 901587                _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial
 1588            }
 901589            if (detectionModel != null)
 1590            {
 901591                _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel)));
 1592            }
 901593            if (_queryParameters.Count > 0)
 1594            {
 901595                _url += "?" + string.Join("&", _queryParameters);
 1596            }
 1597            // Create HTTP transport objects
 901598            var _httpRequest = new HttpRequestMessage();
 901599            HttpResponseMessage _httpResponse = null;
 901600            _httpRequest.Method = new HttpMethod("POST");
 901601            _httpRequest.RequestUri = new System.Uri(_url);
 1602            // Set Headers
 1603
 1604
 901605            if (customHeaders != null)
 1606            {
 01607                foreach(var _header in customHeaders)
 1608                {
 01609                    if (_httpRequest.Headers.Contains(_header.Key))
 1610                    {
 01611                        _httpRequest.Headers.Remove(_header.Key);
 1612                    }
 01613                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1614                }
 1615            }
 1616
 1617            // Serialize Request
 901618            string _requestContent = null;
 901619            if(image == null)
 1620            {
 01621              throw new System.ArgumentNullException("image");
 1622            }
 901623            if (image != null && image != Stream.Null)
 1624            {
 901625                _httpRequest.Content = new StreamContent(image);
 901626                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1627            }
 1628            // Set Credentials
 901629            if (Client.Credentials != null)
 1630            {
 901631                cancellationToken.ThrowIfCancellationRequested();
 901632                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1633            }
 1634            // Send Request
 901635            if (_shouldTrace)
 1636            {
 01637                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1638            }
 901639            cancellationToken.ThrowIfCancellationRequested();
 901640            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 901641            if (_shouldTrace)
 1642            {
 01643                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1644            }
 901645            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 901646            cancellationToken.ThrowIfCancellationRequested();
 901647            string _responseContent = null;
 901648            if ((int)_statusCode != 200)
 1649            {
 01650                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1651                try
 1652                {
 01653                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01654                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01655                    if (_errorBody != null)
 1656                    {
 01657                        ex.Body = _errorBody;
 1658                    }
 01659                }
 01660                catch (JsonException)
 1661                {
 1662                    // Ignore the exception
 01663                }
 01664                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01665                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01666                if (_shouldTrace)
 1667                {
 01668                    ServiceClientTracing.Error(_invocationId, ex);
 1669                }
 01670                _httpRequest.Dispose();
 01671                if (_httpResponse != null)
 1672                {
 01673                    _httpResponse.Dispose();
 1674                }
 01675                throw ex;
 1676            }
 1677            // Create Result
 901678            var _result = new HttpOperationResponse<IList<DetectedFace>>();
 901679            _result.Request = _httpRequest;
 901680            _result.Response = _httpResponse;
 1681            // Deserialize Response
 901682            if ((int)_statusCode == 200)
 1683            {
 901684                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1685                try
 1686                {
 901687                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<DetectedFace>>(_responseCo
 901688                }
 01689                catch (JsonException ex)
 1690                {
 01691                    _httpRequest.Dispose();
 01692                    if (_httpResponse != null)
 1693                    {
 01694                        _httpResponse.Dispose();
 1695                    }
 01696                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1697                }
 1698            }
 901699            if (_shouldTrace)
 1700            {
 01701                ServiceClientTracing.Exit(_invocationId, _result);
 1702            }
 901703            return _result;
 901704        }
 1705
 1706    }
 1707}