| | 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 | | /// Apps operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class Apps : IServiceOperations<LUISAuthoringClient>, IApps |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the Apps 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 Apps(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> |
| 899 | 51 | | public LUISAuthoringClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Creates a new LUIS app. |
| | 55 | | /// </summary> |
| | 56 | | /// <param name='applicationCreateObject'> |
| | 57 | | /// An application containing Name, Description (optional), Culture, Usage |
| | 58 | | /// Scenario (optional), Domain (optional) and initial version ID (optional) of |
| | 59 | | /// the application. Default value for the version ID is "0.1". Note: the |
| | 60 | | /// culture cannot be changed after the app is created. |
| | 61 | | /// </param> |
| | 62 | | /// <param name='customHeaders'> |
| | 63 | | /// Headers that will be added to request. |
| | 64 | | /// </param> |
| | 65 | | /// <param name='cancellationToken'> |
| | 66 | | /// The cancellation token. |
| | 67 | | /// </param> |
| | 68 | | /// <exception cref="ErrorResponseException"> |
| | 69 | | /// Thrown when the operation returned an invalid status code |
| | 70 | | /// </exception> |
| | 71 | | /// <exception cref="SerializationException"> |
| | 72 | | /// Thrown when unable to deserialize the response |
| | 73 | | /// </exception> |
| | 74 | | /// <exception cref="ValidationException"> |
| | 75 | | /// Thrown when a required parameter is null |
| | 76 | | /// </exception> |
| | 77 | | /// <exception cref="System.ArgumentNullException"> |
| | 78 | | /// Thrown when a required parameter is null |
| | 79 | | /// </exception> |
| | 80 | | /// <return> |
| | 81 | | /// A response object containing the response body and response headers. |
| | 82 | | /// </return> |
| | 83 | | public async Task<HttpOperationResponse<System.Guid>> AddWithHttpMessagesAsync(ApplicationCreateObject applicati |
| | 84 | | { |
| 27 | 85 | | if (Client.Endpoint == null) |
| | 86 | | { |
| 0 | 87 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 88 | | } |
| 27 | 89 | | if (applicationCreateObject == null) |
| | 90 | | { |
| 0 | 91 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationCreateObject"); |
| | 92 | | } |
| 27 | 93 | | if (applicationCreateObject != null) |
| | 94 | | { |
| 27 | 95 | | applicationCreateObject.Validate(); |
| | 96 | | } |
| | 97 | | // Tracing |
| 27 | 98 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 27 | 99 | | string _invocationId = null; |
| 27 | 100 | | if (_shouldTrace) |
| | 101 | | { |
| 0 | 102 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 103 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 104 | | tracingParameters.Add("applicationCreateObject", applicationCreateObject); |
| 0 | 105 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 106 | | ServiceClientTracing.Enter(_invocationId, this, "Add", tracingParameters); |
| | 107 | | } |
| | 108 | | // Construct URL |
| 27 | 109 | | var _baseUrl = Client.BaseUri; |
| 27 | 110 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/"; |
| 27 | 111 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 112 | | // Create HTTP transport objects |
| 27 | 113 | | var _httpRequest = new HttpRequestMessage(); |
| 27 | 114 | | HttpResponseMessage _httpResponse = null; |
| 27 | 115 | | _httpRequest.Method = new HttpMethod("POST"); |
| 27 | 116 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 117 | | // Set Headers |
| | 118 | |
|
| | 119 | |
|
| 27 | 120 | | if (customHeaders != null) |
| | 121 | | { |
| 0 | 122 | | foreach(var _header in customHeaders) |
| | 123 | | { |
| 0 | 124 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 125 | | { |
| 0 | 126 | | _httpRequest.Headers.Remove(_header.Key); |
| | 127 | | } |
| 0 | 128 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 129 | | } |
| | 130 | | } |
| | 131 | |
|
| | 132 | | // Serialize Request |
| 27 | 133 | | string _requestContent = null; |
| 27 | 134 | | if(applicationCreateObject != null) |
| | 135 | | { |
| 27 | 136 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(applicationCreateObject, Client.Ser |
| 27 | 137 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 27 | 138 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 139 | | } |
| | 140 | | // Set Credentials |
| 27 | 141 | | if (Client.Credentials != null) |
| | 142 | | { |
| 27 | 143 | | cancellationToken.ThrowIfCancellationRequested(); |
| 27 | 144 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 145 | | } |
| | 146 | | // Send Request |
| 27 | 147 | | if (_shouldTrace) |
| | 148 | | { |
| 0 | 149 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 150 | | } |
| 27 | 151 | | cancellationToken.ThrowIfCancellationRequested(); |
| 27 | 152 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 27 | 153 | | if (_shouldTrace) |
| | 154 | | { |
| 0 | 155 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 156 | | } |
| 27 | 157 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 27 | 158 | | cancellationToken.ThrowIfCancellationRequested(); |
| 27 | 159 | | string _responseContent = null; |
| 27 | 160 | | if ((int)_statusCode != 201) |
| | 161 | | { |
| 0 | 162 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 163 | | try |
| | 164 | | { |
| 0 | 165 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 166 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 167 | | if (_errorBody != null) |
| | 168 | | { |
| 0 | 169 | | ex.Body = _errorBody; |
| | 170 | | } |
| 0 | 171 | | } |
| 0 | 172 | | catch (JsonException) |
| | 173 | | { |
| | 174 | | // Ignore the exception |
| 0 | 175 | | } |
| 0 | 176 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 177 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 178 | | if (_shouldTrace) |
| | 179 | | { |
| 0 | 180 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 181 | | } |
| 0 | 182 | | _httpRequest.Dispose(); |
| 0 | 183 | | if (_httpResponse != null) |
| | 184 | | { |
| 0 | 185 | | _httpResponse.Dispose(); |
| | 186 | | } |
| 0 | 187 | | throw ex; |
| | 188 | | } |
| | 189 | | // Create Result |
| 27 | 190 | | var _result = new HttpOperationResponse<System.Guid>(); |
| 27 | 191 | | _result.Request = _httpRequest; |
| 27 | 192 | | _result.Response = _httpResponse; |
| | 193 | | // Deserialize Response |
| 27 | 194 | | if ((int)_statusCode == 201) |
| | 195 | | { |
| 27 | 196 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 197 | | try |
| | 198 | | { |
| 27 | 199 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<System.Guid>(_responseContent, C |
| 27 | 200 | | } |
| 0 | 201 | | catch (JsonException ex) |
| | 202 | | { |
| 0 | 203 | | _httpRequest.Dispose(); |
| 0 | 204 | | if (_httpResponse != null) |
| | 205 | | { |
| 0 | 206 | | _httpResponse.Dispose(); |
| | 207 | | } |
| 0 | 208 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 209 | | } |
| | 210 | | } |
| 27 | 211 | | if (_shouldTrace) |
| | 212 | | { |
| 0 | 213 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 214 | | } |
| 27 | 215 | | return _result; |
| 27 | 216 | | } |
| | 217 | |
|
| | 218 | | /// <summary> |
| | 219 | | /// Lists all of the user's applications. |
| | 220 | | /// </summary> |
| | 221 | | /// <param name='skip'> |
| | 222 | | /// The number of entries to skip. Default value is 0. |
| | 223 | | /// </param> |
| | 224 | | /// <param name='take'> |
| | 225 | | /// The number of entries to return. Maximum page size is 500. Default is 100. |
| | 226 | | /// </param> |
| | 227 | | /// <param name='customHeaders'> |
| | 228 | | /// Headers that will be added to request. |
| | 229 | | /// </param> |
| | 230 | | /// <param name='cancellationToken'> |
| | 231 | | /// The cancellation token. |
| | 232 | | /// </param> |
| | 233 | | /// <exception cref="ErrorResponseException"> |
| | 234 | | /// Thrown when the operation returned an invalid status code |
| | 235 | | /// </exception> |
| | 236 | | /// <exception cref="SerializationException"> |
| | 237 | | /// Thrown when unable to deserialize the response |
| | 238 | | /// </exception> |
| | 239 | | /// <exception cref="ValidationException"> |
| | 240 | | /// Thrown when a required parameter is null |
| | 241 | | /// </exception> |
| | 242 | | /// <exception cref="System.ArgumentNullException"> |
| | 243 | | /// Thrown when a required parameter is null |
| | 244 | | /// </exception> |
| | 245 | | /// <return> |
| | 246 | | /// A response object containing the response body and response headers. |
| | 247 | | /// </return> |
| | 248 | | public async Task<HttpOperationResponse<IList<ApplicationInfoResponse>>> ListWithHttpMessagesAsync(int? skip = 0 |
| | 249 | | { |
| 2 | 250 | | if (Client.Endpoint == null) |
| | 251 | | { |
| 0 | 252 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 253 | | } |
| 2 | 254 | | if (skip < 0) |
| | 255 | | { |
| 0 | 256 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "skip", 0); |
| | 257 | | } |
| 2 | 258 | | if (take > 500) |
| | 259 | | { |
| 0 | 260 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 500); |
| | 261 | | } |
| 2 | 262 | | if (take < 0) |
| | 263 | | { |
| 0 | 264 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0); |
| | 265 | | } |
| | 266 | | // Tracing |
| 2 | 267 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 268 | | string _invocationId = null; |
| 2 | 269 | | if (_shouldTrace) |
| | 270 | | { |
| 0 | 271 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 272 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 273 | | tracingParameters.Add("skip", skip); |
| 0 | 274 | | tracingParameters.Add("take", take); |
| 0 | 275 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 276 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 277 | | } |
| | 278 | | // Construct URL |
| 2 | 279 | | var _baseUrl = Client.BaseUri; |
| 2 | 280 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/"; |
| 2 | 281 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 282 | | List<string> _queryParameters = new List<string>(); |
| 2 | 283 | | if (skip != null) |
| | 284 | | { |
| 2 | 285 | | _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 286 | | } |
| 2 | 287 | | if (take != null) |
| | 288 | | { |
| 2 | 289 | | _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 290 | | } |
| 2 | 291 | | if (_queryParameters.Count > 0) |
| | 292 | | { |
| 2 | 293 | | _url += "?" + string.Join("&", _queryParameters); |
| | 294 | | } |
| | 295 | | // Create HTTP transport objects |
| 2 | 296 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 297 | | HttpResponseMessage _httpResponse = null; |
| 2 | 298 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 299 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 300 | | // Set Headers |
| | 301 | |
|
| | 302 | |
|
| 2 | 303 | | if (customHeaders != null) |
| | 304 | | { |
| 0 | 305 | | foreach(var _header in customHeaders) |
| | 306 | | { |
| 0 | 307 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 308 | | { |
| 0 | 309 | | _httpRequest.Headers.Remove(_header.Key); |
| | 310 | | } |
| 0 | 311 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 312 | | } |
| | 313 | | } |
| | 314 | |
|
| | 315 | | // Serialize Request |
| 2 | 316 | | string _requestContent = null; |
| | 317 | | // Set Credentials |
| 2 | 318 | | if (Client.Credentials != null) |
| | 319 | | { |
| 2 | 320 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 321 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 322 | | } |
| | 323 | | // Send Request |
| 2 | 324 | | if (_shouldTrace) |
| | 325 | | { |
| 0 | 326 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 327 | | } |
| 2 | 328 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 329 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 330 | | if (_shouldTrace) |
| | 331 | | { |
| 0 | 332 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 333 | | } |
| 2 | 334 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 335 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 336 | | string _responseContent = null; |
| 2 | 337 | | if ((int)_statusCode != 200) |
| | 338 | | { |
| 0 | 339 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 340 | | try |
| | 341 | | { |
| 0 | 342 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 343 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 344 | | if (_errorBody != null) |
| | 345 | | { |
| 0 | 346 | | ex.Body = _errorBody; |
| | 347 | | } |
| 0 | 348 | | } |
| 0 | 349 | | catch (JsonException) |
| | 350 | | { |
| | 351 | | // Ignore the exception |
| 0 | 352 | | } |
| 0 | 353 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 354 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 355 | | if (_shouldTrace) |
| | 356 | | { |
| 0 | 357 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 358 | | } |
| 0 | 359 | | _httpRequest.Dispose(); |
| 0 | 360 | | if (_httpResponse != null) |
| | 361 | | { |
| 0 | 362 | | _httpResponse.Dispose(); |
| | 363 | | } |
| 0 | 364 | | throw ex; |
| | 365 | | } |
| | 366 | | // Create Result |
| 2 | 367 | | var _result = new HttpOperationResponse<IList<ApplicationInfoResponse>>(); |
| 2 | 368 | | _result.Request = _httpRequest; |
| 2 | 369 | | _result.Response = _httpResponse; |
| | 370 | | // Deserialize Response |
| 2 | 371 | | if ((int)_statusCode == 200) |
| | 372 | | { |
| 2 | 373 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 374 | | try |
| | 375 | | { |
| 2 | 376 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<ApplicationInfoResponse>>( |
| 2 | 377 | | } |
| 0 | 378 | | catch (JsonException ex) |
| | 379 | | { |
| 0 | 380 | | _httpRequest.Dispose(); |
| 0 | 381 | | if (_httpResponse != null) |
| | 382 | | { |
| 0 | 383 | | _httpResponse.Dispose(); |
| | 384 | | } |
| 0 | 385 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 386 | | } |
| | 387 | | } |
| 2 | 388 | | if (_shouldTrace) |
| | 389 | | { |
| 0 | 390 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 391 | | } |
| 2 | 392 | | return _result; |
| 2 | 393 | | } |
| | 394 | |
|
| | 395 | | /// <summary> |
| | 396 | | /// Imports an application to LUIS, the application's structure is included in |
| | 397 | | /// the request body. |
| | 398 | | /// </summary> |
| | 399 | | /// <param name='luisApp'> |
| | 400 | | /// A LUIS application structure. |
| | 401 | | /// </param> |
| | 402 | | /// <param name='appName'> |
| | 403 | | /// The application name to create. If not specified, the application name will |
| | 404 | | /// be read from the imported object. If the application name already exists, |
| | 405 | | /// an error is returned. |
| | 406 | | /// </param> |
| | 407 | | /// <param name='customHeaders'> |
| | 408 | | /// Headers that will be added to request. |
| | 409 | | /// </param> |
| | 410 | | /// <param name='cancellationToken'> |
| | 411 | | /// The cancellation token. |
| | 412 | | /// </param> |
| | 413 | | /// <exception cref="ErrorResponseException"> |
| | 414 | | /// Thrown when the operation returned an invalid status code |
| | 415 | | /// </exception> |
| | 416 | | /// <exception cref="SerializationException"> |
| | 417 | | /// Thrown when unable to deserialize the response |
| | 418 | | /// </exception> |
| | 419 | | /// <exception cref="ValidationException"> |
| | 420 | | /// Thrown when a required parameter is null |
| | 421 | | /// </exception> |
| | 422 | | /// <exception cref="System.ArgumentNullException"> |
| | 423 | | /// Thrown when a required parameter is null |
| | 424 | | /// </exception> |
| | 425 | | /// <return> |
| | 426 | | /// A response object containing the response body and response headers. |
| | 427 | | /// </return> |
| | 428 | | public async Task<HttpOperationResponse<System.Guid>> ImportWithHttpMessagesAsync(LuisApp luisApp, string appNam |
| | 429 | | { |
| 2 | 430 | | if (Client.Endpoint == null) |
| | 431 | | { |
| 0 | 432 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 433 | | } |
| 2 | 434 | | if (luisApp == null) |
| | 435 | | { |
| 0 | 436 | | throw new ValidationException(ValidationRules.CannotBeNull, "luisApp"); |
| | 437 | | } |
| | 438 | | // Tracing |
| 2 | 439 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 440 | | string _invocationId = null; |
| 2 | 441 | | if (_shouldTrace) |
| | 442 | | { |
| 0 | 443 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 444 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 445 | | tracingParameters.Add("appName", appName); |
| 0 | 446 | | tracingParameters.Add("luisApp", luisApp); |
| 0 | 447 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 448 | | ServiceClientTracing.Enter(_invocationId, this, "Import", tracingParameters); |
| | 449 | | } |
| | 450 | | // Construct URL |
| 2 | 451 | | var _baseUrl = Client.BaseUri; |
| 2 | 452 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/import"; |
| 2 | 453 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 454 | | List<string> _queryParameters = new List<string>(); |
| 2 | 455 | | if (appName != null) |
| | 456 | | { |
| 2 | 457 | | _queryParameters.Add(string.Format("appName={0}", System.Uri.EscapeDataString(appName))); |
| | 458 | | } |
| 2 | 459 | | if (_queryParameters.Count > 0) |
| | 460 | | { |
| 2 | 461 | | _url += "?" + string.Join("&", _queryParameters); |
| | 462 | | } |
| | 463 | | // Create HTTP transport objects |
| 2 | 464 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 465 | | HttpResponseMessage _httpResponse = null; |
| 2 | 466 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 467 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 468 | | // Set Headers |
| | 469 | |
|
| | 470 | |
|
| 2 | 471 | | if (customHeaders != null) |
| | 472 | | { |
| 0 | 473 | | foreach(var _header in customHeaders) |
| | 474 | | { |
| 0 | 475 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 476 | | { |
| 0 | 477 | | _httpRequest.Headers.Remove(_header.Key); |
| | 478 | | } |
| 0 | 479 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 480 | | } |
| | 481 | | } |
| | 482 | |
|
| | 483 | | // Serialize Request |
| 2 | 484 | | string _requestContent = null; |
| 2 | 485 | | if(luisApp != null) |
| | 486 | | { |
| 2 | 487 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(luisApp, Client.SerializationSettin |
| 2 | 488 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 2 | 489 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 490 | | } |
| | 491 | | // Set Credentials |
| 2 | 492 | | if (Client.Credentials != null) |
| | 493 | | { |
| 2 | 494 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 495 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 496 | | } |
| | 497 | | // Send Request |
| 2 | 498 | | if (_shouldTrace) |
| | 499 | | { |
| 0 | 500 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 501 | | } |
| 2 | 502 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 503 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 504 | | if (_shouldTrace) |
| | 505 | | { |
| 0 | 506 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 507 | | } |
| 2 | 508 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 509 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 510 | | string _responseContent = null; |
| 2 | 511 | | if ((int)_statusCode != 201) |
| | 512 | | { |
| 0 | 513 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 514 | | try |
| | 515 | | { |
| 0 | 516 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 517 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 518 | | if (_errorBody != null) |
| | 519 | | { |
| 0 | 520 | | ex.Body = _errorBody; |
| | 521 | | } |
| 0 | 522 | | } |
| 0 | 523 | | catch (JsonException) |
| | 524 | | { |
| | 525 | | // Ignore the exception |
| 0 | 526 | | } |
| 0 | 527 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 528 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 529 | | if (_shouldTrace) |
| | 530 | | { |
| 0 | 531 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 532 | | } |
| 0 | 533 | | _httpRequest.Dispose(); |
| 0 | 534 | | if (_httpResponse != null) |
| | 535 | | { |
| 0 | 536 | | _httpResponse.Dispose(); |
| | 537 | | } |
| 0 | 538 | | throw ex; |
| | 539 | | } |
| | 540 | | // Create Result |
| 2 | 541 | | var _result = new HttpOperationResponse<System.Guid>(); |
| 2 | 542 | | _result.Request = _httpRequest; |
| 2 | 543 | | _result.Response = _httpResponse; |
| | 544 | | // Deserialize Response |
| 2 | 545 | | if ((int)_statusCode == 201) |
| | 546 | | { |
| 2 | 547 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 548 | | try |
| | 549 | | { |
| 2 | 550 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<System.Guid>(_responseContent, C |
| 2 | 551 | | } |
| 0 | 552 | | catch (JsonException ex) |
| | 553 | | { |
| 0 | 554 | | _httpRequest.Dispose(); |
| 0 | 555 | | if (_httpResponse != null) |
| | 556 | | { |
| 0 | 557 | | _httpResponse.Dispose(); |
| | 558 | | } |
| 0 | 559 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 560 | | } |
| | 561 | | } |
| 2 | 562 | | if (_shouldTrace) |
| | 563 | | { |
| 0 | 564 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 565 | | } |
| 2 | 566 | | return _result; |
| 2 | 567 | | } |
| | 568 | |
|
| | 569 | | /// <summary> |
| | 570 | | /// Gets the endpoint URLs for the prebuilt Cortana applications. |
| | 571 | | /// </summary> |
| | 572 | | /// <param name='customHeaders'> |
| | 573 | | /// Headers that will be added to request. |
| | 574 | | /// </param> |
| | 575 | | /// <param name='cancellationToken'> |
| | 576 | | /// The cancellation token. |
| | 577 | | /// </param> |
| | 578 | | /// <exception cref="ErrorResponseException"> |
| | 579 | | /// Thrown when the operation returned an invalid status code |
| | 580 | | /// </exception> |
| | 581 | | /// <exception cref="SerializationException"> |
| | 582 | | /// Thrown when unable to deserialize the response |
| | 583 | | /// </exception> |
| | 584 | | /// <exception cref="ValidationException"> |
| | 585 | | /// Thrown when a required parameter is null |
| | 586 | | /// </exception> |
| | 587 | | /// <exception cref="System.ArgumentNullException"> |
| | 588 | | /// Thrown when a required parameter is null |
| | 589 | | /// </exception> |
| | 590 | | /// <return> |
| | 591 | | /// A response object containing the response body and response headers. |
| | 592 | | /// </return> |
| | 593 | | public async Task<HttpOperationResponse<PersonalAssistantsResponse>> ListCortanaEndpointsWithHttpMessagesAsync(D |
| | 594 | | { |
| 0 | 595 | | if (Client.Endpoint == null) |
| | 596 | | { |
| 0 | 597 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 598 | | } |
| | 599 | | // Tracing |
| 0 | 600 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 601 | | string _invocationId = null; |
| 0 | 602 | | if (_shouldTrace) |
| | 603 | | { |
| 0 | 604 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 605 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 606 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 607 | | ServiceClientTracing.Enter(_invocationId, this, "ListCortanaEndpoints", tracingParameters); |
| | 608 | | } |
| | 609 | | // Construct URL |
| 0 | 610 | | var _baseUrl = Client.BaseUri; |
| 0 | 611 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/assistants"; |
| 0 | 612 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 613 | | // Create HTTP transport objects |
| 0 | 614 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 615 | | HttpResponseMessage _httpResponse = null; |
| 0 | 616 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 617 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 618 | | // Set Headers |
| | 619 | |
|
| | 620 | |
|
| 0 | 621 | | if (customHeaders != null) |
| | 622 | | { |
| 0 | 623 | | foreach(var _header in customHeaders) |
| | 624 | | { |
| 0 | 625 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 626 | | { |
| 0 | 627 | | _httpRequest.Headers.Remove(_header.Key); |
| | 628 | | } |
| 0 | 629 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 630 | | } |
| | 631 | | } |
| | 632 | |
|
| | 633 | | // Serialize Request |
| 0 | 634 | | string _requestContent = null; |
| | 635 | | // Set Credentials |
| 0 | 636 | | if (Client.Credentials != null) |
| | 637 | | { |
| 0 | 638 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 639 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 640 | | } |
| | 641 | | // Send Request |
| 0 | 642 | | if (_shouldTrace) |
| | 643 | | { |
| 0 | 644 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 645 | | } |
| 0 | 646 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 647 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 648 | | if (_shouldTrace) |
| | 649 | | { |
| 0 | 650 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 651 | | } |
| 0 | 652 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 653 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 654 | | string _responseContent = null; |
| 0 | 655 | | if ((int)_statusCode != 200) |
| | 656 | | { |
| 0 | 657 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 658 | | try |
| | 659 | | { |
| 0 | 660 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 661 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 662 | | if (_errorBody != null) |
| | 663 | | { |
| 0 | 664 | | ex.Body = _errorBody; |
| | 665 | | } |
| 0 | 666 | | } |
| 0 | 667 | | catch (JsonException) |
| | 668 | | { |
| | 669 | | // Ignore the exception |
| 0 | 670 | | } |
| 0 | 671 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 672 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 673 | | if (_shouldTrace) |
| | 674 | | { |
| 0 | 675 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 676 | | } |
| 0 | 677 | | _httpRequest.Dispose(); |
| 0 | 678 | | if (_httpResponse != null) |
| | 679 | | { |
| 0 | 680 | | _httpResponse.Dispose(); |
| | 681 | | } |
| 0 | 682 | | throw ex; |
| | 683 | | } |
| | 684 | | // Create Result |
| 0 | 685 | | var _result = new HttpOperationResponse<PersonalAssistantsResponse>(); |
| 0 | 686 | | _result.Request = _httpRequest; |
| 0 | 687 | | _result.Response = _httpResponse; |
| | 688 | | // Deserialize Response |
| 0 | 689 | | if ((int)_statusCode == 200) |
| | 690 | | { |
| 0 | 691 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 692 | | try |
| | 693 | | { |
| 0 | 694 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersonalAssistantsResponse>(_res |
| 0 | 695 | | } |
| 0 | 696 | | catch (JsonException ex) |
| | 697 | | { |
| 0 | 698 | | _httpRequest.Dispose(); |
| 0 | 699 | | if (_httpResponse != null) |
| | 700 | | { |
| 0 | 701 | | _httpResponse.Dispose(); |
| | 702 | | } |
| 0 | 703 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 704 | | } |
| | 705 | | } |
| 0 | 706 | | if (_shouldTrace) |
| | 707 | | { |
| 0 | 708 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 709 | | } |
| 0 | 710 | | return _result; |
| 0 | 711 | | } |
| | 712 | |
|
| | 713 | | /// <summary> |
| | 714 | | /// Gets the available application domains. |
| | 715 | | /// </summary> |
| | 716 | | /// <param name='customHeaders'> |
| | 717 | | /// Headers that will be added to request. |
| | 718 | | /// </param> |
| | 719 | | /// <param name='cancellationToken'> |
| | 720 | | /// The cancellation token. |
| | 721 | | /// </param> |
| | 722 | | /// <exception cref="ErrorResponseException"> |
| | 723 | | /// Thrown when the operation returned an invalid status code |
| | 724 | | /// </exception> |
| | 725 | | /// <exception cref="SerializationException"> |
| | 726 | | /// Thrown when unable to deserialize the response |
| | 727 | | /// </exception> |
| | 728 | | /// <exception cref="ValidationException"> |
| | 729 | | /// Thrown when a required parameter is null |
| | 730 | | /// </exception> |
| | 731 | | /// <exception cref="System.ArgumentNullException"> |
| | 732 | | /// Thrown when a required parameter is null |
| | 733 | | /// </exception> |
| | 734 | | /// <return> |
| | 735 | | /// A response object containing the response body and response headers. |
| | 736 | | /// </return> |
| | 737 | | public async Task<HttpOperationResponse<IList<string>>> ListDomainsWithHttpMessagesAsync(Dictionary<string, List |
| | 738 | | { |
| 1 | 739 | | if (Client.Endpoint == null) |
| | 740 | | { |
| 0 | 741 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 742 | | } |
| | 743 | | // Tracing |
| 1 | 744 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 745 | | string _invocationId = null; |
| 1 | 746 | | if (_shouldTrace) |
| | 747 | | { |
| 0 | 748 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 749 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 750 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 751 | | ServiceClientTracing.Enter(_invocationId, this, "ListDomains", tracingParameters); |
| | 752 | | } |
| | 753 | | // Construct URL |
| 1 | 754 | | var _baseUrl = Client.BaseUri; |
| 1 | 755 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/domains"; |
| 1 | 756 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 757 | | // Create HTTP transport objects |
| 1 | 758 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 759 | | HttpResponseMessage _httpResponse = null; |
| 1 | 760 | | _httpRequest.Method = new HttpMethod("GET"); |
| 1 | 761 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 762 | | // Set Headers |
| | 763 | |
|
| | 764 | |
|
| 1 | 765 | | if (customHeaders != null) |
| | 766 | | { |
| 0 | 767 | | foreach(var _header in customHeaders) |
| | 768 | | { |
| 0 | 769 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 770 | | { |
| 0 | 771 | | _httpRequest.Headers.Remove(_header.Key); |
| | 772 | | } |
| 0 | 773 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 774 | | } |
| | 775 | | } |
| | 776 | |
|
| | 777 | | // Serialize Request |
| 1 | 778 | | string _requestContent = null; |
| | 779 | | // Set Credentials |
| 1 | 780 | | if (Client.Credentials != null) |
| | 781 | | { |
| 1 | 782 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 783 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 784 | | } |
| | 785 | | // Send Request |
| 1 | 786 | | if (_shouldTrace) |
| | 787 | | { |
| 0 | 788 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 789 | | } |
| 1 | 790 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 791 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 792 | | if (_shouldTrace) |
| | 793 | | { |
| 0 | 794 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 795 | | } |
| 1 | 796 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 797 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 798 | | string _responseContent = null; |
| 1 | 799 | | if ((int)_statusCode != 200) |
| | 800 | | { |
| 0 | 801 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 802 | | try |
| | 803 | | { |
| 0 | 804 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 805 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 806 | | if (_errorBody != null) |
| | 807 | | { |
| 0 | 808 | | ex.Body = _errorBody; |
| | 809 | | } |
| 0 | 810 | | } |
| 0 | 811 | | catch (JsonException) |
| | 812 | | { |
| | 813 | | // Ignore the exception |
| 0 | 814 | | } |
| 0 | 815 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 816 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 817 | | if (_shouldTrace) |
| | 818 | | { |
| 0 | 819 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 820 | | } |
| 0 | 821 | | _httpRequest.Dispose(); |
| 0 | 822 | | if (_httpResponse != null) |
| | 823 | | { |
| 0 | 824 | | _httpResponse.Dispose(); |
| | 825 | | } |
| 0 | 826 | | throw ex; |
| | 827 | | } |
| | 828 | | // Create Result |
| 1 | 829 | | var _result = new HttpOperationResponse<IList<string>>(); |
| 1 | 830 | | _result.Request = _httpRequest; |
| 1 | 831 | | _result.Response = _httpResponse; |
| | 832 | | // Deserialize Response |
| 1 | 833 | | if ((int)_statusCode == 200) |
| | 834 | | { |
| 1 | 835 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 836 | | try |
| | 837 | | { |
| 1 | 838 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<string>>(_responseContent, |
| 1 | 839 | | } |
| 0 | 840 | | catch (JsonException ex) |
| | 841 | | { |
| 0 | 842 | | _httpRequest.Dispose(); |
| 0 | 843 | | if (_httpResponse != null) |
| | 844 | | { |
| 0 | 845 | | _httpResponse.Dispose(); |
| | 846 | | } |
| 0 | 847 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 848 | | } |
| | 849 | | } |
| 1 | 850 | | if (_shouldTrace) |
| | 851 | | { |
| 0 | 852 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 853 | | } |
| 1 | 854 | | return _result; |
| 1 | 855 | | } |
| | 856 | |
|
| | 857 | | /// <summary> |
| | 858 | | /// Gets the application available usage scenarios. |
| | 859 | | /// </summary> |
| | 860 | | /// <param name='customHeaders'> |
| | 861 | | /// Headers that will be added to request. |
| | 862 | | /// </param> |
| | 863 | | /// <param name='cancellationToken'> |
| | 864 | | /// The cancellation token. |
| | 865 | | /// </param> |
| | 866 | | /// <exception cref="ErrorResponseException"> |
| | 867 | | /// Thrown when the operation returned an invalid status code |
| | 868 | | /// </exception> |
| | 869 | | /// <exception cref="SerializationException"> |
| | 870 | | /// Thrown when unable to deserialize the response |
| | 871 | | /// </exception> |
| | 872 | | /// <exception cref="ValidationException"> |
| | 873 | | /// Thrown when a required parameter is null |
| | 874 | | /// </exception> |
| | 875 | | /// <exception cref="System.ArgumentNullException"> |
| | 876 | | /// Thrown when a required parameter is null |
| | 877 | | /// </exception> |
| | 878 | | /// <return> |
| | 879 | | /// A response object containing the response body and response headers. |
| | 880 | | /// </return> |
| | 881 | | public async Task<HttpOperationResponse<IList<string>>> ListUsageScenariosWithHttpMessagesAsync(Dictionary<strin |
| | 882 | | { |
| 1 | 883 | | if (Client.Endpoint == null) |
| | 884 | | { |
| 0 | 885 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 886 | | } |
| | 887 | | // Tracing |
| 1 | 888 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 889 | | string _invocationId = null; |
| 1 | 890 | | if (_shouldTrace) |
| | 891 | | { |
| 0 | 892 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 893 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 894 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 895 | | ServiceClientTracing.Enter(_invocationId, this, "ListUsageScenarios", tracingParameters); |
| | 896 | | } |
| | 897 | | // Construct URL |
| 1 | 898 | | var _baseUrl = Client.BaseUri; |
| 1 | 899 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/usagescenarios"; |
| 1 | 900 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 901 | | // Create HTTP transport objects |
| 1 | 902 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 903 | | HttpResponseMessage _httpResponse = null; |
| 1 | 904 | | _httpRequest.Method = new HttpMethod("GET"); |
| 1 | 905 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 906 | | // Set Headers |
| | 907 | |
|
| | 908 | |
|
| 1 | 909 | | if (customHeaders != null) |
| | 910 | | { |
| 0 | 911 | | foreach(var _header in customHeaders) |
| | 912 | | { |
| 0 | 913 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 914 | | { |
| 0 | 915 | | _httpRequest.Headers.Remove(_header.Key); |
| | 916 | | } |
| 0 | 917 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 918 | | } |
| | 919 | | } |
| | 920 | |
|
| | 921 | | // Serialize Request |
| 1 | 922 | | string _requestContent = null; |
| | 923 | | // Set Credentials |
| 1 | 924 | | if (Client.Credentials != null) |
| | 925 | | { |
| 1 | 926 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 927 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 928 | | } |
| | 929 | | // Send Request |
| 1 | 930 | | if (_shouldTrace) |
| | 931 | | { |
| 0 | 932 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 933 | | } |
| 1 | 934 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 935 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 936 | | if (_shouldTrace) |
| | 937 | | { |
| 0 | 938 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 939 | | } |
| 1 | 940 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 941 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 942 | | string _responseContent = null; |
| 1 | 943 | | if ((int)_statusCode != 200) |
| | 944 | | { |
| 0 | 945 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 946 | | try |
| | 947 | | { |
| 0 | 948 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 949 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 950 | | if (_errorBody != null) |
| | 951 | | { |
| 0 | 952 | | ex.Body = _errorBody; |
| | 953 | | } |
| 0 | 954 | | } |
| 0 | 955 | | catch (JsonException) |
| | 956 | | { |
| | 957 | | // Ignore the exception |
| 0 | 958 | | } |
| 0 | 959 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 960 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 961 | | if (_shouldTrace) |
| | 962 | | { |
| 0 | 963 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 964 | | } |
| 0 | 965 | | _httpRequest.Dispose(); |
| 0 | 966 | | if (_httpResponse != null) |
| | 967 | | { |
| 0 | 968 | | _httpResponse.Dispose(); |
| | 969 | | } |
| 0 | 970 | | throw ex; |
| | 971 | | } |
| | 972 | | // Create Result |
| 1 | 973 | | var _result = new HttpOperationResponse<IList<string>>(); |
| 1 | 974 | | _result.Request = _httpRequest; |
| 1 | 975 | | _result.Response = _httpResponse; |
| | 976 | | // Deserialize Response |
| 1 | 977 | | if ((int)_statusCode == 200) |
| | 978 | | { |
| 1 | 979 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 980 | | try |
| | 981 | | { |
| 1 | 982 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<string>>(_responseContent, |
| 1 | 983 | | } |
| 0 | 984 | | catch (JsonException ex) |
| | 985 | | { |
| 0 | 986 | | _httpRequest.Dispose(); |
| 0 | 987 | | if (_httpResponse != null) |
| | 988 | | { |
| 0 | 989 | | _httpResponse.Dispose(); |
| | 990 | | } |
| 0 | 991 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 992 | | } |
| | 993 | | } |
| 1 | 994 | | if (_shouldTrace) |
| | 995 | | { |
| 0 | 996 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 997 | | } |
| 1 | 998 | | return _result; |
| 1 | 999 | | } |
| | 1000 | |
|
| | 1001 | | /// <summary> |
| | 1002 | | /// Gets a list of supported cultures. Cultures are equivalent to the written |
| | 1003 | | /// language and locale. For example,"en-us" represents the U.S. variation of |
| | 1004 | | /// English. |
| | 1005 | | /// </summary> |
| | 1006 | | /// <param name='customHeaders'> |
| | 1007 | | /// Headers that will be added to request. |
| | 1008 | | /// </param> |
| | 1009 | | /// <param name='cancellationToken'> |
| | 1010 | | /// The cancellation token. |
| | 1011 | | /// </param> |
| | 1012 | | /// <exception cref="ErrorResponseException"> |
| | 1013 | | /// Thrown when the operation returned an invalid status code |
| | 1014 | | /// </exception> |
| | 1015 | | /// <exception cref="SerializationException"> |
| | 1016 | | /// Thrown when unable to deserialize the response |
| | 1017 | | /// </exception> |
| | 1018 | | /// <exception cref="ValidationException"> |
| | 1019 | | /// Thrown when a required parameter is null |
| | 1020 | | /// </exception> |
| | 1021 | | /// <exception cref="System.ArgumentNullException"> |
| | 1022 | | /// Thrown when a required parameter is null |
| | 1023 | | /// </exception> |
| | 1024 | | /// <return> |
| | 1025 | | /// A response object containing the response body and response headers. |
| | 1026 | | /// </return> |
| | 1027 | | public async Task<HttpOperationResponse<IList<AvailableCulture>>> ListSupportedCulturesWithHttpMessagesAsync(Dic |
| | 1028 | | { |
| 1 | 1029 | | if (Client.Endpoint == null) |
| | 1030 | | { |
| 0 | 1031 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1032 | | } |
| | 1033 | | // Tracing |
| 1 | 1034 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 1035 | | string _invocationId = null; |
| 1 | 1036 | | if (_shouldTrace) |
| | 1037 | | { |
| 0 | 1038 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1039 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1040 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1041 | | ServiceClientTracing.Enter(_invocationId, this, "ListSupportedCultures", tracingParameters); |
| | 1042 | | } |
| | 1043 | | // Construct URL |
| 1 | 1044 | | var _baseUrl = Client.BaseUri; |
| 1 | 1045 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/cultures"; |
| 1 | 1046 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 1047 | | // Create HTTP transport objects |
| 1 | 1048 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 1049 | | HttpResponseMessage _httpResponse = null; |
| 1 | 1050 | | _httpRequest.Method = new HttpMethod("GET"); |
| 1 | 1051 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1052 | | // Set Headers |
| | 1053 | |
|
| | 1054 | |
|
| 1 | 1055 | | if (customHeaders != null) |
| | 1056 | | { |
| 0 | 1057 | | foreach(var _header in customHeaders) |
| | 1058 | | { |
| 0 | 1059 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1060 | | { |
| 0 | 1061 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1062 | | } |
| 0 | 1063 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1064 | | } |
| | 1065 | | } |
| | 1066 | |
|
| | 1067 | | // Serialize Request |
| 1 | 1068 | | string _requestContent = null; |
| | 1069 | | // Set Credentials |
| 1 | 1070 | | if (Client.Credentials != null) |
| | 1071 | | { |
| 1 | 1072 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1073 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1074 | | } |
| | 1075 | | // Send Request |
| 1 | 1076 | | if (_shouldTrace) |
| | 1077 | | { |
| 0 | 1078 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1079 | | } |
| 1 | 1080 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1081 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 1082 | | if (_shouldTrace) |
| | 1083 | | { |
| 0 | 1084 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1085 | | } |
| 1 | 1086 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 1087 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1088 | | string _responseContent = null; |
| 1 | 1089 | | if ((int)_statusCode != 200) |
| | 1090 | | { |
| 0 | 1091 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1092 | | try |
| | 1093 | | { |
| 0 | 1094 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1095 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1096 | | if (_errorBody != null) |
| | 1097 | | { |
| 0 | 1098 | | ex.Body = _errorBody; |
| | 1099 | | } |
| 0 | 1100 | | } |
| 0 | 1101 | | catch (JsonException) |
| | 1102 | | { |
| | 1103 | | // Ignore the exception |
| 0 | 1104 | | } |
| 0 | 1105 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1106 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1107 | | if (_shouldTrace) |
| | 1108 | | { |
| 0 | 1109 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1110 | | } |
| 0 | 1111 | | _httpRequest.Dispose(); |
| 0 | 1112 | | if (_httpResponse != null) |
| | 1113 | | { |
| 0 | 1114 | | _httpResponse.Dispose(); |
| | 1115 | | } |
| 0 | 1116 | | throw ex; |
| | 1117 | | } |
| | 1118 | | // Create Result |
| 1 | 1119 | | var _result = new HttpOperationResponse<IList<AvailableCulture>>(); |
| 1 | 1120 | | _result.Request = _httpRequest; |
| 1 | 1121 | | _result.Response = _httpResponse; |
| | 1122 | | // Deserialize Response |
| 1 | 1123 | | if ((int)_statusCode == 200) |
| | 1124 | | { |
| 1 | 1125 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1126 | | try |
| | 1127 | | { |
| 1 | 1128 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<AvailableCulture>>(_respon |
| 1 | 1129 | | } |
| 0 | 1130 | | catch (JsonException ex) |
| | 1131 | | { |
| 0 | 1132 | | _httpRequest.Dispose(); |
| 0 | 1133 | | if (_httpResponse != null) |
| | 1134 | | { |
| 0 | 1135 | | _httpResponse.Dispose(); |
| | 1136 | | } |
| 0 | 1137 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1138 | | } |
| | 1139 | | } |
| 1 | 1140 | | if (_shouldTrace) |
| | 1141 | | { |
| 0 | 1142 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1143 | | } |
| 1 | 1144 | | return _result; |
| 1 | 1145 | | } |
| | 1146 | |
|
| | 1147 | | /// <summary> |
| | 1148 | | /// Gets the logs of the past month's endpoint queries for the application. |
| | 1149 | | /// </summary> |
| | 1150 | | /// <param name='appId'> |
| | 1151 | | /// The application ID. |
| | 1152 | | /// </param> |
| | 1153 | | /// <param name='customHeaders'> |
| | 1154 | | /// Headers that will be added to request. |
| | 1155 | | /// </param> |
| | 1156 | | /// <param name='cancellationToken'> |
| | 1157 | | /// The cancellation token. |
| | 1158 | | /// </param> |
| | 1159 | | /// <exception cref="HttpOperationException"> |
| | 1160 | | /// Thrown when the operation returned an invalid status code |
| | 1161 | | /// </exception> |
| | 1162 | | /// <exception cref="SerializationException"> |
| | 1163 | | /// Thrown when unable to deserialize the response |
| | 1164 | | /// </exception> |
| | 1165 | | /// <exception cref="ValidationException"> |
| | 1166 | | /// Thrown when a required parameter is null |
| | 1167 | | /// </exception> |
| | 1168 | | /// <exception cref="System.ArgumentNullException"> |
| | 1169 | | /// Thrown when a required parameter is null |
| | 1170 | | /// </exception> |
| | 1171 | | /// <return> |
| | 1172 | | /// A response object containing the response body and response headers. |
| | 1173 | | /// </return> |
| | 1174 | | public async Task<HttpOperationResponse<Stream>> DownloadQueryLogsWithHttpMessagesAsync(System.Guid appId, Dicti |
| | 1175 | | { |
| 1 | 1176 | | if (Client.Endpoint == null) |
| | 1177 | | { |
| 0 | 1178 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1179 | | } |
| | 1180 | | // Tracing |
| 1 | 1181 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 1182 | | string _invocationId = null; |
| 1 | 1183 | | if (_shouldTrace) |
| | 1184 | | { |
| 0 | 1185 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1186 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1187 | | tracingParameters.Add("appId", appId); |
| 0 | 1188 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1189 | | ServiceClientTracing.Enter(_invocationId, this, "DownloadQueryLogs", tracingParameters); |
| | 1190 | | } |
| | 1191 | | // Construct URL |
| 1 | 1192 | | var _baseUrl = Client.BaseUri; |
| 1 | 1193 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/querylogs"; |
| 1 | 1194 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 1195 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 1196 | | // Create HTTP transport objects |
| 1 | 1197 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 1198 | | HttpResponseMessage _httpResponse = null; |
| 1 | 1199 | | _httpRequest.Method = new HttpMethod("GET"); |
| 1 | 1200 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1201 | | // Set Headers |
| | 1202 | |
|
| | 1203 | |
|
| 1 | 1204 | | if (customHeaders != null) |
| | 1205 | | { |
| 0 | 1206 | | foreach(var _header in customHeaders) |
| | 1207 | | { |
| 0 | 1208 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1209 | | { |
| 0 | 1210 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1211 | | } |
| 0 | 1212 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1213 | | } |
| | 1214 | | } |
| | 1215 | |
|
| | 1216 | | // Serialize Request |
| 1 | 1217 | | string _requestContent = null; |
| | 1218 | | // Set Credentials |
| 1 | 1219 | | if (Client.Credentials != null) |
| | 1220 | | { |
| 1 | 1221 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1222 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1223 | | } |
| | 1224 | | // Send Request |
| 1 | 1225 | | if (_shouldTrace) |
| | 1226 | | { |
| 0 | 1227 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1228 | | } |
| 1 | 1229 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1230 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons |
| 1 | 1231 | | if (_shouldTrace) |
| | 1232 | | { |
| 0 | 1233 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1234 | | } |
| 1 | 1235 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 1236 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1237 | | string _responseContent = null; |
| 1 | 1238 | | if ((int)_statusCode != 200) |
| | 1239 | | { |
| 0 | 1240 | | var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st |
| 0 | 1241 | | if (_httpResponse.Content != null) { |
| 0 | 1242 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1243 | | } |
| | 1244 | | else { |
| 0 | 1245 | | _responseContent = string.Empty; |
| | 1246 | | } |
| 0 | 1247 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1248 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1249 | | if (_shouldTrace) |
| | 1250 | | { |
| 0 | 1251 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1252 | | } |
| 0 | 1253 | | _httpRequest.Dispose(); |
| 0 | 1254 | | if (_httpResponse != null) |
| | 1255 | | { |
| 0 | 1256 | | _httpResponse.Dispose(); |
| | 1257 | | } |
| 0 | 1258 | | throw ex; |
| | 1259 | | } |
| | 1260 | | // Create Result |
| 1 | 1261 | | var _result = new HttpOperationResponse<Stream>(); |
| 1 | 1262 | | _result.Request = _httpRequest; |
| 1 | 1263 | | _result.Response = _httpResponse; |
| | 1264 | | // Deserialize Response |
| 1 | 1265 | | if ((int)_statusCode == 200) |
| | 1266 | | { |
| 1 | 1267 | | _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); |
| | 1268 | | } |
| 1 | 1269 | | if (_shouldTrace) |
| | 1270 | | { |
| 0 | 1271 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1272 | | } |
| 1 | 1273 | | return _result; |
| 1 | 1274 | | } |
| | 1275 | |
|
| | 1276 | | /// <summary> |
| | 1277 | | /// Gets the application info. |
| | 1278 | | /// </summary> |
| | 1279 | | /// <param name='appId'> |
| | 1280 | | /// The application ID. |
| | 1281 | | /// </param> |
| | 1282 | | /// <param name='customHeaders'> |
| | 1283 | | /// Headers that will be added to request. |
| | 1284 | | /// </param> |
| | 1285 | | /// <param name='cancellationToken'> |
| | 1286 | | /// The cancellation token. |
| | 1287 | | /// </param> |
| | 1288 | | /// <exception cref="ErrorResponseException"> |
| | 1289 | | /// Thrown when the operation returned an invalid status code |
| | 1290 | | /// </exception> |
| | 1291 | | /// <exception cref="SerializationException"> |
| | 1292 | | /// Thrown when unable to deserialize the response |
| | 1293 | | /// </exception> |
| | 1294 | | /// <exception cref="ValidationException"> |
| | 1295 | | /// Thrown when a required parameter is null |
| | 1296 | | /// </exception> |
| | 1297 | | /// <exception cref="System.ArgumentNullException"> |
| | 1298 | | /// Thrown when a required parameter is null |
| | 1299 | | /// </exception> |
| | 1300 | | /// <return> |
| | 1301 | | /// A response object containing the response body and response headers. |
| | 1302 | | /// </return> |
| | 1303 | | public async Task<HttpOperationResponse<ApplicationInfoResponse>> GetWithHttpMessagesAsync(System.Guid appId, Di |
| | 1304 | | { |
| 7 | 1305 | | if (Client.Endpoint == null) |
| | 1306 | | { |
| 0 | 1307 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1308 | | } |
| | 1309 | | // Tracing |
| 7 | 1310 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 7 | 1311 | | string _invocationId = null; |
| 7 | 1312 | | if (_shouldTrace) |
| | 1313 | | { |
| 0 | 1314 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1315 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1316 | | tracingParameters.Add("appId", appId); |
| 0 | 1317 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1318 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 1319 | | } |
| | 1320 | | // Construct URL |
| 7 | 1321 | | var _baseUrl = Client.BaseUri; |
| 7 | 1322 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}"; |
| 7 | 1323 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 7 | 1324 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 1325 | | // Create HTTP transport objects |
| 7 | 1326 | | var _httpRequest = new HttpRequestMessage(); |
| 7 | 1327 | | HttpResponseMessage _httpResponse = null; |
| 7 | 1328 | | _httpRequest.Method = new HttpMethod("GET"); |
| 7 | 1329 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1330 | | // Set Headers |
| | 1331 | |
|
| | 1332 | |
|
| 7 | 1333 | | if (customHeaders != null) |
| | 1334 | | { |
| 0 | 1335 | | foreach(var _header in customHeaders) |
| | 1336 | | { |
| 0 | 1337 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1338 | | { |
| 0 | 1339 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1340 | | } |
| 0 | 1341 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1342 | | } |
| | 1343 | | } |
| | 1344 | |
|
| | 1345 | | // Serialize Request |
| 7 | 1346 | | string _requestContent = null; |
| | 1347 | | // Set Credentials |
| 7 | 1348 | | if (Client.Credentials != null) |
| | 1349 | | { |
| 7 | 1350 | | cancellationToken.ThrowIfCancellationRequested(); |
| 7 | 1351 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1352 | | } |
| | 1353 | | // Send Request |
| 7 | 1354 | | if (_shouldTrace) |
| | 1355 | | { |
| 0 | 1356 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1357 | | } |
| 7 | 1358 | | cancellationToken.ThrowIfCancellationRequested(); |
| 7 | 1359 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 7 | 1360 | | if (_shouldTrace) |
| | 1361 | | { |
| 0 | 1362 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1363 | | } |
| 7 | 1364 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 7 | 1365 | | cancellationToken.ThrowIfCancellationRequested(); |
| 7 | 1366 | | string _responseContent = null; |
| 7 | 1367 | | if ((int)_statusCode != 200) |
| | 1368 | | { |
| 0 | 1369 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1370 | | try |
| | 1371 | | { |
| 0 | 1372 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1373 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1374 | | if (_errorBody != null) |
| | 1375 | | { |
| 0 | 1376 | | ex.Body = _errorBody; |
| | 1377 | | } |
| 0 | 1378 | | } |
| 0 | 1379 | | catch (JsonException) |
| | 1380 | | { |
| | 1381 | | // Ignore the exception |
| 0 | 1382 | | } |
| 0 | 1383 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1384 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1385 | | if (_shouldTrace) |
| | 1386 | | { |
| 0 | 1387 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1388 | | } |
| 0 | 1389 | | _httpRequest.Dispose(); |
| 0 | 1390 | | if (_httpResponse != null) |
| | 1391 | | { |
| 0 | 1392 | | _httpResponse.Dispose(); |
| | 1393 | | } |
| 0 | 1394 | | throw ex; |
| | 1395 | | } |
| | 1396 | | // Create Result |
| 7 | 1397 | | var _result = new HttpOperationResponse<ApplicationInfoResponse>(); |
| 7 | 1398 | | _result.Request = _httpRequest; |
| 7 | 1399 | | _result.Response = _httpResponse; |
| | 1400 | | // Deserialize Response |
| 7 | 1401 | | if ((int)_statusCode == 200) |
| | 1402 | | { |
| 7 | 1403 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1404 | | try |
| | 1405 | | { |
| 7 | 1406 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ApplicationInfoResponse>(_respon |
| 7 | 1407 | | } |
| 0 | 1408 | | catch (JsonException ex) |
| | 1409 | | { |
| 0 | 1410 | | _httpRequest.Dispose(); |
| 0 | 1411 | | if (_httpResponse != null) |
| | 1412 | | { |
| 0 | 1413 | | _httpResponse.Dispose(); |
| | 1414 | | } |
| 0 | 1415 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1416 | | } |
| | 1417 | | } |
| 7 | 1418 | | if (_shouldTrace) |
| | 1419 | | { |
| 0 | 1420 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1421 | | } |
| 7 | 1422 | | return _result; |
| 7 | 1423 | | } |
| | 1424 | |
|
| | 1425 | | /// <summary> |
| | 1426 | | /// Updates the name or description of the application. |
| | 1427 | | /// </summary> |
| | 1428 | | /// <param name='appId'> |
| | 1429 | | /// The application ID. |
| | 1430 | | /// </param> |
| | 1431 | | /// <param name='applicationUpdateObject'> |
| | 1432 | | /// A model containing Name and Description of the application. |
| | 1433 | | /// </param> |
| | 1434 | | /// <param name='customHeaders'> |
| | 1435 | | /// Headers that will be added to request. |
| | 1436 | | /// </param> |
| | 1437 | | /// <param name='cancellationToken'> |
| | 1438 | | /// The cancellation token. |
| | 1439 | | /// </param> |
| | 1440 | | /// <exception cref="ErrorResponseException"> |
| | 1441 | | /// Thrown when the operation returned an invalid status code |
| | 1442 | | /// </exception> |
| | 1443 | | /// <exception cref="SerializationException"> |
| | 1444 | | /// Thrown when unable to deserialize the response |
| | 1445 | | /// </exception> |
| | 1446 | | /// <exception cref="ValidationException"> |
| | 1447 | | /// Thrown when a required parameter is null |
| | 1448 | | /// </exception> |
| | 1449 | | /// <exception cref="System.ArgumentNullException"> |
| | 1450 | | /// Thrown when a required parameter is null |
| | 1451 | | /// </exception> |
| | 1452 | | /// <return> |
| | 1453 | | /// A response object containing the response body and response headers. |
| | 1454 | | /// </return> |
| | 1455 | | public async Task<HttpOperationResponse<OperationStatus>> UpdateWithHttpMessagesAsync(System.Guid appId, Applica |
| | 1456 | | { |
| 1 | 1457 | | if (Client.Endpoint == null) |
| | 1458 | | { |
| 0 | 1459 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1460 | | } |
| 1 | 1461 | | if (applicationUpdateObject == null) |
| | 1462 | | { |
| 0 | 1463 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationUpdateObject"); |
| | 1464 | | } |
| | 1465 | | // Tracing |
| 1 | 1466 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 1467 | | string _invocationId = null; |
| 1 | 1468 | | if (_shouldTrace) |
| | 1469 | | { |
| 0 | 1470 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1471 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1472 | | tracingParameters.Add("appId", appId); |
| 0 | 1473 | | tracingParameters.Add("applicationUpdateObject", applicationUpdateObject); |
| 0 | 1474 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1475 | | ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); |
| | 1476 | | } |
| | 1477 | | // Construct URL |
| 1 | 1478 | | var _baseUrl = Client.BaseUri; |
| 1 | 1479 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}"; |
| 1 | 1480 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 1481 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 1482 | | // Create HTTP transport objects |
| 1 | 1483 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 1484 | | HttpResponseMessage _httpResponse = null; |
| 1 | 1485 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 1 | 1486 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1487 | | // Set Headers |
| | 1488 | |
|
| | 1489 | |
|
| 1 | 1490 | | if (customHeaders != null) |
| | 1491 | | { |
| 0 | 1492 | | foreach(var _header in customHeaders) |
| | 1493 | | { |
| 0 | 1494 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1495 | | { |
| 0 | 1496 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1497 | | } |
| 0 | 1498 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1499 | | } |
| | 1500 | | } |
| | 1501 | |
|
| | 1502 | | // Serialize Request |
| 1 | 1503 | | string _requestContent = null; |
| 1 | 1504 | | if(applicationUpdateObject != null) |
| | 1505 | | { |
| 1 | 1506 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(applicationUpdateObject, Client.Ser |
| 1 | 1507 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 1508 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1509 | | } |
| | 1510 | | // Set Credentials |
| 1 | 1511 | | if (Client.Credentials != null) |
| | 1512 | | { |
| 1 | 1513 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1514 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1515 | | } |
| | 1516 | | // Send Request |
| 1 | 1517 | | if (_shouldTrace) |
| | 1518 | | { |
| 0 | 1519 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1520 | | } |
| 1 | 1521 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1522 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 1523 | | if (_shouldTrace) |
| | 1524 | | { |
| 0 | 1525 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1526 | | } |
| 1 | 1527 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 1528 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1529 | | string _responseContent = null; |
| 1 | 1530 | | if ((int)_statusCode != 200) |
| | 1531 | | { |
| 0 | 1532 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1533 | | try |
| | 1534 | | { |
| 0 | 1535 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1536 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1537 | | if (_errorBody != null) |
| | 1538 | | { |
| 0 | 1539 | | ex.Body = _errorBody; |
| | 1540 | | } |
| 0 | 1541 | | } |
| 0 | 1542 | | catch (JsonException) |
| | 1543 | | { |
| | 1544 | | // Ignore the exception |
| 0 | 1545 | | } |
| 0 | 1546 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1547 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1548 | | if (_shouldTrace) |
| | 1549 | | { |
| 0 | 1550 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1551 | | } |
| 0 | 1552 | | _httpRequest.Dispose(); |
| 0 | 1553 | | if (_httpResponse != null) |
| | 1554 | | { |
| 0 | 1555 | | _httpResponse.Dispose(); |
| | 1556 | | } |
| 0 | 1557 | | throw ex; |
| | 1558 | | } |
| | 1559 | | // Create Result |
| 1 | 1560 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 1 | 1561 | | _result.Request = _httpRequest; |
| 1 | 1562 | | _result.Response = _httpResponse; |
| | 1563 | | // Deserialize Response |
| 1 | 1564 | | if ((int)_statusCode == 200) |
| | 1565 | | { |
| 1 | 1566 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1567 | | try |
| | 1568 | | { |
| 1 | 1569 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 1 | 1570 | | } |
| 0 | 1571 | | catch (JsonException ex) |
| | 1572 | | { |
| 0 | 1573 | | _httpRequest.Dispose(); |
| 0 | 1574 | | if (_httpResponse != null) |
| | 1575 | | { |
| 0 | 1576 | | _httpResponse.Dispose(); |
| | 1577 | | } |
| 0 | 1578 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1579 | | } |
| | 1580 | | } |
| 1 | 1581 | | if (_shouldTrace) |
| | 1582 | | { |
| 0 | 1583 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1584 | | } |
| 1 | 1585 | | return _result; |
| 1 | 1586 | | } |
| | 1587 | |
|
| | 1588 | | /// <summary> |
| | 1589 | | /// Deletes an application. |
| | 1590 | | /// </summary> |
| | 1591 | | /// <param name='appId'> |
| | 1592 | | /// The application ID. |
| | 1593 | | /// </param> |
| | 1594 | | /// <param name='force'> |
| | 1595 | | /// A flag to indicate whether to force an operation. |
| | 1596 | | /// </param> |
| | 1597 | | /// <param name='customHeaders'> |
| | 1598 | | /// Headers that will be added to request. |
| | 1599 | | /// </param> |
| | 1600 | | /// <param name='cancellationToken'> |
| | 1601 | | /// The cancellation token. |
| | 1602 | | /// </param> |
| | 1603 | | /// <exception cref="ErrorResponseException"> |
| | 1604 | | /// Thrown when the operation returned an invalid status code |
| | 1605 | | /// </exception> |
| | 1606 | | /// <exception cref="SerializationException"> |
| | 1607 | | /// Thrown when unable to deserialize the response |
| | 1608 | | /// </exception> |
| | 1609 | | /// <exception cref="ValidationException"> |
| | 1610 | | /// Thrown when a required parameter is null |
| | 1611 | | /// </exception> |
| | 1612 | | /// <exception cref="System.ArgumentNullException"> |
| | 1613 | | /// Thrown when a required parameter is null |
| | 1614 | | /// </exception> |
| | 1615 | | /// <return> |
| | 1616 | | /// A response object containing the response body and response headers. |
| | 1617 | | /// </return> |
| | 1618 | | public async Task<HttpOperationResponse<OperationStatus>> DeleteWithHttpMessagesAsync(System.Guid appId, bool? f |
| | 1619 | | { |
| 32 | 1620 | | if (Client.Endpoint == null) |
| | 1621 | | { |
| 0 | 1622 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1623 | | } |
| | 1624 | | // Tracing |
| 32 | 1625 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 32 | 1626 | | string _invocationId = null; |
| 32 | 1627 | | if (_shouldTrace) |
| | 1628 | | { |
| 0 | 1629 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1630 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1631 | | tracingParameters.Add("appId", appId); |
| 0 | 1632 | | tracingParameters.Add("force", force); |
| 0 | 1633 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1634 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 1635 | | } |
| | 1636 | | // Construct URL |
| 32 | 1637 | | var _baseUrl = Client.BaseUri; |
| 32 | 1638 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}"; |
| 32 | 1639 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 32 | 1640 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 32 | 1641 | | List<string> _queryParameters = new List<string>(); |
| 32 | 1642 | | if (force != null) |
| | 1643 | | { |
| 32 | 1644 | | _queryParameters.Add(string.Format("force={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonC |
| | 1645 | | } |
| 32 | 1646 | | if (_queryParameters.Count > 0) |
| | 1647 | | { |
| 32 | 1648 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1649 | | } |
| | 1650 | | // Create HTTP transport objects |
| 32 | 1651 | | var _httpRequest = new HttpRequestMessage(); |
| 32 | 1652 | | HttpResponseMessage _httpResponse = null; |
| 32 | 1653 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 32 | 1654 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1655 | | // Set Headers |
| | 1656 | |
|
| | 1657 | |
|
| 32 | 1658 | | if (customHeaders != null) |
| | 1659 | | { |
| 0 | 1660 | | foreach(var _header in customHeaders) |
| | 1661 | | { |
| 0 | 1662 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1663 | | { |
| 0 | 1664 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1665 | | } |
| 0 | 1666 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1667 | | } |
| | 1668 | | } |
| | 1669 | |
|
| | 1670 | | // Serialize Request |
| 32 | 1671 | | string _requestContent = null; |
| | 1672 | | // Set Credentials |
| 32 | 1673 | | if (Client.Credentials != null) |
| | 1674 | | { |
| 32 | 1675 | | cancellationToken.ThrowIfCancellationRequested(); |
| 32 | 1676 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1677 | | } |
| | 1678 | | // Send Request |
| 32 | 1679 | | if (_shouldTrace) |
| | 1680 | | { |
| 0 | 1681 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1682 | | } |
| 32 | 1683 | | cancellationToken.ThrowIfCancellationRequested(); |
| 32 | 1684 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 32 | 1685 | | if (_shouldTrace) |
| | 1686 | | { |
| 0 | 1687 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1688 | | } |
| 32 | 1689 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 32 | 1690 | | cancellationToken.ThrowIfCancellationRequested(); |
| 32 | 1691 | | string _responseContent = null; |
| 32 | 1692 | | if ((int)_statusCode != 200) |
| | 1693 | | { |
| 0 | 1694 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1695 | | try |
| | 1696 | | { |
| 0 | 1697 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1698 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1699 | | if (_errorBody != null) |
| | 1700 | | { |
| 0 | 1701 | | ex.Body = _errorBody; |
| | 1702 | | } |
| 0 | 1703 | | } |
| 0 | 1704 | | catch (JsonException) |
| | 1705 | | { |
| | 1706 | | // Ignore the exception |
| 0 | 1707 | | } |
| 0 | 1708 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1709 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1710 | | if (_shouldTrace) |
| | 1711 | | { |
| 0 | 1712 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1713 | | } |
| 0 | 1714 | | _httpRequest.Dispose(); |
| 0 | 1715 | | if (_httpResponse != null) |
| | 1716 | | { |
| 0 | 1717 | | _httpResponse.Dispose(); |
| | 1718 | | } |
| 0 | 1719 | | throw ex; |
| | 1720 | | } |
| | 1721 | | // Create Result |
| 32 | 1722 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 32 | 1723 | | _result.Request = _httpRequest; |
| 32 | 1724 | | _result.Response = _httpResponse; |
| | 1725 | | // Deserialize Response |
| 32 | 1726 | | if ((int)_statusCode == 200) |
| | 1727 | | { |
| 32 | 1728 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1729 | | try |
| | 1730 | | { |
| 32 | 1731 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 32 | 1732 | | } |
| 0 | 1733 | | catch (JsonException ex) |
| | 1734 | | { |
| 0 | 1735 | | _httpRequest.Dispose(); |
| 0 | 1736 | | if (_httpResponse != null) |
| | 1737 | | { |
| 0 | 1738 | | _httpResponse.Dispose(); |
| | 1739 | | } |
| 0 | 1740 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1741 | | } |
| | 1742 | | } |
| 32 | 1743 | | if (_shouldTrace) |
| | 1744 | | { |
| 0 | 1745 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1746 | | } |
| 32 | 1747 | | return _result; |
| 32 | 1748 | | } |
| | 1749 | |
|
| | 1750 | | /// <summary> |
| | 1751 | | /// Publishes a specific version of the application. |
| | 1752 | | /// </summary> |
| | 1753 | | /// <param name='appId'> |
| | 1754 | | /// The application ID. |
| | 1755 | | /// </param> |
| | 1756 | | /// <param name='applicationPublishObject'> |
| | 1757 | | /// The application publish object. The region is the target region that the |
| | 1758 | | /// application is published to. |
| | 1759 | | /// </param> |
| | 1760 | | /// <param name='customHeaders'> |
| | 1761 | | /// Headers that will be added to request. |
| | 1762 | | /// </param> |
| | 1763 | | /// <param name='cancellationToken'> |
| | 1764 | | /// The cancellation token. |
| | 1765 | | /// </param> |
| | 1766 | | /// <exception cref="ErrorResponseException"> |
| | 1767 | | /// Thrown when the operation returned an invalid status code |
| | 1768 | | /// </exception> |
| | 1769 | | /// <exception cref="SerializationException"> |
| | 1770 | | /// Thrown when unable to deserialize the response |
| | 1771 | | /// </exception> |
| | 1772 | | /// <exception cref="ValidationException"> |
| | 1773 | | /// Thrown when a required parameter is null |
| | 1774 | | /// </exception> |
| | 1775 | | /// <exception cref="System.ArgumentNullException"> |
| | 1776 | | /// Thrown when a required parameter is null |
| | 1777 | | /// </exception> |
| | 1778 | | /// <return> |
| | 1779 | | /// A response object containing the response body and response headers. |
| | 1780 | | /// </return> |
| | 1781 | | public async Task<HttpOperationResponse<ProductionOrStagingEndpointInfo>> PublishWithHttpMessagesAsync(System.Gu |
| | 1782 | | { |
| 1 | 1783 | | if (Client.Endpoint == null) |
| | 1784 | | { |
| 0 | 1785 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1786 | | } |
| 1 | 1787 | | if (applicationPublishObject == null) |
| | 1788 | | { |
| 0 | 1789 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationPublishObject"); |
| | 1790 | | } |
| | 1791 | | // Tracing |
| 1 | 1792 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 1793 | | string _invocationId = null; |
| 1 | 1794 | | if (_shouldTrace) |
| | 1795 | | { |
| 0 | 1796 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1797 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1798 | | tracingParameters.Add("appId", appId); |
| 0 | 1799 | | tracingParameters.Add("applicationPublishObject", applicationPublishObject); |
| 0 | 1800 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1801 | | ServiceClientTracing.Enter(_invocationId, this, "Publish", tracingParameters); |
| | 1802 | | } |
| | 1803 | | // Construct URL |
| 1 | 1804 | | var _baseUrl = Client.BaseUri; |
| 1 | 1805 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/publish"; |
| 1 | 1806 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 1807 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 1808 | | // Create HTTP transport objects |
| 1 | 1809 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 1810 | | HttpResponseMessage _httpResponse = null; |
| 1 | 1811 | | _httpRequest.Method = new HttpMethod("POST"); |
| 1 | 1812 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1813 | | // Set Headers |
| | 1814 | |
|
| | 1815 | |
|
| 1 | 1816 | | if (customHeaders != null) |
| | 1817 | | { |
| 0 | 1818 | | foreach(var _header in customHeaders) |
| | 1819 | | { |
| 0 | 1820 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1821 | | { |
| 0 | 1822 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1823 | | } |
| 0 | 1824 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1825 | | } |
| | 1826 | | } |
| | 1827 | |
|
| | 1828 | | // Serialize Request |
| 1 | 1829 | | string _requestContent = null; |
| 1 | 1830 | | if(applicationPublishObject != null) |
| | 1831 | | { |
| 1 | 1832 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(applicationPublishObject, Client.Se |
| 1 | 1833 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 1834 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1835 | | } |
| | 1836 | | // Set Credentials |
| 1 | 1837 | | if (Client.Credentials != null) |
| | 1838 | | { |
| 1 | 1839 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1840 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1841 | | } |
| | 1842 | | // Send Request |
| 1 | 1843 | | if (_shouldTrace) |
| | 1844 | | { |
| 0 | 1845 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1846 | | } |
| 1 | 1847 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1848 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 1849 | | if (_shouldTrace) |
| | 1850 | | { |
| 0 | 1851 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1852 | | } |
| 1 | 1853 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 1854 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1855 | | string _responseContent = null; |
| 1 | 1856 | | if ((int)_statusCode != 201 && (int)_statusCode != 207) |
| | 1857 | | { |
| 0 | 1858 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1859 | | try |
| | 1860 | | { |
| 0 | 1861 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1862 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1863 | | if (_errorBody != null) |
| | 1864 | | { |
| 0 | 1865 | | ex.Body = _errorBody; |
| | 1866 | | } |
| 0 | 1867 | | } |
| 0 | 1868 | | catch (JsonException) |
| | 1869 | | { |
| | 1870 | | // Ignore the exception |
| 0 | 1871 | | } |
| 0 | 1872 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1873 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1874 | | if (_shouldTrace) |
| | 1875 | | { |
| 0 | 1876 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1877 | | } |
| 0 | 1878 | | _httpRequest.Dispose(); |
| 0 | 1879 | | if (_httpResponse != null) |
| | 1880 | | { |
| 0 | 1881 | | _httpResponse.Dispose(); |
| | 1882 | | } |
| 0 | 1883 | | throw ex; |
| | 1884 | | } |
| | 1885 | | // Create Result |
| 1 | 1886 | | var _result = new HttpOperationResponse<ProductionOrStagingEndpointInfo>(); |
| 1 | 1887 | | _result.Request = _httpRequest; |
| 1 | 1888 | | _result.Response = _httpResponse; |
| | 1889 | | // Deserialize Response |
| 1 | 1890 | | if ((int)_statusCode == 201) |
| | 1891 | | { |
| 1 | 1892 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1893 | | try |
| | 1894 | | { |
| 1 | 1895 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ProductionOrStagingEndpointInfo> |
| 1 | 1896 | | } |
| 0 | 1897 | | catch (JsonException ex) |
| | 1898 | | { |
| 0 | 1899 | | _httpRequest.Dispose(); |
| 0 | 1900 | | if (_httpResponse != null) |
| | 1901 | | { |
| 0 | 1902 | | _httpResponse.Dispose(); |
| | 1903 | | } |
| 0 | 1904 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1905 | | } |
| | 1906 | | } |
| | 1907 | | // Deserialize Response |
| 1 | 1908 | | if ((int)_statusCode == 207) |
| | 1909 | | { |
| 0 | 1910 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1911 | | try |
| | 1912 | | { |
| 0 | 1913 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ProductionOrStagingEndpointInfo> |
| 0 | 1914 | | } |
| 0 | 1915 | | catch (JsonException ex) |
| | 1916 | | { |
| 0 | 1917 | | _httpRequest.Dispose(); |
| 0 | 1918 | | if (_httpResponse != null) |
| | 1919 | | { |
| 0 | 1920 | | _httpResponse.Dispose(); |
| | 1921 | | } |
| 0 | 1922 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1923 | | } |
| | 1924 | | } |
| 1 | 1925 | | if (_shouldTrace) |
| | 1926 | | { |
| 0 | 1927 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1928 | | } |
| 1 | 1929 | | return _result; |
| 1 | 1930 | | } |
| | 1931 | |
|
| | 1932 | | /// <summary> |
| | 1933 | | /// Get the application settings including 'UseAllTrainingData'. |
| | 1934 | | /// </summary> |
| | 1935 | | /// <param name='appId'> |
| | 1936 | | /// The application ID. |
| | 1937 | | /// </param> |
| | 1938 | | /// <param name='customHeaders'> |
| | 1939 | | /// Headers that will be added to request. |
| | 1940 | | /// </param> |
| | 1941 | | /// <param name='cancellationToken'> |
| | 1942 | | /// The cancellation token. |
| | 1943 | | /// </param> |
| | 1944 | | /// <exception cref="ErrorResponseException"> |
| | 1945 | | /// Thrown when the operation returned an invalid status code |
| | 1946 | | /// </exception> |
| | 1947 | | /// <exception cref="SerializationException"> |
| | 1948 | | /// Thrown when unable to deserialize the response |
| | 1949 | | /// </exception> |
| | 1950 | | /// <exception cref="ValidationException"> |
| | 1951 | | /// Thrown when a required parameter is null |
| | 1952 | | /// </exception> |
| | 1953 | | /// <exception cref="System.ArgumentNullException"> |
| | 1954 | | /// Thrown when a required parameter is null |
| | 1955 | | /// </exception> |
| | 1956 | | /// <return> |
| | 1957 | | /// A response object containing the response body and response headers. |
| | 1958 | | /// </return> |
| | 1959 | | public async Task<HttpOperationResponse<ApplicationSettings>> GetSettingsWithHttpMessagesAsync(System.Guid appId |
| | 1960 | | { |
| 2 | 1961 | | if (Client.Endpoint == null) |
| | 1962 | | { |
| 0 | 1963 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1964 | | } |
| | 1965 | | // Tracing |
| 2 | 1966 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 1967 | | string _invocationId = null; |
| 2 | 1968 | | if (_shouldTrace) |
| | 1969 | | { |
| 0 | 1970 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1971 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1972 | | tracingParameters.Add("appId", appId); |
| 0 | 1973 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1974 | | ServiceClientTracing.Enter(_invocationId, this, "GetSettings", tracingParameters); |
| | 1975 | | } |
| | 1976 | | // Construct URL |
| 2 | 1977 | | var _baseUrl = Client.BaseUri; |
| 2 | 1978 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/settings"; |
| 2 | 1979 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 1980 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 1981 | | // Create HTTP transport objects |
| 2 | 1982 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 1983 | | HttpResponseMessage _httpResponse = null; |
| 2 | 1984 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 1985 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1986 | | // Set Headers |
| | 1987 | |
|
| | 1988 | |
|
| 2 | 1989 | | if (customHeaders != null) |
| | 1990 | | { |
| 0 | 1991 | | foreach(var _header in customHeaders) |
| | 1992 | | { |
| 0 | 1993 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1994 | | { |
| 0 | 1995 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1996 | | } |
| 0 | 1997 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1998 | | } |
| | 1999 | | } |
| | 2000 | |
|
| | 2001 | | // Serialize Request |
| 2 | 2002 | | string _requestContent = null; |
| | 2003 | | // Set Credentials |
| 2 | 2004 | | if (Client.Credentials != null) |
| | 2005 | | { |
| 2 | 2006 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2007 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2008 | | } |
| | 2009 | | // Send Request |
| 2 | 2010 | | if (_shouldTrace) |
| | 2011 | | { |
| 0 | 2012 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2013 | | } |
| 2 | 2014 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2015 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 2016 | | if (_shouldTrace) |
| | 2017 | | { |
| 0 | 2018 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2019 | | } |
| 2 | 2020 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 2021 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2022 | | string _responseContent = null; |
| 2 | 2023 | | if ((int)_statusCode != 200) |
| | 2024 | | { |
| 0 | 2025 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 2026 | | try |
| | 2027 | | { |
| 0 | 2028 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2029 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 2030 | | if (_errorBody != null) |
| | 2031 | | { |
| 0 | 2032 | | ex.Body = _errorBody; |
| | 2033 | | } |
| 0 | 2034 | | } |
| 0 | 2035 | | catch (JsonException) |
| | 2036 | | { |
| | 2037 | | // Ignore the exception |
| 0 | 2038 | | } |
| 0 | 2039 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2040 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2041 | | if (_shouldTrace) |
| | 2042 | | { |
| 0 | 2043 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2044 | | } |
| 0 | 2045 | | _httpRequest.Dispose(); |
| 0 | 2046 | | if (_httpResponse != null) |
| | 2047 | | { |
| 0 | 2048 | | _httpResponse.Dispose(); |
| | 2049 | | } |
| 0 | 2050 | | throw ex; |
| | 2051 | | } |
| | 2052 | | // Create Result |
| 2 | 2053 | | var _result = new HttpOperationResponse<ApplicationSettings>(); |
| 2 | 2054 | | _result.Request = _httpRequest; |
| 2 | 2055 | | _result.Response = _httpResponse; |
| | 2056 | | // Deserialize Response |
| 2 | 2057 | | if ((int)_statusCode == 200) |
| | 2058 | | { |
| 2 | 2059 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2060 | | try |
| | 2061 | | { |
| 2 | 2062 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ApplicationSettings>(_responseCo |
| 2 | 2063 | | } |
| 0 | 2064 | | catch (JsonException ex) |
| | 2065 | | { |
| 0 | 2066 | | _httpRequest.Dispose(); |
| 0 | 2067 | | if (_httpResponse != null) |
| | 2068 | | { |
| 0 | 2069 | | _httpResponse.Dispose(); |
| | 2070 | | } |
| 0 | 2071 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2072 | | } |
| | 2073 | | } |
| 2 | 2074 | | if (_shouldTrace) |
| | 2075 | | { |
| 0 | 2076 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2077 | | } |
| 2 | 2078 | | return _result; |
| 2 | 2079 | | } |
| | 2080 | |
|
| | 2081 | | /// <summary> |
| | 2082 | | /// Updates the application settings including 'UseAllTrainingData'. |
| | 2083 | | /// </summary> |
| | 2084 | | /// <param name='appId'> |
| | 2085 | | /// The application ID. |
| | 2086 | | /// </param> |
| | 2087 | | /// <param name='applicationSettingUpdateObject'> |
| | 2088 | | /// An object containing the new application settings. |
| | 2089 | | /// </param> |
| | 2090 | | /// <param name='customHeaders'> |
| | 2091 | | /// Headers that will be added to request. |
| | 2092 | | /// </param> |
| | 2093 | | /// <param name='cancellationToken'> |
| | 2094 | | /// The cancellation token. |
| | 2095 | | /// </param> |
| | 2096 | | /// <exception cref="ErrorResponseException"> |
| | 2097 | | /// Thrown when the operation returned an invalid status code |
| | 2098 | | /// </exception> |
| | 2099 | | /// <exception cref="SerializationException"> |
| | 2100 | | /// Thrown when unable to deserialize the response |
| | 2101 | | /// </exception> |
| | 2102 | | /// <exception cref="ValidationException"> |
| | 2103 | | /// Thrown when a required parameter is null |
| | 2104 | | /// </exception> |
| | 2105 | | /// <exception cref="System.ArgumentNullException"> |
| | 2106 | | /// Thrown when a required parameter is null |
| | 2107 | | /// </exception> |
| | 2108 | | /// <return> |
| | 2109 | | /// A response object containing the response body and response headers. |
| | 2110 | | /// </return> |
| | 2111 | | public async Task<HttpOperationResponse<OperationStatus>> UpdateSettingsWithHttpMessagesAsync(System.Guid appId, |
| | 2112 | | { |
| 1 | 2113 | | if (Client.Endpoint == null) |
| | 2114 | | { |
| 0 | 2115 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2116 | | } |
| 1 | 2117 | | if (applicationSettingUpdateObject == null) |
| | 2118 | | { |
| 0 | 2119 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationSettingUpdateObject"); |
| | 2120 | | } |
| | 2121 | | // Tracing |
| 1 | 2122 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 2123 | | string _invocationId = null; |
| 1 | 2124 | | if (_shouldTrace) |
| | 2125 | | { |
| 0 | 2126 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2127 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2128 | | tracingParameters.Add("appId", appId); |
| 0 | 2129 | | tracingParameters.Add("applicationSettingUpdateObject", applicationSettingUpdateObject); |
| 0 | 2130 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2131 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateSettings", tracingParameters); |
| | 2132 | | } |
| | 2133 | | // Construct URL |
| 1 | 2134 | | var _baseUrl = Client.BaseUri; |
| 1 | 2135 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/settings"; |
| 1 | 2136 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 2137 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 2138 | | // Create HTTP transport objects |
| 1 | 2139 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 2140 | | HttpResponseMessage _httpResponse = null; |
| 1 | 2141 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 1 | 2142 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2143 | | // Set Headers |
| | 2144 | |
|
| | 2145 | |
|
| 1 | 2146 | | if (customHeaders != null) |
| | 2147 | | { |
| 0 | 2148 | | foreach(var _header in customHeaders) |
| | 2149 | | { |
| 0 | 2150 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2151 | | { |
| 0 | 2152 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2153 | | } |
| 0 | 2154 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2155 | | } |
| | 2156 | | } |
| | 2157 | |
|
| | 2158 | | // Serialize Request |
| 1 | 2159 | | string _requestContent = null; |
| 1 | 2160 | | if(applicationSettingUpdateObject != null) |
| | 2161 | | { |
| 1 | 2162 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(applicationSettingUpdateObject, Cli |
| 1 | 2163 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 2164 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 2165 | | } |
| | 2166 | | // Set Credentials |
| 1 | 2167 | | if (Client.Credentials != null) |
| | 2168 | | { |
| 1 | 2169 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2170 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2171 | | } |
| | 2172 | | // Send Request |
| 1 | 2173 | | if (_shouldTrace) |
| | 2174 | | { |
| 0 | 2175 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2176 | | } |
| 1 | 2177 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2178 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 2179 | | if (_shouldTrace) |
| | 2180 | | { |
| 0 | 2181 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2182 | | } |
| 1 | 2183 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 2184 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2185 | | string _responseContent = null; |
| 1 | 2186 | | if ((int)_statusCode != 200) |
| | 2187 | | { |
| 0 | 2188 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 2189 | | try |
| | 2190 | | { |
| 0 | 2191 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2192 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 2193 | | if (_errorBody != null) |
| | 2194 | | { |
| 0 | 2195 | | ex.Body = _errorBody; |
| | 2196 | | } |
| 0 | 2197 | | } |
| 0 | 2198 | | catch (JsonException) |
| | 2199 | | { |
| | 2200 | | // Ignore the exception |
| 0 | 2201 | | } |
| 0 | 2202 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2203 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2204 | | if (_shouldTrace) |
| | 2205 | | { |
| 0 | 2206 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2207 | | } |
| 0 | 2208 | | _httpRequest.Dispose(); |
| 0 | 2209 | | if (_httpResponse != null) |
| | 2210 | | { |
| 0 | 2211 | | _httpResponse.Dispose(); |
| | 2212 | | } |
| 0 | 2213 | | throw ex; |
| | 2214 | | } |
| | 2215 | | // Create Result |
| 1 | 2216 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 1 | 2217 | | _result.Request = _httpRequest; |
| 1 | 2218 | | _result.Response = _httpResponse; |
| | 2219 | | // Deserialize Response |
| 1 | 2220 | | if ((int)_statusCode == 200) |
| | 2221 | | { |
| 1 | 2222 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2223 | | try |
| | 2224 | | { |
| 1 | 2225 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 1 | 2226 | | } |
| 0 | 2227 | | catch (JsonException ex) |
| | 2228 | | { |
| 0 | 2229 | | _httpRequest.Dispose(); |
| 0 | 2230 | | if (_httpResponse != null) |
| | 2231 | | { |
| 0 | 2232 | | _httpResponse.Dispose(); |
| | 2233 | | } |
| 0 | 2234 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2235 | | } |
| | 2236 | | } |
| 1 | 2237 | | if (_shouldTrace) |
| | 2238 | | { |
| 0 | 2239 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2240 | | } |
| 1 | 2241 | | return _result; |
| 1 | 2242 | | } |
| | 2243 | |
|
| | 2244 | | /// <summary> |
| | 2245 | | /// Get the application publish settings including 'UseAllTrainingData'. |
| | 2246 | | /// </summary> |
| | 2247 | | /// <param name='appId'> |
| | 2248 | | /// The application ID. |
| | 2249 | | /// </param> |
| | 2250 | | /// <param name='customHeaders'> |
| | 2251 | | /// Headers that will be added to request. |
| | 2252 | | /// </param> |
| | 2253 | | /// <param name='cancellationToken'> |
| | 2254 | | /// The cancellation token. |
| | 2255 | | /// </param> |
| | 2256 | | /// <exception cref="ErrorResponseException"> |
| | 2257 | | /// Thrown when the operation returned an invalid status code |
| | 2258 | | /// </exception> |
| | 2259 | | /// <exception cref="SerializationException"> |
| | 2260 | | /// Thrown when unable to deserialize the response |
| | 2261 | | /// </exception> |
| | 2262 | | /// <exception cref="ValidationException"> |
| | 2263 | | /// Thrown when a required parameter is null |
| | 2264 | | /// </exception> |
| | 2265 | | /// <exception cref="System.ArgumentNullException"> |
| | 2266 | | /// Thrown when a required parameter is null |
| | 2267 | | /// </exception> |
| | 2268 | | /// <return> |
| | 2269 | | /// A response object containing the response body and response headers. |
| | 2270 | | /// </return> |
| | 2271 | | public async Task<HttpOperationResponse<PublishSettings>> GetPublishSettingsWithHttpMessagesAsync(System.Guid ap |
| | 2272 | | { |
| 2 | 2273 | | if (Client.Endpoint == null) |
| | 2274 | | { |
| 0 | 2275 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2276 | | } |
| | 2277 | | // Tracing |
| 2 | 2278 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 2279 | | string _invocationId = null; |
| 2 | 2280 | | if (_shouldTrace) |
| | 2281 | | { |
| 0 | 2282 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2283 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2284 | | tracingParameters.Add("appId", appId); |
| 0 | 2285 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2286 | | ServiceClientTracing.Enter(_invocationId, this, "GetPublishSettings", tracingParameters); |
| | 2287 | | } |
| | 2288 | | // Construct URL |
| 2 | 2289 | | var _baseUrl = Client.BaseUri; |
| 2 | 2290 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/publishsettings"; |
| 2 | 2291 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 2292 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 2293 | | // Create HTTP transport objects |
| 2 | 2294 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 2295 | | HttpResponseMessage _httpResponse = null; |
| 2 | 2296 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 2297 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2298 | | // Set Headers |
| | 2299 | |
|
| | 2300 | |
|
| 2 | 2301 | | if (customHeaders != null) |
| | 2302 | | { |
| 0 | 2303 | | foreach(var _header in customHeaders) |
| | 2304 | | { |
| 0 | 2305 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2306 | | { |
| 0 | 2307 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2308 | | } |
| 0 | 2309 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2310 | | } |
| | 2311 | | } |
| | 2312 | |
|
| | 2313 | | // Serialize Request |
| 2 | 2314 | | string _requestContent = null; |
| | 2315 | | // Set Credentials |
| 2 | 2316 | | if (Client.Credentials != null) |
| | 2317 | | { |
| 2 | 2318 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2319 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2320 | | } |
| | 2321 | | // Send Request |
| 2 | 2322 | | if (_shouldTrace) |
| | 2323 | | { |
| 0 | 2324 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2325 | | } |
| 2 | 2326 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2327 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 2328 | | if (_shouldTrace) |
| | 2329 | | { |
| 0 | 2330 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2331 | | } |
| 2 | 2332 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 2333 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2334 | | string _responseContent = null; |
| 2 | 2335 | | if ((int)_statusCode != 200) |
| | 2336 | | { |
| 0 | 2337 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 2338 | | try |
| | 2339 | | { |
| 0 | 2340 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2341 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 2342 | | if (_errorBody != null) |
| | 2343 | | { |
| 0 | 2344 | | ex.Body = _errorBody; |
| | 2345 | | } |
| 0 | 2346 | | } |
| 0 | 2347 | | catch (JsonException) |
| | 2348 | | { |
| | 2349 | | // Ignore the exception |
| 0 | 2350 | | } |
| 0 | 2351 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2352 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2353 | | if (_shouldTrace) |
| | 2354 | | { |
| 0 | 2355 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2356 | | } |
| 0 | 2357 | | _httpRequest.Dispose(); |
| 0 | 2358 | | if (_httpResponse != null) |
| | 2359 | | { |
| 0 | 2360 | | _httpResponse.Dispose(); |
| | 2361 | | } |
| 0 | 2362 | | throw ex; |
| | 2363 | | } |
| | 2364 | | // Create Result |
| 2 | 2365 | | var _result = new HttpOperationResponse<PublishSettings>(); |
| 2 | 2366 | | _result.Request = _httpRequest; |
| 2 | 2367 | | _result.Response = _httpResponse; |
| | 2368 | | // Deserialize Response |
| 2 | 2369 | | if ((int)_statusCode == 200) |
| | 2370 | | { |
| 2 | 2371 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2372 | | try |
| | 2373 | | { |
| 2 | 2374 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PublishSettings>(_responseConten |
| 2 | 2375 | | } |
| 0 | 2376 | | catch (JsonException ex) |
| | 2377 | | { |
| 0 | 2378 | | _httpRequest.Dispose(); |
| 0 | 2379 | | if (_httpResponse != null) |
| | 2380 | | { |
| 0 | 2381 | | _httpResponse.Dispose(); |
| | 2382 | | } |
| 0 | 2383 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2384 | | } |
| | 2385 | | } |
| 2 | 2386 | | if (_shouldTrace) |
| | 2387 | | { |
| 0 | 2388 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2389 | | } |
| 2 | 2390 | | return _result; |
| 2 | 2391 | | } |
| | 2392 | |
|
| | 2393 | | /// <summary> |
| | 2394 | | /// Updates the application publish settings including 'UseAllTrainingData'. |
| | 2395 | | /// </summary> |
| | 2396 | | /// <param name='appId'> |
| | 2397 | | /// The application ID. |
| | 2398 | | /// </param> |
| | 2399 | | /// <param name='publishSettingUpdateObject'> |
| | 2400 | | /// An object containing the new publish application settings. |
| | 2401 | | /// </param> |
| | 2402 | | /// <param name='customHeaders'> |
| | 2403 | | /// Headers that will be added to request. |
| | 2404 | | /// </param> |
| | 2405 | | /// <param name='cancellationToken'> |
| | 2406 | | /// The cancellation token. |
| | 2407 | | /// </param> |
| | 2408 | | /// <exception cref="ErrorResponseException"> |
| | 2409 | | /// Thrown when the operation returned an invalid status code |
| | 2410 | | /// </exception> |
| | 2411 | | /// <exception cref="SerializationException"> |
| | 2412 | | /// Thrown when unable to deserialize the response |
| | 2413 | | /// </exception> |
| | 2414 | | /// <exception cref="ValidationException"> |
| | 2415 | | /// Thrown when a required parameter is null |
| | 2416 | | /// </exception> |
| | 2417 | | /// <exception cref="System.ArgumentNullException"> |
| | 2418 | | /// Thrown when a required parameter is null |
| | 2419 | | /// </exception> |
| | 2420 | | /// <return> |
| | 2421 | | /// A response object containing the response body and response headers. |
| | 2422 | | /// </return> |
| | 2423 | | public async Task<HttpOperationResponse<OperationStatus>> UpdatePublishSettingsWithHttpMessagesAsync(System.Guid |
| | 2424 | | { |
| 1 | 2425 | | if (Client.Endpoint == null) |
| | 2426 | | { |
| 0 | 2427 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2428 | | } |
| 1 | 2429 | | if (publishSettingUpdateObject == null) |
| | 2430 | | { |
| 0 | 2431 | | throw new ValidationException(ValidationRules.CannotBeNull, "publishSettingUpdateObject"); |
| | 2432 | | } |
| | 2433 | | // Tracing |
| 1 | 2434 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 2435 | | string _invocationId = null; |
| 1 | 2436 | | if (_shouldTrace) |
| | 2437 | | { |
| 0 | 2438 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2439 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2440 | | tracingParameters.Add("appId", appId); |
| 0 | 2441 | | tracingParameters.Add("publishSettingUpdateObject", publishSettingUpdateObject); |
| 0 | 2442 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2443 | | ServiceClientTracing.Enter(_invocationId, this, "UpdatePublishSettings", tracingParameters); |
| | 2444 | | } |
| | 2445 | | // Construct URL |
| 1 | 2446 | | var _baseUrl = Client.BaseUri; |
| 1 | 2447 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/publishsettings"; |
| 1 | 2448 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 2449 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 2450 | | // Create HTTP transport objects |
| 1 | 2451 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 2452 | | HttpResponseMessage _httpResponse = null; |
| 1 | 2453 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 1 | 2454 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2455 | | // Set Headers |
| | 2456 | |
|
| | 2457 | |
|
| 1 | 2458 | | if (customHeaders != null) |
| | 2459 | | { |
| 0 | 2460 | | foreach(var _header in customHeaders) |
| | 2461 | | { |
| 0 | 2462 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2463 | | { |
| 0 | 2464 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2465 | | } |
| 0 | 2466 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2467 | | } |
| | 2468 | | } |
| | 2469 | |
|
| | 2470 | | // Serialize Request |
| 1 | 2471 | | string _requestContent = null; |
| 1 | 2472 | | if(publishSettingUpdateObject != null) |
| | 2473 | | { |
| 1 | 2474 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(publishSettingUpdateObject, Client. |
| 1 | 2475 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 2476 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 2477 | | } |
| | 2478 | | // Set Credentials |
| 1 | 2479 | | if (Client.Credentials != null) |
| | 2480 | | { |
| 1 | 2481 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2482 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2483 | | } |
| | 2484 | | // Send Request |
| 1 | 2485 | | if (_shouldTrace) |
| | 2486 | | { |
| 0 | 2487 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2488 | | } |
| 1 | 2489 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2490 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 2491 | | if (_shouldTrace) |
| | 2492 | | { |
| 0 | 2493 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2494 | | } |
| 1 | 2495 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 2496 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2497 | | string _responseContent = null; |
| 1 | 2498 | | if ((int)_statusCode != 200) |
| | 2499 | | { |
| 0 | 2500 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 2501 | | try |
| | 2502 | | { |
| 0 | 2503 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2504 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 2505 | | if (_errorBody != null) |
| | 2506 | | { |
| 0 | 2507 | | ex.Body = _errorBody; |
| | 2508 | | } |
| 0 | 2509 | | } |
| 0 | 2510 | | catch (JsonException) |
| | 2511 | | { |
| | 2512 | | // Ignore the exception |
| 0 | 2513 | | } |
| 0 | 2514 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2515 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2516 | | if (_shouldTrace) |
| | 2517 | | { |
| 0 | 2518 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2519 | | } |
| 0 | 2520 | | _httpRequest.Dispose(); |
| 0 | 2521 | | if (_httpResponse != null) |
| | 2522 | | { |
| 0 | 2523 | | _httpResponse.Dispose(); |
| | 2524 | | } |
| 0 | 2525 | | throw ex; |
| | 2526 | | } |
| | 2527 | | // Create Result |
| 1 | 2528 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 1 | 2529 | | _result.Request = _httpRequest; |
| 1 | 2530 | | _result.Response = _httpResponse; |
| | 2531 | | // Deserialize Response |
| 1 | 2532 | | if ((int)_statusCode == 200) |
| | 2533 | | { |
| 1 | 2534 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2535 | | try |
| | 2536 | | { |
| 1 | 2537 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 1 | 2538 | | } |
| 0 | 2539 | | catch (JsonException ex) |
| | 2540 | | { |
| 0 | 2541 | | _httpRequest.Dispose(); |
| 0 | 2542 | | if (_httpResponse != null) |
| | 2543 | | { |
| 0 | 2544 | | _httpResponse.Dispose(); |
| | 2545 | | } |
| 0 | 2546 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2547 | | } |
| | 2548 | | } |
| 1 | 2549 | | if (_shouldTrace) |
| | 2550 | | { |
| 0 | 2551 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2552 | | } |
| 1 | 2553 | | return _result; |
| 1 | 2554 | | } |
| | 2555 | |
|
| | 2556 | | /// <summary> |
| | 2557 | | /// Returns the available endpoint deployment regions and URLs. |
| | 2558 | | /// </summary> |
| | 2559 | | /// <param name='appId'> |
| | 2560 | | /// The application ID. |
| | 2561 | | /// </param> |
| | 2562 | | /// <param name='customHeaders'> |
| | 2563 | | /// Headers that will be added to request. |
| | 2564 | | /// </param> |
| | 2565 | | /// <param name='cancellationToken'> |
| | 2566 | | /// The cancellation token. |
| | 2567 | | /// </param> |
| | 2568 | | /// <exception cref="ErrorResponseException"> |
| | 2569 | | /// Thrown when the operation returned an invalid status code |
| | 2570 | | /// </exception> |
| | 2571 | | /// <exception cref="SerializationException"> |
| | 2572 | | /// Thrown when unable to deserialize the response |
| | 2573 | | /// </exception> |
| | 2574 | | /// <exception cref="ValidationException"> |
| | 2575 | | /// Thrown when a required parameter is null |
| | 2576 | | /// </exception> |
| | 2577 | | /// <exception cref="System.ArgumentNullException"> |
| | 2578 | | /// Thrown when a required parameter is null |
| | 2579 | | /// </exception> |
| | 2580 | | /// <return> |
| | 2581 | | /// A response object containing the response body and response headers. |
| | 2582 | | /// </return> |
| | 2583 | | public async Task<HttpOperationResponse<IDictionary<string, string>>> ListEndpointsWithHttpMessagesAsync(System. |
| | 2584 | | { |
| 1 | 2585 | | if (Client.Endpoint == null) |
| | 2586 | | { |
| 0 | 2587 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2588 | | } |
| | 2589 | | // Tracing |
| 1 | 2590 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 2591 | | string _invocationId = null; |
| 1 | 2592 | | if (_shouldTrace) |
| | 2593 | | { |
| 0 | 2594 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2595 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2596 | | tracingParameters.Add("appId", appId); |
| 0 | 2597 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2598 | | ServiceClientTracing.Enter(_invocationId, this, "ListEndpoints", tracingParameters); |
| | 2599 | | } |
| | 2600 | | // Construct URL |
| 1 | 2601 | | var _baseUrl = Client.BaseUri; |
| 1 | 2602 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/endpoints"; |
| 1 | 2603 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 2604 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 2605 | | // Create HTTP transport objects |
| 1 | 2606 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 2607 | | HttpResponseMessage _httpResponse = null; |
| 1 | 2608 | | _httpRequest.Method = new HttpMethod("GET"); |
| 1 | 2609 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2610 | | // Set Headers |
| | 2611 | |
|
| | 2612 | |
|
| 1 | 2613 | | if (customHeaders != null) |
| | 2614 | | { |
| 0 | 2615 | | foreach(var _header in customHeaders) |
| | 2616 | | { |
| 0 | 2617 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2618 | | { |
| 0 | 2619 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2620 | | } |
| 0 | 2621 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2622 | | } |
| | 2623 | | } |
| | 2624 | |
|
| | 2625 | | // Serialize Request |
| 1 | 2626 | | string _requestContent = null; |
| | 2627 | | // Set Credentials |
| 1 | 2628 | | if (Client.Credentials != null) |
| | 2629 | | { |
| 1 | 2630 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2631 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2632 | | } |
| | 2633 | | // Send Request |
| 1 | 2634 | | if (_shouldTrace) |
| | 2635 | | { |
| 0 | 2636 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2637 | | } |
| 1 | 2638 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2639 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 2640 | | if (_shouldTrace) |
| | 2641 | | { |
| 0 | 2642 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2643 | | } |
| 1 | 2644 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 2645 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2646 | | string _responseContent = null; |
| 1 | 2647 | | if ((int)_statusCode != 200) |
| | 2648 | | { |
| 0 | 2649 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 2650 | | try |
| | 2651 | | { |
| 0 | 2652 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2653 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 2654 | | if (_errorBody != null) |
| | 2655 | | { |
| 0 | 2656 | | ex.Body = _errorBody; |
| | 2657 | | } |
| 0 | 2658 | | } |
| 0 | 2659 | | catch (JsonException) |
| | 2660 | | { |
| | 2661 | | // Ignore the exception |
| 0 | 2662 | | } |
| 0 | 2663 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2664 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2665 | | if (_shouldTrace) |
| | 2666 | | { |
| 0 | 2667 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2668 | | } |
| 0 | 2669 | | _httpRequest.Dispose(); |
| 0 | 2670 | | if (_httpResponse != null) |
| | 2671 | | { |
| 0 | 2672 | | _httpResponse.Dispose(); |
| | 2673 | | } |
| 0 | 2674 | | throw ex; |
| | 2675 | | } |
| | 2676 | | // Create Result |
| 1 | 2677 | | var _result = new HttpOperationResponse<IDictionary<string, string>>(); |
| 1 | 2678 | | _result.Request = _httpRequest; |
| 1 | 2679 | | _result.Response = _httpResponse; |
| | 2680 | | // Deserialize Response |
| 1 | 2681 | | if ((int)_statusCode == 200) |
| | 2682 | | { |
| 1 | 2683 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2684 | | try |
| | 2685 | | { |
| 1 | 2686 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IDictionary<string, string>>(_re |
| 1 | 2687 | | } |
| 0 | 2688 | | catch (JsonException ex) |
| | 2689 | | { |
| 0 | 2690 | | _httpRequest.Dispose(); |
| 0 | 2691 | | if (_httpResponse != null) |
| | 2692 | | { |
| 0 | 2693 | | _httpResponse.Dispose(); |
| | 2694 | | } |
| 0 | 2695 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2696 | | } |
| | 2697 | | } |
| 1 | 2698 | | if (_shouldTrace) |
| | 2699 | | { |
| 0 | 2700 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2701 | | } |
| 1 | 2702 | | return _result; |
| 1 | 2703 | | } |
| | 2704 | |
|
| | 2705 | | /// <summary> |
| | 2706 | | /// Gets all the available custom prebuilt domains for all cultures. |
| | 2707 | | /// </summary> |
| | 2708 | | /// <param name='customHeaders'> |
| | 2709 | | /// Headers that will be added to request. |
| | 2710 | | /// </param> |
| | 2711 | | /// <param name='cancellationToken'> |
| | 2712 | | /// The cancellation token. |
| | 2713 | | /// </param> |
| | 2714 | | /// <exception cref="ErrorResponseException"> |
| | 2715 | | /// Thrown when the operation returned an invalid status code |
| | 2716 | | /// </exception> |
| | 2717 | | /// <exception cref="SerializationException"> |
| | 2718 | | /// Thrown when unable to deserialize the response |
| | 2719 | | /// </exception> |
| | 2720 | | /// <exception cref="ValidationException"> |
| | 2721 | | /// Thrown when a required parameter is null |
| | 2722 | | /// </exception> |
| | 2723 | | /// <exception cref="System.ArgumentNullException"> |
| | 2724 | | /// Thrown when a required parameter is null |
| | 2725 | | /// </exception> |
| | 2726 | | /// <return> |
| | 2727 | | /// A response object containing the response body and response headers. |
| | 2728 | | /// </return> |
| | 2729 | | public async Task<HttpOperationResponse<IList<PrebuiltDomain>>> ListAvailableCustomPrebuiltDomainsWithHttpMessag |
| | 2730 | | { |
| 1 | 2731 | | if (Client.Endpoint == null) |
| | 2732 | | { |
| 0 | 2733 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2734 | | } |
| | 2735 | | // Tracing |
| 1 | 2736 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 2737 | | string _invocationId = null; |
| 1 | 2738 | | if (_shouldTrace) |
| | 2739 | | { |
| 0 | 2740 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2741 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2742 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2743 | | ServiceClientTracing.Enter(_invocationId, this, "ListAvailableCustomPrebuiltDomains", tracingParameters) |
| | 2744 | | } |
| | 2745 | | // Construct URL |
| 1 | 2746 | | var _baseUrl = Client.BaseUri; |
| 1 | 2747 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/customprebuiltdomains"; |
| 1 | 2748 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 2749 | | // Create HTTP transport objects |
| 1 | 2750 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 2751 | | HttpResponseMessage _httpResponse = null; |
| 1 | 2752 | | _httpRequest.Method = new HttpMethod("GET"); |
| 1 | 2753 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2754 | | // Set Headers |
| | 2755 | |
|
| | 2756 | |
|
| 1 | 2757 | | if (customHeaders != null) |
| | 2758 | | { |
| 0 | 2759 | | foreach(var _header in customHeaders) |
| | 2760 | | { |
| 0 | 2761 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2762 | | { |
| 0 | 2763 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2764 | | } |
| 0 | 2765 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2766 | | } |
| | 2767 | | } |
| | 2768 | |
|
| | 2769 | | // Serialize Request |
| 1 | 2770 | | string _requestContent = null; |
| | 2771 | | // Set Credentials |
| 1 | 2772 | | if (Client.Credentials != null) |
| | 2773 | | { |
| 1 | 2774 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2775 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2776 | | } |
| | 2777 | | // Send Request |
| 1 | 2778 | | if (_shouldTrace) |
| | 2779 | | { |
| 0 | 2780 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2781 | | } |
| 1 | 2782 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2783 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 2784 | | if (_shouldTrace) |
| | 2785 | | { |
| 0 | 2786 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2787 | | } |
| 1 | 2788 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 2789 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2790 | | string _responseContent = null; |
| 1 | 2791 | | if ((int)_statusCode != 200) |
| | 2792 | | { |
| 0 | 2793 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 2794 | | try |
| | 2795 | | { |
| 0 | 2796 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2797 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 2798 | | if (_errorBody != null) |
| | 2799 | | { |
| 0 | 2800 | | ex.Body = _errorBody; |
| | 2801 | | } |
| 0 | 2802 | | } |
| 0 | 2803 | | catch (JsonException) |
| | 2804 | | { |
| | 2805 | | // Ignore the exception |
| 0 | 2806 | | } |
| 0 | 2807 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2808 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2809 | | if (_shouldTrace) |
| | 2810 | | { |
| 0 | 2811 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2812 | | } |
| 0 | 2813 | | _httpRequest.Dispose(); |
| 0 | 2814 | | if (_httpResponse != null) |
| | 2815 | | { |
| 0 | 2816 | | _httpResponse.Dispose(); |
| | 2817 | | } |
| 0 | 2818 | | throw ex; |
| | 2819 | | } |
| | 2820 | | // Create Result |
| 1 | 2821 | | var _result = new HttpOperationResponse<IList<PrebuiltDomain>>(); |
| 1 | 2822 | | _result.Request = _httpRequest; |
| 1 | 2823 | | _result.Response = _httpResponse; |
| | 2824 | | // Deserialize Response |
| 1 | 2825 | | if ((int)_statusCode == 200) |
| | 2826 | | { |
| 1 | 2827 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2828 | | try |
| | 2829 | | { |
| 1 | 2830 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PrebuiltDomain>>(_response |
| 1 | 2831 | | } |
| 0 | 2832 | | catch (JsonException ex) |
| | 2833 | | { |
| 0 | 2834 | | _httpRequest.Dispose(); |
| 0 | 2835 | | if (_httpResponse != null) |
| | 2836 | | { |
| 0 | 2837 | | _httpResponse.Dispose(); |
| | 2838 | | } |
| 0 | 2839 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2840 | | } |
| | 2841 | | } |
| 1 | 2842 | | if (_shouldTrace) |
| | 2843 | | { |
| 0 | 2844 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2845 | | } |
| 1 | 2846 | | return _result; |
| 1 | 2847 | | } |
| | 2848 | |
|
| | 2849 | | /// <summary> |
| | 2850 | | /// Adds a prebuilt domain along with its intent and entity models as a new |
| | 2851 | | /// application. |
| | 2852 | | /// </summary> |
| | 2853 | | /// <param name='prebuiltDomainCreateObject'> |
| | 2854 | | /// A prebuilt domain create object containing the name and culture of the |
| | 2855 | | /// domain. |
| | 2856 | | /// </param> |
| | 2857 | | /// <param name='customHeaders'> |
| | 2858 | | /// Headers that will be added to request. |
| | 2859 | | /// </param> |
| | 2860 | | /// <param name='cancellationToken'> |
| | 2861 | | /// The cancellation token. |
| | 2862 | | /// </param> |
| | 2863 | | /// <exception cref="ErrorResponseException"> |
| | 2864 | | /// Thrown when the operation returned an invalid status code |
| | 2865 | | /// </exception> |
| | 2866 | | /// <exception cref="SerializationException"> |
| | 2867 | | /// Thrown when unable to deserialize the response |
| | 2868 | | /// </exception> |
| | 2869 | | /// <exception cref="ValidationException"> |
| | 2870 | | /// Thrown when a required parameter is null |
| | 2871 | | /// </exception> |
| | 2872 | | /// <exception cref="System.ArgumentNullException"> |
| | 2873 | | /// Thrown when a required parameter is null |
| | 2874 | | /// </exception> |
| | 2875 | | /// <return> |
| | 2876 | | /// A response object containing the response body and response headers. |
| | 2877 | | /// </return> |
| | 2878 | | public async Task<HttpOperationResponse<System.Guid>> AddCustomPrebuiltDomainWithHttpMessagesAsync(PrebuiltDomai |
| | 2879 | | { |
| 1 | 2880 | | if (Client.Endpoint == null) |
| | 2881 | | { |
| 0 | 2882 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2883 | | } |
| 1 | 2884 | | if (prebuiltDomainCreateObject == null) |
| | 2885 | | { |
| 0 | 2886 | | throw new ValidationException(ValidationRules.CannotBeNull, "prebuiltDomainCreateObject"); |
| | 2887 | | } |
| | 2888 | | // Tracing |
| 1 | 2889 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 2890 | | string _invocationId = null; |
| 1 | 2891 | | if (_shouldTrace) |
| | 2892 | | { |
| 0 | 2893 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2894 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2895 | | tracingParameters.Add("prebuiltDomainCreateObject", prebuiltDomainCreateObject); |
| 0 | 2896 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2897 | | ServiceClientTracing.Enter(_invocationId, this, "AddCustomPrebuiltDomain", tracingParameters); |
| | 2898 | | } |
| | 2899 | | // Construct URL |
| 1 | 2900 | | var _baseUrl = Client.BaseUri; |
| 1 | 2901 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/customprebuiltdomains"; |
| 1 | 2902 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 2903 | | // Create HTTP transport objects |
| 1 | 2904 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 2905 | | HttpResponseMessage _httpResponse = null; |
| 1 | 2906 | | _httpRequest.Method = new HttpMethod("POST"); |
| 1 | 2907 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2908 | | // Set Headers |
| | 2909 | |
|
| | 2910 | |
|
| 1 | 2911 | | if (customHeaders != null) |
| | 2912 | | { |
| 0 | 2913 | | foreach(var _header in customHeaders) |
| | 2914 | | { |
| 0 | 2915 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2916 | | { |
| 0 | 2917 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2918 | | } |
| 0 | 2919 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2920 | | } |
| | 2921 | | } |
| | 2922 | |
|
| | 2923 | | // Serialize Request |
| 1 | 2924 | | string _requestContent = null; |
| 1 | 2925 | | if(prebuiltDomainCreateObject != null) |
| | 2926 | | { |
| 1 | 2927 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(prebuiltDomainCreateObject, Client. |
| 1 | 2928 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 2929 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 2930 | | } |
| | 2931 | | // Set Credentials |
| 1 | 2932 | | if (Client.Credentials != null) |
| | 2933 | | { |
| 1 | 2934 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2935 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2936 | | } |
| | 2937 | | // Send Request |
| 1 | 2938 | | if (_shouldTrace) |
| | 2939 | | { |
| 0 | 2940 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2941 | | } |
| 1 | 2942 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2943 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 2944 | | if (_shouldTrace) |
| | 2945 | | { |
| 0 | 2946 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2947 | | } |
| 1 | 2948 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 2949 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 2950 | | string _responseContent = null; |
| 1 | 2951 | | if ((int)_statusCode != 201) |
| | 2952 | | { |
| 0 | 2953 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 2954 | | try |
| | 2955 | | { |
| 0 | 2956 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2957 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 2958 | | if (_errorBody != null) |
| | 2959 | | { |
| 0 | 2960 | | ex.Body = _errorBody; |
| | 2961 | | } |
| 0 | 2962 | | } |
| 0 | 2963 | | catch (JsonException) |
| | 2964 | | { |
| | 2965 | | // Ignore the exception |
| 0 | 2966 | | } |
| 0 | 2967 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2968 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2969 | | if (_shouldTrace) |
| | 2970 | | { |
| 0 | 2971 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2972 | | } |
| 0 | 2973 | | _httpRequest.Dispose(); |
| 0 | 2974 | | if (_httpResponse != null) |
| | 2975 | | { |
| 0 | 2976 | | _httpResponse.Dispose(); |
| | 2977 | | } |
| 0 | 2978 | | throw ex; |
| | 2979 | | } |
| | 2980 | | // Create Result |
| 1 | 2981 | | var _result = new HttpOperationResponse<System.Guid>(); |
| 1 | 2982 | | _result.Request = _httpRequest; |
| 1 | 2983 | | _result.Response = _httpResponse; |
| | 2984 | | // Deserialize Response |
| 1 | 2985 | | if ((int)_statusCode == 201) |
| | 2986 | | { |
| 1 | 2987 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2988 | | try |
| | 2989 | | { |
| 1 | 2990 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<System.Guid>(_responseContent, C |
| 1 | 2991 | | } |
| 0 | 2992 | | catch (JsonException ex) |
| | 2993 | | { |
| 0 | 2994 | | _httpRequest.Dispose(); |
| 0 | 2995 | | if (_httpResponse != null) |
| | 2996 | | { |
| 0 | 2997 | | _httpResponse.Dispose(); |
| | 2998 | | } |
| 0 | 2999 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3000 | | } |
| | 3001 | | } |
| 1 | 3002 | | if (_shouldTrace) |
| | 3003 | | { |
| 0 | 3004 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3005 | | } |
| 1 | 3006 | | return _result; |
| 1 | 3007 | | } |
| | 3008 | |
|
| | 3009 | | /// <summary> |
| | 3010 | | /// Gets all the available prebuilt domains for a specific culture. |
| | 3011 | | /// </summary> |
| | 3012 | | /// <param name='culture'> |
| | 3013 | | /// Culture. |
| | 3014 | | /// </param> |
| | 3015 | | /// <param name='customHeaders'> |
| | 3016 | | /// Headers that will be added to request. |
| | 3017 | | /// </param> |
| | 3018 | | /// <param name='cancellationToken'> |
| | 3019 | | /// The cancellation token. |
| | 3020 | | /// </param> |
| | 3021 | | /// <exception cref="ErrorResponseException"> |
| | 3022 | | /// Thrown when the operation returned an invalid status code |
| | 3023 | | /// </exception> |
| | 3024 | | /// <exception cref="SerializationException"> |
| | 3025 | | /// Thrown when unable to deserialize the response |
| | 3026 | | /// </exception> |
| | 3027 | | /// <exception cref="ValidationException"> |
| | 3028 | | /// Thrown when a required parameter is null |
| | 3029 | | /// </exception> |
| | 3030 | | /// <exception cref="System.ArgumentNullException"> |
| | 3031 | | /// Thrown when a required parameter is null |
| | 3032 | | /// </exception> |
| | 3033 | | /// <return> |
| | 3034 | | /// A response object containing the response body and response headers. |
| | 3035 | | /// </return> |
| | 3036 | | public async Task<HttpOperationResponse<IList<PrebuiltDomain>>> ListAvailableCustomPrebuiltDomainsForCultureWith |
| | 3037 | | { |
| 2 | 3038 | | if (Client.Endpoint == null) |
| | 3039 | | { |
| 0 | 3040 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 3041 | | } |
| 2 | 3042 | | if (culture == null) |
| | 3043 | | { |
| 0 | 3044 | | throw new ValidationException(ValidationRules.CannotBeNull, "culture"); |
| | 3045 | | } |
| | 3046 | | // Tracing |
| 2 | 3047 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 3048 | | string _invocationId = null; |
| 2 | 3049 | | if (_shouldTrace) |
| | 3050 | | { |
| 0 | 3051 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3052 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3053 | | tracingParameters.Add("culture", culture); |
| 0 | 3054 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3055 | | ServiceClientTracing.Enter(_invocationId, this, "ListAvailableCustomPrebuiltDomainsForCulture", tracingP |
| | 3056 | | } |
| | 3057 | | // Construct URL |
| 2 | 3058 | | var _baseUrl = Client.BaseUri; |
| 2 | 3059 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/customprebuiltdomains/{culture}"; |
| 2 | 3060 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 3061 | | _url = _url.Replace("{culture}", System.Uri.EscapeDataString(culture)); |
| | 3062 | | // Create HTTP transport objects |
| 2 | 3063 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 3064 | | HttpResponseMessage _httpResponse = null; |
| 2 | 3065 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 3066 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3067 | | // Set Headers |
| | 3068 | |
|
| | 3069 | |
|
| 2 | 3070 | | if (customHeaders != null) |
| | 3071 | | { |
| 0 | 3072 | | foreach(var _header in customHeaders) |
| | 3073 | | { |
| 0 | 3074 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3075 | | { |
| 0 | 3076 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3077 | | } |
| 0 | 3078 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3079 | | } |
| | 3080 | | } |
| | 3081 | |
|
| | 3082 | | // Serialize Request |
| 2 | 3083 | | string _requestContent = null; |
| | 3084 | | // Set Credentials |
| 2 | 3085 | | if (Client.Credentials != null) |
| | 3086 | | { |
| 2 | 3087 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3088 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3089 | | } |
| | 3090 | | // Send Request |
| 2 | 3091 | | if (_shouldTrace) |
| | 3092 | | { |
| 0 | 3093 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3094 | | } |
| 2 | 3095 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3096 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 3097 | | if (_shouldTrace) |
| | 3098 | | { |
| 0 | 3099 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3100 | | } |
| 2 | 3101 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 3102 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3103 | | string _responseContent = null; |
| 2 | 3104 | | if ((int)_statusCode != 200) |
| | 3105 | | { |
| 0 | 3106 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 3107 | | try |
| | 3108 | | { |
| 0 | 3109 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3110 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 3111 | | if (_errorBody != null) |
| | 3112 | | { |
| 0 | 3113 | | ex.Body = _errorBody; |
| | 3114 | | } |
| 0 | 3115 | | } |
| 0 | 3116 | | catch (JsonException) |
| | 3117 | | { |
| | 3118 | | // Ignore the exception |
| 0 | 3119 | | } |
| 0 | 3120 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3121 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3122 | | if (_shouldTrace) |
| | 3123 | | { |
| 0 | 3124 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3125 | | } |
| 0 | 3126 | | _httpRequest.Dispose(); |
| 0 | 3127 | | if (_httpResponse != null) |
| | 3128 | | { |
| 0 | 3129 | | _httpResponse.Dispose(); |
| | 3130 | | } |
| 0 | 3131 | | throw ex; |
| | 3132 | | } |
| | 3133 | | // Create Result |
| 2 | 3134 | | var _result = new HttpOperationResponse<IList<PrebuiltDomain>>(); |
| 2 | 3135 | | _result.Request = _httpRequest; |
| 2 | 3136 | | _result.Response = _httpResponse; |
| | 3137 | | // Deserialize Response |
| 2 | 3138 | | if ((int)_statusCode == 200) |
| | 3139 | | { |
| 2 | 3140 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3141 | | try |
| | 3142 | | { |
| 2 | 3143 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PrebuiltDomain>>(_response |
| 2 | 3144 | | } |
| 0 | 3145 | | catch (JsonException ex) |
| | 3146 | | { |
| 0 | 3147 | | _httpRequest.Dispose(); |
| 0 | 3148 | | if (_httpResponse != null) |
| | 3149 | | { |
| 0 | 3150 | | _httpResponse.Dispose(); |
| | 3151 | | } |
| 0 | 3152 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3153 | | } |
| | 3154 | | } |
| 2 | 3155 | | if (_shouldTrace) |
| | 3156 | | { |
| 0 | 3157 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3158 | | } |
| 2 | 3159 | | return _result; |
| 2 | 3160 | | } |
| | 3161 | |
|
| | 3162 | | /// <summary> |
| | 3163 | | /// package - Gets published LUIS application package in binary stream GZip |
| | 3164 | | /// format |
| | 3165 | | /// </summary> |
| | 3166 | | /// <remarks> |
| | 3167 | | /// Packages a published LUIS application as a GZip file to be used in the LUIS |
| | 3168 | | /// container. |
| | 3169 | | /// </remarks> |
| | 3170 | | /// <param name='appId'> |
| | 3171 | | /// The application ID. |
| | 3172 | | /// </param> |
| | 3173 | | /// <param name='slotName'> |
| | 3174 | | /// The publishing slot name. |
| | 3175 | | /// </param> |
| | 3176 | | /// <param name='customHeaders'> |
| | 3177 | | /// Headers that will be added to request. |
| | 3178 | | /// </param> |
| | 3179 | | /// <param name='cancellationToken'> |
| | 3180 | | /// The cancellation token. |
| | 3181 | | /// </param> |
| | 3182 | | /// <exception cref="ErrorResponseException"> |
| | 3183 | | /// Thrown when the operation returned an invalid status code |
| | 3184 | | /// </exception> |
| | 3185 | | /// <exception cref="SerializationException"> |
| | 3186 | | /// Thrown when unable to deserialize the response |
| | 3187 | | /// </exception> |
| | 3188 | | /// <exception cref="ValidationException"> |
| | 3189 | | /// Thrown when a required parameter is null |
| | 3190 | | /// </exception> |
| | 3191 | | /// <exception cref="System.ArgumentNullException"> |
| | 3192 | | /// Thrown when a required parameter is null |
| | 3193 | | /// </exception> |
| | 3194 | | /// <return> |
| | 3195 | | /// A response object containing the response body and response headers. |
| | 3196 | | /// </return> |
| | 3197 | | public async Task<HttpOperationResponse<Stream>> PackagePublishedApplicationAsGzipWithHttpMessagesAsync(System.G |
| | 3198 | | { |
| 0 | 3199 | | if (Client.Endpoint == null) |
| | 3200 | | { |
| 0 | 3201 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 3202 | | } |
| 0 | 3203 | | if (slotName == null) |
| | 3204 | | { |
| 0 | 3205 | | throw new ValidationException(ValidationRules.CannotBeNull, "slotName"); |
| | 3206 | | } |
| | 3207 | | // Tracing |
| 0 | 3208 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 3209 | | string _invocationId = null; |
| 0 | 3210 | | if (_shouldTrace) |
| | 3211 | | { |
| 0 | 3212 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3213 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3214 | | tracingParameters.Add("appId", appId); |
| 0 | 3215 | | tracingParameters.Add("slotName", slotName); |
| 0 | 3216 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3217 | | ServiceClientTracing.Enter(_invocationId, this, "PackagePublishedApplicationAsGzip", tracingParameters); |
| | 3218 | | } |
| | 3219 | | // Construct URL |
| 0 | 3220 | | var _baseUrl = Client.BaseUri; |
| 0 | 3221 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "package/{appId}/slot/{slotName}/gzip"; |
| 0 | 3222 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 3223 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 0 | 3224 | | _url = _url.Replace("{slotName}", System.Uri.EscapeDataString(slotName)); |
| | 3225 | | // Create HTTP transport objects |
| 0 | 3226 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 3227 | | HttpResponseMessage _httpResponse = null; |
| 0 | 3228 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 3229 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3230 | | // Set Headers |
| | 3231 | |
|
| | 3232 | |
|
| 0 | 3233 | | if (customHeaders != null) |
| | 3234 | | { |
| 0 | 3235 | | foreach(var _header in customHeaders) |
| | 3236 | | { |
| 0 | 3237 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3238 | | { |
| 0 | 3239 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3240 | | } |
| 0 | 3241 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3242 | | } |
| | 3243 | | } |
| | 3244 | |
|
| | 3245 | | // Serialize Request |
| 0 | 3246 | | string _requestContent = null; |
| | 3247 | | // Set Credentials |
| 0 | 3248 | | if (Client.Credentials != null) |
| | 3249 | | { |
| 0 | 3250 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3251 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3252 | | } |
| | 3253 | | // Send Request |
| 0 | 3254 | | if (_shouldTrace) |
| | 3255 | | { |
| 0 | 3256 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3257 | | } |
| 0 | 3258 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3259 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons |
| 0 | 3260 | | if (_shouldTrace) |
| | 3261 | | { |
| 0 | 3262 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3263 | | } |
| 0 | 3264 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 3265 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3266 | | string _responseContent = null; |
| 0 | 3267 | | if ((int)_statusCode != 200) |
| | 3268 | | { |
| 0 | 3269 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 3270 | | try |
| | 3271 | | { |
| 0 | 3272 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3273 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 3274 | | if (_errorBody != null) |
| | 3275 | | { |
| 0 | 3276 | | ex.Body = _errorBody; |
| | 3277 | | } |
| 0 | 3278 | | } |
| 0 | 3279 | | catch (JsonException) |
| | 3280 | | { |
| | 3281 | | // Ignore the exception |
| 0 | 3282 | | } |
| 0 | 3283 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3284 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3285 | | if (_shouldTrace) |
| | 3286 | | { |
| 0 | 3287 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3288 | | } |
| 0 | 3289 | | _httpRequest.Dispose(); |
| 0 | 3290 | | if (_httpResponse != null) |
| | 3291 | | { |
| 0 | 3292 | | _httpResponse.Dispose(); |
| | 3293 | | } |
| 0 | 3294 | | throw ex; |
| | 3295 | | } |
| | 3296 | | // Create Result |
| 0 | 3297 | | var _result = new HttpOperationResponse<Stream>(); |
| 0 | 3298 | | _result.Request = _httpRequest; |
| 0 | 3299 | | _result.Response = _httpResponse; |
| | 3300 | | // Deserialize Response |
| 0 | 3301 | | if ((int)_statusCode == 200) |
| | 3302 | | { |
| 0 | 3303 | | _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); |
| | 3304 | | } |
| 0 | 3305 | | if (_shouldTrace) |
| | 3306 | | { |
| 0 | 3307 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3308 | | } |
| 0 | 3309 | | return _result; |
| 0 | 3310 | | } |
| | 3311 | |
|
| | 3312 | | /// <summary> |
| | 3313 | | /// package - Gets trained LUIS application package in binary stream GZip |
| | 3314 | | /// format |
| | 3315 | | /// </summary> |
| | 3316 | | /// <remarks> |
| | 3317 | | /// Packages trained LUIS application as GZip file to be used in the LUIS |
| | 3318 | | /// container. |
| | 3319 | | /// </remarks> |
| | 3320 | | /// <param name='appId'> |
| | 3321 | | /// The application ID. |
| | 3322 | | /// </param> |
| | 3323 | | /// <param name='versionId'> |
| | 3324 | | /// The version ID. |
| | 3325 | | /// </param> |
| | 3326 | | /// <param name='customHeaders'> |
| | 3327 | | /// Headers that will be added to request. |
| | 3328 | | /// </param> |
| | 3329 | | /// <param name='cancellationToken'> |
| | 3330 | | /// The cancellation token. |
| | 3331 | | /// </param> |
| | 3332 | | /// <exception cref="ErrorResponseException"> |
| | 3333 | | /// Thrown when the operation returned an invalid status code |
| | 3334 | | /// </exception> |
| | 3335 | | /// <exception cref="SerializationException"> |
| | 3336 | | /// Thrown when unable to deserialize the response |
| | 3337 | | /// </exception> |
| | 3338 | | /// <exception cref="ValidationException"> |
| | 3339 | | /// Thrown when a required parameter is null |
| | 3340 | | /// </exception> |
| | 3341 | | /// <exception cref="System.ArgumentNullException"> |
| | 3342 | | /// Thrown when a required parameter is null |
| | 3343 | | /// </exception> |
| | 3344 | | /// <return> |
| | 3345 | | /// A response object containing the response body and response headers. |
| | 3346 | | /// </return> |
| | 3347 | | public async Task<HttpOperationResponse<Stream>> PackageTrainedApplicationAsGzipWithHttpMessagesAsync(System.Gui |
| | 3348 | | { |
| 0 | 3349 | | if (Client.Endpoint == null) |
| | 3350 | | { |
| 0 | 3351 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 3352 | | } |
| 0 | 3353 | | if (versionId == null) |
| | 3354 | | { |
| 0 | 3355 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 3356 | | } |
| | 3357 | | // Tracing |
| 0 | 3358 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 3359 | | string _invocationId = null; |
| 0 | 3360 | | if (_shouldTrace) |
| | 3361 | | { |
| 0 | 3362 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3363 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3364 | | tracingParameters.Add("appId", appId); |
| 0 | 3365 | | tracingParameters.Add("versionId", versionId); |
| 0 | 3366 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3367 | | ServiceClientTracing.Enter(_invocationId, this, "PackageTrainedApplicationAsGzip", tracingParameters); |
| | 3368 | | } |
| | 3369 | | // Construct URL |
| 0 | 3370 | | var _baseUrl = Client.BaseUri; |
| 0 | 3371 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "package/{appId}/versions/{versionId}/gzip"; |
| 0 | 3372 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 3373 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 0 | 3374 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 3375 | | // Create HTTP transport objects |
| 0 | 3376 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 3377 | | HttpResponseMessage _httpResponse = null; |
| 0 | 3378 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 3379 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3380 | | // Set Headers |
| | 3381 | |
|
| | 3382 | |
|
| 0 | 3383 | | if (customHeaders != null) |
| | 3384 | | { |
| 0 | 3385 | | foreach(var _header in customHeaders) |
| | 3386 | | { |
| 0 | 3387 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3388 | | { |
| 0 | 3389 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3390 | | } |
| 0 | 3391 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3392 | | } |
| | 3393 | | } |
| | 3394 | |
|
| | 3395 | | // Serialize Request |
| 0 | 3396 | | string _requestContent = null; |
| | 3397 | | // Set Credentials |
| 0 | 3398 | | if (Client.Credentials != null) |
| | 3399 | | { |
| 0 | 3400 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3401 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3402 | | } |
| | 3403 | | // Send Request |
| 0 | 3404 | | if (_shouldTrace) |
| | 3405 | | { |
| 0 | 3406 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3407 | | } |
| 0 | 3408 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3409 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons |
| 0 | 3410 | | if (_shouldTrace) |
| | 3411 | | { |
| 0 | 3412 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3413 | | } |
| 0 | 3414 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 3415 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3416 | | string _responseContent = null; |
| 0 | 3417 | | if ((int)_statusCode != 200) |
| | 3418 | | { |
| 0 | 3419 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 3420 | | try |
| | 3421 | | { |
| 0 | 3422 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3423 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 3424 | | if (_errorBody != null) |
| | 3425 | | { |
| 0 | 3426 | | ex.Body = _errorBody; |
| | 3427 | | } |
| 0 | 3428 | | } |
| 0 | 3429 | | catch (JsonException) |
| | 3430 | | { |
| | 3431 | | // Ignore the exception |
| 0 | 3432 | | } |
| 0 | 3433 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3434 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3435 | | if (_shouldTrace) |
| | 3436 | | { |
| 0 | 3437 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3438 | | } |
| 0 | 3439 | | _httpRequest.Dispose(); |
| 0 | 3440 | | if (_httpResponse != null) |
| | 3441 | | { |
| 0 | 3442 | | _httpResponse.Dispose(); |
| | 3443 | | } |
| 0 | 3444 | | throw ex; |
| | 3445 | | } |
| | 3446 | | // Create Result |
| 0 | 3447 | | var _result = new HttpOperationResponse<Stream>(); |
| 0 | 3448 | | _result.Request = _httpRequest; |
| 0 | 3449 | | _result.Response = _httpResponse; |
| | 3450 | | // Deserialize Response |
| 0 | 3451 | | if ((int)_statusCode == 200) |
| | 3452 | | { |
| 0 | 3453 | | _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); |
| | 3454 | | } |
| 0 | 3455 | | if (_shouldTrace) |
| | 3456 | | { |
| 0 | 3457 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3458 | | } |
| 0 | 3459 | | return _result; |
| 0 | 3460 | | } |
| | 3461 | |
|
| | 3462 | | /// <summary> |
| | 3463 | | /// Imports an application to LUIS, the application's structure is included in |
| | 3464 | | /// the request body. |
| | 3465 | | /// </summary> |
| | 3466 | | /// <param name='luisAppV2'> |
| | 3467 | | /// A LUIS application structure. |
| | 3468 | | /// </param> |
| | 3469 | | /// <param name='appName'> |
| | 3470 | | /// The application name to create. If not specified, the application name will |
| | 3471 | | /// be read from the imported object. If the application name already exists, |
| | 3472 | | /// an error is returned. |
| | 3473 | | /// </param> |
| | 3474 | | /// <param name='customHeaders'> |
| | 3475 | | /// Headers that will be added to request. |
| | 3476 | | /// </param> |
| | 3477 | | /// <param name='cancellationToken'> |
| | 3478 | | /// The cancellation token. |
| | 3479 | | /// </param> |
| | 3480 | | /// <exception cref="ErrorResponseException"> |
| | 3481 | | /// Thrown when the operation returned an invalid status code |
| | 3482 | | /// </exception> |
| | 3483 | | /// <exception cref="SerializationException"> |
| | 3484 | | /// Thrown when unable to deserialize the response |
| | 3485 | | /// </exception> |
| | 3486 | | /// <exception cref="ValidationException"> |
| | 3487 | | /// Thrown when a required parameter is null |
| | 3488 | | /// </exception> |
| | 3489 | | /// <exception cref="System.ArgumentNullException"> |
| | 3490 | | /// Thrown when a required parameter is null |
| | 3491 | | /// </exception> |
| | 3492 | | /// <return> |
| | 3493 | | /// A response object containing the response body and response headers. |
| | 3494 | | /// </return> |
| | 3495 | | public async Task<HttpOperationResponse<System.Guid>> ImportV2AppWithHttpMessagesAsync(LuisAppV2 luisAppV2, stri |
| | 3496 | | { |
| 1 | 3497 | | if (Client.Endpoint == null) |
| | 3498 | | { |
| 0 | 3499 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 3500 | | } |
| 1 | 3501 | | if (luisAppV2 == null) |
| | 3502 | | { |
| 0 | 3503 | | throw new ValidationException(ValidationRules.CannotBeNull, "luisAppV2"); |
| | 3504 | | } |
| | 3505 | | // Tracing |
| 1 | 3506 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 3507 | | string _invocationId = null; |
| 1 | 3508 | | if (_shouldTrace) |
| | 3509 | | { |
| 0 | 3510 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3511 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3512 | | tracingParameters.Add("appName", appName); |
| 0 | 3513 | | tracingParameters.Add("luisAppV2", luisAppV2); |
| 0 | 3514 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3515 | | ServiceClientTracing.Enter(_invocationId, this, "ImportV2App", tracingParameters); |
| | 3516 | | } |
| | 3517 | | // Construct URL |
| 1 | 3518 | | var _baseUrl = Client.BaseUri; |
| 1 | 3519 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/import"; |
| 1 | 3520 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 3521 | | List<string> _queryParameters = new List<string>(); |
| 1 | 3522 | | if (appName != null) |
| | 3523 | | { |
| 1 | 3524 | | _queryParameters.Add(string.Format("appName={0}", System.Uri.EscapeDataString(appName))); |
| | 3525 | | } |
| 1 | 3526 | | if (_queryParameters.Count > 0) |
| | 3527 | | { |
| 1 | 3528 | | _url += "?" + string.Join("&", _queryParameters); |
| | 3529 | | } |
| | 3530 | | // Create HTTP transport objects |
| 1 | 3531 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 3532 | | HttpResponseMessage _httpResponse = null; |
| 1 | 3533 | | _httpRequest.Method = new HttpMethod("POST"); |
| 1 | 3534 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3535 | | // Set Headers |
| | 3536 | |
|
| | 3537 | |
|
| 1 | 3538 | | if (customHeaders != null) |
| | 3539 | | { |
| 0 | 3540 | | foreach(var _header in customHeaders) |
| | 3541 | | { |
| 0 | 3542 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3543 | | { |
| 0 | 3544 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3545 | | } |
| 0 | 3546 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3547 | | } |
| | 3548 | | } |
| | 3549 | |
|
| | 3550 | | // Serialize Request |
| 1 | 3551 | | string _requestContent = null; |
| 1 | 3552 | | if(luisAppV2 != null) |
| | 3553 | | { |
| 1 | 3554 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(luisAppV2, Client.SerializationSett |
| 1 | 3555 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 3556 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 3557 | | } |
| | 3558 | | // Set Credentials |
| 1 | 3559 | | if (Client.Credentials != null) |
| | 3560 | | { |
| 1 | 3561 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 3562 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3563 | | } |
| | 3564 | | // Send Request |
| 1 | 3565 | | if (_shouldTrace) |
| | 3566 | | { |
| 0 | 3567 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3568 | | } |
| 1 | 3569 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 3570 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 3571 | | if (_shouldTrace) |
| | 3572 | | { |
| 0 | 3573 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3574 | | } |
| 1 | 3575 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 3576 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 3577 | | string _responseContent = null; |
| 1 | 3578 | | if ((int)_statusCode != 201) |
| | 3579 | | { |
| 0 | 3580 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 3581 | | try |
| | 3582 | | { |
| 0 | 3583 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3584 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 3585 | | if (_errorBody != null) |
| | 3586 | | { |
| 0 | 3587 | | ex.Body = _errorBody; |
| | 3588 | | } |
| 0 | 3589 | | } |
| 0 | 3590 | | catch (JsonException) |
| | 3591 | | { |
| | 3592 | | // Ignore the exception |
| 0 | 3593 | | } |
| 0 | 3594 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3595 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3596 | | if (_shouldTrace) |
| | 3597 | | { |
| 0 | 3598 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3599 | | } |
| 0 | 3600 | | _httpRequest.Dispose(); |
| 0 | 3601 | | if (_httpResponse != null) |
| | 3602 | | { |
| 0 | 3603 | | _httpResponse.Dispose(); |
| | 3604 | | } |
| 0 | 3605 | | throw ex; |
| | 3606 | | } |
| | 3607 | | // Create Result |
| 1 | 3608 | | var _result = new HttpOperationResponse<System.Guid>(); |
| 1 | 3609 | | _result.Request = _httpRequest; |
| 1 | 3610 | | _result.Response = _httpResponse; |
| | 3611 | | // Deserialize Response |
| 1 | 3612 | | if ((int)_statusCode == 201) |
| | 3613 | | { |
| 1 | 3614 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3615 | | try |
| | 3616 | | { |
| 1 | 3617 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<System.Guid>(_responseContent, C |
| 1 | 3618 | | } |
| 0 | 3619 | | catch (JsonException ex) |
| | 3620 | | { |
| 0 | 3621 | | _httpRequest.Dispose(); |
| 0 | 3622 | | if (_httpResponse != null) |
| | 3623 | | { |
| 0 | 3624 | | _httpResponse.Dispose(); |
| | 3625 | | } |
| 0 | 3626 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3627 | | } |
| | 3628 | | } |
| 1 | 3629 | | if (_shouldTrace) |
| | 3630 | | { |
| 0 | 3631 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3632 | | } |
| 1 | 3633 | | return _result; |
| 1 | 3634 | | } |
| | 3635 | |
|
| | 3636 | | /// <summary> |
| | 3637 | | /// Imports an application to LUIS, the application's structure is included in |
| | 3638 | | /// the request body. |
| | 3639 | | /// </summary> |
| | 3640 | | /// <param name='luisAppLu'> |
| | 3641 | | /// A LUIS application structure. |
| | 3642 | | /// </param> |
| | 3643 | | /// <param name='appName'> |
| | 3644 | | /// The application name to create. If not specified, the application name will |
| | 3645 | | /// be read from the imported object. If the application name already exists, |
| | 3646 | | /// an error is returned. |
| | 3647 | | /// </param> |
| | 3648 | | /// <param name='customHeaders'> |
| | 3649 | | /// Headers that will be added to request. |
| | 3650 | | /// </param> |
| | 3651 | | /// <param name='cancellationToken'> |
| | 3652 | | /// The cancellation token. |
| | 3653 | | /// </param> |
| | 3654 | | /// <exception cref="ErrorResponseException"> |
| | 3655 | | /// Thrown when the operation returned an invalid status code |
| | 3656 | | /// </exception> |
| | 3657 | | /// <exception cref="SerializationException"> |
| | 3658 | | /// Thrown when unable to deserialize the response |
| | 3659 | | /// </exception> |
| | 3660 | | /// <exception cref="ValidationException"> |
| | 3661 | | /// Thrown when a required parameter is null |
| | 3662 | | /// </exception> |
| | 3663 | | /// <exception cref="System.ArgumentNullException"> |
| | 3664 | | /// Thrown when a required parameter is null |
| | 3665 | | /// </exception> |
| | 3666 | | /// <return> |
| | 3667 | | /// A response object containing the response body and response headers. |
| | 3668 | | /// </return> |
| | 3669 | | public async Task<HttpOperationResponse<System.Guid>> ImportLuFormatWithHttpMessagesAsync(string luisAppLu, stri |
| | 3670 | | { |
| 1 | 3671 | | if (Client.Endpoint == null) |
| | 3672 | | { |
| 0 | 3673 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 3674 | | } |
| 1 | 3675 | | if (luisAppLu == null) |
| | 3676 | | { |
| 0 | 3677 | | throw new ValidationException(ValidationRules.CannotBeNull, "luisAppLu"); |
| | 3678 | | } |
| | 3679 | | // Tracing |
| 1 | 3680 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 3681 | | string _invocationId = null; |
| 1 | 3682 | | if (_shouldTrace) |
| | 3683 | | { |
| 0 | 3684 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3685 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3686 | | tracingParameters.Add("appName", appName); |
| 0 | 3687 | | tracingParameters.Add("luisAppLu", luisAppLu); |
| 0 | 3688 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3689 | | ServiceClientTracing.Enter(_invocationId, this, "ImportLuFormat", tracingParameters); |
| | 3690 | | } |
| | 3691 | | // Construct URL |
| 1 | 3692 | | var _baseUrl = Client.BaseUri; |
| 1 | 3693 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/import"; |
| 1 | 3694 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 3695 | | List<string> _queryParameters = new List<string>(); |
| 1 | 3696 | | if (appName != null) |
| | 3697 | | { |
| 1 | 3698 | | _queryParameters.Add(string.Format("appName={0}", System.Uri.EscapeDataString(appName))); |
| | 3699 | | } |
| 1 | 3700 | | if (_queryParameters.Count > 0) |
| | 3701 | | { |
| 1 | 3702 | | _url += "?" + string.Join("&", _queryParameters); |
| | 3703 | | } |
| | 3704 | | // Create HTTP transport objects |
| 1 | 3705 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 3706 | | HttpResponseMessage _httpResponse = null; |
| 1 | 3707 | | _httpRequest.Method = new HttpMethod("POST"); |
| 1 | 3708 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3709 | | // Set Headers |
| | 3710 | |
|
| | 3711 | |
|
| 1 | 3712 | | if (customHeaders != null) |
| | 3713 | | { |
| 0 | 3714 | | foreach(var _header in customHeaders) |
| | 3715 | | { |
| 0 | 3716 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3717 | | { |
| 0 | 3718 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3719 | | } |
| 0 | 3720 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3721 | | } |
| | 3722 | | } |
| | 3723 | |
|
| | 3724 | | // Serialize Request |
| 1 | 3725 | | string _requestContent = null; |
| 1 | 3726 | | if(luisAppLu != null) |
| | 3727 | | { |
| 1 | 3728 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(luisAppLu, Client.SerializationSett |
| 1 | 3729 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 3730 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain |
| | 3731 | | } |
| | 3732 | | // Set Credentials |
| 1 | 3733 | | if (Client.Credentials != null) |
| | 3734 | | { |
| 1 | 3735 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 3736 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3737 | | } |
| | 3738 | | // Send Request |
| 1 | 3739 | | if (_shouldTrace) |
| | 3740 | | { |
| 0 | 3741 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3742 | | } |
| 1 | 3743 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 3744 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 3745 | | if (_shouldTrace) |
| | 3746 | | { |
| 0 | 3747 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3748 | | } |
| 1 | 3749 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 3750 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 3751 | | string _responseContent = null; |
| 1 | 3752 | | if ((int)_statusCode != 201) |
| | 3753 | | { |
| 0 | 3754 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 3755 | | try |
| | 3756 | | { |
| 0 | 3757 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3758 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 3759 | | if (_errorBody != null) |
| | 3760 | | { |
| 0 | 3761 | | ex.Body = _errorBody; |
| | 3762 | | } |
| 0 | 3763 | | } |
| 0 | 3764 | | catch (JsonException) |
| | 3765 | | { |
| | 3766 | | // Ignore the exception |
| 0 | 3767 | | } |
| 0 | 3768 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3769 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3770 | | if (_shouldTrace) |
| | 3771 | | { |
| 0 | 3772 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3773 | | } |
| 0 | 3774 | | _httpRequest.Dispose(); |
| 0 | 3775 | | if (_httpResponse != null) |
| | 3776 | | { |
| 0 | 3777 | | _httpResponse.Dispose(); |
| | 3778 | | } |
| 0 | 3779 | | throw ex; |
| | 3780 | | } |
| | 3781 | | // Create Result |
| 1 | 3782 | | var _result = new HttpOperationResponse<System.Guid>(); |
| 1 | 3783 | | _result.Request = _httpRequest; |
| 1 | 3784 | | _result.Response = _httpResponse; |
| | 3785 | | // Deserialize Response |
| 1 | 3786 | | if ((int)_statusCode == 201) |
| | 3787 | | { |
| 1 | 3788 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3789 | | try |
| | 3790 | | { |
| 1 | 3791 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<System.Guid>(_responseContent, C |
| 1 | 3792 | | } |
| 0 | 3793 | | catch (JsonException ex) |
| | 3794 | | { |
| 0 | 3795 | | _httpRequest.Dispose(); |
| 0 | 3796 | | if (_httpResponse != null) |
| | 3797 | | { |
| 0 | 3798 | | _httpResponse.Dispose(); |
| | 3799 | | } |
| 0 | 3800 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3801 | | } |
| | 3802 | | } |
| 1 | 3803 | | if (_shouldTrace) |
| | 3804 | | { |
| 0 | 3805 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3806 | | } |
| 1 | 3807 | | return _result; |
| 1 | 3808 | | } |
| | 3809 | |
|
| | 3810 | | } |
| | 3811 | | } |