< Summary

Class:Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.CustomVisionPredictionClient
Assembly:Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.CustomVision.Prediction\src\Generated\CustomVisionPredictionClient.cs
Covered lines:233
Uncovered lines:185
Coverable lines:418
Total lines:1783
Line coverage:55.7% (233 of 418)
Covered branches:87
Total branches:196
Branch coverage:44.3% (87 of 196)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_BaseUri()-100%100%
get_SerializationSettings()-100%100%
get_DeserializationSettings()-100%100%
get_Endpoint()-100%100%
get_Credentials()-100%100%
.ctor(...)-0%100%
.ctor(...)-100%100%
.ctor(...)-0%100%
.ctor(...)-85.71%75%
.ctor(...)-0%0%
.ctor(...)-0%0%
Initialize()-100%100%
ClassifyImageUrlWithHttpMessagesAsync()-53.41%45.45%
ClassifyImageUrlWithNoStoreWithHttpMessagesAsync()-53.41%45.45%
DetectImageUrlWithHttpMessagesAsync()-53.41%45.45%
DetectImageUrlWithNoStoreWithHttpMessagesAsync()-53.41%45.45%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.CustomVision.Prediction\src\Generated\CustomVisionPredictionClient.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.CustomVision.Prediction
 12{
 13    using Microsoft.Rest;
 14    using Microsoft.Rest.Serialization;
 15    using Models;
 16    using Newtonsoft.Json;
 17    using System.Collections;
 18    using System.Collections.Generic;
 19    using System.IO;
 20    using System.Net;
 21    using System.Net.Http;
 22    using System.Net.Http.Headers;
 23    using System.Threading;
 24    using System.Threading.Tasks;
 25
 26    public partial class CustomVisionPredictionClient : ServiceClient<CustomVisionPredictionClient>, ICustomVisionPredic
 27    {
 28        /// <summary>
 29        /// The base URI of the service.
 30        /// </summary>
 3231        internal string BaseUri {get; set;}
 32
 33        /// <summary>
 34        /// Gets or sets json serialization settings.
 35        /// </summary>
 4036        public JsonSerializerSettings SerializationSettings { get; private set; }
 37
 38        /// <summary>
 39        /// Gets or sets json deserialization settings.
 40        /// </summary>
 3241        public JsonSerializerSettings DeserializationSettings { get; private set; }
 42
 43        /// <summary>
 44        /// Supported Cognitive Services endpoints.
 45        /// </summary>
 4846        public string Endpoint { get; set; }
 47
 48        /// <summary>
 49        /// Subscription credentials which uniquely identify client subscription.
 50        /// </summary>
 8051        public ServiceClientCredentials Credentials { get; private set; }
 52
 53        /// <summary>
 54        /// Initializes a new instance of the CustomVisionPredictionClient class.
 55        /// </summary>
 56        /// <param name='httpClient'>
 57        /// HttpClient to be used
 58        /// </param>
 59        /// <param name='disposeHttpClient'>
 60        /// True: will dispose the provided httpClient on calling CustomVisionPredictionClient.Dispose(). False: will no
 061        protected CustomVisionPredictionClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, dispose
 62        {
 063            Initialize();
 064        }
 65
 66        /// <summary>
 67        /// Initializes a new instance of the CustomVisionPredictionClient class.
 68        /// </summary>
 69        /// <param name='handlers'>
 70        /// Optional. The delegating handlers to add to the http client pipeline.
 71        /// </param>
 1672        protected CustomVisionPredictionClient(params DelegatingHandler[] handlers) : base(handlers)
 73        {
 1674            Initialize();
 1675        }
 76
 77        /// <summary>
 78        /// Initializes a new instance of the CustomVisionPredictionClient class.
 79        /// </summary>
 80        /// <param name='rootHandler'>
 81        /// Optional. The http client handler used to handle http transport.
 82        /// </param>
 83        /// <param name='handlers'>
 84        /// Optional. The delegating handlers to add to the http client pipeline.
 85        /// </param>
 086        protected CustomVisionPredictionClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : bas
 87        {
 088            Initialize();
 089        }
 90
 91        /// <summary>
 92        /// Initializes a new instance of the CustomVisionPredictionClient class.
 93        /// </summary>
 94        /// <param name='credentials'>
 95        /// Required. Subscription credentials which uniquely identify client subscription.
 96        /// </param>
 97        /// <param name='handlers'>
 98        /// Optional. The delegating handlers to add to the http client pipeline.
 99        /// </param>
 100        /// <exception cref="System.ArgumentNullException">
 101        /// Thrown when a required parameter is null
 102        /// </exception>
 16103        public CustomVisionPredictionClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) :
 104        {
 16105            if (credentials == null)
 106            {
 0107                throw new System.ArgumentNullException("credentials");
 108            }
 16109            Credentials = credentials;
 16110            if (Credentials != null)
 111            {
 16112                Credentials.InitializeServiceClient(this);
 113            }
 16114        }
 115
 116        /// <summary>
 117        /// Initializes a new instance of the CustomVisionPredictionClient class.
 118        /// </summary>
 119        /// <param name='credentials'>
 120        /// Required. Subscription credentials which uniquely identify client subscription.
 121        /// </param>
 122        /// <param name='httpClient'>
 123        /// HttpClient to be used
 124        /// </param>
 125        /// <param name='disposeHttpClient'>
 126        /// True: will dispose the provided httpClient on calling CustomVisionPredictionClient.Dispose(). False: will no
 127        /// <exception cref="System.ArgumentNullException">
 128        /// Thrown when a required parameter is null
 129        /// </exception>
 0130        public CustomVisionPredictionClient(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHtt
 131        {
 0132            if (credentials == null)
 133            {
 0134                throw new System.ArgumentNullException("credentials");
 135            }
 0136            Credentials = credentials;
 0137            if (Credentials != null)
 138            {
 0139                Credentials.InitializeServiceClient(this);
 140            }
 0141        }
 142
 143        /// <summary>
 144        /// Initializes a new instance of the CustomVisionPredictionClient class.
 145        /// </summary>
 146        /// <param name='credentials'>
 147        /// Required. Subscription credentials which uniquely identify client subscription.
 148        /// </param>
 149        /// <param name='rootHandler'>
 150        /// Optional. The http client handler used to handle http transport.
 151        /// </param>
 152        /// <param name='handlers'>
 153        /// Optional. The delegating handlers to add to the http client pipeline.
 154        /// </param>
 155        /// <exception cref="System.ArgumentNullException">
 156        /// Thrown when a required parameter is null
 157        /// </exception>
 0158        public CustomVisionPredictionClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params 
 159        {
 0160            if (credentials == null)
 161            {
 0162                throw new System.ArgumentNullException("credentials");
 163            }
 0164            Credentials = credentials;
 0165            if (Credentials != null)
 166            {
 0167                Credentials.InitializeServiceClient(this);
 168            }
 0169        }
 170
 171        /// <summary>
 172        /// An optional partial-method to perform custom initialization.
 173        ///</summary>
 174        partial void CustomInitialize();
 175        /// <summary>
 176        /// Initializes client properties.
 177        /// </summary>
 178        private void Initialize()
 179        {
 16180            BaseUri = "{Endpoint}/customvision/v3.1/prediction";
 16181            SerializationSettings = new JsonSerializerSettings
 16182            {
 16183                Formatting = Newtonsoft.Json.Formatting.Indented,
 16184                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 16185                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 16186                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 16187                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 16188                ContractResolver = new ReadOnlyJsonContractResolver(),
 16189                Converters = new  List<JsonConverter>
 16190                    {
 16191                        new Iso8601TimeSpanConverter()
 16192                    }
 16193            };
 16194            DeserializationSettings = new JsonSerializerSettings
 16195            {
 16196                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 16197                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 16198                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 16199                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 16200                ContractResolver = new ReadOnlyJsonContractResolver(),
 16201                Converters = new List<JsonConverter>
 16202                    {
 16203                        new Iso8601TimeSpanConverter()
 16204                    }
 16205            };
 206            CustomInitialize();
 16207        }
 208        /// <summary>
 209        /// Classify an image and saves the result.
 210        /// </summary>
 211        /// <param name='projectId'>
 212        /// The project id.
 213        /// </param>
 214        /// <param name='publishedName'>
 215        /// Specifies the name of the model to evaluate against.
 216        /// </param>
 217        /// <param name='imageData'>
 218        /// Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports
 219        /// images up to 4MB.
 220        /// </param>
 221        /// <param name='application'>
 222        /// Optional. Specifies the name of application using the endpoint.
 223        /// </param>
 224        /// <param name='customHeaders'>
 225        /// Headers that will be added to request.
 226        /// </param>
 227        /// <param name='cancellationToken'>
 228        /// The cancellation token.
 229        /// </param>
 230        /// <exception cref="CustomVisionErrorException">
 231        /// Thrown when the operation returned an invalid status code
 232        /// </exception>
 233        /// <exception cref="SerializationException">
 234        /// Thrown when unable to deserialize the response
 235        /// </exception>
 236        /// <exception cref="ValidationException">
 237        /// Thrown when a required parameter is null
 238        /// </exception>
 239        /// <exception cref="System.ArgumentNullException">
 240        /// Thrown when a required parameter is null
 241        /// </exception>
 242        /// <return>
 243        /// A response object containing the response body and response headers.
 244        /// </return>
 245        public async Task<HttpOperationResponse<ImagePrediction>> ClassifyImageWithHttpMessagesAsync(System.Guid project
 246        {
 247            if (Endpoint == null)
 248            {
 249                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 250            }
 251            if (publishedName == null)
 252            {
 253                throw new ValidationException(ValidationRules.CannotBeNull, "publishedName");
 254            }
 255            if (imageData == null)
 256            {
 257                throw new ValidationException(ValidationRules.CannotBeNull, "imageData");
 258            }
 259            // Tracing
 260            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 261            string _invocationId = null;
 262            if (_shouldTrace)
 263            {
 264                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 265                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 266                tracingParameters.Add("projectId", projectId);
 267                tracingParameters.Add("publishedName", publishedName);
 268                tracingParameters.Add("application", application);
 269                tracingParameters.Add("imageData", imageData);
 270                tracingParameters.Add("cancellationToken", cancellationToken);
 271                ServiceClientTracing.Enter(_invocationId, this, "ClassifyImage", tracingParameters);
 272            }
 273            // Construct URL
 274            var _baseUrl = BaseUri;
 275            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{projectId}/classify/iterations/{publishedName}
 276            _url = _url.Replace("{Endpoint}", Endpoint);
 277            _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se
 278            _url = _url.Replace("{publishedName}", System.Uri.EscapeDataString(publishedName));
 279            List<string> _queryParameters = new List<string>();
 280            if (application != null)
 281            {
 282                _queryParameters.Add(string.Format("application={0}", System.Uri.EscapeDataString(application)));
 283            }
 284            if (_queryParameters.Count > 0)
 285            {
 286                _url += "?" + string.Join("&", _queryParameters);
 287            }
 288            // Create HTTP transport objects
 289            var _httpRequest = new HttpRequestMessage();
 290            HttpResponseMessage _httpResponse = null;
 291            _httpRequest.Method = new HttpMethod("POST");
 292            _httpRequest.RequestUri = new System.Uri(_url);
 293            // Set Headers
 294
 295
 296            if (customHeaders != null)
 297            {
 298                foreach(var _header in customHeaders)
 299                {
 300                    if (_httpRequest.Headers.Contains(_header.Key))
 301                    {
 302                        _httpRequest.Headers.Remove(_header.Key);
 303                    }
 304                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 305                }
 306            }
 307
 308            // Serialize Request
 309            string _requestContent = null;
 310            MultipartFormDataContent _multiPartContent = new MultipartFormDataContent();
 311            if (imageData != null)
 312            {
 313                StreamContent _imageData = new StreamContent(imageData);
 314                _imageData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
 315                ContentDispositionHeaderValue _contentDispositionHeaderValue = new ContentDispositionHeaderValue("form-d
 316                _contentDispositionHeaderValue.Name = "imageData";
 317                // get filename from stream if it's a file otherwise, just use  'unknown'
 318                var _fileStream = imageData as FileStream;
 319                var _fileName = (_fileStream != null ? _fileStream.Name : null) ?? "unknown";
 316320                if(System.Linq.Enumerable.Any(_fileName, c => c > 127) )
 321                {
 322                    // non ASCII chars detected, need UTF encoding:
 323                    _contentDispositionHeaderValue.FileNameStar = _fileName;
 324                }
 325                else
 326                {
 327                    // ASCII only
 328                    _contentDispositionHeaderValue.FileName = _fileName;
 329                }
 330                _imageData.Headers.ContentDisposition = _contentDispositionHeaderValue;
 331                _multiPartContent.Add(_imageData, "imageData");
 332            }
 333            _httpRequest.Content = _multiPartContent;
 334            // Set Credentials
 335            if (Credentials != null)
 336            {
 337                cancellationToken.ThrowIfCancellationRequested();
 338                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 339            }
 340            // Send Request
 341            if (_shouldTrace)
 342            {
 343                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 344            }
 345            cancellationToken.ThrowIfCancellationRequested();
 346            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 347            if (_shouldTrace)
 348            {
 349                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 350            }
 351            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 352            cancellationToken.ThrowIfCancellationRequested();
 353            string _responseContent = null;
 354            if ((int)_statusCode != 200)
 355            {
 356                var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'",
 357                try
 358                {
 359                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 360                    CustomVisionError _errorBody =  SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten
 361                    if (_errorBody != null)
 362                    {
 363                        ex.Body = _errorBody;
 364                    }
 365                }
 366                catch (JsonException)
 367                {
 368                    // Ignore the exception
 369                }
 370                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 371                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 372                if (_shouldTrace)
 373                {
 374                    ServiceClientTracing.Error(_invocationId, ex);
 375                }
 376                _httpRequest.Dispose();
 377                if (_httpResponse != null)
 378                {
 379                    _httpResponse.Dispose();
 380                }
 381                throw ex;
 382            }
 383            // Create Result
 384            var _result = new HttpOperationResponse<ImagePrediction>();
 385            _result.Request = _httpRequest;
 386            _result.Response = _httpResponse;
 387            // Deserialize Response
 388            if ((int)_statusCode == 200)
 389            {
 390                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 391                try
 392                {
 393                    _result.Body = SafeJsonConvert.DeserializeObject<ImagePrediction>(_responseContent, DeserializationS
 394                }
 395                catch (JsonException ex)
 396                {
 397                    _httpRequest.Dispose();
 398                    if (_httpResponse != null)
 399                    {
 400                        _httpResponse.Dispose();
 401                    }
 402                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 403                }
 404            }
 405            if (_shouldTrace)
 406            {
 407                ServiceClientTracing.Exit(_invocationId, _result);
 408            }
 409            return _result;
 410        }
 411
 412        /// <summary>
 413        /// Classify an image without saving the result.
 414        /// </summary>
 415        /// <param name='projectId'>
 416        /// The project id.
 417        /// </param>
 418        /// <param name='publishedName'>
 419        /// Specifies the name of the model to evaluate against.
 420        /// </param>
 421        /// <param name='imageData'>
 422        /// Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports
 423        /// images up to 4MB.
 424        /// </param>
 425        /// <param name='application'>
 426        /// Optional. Specifies the name of application using the endpoint.
 427        /// </param>
 428        /// <param name='customHeaders'>
 429        /// Headers that will be added to request.
 430        /// </param>
 431        /// <param name='cancellationToken'>
 432        /// The cancellation token.
 433        /// </param>
 434        /// <exception cref="CustomVisionErrorException">
 435        /// Thrown when the operation returned an invalid status code
 436        /// </exception>
 437        /// <exception cref="SerializationException">
 438        /// Thrown when unable to deserialize the response
 439        /// </exception>
 440        /// <exception cref="ValidationException">
 441        /// Thrown when a required parameter is null
 442        /// </exception>
 443        /// <exception cref="System.ArgumentNullException">
 444        /// Thrown when a required parameter is null
 445        /// </exception>
 446        /// <return>
 447        /// A response object containing the response body and response headers.
 448        /// </return>
 449        public async Task<HttpOperationResponse<ImagePrediction>> ClassifyImageWithNoStoreWithHttpMessagesAsync(System.G
 450        {
 451            if (Endpoint == null)
 452            {
 453                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 454            }
 455            if (publishedName == null)
 456            {
 457                throw new ValidationException(ValidationRules.CannotBeNull, "publishedName");
 458            }
 459            if (imageData == null)
 460            {
 461                throw new ValidationException(ValidationRules.CannotBeNull, "imageData");
 462            }
 463            // Tracing
 464            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 465            string _invocationId = null;
 466            if (_shouldTrace)
 467            {
 468                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 469                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 470                tracingParameters.Add("projectId", projectId);
 471                tracingParameters.Add("publishedName", publishedName);
 472                tracingParameters.Add("application", application);
 473                tracingParameters.Add("imageData", imageData);
 474                tracingParameters.Add("cancellationToken", cancellationToken);
 475                ServiceClientTracing.Enter(_invocationId, this, "ClassifyImageWithNoStore", tracingParameters);
 476            }
 477            // Construct URL
 478            var _baseUrl = BaseUri;
 479            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{projectId}/classify/iterations/{publishedName}
 480            _url = _url.Replace("{Endpoint}", Endpoint);
 481            _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se
 482            _url = _url.Replace("{publishedName}", System.Uri.EscapeDataString(publishedName));
 483            List<string> _queryParameters = new List<string>();
 484            if (application != null)
 485            {
 486                _queryParameters.Add(string.Format("application={0}", System.Uri.EscapeDataString(application)));
 487            }
 488            if (_queryParameters.Count > 0)
 489            {
 490                _url += "?" + string.Join("&", _queryParameters);
 491            }
 492            // Create HTTP transport objects
 493            var _httpRequest = new HttpRequestMessage();
 494            HttpResponseMessage _httpResponse = null;
 495            _httpRequest.Method = new HttpMethod("POST");
 496            _httpRequest.RequestUri = new System.Uri(_url);
 497            // Set Headers
 498
 499
 500            if (customHeaders != null)
 501            {
 502                foreach(var _header in customHeaders)
 503                {
 504                    if (_httpRequest.Headers.Contains(_header.Key))
 505                    {
 506                        _httpRequest.Headers.Remove(_header.Key);
 507                    }
 508                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 509                }
 510            }
 511
 512            // Serialize Request
 513            string _requestContent = null;
 514            MultipartFormDataContent _multiPartContent = new MultipartFormDataContent();
 515            if (imageData != null)
 516            {
 517                StreamContent _imageData = new StreamContent(imageData);
 518                _imageData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
 519                ContentDispositionHeaderValue _contentDispositionHeaderValue = new ContentDispositionHeaderValue("form-d
 520                _contentDispositionHeaderValue.Name = "imageData";
 521                // get filename from stream if it's a file otherwise, just use  'unknown'
 522                var _fileStream = imageData as FileStream;
 523                var _fileName = (_fileStream != null ? _fileStream.Name : null) ?? "unknown";
 316524                if(System.Linq.Enumerable.Any(_fileName, c => c > 127) )
 525                {
 526                    // non ASCII chars detected, need UTF encoding:
 527                    _contentDispositionHeaderValue.FileNameStar = _fileName;
 528                }
 529                else
 530                {
 531                    // ASCII only
 532                    _contentDispositionHeaderValue.FileName = _fileName;
 533                }
 534                _imageData.Headers.ContentDisposition = _contentDispositionHeaderValue;
 535                _multiPartContent.Add(_imageData, "imageData");
 536            }
 537            _httpRequest.Content = _multiPartContent;
 538            // Set Credentials
 539            if (Credentials != null)
 540            {
 541                cancellationToken.ThrowIfCancellationRequested();
 542                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 543            }
 544            // Send Request
 545            if (_shouldTrace)
 546            {
 547                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 548            }
 549            cancellationToken.ThrowIfCancellationRequested();
 550            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 551            if (_shouldTrace)
 552            {
 553                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 554            }
 555            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 556            cancellationToken.ThrowIfCancellationRequested();
 557            string _responseContent = null;
 558            if ((int)_statusCode != 200)
 559            {
 560                var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'",
 561                try
 562                {
 563                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 564                    CustomVisionError _errorBody =  SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten
 565                    if (_errorBody != null)
 566                    {
 567                        ex.Body = _errorBody;
 568                    }
 569                }
 570                catch (JsonException)
 571                {
 572                    // Ignore the exception
 573                }
 574                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 575                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 576                if (_shouldTrace)
 577                {
 578                    ServiceClientTracing.Error(_invocationId, ex);
 579                }
 580                _httpRequest.Dispose();
 581                if (_httpResponse != null)
 582                {
 583                    _httpResponse.Dispose();
 584                }
 585                throw ex;
 586            }
 587            // Create Result
 588            var _result = new HttpOperationResponse<ImagePrediction>();
 589            _result.Request = _httpRequest;
 590            _result.Response = _httpResponse;
 591            // Deserialize Response
 592            if ((int)_statusCode == 200)
 593            {
 594                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 595                try
 596                {
 597                    _result.Body = SafeJsonConvert.DeserializeObject<ImagePrediction>(_responseContent, DeserializationS
 598                }
 599                catch (JsonException ex)
 600                {
 601                    _httpRequest.Dispose();
 602                    if (_httpResponse != null)
 603                    {
 604                        _httpResponse.Dispose();
 605                    }
 606                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 607                }
 608            }
 609            if (_shouldTrace)
 610            {
 611                ServiceClientTracing.Exit(_invocationId, _result);
 612            }
 613            return _result;
 614        }
 615
 616        /// <summary>
 617        /// Classify an image url and saves the result.
 618        /// </summary>
 619        /// <param name='projectId'>
 620        /// The project id.
 621        /// </param>
 622        /// <param name='publishedName'>
 623        /// Specifies the name of the model to evaluate against.
 624        /// </param>
 625        /// <param name='imageUrl'>
 626        /// An ImageUrl that contains the url of the image to be evaluated.
 627        /// </param>
 628        /// <param name='application'>
 629        /// Optional. Specifies the name of application using the endpoint.
 630        /// </param>
 631        /// <param name='customHeaders'>
 632        /// Headers that will be added to request.
 633        /// </param>
 634        /// <param name='cancellationToken'>
 635        /// The cancellation token.
 636        /// </param>
 637        /// <exception cref="CustomVisionErrorException">
 638        /// Thrown when the operation returned an invalid status code
 639        /// </exception>
 640        /// <exception cref="SerializationException">
 641        /// Thrown when unable to deserialize the response
 642        /// </exception>
 643        /// <exception cref="ValidationException">
 644        /// Thrown when a required parameter is null
 645        /// </exception>
 646        /// <exception cref="System.ArgumentNullException">
 647        /// Thrown when a required parameter is null
 648        /// </exception>
 649        /// <return>
 650        /// A response object containing the response body and response headers.
 651        /// </return>
 652        public async Task<HttpOperationResponse<ImagePrediction>> ClassifyImageUrlWithHttpMessagesAsync(System.Guid proj
 653        {
 2654            if (Endpoint == null)
 655            {
 0656                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 657            }
 2658            if (publishedName == null)
 659            {
 0660                throw new ValidationException(ValidationRules.CannotBeNull, "publishedName");
 661            }
 2662            if (imageUrl == null)
 663            {
 0664                throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl");
 665            }
 2666            if (imageUrl != null)
 667            {
 2668                imageUrl.Validate();
 669            }
 670            // Tracing
 2671            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2672            string _invocationId = null;
 2673            if (_shouldTrace)
 674            {
 0675                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0676                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0677                tracingParameters.Add("projectId", projectId);
 0678                tracingParameters.Add("publishedName", publishedName);
 0679                tracingParameters.Add("imageUrl", imageUrl);
 0680                tracingParameters.Add("application", application);
 0681                tracingParameters.Add("cancellationToken", cancellationToken);
 0682                ServiceClientTracing.Enter(_invocationId, this, "ClassifyImageUrl", tracingParameters);
 683            }
 684            // Construct URL
 2685            var _baseUrl = BaseUri;
 2686            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{projectId}/classify/iterations/{publishedName}
 2687            _url = _url.Replace("{Endpoint}", Endpoint);
 2688            _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se
 2689            _url = _url.Replace("{publishedName}", System.Uri.EscapeDataString(publishedName));
 2690            List<string> _queryParameters = new List<string>();
 2691            if (application != null)
 692            {
 0693                _queryParameters.Add(string.Format("application={0}", System.Uri.EscapeDataString(application)));
 694            }
 2695            if (_queryParameters.Count > 0)
 696            {
 0697                _url += "?" + string.Join("&", _queryParameters);
 698            }
 699            // Create HTTP transport objects
 2700            var _httpRequest = new HttpRequestMessage();
 2701            HttpResponseMessage _httpResponse = null;
 2702            _httpRequest.Method = new HttpMethod("POST");
 2703            _httpRequest.RequestUri = new System.Uri(_url);
 704            // Set Headers
 705
 706
 2707            if (customHeaders != null)
 708            {
 0709                foreach(var _header in customHeaders)
 710                {
 0711                    if (_httpRequest.Headers.Contains(_header.Key))
 712                    {
 0713                        _httpRequest.Headers.Remove(_header.Key);
 714                    }
 0715                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 716                }
 717            }
 718
 719            // Serialize Request
 2720            string _requestContent = null;
 2721            if(imageUrl != null)
 722            {
 2723                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 2724                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 2725                _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
 726            }
 727            // Set Credentials
 2728            if (Credentials != null)
 729            {
 2730                cancellationToken.ThrowIfCancellationRequested();
 2731                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 732            }
 733            // Send Request
 2734            if (_shouldTrace)
 735            {
 0736                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 737            }
 2738            cancellationToken.ThrowIfCancellationRequested();
 2739            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2740            if (_shouldTrace)
 741            {
 0742                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 743            }
 2744            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2745            cancellationToken.ThrowIfCancellationRequested();
 2746            string _responseContent = null;
 2747            if ((int)_statusCode != 200)
 748            {
 0749                var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'",
 750                try
 751                {
 0752                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0753                    CustomVisionError _errorBody =  SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten
 0754                    if (_errorBody != null)
 755                    {
 0756                        ex.Body = _errorBody;
 757                    }
 0758                }
 0759                catch (JsonException)
 760                {
 761                    // Ignore the exception
 0762                }
 0763                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0764                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0765                if (_shouldTrace)
 766                {
 0767                    ServiceClientTracing.Error(_invocationId, ex);
 768                }
 0769                _httpRequest.Dispose();
 0770                if (_httpResponse != null)
 771                {
 0772                    _httpResponse.Dispose();
 773                }
 0774                throw ex;
 775            }
 776            // Create Result
 2777            var _result = new HttpOperationResponse<ImagePrediction>();
 2778            _result.Request = _httpRequest;
 2779            _result.Response = _httpResponse;
 780            // Deserialize Response
 2781            if ((int)_statusCode == 200)
 782            {
 2783                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 784                try
 785                {
 2786                    _result.Body = SafeJsonConvert.DeserializeObject<ImagePrediction>(_responseContent, DeserializationS
 2787                }
 0788                catch (JsonException ex)
 789                {
 0790                    _httpRequest.Dispose();
 0791                    if (_httpResponse != null)
 792                    {
 0793                        _httpResponse.Dispose();
 794                    }
 0795                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 796                }
 797            }
 2798            if (_shouldTrace)
 799            {
 0800                ServiceClientTracing.Exit(_invocationId, _result);
 801            }
 2802            return _result;
 2803        }
 804
 805        /// <summary>
 806        /// Classify an image url without saving the result.
 807        /// </summary>
 808        /// <param name='projectId'>
 809        /// The project id.
 810        /// </param>
 811        /// <param name='publishedName'>
 812        /// Specifies the name of the model to evaluate against.
 813        /// </param>
 814        /// <param name='imageUrl'>
 815        /// An {Iris.Web.Api.Models.ImageUrl} that contains the url of the image to be
 816        /// evaluated.
 817        /// </param>
 818        /// <param name='application'>
 819        /// Optional. Specifies the name of application using the endpoint.
 820        /// </param>
 821        /// <param name='customHeaders'>
 822        /// Headers that will be added to request.
 823        /// </param>
 824        /// <param name='cancellationToken'>
 825        /// The cancellation token.
 826        /// </param>
 827        /// <exception cref="CustomVisionErrorException">
 828        /// Thrown when the operation returned an invalid status code
 829        /// </exception>
 830        /// <exception cref="SerializationException">
 831        /// Thrown when unable to deserialize the response
 832        /// </exception>
 833        /// <exception cref="ValidationException">
 834        /// Thrown when a required parameter is null
 835        /// </exception>
 836        /// <exception cref="System.ArgumentNullException">
 837        /// Thrown when a required parameter is null
 838        /// </exception>
 839        /// <return>
 840        /// A response object containing the response body and response headers.
 841        /// </return>
 842        public async Task<HttpOperationResponse<ImagePrediction>> ClassifyImageUrlWithNoStoreWithHttpMessagesAsync(Syste
 843        {
 2844            if (Endpoint == null)
 845            {
 0846                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 847            }
 2848            if (publishedName == null)
 849            {
 0850                throw new ValidationException(ValidationRules.CannotBeNull, "publishedName");
 851            }
 2852            if (imageUrl == null)
 853            {
 0854                throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl");
 855            }
 2856            if (imageUrl != null)
 857            {
 2858                imageUrl.Validate();
 859            }
 860            // Tracing
 2861            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2862            string _invocationId = null;
 2863            if (_shouldTrace)
 864            {
 0865                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0866                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0867                tracingParameters.Add("projectId", projectId);
 0868                tracingParameters.Add("publishedName", publishedName);
 0869                tracingParameters.Add("imageUrl", imageUrl);
 0870                tracingParameters.Add("application", application);
 0871                tracingParameters.Add("cancellationToken", cancellationToken);
 0872                ServiceClientTracing.Enter(_invocationId, this, "ClassifyImageUrlWithNoStore", tracingParameters);
 873            }
 874            // Construct URL
 2875            var _baseUrl = BaseUri;
 2876            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{projectId}/classify/iterations/{publishedName}
 2877            _url = _url.Replace("{Endpoint}", Endpoint);
 2878            _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se
 2879            _url = _url.Replace("{publishedName}", System.Uri.EscapeDataString(publishedName));
 2880            List<string> _queryParameters = new List<string>();
 2881            if (application != null)
 882            {
 0883                _queryParameters.Add(string.Format("application={0}", System.Uri.EscapeDataString(application)));
 884            }
 2885            if (_queryParameters.Count > 0)
 886            {
 0887                _url += "?" + string.Join("&", _queryParameters);
 888            }
 889            // Create HTTP transport objects
 2890            var _httpRequest = new HttpRequestMessage();
 2891            HttpResponseMessage _httpResponse = null;
 2892            _httpRequest.Method = new HttpMethod("POST");
 2893            _httpRequest.RequestUri = new System.Uri(_url);
 894            // Set Headers
 895
 896
 2897            if (customHeaders != null)
 898            {
 0899                foreach(var _header in customHeaders)
 900                {
 0901                    if (_httpRequest.Headers.Contains(_header.Key))
 902                    {
 0903                        _httpRequest.Headers.Remove(_header.Key);
 904                    }
 0905                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 906                }
 907            }
 908
 909            // Serialize Request
 2910            string _requestContent = null;
 2911            if(imageUrl != null)
 912            {
 2913                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 2914                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 2915                _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
 916            }
 917            // Set Credentials
 2918            if (Credentials != null)
 919            {
 2920                cancellationToken.ThrowIfCancellationRequested();
 2921                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 922            }
 923            // Send Request
 2924            if (_shouldTrace)
 925            {
 0926                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 927            }
 2928            cancellationToken.ThrowIfCancellationRequested();
 2929            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2930            if (_shouldTrace)
 931            {
 0932                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 933            }
 2934            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2935            cancellationToken.ThrowIfCancellationRequested();
 2936            string _responseContent = null;
 2937            if ((int)_statusCode != 200)
 938            {
 0939                var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'",
 940                try
 941                {
 0942                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0943                    CustomVisionError _errorBody =  SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten
 0944                    if (_errorBody != null)
 945                    {
 0946                        ex.Body = _errorBody;
 947                    }
 0948                }
 0949                catch (JsonException)
 950                {
 951                    // Ignore the exception
 0952                }
 0953                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0954                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0955                if (_shouldTrace)
 956                {
 0957                    ServiceClientTracing.Error(_invocationId, ex);
 958                }
 0959                _httpRequest.Dispose();
 0960                if (_httpResponse != null)
 961                {
 0962                    _httpResponse.Dispose();
 963                }
 0964                throw ex;
 965            }
 966            // Create Result
 2967            var _result = new HttpOperationResponse<ImagePrediction>();
 2968            _result.Request = _httpRequest;
 2969            _result.Response = _httpResponse;
 970            // Deserialize Response
 2971            if ((int)_statusCode == 200)
 972            {
 2973                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 974                try
 975                {
 2976                    _result.Body = SafeJsonConvert.DeserializeObject<ImagePrediction>(_responseContent, DeserializationS
 2977                }
 0978                catch (JsonException ex)
 979                {
 0980                    _httpRequest.Dispose();
 0981                    if (_httpResponse != null)
 982                    {
 0983                        _httpResponse.Dispose();
 984                    }
 0985                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 986                }
 987            }
 2988            if (_shouldTrace)
 989            {
 0990                ServiceClientTracing.Exit(_invocationId, _result);
 991            }
 2992            return _result;
 2993        }
 994
 995        /// <summary>
 996        /// Detect objects in an image and saves the result.
 997        /// </summary>
 998        /// <param name='projectId'>
 999        /// The project id.
 1000        /// </param>
 1001        /// <param name='publishedName'>
 1002        /// Specifies the name of the model to evaluate against.
 1003        /// </param>
 1004        /// <param name='imageData'>
 1005        /// Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports
 1006        /// images up to 4MB.
 1007        /// </param>
 1008        /// <param name='application'>
 1009        /// Optional. Specifies the name of application using the endpoint.
 1010        /// </param>
 1011        /// <param name='customHeaders'>
 1012        /// Headers that will be added to request.
 1013        /// </param>
 1014        /// <param name='cancellationToken'>
 1015        /// The cancellation token.
 1016        /// </param>
 1017        /// <exception cref="CustomVisionErrorException">
 1018        /// Thrown when the operation returned an invalid status code
 1019        /// </exception>
 1020        /// <exception cref="SerializationException">
 1021        /// Thrown when unable to deserialize the response
 1022        /// </exception>
 1023        /// <exception cref="ValidationException">
 1024        /// Thrown when a required parameter is null
 1025        /// </exception>
 1026        /// <exception cref="System.ArgumentNullException">
 1027        /// Thrown when a required parameter is null
 1028        /// </exception>
 1029        /// <return>
 1030        /// A response object containing the response body and response headers.
 1031        /// </return>
 1032        public async Task<HttpOperationResponse<ImagePrediction>> DetectImageWithHttpMessagesAsync(System.Guid projectId
 1033        {
 1034            if (Endpoint == null)
 1035            {
 1036                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1037            }
 1038            if (publishedName == null)
 1039            {
 1040                throw new ValidationException(ValidationRules.CannotBeNull, "publishedName");
 1041            }
 1042            if (imageData == null)
 1043            {
 1044                throw new ValidationException(ValidationRules.CannotBeNull, "imageData");
 1045            }
 1046            // Tracing
 1047            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 1048            string _invocationId = null;
 1049            if (_shouldTrace)
 1050            {
 1051                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 1052                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 1053                tracingParameters.Add("projectId", projectId);
 1054                tracingParameters.Add("publishedName", publishedName);
 1055                tracingParameters.Add("application", application);
 1056                tracingParameters.Add("imageData", imageData);
 1057                tracingParameters.Add("cancellationToken", cancellationToken);
 1058                ServiceClientTracing.Enter(_invocationId, this, "DetectImage", tracingParameters);
 1059            }
 1060            // Construct URL
 1061            var _baseUrl = BaseUri;
 1062            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{projectId}/detect/iterations/{publishedName}/i
 1063            _url = _url.Replace("{Endpoint}", Endpoint);
 1064            _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se
 1065            _url = _url.Replace("{publishedName}", System.Uri.EscapeDataString(publishedName));
 1066            List<string> _queryParameters = new List<string>();
 1067            if (application != null)
 1068            {
 1069                _queryParameters.Add(string.Format("application={0}", System.Uri.EscapeDataString(application)));
 1070            }
 1071            if (_queryParameters.Count > 0)
 1072            {
 1073                _url += "?" + string.Join("&", _queryParameters);
 1074            }
 1075            // Create HTTP transport objects
 1076            var _httpRequest = new HttpRequestMessage();
 1077            HttpResponseMessage _httpResponse = null;
 1078            _httpRequest.Method = new HttpMethod("POST");
 1079            _httpRequest.RequestUri = new System.Uri(_url);
 1080            // Set Headers
 1081
 1082
 1083            if (customHeaders != null)
 1084            {
 1085                foreach(var _header in customHeaders)
 1086                {
 1087                    if (_httpRequest.Headers.Contains(_header.Key))
 1088                    {
 1089                        _httpRequest.Headers.Remove(_header.Key);
 1090                    }
 1091                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1092                }
 1093            }
 1094
 1095            // Serialize Request
 1096            string _requestContent = null;
 1097            MultipartFormDataContent _multiPartContent = new MultipartFormDataContent();
 1098            if (imageData != null)
 1099            {
 1100                StreamContent _imageData = new StreamContent(imageData);
 1101                _imageData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
 1102                ContentDispositionHeaderValue _contentDispositionHeaderValue = new ContentDispositionHeaderValue("form-d
 1103                _contentDispositionHeaderValue.Name = "imageData";
 1104                // get filename from stream if it's a file otherwise, just use  'unknown'
 1105                var _fileStream = imageData as FileStream;
 1106                var _fileName = (_fileStream != null ? _fileStream.Name : null) ?? "unknown";
 3161107                if(System.Linq.Enumerable.Any(_fileName, c => c > 127) )
 1108                {
 1109                    // non ASCII chars detected, need UTF encoding:
 1110                    _contentDispositionHeaderValue.FileNameStar = _fileName;
 1111                }
 1112                else
 1113                {
 1114                    // ASCII only
 1115                    _contentDispositionHeaderValue.FileName = _fileName;
 1116                }
 1117                _imageData.Headers.ContentDisposition = _contentDispositionHeaderValue;
 1118                _multiPartContent.Add(_imageData, "imageData");
 1119            }
 1120            _httpRequest.Content = _multiPartContent;
 1121            // Set Credentials
 1122            if (Credentials != null)
 1123            {
 1124                cancellationToken.ThrowIfCancellationRequested();
 1125                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1126            }
 1127            // Send Request
 1128            if (_shouldTrace)
 1129            {
 1130                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1131            }
 1132            cancellationToken.ThrowIfCancellationRequested();
 1133            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1134            if (_shouldTrace)
 1135            {
 1136                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1137            }
 1138            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 1139            cancellationToken.ThrowIfCancellationRequested();
 1140            string _responseContent = null;
 1141            if ((int)_statusCode != 200)
 1142            {
 1143                var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'",
 1144                try
 1145                {
 1146                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1147                    CustomVisionError _errorBody =  SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten
 1148                    if (_errorBody != null)
 1149                    {
 1150                        ex.Body = _errorBody;
 1151                    }
 1152                }
 1153                catch (JsonException)
 1154                {
 1155                    // Ignore the exception
 1156                }
 1157                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 1158                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 1159                if (_shouldTrace)
 1160                {
 1161                    ServiceClientTracing.Error(_invocationId, ex);
 1162                }
 1163                _httpRequest.Dispose();
 1164                if (_httpResponse != null)
 1165                {
 1166                    _httpResponse.Dispose();
 1167                }
 1168                throw ex;
 1169            }
 1170            // Create Result
 1171            var _result = new HttpOperationResponse<ImagePrediction>();
 1172            _result.Request = _httpRequest;
 1173            _result.Response = _httpResponse;
 1174            // Deserialize Response
 1175            if ((int)_statusCode == 200)
 1176            {
 1177                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1178                try
 1179                {
 1180                    _result.Body = SafeJsonConvert.DeserializeObject<ImagePrediction>(_responseContent, DeserializationS
 1181                }
 1182                catch (JsonException ex)
 1183                {
 1184                    _httpRequest.Dispose();
 1185                    if (_httpResponse != null)
 1186                    {
 1187                        _httpResponse.Dispose();
 1188                    }
 1189                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1190                }
 1191            }
 1192            if (_shouldTrace)
 1193            {
 1194                ServiceClientTracing.Exit(_invocationId, _result);
 1195            }
 1196            return _result;
 1197        }
 1198
 1199        /// <summary>
 1200        /// Detect objects in an image without saving the result.
 1201        /// </summary>
 1202        /// <param name='projectId'>
 1203        /// The project id.
 1204        /// </param>
 1205        /// <param name='publishedName'>
 1206        /// Specifies the name of the model to evaluate against.
 1207        /// </param>
 1208        /// <param name='imageData'>
 1209        /// Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports
 1210        /// images up to 4MB.
 1211        /// </param>
 1212        /// <param name='application'>
 1213        /// Optional. Specifies the name of application using the endpoint.
 1214        /// </param>
 1215        /// <param name='customHeaders'>
 1216        /// Headers that will be added to request.
 1217        /// </param>
 1218        /// <param name='cancellationToken'>
 1219        /// The cancellation token.
 1220        /// </param>
 1221        /// <exception cref="CustomVisionErrorException">
 1222        /// Thrown when the operation returned an invalid status code
 1223        /// </exception>
 1224        /// <exception cref="SerializationException">
 1225        /// Thrown when unable to deserialize the response
 1226        /// </exception>
 1227        /// <exception cref="ValidationException">
 1228        /// Thrown when a required parameter is null
 1229        /// </exception>
 1230        /// <exception cref="System.ArgumentNullException">
 1231        /// Thrown when a required parameter is null
 1232        /// </exception>
 1233        /// <return>
 1234        /// A response object containing the response body and response headers.
 1235        /// </return>
 1236        public async Task<HttpOperationResponse<ImagePrediction>> DetectImageWithNoStoreWithHttpMessagesAsync(System.Gui
 1237        {
 1238            if (Endpoint == null)
 1239            {
 1240                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1241            }
 1242            if (publishedName == null)
 1243            {
 1244                throw new ValidationException(ValidationRules.CannotBeNull, "publishedName");
 1245            }
 1246            if (imageData == null)
 1247            {
 1248                throw new ValidationException(ValidationRules.CannotBeNull, "imageData");
 1249            }
 1250            // Tracing
 1251            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 1252            string _invocationId = null;
 1253            if (_shouldTrace)
 1254            {
 1255                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 1256                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 1257                tracingParameters.Add("projectId", projectId);
 1258                tracingParameters.Add("publishedName", publishedName);
 1259                tracingParameters.Add("application", application);
 1260                tracingParameters.Add("imageData", imageData);
 1261                tracingParameters.Add("cancellationToken", cancellationToken);
 1262                ServiceClientTracing.Enter(_invocationId, this, "DetectImageWithNoStore", tracingParameters);
 1263            }
 1264            // Construct URL
 1265            var _baseUrl = BaseUri;
 1266            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{projectId}/detect/iterations/{publishedName}/i
 1267            _url = _url.Replace("{Endpoint}", Endpoint);
 1268            _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se
 1269            _url = _url.Replace("{publishedName}", System.Uri.EscapeDataString(publishedName));
 1270            List<string> _queryParameters = new List<string>();
 1271            if (application != null)
 1272            {
 1273                _queryParameters.Add(string.Format("application={0}", System.Uri.EscapeDataString(application)));
 1274            }
 1275            if (_queryParameters.Count > 0)
 1276            {
 1277                _url += "?" + string.Join("&", _queryParameters);
 1278            }
 1279            // Create HTTP transport objects
 1280            var _httpRequest = new HttpRequestMessage();
 1281            HttpResponseMessage _httpResponse = null;
 1282            _httpRequest.Method = new HttpMethod("POST");
 1283            _httpRequest.RequestUri = new System.Uri(_url);
 1284            // Set Headers
 1285
 1286
 1287            if (customHeaders != null)
 1288            {
 1289                foreach(var _header in customHeaders)
 1290                {
 1291                    if (_httpRequest.Headers.Contains(_header.Key))
 1292                    {
 1293                        _httpRequest.Headers.Remove(_header.Key);
 1294                    }
 1295                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1296                }
 1297            }
 1298
 1299            // Serialize Request
 1300            string _requestContent = null;
 1301            MultipartFormDataContent _multiPartContent = new MultipartFormDataContent();
 1302            if (imageData != null)
 1303            {
 1304                StreamContent _imageData = new StreamContent(imageData);
 1305                _imageData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
 1306                ContentDispositionHeaderValue _contentDispositionHeaderValue = new ContentDispositionHeaderValue("form-d
 1307                _contentDispositionHeaderValue.Name = "imageData";
 1308                // get filename from stream if it's a file otherwise, just use  'unknown'
 1309                var _fileStream = imageData as FileStream;
 1310                var _fileName = (_fileStream != null ? _fileStream.Name : null) ?? "unknown";
 3161311                if(System.Linq.Enumerable.Any(_fileName, c => c > 127) )
 1312                {
 1313                    // non ASCII chars detected, need UTF encoding:
 1314                    _contentDispositionHeaderValue.FileNameStar = _fileName;
 1315                }
 1316                else
 1317                {
 1318                    // ASCII only
 1319                    _contentDispositionHeaderValue.FileName = _fileName;
 1320                }
 1321                _imageData.Headers.ContentDisposition = _contentDispositionHeaderValue;
 1322                _multiPartContent.Add(_imageData, "imageData");
 1323            }
 1324            _httpRequest.Content = _multiPartContent;
 1325            // Set Credentials
 1326            if (Credentials != null)
 1327            {
 1328                cancellationToken.ThrowIfCancellationRequested();
 1329                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1330            }
 1331            // Send Request
 1332            if (_shouldTrace)
 1333            {
 1334                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1335            }
 1336            cancellationToken.ThrowIfCancellationRequested();
 1337            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1338            if (_shouldTrace)
 1339            {
 1340                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1341            }
 1342            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 1343            cancellationToken.ThrowIfCancellationRequested();
 1344            string _responseContent = null;
 1345            if ((int)_statusCode != 200)
 1346            {
 1347                var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'",
 1348                try
 1349                {
 1350                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1351                    CustomVisionError _errorBody =  SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten
 1352                    if (_errorBody != null)
 1353                    {
 1354                        ex.Body = _errorBody;
 1355                    }
 1356                }
 1357                catch (JsonException)
 1358                {
 1359                    // Ignore the exception
 1360                }
 1361                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 1362                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 1363                if (_shouldTrace)
 1364                {
 1365                    ServiceClientTracing.Error(_invocationId, ex);
 1366                }
 1367                _httpRequest.Dispose();
 1368                if (_httpResponse != null)
 1369                {
 1370                    _httpResponse.Dispose();
 1371                }
 1372                throw ex;
 1373            }
 1374            // Create Result
 1375            var _result = new HttpOperationResponse<ImagePrediction>();
 1376            _result.Request = _httpRequest;
 1377            _result.Response = _httpResponse;
 1378            // Deserialize Response
 1379            if ((int)_statusCode == 200)
 1380            {
 1381                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1382                try
 1383                {
 1384                    _result.Body = SafeJsonConvert.DeserializeObject<ImagePrediction>(_responseContent, DeserializationS
 1385                }
 1386                catch (JsonException ex)
 1387                {
 1388                    _httpRequest.Dispose();
 1389                    if (_httpResponse != null)
 1390                    {
 1391                        _httpResponse.Dispose();
 1392                    }
 1393                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1394                }
 1395            }
 1396            if (_shouldTrace)
 1397            {
 1398                ServiceClientTracing.Exit(_invocationId, _result);
 1399            }
 1400            return _result;
 1401        }
 1402
 1403        /// <summary>
 1404        /// Detect objects in an image url and saves the result.
 1405        /// </summary>
 1406        /// <param name='projectId'>
 1407        /// The project id.
 1408        /// </param>
 1409        /// <param name='publishedName'>
 1410        /// Specifies the name of the model to evaluate against.
 1411        /// </param>
 1412        /// <param name='imageUrl'>
 1413        /// An ImageUrl that contains the url of the image to be evaluated.
 1414        /// </param>
 1415        /// <param name='application'>
 1416        /// Optional. Specifies the name of application using the endpoint.
 1417        /// </param>
 1418        /// <param name='customHeaders'>
 1419        /// Headers that will be added to request.
 1420        /// </param>
 1421        /// <param name='cancellationToken'>
 1422        /// The cancellation token.
 1423        /// </param>
 1424        /// <exception cref="CustomVisionErrorException">
 1425        /// Thrown when the operation returned an invalid status code
 1426        /// </exception>
 1427        /// <exception cref="SerializationException">
 1428        /// Thrown when unable to deserialize the response
 1429        /// </exception>
 1430        /// <exception cref="ValidationException">
 1431        /// Thrown when a required parameter is null
 1432        /// </exception>
 1433        /// <exception cref="System.ArgumentNullException">
 1434        /// Thrown when a required parameter is null
 1435        /// </exception>
 1436        /// <return>
 1437        /// A response object containing the response body and response headers.
 1438        /// </return>
 1439        public async Task<HttpOperationResponse<ImagePrediction>> DetectImageUrlWithHttpMessagesAsync(System.Guid projec
 1440        {
 21441            if (Endpoint == null)
 1442            {
 01443                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1444            }
 21445            if (publishedName == null)
 1446            {
 01447                throw new ValidationException(ValidationRules.CannotBeNull, "publishedName");
 1448            }
 21449            if (imageUrl == null)
 1450            {
 01451                throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl");
 1452            }
 21453            if (imageUrl != null)
 1454            {
 21455                imageUrl.Validate();
 1456            }
 1457            // Tracing
 21458            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 21459            string _invocationId = null;
 21460            if (_shouldTrace)
 1461            {
 01462                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01463                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01464                tracingParameters.Add("projectId", projectId);
 01465                tracingParameters.Add("publishedName", publishedName);
 01466                tracingParameters.Add("imageUrl", imageUrl);
 01467                tracingParameters.Add("application", application);
 01468                tracingParameters.Add("cancellationToken", cancellationToken);
 01469                ServiceClientTracing.Enter(_invocationId, this, "DetectImageUrl", tracingParameters);
 1470            }
 1471            // Construct URL
 21472            var _baseUrl = BaseUri;
 21473            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{projectId}/detect/iterations/{publishedName}/u
 21474            _url = _url.Replace("{Endpoint}", Endpoint);
 21475            _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se
 21476            _url = _url.Replace("{publishedName}", System.Uri.EscapeDataString(publishedName));
 21477            List<string> _queryParameters = new List<string>();
 21478            if (application != null)
 1479            {
 01480                _queryParameters.Add(string.Format("application={0}", System.Uri.EscapeDataString(application)));
 1481            }
 21482            if (_queryParameters.Count > 0)
 1483            {
 01484                _url += "?" + string.Join("&", _queryParameters);
 1485            }
 1486            // Create HTTP transport objects
 21487            var _httpRequest = new HttpRequestMessage();
 21488            HttpResponseMessage _httpResponse = null;
 21489            _httpRequest.Method = new HttpMethod("POST");
 21490            _httpRequest.RequestUri = new System.Uri(_url);
 1491            // Set Headers
 1492
 1493
 21494            if (customHeaders != null)
 1495            {
 01496                foreach(var _header in customHeaders)
 1497                {
 01498                    if (_httpRequest.Headers.Contains(_header.Key))
 1499                    {
 01500                        _httpRequest.Headers.Remove(_header.Key);
 1501                    }
 01502                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1503                }
 1504            }
 1505
 1506            // Serialize Request
 21507            string _requestContent = null;
 21508            if(imageUrl != null)
 1509            {
 21510                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 21511                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 21512                _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
 1513            }
 1514            // Set Credentials
 21515            if (Credentials != null)
 1516            {
 21517                cancellationToken.ThrowIfCancellationRequested();
 21518                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1519            }
 1520            // Send Request
 21521            if (_shouldTrace)
 1522            {
 01523                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1524            }
 21525            cancellationToken.ThrowIfCancellationRequested();
 21526            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 21527            if (_shouldTrace)
 1528            {
 01529                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1530            }
 21531            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 21532            cancellationToken.ThrowIfCancellationRequested();
 21533            string _responseContent = null;
 21534            if ((int)_statusCode != 200)
 1535            {
 01536                var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'",
 1537                try
 1538                {
 01539                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01540                    CustomVisionError _errorBody =  SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten
 01541                    if (_errorBody != null)
 1542                    {
 01543                        ex.Body = _errorBody;
 1544                    }
 01545                }
 01546                catch (JsonException)
 1547                {
 1548                    // Ignore the exception
 01549                }
 01550                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01551                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01552                if (_shouldTrace)
 1553                {
 01554                    ServiceClientTracing.Error(_invocationId, ex);
 1555                }
 01556                _httpRequest.Dispose();
 01557                if (_httpResponse != null)
 1558                {
 01559                    _httpResponse.Dispose();
 1560                }
 01561                throw ex;
 1562            }
 1563            // Create Result
 21564            var _result = new HttpOperationResponse<ImagePrediction>();
 21565            _result.Request = _httpRequest;
 21566            _result.Response = _httpResponse;
 1567            // Deserialize Response
 21568            if ((int)_statusCode == 200)
 1569            {
 21570                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1571                try
 1572                {
 21573                    _result.Body = SafeJsonConvert.DeserializeObject<ImagePrediction>(_responseContent, DeserializationS
 21574                }
 01575                catch (JsonException ex)
 1576                {
 01577                    _httpRequest.Dispose();
 01578                    if (_httpResponse != null)
 1579                    {
 01580                        _httpResponse.Dispose();
 1581                    }
 01582                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1583                }
 1584            }
 21585            if (_shouldTrace)
 1586            {
 01587                ServiceClientTracing.Exit(_invocationId, _result);
 1588            }
 21589            return _result;
 21590        }
 1591
 1592        /// <summary>
 1593        /// Detect objects in an image url without saving the result.
 1594        /// </summary>
 1595        /// <param name='projectId'>
 1596        /// The project id.
 1597        /// </param>
 1598        /// <param name='publishedName'>
 1599        /// Specifies the name of the model to evaluate against.
 1600        /// </param>
 1601        /// <param name='imageUrl'>
 1602        /// An {Iris.Web.Api.Models.ImageUrl} that contains the url of the image to be
 1603        /// evaluated.
 1604        /// </param>
 1605        /// <param name='application'>
 1606        /// Optional. Specifies the name of application using the endpoint.
 1607        /// </param>
 1608        /// <param name='customHeaders'>
 1609        /// Headers that will be added to request.
 1610        /// </param>
 1611        /// <param name='cancellationToken'>
 1612        /// The cancellation token.
 1613        /// </param>
 1614        /// <exception cref="CustomVisionErrorException">
 1615        /// Thrown when the operation returned an invalid status code
 1616        /// </exception>
 1617        /// <exception cref="SerializationException">
 1618        /// Thrown when unable to deserialize the response
 1619        /// </exception>
 1620        /// <exception cref="ValidationException">
 1621        /// Thrown when a required parameter is null
 1622        /// </exception>
 1623        /// <exception cref="System.ArgumentNullException">
 1624        /// Thrown when a required parameter is null
 1625        /// </exception>
 1626        /// <return>
 1627        /// A response object containing the response body and response headers.
 1628        /// </return>
 1629        public async Task<HttpOperationResponse<ImagePrediction>> DetectImageUrlWithNoStoreWithHttpMessagesAsync(System.
 1630        {
 21631            if (Endpoint == null)
 1632            {
 01633                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1634            }
 21635            if (publishedName == null)
 1636            {
 01637                throw new ValidationException(ValidationRules.CannotBeNull, "publishedName");
 1638            }
 21639            if (imageUrl == null)
 1640            {
 01641                throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl");
 1642            }
 21643            if (imageUrl != null)
 1644            {
 21645                imageUrl.Validate();
 1646            }
 1647            // Tracing
 21648            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 21649            string _invocationId = null;
 21650            if (_shouldTrace)
 1651            {
 01652                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01653                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01654                tracingParameters.Add("projectId", projectId);
 01655                tracingParameters.Add("publishedName", publishedName);
 01656                tracingParameters.Add("imageUrl", imageUrl);
 01657                tracingParameters.Add("application", application);
 01658                tracingParameters.Add("cancellationToken", cancellationToken);
 01659                ServiceClientTracing.Enter(_invocationId, this, "DetectImageUrlWithNoStore", tracingParameters);
 1660            }
 1661            // Construct URL
 21662            var _baseUrl = BaseUri;
 21663            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "{projectId}/detect/iterations/{publishedName}/u
 21664            _url = _url.Replace("{Endpoint}", Endpoint);
 21665            _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se
 21666            _url = _url.Replace("{publishedName}", System.Uri.EscapeDataString(publishedName));
 21667            List<string> _queryParameters = new List<string>();
 21668            if (application != null)
 1669            {
 01670                _queryParameters.Add(string.Format("application={0}", System.Uri.EscapeDataString(application)));
 1671            }
 21672            if (_queryParameters.Count > 0)
 1673            {
 01674                _url += "?" + string.Join("&", _queryParameters);
 1675            }
 1676            // Create HTTP transport objects
 21677            var _httpRequest = new HttpRequestMessage();
 21678            HttpResponseMessage _httpResponse = null;
 21679            _httpRequest.Method = new HttpMethod("POST");
 21680            _httpRequest.RequestUri = new System.Uri(_url);
 1681            // Set Headers
 1682
 1683
 21684            if (customHeaders != null)
 1685            {
 01686                foreach(var _header in customHeaders)
 1687                {
 01688                    if (_httpRequest.Headers.Contains(_header.Key))
 1689                    {
 01690                        _httpRequest.Headers.Remove(_header.Key);
 1691                    }
 01692                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1693                }
 1694            }
 1695
 1696            // Serialize Request
 21697            string _requestContent = null;
 21698            if(imageUrl != null)
 1699            {
 21700                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 21701                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 21702                _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
 1703            }
 1704            // Set Credentials
 21705            if (Credentials != null)
 1706            {
 21707                cancellationToken.ThrowIfCancellationRequested();
 21708                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1709            }
 1710            // Send Request
 21711            if (_shouldTrace)
 1712            {
 01713                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1714            }
 21715            cancellationToken.ThrowIfCancellationRequested();
 21716            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 21717            if (_shouldTrace)
 1718            {
 01719                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1720            }
 21721            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 21722            cancellationToken.ThrowIfCancellationRequested();
 21723            string _responseContent = null;
 21724            if ((int)_statusCode != 200)
 1725            {
 01726                var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'",
 1727                try
 1728                {
 01729                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01730                    CustomVisionError _errorBody =  SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten
 01731                    if (_errorBody != null)
 1732                    {
 01733                        ex.Body = _errorBody;
 1734                    }
 01735                }
 01736                catch (JsonException)
 1737                {
 1738                    // Ignore the exception
 01739                }
 01740                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01741                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01742                if (_shouldTrace)
 1743                {
 01744                    ServiceClientTracing.Error(_invocationId, ex);
 1745                }
 01746                _httpRequest.Dispose();
 01747                if (_httpResponse != null)
 1748                {
 01749                    _httpResponse.Dispose();
 1750                }
 01751                throw ex;
 1752            }
 1753            // Create Result
 21754            var _result = new HttpOperationResponse<ImagePrediction>();
 21755            _result.Request = _httpRequest;
 21756            _result.Response = _httpResponse;
 1757            // Deserialize Response
 21758            if ((int)_statusCode == 200)
 1759            {
 21760                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1761                try
 1762                {
 21763                    _result.Body = SafeJsonConvert.DeserializeObject<ImagePrediction>(_responseContent, DeserializationS
 21764                }
 01765                catch (JsonException ex)
 1766                {
 01767                    _httpRequest.Dispose();
 01768                    if (_httpResponse != null)
 1769                    {
 01770                        _httpResponse.Dispose();
 1771                    }
 01772                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1773                }
 1774            }
 21775            if (_shouldTrace)
 1776            {
 01777                ServiceClientTracing.Exit(_invocationId, _result);
 1778            }
 21779            return _result;
 21780        }
 1781
 1782    }
 1783}