| | 1 | | // <auto-generated> |
| | 2 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 3 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 4 | | // regenerated. |
| | 5 | | // </auto-generated> |
| | 6 | |
|
| | 7 | | namespace Microsoft.Azure.CognitiveServices.ContentModerator |
| | 8 | | { |
| | 9 | | using Microsoft.Rest; |
| | 10 | | using Models; |
| | 11 | | using Newtonsoft.Json; |
| | 12 | | using System.Collections; |
| | 13 | | using System.Collections.Generic; |
| | 14 | | using System.IO; |
| | 15 | | using System.Linq; |
| | 16 | | using System.Net; |
| | 17 | | using System.Net.Http; |
| | 18 | | using System.Threading; |
| | 19 | | using System.Threading.Tasks; |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// ImageModeration operations. |
| | 23 | | /// </summary> |
| | 24 | | public partial class ImageModeration : IServiceOperations<ContentModeratorClient>, IImageModeration |
| | 25 | | { |
| | 26 | | /// <summary> |
| | 27 | | /// Initializes a new instance of the ImageModeration class. |
| | 28 | | /// </summary> |
| | 29 | | /// <param name='client'> |
| | 30 | | /// Reference to the service client. |
| | 31 | | /// </param> |
| | 32 | | /// <exception cref="System.ArgumentNullException"> |
| | 33 | | /// Thrown when a required parameter is null |
| | 34 | | /// </exception> |
| 5 | 35 | | public ImageModeration(ContentModeratorClient client) |
| | 36 | | { |
| 5 | 37 | | if (client == null) |
| | 38 | | { |
| 0 | 39 | | throw new System.ArgumentNullException("client"); |
| | 40 | | } |
| 5 | 41 | | Client = client; |
| 5 | 42 | | } |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Gets a reference to the ContentModeratorClient |
| | 46 | | /// </summary> |
| 0 | 47 | | public ContentModeratorClient Client { get; private set; } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Returns the list of faces found. |
| | 51 | | /// </summary> |
| | 52 | | /// <param name='cacheImage'> |
| | 53 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 54 | | /// omitted. |
| | 55 | | /// </param> |
| | 56 | | /// <param name='customHeaders'> |
| | 57 | | /// Headers that will be added to request. |
| | 58 | | /// </param> |
| | 59 | | /// <param name='cancellationToken'> |
| | 60 | | /// The cancellation token. |
| | 61 | | /// </param> |
| | 62 | | /// <exception cref="APIErrorException"> |
| | 63 | | /// Thrown when the operation returned an invalid status code |
| | 64 | | /// </exception> |
| | 65 | | /// <exception cref="SerializationException"> |
| | 66 | | /// Thrown when unable to deserialize the response |
| | 67 | | /// </exception> |
| | 68 | | /// <exception cref="ValidationException"> |
| | 69 | | /// Thrown when a required parameter is null |
| | 70 | | /// </exception> |
| | 71 | | /// <exception cref="System.ArgumentNullException"> |
| | 72 | | /// Thrown when a required parameter is null |
| | 73 | | /// </exception> |
| | 74 | | /// <return> |
| | 75 | | /// A response object containing the response body and response headers. |
| | 76 | | /// </return> |
| | 77 | | public async Task<HttpOperationResponse<FoundFaces>> FindFacesWithHttpMessagesAsync(bool? cacheImage = default(b |
| | 78 | | { |
| 0 | 79 | | if (Client.Endpoint == null) |
| | 80 | | { |
| 0 | 81 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 82 | | } |
| | 83 | | // Tracing |
| 0 | 84 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 85 | | string _invocationId = null; |
| 0 | 86 | | if (_shouldTrace) |
| | 87 | | { |
| 0 | 88 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 89 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 90 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 91 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 92 | | ServiceClientTracing.Enter(_invocationId, this, "FindFaces", tracingParameters); |
| | 93 | | } |
| | 94 | | // Construct URL |
| 0 | 95 | | var _baseUrl = Client.BaseUri; |
| 0 | 96 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Fin |
| 0 | 97 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 98 | | List<string> _queryParameters = new List<string>(); |
| 0 | 99 | | if (cacheImage != null) |
| | 100 | | { |
| 0 | 101 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 102 | | } |
| 0 | 103 | | if (_queryParameters.Count > 0) |
| | 104 | | { |
| 0 | 105 | | _url += "?" + string.Join("&", _queryParameters); |
| | 106 | | } |
| | 107 | | // Create HTTP transport objects |
| 0 | 108 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 109 | | HttpResponseMessage _httpResponse = null; |
| 0 | 110 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 111 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 112 | | // Set Headers |
| | 113 | |
|
| | 114 | |
|
| 0 | 115 | | if (customHeaders != null) |
| | 116 | | { |
| 0 | 117 | | foreach(var _header in customHeaders) |
| | 118 | | { |
| 0 | 119 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 120 | | { |
| 0 | 121 | | _httpRequest.Headers.Remove(_header.Key); |
| | 122 | | } |
| 0 | 123 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 124 | | } |
| | 125 | | } |
| | 126 | |
|
| | 127 | | // Serialize Request |
| 0 | 128 | | string _requestContent = null; |
| | 129 | | // Set Credentials |
| 0 | 130 | | if (Client.Credentials != null) |
| | 131 | | { |
| 0 | 132 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 133 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 134 | | } |
| | 135 | | // Send Request |
| 0 | 136 | | if (_shouldTrace) |
| | 137 | | { |
| 0 | 138 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 139 | | } |
| 0 | 140 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 141 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 142 | | if (_shouldTrace) |
| | 143 | | { |
| 0 | 144 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 145 | | } |
| 0 | 146 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 147 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 148 | | string _responseContent = null; |
| 0 | 149 | | if ((int)_statusCode != 200) |
| | 150 | | { |
| 0 | 151 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 152 | | try |
| | 153 | | { |
| 0 | 154 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 155 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 156 | | if (_errorBody != null) |
| | 157 | | { |
| 0 | 158 | | ex.Body = _errorBody; |
| | 159 | | } |
| 0 | 160 | | } |
| 0 | 161 | | catch (JsonException) |
| | 162 | | { |
| | 163 | | // Ignore the exception |
| 0 | 164 | | } |
| 0 | 165 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 166 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 167 | | if (_shouldTrace) |
| | 168 | | { |
| 0 | 169 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 170 | | } |
| 0 | 171 | | _httpRequest.Dispose(); |
| 0 | 172 | | if (_httpResponse != null) |
| | 173 | | { |
| 0 | 174 | | _httpResponse.Dispose(); |
| | 175 | | } |
| 0 | 176 | | throw ex; |
| | 177 | | } |
| | 178 | | // Create Result |
| 0 | 179 | | var _result = new HttpOperationResponse<FoundFaces>(); |
| 0 | 180 | | _result.Request = _httpRequest; |
| 0 | 181 | | _result.Response = _httpResponse; |
| | 182 | | // Deserialize Response |
| 0 | 183 | | if ((int)_statusCode == 200) |
| | 184 | | { |
| 0 | 185 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 186 | | try |
| | 187 | | { |
| 0 | 188 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<FoundFaces>(_responseContent, Cl |
| 0 | 189 | | } |
| 0 | 190 | | catch (JsonException ex) |
| | 191 | | { |
| 0 | 192 | | _httpRequest.Dispose(); |
| 0 | 193 | | if (_httpResponse != null) |
| | 194 | | { |
| 0 | 195 | | _httpResponse.Dispose(); |
| | 196 | | } |
| 0 | 197 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 198 | | } |
| | 199 | | } |
| 0 | 200 | | if (_shouldTrace) |
| | 201 | | { |
| 0 | 202 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 203 | | } |
| 0 | 204 | | return _result; |
| 0 | 205 | | } |
| | 206 | |
|
| | 207 | | /// <summary> |
| | 208 | | /// Returns any text found in the image for the language specified. If no |
| | 209 | | /// language is specified in input then the detection defaults to English. |
| | 210 | | /// </summary> |
| | 211 | | /// <param name='language'> |
| | 212 | | /// Language of the terms. |
| | 213 | | /// </param> |
| | 214 | | /// <param name='cacheImage'> |
| | 215 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 216 | | /// omitted. |
| | 217 | | /// </param> |
| | 218 | | /// <param name='enhanced'> |
| | 219 | | /// When set to True, the image goes through additional processing to come with |
| | 220 | | /// additional candidates. |
| | 221 | | /// |
| | 222 | | /// image/tiff is not supported when enhanced is set to true |
| | 223 | | /// |
| | 224 | | /// Note: This impacts the response time. |
| | 225 | | /// </param> |
| | 226 | | /// <param name='customHeaders'> |
| | 227 | | /// Headers that will be added to request. |
| | 228 | | /// </param> |
| | 229 | | /// <param name='cancellationToken'> |
| | 230 | | /// The cancellation token. |
| | 231 | | /// </param> |
| | 232 | | /// <exception cref="APIErrorException"> |
| | 233 | | /// Thrown when the operation returned an invalid status code |
| | 234 | | /// </exception> |
| | 235 | | /// <exception cref="SerializationException"> |
| | 236 | | /// Thrown when unable to deserialize the response |
| | 237 | | /// </exception> |
| | 238 | | /// <exception cref="ValidationException"> |
| | 239 | | /// Thrown when a required parameter is null |
| | 240 | | /// </exception> |
| | 241 | | /// <exception cref="System.ArgumentNullException"> |
| | 242 | | /// Thrown when a required parameter is null |
| | 243 | | /// </exception> |
| | 244 | | /// <return> |
| | 245 | | /// A response object containing the response body and response headers. |
| | 246 | | /// </return> |
| | 247 | | public async Task<HttpOperationResponse<OCR>> OCRMethodWithHttpMessagesAsync(string language, bool? cacheImage = |
| | 248 | | { |
| 0 | 249 | | if (Client.Endpoint == null) |
| | 250 | | { |
| 0 | 251 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 252 | | } |
| 0 | 253 | | if (language == null) |
| | 254 | | { |
| 0 | 255 | | throw new ValidationException(ValidationRules.CannotBeNull, "language"); |
| | 256 | | } |
| | 257 | | // Tracing |
| 0 | 258 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 259 | | string _invocationId = null; |
| 0 | 260 | | if (_shouldTrace) |
| | 261 | | { |
| 0 | 262 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 263 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 264 | | tracingParameters.Add("language", language); |
| 0 | 265 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 266 | | tracingParameters.Add("enhanced", enhanced); |
| 0 | 267 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 268 | | ServiceClientTracing.Enter(_invocationId, this, "OCRMethod", tracingParameters); |
| | 269 | | } |
| | 270 | | // Construct URL |
| 0 | 271 | | var _baseUrl = Client.BaseUri; |
| 0 | 272 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/OCR |
| 0 | 273 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 274 | | List<string> _queryParameters = new List<string>(); |
| 0 | 275 | | if (language != null) |
| | 276 | | { |
| 0 | 277 | | _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language))); |
| | 278 | | } |
| 0 | 279 | | if (cacheImage != null) |
| | 280 | | { |
| 0 | 281 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 282 | | } |
| 0 | 283 | | if (enhanced != null) |
| | 284 | | { |
| 0 | 285 | | _queryParameters.Add(string.Format("enhanced={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJs |
| | 286 | | } |
| 0 | 287 | | if (_queryParameters.Count > 0) |
| | 288 | | { |
| 0 | 289 | | _url += "?" + string.Join("&", _queryParameters); |
| | 290 | | } |
| | 291 | | // Create HTTP transport objects |
| 0 | 292 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 293 | | HttpResponseMessage _httpResponse = null; |
| 0 | 294 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 295 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 296 | | // Set Headers |
| | 297 | |
|
| | 298 | |
|
| 0 | 299 | | if (customHeaders != null) |
| | 300 | | { |
| 0 | 301 | | foreach(var _header in customHeaders) |
| | 302 | | { |
| 0 | 303 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 304 | | { |
| 0 | 305 | | _httpRequest.Headers.Remove(_header.Key); |
| | 306 | | } |
| 0 | 307 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 308 | | } |
| | 309 | | } |
| | 310 | |
|
| | 311 | | // Serialize Request |
| 0 | 312 | | string _requestContent = null; |
| | 313 | | // Set Credentials |
| 0 | 314 | | if (Client.Credentials != null) |
| | 315 | | { |
| 0 | 316 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 317 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 318 | | } |
| | 319 | | // Send Request |
| 0 | 320 | | if (_shouldTrace) |
| | 321 | | { |
| 0 | 322 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 323 | | } |
| 0 | 324 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 325 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 326 | | if (_shouldTrace) |
| | 327 | | { |
| 0 | 328 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 329 | | } |
| 0 | 330 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 331 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 332 | | string _responseContent = null; |
| 0 | 333 | | if ((int)_statusCode != 200) |
| | 334 | | { |
| 0 | 335 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 336 | | try |
| | 337 | | { |
| 0 | 338 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 339 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 340 | | if (_errorBody != null) |
| | 341 | | { |
| 0 | 342 | | ex.Body = _errorBody; |
| | 343 | | } |
| 0 | 344 | | } |
| 0 | 345 | | catch (JsonException) |
| | 346 | | { |
| | 347 | | // Ignore the exception |
| 0 | 348 | | } |
| 0 | 349 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 350 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 351 | | if (_shouldTrace) |
| | 352 | | { |
| 0 | 353 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 354 | | } |
| 0 | 355 | | _httpRequest.Dispose(); |
| 0 | 356 | | if (_httpResponse != null) |
| | 357 | | { |
| 0 | 358 | | _httpResponse.Dispose(); |
| | 359 | | } |
| 0 | 360 | | throw ex; |
| | 361 | | } |
| | 362 | | // Create Result |
| 0 | 363 | | var _result = new HttpOperationResponse<OCR>(); |
| 0 | 364 | | _result.Request = _httpRequest; |
| 0 | 365 | | _result.Response = _httpResponse; |
| | 366 | | // Deserialize Response |
| 0 | 367 | | if ((int)_statusCode == 200) |
| | 368 | | { |
| 0 | 369 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 370 | | try |
| | 371 | | { |
| 0 | 372 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OCR>(_responseContent, Client.De |
| 0 | 373 | | } |
| 0 | 374 | | catch (JsonException ex) |
| | 375 | | { |
| 0 | 376 | | _httpRequest.Dispose(); |
| 0 | 377 | | if (_httpResponse != null) |
| | 378 | | { |
| 0 | 379 | | _httpResponse.Dispose(); |
| | 380 | | } |
| 0 | 381 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 382 | | } |
| | 383 | | } |
| 0 | 384 | | if (_shouldTrace) |
| | 385 | | { |
| 0 | 386 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 387 | | } |
| 0 | 388 | | return _result; |
| 0 | 389 | | } |
| | 390 | |
|
| | 391 | | /// <summary> |
| | 392 | | /// Returns probabilities of the image containing racy or adult content. |
| | 393 | | /// </summary> |
| | 394 | | /// <param name='cacheImage'> |
| | 395 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 396 | | /// omitted. |
| | 397 | | /// </param> |
| | 398 | | /// <param name='customHeaders'> |
| | 399 | | /// Headers that will be added to request. |
| | 400 | | /// </param> |
| | 401 | | /// <param name='cancellationToken'> |
| | 402 | | /// The cancellation token. |
| | 403 | | /// </param> |
| | 404 | | /// <exception cref="APIErrorException"> |
| | 405 | | /// Thrown when the operation returned an invalid status code |
| | 406 | | /// </exception> |
| | 407 | | /// <exception cref="SerializationException"> |
| | 408 | | /// Thrown when unable to deserialize the response |
| | 409 | | /// </exception> |
| | 410 | | /// <exception cref="ValidationException"> |
| | 411 | | /// Thrown when a required parameter is null |
| | 412 | | /// </exception> |
| | 413 | | /// <exception cref="System.ArgumentNullException"> |
| | 414 | | /// Thrown when a required parameter is null |
| | 415 | | /// </exception> |
| | 416 | | /// <return> |
| | 417 | | /// A response object containing the response body and response headers. |
| | 418 | | /// </return> |
| | 419 | | public async Task<HttpOperationResponse<Evaluate>> EvaluateMethodWithHttpMessagesAsync(bool? cacheImage = defaul |
| | 420 | | { |
| 0 | 421 | | if (Client.Endpoint == null) |
| | 422 | | { |
| 0 | 423 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 424 | | } |
| | 425 | | // Tracing |
| 0 | 426 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 427 | | string _invocationId = null; |
| 0 | 428 | | if (_shouldTrace) |
| | 429 | | { |
| 0 | 430 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 431 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 432 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 433 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 434 | | ServiceClientTracing.Enter(_invocationId, this, "EvaluateMethod", tracingParameters); |
| | 435 | | } |
| | 436 | | // Construct URL |
| 0 | 437 | | var _baseUrl = Client.BaseUri; |
| 0 | 438 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Eva |
| 0 | 439 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 440 | | List<string> _queryParameters = new List<string>(); |
| 0 | 441 | | if (cacheImage != null) |
| | 442 | | { |
| 0 | 443 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 444 | | } |
| 0 | 445 | | if (_queryParameters.Count > 0) |
| | 446 | | { |
| 0 | 447 | | _url += "?" + string.Join("&", _queryParameters); |
| | 448 | | } |
| | 449 | | // Create HTTP transport objects |
| 0 | 450 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 451 | | HttpResponseMessage _httpResponse = null; |
| 0 | 452 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 453 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 454 | | // Set Headers |
| | 455 | |
|
| | 456 | |
|
| 0 | 457 | | if (customHeaders != null) |
| | 458 | | { |
| 0 | 459 | | foreach(var _header in customHeaders) |
| | 460 | | { |
| 0 | 461 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 462 | | { |
| 0 | 463 | | _httpRequest.Headers.Remove(_header.Key); |
| | 464 | | } |
| 0 | 465 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 466 | | } |
| | 467 | | } |
| | 468 | |
|
| | 469 | | // Serialize Request |
| 0 | 470 | | string _requestContent = null; |
| | 471 | | // Set Credentials |
| 0 | 472 | | if (Client.Credentials != null) |
| | 473 | | { |
| 0 | 474 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 475 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 476 | | } |
| | 477 | | // Send Request |
| 0 | 478 | | if (_shouldTrace) |
| | 479 | | { |
| 0 | 480 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 481 | | } |
| 0 | 482 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 483 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 484 | | if (_shouldTrace) |
| | 485 | | { |
| 0 | 486 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 487 | | } |
| 0 | 488 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 489 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 490 | | string _responseContent = null; |
| 0 | 491 | | if ((int)_statusCode != 200) |
| | 492 | | { |
| 0 | 493 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 494 | | try |
| | 495 | | { |
| 0 | 496 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 497 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 498 | | if (_errorBody != null) |
| | 499 | | { |
| 0 | 500 | | ex.Body = _errorBody; |
| | 501 | | } |
| 0 | 502 | | } |
| 0 | 503 | | catch (JsonException) |
| | 504 | | { |
| | 505 | | // Ignore the exception |
| 0 | 506 | | } |
| 0 | 507 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 508 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 509 | | if (_shouldTrace) |
| | 510 | | { |
| 0 | 511 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 512 | | } |
| 0 | 513 | | _httpRequest.Dispose(); |
| 0 | 514 | | if (_httpResponse != null) |
| | 515 | | { |
| 0 | 516 | | _httpResponse.Dispose(); |
| | 517 | | } |
| 0 | 518 | | throw ex; |
| | 519 | | } |
| | 520 | | // Create Result |
| 0 | 521 | | var _result = new HttpOperationResponse<Evaluate>(); |
| 0 | 522 | | _result.Request = _httpRequest; |
| 0 | 523 | | _result.Response = _httpResponse; |
| | 524 | | // Deserialize Response |
| 0 | 525 | | if ((int)_statusCode == 200) |
| | 526 | | { |
| 0 | 527 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 528 | | try |
| | 529 | | { |
| 0 | 530 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Evaluate>(_responseContent, Clie |
| 0 | 531 | | } |
| 0 | 532 | | catch (JsonException ex) |
| | 533 | | { |
| 0 | 534 | | _httpRequest.Dispose(); |
| 0 | 535 | | if (_httpResponse != null) |
| | 536 | | { |
| 0 | 537 | | _httpResponse.Dispose(); |
| | 538 | | } |
| 0 | 539 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 540 | | } |
| | 541 | | } |
| 0 | 542 | | if (_shouldTrace) |
| | 543 | | { |
| 0 | 544 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 545 | | } |
| 0 | 546 | | return _result; |
| 0 | 547 | | } |
| | 548 | |
|
| | 549 | | /// <summary> |
| | 550 | | /// Fuzzily match an image against one of your custom Image Lists. You can |
| | 551 | | /// create and manage your custom image lists using <a |
| | 552 | | /// href="/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe">this</a> |
| | 553 | | /// API. |
| | 554 | | /// |
| | 555 | | /// Returns ID and tags of matching image.<br/> |
| | 556 | | /// <br/> |
| | 557 | | /// Note: Refresh Index must be run on the corresponding Image List before |
| | 558 | | /// additions and removals are reflected in the response. |
| | 559 | | /// </summary> |
| | 560 | | /// <param name='listId'> |
| | 561 | | /// The list Id. |
| | 562 | | /// </param> |
| | 563 | | /// <param name='cacheImage'> |
| | 564 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 565 | | /// omitted. |
| | 566 | | /// </param> |
| | 567 | | /// <param name='customHeaders'> |
| | 568 | | /// Headers that will be added to request. |
| | 569 | | /// </param> |
| | 570 | | /// <param name='cancellationToken'> |
| | 571 | | /// The cancellation token. |
| | 572 | | /// </param> |
| | 573 | | /// <exception cref="APIErrorException"> |
| | 574 | | /// Thrown when the operation returned an invalid status code |
| | 575 | | /// </exception> |
| | 576 | | /// <exception cref="SerializationException"> |
| | 577 | | /// Thrown when unable to deserialize the response |
| | 578 | | /// </exception> |
| | 579 | | /// <exception cref="ValidationException"> |
| | 580 | | /// Thrown when a required parameter is null |
| | 581 | | /// </exception> |
| | 582 | | /// <exception cref="System.ArgumentNullException"> |
| | 583 | | /// Thrown when a required parameter is null |
| | 584 | | /// </exception> |
| | 585 | | /// <return> |
| | 586 | | /// A response object containing the response body and response headers. |
| | 587 | | /// </return> |
| | 588 | | public async Task<HttpOperationResponse<MatchResponse>> MatchMethodWithHttpMessagesAsync(string listId = default |
| | 589 | | { |
| 0 | 590 | | if (Client.Endpoint == null) |
| | 591 | | { |
| 0 | 592 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 593 | | } |
| | 594 | | // Tracing |
| 0 | 595 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 596 | | string _invocationId = null; |
| 0 | 597 | | if (_shouldTrace) |
| | 598 | | { |
| 0 | 599 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 600 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 601 | | tracingParameters.Add("listId", listId); |
| 0 | 602 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 603 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 604 | | ServiceClientTracing.Enter(_invocationId, this, "MatchMethod", tracingParameters); |
| | 605 | | } |
| | 606 | | // Construct URL |
| 0 | 607 | | var _baseUrl = Client.BaseUri; |
| 0 | 608 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Mat |
| 0 | 609 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 610 | | List<string> _queryParameters = new List<string>(); |
| 0 | 611 | | if (listId != null) |
| | 612 | | { |
| 0 | 613 | | _queryParameters.Add(string.Format("listId={0}", System.Uri.EscapeDataString(listId))); |
| | 614 | | } |
| 0 | 615 | | if (cacheImage != null) |
| | 616 | | { |
| 0 | 617 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 618 | | } |
| 0 | 619 | | if (_queryParameters.Count > 0) |
| | 620 | | { |
| 0 | 621 | | _url += "?" + string.Join("&", _queryParameters); |
| | 622 | | } |
| | 623 | | // Create HTTP transport objects |
| 0 | 624 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 625 | | HttpResponseMessage _httpResponse = null; |
| 0 | 626 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 627 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 628 | | // Set Headers |
| | 629 | |
|
| | 630 | |
|
| 0 | 631 | | if (customHeaders != null) |
| | 632 | | { |
| 0 | 633 | | foreach(var _header in customHeaders) |
| | 634 | | { |
| 0 | 635 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 636 | | { |
| 0 | 637 | | _httpRequest.Headers.Remove(_header.Key); |
| | 638 | | } |
| 0 | 639 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 640 | | } |
| | 641 | | } |
| | 642 | |
|
| | 643 | | // Serialize Request |
| 0 | 644 | | string _requestContent = null; |
| | 645 | | // Set Credentials |
| 0 | 646 | | if (Client.Credentials != null) |
| | 647 | | { |
| 0 | 648 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 649 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 650 | | } |
| | 651 | | // Send Request |
| 0 | 652 | | if (_shouldTrace) |
| | 653 | | { |
| 0 | 654 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 655 | | } |
| 0 | 656 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 657 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 658 | | if (_shouldTrace) |
| | 659 | | { |
| 0 | 660 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 661 | | } |
| 0 | 662 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 663 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 664 | | string _responseContent = null; |
| 0 | 665 | | if ((int)_statusCode != 200) |
| | 666 | | { |
| 0 | 667 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 668 | | try |
| | 669 | | { |
| 0 | 670 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 671 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 672 | | if (_errorBody != null) |
| | 673 | | { |
| 0 | 674 | | ex.Body = _errorBody; |
| | 675 | | } |
| 0 | 676 | | } |
| 0 | 677 | | catch (JsonException) |
| | 678 | | { |
| | 679 | | // Ignore the exception |
| 0 | 680 | | } |
| 0 | 681 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 682 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 683 | | if (_shouldTrace) |
| | 684 | | { |
| 0 | 685 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 686 | | } |
| 0 | 687 | | _httpRequest.Dispose(); |
| 0 | 688 | | if (_httpResponse != null) |
| | 689 | | { |
| 0 | 690 | | _httpResponse.Dispose(); |
| | 691 | | } |
| 0 | 692 | | throw ex; |
| | 693 | | } |
| | 694 | | // Create Result |
| 0 | 695 | | var _result = new HttpOperationResponse<MatchResponse>(); |
| 0 | 696 | | _result.Request = _httpRequest; |
| 0 | 697 | | _result.Response = _httpResponse; |
| | 698 | | // Deserialize Response |
| 0 | 699 | | if ((int)_statusCode == 200) |
| | 700 | | { |
| 0 | 701 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 702 | | try |
| | 703 | | { |
| 0 | 704 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<MatchResponse>(_responseContent, |
| 0 | 705 | | } |
| 0 | 706 | | catch (JsonException ex) |
| | 707 | | { |
| 0 | 708 | | _httpRequest.Dispose(); |
| 0 | 709 | | if (_httpResponse != null) |
| | 710 | | { |
| 0 | 711 | | _httpResponse.Dispose(); |
| | 712 | | } |
| 0 | 713 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 714 | | } |
| | 715 | | } |
| 0 | 716 | | if (_shouldTrace) |
| | 717 | | { |
| 0 | 718 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 719 | | } |
| 0 | 720 | | return _result; |
| 0 | 721 | | } |
| | 722 | |
|
| | 723 | | /// <summary> |
| | 724 | | /// Returns the list of faces found. |
| | 725 | | /// </summary> |
| | 726 | | /// <param name='imageStream'> |
| | 727 | | /// The image file. |
| | 728 | | /// </param> |
| | 729 | | /// <param name='cacheImage'> |
| | 730 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 731 | | /// omitted. |
| | 732 | | /// </param> |
| | 733 | | /// <param name='customHeaders'> |
| | 734 | | /// Headers that will be added to request. |
| | 735 | | /// </param> |
| | 736 | | /// <param name='cancellationToken'> |
| | 737 | | /// The cancellation token. |
| | 738 | | /// </param> |
| | 739 | | /// <exception cref="APIErrorException"> |
| | 740 | | /// Thrown when the operation returned an invalid status code |
| | 741 | | /// </exception> |
| | 742 | | /// <exception cref="SerializationException"> |
| | 743 | | /// Thrown when unable to deserialize the response |
| | 744 | | /// </exception> |
| | 745 | | /// <exception cref="ValidationException"> |
| | 746 | | /// Thrown when a required parameter is null |
| | 747 | | /// </exception> |
| | 748 | | /// <exception cref="System.ArgumentNullException"> |
| | 749 | | /// Thrown when a required parameter is null |
| | 750 | | /// </exception> |
| | 751 | | /// <return> |
| | 752 | | /// A response object containing the response body and response headers. |
| | 753 | | /// </return> |
| | 754 | | public async Task<HttpOperationResponse<FoundFaces>> FindFacesFileInputWithHttpMessagesAsync(Stream imageStream, |
| | 755 | | { |
| 0 | 756 | | if (Client.Endpoint == null) |
| | 757 | | { |
| 0 | 758 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 759 | | } |
| 0 | 760 | | if (imageStream == null) |
| | 761 | | { |
| 0 | 762 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageStream"); |
| | 763 | | } |
| | 764 | | // Tracing |
| 0 | 765 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 766 | | string _invocationId = null; |
| 0 | 767 | | if (_shouldTrace) |
| | 768 | | { |
| 0 | 769 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 770 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 771 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 772 | | tracingParameters.Add("imageStream", imageStream); |
| 0 | 773 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 774 | | ServiceClientTracing.Enter(_invocationId, this, "FindFacesFileInput", tracingParameters); |
| | 775 | | } |
| | 776 | | // Construct URL |
| 0 | 777 | | var _baseUrl = Client.BaseUri; |
| 0 | 778 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Fin |
| 0 | 779 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 780 | | List<string> _queryParameters = new List<string>(); |
| 0 | 781 | | if (cacheImage != null) |
| | 782 | | { |
| 0 | 783 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 784 | | } |
| 0 | 785 | | if (_queryParameters.Count > 0) |
| | 786 | | { |
| 0 | 787 | | _url += "?" + string.Join("&", _queryParameters); |
| | 788 | | } |
| | 789 | | // Create HTTP transport objects |
| 0 | 790 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 791 | | HttpResponseMessage _httpResponse = null; |
| 0 | 792 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 793 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 794 | | // Set Headers |
| | 795 | |
|
| | 796 | |
|
| 0 | 797 | | if (customHeaders != null) |
| | 798 | | { |
| 0 | 799 | | foreach(var _header in customHeaders) |
| | 800 | | { |
| 0 | 801 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 802 | | { |
| 0 | 803 | | _httpRequest.Headers.Remove(_header.Key); |
| | 804 | | } |
| 0 | 805 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 806 | | } |
| | 807 | | } |
| | 808 | |
|
| | 809 | | // Serialize Request |
| 0 | 810 | | string _requestContent = null; |
| 0 | 811 | | if(imageStream == null) |
| | 812 | | { |
| 0 | 813 | | throw new System.ArgumentNullException("imageStream"); |
| | 814 | | } |
| 0 | 815 | | if (imageStream != null && imageStream != Stream.Null) |
| | 816 | | { |
| 0 | 817 | | _httpRequest.Content = new StreamContent(imageStream); |
| 0 | 818 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("image/gif" |
| | 819 | | } |
| | 820 | | // Set Credentials |
| 0 | 821 | | if (Client.Credentials != null) |
| | 822 | | { |
| 0 | 823 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 824 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 825 | | } |
| | 826 | | // Send Request |
| 0 | 827 | | if (_shouldTrace) |
| | 828 | | { |
| 0 | 829 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 830 | | } |
| 0 | 831 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 832 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 833 | | if (_shouldTrace) |
| | 834 | | { |
| 0 | 835 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 836 | | } |
| 0 | 837 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 838 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 839 | | string _responseContent = null; |
| 0 | 840 | | if ((int)_statusCode != 200) |
| | 841 | | { |
| 0 | 842 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 843 | | try |
| | 844 | | { |
| 0 | 845 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 846 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 847 | | if (_errorBody != null) |
| | 848 | | { |
| 0 | 849 | | ex.Body = _errorBody; |
| | 850 | | } |
| 0 | 851 | | } |
| 0 | 852 | | catch (JsonException) |
| | 853 | | { |
| | 854 | | // Ignore the exception |
| 0 | 855 | | } |
| 0 | 856 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 857 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 858 | | if (_shouldTrace) |
| | 859 | | { |
| 0 | 860 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 861 | | } |
| 0 | 862 | | _httpRequest.Dispose(); |
| 0 | 863 | | if (_httpResponse != null) |
| | 864 | | { |
| 0 | 865 | | _httpResponse.Dispose(); |
| | 866 | | } |
| 0 | 867 | | throw ex; |
| | 868 | | } |
| | 869 | | // Create Result |
| 0 | 870 | | var _result = new HttpOperationResponse<FoundFaces>(); |
| 0 | 871 | | _result.Request = _httpRequest; |
| 0 | 872 | | _result.Response = _httpResponse; |
| | 873 | | // Deserialize Response |
| 0 | 874 | | if ((int)_statusCode == 200) |
| | 875 | | { |
| 0 | 876 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 877 | | try |
| | 878 | | { |
| 0 | 879 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<FoundFaces>(_responseContent, Cl |
| 0 | 880 | | } |
| 0 | 881 | | catch (JsonException ex) |
| | 882 | | { |
| 0 | 883 | | _httpRequest.Dispose(); |
| 0 | 884 | | if (_httpResponse != null) |
| | 885 | | { |
| 0 | 886 | | _httpResponse.Dispose(); |
| | 887 | | } |
| 0 | 888 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 889 | | } |
| | 890 | | } |
| 0 | 891 | | if (_shouldTrace) |
| | 892 | | { |
| 0 | 893 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 894 | | } |
| 0 | 895 | | return _result; |
| 0 | 896 | | } |
| | 897 | |
|
| | 898 | | /// <summary> |
| | 899 | | /// Returns the list of faces found. |
| | 900 | | /// </summary> |
| | 901 | | /// <param name='contentType'> |
| | 902 | | /// The content type. |
| | 903 | | /// </param> |
| | 904 | | /// <param name='imageUrl'> |
| | 905 | | /// The image url. |
| | 906 | | /// </param> |
| | 907 | | /// <param name='cacheImage'> |
| | 908 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 909 | | /// omitted. |
| | 910 | | /// </param> |
| | 911 | | /// <param name='customHeaders'> |
| | 912 | | /// Headers that will be added to request. |
| | 913 | | /// </param> |
| | 914 | | /// <param name='cancellationToken'> |
| | 915 | | /// The cancellation token. |
| | 916 | | /// </param> |
| | 917 | | /// <exception cref="APIErrorException"> |
| | 918 | | /// Thrown when the operation returned an invalid status code |
| | 919 | | /// </exception> |
| | 920 | | /// <exception cref="SerializationException"> |
| | 921 | | /// Thrown when unable to deserialize the response |
| | 922 | | /// </exception> |
| | 923 | | /// <exception cref="ValidationException"> |
| | 924 | | /// Thrown when a required parameter is null |
| | 925 | | /// </exception> |
| | 926 | | /// <exception cref="System.ArgumentNullException"> |
| | 927 | | /// Thrown when a required parameter is null |
| | 928 | | /// </exception> |
| | 929 | | /// <return> |
| | 930 | | /// A response object containing the response body and response headers. |
| | 931 | | /// </return> |
| | 932 | | public async Task<HttpOperationResponse<FoundFaces>> FindFacesUrlInputWithHttpMessagesAsync(string contentType, |
| | 933 | | { |
| 0 | 934 | | if (Client.Endpoint == null) |
| | 935 | | { |
| 0 | 936 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 937 | | } |
| 0 | 938 | | if (contentType == null) |
| | 939 | | { |
| 0 | 940 | | throw new ValidationException(ValidationRules.CannotBeNull, "contentType"); |
| | 941 | | } |
| 0 | 942 | | if (imageUrl == null) |
| | 943 | | { |
| 0 | 944 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl"); |
| | 945 | | } |
| | 946 | | // Tracing |
| 0 | 947 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 948 | | string _invocationId = null; |
| 0 | 949 | | if (_shouldTrace) |
| | 950 | | { |
| 0 | 951 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 952 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 953 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 954 | | tracingParameters.Add("contentType", contentType); |
| 0 | 955 | | tracingParameters.Add("imageUrl", imageUrl); |
| 0 | 956 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 957 | | ServiceClientTracing.Enter(_invocationId, this, "FindFacesUrlInput", tracingParameters); |
| | 958 | | } |
| | 959 | | // Construct URL |
| 0 | 960 | | var _baseUrl = Client.BaseUri; |
| 0 | 961 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Fin |
| 0 | 962 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 963 | | List<string> _queryParameters = new List<string>(); |
| 0 | 964 | | if (cacheImage != null) |
| | 965 | | { |
| 0 | 966 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 967 | | } |
| 0 | 968 | | if (_queryParameters.Count > 0) |
| | 969 | | { |
| 0 | 970 | | _url += "?" + string.Join("&", _queryParameters); |
| | 971 | | } |
| | 972 | | // Create HTTP transport objects |
| 0 | 973 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 974 | | HttpResponseMessage _httpResponse = null; |
| 0 | 975 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 976 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 977 | | // Set Headers |
| | 978 | |
|
| | 979 | |
|
| 0 | 980 | | if (customHeaders != null) |
| | 981 | | { |
| 0 | 982 | | foreach(var _header in customHeaders) |
| | 983 | | { |
| 0 | 984 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 985 | | { |
| 0 | 986 | | _httpRequest.Headers.Remove(_header.Key); |
| | 987 | | } |
| 0 | 988 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 989 | | } |
| | 990 | | } |
| | 991 | |
|
| | 992 | | // Serialize Request |
| 0 | 993 | | string _requestContent = null; |
| 0 | 994 | | if(imageUrl != null) |
| | 995 | | { |
| 0 | 996 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti |
| 0 | 997 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 998 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 999 | | } |
| | 1000 | | // Set Credentials |
| 0 | 1001 | | if (Client.Credentials != null) |
| | 1002 | | { |
| 0 | 1003 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1004 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1005 | | } |
| | 1006 | | // Send Request |
| 0 | 1007 | | if (_shouldTrace) |
| | 1008 | | { |
| 0 | 1009 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1010 | | } |
| 0 | 1011 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1012 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1013 | | if (_shouldTrace) |
| | 1014 | | { |
| 0 | 1015 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1016 | | } |
| 0 | 1017 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1018 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1019 | | string _responseContent = null; |
| 0 | 1020 | | if ((int)_statusCode != 200) |
| | 1021 | | { |
| 0 | 1022 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1023 | | try |
| | 1024 | | { |
| 0 | 1025 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1026 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1027 | | if (_errorBody != null) |
| | 1028 | | { |
| 0 | 1029 | | ex.Body = _errorBody; |
| | 1030 | | } |
| 0 | 1031 | | } |
| 0 | 1032 | | catch (JsonException) |
| | 1033 | | { |
| | 1034 | | // Ignore the exception |
| 0 | 1035 | | } |
| 0 | 1036 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1037 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1038 | | if (_shouldTrace) |
| | 1039 | | { |
| 0 | 1040 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1041 | | } |
| 0 | 1042 | | _httpRequest.Dispose(); |
| 0 | 1043 | | if (_httpResponse != null) |
| | 1044 | | { |
| 0 | 1045 | | _httpResponse.Dispose(); |
| | 1046 | | } |
| 0 | 1047 | | throw ex; |
| | 1048 | | } |
| | 1049 | | // Create Result |
| 0 | 1050 | | var _result = new HttpOperationResponse<FoundFaces>(); |
| 0 | 1051 | | _result.Request = _httpRequest; |
| 0 | 1052 | | _result.Response = _httpResponse; |
| | 1053 | | // Deserialize Response |
| 0 | 1054 | | if ((int)_statusCode == 200) |
| | 1055 | | { |
| 0 | 1056 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1057 | | try |
| | 1058 | | { |
| 0 | 1059 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<FoundFaces>(_responseContent, Cl |
| 0 | 1060 | | } |
| 0 | 1061 | | catch (JsonException ex) |
| | 1062 | | { |
| 0 | 1063 | | _httpRequest.Dispose(); |
| 0 | 1064 | | if (_httpResponse != null) |
| | 1065 | | { |
| 0 | 1066 | | _httpResponse.Dispose(); |
| | 1067 | | } |
| 0 | 1068 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1069 | | } |
| | 1070 | | } |
| 0 | 1071 | | if (_shouldTrace) |
| | 1072 | | { |
| 0 | 1073 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1074 | | } |
| 0 | 1075 | | return _result; |
| 0 | 1076 | | } |
| | 1077 | |
|
| | 1078 | | /// <summary> |
| | 1079 | | /// Returns any text found in the image for the language specified. If no |
| | 1080 | | /// language is specified in input then the detection defaults to English. |
| | 1081 | | /// </summary> |
| | 1082 | | /// <param name='language'> |
| | 1083 | | /// Language of the terms. |
| | 1084 | | /// </param> |
| | 1085 | | /// <param name='contentType'> |
| | 1086 | | /// The content type. |
| | 1087 | | /// </param> |
| | 1088 | | /// <param name='imageUrl'> |
| | 1089 | | /// The image url. |
| | 1090 | | /// </param> |
| | 1091 | | /// <param name='cacheImage'> |
| | 1092 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 1093 | | /// omitted. |
| | 1094 | | /// </param> |
| | 1095 | | /// <param name='enhanced'> |
| | 1096 | | /// When set to True, the image goes through additional processing to come with |
| | 1097 | | /// additional candidates. |
| | 1098 | | /// |
| | 1099 | | /// image/tiff is not supported when enhanced is set to true |
| | 1100 | | /// |
| | 1101 | | /// Note: This impacts the response time. |
| | 1102 | | /// </param> |
| | 1103 | | /// <param name='customHeaders'> |
| | 1104 | | /// Headers that will be added to request. |
| | 1105 | | /// </param> |
| | 1106 | | /// <param name='cancellationToken'> |
| | 1107 | | /// The cancellation token. |
| | 1108 | | /// </param> |
| | 1109 | | /// <exception cref="APIErrorException"> |
| | 1110 | | /// Thrown when the operation returned an invalid status code |
| | 1111 | | /// </exception> |
| | 1112 | | /// <exception cref="SerializationException"> |
| | 1113 | | /// Thrown when unable to deserialize the response |
| | 1114 | | /// </exception> |
| | 1115 | | /// <exception cref="ValidationException"> |
| | 1116 | | /// Thrown when a required parameter is null |
| | 1117 | | /// </exception> |
| | 1118 | | /// <exception cref="System.ArgumentNullException"> |
| | 1119 | | /// Thrown when a required parameter is null |
| | 1120 | | /// </exception> |
| | 1121 | | /// <return> |
| | 1122 | | /// A response object containing the response body and response headers. |
| | 1123 | | /// </return> |
| | 1124 | | public async Task<HttpOperationResponse<OCR>> OCRUrlInputWithHttpMessagesAsync(string language, string contentTy |
| | 1125 | | { |
| 0 | 1126 | | if (Client.Endpoint == null) |
| | 1127 | | { |
| 0 | 1128 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1129 | | } |
| 0 | 1130 | | if (language == null) |
| | 1131 | | { |
| 0 | 1132 | | throw new ValidationException(ValidationRules.CannotBeNull, "language"); |
| | 1133 | | } |
| 0 | 1134 | | if (contentType == null) |
| | 1135 | | { |
| 0 | 1136 | | throw new ValidationException(ValidationRules.CannotBeNull, "contentType"); |
| | 1137 | | } |
| 0 | 1138 | | if (imageUrl == null) |
| | 1139 | | { |
| 0 | 1140 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl"); |
| | 1141 | | } |
| | 1142 | | // Tracing |
| 0 | 1143 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1144 | | string _invocationId = null; |
| 0 | 1145 | | if (_shouldTrace) |
| | 1146 | | { |
| 0 | 1147 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1148 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1149 | | tracingParameters.Add("language", language); |
| 0 | 1150 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 1151 | | tracingParameters.Add("enhanced", enhanced); |
| 0 | 1152 | | tracingParameters.Add("contentType", contentType); |
| 0 | 1153 | | tracingParameters.Add("imageUrl", imageUrl); |
| 0 | 1154 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1155 | | ServiceClientTracing.Enter(_invocationId, this, "OCRUrlInput", tracingParameters); |
| | 1156 | | } |
| | 1157 | | // Construct URL |
| 0 | 1158 | | var _baseUrl = Client.BaseUri; |
| 0 | 1159 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/OCR |
| 0 | 1160 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1161 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1162 | | if (language != null) |
| | 1163 | | { |
| 0 | 1164 | | _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language))); |
| | 1165 | | } |
| 0 | 1166 | | if (cacheImage != null) |
| | 1167 | | { |
| 0 | 1168 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 1169 | | } |
| 0 | 1170 | | if (enhanced != null) |
| | 1171 | | { |
| 0 | 1172 | | _queryParameters.Add(string.Format("enhanced={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJs |
| | 1173 | | } |
| 0 | 1174 | | if (_queryParameters.Count > 0) |
| | 1175 | | { |
| 0 | 1176 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1177 | | } |
| | 1178 | | // Create HTTP transport objects |
| 0 | 1179 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1180 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1181 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1182 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1183 | | // Set Headers |
| | 1184 | |
|
| | 1185 | |
|
| 0 | 1186 | | if (customHeaders != null) |
| | 1187 | | { |
| 0 | 1188 | | foreach(var _header in customHeaders) |
| | 1189 | | { |
| 0 | 1190 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1191 | | { |
| 0 | 1192 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1193 | | } |
| 0 | 1194 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1195 | | } |
| | 1196 | | } |
| | 1197 | |
|
| | 1198 | | // Serialize Request |
| 0 | 1199 | | string _requestContent = null; |
| 0 | 1200 | | if(imageUrl != null) |
| | 1201 | | { |
| 0 | 1202 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti |
| 0 | 1203 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1204 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1205 | | } |
| | 1206 | | // Set Credentials |
| 0 | 1207 | | if (Client.Credentials != null) |
| | 1208 | | { |
| 0 | 1209 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1210 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1211 | | } |
| | 1212 | | // Send Request |
| 0 | 1213 | | if (_shouldTrace) |
| | 1214 | | { |
| 0 | 1215 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1216 | | } |
| 0 | 1217 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1218 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1219 | | if (_shouldTrace) |
| | 1220 | | { |
| 0 | 1221 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1222 | | } |
| 0 | 1223 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1224 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1225 | | string _responseContent = null; |
| 0 | 1226 | | if ((int)_statusCode != 200) |
| | 1227 | | { |
| 0 | 1228 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1229 | | try |
| | 1230 | | { |
| 0 | 1231 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1232 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1233 | | if (_errorBody != null) |
| | 1234 | | { |
| 0 | 1235 | | ex.Body = _errorBody; |
| | 1236 | | } |
| 0 | 1237 | | } |
| 0 | 1238 | | catch (JsonException) |
| | 1239 | | { |
| | 1240 | | // Ignore the exception |
| 0 | 1241 | | } |
| 0 | 1242 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1243 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1244 | | if (_shouldTrace) |
| | 1245 | | { |
| 0 | 1246 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1247 | | } |
| 0 | 1248 | | _httpRequest.Dispose(); |
| 0 | 1249 | | if (_httpResponse != null) |
| | 1250 | | { |
| 0 | 1251 | | _httpResponse.Dispose(); |
| | 1252 | | } |
| 0 | 1253 | | throw ex; |
| | 1254 | | } |
| | 1255 | | // Create Result |
| 0 | 1256 | | var _result = new HttpOperationResponse<OCR>(); |
| 0 | 1257 | | _result.Request = _httpRequest; |
| 0 | 1258 | | _result.Response = _httpResponse; |
| | 1259 | | // Deserialize Response |
| 0 | 1260 | | if ((int)_statusCode == 200) |
| | 1261 | | { |
| 0 | 1262 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1263 | | try |
| | 1264 | | { |
| 0 | 1265 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OCR>(_responseContent, Client.De |
| 0 | 1266 | | } |
| 0 | 1267 | | catch (JsonException ex) |
| | 1268 | | { |
| 0 | 1269 | | _httpRequest.Dispose(); |
| 0 | 1270 | | if (_httpResponse != null) |
| | 1271 | | { |
| 0 | 1272 | | _httpResponse.Dispose(); |
| | 1273 | | } |
| 0 | 1274 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1275 | | } |
| | 1276 | | } |
| 0 | 1277 | | if (_shouldTrace) |
| | 1278 | | { |
| 0 | 1279 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1280 | | } |
| 0 | 1281 | | return _result; |
| 0 | 1282 | | } |
| | 1283 | |
|
| | 1284 | | /// <summary> |
| | 1285 | | /// Returns any text found in the image for the language specified. If no |
| | 1286 | | /// language is specified in input then the detection defaults to English. |
| | 1287 | | /// </summary> |
| | 1288 | | /// <param name='language'> |
| | 1289 | | /// Language of the terms. |
| | 1290 | | /// </param> |
| | 1291 | | /// <param name='imageStream'> |
| | 1292 | | /// The image file. |
| | 1293 | | /// </param> |
| | 1294 | | /// <param name='cacheImage'> |
| | 1295 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 1296 | | /// omitted. |
| | 1297 | | /// </param> |
| | 1298 | | /// <param name='enhanced'> |
| | 1299 | | /// When set to True, the image goes through additional processing to come with |
| | 1300 | | /// additional candidates. |
| | 1301 | | /// |
| | 1302 | | /// image/tiff is not supported when enhanced is set to true |
| | 1303 | | /// |
| | 1304 | | /// Note: This impacts the response time. |
| | 1305 | | /// </param> |
| | 1306 | | /// <param name='customHeaders'> |
| | 1307 | | /// Headers that will be added to request. |
| | 1308 | | /// </param> |
| | 1309 | | /// <param name='cancellationToken'> |
| | 1310 | | /// The cancellation token. |
| | 1311 | | /// </param> |
| | 1312 | | /// <exception cref="APIErrorException"> |
| | 1313 | | /// Thrown when the operation returned an invalid status code |
| | 1314 | | /// </exception> |
| | 1315 | | /// <exception cref="SerializationException"> |
| | 1316 | | /// Thrown when unable to deserialize the response |
| | 1317 | | /// </exception> |
| | 1318 | | /// <exception cref="ValidationException"> |
| | 1319 | | /// Thrown when a required parameter is null |
| | 1320 | | /// </exception> |
| | 1321 | | /// <exception cref="System.ArgumentNullException"> |
| | 1322 | | /// Thrown when a required parameter is null |
| | 1323 | | /// </exception> |
| | 1324 | | /// <return> |
| | 1325 | | /// A response object containing the response body and response headers. |
| | 1326 | | /// </return> |
| | 1327 | | public async Task<HttpOperationResponse<OCR>> OCRFileInputWithHttpMessagesAsync(string language, Stream imageStr |
| | 1328 | | { |
| 0 | 1329 | | if (Client.Endpoint == null) |
| | 1330 | | { |
| 0 | 1331 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1332 | | } |
| 0 | 1333 | | if (language == null) |
| | 1334 | | { |
| 0 | 1335 | | throw new ValidationException(ValidationRules.CannotBeNull, "language"); |
| | 1336 | | } |
| 0 | 1337 | | if (imageStream == null) |
| | 1338 | | { |
| 0 | 1339 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageStream"); |
| | 1340 | | } |
| | 1341 | | // Tracing |
| 0 | 1342 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1343 | | string _invocationId = null; |
| 0 | 1344 | | if (_shouldTrace) |
| | 1345 | | { |
| 0 | 1346 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1347 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1348 | | tracingParameters.Add("language", language); |
| 0 | 1349 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 1350 | | tracingParameters.Add("enhanced", enhanced); |
| 0 | 1351 | | tracingParameters.Add("imageStream", imageStream); |
| 0 | 1352 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1353 | | ServiceClientTracing.Enter(_invocationId, this, "OCRFileInput", tracingParameters); |
| | 1354 | | } |
| | 1355 | | // Construct URL |
| 0 | 1356 | | var _baseUrl = Client.BaseUri; |
| 0 | 1357 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/OCR |
| 0 | 1358 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1359 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1360 | | if (language != null) |
| | 1361 | | { |
| 0 | 1362 | | _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language))); |
| | 1363 | | } |
| 0 | 1364 | | if (cacheImage != null) |
| | 1365 | | { |
| 0 | 1366 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 1367 | | } |
| 0 | 1368 | | if (enhanced != null) |
| | 1369 | | { |
| 0 | 1370 | | _queryParameters.Add(string.Format("enhanced={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJs |
| | 1371 | | } |
| 0 | 1372 | | if (_queryParameters.Count > 0) |
| | 1373 | | { |
| 0 | 1374 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1375 | | } |
| | 1376 | | // Create HTTP transport objects |
| 0 | 1377 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1378 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1379 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1380 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1381 | | // Set Headers |
| | 1382 | |
|
| | 1383 | |
|
| 0 | 1384 | | if (customHeaders != null) |
| | 1385 | | { |
| 0 | 1386 | | foreach(var _header in customHeaders) |
| | 1387 | | { |
| 0 | 1388 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1389 | | { |
| 0 | 1390 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1391 | | } |
| 0 | 1392 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1393 | | } |
| | 1394 | | } |
| | 1395 | |
|
| | 1396 | | // Serialize Request |
| 0 | 1397 | | string _requestContent = null; |
| 0 | 1398 | | if(imageStream == null) |
| | 1399 | | { |
| 0 | 1400 | | throw new System.ArgumentNullException("imageStream"); |
| | 1401 | | } |
| 0 | 1402 | | if (imageStream != null && imageStream != Stream.Null) |
| | 1403 | | { |
| 0 | 1404 | | _httpRequest.Content = new StreamContent(imageStream); |
| 0 | 1405 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("image/gif" |
| | 1406 | | } |
| | 1407 | | // Set Credentials |
| 0 | 1408 | | if (Client.Credentials != null) |
| | 1409 | | { |
| 0 | 1410 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1411 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1412 | | } |
| | 1413 | | // Send Request |
| 0 | 1414 | | if (_shouldTrace) |
| | 1415 | | { |
| 0 | 1416 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1417 | | } |
| 0 | 1418 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1419 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1420 | | if (_shouldTrace) |
| | 1421 | | { |
| 0 | 1422 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1423 | | } |
| 0 | 1424 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1425 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1426 | | string _responseContent = null; |
| 0 | 1427 | | if ((int)_statusCode != 200) |
| | 1428 | | { |
| 0 | 1429 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1430 | | try |
| | 1431 | | { |
| 0 | 1432 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1433 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1434 | | if (_errorBody != null) |
| | 1435 | | { |
| 0 | 1436 | | ex.Body = _errorBody; |
| | 1437 | | } |
| 0 | 1438 | | } |
| 0 | 1439 | | catch (JsonException) |
| | 1440 | | { |
| | 1441 | | // Ignore the exception |
| 0 | 1442 | | } |
| 0 | 1443 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1444 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1445 | | if (_shouldTrace) |
| | 1446 | | { |
| 0 | 1447 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1448 | | } |
| 0 | 1449 | | _httpRequest.Dispose(); |
| 0 | 1450 | | if (_httpResponse != null) |
| | 1451 | | { |
| 0 | 1452 | | _httpResponse.Dispose(); |
| | 1453 | | } |
| 0 | 1454 | | throw ex; |
| | 1455 | | } |
| | 1456 | | // Create Result |
| 0 | 1457 | | var _result = new HttpOperationResponse<OCR>(); |
| 0 | 1458 | | _result.Request = _httpRequest; |
| 0 | 1459 | | _result.Response = _httpResponse; |
| | 1460 | | // Deserialize Response |
| 0 | 1461 | | if ((int)_statusCode == 200) |
| | 1462 | | { |
| 0 | 1463 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1464 | | try |
| | 1465 | | { |
| 0 | 1466 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OCR>(_responseContent, Client.De |
| 0 | 1467 | | } |
| 0 | 1468 | | catch (JsonException ex) |
| | 1469 | | { |
| 0 | 1470 | | _httpRequest.Dispose(); |
| 0 | 1471 | | if (_httpResponse != null) |
| | 1472 | | { |
| 0 | 1473 | | _httpResponse.Dispose(); |
| | 1474 | | } |
| 0 | 1475 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1476 | | } |
| | 1477 | | } |
| 0 | 1478 | | if (_shouldTrace) |
| | 1479 | | { |
| 0 | 1480 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1481 | | } |
| 0 | 1482 | | return _result; |
| 0 | 1483 | | } |
| | 1484 | |
|
| | 1485 | | /// <summary> |
| | 1486 | | /// Returns probabilities of the image containing racy or adult content. |
| | 1487 | | /// </summary> |
| | 1488 | | /// <param name='imageStream'> |
| | 1489 | | /// The image file. |
| | 1490 | | /// </param> |
| | 1491 | | /// <param name='cacheImage'> |
| | 1492 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 1493 | | /// omitted. |
| | 1494 | | /// </param> |
| | 1495 | | /// <param name='customHeaders'> |
| | 1496 | | /// Headers that will be added to request. |
| | 1497 | | /// </param> |
| | 1498 | | /// <param name='cancellationToken'> |
| | 1499 | | /// The cancellation token. |
| | 1500 | | /// </param> |
| | 1501 | | /// <exception cref="APIErrorException"> |
| | 1502 | | /// Thrown when the operation returned an invalid status code |
| | 1503 | | /// </exception> |
| | 1504 | | /// <exception cref="SerializationException"> |
| | 1505 | | /// Thrown when unable to deserialize the response |
| | 1506 | | /// </exception> |
| | 1507 | | /// <exception cref="ValidationException"> |
| | 1508 | | /// Thrown when a required parameter is null |
| | 1509 | | /// </exception> |
| | 1510 | | /// <exception cref="System.ArgumentNullException"> |
| | 1511 | | /// Thrown when a required parameter is null |
| | 1512 | | /// </exception> |
| | 1513 | | /// <return> |
| | 1514 | | /// A response object containing the response body and response headers. |
| | 1515 | | /// </return> |
| | 1516 | | public async Task<HttpOperationResponse<Evaluate>> EvaluateFileInputWithHttpMessagesAsync(Stream imageStream, bo |
| | 1517 | | { |
| 0 | 1518 | | if (Client.Endpoint == null) |
| | 1519 | | { |
| 0 | 1520 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1521 | | } |
| 0 | 1522 | | if (imageStream == null) |
| | 1523 | | { |
| 0 | 1524 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageStream"); |
| | 1525 | | } |
| | 1526 | | // Tracing |
| 0 | 1527 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1528 | | string _invocationId = null; |
| 0 | 1529 | | if (_shouldTrace) |
| | 1530 | | { |
| 0 | 1531 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1532 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1533 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 1534 | | tracingParameters.Add("imageStream", imageStream); |
| 0 | 1535 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1536 | | ServiceClientTracing.Enter(_invocationId, this, "EvaluateFileInput", tracingParameters); |
| | 1537 | | } |
| | 1538 | | // Construct URL |
| 0 | 1539 | | var _baseUrl = Client.BaseUri; |
| 0 | 1540 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Eva |
| 0 | 1541 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1542 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1543 | | if (cacheImage != null) |
| | 1544 | | { |
| 0 | 1545 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 1546 | | } |
| 0 | 1547 | | if (_queryParameters.Count > 0) |
| | 1548 | | { |
| 0 | 1549 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1550 | | } |
| | 1551 | | // Create HTTP transport objects |
| 0 | 1552 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1553 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1554 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1555 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1556 | | // Set Headers |
| | 1557 | |
|
| | 1558 | |
|
| 0 | 1559 | | if (customHeaders != null) |
| | 1560 | | { |
| 0 | 1561 | | foreach(var _header in customHeaders) |
| | 1562 | | { |
| 0 | 1563 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1564 | | { |
| 0 | 1565 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1566 | | } |
| 0 | 1567 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1568 | | } |
| | 1569 | | } |
| | 1570 | |
|
| | 1571 | | // Serialize Request |
| 0 | 1572 | | string _requestContent = null; |
| 0 | 1573 | | if(imageStream == null) |
| | 1574 | | { |
| 0 | 1575 | | throw new System.ArgumentNullException("imageStream"); |
| | 1576 | | } |
| 0 | 1577 | | if (imageStream != null && imageStream != Stream.Null) |
| | 1578 | | { |
| 0 | 1579 | | _httpRequest.Content = new StreamContent(imageStream); |
| 0 | 1580 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("image/gif" |
| | 1581 | | } |
| | 1582 | | // Set Credentials |
| 0 | 1583 | | if (Client.Credentials != null) |
| | 1584 | | { |
| 0 | 1585 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1586 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1587 | | } |
| | 1588 | | // Send Request |
| 0 | 1589 | | if (_shouldTrace) |
| | 1590 | | { |
| 0 | 1591 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1592 | | } |
| 0 | 1593 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1594 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1595 | | if (_shouldTrace) |
| | 1596 | | { |
| 0 | 1597 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1598 | | } |
| 0 | 1599 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1600 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1601 | | string _responseContent = null; |
| 0 | 1602 | | if ((int)_statusCode != 200) |
| | 1603 | | { |
| 0 | 1604 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1605 | | try |
| | 1606 | | { |
| 0 | 1607 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1608 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1609 | | if (_errorBody != null) |
| | 1610 | | { |
| 0 | 1611 | | ex.Body = _errorBody; |
| | 1612 | | } |
| 0 | 1613 | | } |
| 0 | 1614 | | catch (JsonException) |
| | 1615 | | { |
| | 1616 | | // Ignore the exception |
| 0 | 1617 | | } |
| 0 | 1618 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1619 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1620 | | if (_shouldTrace) |
| | 1621 | | { |
| 0 | 1622 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1623 | | } |
| 0 | 1624 | | _httpRequest.Dispose(); |
| 0 | 1625 | | if (_httpResponse != null) |
| | 1626 | | { |
| 0 | 1627 | | _httpResponse.Dispose(); |
| | 1628 | | } |
| 0 | 1629 | | throw ex; |
| | 1630 | | } |
| | 1631 | | // Create Result |
| 0 | 1632 | | var _result = new HttpOperationResponse<Evaluate>(); |
| 0 | 1633 | | _result.Request = _httpRequest; |
| 0 | 1634 | | _result.Response = _httpResponse; |
| | 1635 | | // Deserialize Response |
| 0 | 1636 | | if ((int)_statusCode == 200) |
| | 1637 | | { |
| 0 | 1638 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1639 | | try |
| | 1640 | | { |
| 0 | 1641 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Evaluate>(_responseContent, Clie |
| 0 | 1642 | | } |
| 0 | 1643 | | catch (JsonException ex) |
| | 1644 | | { |
| 0 | 1645 | | _httpRequest.Dispose(); |
| 0 | 1646 | | if (_httpResponse != null) |
| | 1647 | | { |
| 0 | 1648 | | _httpResponse.Dispose(); |
| | 1649 | | } |
| 0 | 1650 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1651 | | } |
| | 1652 | | } |
| 0 | 1653 | | if (_shouldTrace) |
| | 1654 | | { |
| 0 | 1655 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1656 | | } |
| 0 | 1657 | | return _result; |
| 0 | 1658 | | } |
| | 1659 | |
|
| | 1660 | | /// <summary> |
| | 1661 | | /// Returns probabilities of the image containing racy or adult content. |
| | 1662 | | /// </summary> |
| | 1663 | | /// <param name='contentType'> |
| | 1664 | | /// The content type. |
| | 1665 | | /// </param> |
| | 1666 | | /// <param name='imageUrl'> |
| | 1667 | | /// The image url. |
| | 1668 | | /// </param> |
| | 1669 | | /// <param name='cacheImage'> |
| | 1670 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 1671 | | /// omitted. |
| | 1672 | | /// </param> |
| | 1673 | | /// <param name='customHeaders'> |
| | 1674 | | /// Headers that will be added to request. |
| | 1675 | | /// </param> |
| | 1676 | | /// <param name='cancellationToken'> |
| | 1677 | | /// The cancellation token. |
| | 1678 | | /// </param> |
| | 1679 | | /// <exception cref="APIErrorException"> |
| | 1680 | | /// Thrown when the operation returned an invalid status code |
| | 1681 | | /// </exception> |
| | 1682 | | /// <exception cref="SerializationException"> |
| | 1683 | | /// Thrown when unable to deserialize the response |
| | 1684 | | /// </exception> |
| | 1685 | | /// <exception cref="ValidationException"> |
| | 1686 | | /// Thrown when a required parameter is null |
| | 1687 | | /// </exception> |
| | 1688 | | /// <exception cref="System.ArgumentNullException"> |
| | 1689 | | /// Thrown when a required parameter is null |
| | 1690 | | /// </exception> |
| | 1691 | | /// <return> |
| | 1692 | | /// A response object containing the response body and response headers. |
| | 1693 | | /// </return> |
| | 1694 | | public async Task<HttpOperationResponse<Evaluate>> EvaluateUrlInputWithHttpMessagesAsync(string contentType, Bod |
| | 1695 | | { |
| 0 | 1696 | | if (Client.Endpoint == null) |
| | 1697 | | { |
| 0 | 1698 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1699 | | } |
| 0 | 1700 | | if (contentType == null) |
| | 1701 | | { |
| 0 | 1702 | | throw new ValidationException(ValidationRules.CannotBeNull, "contentType"); |
| | 1703 | | } |
| 0 | 1704 | | if (imageUrl == null) |
| | 1705 | | { |
| 0 | 1706 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl"); |
| | 1707 | | } |
| | 1708 | | // Tracing |
| 0 | 1709 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1710 | | string _invocationId = null; |
| 0 | 1711 | | if (_shouldTrace) |
| | 1712 | | { |
| 0 | 1713 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1714 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1715 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 1716 | | tracingParameters.Add("contentType", contentType); |
| 0 | 1717 | | tracingParameters.Add("imageUrl", imageUrl); |
| 0 | 1718 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1719 | | ServiceClientTracing.Enter(_invocationId, this, "EvaluateUrlInput", tracingParameters); |
| | 1720 | | } |
| | 1721 | | // Construct URL |
| 0 | 1722 | | var _baseUrl = Client.BaseUri; |
| 0 | 1723 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Eva |
| 0 | 1724 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1725 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1726 | | if (cacheImage != null) |
| | 1727 | | { |
| 0 | 1728 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 1729 | | } |
| 0 | 1730 | | if (_queryParameters.Count > 0) |
| | 1731 | | { |
| 0 | 1732 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1733 | | } |
| | 1734 | | // Create HTTP transport objects |
| 0 | 1735 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1736 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1737 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1738 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1739 | | // Set Headers |
| | 1740 | |
|
| | 1741 | |
|
| 0 | 1742 | | if (customHeaders != null) |
| | 1743 | | { |
| 0 | 1744 | | foreach(var _header in customHeaders) |
| | 1745 | | { |
| 0 | 1746 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1747 | | { |
| 0 | 1748 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1749 | | } |
| 0 | 1750 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1751 | | } |
| | 1752 | | } |
| | 1753 | |
|
| | 1754 | | // Serialize Request |
| 0 | 1755 | | string _requestContent = null; |
| 0 | 1756 | | if(imageUrl != null) |
| | 1757 | | { |
| 0 | 1758 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti |
| 0 | 1759 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1760 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1761 | | } |
| | 1762 | | // Set Credentials |
| 0 | 1763 | | if (Client.Credentials != null) |
| | 1764 | | { |
| 0 | 1765 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1766 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1767 | | } |
| | 1768 | | // Send Request |
| 0 | 1769 | | if (_shouldTrace) |
| | 1770 | | { |
| 0 | 1771 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1772 | | } |
| 0 | 1773 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1774 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1775 | | if (_shouldTrace) |
| | 1776 | | { |
| 0 | 1777 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1778 | | } |
| 0 | 1779 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1780 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1781 | | string _responseContent = null; |
| 0 | 1782 | | if ((int)_statusCode != 200) |
| | 1783 | | { |
| 0 | 1784 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1785 | | try |
| | 1786 | | { |
| 0 | 1787 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1788 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1789 | | if (_errorBody != null) |
| | 1790 | | { |
| 0 | 1791 | | ex.Body = _errorBody; |
| | 1792 | | } |
| 0 | 1793 | | } |
| 0 | 1794 | | catch (JsonException) |
| | 1795 | | { |
| | 1796 | | // Ignore the exception |
| 0 | 1797 | | } |
| 0 | 1798 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1799 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1800 | | if (_shouldTrace) |
| | 1801 | | { |
| 0 | 1802 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1803 | | } |
| 0 | 1804 | | _httpRequest.Dispose(); |
| 0 | 1805 | | if (_httpResponse != null) |
| | 1806 | | { |
| 0 | 1807 | | _httpResponse.Dispose(); |
| | 1808 | | } |
| 0 | 1809 | | throw ex; |
| | 1810 | | } |
| | 1811 | | // Create Result |
| 0 | 1812 | | var _result = new HttpOperationResponse<Evaluate>(); |
| 0 | 1813 | | _result.Request = _httpRequest; |
| 0 | 1814 | | _result.Response = _httpResponse; |
| | 1815 | | // Deserialize Response |
| 0 | 1816 | | if ((int)_statusCode == 200) |
| | 1817 | | { |
| 0 | 1818 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1819 | | try |
| | 1820 | | { |
| 0 | 1821 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Evaluate>(_responseContent, Clie |
| 0 | 1822 | | } |
| 0 | 1823 | | catch (JsonException ex) |
| | 1824 | | { |
| 0 | 1825 | | _httpRequest.Dispose(); |
| 0 | 1826 | | if (_httpResponse != null) |
| | 1827 | | { |
| 0 | 1828 | | _httpResponse.Dispose(); |
| | 1829 | | } |
| 0 | 1830 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1831 | | } |
| | 1832 | | } |
| 0 | 1833 | | if (_shouldTrace) |
| | 1834 | | { |
| 0 | 1835 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1836 | | } |
| 0 | 1837 | | return _result; |
| 0 | 1838 | | } |
| | 1839 | |
|
| | 1840 | | /// <summary> |
| | 1841 | | /// Fuzzily match an image against one of your custom Image Lists. You can |
| | 1842 | | /// create and manage your custom image lists using <a |
| | 1843 | | /// href="/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe">this</a> |
| | 1844 | | /// API. |
| | 1845 | | /// |
| | 1846 | | /// Returns ID and tags of matching image.<br/> |
| | 1847 | | /// <br/> |
| | 1848 | | /// Note: Refresh Index must be run on the corresponding Image List before |
| | 1849 | | /// additions and removals are reflected in the response. |
| | 1850 | | /// </summary> |
| | 1851 | | /// <param name='contentType'> |
| | 1852 | | /// The content type. |
| | 1853 | | /// </param> |
| | 1854 | | /// <param name='imageUrl'> |
| | 1855 | | /// The image url. |
| | 1856 | | /// </param> |
| | 1857 | | /// <param name='listId'> |
| | 1858 | | /// The list Id. |
| | 1859 | | /// </param> |
| | 1860 | | /// <param name='cacheImage'> |
| | 1861 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 1862 | | /// omitted. |
| | 1863 | | /// </param> |
| | 1864 | | /// <param name='customHeaders'> |
| | 1865 | | /// Headers that will be added to request. |
| | 1866 | | /// </param> |
| | 1867 | | /// <param name='cancellationToken'> |
| | 1868 | | /// The cancellation token. |
| | 1869 | | /// </param> |
| | 1870 | | /// <exception cref="APIErrorException"> |
| | 1871 | | /// Thrown when the operation returned an invalid status code |
| | 1872 | | /// </exception> |
| | 1873 | | /// <exception cref="SerializationException"> |
| | 1874 | | /// Thrown when unable to deserialize the response |
| | 1875 | | /// </exception> |
| | 1876 | | /// <exception cref="ValidationException"> |
| | 1877 | | /// Thrown when a required parameter is null |
| | 1878 | | /// </exception> |
| | 1879 | | /// <exception cref="System.ArgumentNullException"> |
| | 1880 | | /// Thrown when a required parameter is null |
| | 1881 | | /// </exception> |
| | 1882 | | /// <return> |
| | 1883 | | /// A response object containing the response body and response headers. |
| | 1884 | | /// </return> |
| | 1885 | | public async Task<HttpOperationResponse<MatchResponse>> MatchUrlInputWithHttpMessagesAsync(string contentType, B |
| | 1886 | | { |
| 0 | 1887 | | if (Client.Endpoint == null) |
| | 1888 | | { |
| 0 | 1889 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1890 | | } |
| 0 | 1891 | | if (contentType == null) |
| | 1892 | | { |
| 0 | 1893 | | throw new ValidationException(ValidationRules.CannotBeNull, "contentType"); |
| | 1894 | | } |
| 0 | 1895 | | if (imageUrl == null) |
| | 1896 | | { |
| 0 | 1897 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl"); |
| | 1898 | | } |
| | 1899 | | // Tracing |
| 0 | 1900 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1901 | | string _invocationId = null; |
| 0 | 1902 | | if (_shouldTrace) |
| | 1903 | | { |
| 0 | 1904 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1905 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1906 | | tracingParameters.Add("listId", listId); |
| 0 | 1907 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 1908 | | tracingParameters.Add("contentType", contentType); |
| 0 | 1909 | | tracingParameters.Add("imageUrl", imageUrl); |
| 0 | 1910 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1911 | | ServiceClientTracing.Enter(_invocationId, this, "MatchUrlInput", tracingParameters); |
| | 1912 | | } |
| | 1913 | | // Construct URL |
| 0 | 1914 | | var _baseUrl = Client.BaseUri; |
| 0 | 1915 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Mat |
| 0 | 1916 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1917 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1918 | | if (listId != null) |
| | 1919 | | { |
| 0 | 1920 | | _queryParameters.Add(string.Format("listId={0}", System.Uri.EscapeDataString(listId))); |
| | 1921 | | } |
| 0 | 1922 | | if (cacheImage != null) |
| | 1923 | | { |
| 0 | 1924 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 1925 | | } |
| 0 | 1926 | | if (_queryParameters.Count > 0) |
| | 1927 | | { |
| 0 | 1928 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1929 | | } |
| | 1930 | | // Create HTTP transport objects |
| 0 | 1931 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1932 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1933 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1934 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1935 | | // Set Headers |
| | 1936 | |
|
| | 1937 | |
|
| 0 | 1938 | | if (customHeaders != null) |
| | 1939 | | { |
| 0 | 1940 | | foreach(var _header in customHeaders) |
| | 1941 | | { |
| 0 | 1942 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1943 | | { |
| 0 | 1944 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1945 | | } |
| 0 | 1946 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1947 | | } |
| | 1948 | | } |
| | 1949 | |
|
| | 1950 | | // Serialize Request |
| 0 | 1951 | | string _requestContent = null; |
| 0 | 1952 | | if(imageUrl != null) |
| | 1953 | | { |
| 0 | 1954 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti |
| 0 | 1955 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1956 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1957 | | } |
| | 1958 | | // Set Credentials |
| 0 | 1959 | | if (Client.Credentials != null) |
| | 1960 | | { |
| 0 | 1961 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1962 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1963 | | } |
| | 1964 | | // Send Request |
| 0 | 1965 | | if (_shouldTrace) |
| | 1966 | | { |
| 0 | 1967 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1968 | | } |
| 0 | 1969 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1970 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1971 | | if (_shouldTrace) |
| | 1972 | | { |
| 0 | 1973 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1974 | | } |
| 0 | 1975 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1976 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1977 | | string _responseContent = null; |
| 0 | 1978 | | if ((int)_statusCode != 200) |
| | 1979 | | { |
| 0 | 1980 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1981 | | try |
| | 1982 | | { |
| 0 | 1983 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1984 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1985 | | if (_errorBody != null) |
| | 1986 | | { |
| 0 | 1987 | | ex.Body = _errorBody; |
| | 1988 | | } |
| 0 | 1989 | | } |
| 0 | 1990 | | catch (JsonException) |
| | 1991 | | { |
| | 1992 | | // Ignore the exception |
| 0 | 1993 | | } |
| 0 | 1994 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1995 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1996 | | if (_shouldTrace) |
| | 1997 | | { |
| 0 | 1998 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1999 | | } |
| 0 | 2000 | | _httpRequest.Dispose(); |
| 0 | 2001 | | if (_httpResponse != null) |
| | 2002 | | { |
| 0 | 2003 | | _httpResponse.Dispose(); |
| | 2004 | | } |
| 0 | 2005 | | throw ex; |
| | 2006 | | } |
| | 2007 | | // Create Result |
| 0 | 2008 | | var _result = new HttpOperationResponse<MatchResponse>(); |
| 0 | 2009 | | _result.Request = _httpRequest; |
| 0 | 2010 | | _result.Response = _httpResponse; |
| | 2011 | | // Deserialize Response |
| 0 | 2012 | | if ((int)_statusCode == 200) |
| | 2013 | | { |
| 0 | 2014 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2015 | | try |
| | 2016 | | { |
| 0 | 2017 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<MatchResponse>(_responseContent, |
| 0 | 2018 | | } |
| 0 | 2019 | | catch (JsonException ex) |
| | 2020 | | { |
| 0 | 2021 | | _httpRequest.Dispose(); |
| 0 | 2022 | | if (_httpResponse != null) |
| | 2023 | | { |
| 0 | 2024 | | _httpResponse.Dispose(); |
| | 2025 | | } |
| 0 | 2026 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2027 | | } |
| | 2028 | | } |
| 0 | 2029 | | if (_shouldTrace) |
| | 2030 | | { |
| 0 | 2031 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2032 | | } |
| 0 | 2033 | | return _result; |
| 0 | 2034 | | } |
| | 2035 | |
|
| | 2036 | | /// <summary> |
| | 2037 | | /// Fuzzily match an image against one of your custom Image Lists. You can |
| | 2038 | | /// create and manage your custom image lists using <a |
| | 2039 | | /// href="/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe">this</a> |
| | 2040 | | /// API. |
| | 2041 | | /// |
| | 2042 | | /// Returns ID and tags of matching image.<br/> |
| | 2043 | | /// <br/> |
| | 2044 | | /// Note: Refresh Index must be run on the corresponding Image List before |
| | 2045 | | /// additions and removals are reflected in the response. |
| | 2046 | | /// </summary> |
| | 2047 | | /// <param name='imageStream'> |
| | 2048 | | /// The image file. |
| | 2049 | | /// </param> |
| | 2050 | | /// <param name='listId'> |
| | 2051 | | /// The list Id. |
| | 2052 | | /// </param> |
| | 2053 | | /// <param name='cacheImage'> |
| | 2054 | | /// Whether to retain the submitted image for future use; defaults to false if |
| | 2055 | | /// omitted. |
| | 2056 | | /// </param> |
| | 2057 | | /// <param name='customHeaders'> |
| | 2058 | | /// Headers that will be added to request. |
| | 2059 | | /// </param> |
| | 2060 | | /// <param name='cancellationToken'> |
| | 2061 | | /// The cancellation token. |
| | 2062 | | /// </param> |
| | 2063 | | /// <exception cref="APIErrorException"> |
| | 2064 | | /// Thrown when the operation returned an invalid status code |
| | 2065 | | /// </exception> |
| | 2066 | | /// <exception cref="SerializationException"> |
| | 2067 | | /// Thrown when unable to deserialize the response |
| | 2068 | | /// </exception> |
| | 2069 | | /// <exception cref="ValidationException"> |
| | 2070 | | /// Thrown when a required parameter is null |
| | 2071 | | /// </exception> |
| | 2072 | | /// <exception cref="System.ArgumentNullException"> |
| | 2073 | | /// Thrown when a required parameter is null |
| | 2074 | | /// </exception> |
| | 2075 | | /// <return> |
| | 2076 | | /// A response object containing the response body and response headers. |
| | 2077 | | /// </return> |
| | 2078 | | public async Task<HttpOperationResponse<MatchResponse>> MatchFileInputWithHttpMessagesAsync(Stream imageStream, |
| | 2079 | | { |
| 0 | 2080 | | if (Client.Endpoint == null) |
| | 2081 | | { |
| 0 | 2082 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2083 | | } |
| 0 | 2084 | | if (imageStream == null) |
| | 2085 | | { |
| 0 | 2086 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageStream"); |
| | 2087 | | } |
| | 2088 | | // Tracing |
| 0 | 2089 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2090 | | string _invocationId = null; |
| 0 | 2091 | | if (_shouldTrace) |
| | 2092 | | { |
| 0 | 2093 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2094 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2095 | | tracingParameters.Add("listId", listId); |
| 0 | 2096 | | tracingParameters.Add("cacheImage", cacheImage); |
| 0 | 2097 | | tracingParameters.Add("imageStream", imageStream); |
| 0 | 2098 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2099 | | ServiceClientTracing.Enter(_invocationId, this, "MatchFileInput", tracingParameters); |
| | 2100 | | } |
| | 2101 | | // Construct URL |
| 0 | 2102 | | var _baseUrl = Client.BaseUri; |
| 0 | 2103 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Mat |
| 0 | 2104 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 2105 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2106 | | if (listId != null) |
| | 2107 | | { |
| 0 | 2108 | | _queryParameters.Add(string.Format("listId={0}", System.Uri.EscapeDataString(listId))); |
| | 2109 | | } |
| 0 | 2110 | | if (cacheImage != null) |
| | 2111 | | { |
| 0 | 2112 | | _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe |
| | 2113 | | } |
| 0 | 2114 | | if (_queryParameters.Count > 0) |
| | 2115 | | { |
| 0 | 2116 | | _url += "?" + string.Join("&", _queryParameters); |
| | 2117 | | } |
| | 2118 | | // Create HTTP transport objects |
| 0 | 2119 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2120 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2121 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 2122 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2123 | | // Set Headers |
| | 2124 | |
|
| | 2125 | |
|
| 0 | 2126 | | if (customHeaders != null) |
| | 2127 | | { |
| 0 | 2128 | | foreach(var _header in customHeaders) |
| | 2129 | | { |
| 0 | 2130 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2131 | | { |
| 0 | 2132 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2133 | | } |
| 0 | 2134 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2135 | | } |
| | 2136 | | } |
| | 2137 | |
|
| | 2138 | | // Serialize Request |
| 0 | 2139 | | string _requestContent = null; |
| 0 | 2140 | | if(imageStream == null) |
| | 2141 | | { |
| 0 | 2142 | | throw new System.ArgumentNullException("imageStream"); |
| | 2143 | | } |
| 0 | 2144 | | if (imageStream != null && imageStream != Stream.Null) |
| | 2145 | | { |
| 0 | 2146 | | _httpRequest.Content = new StreamContent(imageStream); |
| 0 | 2147 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("image/gif" |
| | 2148 | | } |
| | 2149 | | // Set Credentials |
| 0 | 2150 | | if (Client.Credentials != null) |
| | 2151 | | { |
| 0 | 2152 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2153 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2154 | | } |
| | 2155 | | // Send Request |
| 0 | 2156 | | if (_shouldTrace) |
| | 2157 | | { |
| 0 | 2158 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2159 | | } |
| 0 | 2160 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2161 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2162 | | if (_shouldTrace) |
| | 2163 | | { |
| 0 | 2164 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2165 | | } |
| 0 | 2166 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2167 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2168 | | string _responseContent = null; |
| 0 | 2169 | | if ((int)_statusCode != 200) |
| | 2170 | | { |
| 0 | 2171 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 2172 | | try |
| | 2173 | | { |
| 0 | 2174 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2175 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 2176 | | if (_errorBody != null) |
| | 2177 | | { |
| 0 | 2178 | | ex.Body = _errorBody; |
| | 2179 | | } |
| 0 | 2180 | | } |
| 0 | 2181 | | catch (JsonException) |
| | 2182 | | { |
| | 2183 | | // Ignore the exception |
| 0 | 2184 | | } |
| 0 | 2185 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2186 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2187 | | if (_shouldTrace) |
| | 2188 | | { |
| 0 | 2189 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2190 | | } |
| 0 | 2191 | | _httpRequest.Dispose(); |
| 0 | 2192 | | if (_httpResponse != null) |
| | 2193 | | { |
| 0 | 2194 | | _httpResponse.Dispose(); |
| | 2195 | | } |
| 0 | 2196 | | throw ex; |
| | 2197 | | } |
| | 2198 | | // Create Result |
| 0 | 2199 | | var _result = new HttpOperationResponse<MatchResponse>(); |
| 0 | 2200 | | _result.Request = _httpRequest; |
| 0 | 2201 | | _result.Response = _httpResponse; |
| | 2202 | | // Deserialize Response |
| 0 | 2203 | | if ((int)_statusCode == 200) |
| | 2204 | | { |
| 0 | 2205 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2206 | | try |
| | 2207 | | { |
| 0 | 2208 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<MatchResponse>(_responseContent, |
| 0 | 2209 | | } |
| 0 | 2210 | | catch (JsonException ex) |
| | 2211 | | { |
| 0 | 2212 | | _httpRequest.Dispose(); |
| 0 | 2213 | | if (_httpResponse != null) |
| | 2214 | | { |
| 0 | 2215 | | _httpResponse.Dispose(); |
| | 2216 | | } |
| 0 | 2217 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2218 | | } |
| | 2219 | | } |
| 0 | 2220 | | if (_shouldTrace) |
| | 2221 | | { |
| 0 | 2222 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2223 | | } |
| 0 | 2224 | | return _result; |
| 0 | 2225 | | } |
| | 2226 | |
|
| | 2227 | | } |
| | 2228 | | } |