| | 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.Authoring |
| | 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 | | /// Versions operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class Versions : IServiceOperations<LUISAuthoringClient>, IVersions |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the Versions 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> |
| 156 | 39 | | public Versions(LUISAuthoringClient client) |
| | 40 | | { |
| 156 | 41 | | if (client == null) |
| | 42 | | { |
| 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | 44 | | } |
| 156 | 45 | | Client = client; |
| 156 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Gets a reference to the LUISAuthoringClient |
| | 50 | | /// </summary> |
| 520 | 51 | | public LUISAuthoringClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Creates a new version from the selected version. |
| | 55 | | /// </summary> |
| | 56 | | /// <param name='appId'> |
| | 57 | | /// The application ID. |
| | 58 | | /// </param> |
| | 59 | | /// <param name='versionId'> |
| | 60 | | /// The version ID. |
| | 61 | | /// </param> |
| | 62 | | /// <param name='versionCloneObject'> |
| | 63 | | /// A model containing the new version ID. |
| | 64 | | /// </param> |
| | 65 | | /// <param name='customHeaders'> |
| | 66 | | /// Headers that will be added to request. |
| | 67 | | /// </param> |
| | 68 | | /// <param name='cancellationToken'> |
| | 69 | | /// The cancellation token. |
| | 70 | | /// </param> |
| | 71 | | /// <exception cref="ErrorResponseException"> |
| | 72 | | /// Thrown when the operation returned an invalid status code |
| | 73 | | /// </exception> |
| | 74 | | /// <exception cref="SerializationException"> |
| | 75 | | /// Thrown when unable to deserialize the response |
| | 76 | | /// </exception> |
| | 77 | | /// <exception cref="ValidationException"> |
| | 78 | | /// Thrown when a required parameter is null |
| | 79 | | /// </exception> |
| | 80 | | /// <exception cref="System.ArgumentNullException"> |
| | 81 | | /// Thrown when a required parameter is null |
| | 82 | | /// </exception> |
| | 83 | | /// <return> |
| | 84 | | /// A response object containing the response body and response headers. |
| | 85 | | /// </return> |
| | 86 | | public async Task<HttpOperationResponse<string>> CloneWithHttpMessagesAsync(System.Guid appId, string versionId, |
| | 87 | | { |
| 3 | 88 | | if (Client.Endpoint == null) |
| | 89 | | { |
| 0 | 90 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 91 | | } |
| 3 | 92 | | if (versionId == null) |
| | 93 | | { |
| 0 | 94 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 95 | | } |
| 3 | 96 | | if (versionCloneObject == null) |
| | 97 | | { |
| 0 | 98 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionCloneObject"); |
| | 99 | | } |
| | 100 | | // Tracing |
| 3 | 101 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 3 | 102 | | string _invocationId = null; |
| 3 | 103 | | if (_shouldTrace) |
| | 104 | | { |
| 0 | 105 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 106 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 107 | | tracingParameters.Add("appId", appId); |
| 0 | 108 | | tracingParameters.Add("versionId", versionId); |
| 0 | 109 | | tracingParameters.Add("versionCloneObject", versionCloneObject); |
| 0 | 110 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 111 | | ServiceClientTracing.Enter(_invocationId, this, "Clone", tracingParameters); |
| | 112 | | } |
| | 113 | | // Construct URL |
| 3 | 114 | | var _baseUrl = Client.BaseUri; |
| 3 | 115 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/clone"; |
| 3 | 116 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 3 | 117 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 3 | 118 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 119 | | // Create HTTP transport objects |
| 3 | 120 | | var _httpRequest = new HttpRequestMessage(); |
| 3 | 121 | | HttpResponseMessage _httpResponse = null; |
| 3 | 122 | | _httpRequest.Method = new HttpMethod("POST"); |
| 3 | 123 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 124 | | // Set Headers |
| | 125 | |
|
| | 126 | |
|
| 3 | 127 | | if (customHeaders != null) |
| | 128 | | { |
| 0 | 129 | | foreach(var _header in customHeaders) |
| | 130 | | { |
| 0 | 131 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 132 | | { |
| 0 | 133 | | _httpRequest.Headers.Remove(_header.Key); |
| | 134 | | } |
| 0 | 135 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 136 | | } |
| | 137 | | } |
| | 138 | |
|
| | 139 | | // Serialize Request |
| 3 | 140 | | string _requestContent = null; |
| 3 | 141 | | if(versionCloneObject != null) |
| | 142 | | { |
| 3 | 143 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(versionCloneObject, Client.Serializ |
| 3 | 144 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 3 | 145 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 146 | | } |
| | 147 | | // Set Credentials |
| 3 | 148 | | if (Client.Credentials != null) |
| | 149 | | { |
| 3 | 150 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 151 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 152 | | } |
| | 153 | | // Send Request |
| 3 | 154 | | if (_shouldTrace) |
| | 155 | | { |
| 0 | 156 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 157 | | } |
| 3 | 158 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 159 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 3 | 160 | | if (_shouldTrace) |
| | 161 | | { |
| 0 | 162 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 163 | | } |
| 3 | 164 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 3 | 165 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 166 | | string _responseContent = null; |
| 3 | 167 | | if ((int)_statusCode != 201) |
| | 168 | | { |
| 1 | 169 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 170 | | try |
| | 171 | | { |
| 1 | 172 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 1 | 173 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 1 | 174 | | if (_errorBody != null) |
| | 175 | | { |
| 1 | 176 | | ex.Body = _errorBody; |
| | 177 | | } |
| 1 | 178 | | } |
| 0 | 179 | | catch (JsonException) |
| | 180 | | { |
| | 181 | | // Ignore the exception |
| 0 | 182 | | } |
| 1 | 183 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 1 | 184 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 1 | 185 | | if (_shouldTrace) |
| | 186 | | { |
| 0 | 187 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 188 | | } |
| 1 | 189 | | _httpRequest.Dispose(); |
| 1 | 190 | | if (_httpResponse != null) |
| | 191 | | { |
| 1 | 192 | | _httpResponse.Dispose(); |
| | 193 | | } |
| 1 | 194 | | throw ex; |
| | 195 | | } |
| | 196 | | // Create Result |
| 2 | 197 | | var _result = new HttpOperationResponse<string>(); |
| 2 | 198 | | _result.Request = _httpRequest; |
| 2 | 199 | | _result.Response = _httpResponse; |
| | 200 | | // Deserialize Response |
| 2 | 201 | | if ((int)_statusCode == 201) |
| | 202 | | { |
| 2 | 203 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 204 | | try |
| | 205 | | { |
| 2 | 206 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client |
| 2 | 207 | | } |
| 0 | 208 | | catch (JsonException ex) |
| | 209 | | { |
| 0 | 210 | | _httpRequest.Dispose(); |
| 0 | 211 | | if (_httpResponse != null) |
| | 212 | | { |
| 0 | 213 | | _httpResponse.Dispose(); |
| | 214 | | } |
| 0 | 215 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 216 | | } |
| | 217 | | } |
| 2 | 218 | | if (_shouldTrace) |
| | 219 | | { |
| 0 | 220 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 221 | | } |
| 2 | 222 | | return _result; |
| 2 | 223 | | } |
| | 224 | |
|
| | 225 | | /// <summary> |
| | 226 | | /// Gets a list of versions for this application ID. |
| | 227 | | /// </summary> |
| | 228 | | /// <param name='appId'> |
| | 229 | | /// The application ID. |
| | 230 | | /// </param> |
| | 231 | | /// <param name='skip'> |
| | 232 | | /// The number of entries to skip. Default value is 0. |
| | 233 | | /// </param> |
| | 234 | | /// <param name='take'> |
| | 235 | | /// The number of entries to return. Maximum page size is 500. Default is 100. |
| | 236 | | /// </param> |
| | 237 | | /// <param name='customHeaders'> |
| | 238 | | /// Headers that will be added to request. |
| | 239 | | /// </param> |
| | 240 | | /// <param name='cancellationToken'> |
| | 241 | | /// The cancellation token. |
| | 242 | | /// </param> |
| | 243 | | /// <exception cref="ErrorResponseException"> |
| | 244 | | /// Thrown when the operation returned an invalid status code |
| | 245 | | /// </exception> |
| | 246 | | /// <exception cref="SerializationException"> |
| | 247 | | /// Thrown when unable to deserialize the response |
| | 248 | | /// </exception> |
| | 249 | | /// <exception cref="ValidationException"> |
| | 250 | | /// Thrown when a required parameter is null |
| | 251 | | /// </exception> |
| | 252 | | /// <exception cref="System.ArgumentNullException"> |
| | 253 | | /// Thrown when a required parameter is null |
| | 254 | | /// </exception> |
| | 255 | | /// <return> |
| | 256 | | /// A response object containing the response body and response headers. |
| | 257 | | /// </return> |
| | 258 | | public async Task<HttpOperationResponse<IList<VersionInfo>>> ListWithHttpMessagesAsync(System.Guid appId, int? s |
| | 259 | | { |
| 22 | 260 | | if (Client.Endpoint == null) |
| | 261 | | { |
| 0 | 262 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 263 | | } |
| 22 | 264 | | if (skip < 0) |
| | 265 | | { |
| 0 | 266 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "skip", 0); |
| | 267 | | } |
| 22 | 268 | | if (take > 500) |
| | 269 | | { |
| 0 | 270 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 500); |
| | 271 | | } |
| 22 | 272 | | if (take < 0) |
| | 273 | | { |
| 0 | 274 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0); |
| | 275 | | } |
| | 276 | | // Tracing |
| 22 | 277 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 22 | 278 | | string _invocationId = null; |
| 22 | 279 | | if (_shouldTrace) |
| | 280 | | { |
| 0 | 281 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 282 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 283 | | tracingParameters.Add("appId", appId); |
| 0 | 284 | | tracingParameters.Add("skip", skip); |
| 0 | 285 | | tracingParameters.Add("take", take); |
| 0 | 286 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 287 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 288 | | } |
| | 289 | | // Construct URL |
| 22 | 290 | | var _baseUrl = Client.BaseUri; |
| 22 | 291 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions"; |
| 22 | 292 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 22 | 293 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 22 | 294 | | List<string> _queryParameters = new List<string>(); |
| 22 | 295 | | if (skip != null) |
| | 296 | | { |
| 22 | 297 | | _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 298 | | } |
| 22 | 299 | | if (take != null) |
| | 300 | | { |
| 22 | 301 | | _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 302 | | } |
| 22 | 303 | | if (_queryParameters.Count > 0) |
| | 304 | | { |
| 22 | 305 | | _url += "?" + string.Join("&", _queryParameters); |
| | 306 | | } |
| | 307 | | // Create HTTP transport objects |
| 22 | 308 | | var _httpRequest = new HttpRequestMessage(); |
| 22 | 309 | | HttpResponseMessage _httpResponse = null; |
| 22 | 310 | | _httpRequest.Method = new HttpMethod("GET"); |
| 22 | 311 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 312 | | // Set Headers |
| | 313 | |
|
| | 314 | |
|
| 22 | 315 | | if (customHeaders != null) |
| | 316 | | { |
| 4 | 317 | | foreach(var _header in customHeaders) |
| | 318 | | { |
| 1 | 319 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 320 | | { |
| 0 | 321 | | _httpRequest.Headers.Remove(_header.Key); |
| | 322 | | } |
| 1 | 323 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 324 | | } |
| | 325 | | } |
| | 326 | |
|
| | 327 | | // Serialize Request |
| 22 | 328 | | string _requestContent = null; |
| | 329 | | // Set Credentials |
| 22 | 330 | | if (Client.Credentials != null) |
| | 331 | | { |
| 22 | 332 | | cancellationToken.ThrowIfCancellationRequested(); |
| 22 | 333 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 334 | | } |
| | 335 | | // Send Request |
| 22 | 336 | | if (_shouldTrace) |
| | 337 | | { |
| 0 | 338 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 339 | | } |
| 22 | 340 | | cancellationToken.ThrowIfCancellationRequested(); |
| 22 | 341 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 22 | 342 | | if (_shouldTrace) |
| | 343 | | { |
| 0 | 344 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 345 | | } |
| 22 | 346 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 22 | 347 | | cancellationToken.ThrowIfCancellationRequested(); |
| 22 | 348 | | string _responseContent = null; |
| 22 | 349 | | if ((int)_statusCode != 200) |
| | 350 | | { |
| 2 | 351 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 352 | | try |
| | 353 | | { |
| 2 | 354 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 2 | 355 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 2 | 356 | | if (_errorBody != null) |
| | 357 | | { |
| 1 | 358 | | ex.Body = _errorBody; |
| | 359 | | } |
| 2 | 360 | | } |
| 0 | 361 | | catch (JsonException) |
| | 362 | | { |
| | 363 | | // Ignore the exception |
| 0 | 364 | | } |
| 2 | 365 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 2 | 366 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 2 | 367 | | if (_shouldTrace) |
| | 368 | | { |
| 0 | 369 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 370 | | } |
| 2 | 371 | | _httpRequest.Dispose(); |
| 2 | 372 | | if (_httpResponse != null) |
| | 373 | | { |
| 2 | 374 | | _httpResponse.Dispose(); |
| | 375 | | } |
| 2 | 376 | | throw ex; |
| | 377 | | } |
| | 378 | | // Create Result |
| 20 | 379 | | var _result = new HttpOperationResponse<IList<VersionInfo>>(); |
| 20 | 380 | | _result.Request = _httpRequest; |
| 20 | 381 | | _result.Response = _httpResponse; |
| | 382 | | // Deserialize Response |
| 20 | 383 | | if ((int)_statusCode == 200) |
| | 384 | | { |
| 20 | 385 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 386 | | try |
| | 387 | | { |
| 20 | 388 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<VersionInfo>>(_responseCon |
| 20 | 389 | | } |
| 0 | 390 | | catch (JsonException ex) |
| | 391 | | { |
| 0 | 392 | | _httpRequest.Dispose(); |
| 0 | 393 | | if (_httpResponse != null) |
| | 394 | | { |
| 0 | 395 | | _httpResponse.Dispose(); |
| | 396 | | } |
| 0 | 397 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 398 | | } |
| | 399 | | } |
| 20 | 400 | | if (_shouldTrace) |
| | 401 | | { |
| 0 | 402 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 403 | | } |
| 20 | 404 | | return _result; |
| 20 | 405 | | } |
| | 406 | |
|
| | 407 | | /// <summary> |
| | 408 | | /// Gets the version information such as date created, last modified date, |
| | 409 | | /// endpoint URL, count of intents and entities, training and publishing |
| | 410 | | /// status. |
| | 411 | | /// </summary> |
| | 412 | | /// <param name='appId'> |
| | 413 | | /// The application ID. |
| | 414 | | /// </param> |
| | 415 | | /// <param name='versionId'> |
| | 416 | | /// The version ID. |
| | 417 | | /// </param> |
| | 418 | | /// <param name='customHeaders'> |
| | 419 | | /// Headers that will be added to request. |
| | 420 | | /// </param> |
| | 421 | | /// <param name='cancellationToken'> |
| | 422 | | /// The cancellation token. |
| | 423 | | /// </param> |
| | 424 | | /// <exception cref="ErrorResponseException"> |
| | 425 | | /// Thrown when the operation returned an invalid status code |
| | 426 | | /// </exception> |
| | 427 | | /// <exception cref="SerializationException"> |
| | 428 | | /// Thrown when unable to deserialize the response |
| | 429 | | /// </exception> |
| | 430 | | /// <exception cref="ValidationException"> |
| | 431 | | /// Thrown when a required parameter is null |
| | 432 | | /// </exception> |
| | 433 | | /// <exception cref="System.ArgumentNullException"> |
| | 434 | | /// Thrown when a required parameter is null |
| | 435 | | /// </exception> |
| | 436 | | /// <return> |
| | 437 | | /// A response object containing the response body and response headers. |
| | 438 | | /// </return> |
| | 439 | | public async Task<HttpOperationResponse<VersionInfo>> GetWithHttpMessagesAsync(System.Guid appId, string version |
| | 440 | | { |
| 3 | 441 | | if (Client.Endpoint == null) |
| | 442 | | { |
| 0 | 443 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 444 | | } |
| 3 | 445 | | if (versionId == null) |
| | 446 | | { |
| 0 | 447 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 448 | | } |
| | 449 | | // Tracing |
| 3 | 450 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 3 | 451 | | string _invocationId = null; |
| 3 | 452 | | if (_shouldTrace) |
| | 453 | | { |
| 0 | 454 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 455 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 456 | | tracingParameters.Add("appId", appId); |
| 0 | 457 | | tracingParameters.Add("versionId", versionId); |
| 0 | 458 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 459 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 460 | | } |
| | 461 | | // Construct URL |
| 3 | 462 | | var _baseUrl = Client.BaseUri; |
| 3 | 463 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/"; |
| 3 | 464 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 3 | 465 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 3 | 466 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 467 | | // Create HTTP transport objects |
| 3 | 468 | | var _httpRequest = new HttpRequestMessage(); |
| 3 | 469 | | HttpResponseMessage _httpResponse = null; |
| 3 | 470 | | _httpRequest.Method = new HttpMethod("GET"); |
| 3 | 471 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 472 | | // Set Headers |
| | 473 | |
|
| | 474 | |
|
| 3 | 475 | | if (customHeaders != null) |
| | 476 | | { |
| 0 | 477 | | foreach(var _header in customHeaders) |
| | 478 | | { |
| 0 | 479 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 480 | | { |
| 0 | 481 | | _httpRequest.Headers.Remove(_header.Key); |
| | 482 | | } |
| 0 | 483 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 484 | | } |
| | 485 | | } |
| | 486 | |
|
| | 487 | | // Serialize Request |
| 3 | 488 | | string _requestContent = null; |
| | 489 | | // Set Credentials |
| 3 | 490 | | if (Client.Credentials != null) |
| | 491 | | { |
| 3 | 492 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 493 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 494 | | } |
| | 495 | | // Send Request |
| 3 | 496 | | if (_shouldTrace) |
| | 497 | | { |
| 0 | 498 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 499 | | } |
| 3 | 500 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 501 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 3 | 502 | | if (_shouldTrace) |
| | 503 | | { |
| 0 | 504 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 505 | | } |
| 3 | 506 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 3 | 507 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 508 | | string _responseContent = null; |
| 3 | 509 | | if ((int)_statusCode != 200) |
| | 510 | | { |
| 1 | 511 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 512 | | try |
| | 513 | | { |
| 1 | 514 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 1 | 515 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 1 | 516 | | if (_errorBody != null) |
| | 517 | | { |
| 1 | 518 | | ex.Body = _errorBody; |
| | 519 | | } |
| 1 | 520 | | } |
| 0 | 521 | | catch (JsonException) |
| | 522 | | { |
| | 523 | | // Ignore the exception |
| 0 | 524 | | } |
| 1 | 525 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 1 | 526 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 1 | 527 | | if (_shouldTrace) |
| | 528 | | { |
| 0 | 529 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 530 | | } |
| 1 | 531 | | _httpRequest.Dispose(); |
| 1 | 532 | | if (_httpResponse != null) |
| | 533 | | { |
| 1 | 534 | | _httpResponse.Dispose(); |
| | 535 | | } |
| 1 | 536 | | throw ex; |
| | 537 | | } |
| | 538 | | // Create Result |
| 2 | 539 | | var _result = new HttpOperationResponse<VersionInfo>(); |
| 2 | 540 | | _result.Request = _httpRequest; |
| 2 | 541 | | _result.Response = _httpResponse; |
| | 542 | | // Deserialize Response |
| 2 | 543 | | if ((int)_statusCode == 200) |
| | 544 | | { |
| 2 | 545 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 546 | | try |
| | 547 | | { |
| 2 | 548 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<VersionInfo>(_responseContent, C |
| 2 | 549 | | } |
| 0 | 550 | | catch (JsonException ex) |
| | 551 | | { |
| 0 | 552 | | _httpRequest.Dispose(); |
| 0 | 553 | | if (_httpResponse != null) |
| | 554 | | { |
| 0 | 555 | | _httpResponse.Dispose(); |
| | 556 | | } |
| 0 | 557 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 558 | | } |
| | 559 | | } |
| 2 | 560 | | if (_shouldTrace) |
| | 561 | | { |
| 0 | 562 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 563 | | } |
| 2 | 564 | | return _result; |
| 2 | 565 | | } |
| | 566 | |
|
| | 567 | | /// <summary> |
| | 568 | | /// Updates the name or description of the application version. |
| | 569 | | /// </summary> |
| | 570 | | /// <param name='appId'> |
| | 571 | | /// The application ID. |
| | 572 | | /// </param> |
| | 573 | | /// <param name='versionId'> |
| | 574 | | /// The version ID. |
| | 575 | | /// </param> |
| | 576 | | /// <param name='versionUpdateObject'> |
| | 577 | | /// A model containing Name and Description of the application. |
| | 578 | | /// </param> |
| | 579 | | /// <param name='customHeaders'> |
| | 580 | | /// Headers that will be added to request. |
| | 581 | | /// </param> |
| | 582 | | /// <param name='cancellationToken'> |
| | 583 | | /// The cancellation token. |
| | 584 | | /// </param> |
| | 585 | | /// <exception cref="ErrorResponseException"> |
| | 586 | | /// Thrown when the operation returned an invalid status code |
| | 587 | | /// </exception> |
| | 588 | | /// <exception cref="SerializationException"> |
| | 589 | | /// Thrown when unable to deserialize the response |
| | 590 | | /// </exception> |
| | 591 | | /// <exception cref="ValidationException"> |
| | 592 | | /// Thrown when a required parameter is null |
| | 593 | | /// </exception> |
| | 594 | | /// <exception cref="System.ArgumentNullException"> |
| | 595 | | /// Thrown when a required parameter is null |
| | 596 | | /// </exception> |
| | 597 | | /// <return> |
| | 598 | | /// A response object containing the response body and response headers. |
| | 599 | | /// </return> |
| | 600 | | public async Task<HttpOperationResponse<OperationStatus>> UpdateWithHttpMessagesAsync(System.Guid appId, string |
| | 601 | | { |
| 3 | 602 | | if (Client.Endpoint == null) |
| | 603 | | { |
| 0 | 604 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 605 | | } |
| 3 | 606 | | if (versionId == null) |
| | 607 | | { |
| 0 | 608 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 609 | | } |
| 3 | 610 | | if (versionUpdateObject == null) |
| | 611 | | { |
| 0 | 612 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionUpdateObject"); |
| | 613 | | } |
| | 614 | | // Tracing |
| 3 | 615 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 3 | 616 | | string _invocationId = null; |
| 3 | 617 | | if (_shouldTrace) |
| | 618 | | { |
| 0 | 619 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 620 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 621 | | tracingParameters.Add("appId", appId); |
| 0 | 622 | | tracingParameters.Add("versionId", versionId); |
| 0 | 623 | | tracingParameters.Add("versionUpdateObject", versionUpdateObject); |
| 0 | 624 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 625 | | ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); |
| | 626 | | } |
| | 627 | | // Construct URL |
| 3 | 628 | | var _baseUrl = Client.BaseUri; |
| 3 | 629 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/"; |
| 3 | 630 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 3 | 631 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 3 | 632 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 633 | | // Create HTTP transport objects |
| 3 | 634 | | var _httpRequest = new HttpRequestMessage(); |
| 3 | 635 | | HttpResponseMessage _httpResponse = null; |
| 3 | 636 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 3 | 637 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 638 | | // Set Headers |
| | 639 | |
|
| | 640 | |
|
| 3 | 641 | | if (customHeaders != null) |
| | 642 | | { |
| 0 | 643 | | foreach(var _header in customHeaders) |
| | 644 | | { |
| 0 | 645 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 646 | | { |
| 0 | 647 | | _httpRequest.Headers.Remove(_header.Key); |
| | 648 | | } |
| 0 | 649 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 650 | | } |
| | 651 | | } |
| | 652 | |
|
| | 653 | | // Serialize Request |
| 3 | 654 | | string _requestContent = null; |
| 3 | 655 | | if(versionUpdateObject != null) |
| | 656 | | { |
| 3 | 657 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(versionUpdateObject, Client.Seriali |
| 3 | 658 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 3 | 659 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 660 | | } |
| | 661 | | // Set Credentials |
| 3 | 662 | | if (Client.Credentials != null) |
| | 663 | | { |
| 3 | 664 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 665 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 666 | | } |
| | 667 | | // Send Request |
| 3 | 668 | | if (_shouldTrace) |
| | 669 | | { |
| 0 | 670 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 671 | | } |
| 3 | 672 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 673 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 3 | 674 | | if (_shouldTrace) |
| | 675 | | { |
| 0 | 676 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 677 | | } |
| 3 | 678 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 3 | 679 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 680 | | string _responseContent = null; |
| 3 | 681 | | if ((int)_statusCode != 200) |
| | 682 | | { |
| 1 | 683 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 684 | | try |
| | 685 | | { |
| 1 | 686 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 1 | 687 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 1 | 688 | | if (_errorBody != null) |
| | 689 | | { |
| 1 | 690 | | ex.Body = _errorBody; |
| | 691 | | } |
| 1 | 692 | | } |
| 0 | 693 | | catch (JsonException) |
| | 694 | | { |
| | 695 | | // Ignore the exception |
| 0 | 696 | | } |
| 1 | 697 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 1 | 698 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 1 | 699 | | if (_shouldTrace) |
| | 700 | | { |
| 0 | 701 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 702 | | } |
| 1 | 703 | | _httpRequest.Dispose(); |
| 1 | 704 | | if (_httpResponse != null) |
| | 705 | | { |
| 1 | 706 | | _httpResponse.Dispose(); |
| | 707 | | } |
| 1 | 708 | | throw ex; |
| | 709 | | } |
| | 710 | | // Create Result |
| 2 | 711 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 2 | 712 | | _result.Request = _httpRequest; |
| 2 | 713 | | _result.Response = _httpResponse; |
| | 714 | | // Deserialize Response |
| 2 | 715 | | if ((int)_statusCode == 200) |
| | 716 | | { |
| 2 | 717 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 718 | | try |
| | 719 | | { |
| 2 | 720 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 2 | 721 | | } |
| 0 | 722 | | catch (JsonException ex) |
| | 723 | | { |
| 0 | 724 | | _httpRequest.Dispose(); |
| 0 | 725 | | if (_httpResponse != null) |
| | 726 | | { |
| 0 | 727 | | _httpResponse.Dispose(); |
| | 728 | | } |
| 0 | 729 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 730 | | } |
| | 731 | | } |
| 2 | 732 | | if (_shouldTrace) |
| | 733 | | { |
| 0 | 734 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 735 | | } |
| 2 | 736 | | return _result; |
| 2 | 737 | | } |
| | 738 | |
|
| | 739 | | /// <summary> |
| | 740 | | /// Deletes an application version. |
| | 741 | | /// </summary> |
| | 742 | | /// <param name='appId'> |
| | 743 | | /// The application ID. |
| | 744 | | /// </param> |
| | 745 | | /// <param name='versionId'> |
| | 746 | | /// The version ID. |
| | 747 | | /// </param> |
| | 748 | | /// <param name='customHeaders'> |
| | 749 | | /// Headers that will be added to request. |
| | 750 | | /// </param> |
| | 751 | | /// <param name='cancellationToken'> |
| | 752 | | /// The cancellation token. |
| | 753 | | /// </param> |
| | 754 | | /// <exception cref="ErrorResponseException"> |
| | 755 | | /// Thrown when the operation returned an invalid status code |
| | 756 | | /// </exception> |
| | 757 | | /// <exception cref="SerializationException"> |
| | 758 | | /// Thrown when unable to deserialize the response |
| | 759 | | /// </exception> |
| | 760 | | /// <exception cref="ValidationException"> |
| | 761 | | /// Thrown when a required parameter is null |
| | 762 | | /// </exception> |
| | 763 | | /// <exception cref="System.ArgumentNullException"> |
| | 764 | | /// Thrown when a required parameter is null |
| | 765 | | /// </exception> |
| | 766 | | /// <return> |
| | 767 | | /// A response object containing the response body and response headers. |
| | 768 | | /// </return> |
| | 769 | | public async Task<HttpOperationResponse<OperationStatus>> DeleteWithHttpMessagesAsync(System.Guid appId, string |
| | 770 | | { |
| 3 | 771 | | if (Client.Endpoint == null) |
| | 772 | | { |
| 0 | 773 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 774 | | } |
| 3 | 775 | | if (versionId == null) |
| | 776 | | { |
| 0 | 777 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 778 | | } |
| | 779 | | // Tracing |
| 3 | 780 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 3 | 781 | | string _invocationId = null; |
| 3 | 782 | | if (_shouldTrace) |
| | 783 | | { |
| 0 | 784 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 785 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 786 | | tracingParameters.Add("appId", appId); |
| 0 | 787 | | tracingParameters.Add("versionId", versionId); |
| 0 | 788 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 789 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 790 | | } |
| | 791 | | // Construct URL |
| 3 | 792 | | var _baseUrl = Client.BaseUri; |
| 3 | 793 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/"; |
| 3 | 794 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 3 | 795 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 3 | 796 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 797 | | // Create HTTP transport objects |
| 3 | 798 | | var _httpRequest = new HttpRequestMessage(); |
| 3 | 799 | | HttpResponseMessage _httpResponse = null; |
| 3 | 800 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 3 | 801 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 802 | | // Set Headers |
| | 803 | |
|
| | 804 | |
|
| 3 | 805 | | if (customHeaders != null) |
| | 806 | | { |
| 0 | 807 | | foreach(var _header in customHeaders) |
| | 808 | | { |
| 0 | 809 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 810 | | { |
| 0 | 811 | | _httpRequest.Headers.Remove(_header.Key); |
| | 812 | | } |
| 0 | 813 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 814 | | } |
| | 815 | | } |
| | 816 | |
|
| | 817 | | // Serialize Request |
| 3 | 818 | | string _requestContent = null; |
| | 819 | | // Set Credentials |
| 3 | 820 | | if (Client.Credentials != null) |
| | 821 | | { |
| 3 | 822 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 823 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 824 | | } |
| | 825 | | // Send Request |
| 3 | 826 | | if (_shouldTrace) |
| | 827 | | { |
| 0 | 828 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 829 | | } |
| 3 | 830 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 831 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 3 | 832 | | if (_shouldTrace) |
| | 833 | | { |
| 0 | 834 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 835 | | } |
| 3 | 836 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 3 | 837 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 838 | | string _responseContent = null; |
| 3 | 839 | | if ((int)_statusCode != 200) |
| | 840 | | { |
| 1 | 841 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 842 | | try |
| | 843 | | { |
| 1 | 844 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 1 | 845 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 1 | 846 | | if (_errorBody != null) |
| | 847 | | { |
| 1 | 848 | | ex.Body = _errorBody; |
| | 849 | | } |
| 1 | 850 | | } |
| 0 | 851 | | catch (JsonException) |
| | 852 | | { |
| | 853 | | // Ignore the exception |
| 0 | 854 | | } |
| 1 | 855 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 1 | 856 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 1 | 857 | | if (_shouldTrace) |
| | 858 | | { |
| 0 | 859 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 860 | | } |
| 1 | 861 | | _httpRequest.Dispose(); |
| 1 | 862 | | if (_httpResponse != null) |
| | 863 | | { |
| 1 | 864 | | _httpResponse.Dispose(); |
| | 865 | | } |
| 1 | 866 | | throw ex; |
| | 867 | | } |
| | 868 | | // Create Result |
| 2 | 869 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 2 | 870 | | _result.Request = _httpRequest; |
| 2 | 871 | | _result.Response = _httpResponse; |
| | 872 | | // Deserialize Response |
| 2 | 873 | | if ((int)_statusCode == 200) |
| | 874 | | { |
| 2 | 875 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 876 | | try |
| | 877 | | { |
| 2 | 878 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 2 | 879 | | } |
| 0 | 880 | | catch (JsonException ex) |
| | 881 | | { |
| 0 | 882 | | _httpRequest.Dispose(); |
| 0 | 883 | | if (_httpResponse != null) |
| | 884 | | { |
| 0 | 885 | | _httpResponse.Dispose(); |
| | 886 | | } |
| 0 | 887 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 888 | | } |
| | 889 | | } |
| 2 | 890 | | if (_shouldTrace) |
| | 891 | | { |
| 0 | 892 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 893 | | } |
| 2 | 894 | | return _result; |
| 2 | 895 | | } |
| | 896 | |
|
| | 897 | | /// <summary> |
| | 898 | | /// Exports a LUIS application to JSON format. |
| | 899 | | /// </summary> |
| | 900 | | /// <param name='appId'> |
| | 901 | | /// The application ID. |
| | 902 | | /// </param> |
| | 903 | | /// <param name='versionId'> |
| | 904 | | /// The version ID. |
| | 905 | | /// </param> |
| | 906 | | /// <param name='customHeaders'> |
| | 907 | | /// Headers that will be added to request. |
| | 908 | | /// </param> |
| | 909 | | /// <param name='cancellationToken'> |
| | 910 | | /// The cancellation token. |
| | 911 | | /// </param> |
| | 912 | | /// <exception cref="ErrorResponseException"> |
| | 913 | | /// Thrown when the operation returned an invalid status code |
| | 914 | | /// </exception> |
| | 915 | | /// <exception cref="SerializationException"> |
| | 916 | | /// Thrown when unable to deserialize the response |
| | 917 | | /// </exception> |
| | 918 | | /// <exception cref="ValidationException"> |
| | 919 | | /// Thrown when a required parameter is null |
| | 920 | | /// </exception> |
| | 921 | | /// <exception cref="System.ArgumentNullException"> |
| | 922 | | /// Thrown when a required parameter is null |
| | 923 | | /// </exception> |
| | 924 | | /// <return> |
| | 925 | | /// A response object containing the response body and response headers. |
| | 926 | | /// </return> |
| | 927 | | public async Task<HttpOperationResponse<LuisApp>> ExportWithHttpMessagesAsync(System.Guid appId, string versionI |
| | 928 | | { |
| 1 | 929 | | if (Client.Endpoint == null) |
| | 930 | | { |
| 0 | 931 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 932 | | } |
| 1 | 933 | | if (versionId == null) |
| | 934 | | { |
| 0 | 935 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 936 | | } |
| | 937 | | // Tracing |
| 1 | 938 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 939 | | string _invocationId = null; |
| 1 | 940 | | if (_shouldTrace) |
| | 941 | | { |
| 0 | 942 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 943 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 944 | | tracingParameters.Add("appId", appId); |
| 0 | 945 | | tracingParameters.Add("versionId", versionId); |
| 0 | 946 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 947 | | ServiceClientTracing.Enter(_invocationId, this, "Export", tracingParameters); |
| | 948 | | } |
| | 949 | | // Construct URL |
| 1 | 950 | | var _baseUrl = Client.BaseUri; |
| 1 | 951 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/export"; |
| 1 | 952 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 953 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 1 | 954 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 955 | | // Create HTTP transport objects |
| 1 | 956 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 957 | | HttpResponseMessage _httpResponse = null; |
| 1 | 958 | | _httpRequest.Method = new HttpMethod("GET"); |
| 1 | 959 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 960 | | // Set Headers |
| | 961 | |
|
| | 962 | |
|
| 1 | 963 | | if (customHeaders != null) |
| | 964 | | { |
| 0 | 965 | | foreach(var _header in customHeaders) |
| | 966 | | { |
| 0 | 967 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 968 | | { |
| 0 | 969 | | _httpRequest.Headers.Remove(_header.Key); |
| | 970 | | } |
| 0 | 971 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 972 | | } |
| | 973 | | } |
| | 974 | |
|
| | 975 | | // Serialize Request |
| 1 | 976 | | string _requestContent = null; |
| | 977 | | // Set Credentials |
| 1 | 978 | | if (Client.Credentials != null) |
| | 979 | | { |
| 1 | 980 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 981 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 982 | | } |
| | 983 | | // Send Request |
| 1 | 984 | | if (_shouldTrace) |
| | 985 | | { |
| 0 | 986 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 987 | | } |
| 1 | 988 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 989 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 990 | | if (_shouldTrace) |
| | 991 | | { |
| 0 | 992 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 993 | | } |
| 1 | 994 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 995 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 996 | | string _responseContent = null; |
| 1 | 997 | | if ((int)_statusCode != 200) |
| | 998 | | { |
| 0 | 999 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1000 | | try |
| | 1001 | | { |
| 0 | 1002 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1003 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1004 | | if (_errorBody != null) |
| | 1005 | | { |
| 0 | 1006 | | ex.Body = _errorBody; |
| | 1007 | | } |
| 0 | 1008 | | } |
| 0 | 1009 | | catch (JsonException) |
| | 1010 | | { |
| | 1011 | | // Ignore the exception |
| 0 | 1012 | | } |
| 0 | 1013 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1014 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1015 | | if (_shouldTrace) |
| | 1016 | | { |
| 0 | 1017 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1018 | | } |
| 0 | 1019 | | _httpRequest.Dispose(); |
| 0 | 1020 | | if (_httpResponse != null) |
| | 1021 | | { |
| 0 | 1022 | | _httpResponse.Dispose(); |
| | 1023 | | } |
| 0 | 1024 | | throw ex; |
| | 1025 | | } |
| | 1026 | | // Create Result |
| 1 | 1027 | | var _result = new HttpOperationResponse<LuisApp>(); |
| 1 | 1028 | | _result.Request = _httpRequest; |
| 1 | 1029 | | _result.Response = _httpResponse; |
| | 1030 | | // Deserialize Response |
| 1 | 1031 | | if ((int)_statusCode == 200) |
| | 1032 | | { |
| 1 | 1033 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1034 | | try |
| | 1035 | | { |
| 1 | 1036 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<LuisApp>(_responseContent, Clien |
| 1 | 1037 | | } |
| 0 | 1038 | | catch (JsonException ex) |
| | 1039 | | { |
| 0 | 1040 | | _httpRequest.Dispose(); |
| 0 | 1041 | | if (_httpResponse != null) |
| | 1042 | | { |
| 0 | 1043 | | _httpResponse.Dispose(); |
| | 1044 | | } |
| 0 | 1045 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1046 | | } |
| | 1047 | | } |
| 1 | 1048 | | if (_shouldTrace) |
| | 1049 | | { |
| 0 | 1050 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1051 | | } |
| 1 | 1052 | | return _result; |
| 1 | 1053 | | } |
| | 1054 | |
|
| | 1055 | | /// <summary> |
| | 1056 | | /// Imports a new version into a LUIS application. |
| | 1057 | | /// </summary> |
| | 1058 | | /// <param name='appId'> |
| | 1059 | | /// The application ID. |
| | 1060 | | /// </param> |
| | 1061 | | /// <param name='luisApp'> |
| | 1062 | | /// A LUIS application structure. |
| | 1063 | | /// </param> |
| | 1064 | | /// <param name='versionId'> |
| | 1065 | | /// The new versionId to import. If not specified, the versionId will be read |
| | 1066 | | /// from the imported object. |
| | 1067 | | /// </param> |
| | 1068 | | /// <param name='customHeaders'> |
| | 1069 | | /// Headers that will be added to request. |
| | 1070 | | /// </param> |
| | 1071 | | /// <param name='cancellationToken'> |
| | 1072 | | /// The cancellation token. |
| | 1073 | | /// </param> |
| | 1074 | | /// <exception cref="ErrorResponseException"> |
| | 1075 | | /// Thrown when the operation returned an invalid status code |
| | 1076 | | /// </exception> |
| | 1077 | | /// <exception cref="SerializationException"> |
| | 1078 | | /// Thrown when unable to deserialize the response |
| | 1079 | | /// </exception> |
| | 1080 | | /// <exception cref="ValidationException"> |
| | 1081 | | /// Thrown when a required parameter is null |
| | 1082 | | /// </exception> |
| | 1083 | | /// <exception cref="System.ArgumentNullException"> |
| | 1084 | | /// Thrown when a required parameter is null |
| | 1085 | | /// </exception> |
| | 1086 | | /// <return> |
| | 1087 | | /// A response object containing the response body and response headers. |
| | 1088 | | /// </return> |
| | 1089 | | public async Task<HttpOperationResponse<string>> ImportWithHttpMessagesAsync(System.Guid appId, LuisApp luisApp, |
| | 1090 | | { |
| 1 | 1091 | | if (Client.Endpoint == null) |
| | 1092 | | { |
| 0 | 1093 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1094 | | } |
| 1 | 1095 | | if (luisApp == null) |
| | 1096 | | { |
| 0 | 1097 | | throw new ValidationException(ValidationRules.CannotBeNull, "luisApp"); |
| | 1098 | | } |
| | 1099 | | // Tracing |
| 1 | 1100 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 1101 | | string _invocationId = null; |
| 1 | 1102 | | if (_shouldTrace) |
| | 1103 | | { |
| 0 | 1104 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1105 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1106 | | tracingParameters.Add("appId", appId); |
| 0 | 1107 | | tracingParameters.Add("versionId", versionId); |
| 0 | 1108 | | tracingParameters.Add("luisApp", luisApp); |
| 0 | 1109 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1110 | | ServiceClientTracing.Enter(_invocationId, this, "Import", tracingParameters); |
| | 1111 | | } |
| | 1112 | | // Construct URL |
| 1 | 1113 | | var _baseUrl = Client.BaseUri; |
| 1 | 1114 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/import"; |
| 1 | 1115 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 1116 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 1 | 1117 | | List<string> _queryParameters = new List<string>(); |
| 1 | 1118 | | if (versionId != null) |
| | 1119 | | { |
| 1 | 1120 | | _queryParameters.Add(string.Format("versionId={0}", System.Uri.EscapeDataString(versionId))); |
| | 1121 | | } |
| 1 | 1122 | | if (_queryParameters.Count > 0) |
| | 1123 | | { |
| 1 | 1124 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1125 | | } |
| | 1126 | | // Create HTTP transport objects |
| 1 | 1127 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 1128 | | HttpResponseMessage _httpResponse = null; |
| 1 | 1129 | | _httpRequest.Method = new HttpMethod("POST"); |
| 1 | 1130 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1131 | | // Set Headers |
| | 1132 | |
|
| | 1133 | |
|
| 1 | 1134 | | if (customHeaders != null) |
| | 1135 | | { |
| 0 | 1136 | | foreach(var _header in customHeaders) |
| | 1137 | | { |
| 0 | 1138 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1139 | | { |
| 0 | 1140 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1141 | | } |
| 0 | 1142 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1143 | | } |
| | 1144 | | } |
| | 1145 | |
|
| | 1146 | | // Serialize Request |
| 1 | 1147 | | string _requestContent = null; |
| 1 | 1148 | | if(luisApp != null) |
| | 1149 | | { |
| 1 | 1150 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(luisApp, Client.SerializationSettin |
| 1 | 1151 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 1152 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1153 | | } |
| | 1154 | | // Set Credentials |
| 1 | 1155 | | if (Client.Credentials != null) |
| | 1156 | | { |
| 1 | 1157 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1158 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1159 | | } |
| | 1160 | | // Send Request |
| 1 | 1161 | | if (_shouldTrace) |
| | 1162 | | { |
| 0 | 1163 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1164 | | } |
| 1 | 1165 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1166 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 1167 | | if (_shouldTrace) |
| | 1168 | | { |
| 0 | 1169 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1170 | | } |
| 1 | 1171 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 1172 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1173 | | string _responseContent = null; |
| 1 | 1174 | | if ((int)_statusCode != 201) |
| | 1175 | | { |
| 0 | 1176 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1177 | | try |
| | 1178 | | { |
| 0 | 1179 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1180 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1181 | | if (_errorBody != null) |
| | 1182 | | { |
| 0 | 1183 | | ex.Body = _errorBody; |
| | 1184 | | } |
| 0 | 1185 | | } |
| 0 | 1186 | | catch (JsonException) |
| | 1187 | | { |
| | 1188 | | // Ignore the exception |
| 0 | 1189 | | } |
| 0 | 1190 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1191 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1192 | | if (_shouldTrace) |
| | 1193 | | { |
| 0 | 1194 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1195 | | } |
| 0 | 1196 | | _httpRequest.Dispose(); |
| 0 | 1197 | | if (_httpResponse != null) |
| | 1198 | | { |
| 0 | 1199 | | _httpResponse.Dispose(); |
| | 1200 | | } |
| 0 | 1201 | | throw ex; |
| | 1202 | | } |
| | 1203 | | // Create Result |
| 1 | 1204 | | var _result = new HttpOperationResponse<string>(); |
| 1 | 1205 | | _result.Request = _httpRequest; |
| 1 | 1206 | | _result.Response = _httpResponse; |
| | 1207 | | // Deserialize Response |
| 1 | 1208 | | if ((int)_statusCode == 201) |
| | 1209 | | { |
| 1 | 1210 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1211 | | try |
| | 1212 | | { |
| 1 | 1213 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client |
| 1 | 1214 | | } |
| 0 | 1215 | | catch (JsonException ex) |
| | 1216 | | { |
| 0 | 1217 | | _httpRequest.Dispose(); |
| 0 | 1218 | | if (_httpResponse != null) |
| | 1219 | | { |
| 0 | 1220 | | _httpResponse.Dispose(); |
| | 1221 | | } |
| 0 | 1222 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1223 | | } |
| | 1224 | | } |
| 1 | 1225 | | if (_shouldTrace) |
| | 1226 | | { |
| 0 | 1227 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1228 | | } |
| 1 | 1229 | | return _result; |
| 1 | 1230 | | } |
| | 1231 | |
|
| | 1232 | | /// <summary> |
| | 1233 | | /// Deleted an unlabelled utterance in a version of the application. |
| | 1234 | | /// </summary> |
| | 1235 | | /// <param name='appId'> |
| | 1236 | | /// The application ID. |
| | 1237 | | /// </param> |
| | 1238 | | /// <param name='versionId'> |
| | 1239 | | /// The version ID. |
| | 1240 | | /// </param> |
| | 1241 | | /// <param name='utterance'> |
| | 1242 | | /// The utterance text to delete. |
| | 1243 | | /// </param> |
| | 1244 | | /// <param name='customHeaders'> |
| | 1245 | | /// Headers that will be added to request. |
| | 1246 | | /// </param> |
| | 1247 | | /// <param name='cancellationToken'> |
| | 1248 | | /// The cancellation token. |
| | 1249 | | /// </param> |
| | 1250 | | /// <exception cref="ErrorResponseException"> |
| | 1251 | | /// Thrown when the operation returned an invalid status code |
| | 1252 | | /// </exception> |
| | 1253 | | /// <exception cref="SerializationException"> |
| | 1254 | | /// Thrown when unable to deserialize the response |
| | 1255 | | /// </exception> |
| | 1256 | | /// <exception cref="ValidationException"> |
| | 1257 | | /// Thrown when a required parameter is null |
| | 1258 | | /// </exception> |
| | 1259 | | /// <exception cref="System.ArgumentNullException"> |
| | 1260 | | /// Thrown when a required parameter is null |
| | 1261 | | /// </exception> |
| | 1262 | | /// <return> |
| | 1263 | | /// A response object containing the response body and response headers. |
| | 1264 | | /// </return> |
| | 1265 | | public async Task<HttpOperationResponse<OperationStatus>> DeleteUnlabelledUtteranceWithHttpMessagesAsync(System. |
| | 1266 | | { |
| 0 | 1267 | | if (Client.Endpoint == null) |
| | 1268 | | { |
| 0 | 1269 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1270 | | } |
| 0 | 1271 | | if (versionId == null) |
| | 1272 | | { |
| 0 | 1273 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 1274 | | } |
| 0 | 1275 | | if (utterance == null) |
| | 1276 | | { |
| 0 | 1277 | | throw new ValidationException(ValidationRules.CannotBeNull, "utterance"); |
| | 1278 | | } |
| | 1279 | | // Tracing |
| 0 | 1280 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1281 | | string _invocationId = null; |
| 0 | 1282 | | if (_shouldTrace) |
| | 1283 | | { |
| 0 | 1284 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1285 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1286 | | tracingParameters.Add("appId", appId); |
| 0 | 1287 | | tracingParameters.Add("versionId", versionId); |
| 0 | 1288 | | tracingParameters.Add("utterance", utterance); |
| 0 | 1289 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1290 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteUnlabelledUtterance", tracingParameters); |
| | 1291 | | } |
| | 1292 | | // Construct URL |
| 0 | 1293 | | var _baseUrl = Client.BaseUri; |
| 0 | 1294 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/suggest"; |
| 0 | 1295 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1296 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 0 | 1297 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 1298 | | // Create HTTP transport objects |
| 0 | 1299 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1300 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1301 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 1302 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1303 | | // Set Headers |
| | 1304 | |
|
| | 1305 | |
|
| 0 | 1306 | | if (customHeaders != null) |
| | 1307 | | { |
| 0 | 1308 | | foreach(var _header in customHeaders) |
| | 1309 | | { |
| 0 | 1310 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1311 | | { |
| 0 | 1312 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1313 | | } |
| 0 | 1314 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1315 | | } |
| | 1316 | | } |
| | 1317 | |
|
| | 1318 | | // Serialize Request |
| 0 | 1319 | | string _requestContent = null; |
| 0 | 1320 | | if(utterance != null) |
| | 1321 | | { |
| 0 | 1322 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(utterance, Client.SerializationSett |
| 0 | 1323 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1324 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1325 | | } |
| | 1326 | | // Set Credentials |
| 0 | 1327 | | if (Client.Credentials != null) |
| | 1328 | | { |
| 0 | 1329 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1330 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1331 | | } |
| | 1332 | | // Send Request |
| 0 | 1333 | | if (_shouldTrace) |
| | 1334 | | { |
| 0 | 1335 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1336 | | } |
| 0 | 1337 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1338 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1339 | | if (_shouldTrace) |
| | 1340 | | { |
| 0 | 1341 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1342 | | } |
| 0 | 1343 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1344 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1345 | | string _responseContent = null; |
| 0 | 1346 | | if ((int)_statusCode != 200) |
| | 1347 | | { |
| 0 | 1348 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1349 | | try |
| | 1350 | | { |
| 0 | 1351 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1352 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1353 | | if (_errorBody != null) |
| | 1354 | | { |
| 0 | 1355 | | ex.Body = _errorBody; |
| | 1356 | | } |
| 0 | 1357 | | } |
| 0 | 1358 | | catch (JsonException) |
| | 1359 | | { |
| | 1360 | | // Ignore the exception |
| 0 | 1361 | | } |
| 0 | 1362 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1363 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1364 | | if (_shouldTrace) |
| | 1365 | | { |
| 0 | 1366 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1367 | | } |
| 0 | 1368 | | _httpRequest.Dispose(); |
| 0 | 1369 | | if (_httpResponse != null) |
| | 1370 | | { |
| 0 | 1371 | | _httpResponse.Dispose(); |
| | 1372 | | } |
| 0 | 1373 | | throw ex; |
| | 1374 | | } |
| | 1375 | | // Create Result |
| 0 | 1376 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 0 | 1377 | | _result.Request = _httpRequest; |
| 0 | 1378 | | _result.Response = _httpResponse; |
| | 1379 | | // Deserialize Response |
| 0 | 1380 | | if ((int)_statusCode == 200) |
| | 1381 | | { |
| 0 | 1382 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1383 | | try |
| | 1384 | | { |
| 0 | 1385 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 0 | 1386 | | } |
| 0 | 1387 | | catch (JsonException ex) |
| | 1388 | | { |
| 0 | 1389 | | _httpRequest.Dispose(); |
| 0 | 1390 | | if (_httpResponse != null) |
| | 1391 | | { |
| 0 | 1392 | | _httpResponse.Dispose(); |
| | 1393 | | } |
| 0 | 1394 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1395 | | } |
| | 1396 | | } |
| 0 | 1397 | | if (_shouldTrace) |
| | 1398 | | { |
| 0 | 1399 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1400 | | } |
| 0 | 1401 | | return _result; |
| 0 | 1402 | | } |
| | 1403 | |
|
| | 1404 | | /// <summary> |
| | 1405 | | /// Imports a new version into a LUIS application. |
| | 1406 | | /// </summary> |
| | 1407 | | /// <param name='appId'> |
| | 1408 | | /// The application ID. |
| | 1409 | | /// </param> |
| | 1410 | | /// <param name='luisAppV2'> |
| | 1411 | | /// A LUIS application structure. |
| | 1412 | | /// </param> |
| | 1413 | | /// <param name='versionId'> |
| | 1414 | | /// The new versionId to import. If not specified, the versionId will be read |
| | 1415 | | /// from the imported object. |
| | 1416 | | /// </param> |
| | 1417 | | /// <param name='customHeaders'> |
| | 1418 | | /// Headers that will be added to request. |
| | 1419 | | /// </param> |
| | 1420 | | /// <param name='cancellationToken'> |
| | 1421 | | /// The cancellation token. |
| | 1422 | | /// </param> |
| | 1423 | | /// <exception cref="ErrorResponseException"> |
| | 1424 | | /// Thrown when the operation returned an invalid status code |
| | 1425 | | /// </exception> |
| | 1426 | | /// <exception cref="SerializationException"> |
| | 1427 | | /// Thrown when unable to deserialize the response |
| | 1428 | | /// </exception> |
| | 1429 | | /// <exception cref="ValidationException"> |
| | 1430 | | /// Thrown when a required parameter is null |
| | 1431 | | /// </exception> |
| | 1432 | | /// <exception cref="System.ArgumentNullException"> |
| | 1433 | | /// Thrown when a required parameter is null |
| | 1434 | | /// </exception> |
| | 1435 | | /// <return> |
| | 1436 | | /// A response object containing the response body and response headers. |
| | 1437 | | /// </return> |
| | 1438 | | public async Task<HttpOperationResponse<string>> ImportV2AppWithHttpMessagesAsync(System.Guid appId, LuisAppV2 l |
| | 1439 | | { |
| 1 | 1440 | | if (Client.Endpoint == null) |
| | 1441 | | { |
| 0 | 1442 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1443 | | } |
| 1 | 1444 | | if (luisAppV2 == null) |
| | 1445 | | { |
| 0 | 1446 | | throw new ValidationException(ValidationRules.CannotBeNull, "luisAppV2"); |
| | 1447 | | } |
| | 1448 | | // Tracing |
| 1 | 1449 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 1450 | | string _invocationId = null; |
| 1 | 1451 | | if (_shouldTrace) |
| | 1452 | | { |
| 0 | 1453 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1454 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1455 | | tracingParameters.Add("appId", appId); |
| 0 | 1456 | | tracingParameters.Add("versionId", versionId); |
| 0 | 1457 | | tracingParameters.Add("luisAppV2", luisAppV2); |
| 0 | 1458 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1459 | | ServiceClientTracing.Enter(_invocationId, this, "ImportV2App", tracingParameters); |
| | 1460 | | } |
| | 1461 | | // Construct URL |
| 1 | 1462 | | var _baseUrl = Client.BaseUri; |
| 1 | 1463 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/import"; |
| 1 | 1464 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 1465 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 1 | 1466 | | List<string> _queryParameters = new List<string>(); |
| 1 | 1467 | | if (versionId != null) |
| | 1468 | | { |
| 1 | 1469 | | _queryParameters.Add(string.Format("versionId={0}", System.Uri.EscapeDataString(versionId))); |
| | 1470 | | } |
| 1 | 1471 | | if (_queryParameters.Count > 0) |
| | 1472 | | { |
| 1 | 1473 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1474 | | } |
| | 1475 | | // Create HTTP transport objects |
| 1 | 1476 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 1477 | | HttpResponseMessage _httpResponse = null; |
| 1 | 1478 | | _httpRequest.Method = new HttpMethod("POST"); |
| 1 | 1479 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1480 | | // Set Headers |
| | 1481 | |
|
| | 1482 | |
|
| 1 | 1483 | | if (customHeaders != null) |
| | 1484 | | { |
| 0 | 1485 | | foreach(var _header in customHeaders) |
| | 1486 | | { |
| 0 | 1487 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1488 | | { |
| 0 | 1489 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1490 | | } |
| 0 | 1491 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1492 | | } |
| | 1493 | | } |
| | 1494 | |
|
| | 1495 | | // Serialize Request |
| 1 | 1496 | | string _requestContent = null; |
| 1 | 1497 | | if(luisAppV2 != null) |
| | 1498 | | { |
| 1 | 1499 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(luisAppV2, Client.SerializationSett |
| 1 | 1500 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 1501 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1502 | | } |
| | 1503 | | // Set Credentials |
| 1 | 1504 | | if (Client.Credentials != null) |
| | 1505 | | { |
| 1 | 1506 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1507 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1508 | | } |
| | 1509 | | // Send Request |
| 1 | 1510 | | if (_shouldTrace) |
| | 1511 | | { |
| 0 | 1512 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1513 | | } |
| 1 | 1514 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1515 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 1516 | | if (_shouldTrace) |
| | 1517 | | { |
| 0 | 1518 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1519 | | } |
| 1 | 1520 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 1521 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1522 | | string _responseContent = null; |
| 1 | 1523 | | if ((int)_statusCode != 201) |
| | 1524 | | { |
| 0 | 1525 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1526 | | try |
| | 1527 | | { |
| 0 | 1528 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1529 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1530 | | if (_errorBody != null) |
| | 1531 | | { |
| 0 | 1532 | | ex.Body = _errorBody; |
| | 1533 | | } |
| 0 | 1534 | | } |
| 0 | 1535 | | catch (JsonException) |
| | 1536 | | { |
| | 1537 | | // Ignore the exception |
| 0 | 1538 | | } |
| 0 | 1539 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1540 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1541 | | if (_shouldTrace) |
| | 1542 | | { |
| 0 | 1543 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1544 | | } |
| 0 | 1545 | | _httpRequest.Dispose(); |
| 0 | 1546 | | if (_httpResponse != null) |
| | 1547 | | { |
| 0 | 1548 | | _httpResponse.Dispose(); |
| | 1549 | | } |
| 0 | 1550 | | throw ex; |
| | 1551 | | } |
| | 1552 | | // Create Result |
| 1 | 1553 | | var _result = new HttpOperationResponse<string>(); |
| 1 | 1554 | | _result.Request = _httpRequest; |
| 1 | 1555 | | _result.Response = _httpResponse; |
| | 1556 | | // Deserialize Response |
| 1 | 1557 | | if ((int)_statusCode == 201) |
| | 1558 | | { |
| 1 | 1559 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1560 | | try |
| | 1561 | | { |
| 1 | 1562 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client |
| 1 | 1563 | | } |
| 0 | 1564 | | catch (JsonException ex) |
| | 1565 | | { |
| 0 | 1566 | | _httpRequest.Dispose(); |
| 0 | 1567 | | if (_httpResponse != null) |
| | 1568 | | { |
| 0 | 1569 | | _httpResponse.Dispose(); |
| | 1570 | | } |
| 0 | 1571 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1572 | | } |
| | 1573 | | } |
| 1 | 1574 | | if (_shouldTrace) |
| | 1575 | | { |
| 0 | 1576 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1577 | | } |
| 1 | 1578 | | return _result; |
| 1 | 1579 | | } |
| | 1580 | |
|
| | 1581 | | /// <summary> |
| | 1582 | | /// Imports a new version into a LUIS application. |
| | 1583 | | /// </summary> |
| | 1584 | | /// <param name='appId'> |
| | 1585 | | /// The application ID. |
| | 1586 | | /// </param> |
| | 1587 | | /// <param name='luisAppLu'> |
| | 1588 | | /// An LU representing the LUIS application structure. |
| | 1589 | | /// </param> |
| | 1590 | | /// <param name='versionId'> |
| | 1591 | | /// The new versionId to import. If not specified, the versionId will be read |
| | 1592 | | /// from the imported object. |
| | 1593 | | /// </param> |
| | 1594 | | /// <param name='customHeaders'> |
| | 1595 | | /// Headers that will be added to request. |
| | 1596 | | /// </param> |
| | 1597 | | /// <param name='cancellationToken'> |
| | 1598 | | /// The cancellation token. |
| | 1599 | | /// </param> |
| | 1600 | | /// <exception cref="ErrorResponseException"> |
| | 1601 | | /// Thrown when the operation returned an invalid status code |
| | 1602 | | /// </exception> |
| | 1603 | | /// <exception cref="SerializationException"> |
| | 1604 | | /// Thrown when unable to deserialize the response |
| | 1605 | | /// </exception> |
| | 1606 | | /// <exception cref="ValidationException"> |
| | 1607 | | /// Thrown when a required parameter is null |
| | 1608 | | /// </exception> |
| | 1609 | | /// <exception cref="System.ArgumentNullException"> |
| | 1610 | | /// Thrown when a required parameter is null |
| | 1611 | | /// </exception> |
| | 1612 | | /// <return> |
| | 1613 | | /// A response object containing the response body and response headers. |
| | 1614 | | /// </return> |
| | 1615 | | public async Task<HttpOperationResponse<string>> ImportLuFormatWithHttpMessagesAsync(System.Guid appId, string l |
| | 1616 | | { |
| 1 | 1617 | | if (Client.Endpoint == null) |
| | 1618 | | { |
| 0 | 1619 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1620 | | } |
| 1 | 1621 | | if (luisAppLu == null) |
| | 1622 | | { |
| 0 | 1623 | | throw new ValidationException(ValidationRules.CannotBeNull, "luisAppLu"); |
| | 1624 | | } |
| | 1625 | | // Tracing |
| 1 | 1626 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 1627 | | string _invocationId = null; |
| 1 | 1628 | | if (_shouldTrace) |
| | 1629 | | { |
| 0 | 1630 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1631 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1632 | | tracingParameters.Add("appId", appId); |
| 0 | 1633 | | tracingParameters.Add("versionId", versionId); |
| 0 | 1634 | | tracingParameters.Add("luisAppLu", luisAppLu); |
| 0 | 1635 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1636 | | ServiceClientTracing.Enter(_invocationId, this, "ImportLuFormat", tracingParameters); |
| | 1637 | | } |
| | 1638 | | // Construct URL |
| 1 | 1639 | | var _baseUrl = Client.BaseUri; |
| 1 | 1640 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/import"; |
| 1 | 1641 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 1642 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 1 | 1643 | | List<string> _queryParameters = new List<string>(); |
| 1 | 1644 | | if (versionId != null) |
| | 1645 | | { |
| 1 | 1646 | | _queryParameters.Add(string.Format("versionId={0}", System.Uri.EscapeDataString(versionId))); |
| | 1647 | | } |
| 1 | 1648 | | if (_queryParameters.Count > 0) |
| | 1649 | | { |
| 1 | 1650 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1651 | | } |
| | 1652 | | // Create HTTP transport objects |
| 1 | 1653 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 1654 | | HttpResponseMessage _httpResponse = null; |
| 1 | 1655 | | _httpRequest.Method = new HttpMethod("POST"); |
| 1 | 1656 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1657 | | // Set Headers |
| | 1658 | |
|
| | 1659 | |
|
| 1 | 1660 | | if (customHeaders != null) |
| | 1661 | | { |
| 0 | 1662 | | foreach(var _header in customHeaders) |
| | 1663 | | { |
| 0 | 1664 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1665 | | { |
| 0 | 1666 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1667 | | } |
| 0 | 1668 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1669 | | } |
| | 1670 | | } |
| | 1671 | |
|
| | 1672 | | // Serialize Request |
| 1 | 1673 | | string _requestContent = null; |
| 1 | 1674 | | if(luisAppLu != null) |
| | 1675 | | { |
| 1 | 1676 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(luisAppLu, Client.SerializationSett |
| 1 | 1677 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 1678 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain |
| | 1679 | | } |
| | 1680 | | // Set Credentials |
| 1 | 1681 | | if (Client.Credentials != null) |
| | 1682 | | { |
| 1 | 1683 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1684 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1685 | | } |
| | 1686 | | // Send Request |
| 1 | 1687 | | if (_shouldTrace) |
| | 1688 | | { |
| 0 | 1689 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1690 | | } |
| 1 | 1691 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1692 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 1693 | | if (_shouldTrace) |
| | 1694 | | { |
| 0 | 1695 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1696 | | } |
| 1 | 1697 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 1698 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1699 | | string _responseContent = null; |
| 1 | 1700 | | if ((int)_statusCode != 201) |
| | 1701 | | { |
| 0 | 1702 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1703 | | try |
| | 1704 | | { |
| 0 | 1705 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1706 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1707 | | if (_errorBody != null) |
| | 1708 | | { |
| 0 | 1709 | | ex.Body = _errorBody; |
| | 1710 | | } |
| 0 | 1711 | | } |
| 0 | 1712 | | catch (JsonException) |
| | 1713 | | { |
| | 1714 | | // Ignore the exception |
| 0 | 1715 | | } |
| 0 | 1716 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1717 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1718 | | if (_shouldTrace) |
| | 1719 | | { |
| 0 | 1720 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1721 | | } |
| 0 | 1722 | | _httpRequest.Dispose(); |
| 0 | 1723 | | if (_httpResponse != null) |
| | 1724 | | { |
| 0 | 1725 | | _httpResponse.Dispose(); |
| | 1726 | | } |
| 0 | 1727 | | throw ex; |
| | 1728 | | } |
| | 1729 | | // Create Result |
| 1 | 1730 | | var _result = new HttpOperationResponse<string>(); |
| 1 | 1731 | | _result.Request = _httpRequest; |
| 1 | 1732 | | _result.Response = _httpResponse; |
| | 1733 | | // Deserialize Response |
| 1 | 1734 | | if ((int)_statusCode == 201) |
| | 1735 | | { |
| 1 | 1736 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1737 | | try |
| | 1738 | | { |
| 1 | 1739 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client |
| 1 | 1740 | | } |
| 0 | 1741 | | catch (JsonException ex) |
| | 1742 | | { |
| 0 | 1743 | | _httpRequest.Dispose(); |
| 0 | 1744 | | if (_httpResponse != null) |
| | 1745 | | { |
| 0 | 1746 | | _httpResponse.Dispose(); |
| | 1747 | | } |
| 0 | 1748 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1749 | | } |
| | 1750 | | } |
| 1 | 1751 | | if (_shouldTrace) |
| | 1752 | | { |
| 0 | 1753 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1754 | | } |
| 1 | 1755 | | return _result; |
| 1 | 1756 | | } |
| | 1757 | |
|
| | 1758 | | /// <summary> |
| | 1759 | | /// Exports a LUIS application to text format. |
| | 1760 | | /// </summary> |
| | 1761 | | /// <param name='appId'> |
| | 1762 | | /// The application ID. |
| | 1763 | | /// </param> |
| | 1764 | | /// <param name='versionId'> |
| | 1765 | | /// The version ID. |
| | 1766 | | /// </param> |
| | 1767 | | /// <param name='customHeaders'> |
| | 1768 | | /// Headers that will be added to request. |
| | 1769 | | /// </param> |
| | 1770 | | /// <param name='cancellationToken'> |
| | 1771 | | /// The cancellation token. |
| | 1772 | | /// </param> |
| | 1773 | | /// <exception cref="HttpOperationException"> |
| | 1774 | | /// Thrown when the operation returned an invalid status code |
| | 1775 | | /// </exception> |
| | 1776 | | /// <exception cref="SerializationException"> |
| | 1777 | | /// Thrown when unable to deserialize the response |
| | 1778 | | /// </exception> |
| | 1779 | | /// <exception cref="ValidationException"> |
| | 1780 | | /// Thrown when a required parameter is null |
| | 1781 | | /// </exception> |
| | 1782 | | /// <exception cref="System.ArgumentNullException"> |
| | 1783 | | /// Thrown when a required parameter is null |
| | 1784 | | /// </exception> |
| | 1785 | | /// <return> |
| | 1786 | | /// A response object containing the response body and response headers. |
| | 1787 | | /// </return> |
| | 1788 | | public async Task<HttpOperationResponse<Stream>> ExportLuFormatWithHttpMessagesAsync(System.Guid appId, string v |
| | 1789 | | { |
| 1 | 1790 | | if (Client.Endpoint == null) |
| | 1791 | | { |
| 0 | 1792 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1793 | | } |
| 1 | 1794 | | if (versionId == null) |
| | 1795 | | { |
| 0 | 1796 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 1797 | | } |
| 1 | 1798 | | string format = "lu"; |
| | 1799 | | // Tracing |
| 1 | 1800 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 1801 | | string _invocationId = null; |
| 1 | 1802 | | if (_shouldTrace) |
| | 1803 | | { |
| 0 | 1804 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1805 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1806 | | tracingParameters.Add("format", format); |
| 0 | 1807 | | tracingParameters.Add("appId", appId); |
| 0 | 1808 | | tracingParameters.Add("versionId", versionId); |
| 0 | 1809 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1810 | | ServiceClientTracing.Enter(_invocationId, this, "ExportLuFormat", tracingParameters); |
| | 1811 | | } |
| | 1812 | | // Construct URL |
| 1 | 1813 | | var _baseUrl = Client.BaseUri; |
| 1 | 1814 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/export"; |
| 1 | 1815 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 1816 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 1 | 1817 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| 1 | 1818 | | List<string> _queryParameters = new List<string>(); |
| 1 | 1819 | | if (format != null) |
| | 1820 | | { |
| 1 | 1821 | | _queryParameters.Add(string.Format("format={0}", System.Uri.EscapeDataString(format))); |
| | 1822 | | } |
| 1 | 1823 | | if (_queryParameters.Count > 0) |
| | 1824 | | { |
| 1 | 1825 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1826 | | } |
| | 1827 | | // Create HTTP transport objects |
| 1 | 1828 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 1829 | | HttpResponseMessage _httpResponse = null; |
| 1 | 1830 | | _httpRequest.Method = new HttpMethod("GET"); |
| 1 | 1831 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1832 | | // Set Headers |
| | 1833 | |
|
| | 1834 | |
|
| 1 | 1835 | | if (customHeaders != null) |
| | 1836 | | { |
| 0 | 1837 | | foreach(var _header in customHeaders) |
| | 1838 | | { |
| 0 | 1839 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1840 | | { |
| 0 | 1841 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1842 | | } |
| 0 | 1843 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1844 | | } |
| | 1845 | | } |
| | 1846 | |
|
| | 1847 | | // Serialize Request |
| 1 | 1848 | | string _requestContent = null; |
| | 1849 | | // Set Credentials |
| 1 | 1850 | | if (Client.Credentials != null) |
| | 1851 | | { |
| 1 | 1852 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1853 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1854 | | } |
| | 1855 | | // Send Request |
| 1 | 1856 | | if (_shouldTrace) |
| | 1857 | | { |
| 0 | 1858 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1859 | | } |
| 1 | 1860 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1861 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons |
| 1 | 1862 | | if (_shouldTrace) |
| | 1863 | | { |
| 0 | 1864 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1865 | | } |
| 1 | 1866 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 1867 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1868 | | string _responseContent = null; |
| 1 | 1869 | | if ((int)_statusCode != 200) |
| | 1870 | | { |
| 0 | 1871 | | var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st |
| 0 | 1872 | | if (_httpResponse.Content != null) { |
| 0 | 1873 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1874 | | } |
| | 1875 | | else { |
| 0 | 1876 | | _responseContent = string.Empty; |
| | 1877 | | } |
| 0 | 1878 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1879 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1880 | | if (_shouldTrace) |
| | 1881 | | { |
| 0 | 1882 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1883 | | } |
| 0 | 1884 | | _httpRequest.Dispose(); |
| 0 | 1885 | | if (_httpResponse != null) |
| | 1886 | | { |
| 0 | 1887 | | _httpResponse.Dispose(); |
| | 1888 | | } |
| 0 | 1889 | | throw ex; |
| | 1890 | | } |
| | 1891 | | // Create Result |
| 1 | 1892 | | var _result = new HttpOperationResponse<Stream>(); |
| 1 | 1893 | | _result.Request = _httpRequest; |
| 1 | 1894 | | _result.Response = _httpResponse; |
| | 1895 | | // Deserialize Response |
| 1 | 1896 | | if ((int)_statusCode == 200) |
| | 1897 | | { |
| 1 | 1898 | | _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); |
| | 1899 | | } |
| 1 | 1900 | | if (_shouldTrace) |
| | 1901 | | { |
| 0 | 1902 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1903 | | } |
| 1 | 1904 | | return _result; |
| 1 | 1905 | | } |
| | 1906 | |
|
| | 1907 | | } |
| | 1908 | | } |