| | | 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.LUIS.Runtime |
| | | 12 | | { |
| | | 13 | | using Microsoft.Rest; |
| | | 14 | | using Models; |
| | | 15 | | using Newtonsoft.Json; |
| | | 16 | | using System.Collections; |
| | | 17 | | using System.Collections.Generic; |
| | | 18 | | using System.IO; |
| | | 19 | | using System.Linq; |
| | | 20 | | using System.Net; |
| | | 21 | | using System.Net.Http; |
| | | 22 | | using System.Threading; |
| | | 23 | | using System.Threading.Tasks; |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// PredictionOperations operations. |
| | | 27 | | /// </summary> |
| | | 28 | | public partial class PredictionOperations : IServiceOperations<LUISRuntimeClient>, IPredictionOperations |
| | | 29 | | { |
| | | 30 | | /// <summary> |
| | | 31 | | /// Initializes a new instance of the PredictionOperations class. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <param name='client'> |
| | | 34 | | /// Reference to the service client. |
| | | 35 | | /// </param> |
| | | 36 | | /// <exception cref="System.ArgumentNullException"> |
| | | 37 | | /// Thrown when a required parameter is null |
| | | 38 | | /// </exception> |
| | 8 | 39 | | public PredictionOperations(LUISRuntimeClient client) |
| | | 40 | | { |
| | 8 | 41 | | if (client == null) |
| | | 42 | | { |
| | 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | | 44 | | } |
| | 8 | 45 | | Client = client; |
| | 8 | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Gets a reference to the LUISRuntimeClient |
| | | 50 | | /// </summary> |
| | 72 | 51 | | public LUISRuntimeClient Client { get; private set; } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Gets the predictions for an application version. |
| | | 55 | | /// </summary> |
| | | 56 | | /// <param name='appId'> |
| | | 57 | | /// The application ID. |
| | | 58 | | /// </param> |
| | | 59 | | /// <param name='versionId'> |
| | | 60 | | /// The application version ID. |
| | | 61 | | /// </param> |
| | | 62 | | /// <param name='predictionRequest'> |
| | | 63 | | /// The prediction request parameters. |
| | | 64 | | /// </param> |
| | | 65 | | /// <param name='verbose'> |
| | | 66 | | /// Indicates whether to get extra metadata for the entities predictions or |
| | | 67 | | /// not. |
| | | 68 | | /// </param> |
| | | 69 | | /// <param name='showAllIntents'> |
| | | 70 | | /// Indicates whether to return all the intents in the response or just the top |
| | | 71 | | /// intent. |
| | | 72 | | /// </param> |
| | | 73 | | /// <param name='log'> |
| | | 74 | | /// Indicates whether to log the endpoint query or not. |
| | | 75 | | /// </param> |
| | | 76 | | /// <param name='customHeaders'> |
| | | 77 | | /// Headers that will be added to request. |
| | | 78 | | /// </param> |
| | | 79 | | /// <param name='cancellationToken'> |
| | | 80 | | /// The cancellation token. |
| | | 81 | | /// </param> |
| | | 82 | | /// <exception cref="ErrorException"> |
| | | 83 | | /// Thrown when the operation returned an invalid status code |
| | | 84 | | /// </exception> |
| | | 85 | | /// <exception cref="SerializationException"> |
| | | 86 | | /// Thrown when unable to deserialize the response |
| | | 87 | | /// </exception> |
| | | 88 | | /// <exception cref="ValidationException"> |
| | | 89 | | /// Thrown when a required parameter is null |
| | | 90 | | /// </exception> |
| | | 91 | | /// <exception cref="System.ArgumentNullException"> |
| | | 92 | | /// Thrown when a required parameter is null |
| | | 93 | | /// </exception> |
| | | 94 | | /// <return> |
| | | 95 | | /// A response object containing the response body and response headers. |
| | | 96 | | /// </return> |
| | | 97 | | public async Task<HttpOperationResponse<PredictionResponse>> GetVersionPredictionWithHttpMessagesAsync(System.Gu |
| | | 98 | | { |
| | 2 | 99 | | if (Client.Endpoint == null) |
| | | 100 | | { |
| | 0 | 101 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | | 102 | | } |
| | 2 | 103 | | if (versionId == null) |
| | | 104 | | { |
| | 0 | 105 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | | 106 | | } |
| | 2 | 107 | | if (predictionRequest == null) |
| | | 108 | | { |
| | 0 | 109 | | throw new ValidationException(ValidationRules.CannotBeNull, "predictionRequest"); |
| | | 110 | | } |
| | 2 | 111 | | if (predictionRequest != null) |
| | | 112 | | { |
| | 2 | 113 | | predictionRequest.Validate(); |
| | | 114 | | } |
| | | 115 | | // Tracing |
| | 2 | 116 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 2 | 117 | | string _invocationId = null; |
| | 2 | 118 | | if (_shouldTrace) |
| | | 119 | | { |
| | 0 | 120 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 121 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 122 | | tracingParameters.Add("appId", appId); |
| | 0 | 123 | | tracingParameters.Add("versionId", versionId); |
| | 0 | 124 | | tracingParameters.Add("verbose", verbose); |
| | 0 | 125 | | tracingParameters.Add("showAllIntents", showAllIntents); |
| | 0 | 126 | | tracingParameters.Add("log", log); |
| | 0 | 127 | | tracingParameters.Add("predictionRequest", predictionRequest); |
| | 0 | 128 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 129 | | ServiceClientTracing.Enter(_invocationId, this, "GetVersionPrediction", tracingParameters); |
| | | 130 | | } |
| | | 131 | | // Construct URL |
| | 2 | 132 | | var _baseUrl = Client.BaseUri; |
| | 2 | 133 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/predict"; |
| | 2 | 134 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 2 | 135 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 2 | 136 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 2 | 137 | | List<string> _queryParameters = new List<string>(); |
| | 2 | 138 | | if (verbose != null) |
| | | 139 | | { |
| | 2 | 140 | | _queryParameters.Add(string.Format("verbose={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJso |
| | | 141 | | } |
| | 2 | 142 | | if (showAllIntents != null) |
| | | 143 | | { |
| | 2 | 144 | | _queryParameters.Add(string.Format("show-all-intents={0}", System.Uri.EscapeDataString(Rest.Serializatio |
| | | 145 | | } |
| | 2 | 146 | | if (log != null) |
| | | 147 | | { |
| | 0 | 148 | | _queryParameters.Add(string.Format("log={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon |
| | | 149 | | } |
| | 2 | 150 | | if (_queryParameters.Count > 0) |
| | | 151 | | { |
| | 2 | 152 | | _url += "?" + string.Join("&", _queryParameters); |
| | | 153 | | } |
| | | 154 | | // Create HTTP transport objects |
| | 2 | 155 | | var _httpRequest = new HttpRequestMessage(); |
| | 2 | 156 | | HttpResponseMessage _httpResponse = null; |
| | 2 | 157 | | _httpRequest.Method = new HttpMethod("POST"); |
| | 2 | 158 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 159 | | // Set Headers |
| | | 160 | | |
| | | 161 | | |
| | 2 | 162 | | if (customHeaders != null) |
| | | 163 | | { |
| | 0 | 164 | | foreach(var _header in customHeaders) |
| | | 165 | | { |
| | 0 | 166 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 167 | | { |
| | 0 | 168 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 169 | | } |
| | 0 | 170 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 171 | | } |
| | | 172 | | } |
| | | 173 | | |
| | | 174 | | // Serialize Request |
| | 2 | 175 | | string _requestContent = null; |
| | 2 | 176 | | if(predictionRequest != null) |
| | | 177 | | { |
| | 2 | 178 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(predictionRequest, Client.Serializa |
| | 2 | 179 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| | 2 | 180 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | | 181 | | } |
| | | 182 | | // Set Credentials |
| | 2 | 183 | | if (Client.Credentials != null) |
| | | 184 | | { |
| | 2 | 185 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 2 | 186 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 187 | | } |
| | | 188 | | // Send Request |
| | 2 | 189 | | if (_shouldTrace) |
| | | 190 | | { |
| | 0 | 191 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 192 | | } |
| | 2 | 193 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 2 | 194 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2 | 195 | | if (_shouldTrace) |
| | | 196 | | { |
| | 0 | 197 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 198 | | } |
| | 2 | 199 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 2 | 200 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 2 | 201 | | string _responseContent = null; |
| | 2 | 202 | | if ((int)_statusCode != 200) |
| | | 203 | | { |
| | 0 | 204 | | var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | | 205 | | try |
| | | 206 | | { |
| | 0 | 207 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 208 | | Error _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<Error>(_responseContent, Cl |
| | 0 | 209 | | if (_errorBody != null) |
| | | 210 | | { |
| | 0 | 211 | | ex.Body = _errorBody; |
| | | 212 | | } |
| | 0 | 213 | | } |
| | 0 | 214 | | catch (JsonException) |
| | | 215 | | { |
| | | 216 | | // Ignore the exception |
| | 0 | 217 | | } |
| | 0 | 218 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 219 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 220 | | if (_shouldTrace) |
| | | 221 | | { |
| | 0 | 222 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 223 | | } |
| | 0 | 224 | | _httpRequest.Dispose(); |
| | 0 | 225 | | if (_httpResponse != null) |
| | | 226 | | { |
| | 0 | 227 | | _httpResponse.Dispose(); |
| | | 228 | | } |
| | 0 | 229 | | throw ex; |
| | | 230 | | } |
| | | 231 | | // Create Result |
| | 2 | 232 | | var _result = new HttpOperationResponse<PredictionResponse>(); |
| | 2 | 233 | | _result.Request = _httpRequest; |
| | 2 | 234 | | _result.Response = _httpResponse; |
| | | 235 | | // Deserialize Response |
| | 2 | 236 | | if ((int)_statusCode == 200) |
| | | 237 | | { |
| | 2 | 238 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 239 | | try |
| | | 240 | | { |
| | 2 | 241 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PredictionResponse>(_responseCon |
| | 2 | 242 | | } |
| | 0 | 243 | | catch (JsonException ex) |
| | | 244 | | { |
| | 0 | 245 | | _httpRequest.Dispose(); |
| | 0 | 246 | | if (_httpResponse != null) |
| | | 247 | | { |
| | 0 | 248 | | _httpResponse.Dispose(); |
| | | 249 | | } |
| | 0 | 250 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 251 | | } |
| | | 252 | | } |
| | 2 | 253 | | if (_shouldTrace) |
| | | 254 | | { |
| | 0 | 255 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 256 | | } |
| | 2 | 257 | | return _result; |
| | 2 | 258 | | } |
| | | 259 | | |
| | | 260 | | /// <summary> |
| | | 261 | | /// Gets the predictions for an application slot. |
| | | 262 | | /// </summary> |
| | | 263 | | /// <param name='appId'> |
| | | 264 | | /// The application ID. |
| | | 265 | | /// </param> |
| | | 266 | | /// <param name='slotName'> |
| | | 267 | | /// The application slot name. |
| | | 268 | | /// </param> |
| | | 269 | | /// <param name='predictionRequest'> |
| | | 270 | | /// The prediction request parameters. |
| | | 271 | | /// </param> |
| | | 272 | | /// <param name='verbose'> |
| | | 273 | | /// Indicates whether to get extra metadata for the entities predictions or |
| | | 274 | | /// not. |
| | | 275 | | /// </param> |
| | | 276 | | /// <param name='showAllIntents'> |
| | | 277 | | /// Indicates whether to return all the intents in the response or just the top |
| | | 278 | | /// intent. |
| | | 279 | | /// </param> |
| | | 280 | | /// <param name='log'> |
| | | 281 | | /// Indicates whether to log the endpoint query or not. |
| | | 282 | | /// </param> |
| | | 283 | | /// <param name='customHeaders'> |
| | | 284 | | /// Headers that will be added to request. |
| | | 285 | | /// </param> |
| | | 286 | | /// <param name='cancellationToken'> |
| | | 287 | | /// The cancellation token. |
| | | 288 | | /// </param> |
| | | 289 | | /// <exception cref="ErrorException"> |
| | | 290 | | /// Thrown when the operation returned an invalid status code |
| | | 291 | | /// </exception> |
| | | 292 | | /// <exception cref="SerializationException"> |
| | | 293 | | /// Thrown when unable to deserialize the response |
| | | 294 | | /// </exception> |
| | | 295 | | /// <exception cref="ValidationException"> |
| | | 296 | | /// Thrown when a required parameter is null |
| | | 297 | | /// </exception> |
| | | 298 | | /// <exception cref="System.ArgumentNullException"> |
| | | 299 | | /// Thrown when a required parameter is null |
| | | 300 | | /// </exception> |
| | | 301 | | /// <return> |
| | | 302 | | /// A response object containing the response body and response headers. |
| | | 303 | | /// </return> |
| | | 304 | | public async Task<HttpOperationResponse<PredictionResponse>> GetSlotPredictionWithHttpMessagesAsync(System.Guid |
| | | 305 | | { |
| | 6 | 306 | | if (Client.Endpoint == null) |
| | | 307 | | { |
| | 0 | 308 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | | 309 | | } |
| | 6 | 310 | | if (slotName == null) |
| | | 311 | | { |
| | 0 | 312 | | throw new ValidationException(ValidationRules.CannotBeNull, "slotName"); |
| | | 313 | | } |
| | 6 | 314 | | if (predictionRequest == null) |
| | | 315 | | { |
| | 0 | 316 | | throw new ValidationException(ValidationRules.CannotBeNull, "predictionRequest"); |
| | | 317 | | } |
| | 6 | 318 | | if (predictionRequest != null) |
| | | 319 | | { |
| | 6 | 320 | | predictionRequest.Validate(); |
| | | 321 | | } |
| | | 322 | | // Tracing |
| | 4 | 323 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 4 | 324 | | string _invocationId = null; |
| | 4 | 325 | | if (_shouldTrace) |
| | | 326 | | { |
| | 0 | 327 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 328 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 329 | | tracingParameters.Add("appId", appId); |
| | 0 | 330 | | tracingParameters.Add("slotName", slotName); |
| | 0 | 331 | | tracingParameters.Add("verbose", verbose); |
| | 0 | 332 | | tracingParameters.Add("showAllIntents", showAllIntents); |
| | 0 | 333 | | tracingParameters.Add("log", log); |
| | 0 | 334 | | tracingParameters.Add("predictionRequest", predictionRequest); |
| | 0 | 335 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 336 | | ServiceClientTracing.Enter(_invocationId, this, "GetSlotPrediction", tracingParameters); |
| | | 337 | | } |
| | | 338 | | // Construct URL |
| | 4 | 339 | | var _baseUrl = Client.BaseUri; |
| | 4 | 340 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/slots/{slotName}/predict"; |
| | 4 | 341 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 4 | 342 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 4 | 343 | | _url = _url.Replace("{slotName}", System.Uri.EscapeDataString(slotName)); |
| | 4 | 344 | | List<string> _queryParameters = new List<string>(); |
| | 4 | 345 | | if (verbose != null) |
| | | 346 | | { |
| | 2 | 347 | | _queryParameters.Add(string.Format("verbose={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJso |
| | | 348 | | } |
| | 4 | 349 | | if (showAllIntents != null) |
| | | 350 | | { |
| | 2 | 351 | | _queryParameters.Add(string.Format("show-all-intents={0}", System.Uri.EscapeDataString(Rest.Serializatio |
| | | 352 | | } |
| | 4 | 353 | | if (log != null) |
| | | 354 | | { |
| | 0 | 355 | | _queryParameters.Add(string.Format("log={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon |
| | | 356 | | } |
| | 4 | 357 | | if (_queryParameters.Count > 0) |
| | | 358 | | { |
| | 2 | 359 | | _url += "?" + string.Join("&", _queryParameters); |
| | | 360 | | } |
| | | 361 | | // Create HTTP transport objects |
| | 4 | 362 | | var _httpRequest = new HttpRequestMessage(); |
| | 4 | 363 | | HttpResponseMessage _httpResponse = null; |
| | 4 | 364 | | _httpRequest.Method = new HttpMethod("POST"); |
| | 4 | 365 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 366 | | // Set Headers |
| | | 367 | | |
| | | 368 | | |
| | 4 | 369 | | if (customHeaders != null) |
| | | 370 | | { |
| | 0 | 371 | | foreach(var _header in customHeaders) |
| | | 372 | | { |
| | 0 | 373 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 374 | | { |
| | 0 | 375 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 376 | | } |
| | 0 | 377 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 378 | | } |
| | | 379 | | } |
| | | 380 | | |
| | | 381 | | // Serialize Request |
| | 4 | 382 | | string _requestContent = null; |
| | 4 | 383 | | if(predictionRequest != null) |
| | | 384 | | { |
| | 4 | 385 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(predictionRequest, Client.Serializa |
| | 4 | 386 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| | 4 | 387 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | | 388 | | } |
| | | 389 | | // Set Credentials |
| | 4 | 390 | | if (Client.Credentials != null) |
| | | 391 | | { |
| | 4 | 392 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 4 | 393 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 394 | | } |
| | | 395 | | // Send Request |
| | 4 | 396 | | if (_shouldTrace) |
| | | 397 | | { |
| | 0 | 398 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 399 | | } |
| | 4 | 400 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 4 | 401 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4 | 402 | | if (_shouldTrace) |
| | | 403 | | { |
| | 0 | 404 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 405 | | } |
| | 4 | 406 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 4 | 407 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 4 | 408 | | string _responseContent = null; |
| | 4 | 409 | | if ((int)_statusCode != 200) |
| | | 410 | | { |
| | 2 | 411 | | var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | | 412 | | try |
| | | 413 | | { |
| | 2 | 414 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2 | 415 | | Error _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<Error>(_responseContent, Cl |
| | 2 | 416 | | if (_errorBody != null) |
| | | 417 | | { |
| | 2 | 418 | | ex.Body = _errorBody; |
| | | 419 | | } |
| | 2 | 420 | | } |
| | 0 | 421 | | catch (JsonException) |
| | | 422 | | { |
| | | 423 | | // Ignore the exception |
| | 0 | 424 | | } |
| | 2 | 425 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 2 | 426 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 2 | 427 | | if (_shouldTrace) |
| | | 428 | | { |
| | 0 | 429 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 430 | | } |
| | 2 | 431 | | _httpRequest.Dispose(); |
| | 2 | 432 | | if (_httpResponse != null) |
| | | 433 | | { |
| | 2 | 434 | | _httpResponse.Dispose(); |
| | | 435 | | } |
| | 2 | 436 | | throw ex; |
| | | 437 | | } |
| | | 438 | | // Create Result |
| | 2 | 439 | | var _result = new HttpOperationResponse<PredictionResponse>(); |
| | 2 | 440 | | _result.Request = _httpRequest; |
| | 2 | 441 | | _result.Response = _httpResponse; |
| | | 442 | | // Deserialize Response |
| | 2 | 443 | | if ((int)_statusCode == 200) |
| | | 444 | | { |
| | 2 | 445 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 446 | | try |
| | | 447 | | { |
| | 2 | 448 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PredictionResponse>(_responseCon |
| | 2 | 449 | | } |
| | 0 | 450 | | catch (JsonException ex) |
| | | 451 | | { |
| | 0 | 452 | | _httpRequest.Dispose(); |
| | 0 | 453 | | if (_httpResponse != null) |
| | | 454 | | { |
| | 0 | 455 | | _httpResponse.Dispose(); |
| | | 456 | | } |
| | 0 | 457 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 458 | | } |
| | | 459 | | } |
| | 2 | 460 | | if (_shouldTrace) |
| | | 461 | | { |
| | 0 | 462 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 463 | | } |
| | 2 | 464 | | return _result; |
| | 2 | 465 | | } |
| | | 466 | | |
| | | 467 | | } |
| | | 468 | | } |