< Summary

Class:Microsoft.Azure.CognitiveServices.Vision.Face.LargePersonGroupOperations
Assembly:Microsoft.Azure.CognitiveServices.Vision.Face
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.Face\src\Generated\LargePersonGroupOperations.cs
Covered lines:206
Uncovered lines:343
Coverable lines:549
Total lines:1289
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\LargePersonGroupOperations.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    /// LargePersonGroupOperations operations.
 27    /// </summary>
 28    public partial class LargePersonGroupOperations : IServiceOperations<FaceClient>, ILargePersonGroupOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the LargePersonGroupOperations 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 LargePersonGroupOperations(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>
 24651        public FaceClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Create a new large person group with user-specified largePersonGroupId,
 55        /// name, an optional userData and recognitionModel.
 56        /// &lt;br /&gt; A large person group is the container of the uploaded person
 57        /// data, including face recognition feature, and up to 1,000,000
 58        /// people.
 59        /// &lt;br /&gt; After creation, use [LargePersonGroup Person -
 60        /// Create](/docs/services/563879b61984550e40cbbe8d/operations/599adcba3a7b9412a4d53f40)
 61        /// to add person into the group, and call [LargePersonGroup -
 62        /// Train](/docs/services/563879b61984550e40cbbe8d/operations/599ae2d16ac60f11b48b5aa4)
 63        /// to get this group ready for [Face -
 64        /// Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239).
 65        /// &lt;br /&gt; No image will be stored. Only the person's extracted face
 66        /// features and userData will be stored on server until [LargePersonGroup
 67        /// Person -
 68        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/599ade5c6ac60f11b48b5aa2)
 69        /// or [LargePersonGroup -
 70        /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/599adc216ac60f11b48b5a9f)
 71        /// is called.
 72        /// &lt;br/&gt;'recognitionModel' should be specified to associate with this
 73        /// large person group. The default value for 'recognitionModel' is
 74        /// 'recognition_01', if the latest model needed, please explicitly specify the
 75        /// model you need in this parameter. New faces that are added to an existing
 76        /// large person group will use the recognition model that's already associated
 77        /// with the collection. Existing face features in a large person group can't
 78        /// be updated to features extracted by another version of recognition model.
 79        /// * 'recognition_01': The default recognition model for [LargePersonGroup -
 80        /// Create](/docs/services/563879b61984550e40cbbe8d/operations/599acdee6ac60f11b48b5a9d).
 81        /// All those large person groups created before 2019 March are bonded with
 82        /// this recognition model.
 83        /// * 'recognition_02': Recognition model released in 2019 March.
 84        /// 'recognition_02' is recommended since its overall accuracy is improved
 85        /// compared with 'recognition_01'.
 86        ///
 87        /// Large person group quota:
 88        /// * Free-tier subscription quota: 1,000 large person groups.
 89        /// * S0-tier subscription quota: 1,000,000 large person groups.
 90        /// </summary>
 91        /// <param name='largePersonGroupId'>
 92        /// Id referencing a particular large person group.
 93        /// </param>
 94        /// <param name='name'>
 95        /// User defined name, maximum length is 128.
 96        /// </param>
 97        /// <param name='userData'>
 98        /// User specified data. Length should not exceed 16KB.
 99        /// </param>
 100        /// <param name='recognitionModel'>
 101        /// Possible values include: 'recognition_01', 'recognition_02'
 102        /// </param>
 103        /// <param name='customHeaders'>
 104        /// Headers that will be added to request.
 105        /// </param>
 106        /// <param name='cancellationToken'>
 107        /// The cancellation token.
 108        /// </param>
 109        /// <exception cref="APIErrorException">
 110        /// Thrown when the operation returned an invalid status code
 111        /// </exception>
 112        /// <exception cref="ValidationException">
 113        /// Thrown when a required parameter is null
 114        /// </exception>
 115        /// <exception cref="System.ArgumentNullException">
 116        /// Thrown when a required parameter is null
 117        /// </exception>
 118        /// <return>
 119        /// A response object containing the response body and response headers.
 120        /// </return>
 121        public async Task<HttpOperationResponse> CreateWithHttpMessagesAsync(string largePersonGroupId, string name = de
 122        {
 8123            if (Client.Endpoint == null)
 124            {
 0125                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 126            }
 8127            if (largePersonGroupId == null)
 128            {
 0129                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 130            }
 8131            if (largePersonGroupId != null)
 132            {
 8133                if (largePersonGroupId.Length > 64)
 134                {
 0135                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 136                }
 8137                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 138                {
 0139                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 140                }
 141            }
 8142            if (name != null)
 143            {
 8144                if (name.Length > 128)
 145                {
 0146                    throw new ValidationException(ValidationRules.MaxLength, "name", 128);
 147                }
 148            }
 8149            if (userData != null)
 150            {
 2151                if (userData.Length > 16384)
 152                {
 0153                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 154                }
 155            }
 8156            MetaDataContract body = new MetaDataContract();
 8157            if (name != null || userData != null || recognitionModel != null)
 158            {
 8159                body.Name = name;
 8160                body.UserData = userData;
 8161                body.RecognitionModel = recognitionModel;
 162            }
 163            // Tracing
 8164            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 8165            string _invocationId = null;
 8166            if (_shouldTrace)
 167            {
 0168                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0169                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0170                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 0171                tracingParameters.Add("body", body);
 0172                tracingParameters.Add("cancellationToken", cancellationToken);
 0173                ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters);
 174            }
 175            // Construct URL
 8176            var _baseUrl = Client.BaseUri;
 8177            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}";
 8178            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 8179            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 180            // Create HTTP transport objects
 8181            var _httpRequest = new HttpRequestMessage();
 8182            HttpResponseMessage _httpResponse = null;
 8183            _httpRequest.Method = new HttpMethod("PUT");
 8184            _httpRequest.RequestUri = new System.Uri(_url);
 185            // Set Headers
 186
 187
 8188            if (customHeaders != null)
 189            {
 0190                foreach(var _header in customHeaders)
 191                {
 0192                    if (_httpRequest.Headers.Contains(_header.Key))
 193                    {
 0194                        _httpRequest.Headers.Remove(_header.Key);
 195                    }
 0196                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 197                }
 198            }
 199
 200            // Serialize Request
 8201            string _requestContent = null;
 8202            if(body != null)
 203            {
 8204                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 8205                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 8206                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 207            }
 208            // Set Credentials
 8209            if (Client.Credentials != null)
 210            {
 8211                cancellationToken.ThrowIfCancellationRequested();
 8212                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 213            }
 214            // Send Request
 8215            if (_shouldTrace)
 216            {
 0217                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 218            }
 8219            cancellationToken.ThrowIfCancellationRequested();
 8220            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 8221            if (_shouldTrace)
 222            {
 0223                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 224            }
 8225            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 8226            cancellationToken.ThrowIfCancellationRequested();
 8227            string _responseContent = null;
 8228            if ((int)_statusCode != 200)
 229            {
 0230                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 231                try
 232                {
 0233                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0234                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0235                    if (_errorBody != null)
 236                    {
 0237                        ex.Body = _errorBody;
 238                    }
 0239                }
 0240                catch (JsonException)
 241                {
 242                    // Ignore the exception
 0243                }
 0244                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0245                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0246                if (_shouldTrace)
 247                {
 0248                    ServiceClientTracing.Error(_invocationId, ex);
 249                }
 0250                _httpRequest.Dispose();
 0251                if (_httpResponse != null)
 252                {
 0253                    _httpResponse.Dispose();
 254                }
 0255                throw ex;
 256            }
 257            // Create Result
 8258            var _result = new HttpOperationResponse();
 8259            _result.Request = _httpRequest;
 8260            _result.Response = _httpResponse;
 8261            if (_shouldTrace)
 262            {
 0263                ServiceClientTracing.Exit(_invocationId, _result);
 264            }
 8265            return _result;
 8266        }
 267
 268        /// <summary>
 269        /// Delete an existing large person group. Persisted face features of all
 270        /// people in the large person group will also be deleted.
 271        /// </summary>
 272        /// <param name='largePersonGroupId'>
 273        /// Id referencing a particular large person group.
 274        /// </param>
 275        /// <param name='customHeaders'>
 276        /// Headers that will be added to request.
 277        /// </param>
 278        /// <param name='cancellationToken'>
 279        /// The cancellation token.
 280        /// </param>
 281        /// <exception cref="APIErrorException">
 282        /// Thrown when the operation returned an invalid status code
 283        /// </exception>
 284        /// <exception cref="ValidationException">
 285        /// Thrown when a required parameter is null
 286        /// </exception>
 287        /// <exception cref="System.ArgumentNullException">
 288        /// Thrown when a required parameter is null
 289        /// </exception>
 290        /// <return>
 291        /// A response object containing the response body and response headers.
 292        /// </return>
 293        public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(string largePersonGroupId, Dictionary<strin
 294        {
 10295            if (Client.Endpoint == null)
 296            {
 0297                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 298            }
 10299            if (largePersonGroupId == null)
 300            {
 0301                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 302            }
 10303            if (largePersonGroupId != null)
 304            {
 10305                if (largePersonGroupId.Length > 64)
 306                {
 0307                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 308                }
 10309                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 310                {
 0311                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 312                }
 313            }
 314            // Tracing
 10315            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 10316            string _invocationId = null;
 10317            if (_shouldTrace)
 318            {
 0319                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0320                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0321                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 0322                tracingParameters.Add("cancellationToken", cancellationToken);
 0323                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 324            }
 325            // Construct URL
 10326            var _baseUrl = Client.BaseUri;
 10327            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}";
 10328            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 10329            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 330            // Create HTTP transport objects
 10331            var _httpRequest = new HttpRequestMessage();
 10332            HttpResponseMessage _httpResponse = null;
 10333            _httpRequest.Method = new HttpMethod("DELETE");
 10334            _httpRequest.RequestUri = new System.Uri(_url);
 335            // Set Headers
 336
 337
 10338            if (customHeaders != null)
 339            {
 0340                foreach(var _header in customHeaders)
 341                {
 0342                    if (_httpRequest.Headers.Contains(_header.Key))
 343                    {
 0344                        _httpRequest.Headers.Remove(_header.Key);
 345                    }
 0346                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 347                }
 348            }
 349
 350            // Serialize Request
 10351            string _requestContent = null;
 352            // Set Credentials
 10353            if (Client.Credentials != null)
 354            {
 10355                cancellationToken.ThrowIfCancellationRequested();
 10356                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 357            }
 358            // Send Request
 10359            if (_shouldTrace)
 360            {
 0361                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 362            }
 10363            cancellationToken.ThrowIfCancellationRequested();
 10364            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 10365            if (_shouldTrace)
 366            {
 0367                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 368            }
 10369            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 10370            cancellationToken.ThrowIfCancellationRequested();
 10371            string _responseContent = null;
 10372            if ((int)_statusCode != 200)
 373            {
 0374                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 375                try
 376                {
 0377                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0378                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0379                    if (_errorBody != null)
 380                    {
 0381                        ex.Body = _errorBody;
 382                    }
 0383                }
 0384                catch (JsonException)
 385                {
 386                    // Ignore the exception
 0387                }
 0388                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0389                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0390                if (_shouldTrace)
 391                {
 0392                    ServiceClientTracing.Error(_invocationId, ex);
 393                }
 0394                _httpRequest.Dispose();
 0395                if (_httpResponse != null)
 396                {
 0397                    _httpResponse.Dispose();
 398                }
 0399                throw ex;
 400            }
 401            // Create Result
 10402            var _result = new HttpOperationResponse();
 10403            _result.Request = _httpRequest;
 10404            _result.Response = _httpResponse;
 10405            if (_shouldTrace)
 406            {
 0407                ServiceClientTracing.Exit(_invocationId, _result);
 408            }
 10409            return _result;
 10410        }
 411
 412        /// <summary>
 413        /// Retrieve the information of a large person group, including its name,
 414        /// userData and recognitionModel. This API returns large person group
 415        /// information only, use [LargePersonGroup Person -
 416        /// List](/docs/services/563879b61984550e40cbbe8d/operations/599adda06ac60f11b48b5aa1)
 417        /// instead to retrieve person information under the large person group.
 418        ///
 419        /// </summary>
 420        /// <param name='largePersonGroupId'>
 421        /// Id referencing a particular large person group.
 422        /// </param>
 423        /// <param name='returnRecognitionModel'>
 424        /// A value indicating whether the operation should return 'recognitionModel'
 425        /// in response.
 426        /// </param>
 427        /// <param name='customHeaders'>
 428        /// Headers that will be added to request.
 429        /// </param>
 430        /// <param name='cancellationToken'>
 431        /// The cancellation token.
 432        /// </param>
 433        /// <exception cref="APIErrorException">
 434        /// Thrown when the operation returned an invalid status code
 435        /// </exception>
 436        /// <exception cref="SerializationException">
 437        /// Thrown when unable to deserialize the response
 438        /// </exception>
 439        /// <exception cref="ValidationException">
 440        /// Thrown when a required parameter is null
 441        /// </exception>
 442        /// <exception cref="System.ArgumentNullException">
 443        /// Thrown when a required parameter is null
 444        /// </exception>
 445        /// <return>
 446        /// A response object containing the response body and response headers.
 447        /// </return>
 448        public async Task<HttpOperationResponse<LargePersonGroup>> GetWithHttpMessagesAsync(string largePersonGroupId, b
 449        {
 2450            if (Client.Endpoint == null)
 451            {
 0452                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 453            }
 2454            if (largePersonGroupId == null)
 455            {
 0456                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 457            }
 2458            if (largePersonGroupId != null)
 459            {
 2460                if (largePersonGroupId.Length > 64)
 461                {
 0462                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 463                }
 2464                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 465                {
 0466                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 467                }
 468            }
 469            // Tracing
 2470            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2471            string _invocationId = null;
 2472            if (_shouldTrace)
 473            {
 0474                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0475                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0476                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 0477                tracingParameters.Add("returnRecognitionModel", returnRecognitionModel);
 0478                tracingParameters.Add("cancellationToken", cancellationToken);
 0479                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 480            }
 481            // Construct URL
 2482            var _baseUrl = Client.BaseUri;
 2483            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}";
 2484            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 2485            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 2486            List<string> _queryParameters = new List<string>();
 2487            if (returnRecognitionModel != null)
 488            {
 2489                _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial
 490            }
 2491            if (_queryParameters.Count > 0)
 492            {
 2493                _url += "?" + string.Join("&", _queryParameters);
 494            }
 495            // Create HTTP transport objects
 2496            var _httpRequest = new HttpRequestMessage();
 2497            HttpResponseMessage _httpResponse = null;
 2498            _httpRequest.Method = new HttpMethod("GET");
 2499            _httpRequest.RequestUri = new System.Uri(_url);
 500            // Set Headers
 501
 502
 2503            if (customHeaders != null)
 504            {
 0505                foreach(var _header in customHeaders)
 506                {
 0507                    if (_httpRequest.Headers.Contains(_header.Key))
 508                    {
 0509                        _httpRequest.Headers.Remove(_header.Key);
 510                    }
 0511                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 512                }
 513            }
 514
 515            // Serialize Request
 2516            string _requestContent = null;
 517            // Set Credentials
 2518            if (Client.Credentials != null)
 519            {
 2520                cancellationToken.ThrowIfCancellationRequested();
 2521                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 522            }
 523            // Send Request
 2524            if (_shouldTrace)
 525            {
 0526                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 527            }
 2528            cancellationToken.ThrowIfCancellationRequested();
 2529            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2530            if (_shouldTrace)
 531            {
 0532                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 533            }
 2534            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2535            cancellationToken.ThrowIfCancellationRequested();
 2536            string _responseContent = null;
 2537            if ((int)_statusCode != 200)
 538            {
 0539                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 540                try
 541                {
 0542                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0543                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0544                    if (_errorBody != null)
 545                    {
 0546                        ex.Body = _errorBody;
 547                    }
 0548                }
 0549                catch (JsonException)
 550                {
 551                    // Ignore the exception
 0552                }
 0553                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0554                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0555                if (_shouldTrace)
 556                {
 0557                    ServiceClientTracing.Error(_invocationId, ex);
 558                }
 0559                _httpRequest.Dispose();
 0560                if (_httpResponse != null)
 561                {
 0562                    _httpResponse.Dispose();
 563                }
 0564                throw ex;
 565            }
 566            // Create Result
 2567            var _result = new HttpOperationResponse<LargePersonGroup>();
 2568            _result.Request = _httpRequest;
 2569            _result.Response = _httpResponse;
 570            // Deserialize Response
 2571            if ((int)_statusCode == 200)
 572            {
 2573                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 574                try
 575                {
 2576                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<LargePersonGroup>(_responseConte
 2577                }
 0578                catch (JsonException ex)
 579                {
 0580                    _httpRequest.Dispose();
 0581                    if (_httpResponse != null)
 582                    {
 0583                        _httpResponse.Dispose();
 584                    }
 0585                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 586                }
 587            }
 2588            if (_shouldTrace)
 589            {
 0590                ServiceClientTracing.Exit(_invocationId, _result);
 591            }
 2592            return _result;
 2593        }
 594
 595        /// <summary>
 596        /// Update an existing large person group's display name and userData. The
 597        /// properties which does not appear in request body will not be updated.
 598        /// </summary>
 599        /// <param name='largePersonGroupId'>
 600        /// Id referencing a particular large person group.
 601        /// </param>
 602        /// <param name='name'>
 603        /// User defined name, maximum length is 128.
 604        /// </param>
 605        /// <param name='userData'>
 606        /// User specified data. Length should not exceed 16KB.
 607        /// </param>
 608        /// <param name='customHeaders'>
 609        /// Headers that will be added to request.
 610        /// </param>
 611        /// <param name='cancellationToken'>
 612        /// The cancellation token.
 613        /// </param>
 614        /// <exception cref="APIErrorException">
 615        /// Thrown when the operation returned an invalid status code
 616        /// </exception>
 617        /// <exception cref="ValidationException">
 618        /// Thrown when a required parameter is null
 619        /// </exception>
 620        /// <exception cref="System.ArgumentNullException">
 621        /// Thrown when a required parameter is null
 622        /// </exception>
 623        /// <return>
 624        /// A response object containing the response body and response headers.
 625        /// </return>
 626        public async Task<HttpOperationResponse> UpdateWithHttpMessagesAsync(string largePersonGroupId, string name = de
 627        {
 0628            if (Client.Endpoint == null)
 629            {
 0630                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 631            }
 0632            if (largePersonGroupId == null)
 633            {
 0634                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 635            }
 0636            if (largePersonGroupId != null)
 637            {
 0638                if (largePersonGroupId.Length > 64)
 639                {
 0640                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 641                }
 0642                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 643                {
 0644                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 645                }
 646            }
 0647            if (name != null)
 648            {
 0649                if (name.Length > 128)
 650                {
 0651                    throw new ValidationException(ValidationRules.MaxLength, "name", 128);
 652                }
 653            }
 0654            if (userData != null)
 655            {
 0656                if (userData.Length > 16384)
 657                {
 0658                    throw new ValidationException(ValidationRules.MaxLength, "userData", 16384);
 659                }
 660            }
 0661            NameAndUserDataContract body = new NameAndUserDataContract();
 0662            if (name != null || userData != null)
 663            {
 0664                body.Name = name;
 0665                body.UserData = userData;
 666            }
 667            // Tracing
 0668            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0669            string _invocationId = null;
 0670            if (_shouldTrace)
 671            {
 0672                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0673                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0674                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 0675                tracingParameters.Add("body", body);
 0676                tracingParameters.Add("cancellationToken", cancellationToken);
 0677                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
 678            }
 679            // Construct URL
 0680            var _baseUrl = Client.BaseUri;
 0681            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}";
 0682            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0683            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 684            // Create HTTP transport objects
 0685            var _httpRequest = new HttpRequestMessage();
 0686            HttpResponseMessage _httpResponse = null;
 0687            _httpRequest.Method = new HttpMethod("PATCH");
 0688            _httpRequest.RequestUri = new System.Uri(_url);
 689            // Set Headers
 690
 691
 0692            if (customHeaders != null)
 693            {
 0694                foreach(var _header in customHeaders)
 695                {
 0696                    if (_httpRequest.Headers.Contains(_header.Key))
 697                    {
 0698                        _httpRequest.Headers.Remove(_header.Key);
 699                    }
 0700                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 701                }
 702            }
 703
 704            // Serialize Request
 0705            string _requestContent = null;
 0706            if(body != null)
 707            {
 0708                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 0709                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0710                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 711            }
 712            // Set Credentials
 0713            if (Client.Credentials != null)
 714            {
 0715                cancellationToken.ThrowIfCancellationRequested();
 0716                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 717            }
 718            // Send Request
 0719            if (_shouldTrace)
 720            {
 0721                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 722            }
 0723            cancellationToken.ThrowIfCancellationRequested();
 0724            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0725            if (_shouldTrace)
 726            {
 0727                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 728            }
 0729            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0730            cancellationToken.ThrowIfCancellationRequested();
 0731            string _responseContent = null;
 0732            if ((int)_statusCode != 200)
 733            {
 0734                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 735                try
 736                {
 0737                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0738                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0739                    if (_errorBody != null)
 740                    {
 0741                        ex.Body = _errorBody;
 742                    }
 0743                }
 0744                catch (JsonException)
 745                {
 746                    // Ignore the exception
 0747                }
 0748                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0749                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0750                if (_shouldTrace)
 751                {
 0752                    ServiceClientTracing.Error(_invocationId, ex);
 753                }
 0754                _httpRequest.Dispose();
 0755                if (_httpResponse != null)
 756                {
 0757                    _httpResponse.Dispose();
 758                }
 0759                throw ex;
 760            }
 761            // Create Result
 0762            var _result = new HttpOperationResponse();
 0763            _result.Request = _httpRequest;
 0764            _result.Response = _httpResponse;
 0765            if (_shouldTrace)
 766            {
 0767                ServiceClientTracing.Exit(_invocationId, _result);
 768            }
 0769            return _result;
 0770        }
 771
 772        /// <summary>
 773        /// Retrieve the training status of a large person group (completed or
 774        /// ongoing).
 775        /// </summary>
 776        /// <param name='largePersonGroupId'>
 777        /// Id referencing a particular large person group.
 778        /// </param>
 779        /// <param name='customHeaders'>
 780        /// Headers that will be added to request.
 781        /// </param>
 782        /// <param name='cancellationToken'>
 783        /// The cancellation token.
 784        /// </param>
 785        /// <exception cref="APIErrorException">
 786        /// Thrown when the operation returned an invalid status code
 787        /// </exception>
 788        /// <exception cref="SerializationException">
 789        /// Thrown when unable to deserialize the response
 790        /// </exception>
 791        /// <exception cref="ValidationException">
 792        /// Thrown when a required parameter is null
 793        /// </exception>
 794        /// <exception cref="System.ArgumentNullException">
 795        /// Thrown when a required parameter is null
 796        /// </exception>
 797        /// <return>
 798        /// A response object containing the response body and response headers.
 799        /// </return>
 800        public async Task<HttpOperationResponse<TrainingStatus>> GetTrainingStatusWithHttpMessagesAsync(string largePers
 801        {
 8802            if (Client.Endpoint == null)
 803            {
 0804                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 805            }
 8806            if (largePersonGroupId == null)
 807            {
 0808                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 809            }
 8810            if (largePersonGroupId != null)
 811            {
 8812                if (largePersonGroupId.Length > 64)
 813                {
 0814                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 815                }
 8816                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 817                {
 0818                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 819                }
 820            }
 821            // Tracing
 8822            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 8823            string _invocationId = null;
 8824            if (_shouldTrace)
 825            {
 0826                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0827                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0828                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 0829                tracingParameters.Add("cancellationToken", cancellationToken);
 0830                ServiceClientTracing.Enter(_invocationId, this, "GetTrainingStatus", tracingParameters);
 831            }
 832            // Construct URL
 8833            var _baseUrl = Client.BaseUri;
 8834            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/training
 8835            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 8836            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 837            // Create HTTP transport objects
 8838            var _httpRequest = new HttpRequestMessage();
 8839            HttpResponseMessage _httpResponse = null;
 8840            _httpRequest.Method = new HttpMethod("GET");
 8841            _httpRequest.RequestUri = new System.Uri(_url);
 842            // Set Headers
 843
 844
 8845            if (customHeaders != null)
 846            {
 0847                foreach(var _header in customHeaders)
 848                {
 0849                    if (_httpRequest.Headers.Contains(_header.Key))
 850                    {
 0851                        _httpRequest.Headers.Remove(_header.Key);
 852                    }
 0853                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 854                }
 855            }
 856
 857            // Serialize Request
 8858            string _requestContent = null;
 859            // Set Credentials
 8860            if (Client.Credentials != null)
 861            {
 8862                cancellationToken.ThrowIfCancellationRequested();
 8863                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 864            }
 865            // Send Request
 8866            if (_shouldTrace)
 867            {
 0868                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 869            }
 8870            cancellationToken.ThrowIfCancellationRequested();
 8871            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 8872            if (_shouldTrace)
 873            {
 0874                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 875            }
 8876            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 8877            cancellationToken.ThrowIfCancellationRequested();
 8878            string _responseContent = null;
 8879            if ((int)_statusCode != 200)
 880            {
 0881                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 882                try
 883                {
 0884                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0885                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0886                    if (_errorBody != null)
 887                    {
 0888                        ex.Body = _errorBody;
 889                    }
 0890                }
 0891                catch (JsonException)
 892                {
 893                    // Ignore the exception
 0894                }
 0895                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0896                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0897                if (_shouldTrace)
 898                {
 0899                    ServiceClientTracing.Error(_invocationId, ex);
 900                }
 0901                _httpRequest.Dispose();
 0902                if (_httpResponse != null)
 903                {
 0904                    _httpResponse.Dispose();
 905                }
 0906                throw ex;
 907            }
 908            // Create Result
 8909            var _result = new HttpOperationResponse<TrainingStatus>();
 8910            _result.Request = _httpRequest;
 8911            _result.Response = _httpResponse;
 912            // Deserialize Response
 8913            if ((int)_statusCode == 200)
 914            {
 8915                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 916                try
 917                {
 8918                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<TrainingStatus>(_responseContent
 8919                }
 0920                catch (JsonException ex)
 921                {
 0922                    _httpRequest.Dispose();
 0923                    if (_httpResponse != null)
 924                    {
 0925                        _httpResponse.Dispose();
 926                    }
 0927                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 928                }
 929            }
 8930            if (_shouldTrace)
 931            {
 0932                ServiceClientTracing.Exit(_invocationId, _result);
 933            }
 8934            return _result;
 8935        }
 936
 937        /// <summary>
 938        /// List all existing large person groups’ largePersonGroupId, name, userData
 939        /// and recognitionModel.&lt;br /&gt;
 940        /// * Large person groups are stored in alphabetical order of
 941        /// largePersonGroupId.
 942        /// * "start" parameter (string, optional) is a user-provided
 943        /// largePersonGroupId value that returned entries have larger ids by string
 944        /// comparison. "start" set to empty to indicate return from the first item.
 945        /// * "top" parameter (int, optional) specifies the number of entries to
 946        /// return. A maximal of 1000 entries can be returned in one call. To fetch
 947        /// more, you can specify "start" with the last returned entry’s Id of the
 948        /// current call.
 949        /// &lt;br /&gt;
 950        /// For example, total 5 large person groups: "group1", ..., "group5".
 951        /// &lt;br /&gt; "start=&amp;top=" will return all 5 groups.
 952        /// &lt;br /&gt; "start=&amp;top=2" will return "group1", "group2".
 953        /// &lt;br /&gt; "start=group2&amp;top=3" will return "group3", "group4",
 954        /// "group5".
 955        ///
 956        /// </summary>
 957        /// <param name='start'>
 958        /// List large person groups from the least largePersonGroupId greater than the
 959        /// "start".
 960        /// </param>
 961        /// <param name='top'>
 962        /// The number of large person groups to list.
 963        /// </param>
 964        /// <param name='returnRecognitionModel'>
 965        /// A value indicating whether the operation should return 'recognitionModel'
 966        /// in response.
 967        /// </param>
 968        /// <param name='customHeaders'>
 969        /// Headers that will be added to request.
 970        /// </param>
 971        /// <param name='cancellationToken'>
 972        /// The cancellation token.
 973        /// </param>
 974        /// <exception cref="APIErrorException">
 975        /// Thrown when the operation returned an invalid status code
 976        /// </exception>
 977        /// <exception cref="SerializationException">
 978        /// Thrown when unable to deserialize the response
 979        /// </exception>
 980        /// <exception cref="ValidationException">
 981        /// Thrown when a required parameter is null
 982        /// </exception>
 983        /// <exception cref="System.ArgumentNullException">
 984        /// Thrown when a required parameter is null
 985        /// </exception>
 986        /// <return>
 987        /// A response object containing the response body and response headers.
 988        /// </return>
 989        public async Task<HttpOperationResponse<IList<LargePersonGroup>>> ListWithHttpMessagesAsync(string start = defau
 990        {
 0991            if (Client.Endpoint == null)
 992            {
 0993                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 994            }
 0995            if (start != null)
 996            {
 0997                if (start.Length > 64)
 998                {
 0999                    throw new ValidationException(ValidationRules.MaxLength, "start", 64);
 1000                }
 1001            }
 01002            if (top > 1000)
 1003            {
 01004                throw new ValidationException(ValidationRules.InclusiveMaximum, "top", 1000);
 1005            }
 01006            if (top < 1)
 1007            {
 01008                throw new ValidationException(ValidationRules.InclusiveMinimum, "top", 1);
 1009            }
 1010            // Tracing
 01011            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01012            string _invocationId = null;
 01013            if (_shouldTrace)
 1014            {
 01015                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01016                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01017                tracingParameters.Add("start", start);
 01018                tracingParameters.Add("top", top);
 01019                tracingParameters.Add("returnRecognitionModel", returnRecognitionModel);
 01020                tracingParameters.Add("cancellationToken", cancellationToken);
 01021                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 1022            }
 1023            // Construct URL
 01024            var _baseUrl = Client.BaseUri;
 01025            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups";
 01026            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01027            List<string> _queryParameters = new List<string>();
 01028            if (start != null)
 1029            {
 01030                _queryParameters.Add(string.Format("start={0}", System.Uri.EscapeDataString(start)));
 1031            }
 01032            if (top != null)
 1033            {
 01034                _queryParameters.Add(string.Format("top={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon
 1035            }
 01036            if (returnRecognitionModel != null)
 1037            {
 01038                _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial
 1039            }
 01040            if (_queryParameters.Count > 0)
 1041            {
 01042                _url += "?" + string.Join("&", _queryParameters);
 1043            }
 1044            // Create HTTP transport objects
 01045            var _httpRequest = new HttpRequestMessage();
 01046            HttpResponseMessage _httpResponse = null;
 01047            _httpRequest.Method = new HttpMethod("GET");
 01048            _httpRequest.RequestUri = new System.Uri(_url);
 1049            // Set Headers
 1050
 1051
 01052            if (customHeaders != null)
 1053            {
 01054                foreach(var _header in customHeaders)
 1055                {
 01056                    if (_httpRequest.Headers.Contains(_header.Key))
 1057                    {
 01058                        _httpRequest.Headers.Remove(_header.Key);
 1059                    }
 01060                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1061                }
 1062            }
 1063
 1064            // Serialize Request
 01065            string _requestContent = null;
 1066            // Set Credentials
 01067            if (Client.Credentials != null)
 1068            {
 01069                cancellationToken.ThrowIfCancellationRequested();
 01070                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1071            }
 1072            // Send Request
 01073            if (_shouldTrace)
 1074            {
 01075                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1076            }
 01077            cancellationToken.ThrowIfCancellationRequested();
 01078            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01079            if (_shouldTrace)
 1080            {
 01081                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1082            }
 01083            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01084            cancellationToken.ThrowIfCancellationRequested();
 01085            string _responseContent = null;
 01086            if ((int)_statusCode != 200)
 1087            {
 01088                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1089                try
 1090                {
 01091                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01092                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01093                    if (_errorBody != null)
 1094                    {
 01095                        ex.Body = _errorBody;
 1096                    }
 01097                }
 01098                catch (JsonException)
 1099                {
 1100                    // Ignore the exception
 01101                }
 01102                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01103                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01104                if (_shouldTrace)
 1105                {
 01106                    ServiceClientTracing.Error(_invocationId, ex);
 1107                }
 01108                _httpRequest.Dispose();
 01109                if (_httpResponse != null)
 1110                {
 01111                    _httpResponse.Dispose();
 1112                }
 01113                throw ex;
 1114            }
 1115            // Create Result
 01116            var _result = new HttpOperationResponse<IList<LargePersonGroup>>();
 01117            _result.Request = _httpRequest;
 01118            _result.Response = _httpResponse;
 1119            // Deserialize Response
 01120            if ((int)_statusCode == 200)
 1121            {
 01122                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1123                try
 1124                {
 01125                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<LargePersonGroup>>(_respon
 01126                }
 01127                catch (JsonException ex)
 1128                {
 01129                    _httpRequest.Dispose();
 01130                    if (_httpResponse != null)
 1131                    {
 01132                        _httpResponse.Dispose();
 1133                    }
 01134                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1135                }
 1136            }
 01137            if (_shouldTrace)
 1138            {
 01139                ServiceClientTracing.Exit(_invocationId, _result);
 1140            }
 01141            return _result;
 01142        }
 1143
 1144        /// <summary>
 1145        /// Queue a large person group training task, the training task may not be
 1146        /// started immediately.
 1147        /// </summary>
 1148        /// <param name='largePersonGroupId'>
 1149        /// Id referencing a particular large person group.
 1150        /// </param>
 1151        /// <param name='customHeaders'>
 1152        /// Headers that will be added to request.
 1153        /// </param>
 1154        /// <param name='cancellationToken'>
 1155        /// The cancellation token.
 1156        /// </param>
 1157        /// <exception cref="APIErrorException">
 1158        /// Thrown when the operation returned an invalid status code
 1159        /// </exception>
 1160        /// <exception cref="ValidationException">
 1161        /// Thrown when a required parameter is null
 1162        /// </exception>
 1163        /// <exception cref="System.ArgumentNullException">
 1164        /// Thrown when a required parameter is null
 1165        /// </exception>
 1166        /// <return>
 1167        /// A response object containing the response body and response headers.
 1168        /// </return>
 1169        public async Task<HttpOperationResponse> TrainWithHttpMessagesAsync(string largePersonGroupId, Dictionary<string
 1170        {
 41171            if (Client.Endpoint == null)
 1172            {
 01173                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1174            }
 41175            if (largePersonGroupId == null)
 1176            {
 01177                throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId");
 1178            }
 41179            if (largePersonGroupId != null)
 1180            {
 41181                if (largePersonGroupId.Length > 64)
 1182                {
 01183                    throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64);
 1184                }
 41185                if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$"))
 1186                {
 01187                    throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$");
 1188                }
 1189            }
 1190            // Tracing
 41191            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 41192            string _invocationId = null;
 41193            if (_shouldTrace)
 1194            {
 01195                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01196                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01197                tracingParameters.Add("largePersonGroupId", largePersonGroupId);
 01198                tracingParameters.Add("cancellationToken", cancellationToken);
 01199                ServiceClientTracing.Enter(_invocationId, this, "Train", tracingParameters);
 1200            }
 1201            // Construct URL
 41202            var _baseUrl = Client.BaseUri;
 41203            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/train";
 41204            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 41205            _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId));
 1206            // Create HTTP transport objects
 41207            var _httpRequest = new HttpRequestMessage();
 41208            HttpResponseMessage _httpResponse = null;
 41209            _httpRequest.Method = new HttpMethod("POST");
 41210            _httpRequest.RequestUri = new System.Uri(_url);
 1211            // Set Headers
 1212
 1213
 41214            if (customHeaders != null)
 1215            {
 01216                foreach(var _header in customHeaders)
 1217                {
 01218                    if (_httpRequest.Headers.Contains(_header.Key))
 1219                    {
 01220                        _httpRequest.Headers.Remove(_header.Key);
 1221                    }
 01222                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1223                }
 1224            }
 1225
 1226            // Serialize Request
 41227            string _requestContent = null;
 1228            // Set Credentials
 41229            if (Client.Credentials != null)
 1230            {
 41231                cancellationToken.ThrowIfCancellationRequested();
 41232                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1233            }
 1234            // Send Request
 41235            if (_shouldTrace)
 1236            {
 01237                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1238            }
 41239            cancellationToken.ThrowIfCancellationRequested();
 41240            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 41241            if (_shouldTrace)
 1242            {
 01243                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1244            }
 41245            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 41246            cancellationToken.ThrowIfCancellationRequested();
 41247            string _responseContent = null;
 41248            if ((int)_statusCode != 202)
 1249            {
 01250                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1251                try
 1252                {
 01253                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01254                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01255                    if (_errorBody != null)
 1256                    {
 01257                        ex.Body = _errorBody;
 1258                    }
 01259                }
 01260                catch (JsonException)
 1261                {
 1262                    // Ignore the exception
 01263                }
 01264                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01265                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01266                if (_shouldTrace)
 1267                {
 01268                    ServiceClientTracing.Error(_invocationId, ex);
 1269                }
 01270                _httpRequest.Dispose();
 01271                if (_httpResponse != null)
 1272                {
 01273                    _httpResponse.Dispose();
 1274                }
 01275                throw ex;
 1276            }
 1277            // Create Result
 41278            var _result = new HttpOperationResponse();
 41279            _result.Request = _httpRequest;
 41280            _result.Response = _httpResponse;
 41281            if (_shouldTrace)
 1282            {
 01283                ServiceClientTracing.Exit(_invocationId, _result);
 1284            }
 41285            return _result;
 41286        }
 1287
 1288    }
 1289}