< Summary

Class:Microsoft.Azure.CognitiveServices.Vision.Face.PersonGroupOperations
Assembly:Microsoft.Azure.CognitiveServices.Vision.Face
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\PersonGroupOperations.cs
Covered lines:206
Uncovered lines:343
Coverable lines:549
Total lines:1285
Line coverage:37.5% (206 of 549)
Covered branches:96
Total branches:308
Branch coverage:31.1% (96 of 308)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
CreateWithHttpMessagesAsync()-57.83%51.92%
DeleteWithHttpMessagesAsync()-52.24%41.67%
GetWithHttpMessagesAsync()-53.66%47.73%
UpdateWithHttpMessagesAsync()-0%0%
GetTrainingStatusWithHttpMessagesAsync()-51.32%42.5%
ListWithHttpMessagesAsync()-0%0%
TrainWithHttpMessagesAsync()-52.24%41.67%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\PersonGroupOperations.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    /// PersonGroupOperations operations.
 27    /// </summary>
 28    public partial class PersonGroupOperations : IServiceOperations<FaceClient>, IPersonGroupOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the PersonGroupOperations 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 PersonGroupOperations(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>
 23251        public FaceClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Create a new person group with specified personGroupId, name, user-provided
 55        /// userData and recognitionModel.
 56        /// &lt;br /&gt; A person group is the container of the uploaded person data,
 57        /// including face recognition features.
 58        /// &lt;br /&gt; After creation, use [PersonGroup Person -
 59        /// Create](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523c)
 60        /// to add persons into the group, and then call [PersonGroup -
 61        /// Train](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395249)
 62        /// to get this group ready for [Face -
 63        /// Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239).
 64        /// &lt;br /&gt; No image will be stored. Only the person's extracted face
 65        /// features and userData will be stored on server until [PersonGroup Person -
 66        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
 67        /// or [PersonGroup -
 68        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
 69        /// is called.
 70        /// &lt;br/&gt;'recognitionModel' should be specified to associate with this
 71        /// person group. The default value for 'recognitionModel' is 'recognition_01',
 72        /// if the latest model needed, please explicitly specify the model you need in
 73        /// this parameter. New faces that are added to an existing person group will
 74        /// use the recognition model that's already associated with the collection.
 75        /// Existing face features in a person group can't be updated to features
 76        /// extracted by another version of recognition model.
 77        /// * 'recognition_01': The default recognition model for [PersonGroup -
 78        /// Create](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395244).
 79        /// All those person groups created before 2019 March are bonded with this
 80        /// recognition model.
 81        /// * 'recognition_02': Recognition model released in 2019 March.
 82        /// 'recognition_02' is recommended since its overall accuracy is improved
 83        /// compared with 'recognition_01'.
 84        ///
 85        /// Person group quota:
 86        /// * Free-tier subscription quota: 1,000 person groups. Each holds up to 1,000
 87        /// persons.
 88        /// * S0-tier subscription quota: 1,000,000 person groups. Each holds up to
 89        /// 10,000 persons.
 90        /// * to handle larger scale face identification problem, please consider using
 91        /// [LargePersonGroup](/docs/services/563879b61984550e40cbbe8d/operations/599acdee6ac60f11b48b5a9d).
 92        /// </summary>
 93        /// <param name='personGroupId'>
 94        /// Id referencing a particular person group.
 95        /// </param>
 96        /// <param name='name'>
 97        /// User defined name, maximum length is 128.
 98        /// </param>
 99        /// <param name='userData'>
 100        /// User specified data. Length should not exceed 16KB.
 101        /// </param>
 102        /// <param name='recognitionModel'>
 103        /// Possible values include: 'recognition_01', 'recognition_02'
 104        /// </param>
 105        /// <param name='customHeaders'>
 106        /// Headers that will be added to request.
 107        /// </param>
 108        /// <param name='cancellationToken'>
 109        /// The cancellation token.
 110        /// </param>
 111        /// <exception cref="APIErrorException">
 112        /// Thrown when the operation returned an invalid status code
 113        /// </exception>
 114        /// <exception cref="ValidationException">
 115        /// Thrown when a required parameter is null
 116        /// </exception>
 117        /// <exception cref="System.ArgumentNullException">
 118        /// Thrown when a required parameter is null
 119        /// </exception>
 120        /// <return>
 121        /// A response object containing the response body and response headers.
 122        /// </return>
 123        public async Task<HttpOperationResponse> CreateWithHttpMessagesAsync(string personGroupId, string name = default
 124        {
 8125            if (Client.Endpoint == null)
 126            {
 0127                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 128            }
 8129            if (personGroupId == null)
 130            {
 0131                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 132            }
 8133            if (personGroupId != null)
 134            {
 8135                if (personGroupId.Length > 64)
 136                {
 0137                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 138                }
 8139                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 140                {
 0141                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$");
 142                }
 143            }
 8144            if (name != null)
 145            {
 8146                if (name.Length > 128)
 147                {
 0148                    throw new ValidationException(ValidationRules.MaxLength, "name", 128);
 149                }
 150            }
 8151            if (userData != null)
 152            {
 2153                if (userData.Length > 16384)
 154                {
 0155                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 156                }
 157            }
 8158            MetaDataContract body = new MetaDataContract();
 8159            if (name != null || userData != null || recognitionModel != null)
 160            {
 8161                body.Name = name;
 8162                body.UserData = userData;
 8163                body.RecognitionModel = recognitionModel;
 164            }
 165            // Tracing
 8166            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 8167            string _invocationId = null;
 8168            if (_shouldTrace)
 169            {
 0170                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0171                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0172                tracingParameters.Add("personGroupId", personGroupId);
 0173                tracingParameters.Add("body", body);
 0174                tracingParameters.Add("cancellationToken", cancellationToken);
 0175                ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters);
 176            }
 177            // Construct URL
 8178            var _baseUrl = Client.BaseUri;
 8179            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}";
 8180            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 8181            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 182            // Create HTTP transport objects
 8183            var _httpRequest = new HttpRequestMessage();
 8184            HttpResponseMessage _httpResponse = null;
 8185            _httpRequest.Method = new HttpMethod("PUT");
 8186            _httpRequest.RequestUri = new System.Uri(_url);
 187            // Set Headers
 188
 189
 8190            if (customHeaders != null)
 191            {
 0192                foreach(var _header in customHeaders)
 193                {
 0194                    if (_httpRequest.Headers.Contains(_header.Key))
 195                    {
 0196                        _httpRequest.Headers.Remove(_header.Key);
 197                    }
 0198                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 199                }
 200            }
 201
 202            // Serialize Request
 8203            string _requestContent = null;
 8204            if(body != null)
 205            {
 8206                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 8207                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 8208                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 209            }
 210            // Set Credentials
 8211            if (Client.Credentials != null)
 212            {
 8213                cancellationToken.ThrowIfCancellationRequested();
 8214                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 215            }
 216            // Send Request
 8217            if (_shouldTrace)
 218            {
 0219                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 220            }
 8221            cancellationToken.ThrowIfCancellationRequested();
 8222            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 8223            if (_shouldTrace)
 224            {
 0225                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 226            }
 8227            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 8228            cancellationToken.ThrowIfCancellationRequested();
 8229            string _responseContent = null;
 8230            if ((int)_statusCode != 200)
 231            {
 0232                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 233                try
 234                {
 0235                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0236                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0237                    if (_errorBody != null)
 238                    {
 0239                        ex.Body = _errorBody;
 240                    }
 0241                }
 0242                catch (JsonException)
 243                {
 244                    // Ignore the exception
 0245                }
 0246                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0247                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0248                if (_shouldTrace)
 249                {
 0250                    ServiceClientTracing.Error(_invocationId, ex);
 251                }
 0252                _httpRequest.Dispose();
 0253                if (_httpResponse != null)
 254                {
 0255                    _httpResponse.Dispose();
 256                }
 0257                throw ex;
 258            }
 259            // Create Result
 8260            var _result = new HttpOperationResponse();
 8261            _result.Request = _httpRequest;
 8262            _result.Response = _httpResponse;
 8263            if (_shouldTrace)
 264            {
 0265                ServiceClientTracing.Exit(_invocationId, _result);
 266            }
 8267            return _result;
 8268        }
 269
 270        /// <summary>
 271        /// Delete an existing person group. Persisted face features of all people in
 272        /// the person group will also be deleted.
 273        /// </summary>
 274        /// <param name='personGroupId'>
 275        /// Id referencing a particular person group.
 276        /// </param>
 277        /// <param name='customHeaders'>
 278        /// Headers that will be added to request.
 279        /// </param>
 280        /// <param name='cancellationToken'>
 281        /// The cancellation token.
 282        /// </param>
 283        /// <exception cref="APIErrorException">
 284        /// Thrown when the operation returned an invalid status code
 285        /// </exception>
 286        /// <exception cref="ValidationException">
 287        /// Thrown when a required parameter is null
 288        /// </exception>
 289        /// <exception cref="System.ArgumentNullException">
 290        /// Thrown when a required parameter is null
 291        /// </exception>
 292        /// <return>
 293        /// A response object containing the response body and response headers.
 294        /// </return>
 295        public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(string personGroupId, Dictionary<string, Li
 296        {
 10297            if (Client.Endpoint == null)
 298            {
 0299                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 300            }
 10301            if (personGroupId == null)
 302            {
 0303                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 304            }
 10305            if (personGroupId != null)
 306            {
 10307                if (personGroupId.Length > 64)
 308                {
 0309                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 310                }
 10311                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 312                {
 0313                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$");
 314                }
 315            }
 316            // Tracing
 10317            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 10318            string _invocationId = null;
 10319            if (_shouldTrace)
 320            {
 0321                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0322                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0323                tracingParameters.Add("personGroupId", personGroupId);
 0324                tracingParameters.Add("cancellationToken", cancellationToken);
 0325                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 326            }
 327            // Construct URL
 10328            var _baseUrl = Client.BaseUri;
 10329            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}";
 10330            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 10331            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 332            // Create HTTP transport objects
 10333            var _httpRequest = new HttpRequestMessage();
 10334            HttpResponseMessage _httpResponse = null;
 10335            _httpRequest.Method = new HttpMethod("DELETE");
 10336            _httpRequest.RequestUri = new System.Uri(_url);
 337            // Set Headers
 338
 339
 10340            if (customHeaders != null)
 341            {
 0342                foreach(var _header in customHeaders)
 343                {
 0344                    if (_httpRequest.Headers.Contains(_header.Key))
 345                    {
 0346                        _httpRequest.Headers.Remove(_header.Key);
 347                    }
 0348                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 349                }
 350            }
 351
 352            // Serialize Request
 10353            string _requestContent = null;
 354            // Set Credentials
 10355            if (Client.Credentials != null)
 356            {
 10357                cancellationToken.ThrowIfCancellationRequested();
 10358                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 359            }
 360            // Send Request
 10361            if (_shouldTrace)
 362            {
 0363                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 364            }
 10365            cancellationToken.ThrowIfCancellationRequested();
 10366            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 10367            if (_shouldTrace)
 368            {
 0369                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 370            }
 10371            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 10372            cancellationToken.ThrowIfCancellationRequested();
 10373            string _responseContent = null;
 10374            if ((int)_statusCode != 200)
 375            {
 0376                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 377                try
 378                {
 0379                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0380                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0381                    if (_errorBody != null)
 382                    {
 0383                        ex.Body = _errorBody;
 384                    }
 0385                }
 0386                catch (JsonException)
 387                {
 388                    // Ignore the exception
 0389                }
 0390                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0391                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0392                if (_shouldTrace)
 393                {
 0394                    ServiceClientTracing.Error(_invocationId, ex);
 395                }
 0396                _httpRequest.Dispose();
 0397                if (_httpResponse != null)
 398                {
 0399                    _httpResponse.Dispose();
 400                }
 0401                throw ex;
 402            }
 403            // Create Result
 10404            var _result = new HttpOperationResponse();
 10405            _result.Request = _httpRequest;
 10406            _result.Response = _httpResponse;
 10407            if (_shouldTrace)
 408            {
 0409                ServiceClientTracing.Exit(_invocationId, _result);
 410            }
 10411            return _result;
 10412        }
 413
 414        /// <summary>
 415        /// Retrieve person group name, userData and recognitionModel. To get person
 416        /// information under this personGroup, use [PersonGroup Person -
 417        /// List](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395241).
 418        /// </summary>
 419        /// <param name='personGroupId'>
 420        /// Id referencing a particular person group.
 421        /// </param>
 422        /// <param name='returnRecognitionModel'>
 423        /// A value indicating whether the operation should return 'recognitionModel'
 424        /// in response.
 425        /// </param>
 426        /// <param name='customHeaders'>
 427        /// Headers that will be added to request.
 428        /// </param>
 429        /// <param name='cancellationToken'>
 430        /// The cancellation token.
 431        /// </param>
 432        /// <exception cref="APIErrorException">
 433        /// Thrown when the operation returned an invalid status code
 434        /// </exception>
 435        /// <exception cref="SerializationException">
 436        /// Thrown when unable to deserialize the response
 437        /// </exception>
 438        /// <exception cref="ValidationException">
 439        /// Thrown when a required parameter is null
 440        /// </exception>
 441        /// <exception cref="System.ArgumentNullException">
 442        /// Thrown when a required parameter is null
 443        /// </exception>
 444        /// <return>
 445        /// A response object containing the response body and response headers.
 446        /// </return>
 447        public async Task<HttpOperationResponse<PersonGroup>> GetWithHttpMessagesAsync(string personGroupId, bool? retur
 448        {
 2449            if (Client.Endpoint == null)
 450            {
 0451                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 452            }
 2453            if (personGroupId == null)
 454            {
 0455                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 456            }
 2457            if (personGroupId != null)
 458            {
 2459                if (personGroupId.Length > 64)
 460                {
 0461                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 462                }
 2463                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 464                {
 0465                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$");
 466                }
 467            }
 468            // Tracing
 2469            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2470            string _invocationId = null;
 2471            if (_shouldTrace)
 472            {
 0473                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0474                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0475                tracingParameters.Add("personGroupId", personGroupId);
 0476                tracingParameters.Add("returnRecognitionModel", returnRecognitionModel);
 0477                tracingParameters.Add("cancellationToken", cancellationToken);
 0478                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 479            }
 480            // Construct URL
 2481            var _baseUrl = Client.BaseUri;
 2482            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}";
 2483            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 2484            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 2485            List<string> _queryParameters = new List<string>();
 2486            if (returnRecognitionModel != null)
 487            {
 2488                _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial
 489            }
 2490            if (_queryParameters.Count > 0)
 491            {
 2492                _url += "?" + string.Join("&", _queryParameters);
 493            }
 494            // Create HTTP transport objects
 2495            var _httpRequest = new HttpRequestMessage();
 2496            HttpResponseMessage _httpResponse = null;
 2497            _httpRequest.Method = new HttpMethod("GET");
 2498            _httpRequest.RequestUri = new System.Uri(_url);
 499            // Set Headers
 500
 501
 2502            if (customHeaders != null)
 503            {
 0504                foreach(var _header in customHeaders)
 505                {
 0506                    if (_httpRequest.Headers.Contains(_header.Key))
 507                    {
 0508                        _httpRequest.Headers.Remove(_header.Key);
 509                    }
 0510                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 511                }
 512            }
 513
 514            // Serialize Request
 2515            string _requestContent = null;
 516            // Set Credentials
 2517            if (Client.Credentials != null)
 518            {
 2519                cancellationToken.ThrowIfCancellationRequested();
 2520                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 521            }
 522            // Send Request
 2523            if (_shouldTrace)
 524            {
 0525                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 526            }
 2527            cancellationToken.ThrowIfCancellationRequested();
 2528            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2529            if (_shouldTrace)
 530            {
 0531                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 532            }
 2533            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2534            cancellationToken.ThrowIfCancellationRequested();
 2535            string _responseContent = null;
 2536            if ((int)_statusCode != 200)
 537            {
 0538                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 539                try
 540                {
 0541                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0542                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0543                    if (_errorBody != null)
 544                    {
 0545                        ex.Body = _errorBody;
 546                    }
 0547                }
 0548                catch (JsonException)
 549                {
 550                    // Ignore the exception
 0551                }
 0552                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0553                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0554                if (_shouldTrace)
 555                {
 0556                    ServiceClientTracing.Error(_invocationId, ex);
 557                }
 0558                _httpRequest.Dispose();
 0559                if (_httpResponse != null)
 560                {
 0561                    _httpResponse.Dispose();
 562                }
 0563                throw ex;
 564            }
 565            // Create Result
 2566            var _result = new HttpOperationResponse<PersonGroup>();
 2567            _result.Request = _httpRequest;
 2568            _result.Response = _httpResponse;
 569            // Deserialize Response
 2570            if ((int)_statusCode == 200)
 571            {
 2572                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 573                try
 574                {
 2575                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersonGroup>(_responseContent, C
 2576                }
 0577                catch (JsonException ex)
 578                {
 0579                    _httpRequest.Dispose();
 0580                    if (_httpResponse != null)
 581                    {
 0582                        _httpResponse.Dispose();
 583                    }
 0584                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 585                }
 586            }
 2587            if (_shouldTrace)
 588            {
 0589                ServiceClientTracing.Exit(_invocationId, _result);
 590            }
 2591            return _result;
 2592        }
 593
 594        /// <summary>
 595        /// Update an existing person group's display name and userData. The properties
 596        /// which does not appear in request body will not be updated.
 597        /// </summary>
 598        /// <param name='personGroupId'>
 599        /// Id referencing a particular person group.
 600        /// </param>
 601        /// <param name='name'>
 602        /// User defined name, maximum length is 128.
 603        /// </param>
 604        /// <param name='userData'>
 605        /// User specified data. Length should not exceed 16KB.
 606        /// </param>
 607        /// <param name='customHeaders'>
 608        /// Headers that will be added to request.
 609        /// </param>
 610        /// <param name='cancellationToken'>
 611        /// The cancellation token.
 612        /// </param>
 613        /// <exception cref="APIErrorException">
 614        /// Thrown when the operation returned an invalid status code
 615        /// </exception>
 616        /// <exception cref="ValidationException">
 617        /// Thrown when a required parameter is null
 618        /// </exception>
 619        /// <exception cref="System.ArgumentNullException">
 620        /// Thrown when a required parameter is null
 621        /// </exception>
 622        /// <return>
 623        /// A response object containing the response body and response headers.
 624        /// </return>
 625        public async Task<HttpOperationResponse> UpdateWithHttpMessagesAsync(string personGroupId, string name = default
 626        {
 0627            if (Client.Endpoint == null)
 628            {
 0629                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 630            }
 0631            if (personGroupId == null)
 632            {
 0633                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 634            }
 0635            if (personGroupId != null)
 636            {
 0637                if (personGroupId.Length > 64)
 638                {
 0639                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 640                }
 0641                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 642                {
 0643                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$");
 644                }
 645            }
 0646            if (name != null)
 647            {
 0648                if (name.Length > 128)
 649                {
 0650                    throw new ValidationException(ValidationRules.MaxLength, "name", 128);
 651                }
 652            }
 0653            if (userData != null)
 654            {
 0655                if (userData.Length > 16384)
 656                {
 0657                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 658                }
 659            }
 0660            NameAndUserDataContract body = new NameAndUserDataContract();
 0661            if (name != null || userData != null)
 662            {
 0663                body.Name = name;
 0664                body.UserData = userData;
 665            }
 666            // Tracing
 0667            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0668            string _invocationId = null;
 0669            if (_shouldTrace)
 670            {
 0671                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0672                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0673                tracingParameters.Add("personGroupId", personGroupId);
 0674                tracingParameters.Add("body", body);
 0675                tracingParameters.Add("cancellationToken", cancellationToken);
 0676                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
 677            }
 678            // Construct URL
 0679            var _baseUrl = Client.BaseUri;
 0680            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}";
 0681            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0682            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 683            // Create HTTP transport objects
 0684            var _httpRequest = new HttpRequestMessage();
 0685            HttpResponseMessage _httpResponse = null;
 0686            _httpRequest.Method = new HttpMethod("PATCH");
 0687            _httpRequest.RequestUri = new System.Uri(_url);
 688            // Set Headers
 689
 690
 0691            if (customHeaders != null)
 692            {
 0693                foreach(var _header in customHeaders)
 694                {
 0695                    if (_httpRequest.Headers.Contains(_header.Key))
 696                    {
 0697                        _httpRequest.Headers.Remove(_header.Key);
 698                    }
 0699                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 700                }
 701            }
 702
 703            // Serialize Request
 0704            string _requestContent = null;
 0705            if(body != null)
 706            {
 0707                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 0708                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0709                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 710            }
 711            // Set Credentials
 0712            if (Client.Credentials != null)
 713            {
 0714                cancellationToken.ThrowIfCancellationRequested();
 0715                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 716            }
 717            // Send Request
 0718            if (_shouldTrace)
 719            {
 0720                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 721            }
 0722            cancellationToken.ThrowIfCancellationRequested();
 0723            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0724            if (_shouldTrace)
 725            {
 0726                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 727            }
 0728            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0729            cancellationToken.ThrowIfCancellationRequested();
 0730            string _responseContent = null;
 0731            if ((int)_statusCode != 200)
 732            {
 0733                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 734                try
 735                {
 0736                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0737                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0738                    if (_errorBody != null)
 739                    {
 0740                        ex.Body = _errorBody;
 741                    }
 0742                }
 0743                catch (JsonException)
 744                {
 745                    // Ignore the exception
 0746                }
 0747                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0748                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0749                if (_shouldTrace)
 750                {
 0751                    ServiceClientTracing.Error(_invocationId, ex);
 752                }
 0753                _httpRequest.Dispose();
 0754                if (_httpResponse != null)
 755                {
 0756                    _httpResponse.Dispose();
 757                }
 0758                throw ex;
 759            }
 760            // Create Result
 0761            var _result = new HttpOperationResponse();
 0762            _result.Request = _httpRequest;
 0763            _result.Response = _httpResponse;
 0764            if (_shouldTrace)
 765            {
 0766                ServiceClientTracing.Exit(_invocationId, _result);
 767            }
 0768            return _result;
 0769        }
 770
 771        /// <summary>
 772        /// Retrieve the training status of a person group (completed or ongoing).
 773        /// </summary>
 774        /// <param name='personGroupId'>
 775        /// Id referencing a particular person group.
 776        /// </param>
 777        /// <param name='customHeaders'>
 778        /// Headers that will be added to request.
 779        /// </param>
 780        /// <param name='cancellationToken'>
 781        /// The cancellation token.
 782        /// </param>
 783        /// <exception cref="APIErrorException">
 784        /// Thrown when the operation returned an invalid status code
 785        /// </exception>
 786        /// <exception cref="SerializationException">
 787        /// Thrown when unable to deserialize the response
 788        /// </exception>
 789        /// <exception cref="ValidationException">
 790        /// Thrown when a required parameter is null
 791        /// </exception>
 792        /// <exception cref="System.ArgumentNullException">
 793        /// Thrown when a required parameter is null
 794        /// </exception>
 795        /// <return>
 796        /// A response object containing the response body and response headers.
 797        /// </return>
 798        public async Task<HttpOperationResponse<TrainingStatus>> GetTrainingStatusWithHttpMessagesAsync(string personGro
 799        {
 6800            if (Client.Endpoint == null)
 801            {
 0802                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 803            }
 6804            if (personGroupId == null)
 805            {
 0806                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 807            }
 6808            if (personGroupId != null)
 809            {
 6810                if (personGroupId.Length > 64)
 811                {
 0812                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 813                }
 6814                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 815                {
 0816                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$");
 817                }
 818            }
 819            // Tracing
 6820            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 6821            string _invocationId = null;
 6822            if (_shouldTrace)
 823            {
 0824                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0825                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0826                tracingParameters.Add("personGroupId", personGroupId);
 0827                tracingParameters.Add("cancellationToken", cancellationToken);
 0828                ServiceClientTracing.Enter(_invocationId, this, "GetTrainingStatus", tracingParameters);
 829            }
 830            // Construct URL
 6831            var _baseUrl = Client.BaseUri;
 6832            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/training";
 6833            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 6834            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 835            // Create HTTP transport objects
 6836            var _httpRequest = new HttpRequestMessage();
 6837            HttpResponseMessage _httpResponse = null;
 6838            _httpRequest.Method = new HttpMethod("GET");
 6839            _httpRequest.RequestUri = new System.Uri(_url);
 840            // Set Headers
 841
 842
 6843            if (customHeaders != null)
 844            {
 0845                foreach(var _header in customHeaders)
 846                {
 0847                    if (_httpRequest.Headers.Contains(_header.Key))
 848                    {
 0849                        _httpRequest.Headers.Remove(_header.Key);
 850                    }
 0851                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 852                }
 853            }
 854
 855            // Serialize Request
 6856            string _requestContent = null;
 857            // Set Credentials
 6858            if (Client.Credentials != null)
 859            {
 6860                cancellationToken.ThrowIfCancellationRequested();
 6861                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 862            }
 863            // Send Request
 6864            if (_shouldTrace)
 865            {
 0866                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 867            }
 6868            cancellationToken.ThrowIfCancellationRequested();
 6869            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 6870            if (_shouldTrace)
 871            {
 0872                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 873            }
 6874            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 6875            cancellationToken.ThrowIfCancellationRequested();
 6876            string _responseContent = null;
 6877            if ((int)_statusCode != 200)
 878            {
 0879                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 880                try
 881                {
 0882                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0883                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0884                    if (_errorBody != null)
 885                    {
 0886                        ex.Body = _errorBody;
 887                    }
 0888                }
 0889                catch (JsonException)
 890                {
 891                    // Ignore the exception
 0892                }
 0893                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0894                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0895                if (_shouldTrace)
 896                {
 0897                    ServiceClientTracing.Error(_invocationId, ex);
 898                }
 0899                _httpRequest.Dispose();
 0900                if (_httpResponse != null)
 901                {
 0902                    _httpResponse.Dispose();
 903                }
 0904                throw ex;
 905            }
 906            // Create Result
 6907            var _result = new HttpOperationResponse<TrainingStatus>();
 6908            _result.Request = _httpRequest;
 6909            _result.Response = _httpResponse;
 910            // Deserialize Response
 6911            if ((int)_statusCode == 200)
 912            {
 6913                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 914                try
 915                {
 6916                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<TrainingStatus>(_responseContent
 6917                }
 0918                catch (JsonException ex)
 919                {
 0920                    _httpRequest.Dispose();
 0921                    if (_httpResponse != null)
 922                    {
 0923                        _httpResponse.Dispose();
 924                    }
 0925                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 926                }
 927            }
 6928            if (_shouldTrace)
 929            {
 0930                ServiceClientTracing.Exit(_invocationId, _result);
 931            }
 6932            return _result;
 6933        }
 934
 935        /// <summary>
 936        /// List person groups’ personGroupId, name, userData and
 937        /// recognitionModel.&lt;br /&gt;
 938        /// * Person groups are stored in alphabetical order of personGroupId.
 939        /// * "start" parameter (string, optional) is a user-provided personGroupId
 940        /// value that returned entries have larger ids by string comparison. "start"
 941        /// set to empty to indicate return from the first item.
 942        /// * "top" parameter (int, optional) specifies the number of entries to
 943        /// return. A maximal of 1000 entries can be returned in one call. To fetch
 944        /// more, you can specify "start" with the last returned entry’s Id of the
 945        /// current call.
 946        /// &lt;br /&gt;
 947        /// For example, total 5 person groups: "group1", ..., "group5".
 948        /// &lt;br /&gt; "start=&amp;top=" will return all 5 groups.
 949        /// &lt;br /&gt; "start=&amp;top=2" will return "group1", "group2".
 950        /// &lt;br /&gt; "start=group2&amp;top=3" will return "group3", "group4",
 951        /// "group5".
 952        ///
 953        /// </summary>
 954        /// <param name='start'>
 955        /// List person groups from the least personGroupId greater than the "start".
 956        /// </param>
 957        /// <param name='top'>
 958        /// The number of person groups to list.
 959        /// </param>
 960        /// <param name='returnRecognitionModel'>
 961        /// A value indicating whether the operation should return 'recognitionModel'
 962        /// in response.
 963        /// </param>
 964        /// <param name='customHeaders'>
 965        /// Headers that will be added to request.
 966        /// </param>
 967        /// <param name='cancellationToken'>
 968        /// The cancellation token.
 969        /// </param>
 970        /// <exception cref="APIErrorException">
 971        /// Thrown when the operation returned an invalid status code
 972        /// </exception>
 973        /// <exception cref="SerializationException">
 974        /// Thrown when unable to deserialize the response
 975        /// </exception>
 976        /// <exception cref="ValidationException">
 977        /// Thrown when a required parameter is null
 978        /// </exception>
 979        /// <exception cref="System.ArgumentNullException">
 980        /// Thrown when a required parameter is null
 981        /// </exception>
 982        /// <return>
 983        /// A response object containing the response body and response headers.
 984        /// </return>
 985        public async Task<HttpOperationResponse<IList<PersonGroup>>> ListWithHttpMessagesAsync(string start = default(st
 986        {
 0987            if (Client.Endpoint == null)
 988            {
 0989                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 990            }
 0991            if (start != null)
 992            {
 0993                if (start.Length > 64)
 994                {
 0995                    throw new ValidationException(ValidationRules.MaxLength, "start", 64);
 996                }
 997            }
 0998            if (top > 1000)
 999            {
 01000                throw new ValidationException(ValidationRules.InclusiveMaximum, "top", 1000);
 1001            }
 01002            if (top < 1)
 1003            {
 01004                throw new ValidationException(ValidationRules.InclusiveMinimum, "top", 1);
 1005            }
 1006            // Tracing
 01007            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01008            string _invocationId = null;
 01009            if (_shouldTrace)
 1010            {
 01011                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01012                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01013                tracingParameters.Add("start", start);
 01014                tracingParameters.Add("top", top);
 01015                tracingParameters.Add("returnRecognitionModel", returnRecognitionModel);
 01016                tracingParameters.Add("cancellationToken", cancellationToken);
 01017                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 1018            }
 1019            // Construct URL
 01020            var _baseUrl = Client.BaseUri;
 01021            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups";
 01022            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01023            List<string> _queryParameters = new List<string>();
 01024            if (start != null)
 1025            {
 01026                _queryParameters.Add(string.Format("start={0}", System.Uri.EscapeDataString(start)));
 1027            }
 01028            if (top != null)
 1029            {
 01030                _queryParameters.Add(string.Format("top={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon
 1031            }
 01032            if (returnRecognitionModel != null)
 1033            {
 01034                _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial
 1035            }
 01036            if (_queryParameters.Count > 0)
 1037            {
 01038                _url += "?" + string.Join("&", _queryParameters);
 1039            }
 1040            // Create HTTP transport objects
 01041            var _httpRequest = new HttpRequestMessage();
 01042            HttpResponseMessage _httpResponse = null;
 01043            _httpRequest.Method = new HttpMethod("GET");
 01044            _httpRequest.RequestUri = new System.Uri(_url);
 1045            // Set Headers
 1046
 1047
 01048            if (customHeaders != null)
 1049            {
 01050                foreach(var _header in customHeaders)
 1051                {
 01052                    if (_httpRequest.Headers.Contains(_header.Key))
 1053                    {
 01054                        _httpRequest.Headers.Remove(_header.Key);
 1055                    }
 01056                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1057                }
 1058            }
 1059
 1060            // Serialize Request
 01061            string _requestContent = null;
 1062            // Set Credentials
 01063            if (Client.Credentials != null)
 1064            {
 01065                cancellationToken.ThrowIfCancellationRequested();
 01066                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1067            }
 1068            // Send Request
 01069            if (_shouldTrace)
 1070            {
 01071                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1072            }
 01073            cancellationToken.ThrowIfCancellationRequested();
 01074            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01075            if (_shouldTrace)
 1076            {
 01077                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1078            }
 01079            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01080            cancellationToken.ThrowIfCancellationRequested();
 01081            string _responseContent = null;
 01082            if ((int)_statusCode != 200)
 1083            {
 01084                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1085                try
 1086                {
 01087                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01088                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01089                    if (_errorBody != null)
 1090                    {
 01091                        ex.Body = _errorBody;
 1092                    }
 01093                }
 01094                catch (JsonException)
 1095                {
 1096                    // Ignore the exception
 01097                }
 01098                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01099                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01100                if (_shouldTrace)
 1101                {
 01102                    ServiceClientTracing.Error(_invocationId, ex);
 1103                }
 01104                _httpRequest.Dispose();
 01105                if (_httpResponse != null)
 1106                {
 01107                    _httpResponse.Dispose();
 1108                }
 01109                throw ex;
 1110            }
 1111            // Create Result
 01112            var _result = new HttpOperationResponse<IList<PersonGroup>>();
 01113            _result.Request = _httpRequest;
 01114            _result.Response = _httpResponse;
 1115            // Deserialize Response
 01116            if ((int)_statusCode == 200)
 1117            {
 01118                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1119                try
 1120                {
 01121                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PersonGroup>>(_responseCon
 01122                }
 01123                catch (JsonException ex)
 1124                {
 01125                    _httpRequest.Dispose();
 01126                    if (_httpResponse != null)
 1127                    {
 01128                        _httpResponse.Dispose();
 1129                    }
 01130                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1131                }
 1132            }
 01133            if (_shouldTrace)
 1134            {
 01135                ServiceClientTracing.Exit(_invocationId, _result);
 1136            }
 01137            return _result;
 01138        }
 1139
 1140        /// <summary>
 1141        /// Queue a person group training task, the training task may not be started
 1142        /// immediately.
 1143        /// </summary>
 1144        /// <param name='personGroupId'>
 1145        /// Id referencing a particular person group.
 1146        /// </param>
 1147        /// <param name='customHeaders'>
 1148        /// Headers that will be added to request.
 1149        /// </param>
 1150        /// <param name='cancellationToken'>
 1151        /// The cancellation token.
 1152        /// </param>
 1153        /// <exception cref="APIErrorException">
 1154        /// Thrown when the operation returned an invalid status code
 1155        /// </exception>
 1156        /// <exception cref="ValidationException">
 1157        /// Thrown when a required parameter is null
 1158        /// </exception>
 1159        /// <exception cref="System.ArgumentNullException">
 1160        /// Thrown when a required parameter is null
 1161        /// </exception>
 1162        /// <return>
 1163        /// A response object containing the response body and response headers.
 1164        /// </return>
 1165        public async Task<HttpOperationResponse> TrainWithHttpMessagesAsync(string personGroupId, Dictionary<string, Lis
 1166        {
 41167            if (Client.Endpoint == null)
 1168            {
 01169                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1170            }
 41171            if (personGroupId == null)
 1172            {
 01173                throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId");
 1174            }
 41175            if (personGroupId != null)
 1176            {
 41177                if (personGroupId.Length > 64)
 1178                {
 01179                    throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64);
 1180                }
 41181                if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$"))
 1182                {
 01183                    throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$");
 1184                }
 1185            }
 1186            // Tracing
 41187            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 41188            string _invocationId = null;
 41189            if (_shouldTrace)
 1190            {
 01191                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01192                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01193                tracingParameters.Add("personGroupId", personGroupId);
 01194                tracingParameters.Add("cancellationToken", cancellationToken);
 01195                ServiceClientTracing.Enter(_invocationId, this, "Train", tracingParameters);
 1196            }
 1197            // Construct URL
 41198            var _baseUrl = Client.BaseUri;
 41199            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/train";
 41200            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 41201            _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId));
 1202            // Create HTTP transport objects
 41203            var _httpRequest = new HttpRequestMessage();
 41204            HttpResponseMessage _httpResponse = null;
 41205            _httpRequest.Method = new HttpMethod("POST");
 41206            _httpRequest.RequestUri = new System.Uri(_url);
 1207            // Set Headers
 1208
 1209
 41210            if (customHeaders != null)
 1211            {
 01212                foreach(var _header in customHeaders)
 1213                {
 01214                    if (_httpRequest.Headers.Contains(_header.Key))
 1215                    {
 01216                        _httpRequest.Headers.Remove(_header.Key);
 1217                    }
 01218                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1219                }
 1220            }
 1221
 1222            // Serialize Request
 41223            string _requestContent = null;
 1224            // Set Credentials
 41225            if (Client.Credentials != null)
 1226            {
 41227                cancellationToken.ThrowIfCancellationRequested();
 41228                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1229            }
 1230            // Send Request
 41231            if (_shouldTrace)
 1232            {
 01233                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1234            }
 41235            cancellationToken.ThrowIfCancellationRequested();
 41236            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 41237            if (_shouldTrace)
 1238            {
 01239                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1240            }
 41241            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 41242            cancellationToken.ThrowIfCancellationRequested();
 41243            string _responseContent = null;
 41244            if ((int)_statusCode != 202)
 1245            {
 01246                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1247                try
 1248                {
 01249                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01250                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01251                    if (_errorBody != null)
 1252                    {
 01253                        ex.Body = _errorBody;
 1254                    }
 01255                }
 01256                catch (JsonException)
 1257                {
 1258                    // Ignore the exception
 01259                }
 01260                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01261                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01262                if (_shouldTrace)
 1263                {
 01264                    ServiceClientTracing.Error(_invocationId, ex);
 1265                }
 01266                _httpRequest.Dispose();
 01267                if (_httpResponse != null)
 1268                {
 01269                    _httpResponse.Dispose();
 1270                }
 01271                throw ex;
 1272            }
 1273            // Create Result
 41274            var _result = new HttpOperationResponse();
 41275            _result.Request = _httpRequest;
 41276            _result.Response = _httpResponse;
 41277            if (_shouldTrace)
 1278            {
 01279                ServiceClientTracing.Exit(_invocationId, _result);
 1280            }
 41281            return _result;
 41282        }
 1283
 1284    }
 1285}