| | 1 | | // <auto-generated> |
| | 2 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 3 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 4 | | // license information. |
| | 5 | | // |
| | 6 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 7 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 8 | | // regenerated. |
| | 9 | | // </auto-generated> |
| | 10 | |
|
| | 11 | | namespace Microsoft.Azure.CognitiveServices.Language.TextAnalytics |
| | 12 | | { |
| | 13 | | using Microsoft.Rest; |
| | 14 | | using Microsoft.Rest.Serialization; |
| | 15 | | using Models; |
| | 16 | | using Newtonsoft.Json; |
| | 17 | | using System.Collections; |
| | 18 | | using System.Collections.Generic; |
| | 19 | | using System.Net; |
| | 20 | | using System.Net.Http; |
| | 21 | | using System.Threading; |
| | 22 | | using System.Threading.Tasks; |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// The Text Analytics API is a suite of text analytics web services built |
| | 26 | | /// with best-in-class Microsoft machine learning algorithms. The API can |
| | 27 | | /// be used to analyze unstructured text for tasks such as sentiment |
| | 28 | | /// analysis, key phrase extraction and language detection. No training |
| | 29 | | /// data is needed to use this API; just bring your text data. This API |
| | 30 | | /// uses advanced natural language processing techniques to deliver best in |
| | 31 | | /// class predictions. Further documentation can be found in |
| | 32 | | /// https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview |
| | 33 | | /// </summary> |
| | 34 | | public partial class TextAnalyticsClient : ServiceClient<TextAnalyticsClient>, ITextAnalyticsClient |
| | 35 | | { |
| | 36 | | /// <summary> |
| | 37 | | /// The base URI of the service. |
| | 38 | | /// </summary> |
| 32 | 39 | | internal string BaseUri {get; set;} |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Gets or sets json serialization settings. |
| | 43 | | /// </summary> |
| 32 | 44 | | public JsonSerializerSettings SerializationSettings { get; private set; } |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Gets or sets json deserialization settings. |
| | 48 | | /// </summary> |
| 32 | 49 | | public JsonSerializerSettings DeserializationSettings { get; private set; } |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// Supported Cognitive Services endpoints (protocol and hostname, for example: |
| | 53 | | /// https://westus.api.cognitive.microsoft.com). |
| | 54 | | /// </summary> |
| 48 | 55 | | public string Endpoint { get; set; } |
| | 56 | |
|
| | 57 | | /// <summary> |
| | 58 | | /// Subscription credentials which uniquely identify client subscription. |
| | 59 | | /// </summary> |
| 80 | 60 | | public ServiceClientCredentials Credentials { get; private set; } |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// Initializes a new instance of the TextAnalyticsClient class. |
| | 64 | | /// </summary> |
| | 65 | | /// <param name='httpClient'> |
| | 66 | | /// HttpClient to be used |
| | 67 | | /// </param> |
| | 68 | | /// <param name='disposeHttpClient'> |
| | 69 | | /// True: will dispose the provided httpClient on calling TextAnalyticsClient.Dispose(). False: will not dispose |
| 0 | 70 | | protected TextAnalyticsClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClien |
| | 71 | | { |
| 0 | 72 | | Initialize(); |
| 0 | 73 | | } |
| | 74 | |
|
| | 75 | | /// <summary> |
| | 76 | | /// Initializes a new instance of the TextAnalyticsClient class. |
| | 77 | | /// </summary> |
| | 78 | | /// <param name='handlers'> |
| | 79 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 80 | | /// </param> |
| 16 | 81 | | protected TextAnalyticsClient(params DelegatingHandler[] handlers) : base(handlers) |
| | 82 | | { |
| 16 | 83 | | Initialize(); |
| 16 | 84 | | } |
| | 85 | |
|
| | 86 | | /// <summary> |
| | 87 | | /// Initializes a new instance of the TextAnalyticsClient class. |
| | 88 | | /// </summary> |
| | 89 | | /// <param name='rootHandler'> |
| | 90 | | /// Optional. The http client handler used to handle http transport. |
| | 91 | | /// </param> |
| | 92 | | /// <param name='handlers'> |
| | 93 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 94 | | /// </param> |
| 0 | 95 | | protected TextAnalyticsClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHan |
| | 96 | | { |
| 0 | 97 | | Initialize(); |
| 0 | 98 | | } |
| | 99 | |
|
| | 100 | | /// <summary> |
| | 101 | | /// Initializes a new instance of the TextAnalyticsClient class. |
| | 102 | | /// </summary> |
| | 103 | | /// <param name='credentials'> |
| | 104 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 105 | | /// </param> |
| | 106 | | /// <param name='handlers'> |
| | 107 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 108 | | /// </param> |
| | 109 | | /// <exception cref="System.ArgumentNullException"> |
| | 110 | | /// Thrown when a required parameter is null |
| | 111 | | /// </exception> |
| 16 | 112 | | public TextAnalyticsClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(han |
| | 113 | | { |
| 16 | 114 | | if (credentials == null) |
| | 115 | | { |
| 0 | 116 | | throw new System.ArgumentNullException("credentials"); |
| | 117 | | } |
| 16 | 118 | | Credentials = credentials; |
| 16 | 119 | | if (Credentials != null) |
| | 120 | | { |
| 16 | 121 | | Credentials.InitializeServiceClient(this); |
| | 122 | | } |
| 16 | 123 | | } |
| | 124 | |
|
| | 125 | | /// <summary> |
| | 126 | | /// Initializes a new instance of the TextAnalyticsClient class. |
| | 127 | | /// </summary> |
| | 128 | | /// <param name='credentials'> |
| | 129 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 130 | | /// </param> |
| | 131 | | /// <param name='httpClient'> |
| | 132 | | /// HttpClient to be used |
| | 133 | | /// </param> |
| | 134 | | /// <param name='disposeHttpClient'> |
| | 135 | | /// True: will dispose the provided httpClient on calling TextAnalyticsClient.Dispose(). False: will not dispose |
| | 136 | | /// <exception cref="System.ArgumentNullException"> |
| | 137 | | /// Thrown when a required parameter is null |
| | 138 | | /// </exception> |
| 0 | 139 | | public TextAnalyticsClient(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient) |
| | 140 | | { |
| 0 | 141 | | if (credentials == null) |
| | 142 | | { |
| 0 | 143 | | throw new System.ArgumentNullException("credentials"); |
| | 144 | | } |
| 0 | 145 | | Credentials = credentials; |
| 0 | 146 | | if (Credentials != null) |
| | 147 | | { |
| 0 | 148 | | Credentials.InitializeServiceClient(this); |
| | 149 | | } |
| 0 | 150 | | } |
| | 151 | |
|
| | 152 | | /// <summary> |
| | 153 | | /// Initializes a new instance of the TextAnalyticsClient class. |
| | 154 | | /// </summary> |
| | 155 | | /// <param name='credentials'> |
| | 156 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 157 | | /// </param> |
| | 158 | | /// <param name='rootHandler'> |
| | 159 | | /// Optional. The http client handler used to handle http transport. |
| | 160 | | /// </param> |
| | 161 | | /// <param name='handlers'> |
| | 162 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 163 | | /// </param> |
| | 164 | | /// <exception cref="System.ArgumentNullException"> |
| | 165 | | /// Thrown when a required parameter is null |
| | 166 | | /// </exception> |
| 0 | 167 | | public TextAnalyticsClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params Delegatin |
| | 168 | | { |
| 0 | 169 | | if (credentials == null) |
| | 170 | | { |
| 0 | 171 | | throw new System.ArgumentNullException("credentials"); |
| | 172 | | } |
| 0 | 173 | | Credentials = credentials; |
| 0 | 174 | | if (Credentials != null) |
| | 175 | | { |
| 0 | 176 | | Credentials.InitializeServiceClient(this); |
| | 177 | | } |
| 0 | 178 | | } |
| | 179 | |
|
| | 180 | | /// <summary> |
| | 181 | | /// An optional partial-method to perform custom initialization. |
| | 182 | | ///</summary> |
| | 183 | | partial void CustomInitialize(); |
| | 184 | | /// <summary> |
| | 185 | | /// Initializes client properties. |
| | 186 | | /// </summary> |
| | 187 | | private void Initialize() |
| | 188 | | { |
| 16 | 189 | | BaseUri = "{Endpoint}/text/analytics/v2.1"; |
| 16 | 190 | | SerializationSettings = new JsonSerializerSettings |
| 16 | 191 | | { |
| 16 | 192 | | Formatting = Newtonsoft.Json.Formatting.Indented, |
| 16 | 193 | | DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, |
| 16 | 194 | | DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, |
| 16 | 195 | | NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, |
| 16 | 196 | | ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, |
| 16 | 197 | | ContractResolver = new ReadOnlyJsonContractResolver(), |
| 16 | 198 | | Converters = new List<JsonConverter> |
| 16 | 199 | | { |
| 16 | 200 | | new Iso8601TimeSpanConverter() |
| 16 | 201 | | } |
| 16 | 202 | | }; |
| 16 | 203 | | DeserializationSettings = new JsonSerializerSettings |
| 16 | 204 | | { |
| 16 | 205 | | DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, |
| 16 | 206 | | DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, |
| 16 | 207 | | NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, |
| 16 | 208 | | ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, |
| 16 | 209 | | ContractResolver = new ReadOnlyJsonContractResolver(), |
| 16 | 210 | | Converters = new List<JsonConverter> |
| 16 | 211 | | { |
| 16 | 212 | | new Iso8601TimeSpanConverter() |
| 16 | 213 | | } |
| 16 | 214 | | }; |
| | 215 | | CustomInitialize(); |
| 16 | 216 | | } |
| | 217 | | /// <summary> |
| | 218 | | /// The API returns the detected language and a numeric score between 0 and 1. |
| | 219 | | /// </summary> |
| | 220 | | /// <remarks> |
| | 221 | | /// Scores close to 1 indicate 100% certainty that the identified language is |
| | 222 | | /// true. A total of 120 languages are supported. |
| | 223 | | /// </remarks> |
| | 224 | | /// <param name='showStats'> |
| | 225 | | /// (optional) if set to true, response will contain input and document level |
| | 226 | | /// statistics. |
| | 227 | | /// </param> |
| | 228 | | /// <param name='languageBatchInput'> |
| | 229 | | /// Collection of documents to analyze. |
| | 230 | | /// </param> |
| | 231 | | /// <param name='customHeaders'> |
| | 232 | | /// Headers that will be added to request. |
| | 233 | | /// </param> |
| | 234 | | /// <param name='cancellationToken'> |
| | 235 | | /// The cancellation token. |
| | 236 | | /// </param> |
| | 237 | | /// <exception cref="ErrorResponseException"> |
| | 238 | | /// Thrown when the operation returned an invalid status code |
| | 239 | | /// </exception> |
| | 240 | | /// <exception cref="SerializationException"> |
| | 241 | | /// Thrown when unable to deserialize the response |
| | 242 | | /// </exception> |
| | 243 | | /// <exception cref="ValidationException"> |
| | 244 | | /// Thrown when a required parameter is null |
| | 245 | | /// </exception> |
| | 246 | | /// <exception cref="System.ArgumentNullException"> |
| | 247 | | /// Thrown when a required parameter is null |
| | 248 | | /// </exception> |
| | 249 | | /// <return> |
| | 250 | | /// A response object containing the response body and response headers. |
| | 251 | | /// </return> |
| | 252 | | public async Task<HttpOperationResponse<LanguageBatchResult>> DetectLanguageWithHttpMessagesAsync(bool? showStat |
| | 253 | | { |
| 4 | 254 | | if (Endpoint == null) |
| | 255 | | { |
| 0 | 256 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 257 | | } |
| | 258 | | // Tracing |
| 4 | 259 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 260 | | string _invocationId = null; |
| 4 | 261 | | if (_shouldTrace) |
| | 262 | | { |
| 0 | 263 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 264 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 265 | | tracingParameters.Add("showStats", showStats); |
| 0 | 266 | | tracingParameters.Add("languageBatchInput", languageBatchInput); |
| 0 | 267 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 268 | | ServiceClientTracing.Enter(_invocationId, this, "DetectLanguage", tracingParameters); |
| | 269 | | } |
| | 270 | | // Construct URL |
| 4 | 271 | | var _baseUrl = BaseUri; |
| 4 | 272 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "languages"; |
| 4 | 273 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 4 | 274 | | List<string> _queryParameters = new List<string>(); |
| 4 | 275 | | if (showStats != null) |
| | 276 | | { |
| 0 | 277 | | _queryParameters.Add(string.Format("showStats={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serializ |
| | 278 | | } |
| 4 | 279 | | if (_queryParameters.Count > 0) |
| | 280 | | { |
| 0 | 281 | | _url += "?" + string.Join("&", _queryParameters); |
| | 282 | | } |
| | 283 | | // Create HTTP transport objects |
| 4 | 284 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 285 | | HttpResponseMessage _httpResponse = null; |
| 4 | 286 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 287 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 288 | | // Set Headers |
| | 289 | |
|
| | 290 | |
|
| 4 | 291 | | if (customHeaders != null) |
| | 292 | | { |
| 0 | 293 | | foreach(var _header in customHeaders) |
| | 294 | | { |
| 0 | 295 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 296 | | { |
| 0 | 297 | | _httpRequest.Headers.Remove(_header.Key); |
| | 298 | | } |
| 0 | 299 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 300 | | } |
| | 301 | | } |
| | 302 | |
|
| | 303 | | // Serialize Request |
| 4 | 304 | | string _requestContent = null; |
| 4 | 305 | | if(languageBatchInput != null) |
| | 306 | | { |
| 4 | 307 | | _requestContent = SafeJsonConvert.SerializeObject(languageBatchInput, SerializationSettings); |
| 4 | 308 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 309 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 310 | | } |
| | 311 | | // Set Credentials |
| 4 | 312 | | if (Credentials != null) |
| | 313 | | { |
| 4 | 314 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 315 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 316 | | } |
| | 317 | | // Send Request |
| 4 | 318 | | if (_shouldTrace) |
| | 319 | | { |
| 0 | 320 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 321 | | } |
| 4 | 322 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 323 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 324 | | if (_shouldTrace) |
| | 325 | | { |
| 0 | 326 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 327 | | } |
| 4 | 328 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 329 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 330 | | string _responseContent = null; |
| 4 | 331 | | if ((int)_statusCode != 200) |
| | 332 | | { |
| 0 | 333 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 334 | | try |
| | 335 | | { |
| 0 | 336 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 337 | | ErrorResponse _errorBody = SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser |
| 0 | 338 | | if (_errorBody != null) |
| | 339 | | { |
| 0 | 340 | | ex.Body = _errorBody; |
| | 341 | | } |
| 0 | 342 | | } |
| 0 | 343 | | catch (JsonException) |
| | 344 | | { |
| | 345 | | // Ignore the exception |
| 0 | 346 | | } |
| 0 | 347 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 348 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 349 | | if (_shouldTrace) |
| | 350 | | { |
| 0 | 351 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 352 | | } |
| 0 | 353 | | _httpRequest.Dispose(); |
| 0 | 354 | | if (_httpResponse != null) |
| | 355 | | { |
| 0 | 356 | | _httpResponse.Dispose(); |
| | 357 | | } |
| 0 | 358 | | throw ex; |
| | 359 | | } |
| | 360 | | // Create Result |
| 4 | 361 | | var _result = new HttpOperationResponse<LanguageBatchResult>(); |
| 4 | 362 | | _result.Request = _httpRequest; |
| 4 | 363 | | _result.Response = _httpResponse; |
| | 364 | | // Deserialize Response |
| 4 | 365 | | if ((int)_statusCode == 200) |
| | 366 | | { |
| 4 | 367 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 368 | | try |
| | 369 | | { |
| 4 | 370 | | _result.Body = SafeJsonConvert.DeserializeObject<LanguageBatchResult>(_responseContent, Deserializat |
| 4 | 371 | | } |
| 0 | 372 | | catch (JsonException ex) |
| | 373 | | { |
| 0 | 374 | | _httpRequest.Dispose(); |
| 0 | 375 | | if (_httpResponse != null) |
| | 376 | | { |
| 0 | 377 | | _httpResponse.Dispose(); |
| | 378 | | } |
| 0 | 379 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 380 | | } |
| | 381 | | } |
| 4 | 382 | | if (_shouldTrace) |
| | 383 | | { |
| 0 | 384 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 385 | | } |
| 4 | 386 | | return _result; |
| 4 | 387 | | } |
| | 388 | |
|
| | 389 | | /// <summary> |
| | 390 | | /// The API returns a list of recognized entities in a given document. |
| | 391 | | /// </summary> |
| | 392 | | /// <remarks> |
| | 393 | | /// To get even more information on each recognized entity we recommend using |
| | 394 | | /// the Bing Entity Search API by querying for the recognized entities names. |
| | 395 | | /// See the <a |
| | 396 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-lang |
| | 397 | | /// languages in Text Analytics API</a> for the list of enabled |
| | 398 | | /// languages. |
| | 399 | | /// </remarks> |
| | 400 | | /// <param name='showStats'> |
| | 401 | | /// (optional) if set to true, response will contain input and document level |
| | 402 | | /// statistics. |
| | 403 | | /// </param> |
| | 404 | | /// <param name='multiLanguageBatchInput'> |
| | 405 | | /// Collection of documents to analyze. |
| | 406 | | /// </param> |
| | 407 | | /// <param name='customHeaders'> |
| | 408 | | /// Headers that will be added to request. |
| | 409 | | /// </param> |
| | 410 | | /// <param name='cancellationToken'> |
| | 411 | | /// The cancellation token. |
| | 412 | | /// </param> |
| | 413 | | /// <exception cref="ErrorResponseException"> |
| | 414 | | /// Thrown when the operation returned an invalid status code |
| | 415 | | /// </exception> |
| | 416 | | /// <exception cref="SerializationException"> |
| | 417 | | /// Thrown when unable to deserialize the response |
| | 418 | | /// </exception> |
| | 419 | | /// <exception cref="ValidationException"> |
| | 420 | | /// Thrown when a required parameter is null |
| | 421 | | /// </exception> |
| | 422 | | /// <exception cref="System.ArgumentNullException"> |
| | 423 | | /// Thrown when a required parameter is null |
| | 424 | | /// </exception> |
| | 425 | | /// <return> |
| | 426 | | /// A response object containing the response body and response headers. |
| | 427 | | /// </return> |
| | 428 | | public async Task<HttpOperationResponse<EntitiesBatchResult>> EntitiesWithHttpMessagesAsync(bool? showStats = de |
| | 429 | | { |
| 4 | 430 | | if (Endpoint == null) |
| | 431 | | { |
| 0 | 432 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 433 | | } |
| | 434 | | // Tracing |
| 4 | 435 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 436 | | string _invocationId = null; |
| 4 | 437 | | if (_shouldTrace) |
| | 438 | | { |
| 0 | 439 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 440 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 441 | | tracingParameters.Add("showStats", showStats); |
| 0 | 442 | | tracingParameters.Add("multiLanguageBatchInput", multiLanguageBatchInput); |
| 0 | 443 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 444 | | ServiceClientTracing.Enter(_invocationId, this, "Entities", tracingParameters); |
| | 445 | | } |
| | 446 | | // Construct URL |
| 4 | 447 | | var _baseUrl = BaseUri; |
| 4 | 448 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "entities"; |
| 4 | 449 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 4 | 450 | | List<string> _queryParameters = new List<string>(); |
| 4 | 451 | | if (showStats != null) |
| | 452 | | { |
| 0 | 453 | | _queryParameters.Add(string.Format("showStats={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serializ |
| | 454 | | } |
| 4 | 455 | | if (_queryParameters.Count > 0) |
| | 456 | | { |
| 0 | 457 | | _url += "?" + string.Join("&", _queryParameters); |
| | 458 | | } |
| | 459 | | // Create HTTP transport objects |
| 4 | 460 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 461 | | HttpResponseMessage _httpResponse = null; |
| 4 | 462 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 463 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 464 | | // Set Headers |
| | 465 | |
|
| | 466 | |
|
| 4 | 467 | | if (customHeaders != null) |
| | 468 | | { |
| 0 | 469 | | foreach(var _header in customHeaders) |
| | 470 | | { |
| 0 | 471 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 472 | | { |
| 0 | 473 | | _httpRequest.Headers.Remove(_header.Key); |
| | 474 | | } |
| 0 | 475 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 476 | | } |
| | 477 | | } |
| | 478 | |
|
| | 479 | | // Serialize Request |
| 4 | 480 | | string _requestContent = null; |
| 4 | 481 | | if(multiLanguageBatchInput != null) |
| | 482 | | { |
| 4 | 483 | | _requestContent = SafeJsonConvert.SerializeObject(multiLanguageBatchInput, SerializationSettings); |
| 4 | 484 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 485 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 486 | | } |
| | 487 | | // Set Credentials |
| 4 | 488 | | if (Credentials != null) |
| | 489 | | { |
| 4 | 490 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 491 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 492 | | } |
| | 493 | | // Send Request |
| 4 | 494 | | if (_shouldTrace) |
| | 495 | | { |
| 0 | 496 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 497 | | } |
| 4 | 498 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 499 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 500 | | if (_shouldTrace) |
| | 501 | | { |
| 0 | 502 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 503 | | } |
| 4 | 504 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 505 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 506 | | string _responseContent = null; |
| 4 | 507 | | if ((int)_statusCode != 200) |
| | 508 | | { |
| 0 | 509 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 510 | | try |
| | 511 | | { |
| 0 | 512 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 513 | | ErrorResponse _errorBody = SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser |
| 0 | 514 | | if (_errorBody != null) |
| | 515 | | { |
| 0 | 516 | | ex.Body = _errorBody; |
| | 517 | | } |
| 0 | 518 | | } |
| 0 | 519 | | catch (JsonException) |
| | 520 | | { |
| | 521 | | // Ignore the exception |
| 0 | 522 | | } |
| 0 | 523 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 524 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 525 | | if (_shouldTrace) |
| | 526 | | { |
| 0 | 527 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 528 | | } |
| 0 | 529 | | _httpRequest.Dispose(); |
| 0 | 530 | | if (_httpResponse != null) |
| | 531 | | { |
| 0 | 532 | | _httpResponse.Dispose(); |
| | 533 | | } |
| 0 | 534 | | throw ex; |
| | 535 | | } |
| | 536 | | // Create Result |
| 4 | 537 | | var _result = new HttpOperationResponse<EntitiesBatchResult>(); |
| 4 | 538 | | _result.Request = _httpRequest; |
| 4 | 539 | | _result.Response = _httpResponse; |
| | 540 | | // Deserialize Response |
| 4 | 541 | | if ((int)_statusCode == 200) |
| | 542 | | { |
| 4 | 543 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 544 | | try |
| | 545 | | { |
| 4 | 546 | | _result.Body = SafeJsonConvert.DeserializeObject<EntitiesBatchResult>(_responseContent, Deserializat |
| 4 | 547 | | } |
| 0 | 548 | | catch (JsonException ex) |
| | 549 | | { |
| 0 | 550 | | _httpRequest.Dispose(); |
| 0 | 551 | | if (_httpResponse != null) |
| | 552 | | { |
| 0 | 553 | | _httpResponse.Dispose(); |
| | 554 | | } |
| 0 | 555 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 556 | | } |
| | 557 | | } |
| 4 | 558 | | if (_shouldTrace) |
| | 559 | | { |
| 0 | 560 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 561 | | } |
| 4 | 562 | | return _result; |
| 4 | 563 | | } |
| | 564 | |
|
| | 565 | | /// <summary> |
| | 566 | | /// The API returns a list of strings denoting the key talking points in the |
| | 567 | | /// input text. |
| | 568 | | /// </summary> |
| | 569 | | /// <remarks> |
| | 570 | | /// See the <a |
| | 571 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages" |
| | 572 | | /// Analytics Documentation</a> for details about the languages that are |
| | 573 | | /// supported by key phrase extraction. |
| | 574 | | /// </remarks> |
| | 575 | | /// <param name='showStats'> |
| | 576 | | /// (optional) if set to true, response will contain input and document level |
| | 577 | | /// statistics. |
| | 578 | | /// </param> |
| | 579 | | /// <param name='multiLanguageBatchInput'> |
| | 580 | | /// Collection of documents to analyze. Documents can now contain a language |
| | 581 | | /// field to indicate the text language |
| | 582 | | /// </param> |
| | 583 | | /// <param name='customHeaders'> |
| | 584 | | /// Headers that will be added to request. |
| | 585 | | /// </param> |
| | 586 | | /// <param name='cancellationToken'> |
| | 587 | | /// The cancellation token. |
| | 588 | | /// </param> |
| | 589 | | /// <exception cref="ErrorResponseException"> |
| | 590 | | /// Thrown when the operation returned an invalid status code |
| | 591 | | /// </exception> |
| | 592 | | /// <exception cref="SerializationException"> |
| | 593 | | /// Thrown when unable to deserialize the response |
| | 594 | | /// </exception> |
| | 595 | | /// <exception cref="ValidationException"> |
| | 596 | | /// Thrown when a required parameter is null |
| | 597 | | /// </exception> |
| | 598 | | /// <exception cref="System.ArgumentNullException"> |
| | 599 | | /// Thrown when a required parameter is null |
| | 600 | | /// </exception> |
| | 601 | | /// <return> |
| | 602 | | /// A response object containing the response body and response headers. |
| | 603 | | /// </return> |
| | 604 | | public async Task<HttpOperationResponse<KeyPhraseBatchResult>> KeyPhrasesWithHttpMessagesAsync(bool? showStats = |
| | 605 | | { |
| 4 | 606 | | if (Endpoint == null) |
| | 607 | | { |
| 0 | 608 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 609 | | } |
| | 610 | | // Tracing |
| 4 | 611 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 612 | | string _invocationId = null; |
| 4 | 613 | | if (_shouldTrace) |
| | 614 | | { |
| 0 | 615 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 616 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 617 | | tracingParameters.Add("showStats", showStats); |
| 0 | 618 | | tracingParameters.Add("multiLanguageBatchInput", multiLanguageBatchInput); |
| 0 | 619 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 620 | | ServiceClientTracing.Enter(_invocationId, this, "KeyPhrases", tracingParameters); |
| | 621 | | } |
| | 622 | | // Construct URL |
| 4 | 623 | | var _baseUrl = BaseUri; |
| 4 | 624 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "keyPhrases"; |
| 4 | 625 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 4 | 626 | | List<string> _queryParameters = new List<string>(); |
| 4 | 627 | | if (showStats != null) |
| | 628 | | { |
| 0 | 629 | | _queryParameters.Add(string.Format("showStats={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serializ |
| | 630 | | } |
| 4 | 631 | | if (_queryParameters.Count > 0) |
| | 632 | | { |
| 0 | 633 | | _url += "?" + string.Join("&", _queryParameters); |
| | 634 | | } |
| | 635 | | // Create HTTP transport objects |
| 4 | 636 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 637 | | HttpResponseMessage _httpResponse = null; |
| 4 | 638 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 639 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 640 | | // Set Headers |
| | 641 | |
|
| | 642 | |
|
| 4 | 643 | | if (customHeaders != null) |
| | 644 | | { |
| 0 | 645 | | foreach(var _header in customHeaders) |
| | 646 | | { |
| 0 | 647 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 648 | | { |
| 0 | 649 | | _httpRequest.Headers.Remove(_header.Key); |
| | 650 | | } |
| 0 | 651 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 652 | | } |
| | 653 | | } |
| | 654 | |
|
| | 655 | | // Serialize Request |
| 4 | 656 | | string _requestContent = null; |
| 4 | 657 | | if(multiLanguageBatchInput != null) |
| | 658 | | { |
| 4 | 659 | | _requestContent = SafeJsonConvert.SerializeObject(multiLanguageBatchInput, SerializationSettings); |
| 4 | 660 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 661 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 662 | | } |
| | 663 | | // Set Credentials |
| 4 | 664 | | if (Credentials != null) |
| | 665 | | { |
| 4 | 666 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 667 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 668 | | } |
| | 669 | | // Send Request |
| 4 | 670 | | if (_shouldTrace) |
| | 671 | | { |
| 0 | 672 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 673 | | } |
| 4 | 674 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 675 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 676 | | if (_shouldTrace) |
| | 677 | | { |
| 0 | 678 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 679 | | } |
| 4 | 680 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 681 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 682 | | string _responseContent = null; |
| 4 | 683 | | if ((int)_statusCode != 200) |
| | 684 | | { |
| 0 | 685 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 686 | | try |
| | 687 | | { |
| 0 | 688 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 689 | | ErrorResponse _errorBody = SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser |
| 0 | 690 | | if (_errorBody != null) |
| | 691 | | { |
| 0 | 692 | | ex.Body = _errorBody; |
| | 693 | | } |
| 0 | 694 | | } |
| 0 | 695 | | catch (JsonException) |
| | 696 | | { |
| | 697 | | // Ignore the exception |
| 0 | 698 | | } |
| 0 | 699 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 700 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 701 | | if (_shouldTrace) |
| | 702 | | { |
| 0 | 703 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 704 | | } |
| 0 | 705 | | _httpRequest.Dispose(); |
| 0 | 706 | | if (_httpResponse != null) |
| | 707 | | { |
| 0 | 708 | | _httpResponse.Dispose(); |
| | 709 | | } |
| 0 | 710 | | throw ex; |
| | 711 | | } |
| | 712 | | // Create Result |
| 4 | 713 | | var _result = new HttpOperationResponse<KeyPhraseBatchResult>(); |
| 4 | 714 | | _result.Request = _httpRequest; |
| 4 | 715 | | _result.Response = _httpResponse; |
| | 716 | | // Deserialize Response |
| 4 | 717 | | if ((int)_statusCode == 200) |
| | 718 | | { |
| 4 | 719 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 720 | | try |
| | 721 | | { |
| 4 | 722 | | _result.Body = SafeJsonConvert.DeserializeObject<KeyPhraseBatchResult>(_responseContent, Deserializa |
| 4 | 723 | | } |
| 0 | 724 | | catch (JsonException ex) |
| | 725 | | { |
| 0 | 726 | | _httpRequest.Dispose(); |
| 0 | 727 | | if (_httpResponse != null) |
| | 728 | | { |
| 0 | 729 | | _httpResponse.Dispose(); |
| | 730 | | } |
| 0 | 731 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 732 | | } |
| | 733 | | } |
| 4 | 734 | | if (_shouldTrace) |
| | 735 | | { |
| 0 | 736 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 737 | | } |
| 4 | 738 | | return _result; |
| 4 | 739 | | } |
| | 740 | |
|
| | 741 | | /// <summary> |
| | 742 | | /// The API returns a numeric score between 0 and 1. |
| | 743 | | /// </summary> |
| | 744 | | /// <remarks> |
| | 745 | | /// Scores close to 1 indicate positive sentiment, while scores close to 0 |
| | 746 | | /// indicate negative sentiment. A score of 0.5 indicates the lack of sentiment |
| | 747 | | /// (e.g. a factoid statement). See the <a |
| | 748 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages" |
| | 749 | | /// Analytics Documentation</a> for details about the languages that are |
| | 750 | | /// supported by sentiment analysis. |
| | 751 | | /// </remarks> |
| | 752 | | /// <param name='showStats'> |
| | 753 | | /// (optional) if set to true, response will contain input and document level |
| | 754 | | /// statistics. |
| | 755 | | /// </param> |
| | 756 | | /// <param name='multiLanguageBatchInput'> |
| | 757 | | /// Collection of documents to analyze. |
| | 758 | | /// </param> |
| | 759 | | /// <param name='customHeaders'> |
| | 760 | | /// Headers that will be added to request. |
| | 761 | | /// </param> |
| | 762 | | /// <param name='cancellationToken'> |
| | 763 | | /// The cancellation token. |
| | 764 | | /// </param> |
| | 765 | | /// <exception cref="HttpOperationException"> |
| | 766 | | /// Thrown when the operation returned an invalid status code |
| | 767 | | /// </exception> |
| | 768 | | /// <exception cref="SerializationException"> |
| | 769 | | /// Thrown when unable to deserialize the response |
| | 770 | | /// </exception> |
| | 771 | | /// <exception cref="ValidationException"> |
| | 772 | | /// Thrown when a required parameter is null |
| | 773 | | /// </exception> |
| | 774 | | /// <exception cref="System.ArgumentNullException"> |
| | 775 | | /// Thrown when a required parameter is null |
| | 776 | | /// </exception> |
| | 777 | | /// <return> |
| | 778 | | /// A response object containing the response body and response headers. |
| | 779 | | /// </return> |
| | 780 | | public async Task<HttpOperationResponse<SentimentBatchResult>> SentimentWithHttpMessagesAsync(bool? showStats = |
| | 781 | | { |
| 4 | 782 | | if (Endpoint == null) |
| | 783 | | { |
| 0 | 784 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 785 | | } |
| | 786 | | // Tracing |
| 4 | 787 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 788 | | string _invocationId = null; |
| 4 | 789 | | if (_shouldTrace) |
| | 790 | | { |
| 0 | 791 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 792 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 793 | | tracingParameters.Add("showStats", showStats); |
| 0 | 794 | | tracingParameters.Add("multiLanguageBatchInput", multiLanguageBatchInput); |
| 0 | 795 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 796 | | ServiceClientTracing.Enter(_invocationId, this, "Sentiment", tracingParameters); |
| | 797 | | } |
| | 798 | | // Construct URL |
| 4 | 799 | | var _baseUrl = BaseUri; |
| 4 | 800 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "sentiment"; |
| 4 | 801 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 4 | 802 | | List<string> _queryParameters = new List<string>(); |
| 4 | 803 | | if (showStats != null) |
| | 804 | | { |
| 0 | 805 | | _queryParameters.Add(string.Format("showStats={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serializ |
| | 806 | | } |
| 4 | 807 | | if (_queryParameters.Count > 0) |
| | 808 | | { |
| 0 | 809 | | _url += "?" + string.Join("&", _queryParameters); |
| | 810 | | } |
| | 811 | | // Create HTTP transport objects |
| 4 | 812 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 813 | | HttpResponseMessage _httpResponse = null; |
| 4 | 814 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 815 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 816 | | // Set Headers |
| | 817 | |
|
| | 818 | |
|
| 4 | 819 | | if (customHeaders != null) |
| | 820 | | { |
| 0 | 821 | | foreach(var _header in customHeaders) |
| | 822 | | { |
| 0 | 823 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 824 | | { |
| 0 | 825 | | _httpRequest.Headers.Remove(_header.Key); |
| | 826 | | } |
| 0 | 827 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 828 | | } |
| | 829 | | } |
| | 830 | |
|
| | 831 | | // Serialize Request |
| 4 | 832 | | string _requestContent = null; |
| 4 | 833 | | if(multiLanguageBatchInput != null) |
| | 834 | | { |
| 4 | 835 | | _requestContent = SafeJsonConvert.SerializeObject(multiLanguageBatchInput, SerializationSettings); |
| 4 | 836 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 837 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 838 | | } |
| | 839 | | // Set Credentials |
| 4 | 840 | | if (Credentials != null) |
| | 841 | | { |
| 4 | 842 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 843 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 844 | | } |
| | 845 | | // Send Request |
| 4 | 846 | | if (_shouldTrace) |
| | 847 | | { |
| 0 | 848 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 849 | | } |
| 4 | 850 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 851 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 852 | | if (_shouldTrace) |
| | 853 | | { |
| 0 | 854 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 855 | | } |
| 4 | 856 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 857 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 858 | | string _responseContent = null; |
| 4 | 859 | | if ((int)_statusCode != 200) |
| | 860 | | { |
| 0 | 861 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 862 | | try |
| | 863 | | { |
| 0 | 864 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 865 | | ErrorResponse _errorBody = SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser |
| 0 | 866 | | if (_errorBody != null) |
| | 867 | | { |
| 0 | 868 | | ex.Body = _errorBody; |
| | 869 | | } |
| 0 | 870 | | } |
| 0 | 871 | | catch (JsonException) |
| | 872 | | { |
| | 873 | | // Ignore the exception |
| 0 | 874 | | } |
| 0 | 875 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 876 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 877 | | if (_shouldTrace) |
| | 878 | | { |
| 0 | 879 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 880 | | } |
| 0 | 881 | | _httpRequest.Dispose(); |
| 0 | 882 | | if (_httpResponse != null) |
| | 883 | | { |
| 0 | 884 | | _httpResponse.Dispose(); |
| | 885 | | } |
| 0 | 886 | | throw ex; |
| | 887 | | } |
| | 888 | | // Create Result |
| 4 | 889 | | var _result = new HttpOperationResponse<SentimentBatchResult>(); |
| 4 | 890 | | _result.Request = _httpRequest; |
| 4 | 891 | | _result.Response = _httpResponse; |
| | 892 | | // Deserialize Response |
| 4 | 893 | | if ((int)_statusCode == 200) |
| | 894 | | { |
| 4 | 895 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 896 | | try |
| | 897 | | { |
| 4 | 898 | | _result.Body = SafeJsonConvert.DeserializeObject<SentimentBatchResult>(_responseContent, Deserializa |
| 4 | 899 | | } |
| 0 | 900 | | catch (JsonException ex) |
| | 901 | | { |
| 0 | 902 | | _httpRequest.Dispose(); |
| 0 | 903 | | if (_httpResponse != null) |
| | 904 | | { |
| 0 | 905 | | _httpResponse.Dispose(); |
| | 906 | | } |
| 0 | 907 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 908 | | } |
| | 909 | | } |
| 4 | 910 | | if (_shouldTrace) |
| | 911 | | { |
| 0 | 912 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 913 | | } |
| 4 | 914 | | return _result; |
| 4 | 915 | | } |
| | 916 | |
|
| | 917 | | } |
| | 918 | | } |