| | 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 | | /// Pattern operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class Pattern : IServiceOperations<LUISAuthoringClient>, IPattern |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the Pattern 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 Pattern(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> |
| 360 | 51 | | public LUISAuthoringClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Adds a pattern to a version of the application. |
| | 55 | | /// </summary> |
| | 56 | | /// <param name='appId'> |
| | 57 | | /// The application ID. |
| | 58 | | /// </param> |
| | 59 | | /// <param name='versionId'> |
| | 60 | | /// The version ID. |
| | 61 | | /// </param> |
| | 62 | | /// <param name='pattern'> |
| | 63 | | /// The input pattern. |
| | 64 | | /// </param> |
| | 65 | | /// <param name='customHeaders'> |
| | 66 | | /// Headers that will be added to request. |
| | 67 | | /// </param> |
| | 68 | | /// <param name='cancellationToken'> |
| | 69 | | /// The cancellation token. |
| | 70 | | /// </param> |
| | 71 | | /// <exception cref="ErrorResponseException"> |
| | 72 | | /// Thrown when the operation returned an invalid status code |
| | 73 | | /// </exception> |
| | 74 | | /// <exception cref="SerializationException"> |
| | 75 | | /// Thrown when unable to deserialize the response |
| | 76 | | /// </exception> |
| | 77 | | /// <exception cref="ValidationException"> |
| | 78 | | /// Thrown when a required parameter is null |
| | 79 | | /// </exception> |
| | 80 | | /// <exception cref="System.ArgumentNullException"> |
| | 81 | | /// Thrown when a required parameter is null |
| | 82 | | /// </exception> |
| | 83 | | /// <return> |
| | 84 | | /// A response object containing the response body and response headers. |
| | 85 | | /// </return> |
| | 86 | | public async Task<HttpOperationResponse<PatternRuleInfo>> AddPatternWithHttpMessagesAsync(System.Guid appId, str |
| | 87 | | { |
| 3 | 88 | | if (Client.Endpoint == null) |
| | 89 | | { |
| 0 | 90 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 91 | | } |
| 3 | 92 | | if (versionId == null) |
| | 93 | | { |
| 0 | 94 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 95 | | } |
| 3 | 96 | | if (pattern == null) |
| | 97 | | { |
| 0 | 98 | | throw new ValidationException(ValidationRules.CannotBeNull, "pattern"); |
| | 99 | | } |
| | 100 | | // Tracing |
| 3 | 101 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 3 | 102 | | string _invocationId = null; |
| 3 | 103 | | if (_shouldTrace) |
| | 104 | | { |
| 0 | 105 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 106 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 107 | | tracingParameters.Add("appId", appId); |
| 0 | 108 | | tracingParameters.Add("versionId", versionId); |
| 0 | 109 | | tracingParameters.Add("pattern", pattern); |
| 0 | 110 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 111 | | ServiceClientTracing.Enter(_invocationId, this, "AddPattern", tracingParameters); |
| | 112 | | } |
| | 113 | | // Construct URL |
| 3 | 114 | | var _baseUrl = Client.BaseUri; |
| 3 | 115 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrule"; |
| 3 | 116 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 3 | 117 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 3 | 118 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 119 | | // Create HTTP transport objects |
| 3 | 120 | | var _httpRequest = new HttpRequestMessage(); |
| 3 | 121 | | HttpResponseMessage _httpResponse = null; |
| 3 | 122 | | _httpRequest.Method = new HttpMethod("POST"); |
| 3 | 123 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 124 | | // Set Headers |
| | 125 | |
|
| | 126 | |
|
| 3 | 127 | | if (customHeaders != null) |
| | 128 | | { |
| 0 | 129 | | foreach(var _header in customHeaders) |
| | 130 | | { |
| 0 | 131 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 132 | | { |
| 0 | 133 | | _httpRequest.Headers.Remove(_header.Key); |
| | 134 | | } |
| 0 | 135 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 136 | | } |
| | 137 | | } |
| | 138 | |
|
| | 139 | | // Serialize Request |
| 3 | 140 | | string _requestContent = null; |
| 3 | 141 | | if(pattern != null) |
| | 142 | | { |
| 3 | 143 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(pattern, Client.SerializationSettin |
| 3 | 144 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 3 | 145 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 146 | | } |
| | 147 | | // Set Credentials |
| 3 | 148 | | if (Client.Credentials != null) |
| | 149 | | { |
| 3 | 150 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 151 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 152 | | } |
| | 153 | | // Send Request |
| 3 | 154 | | if (_shouldTrace) |
| | 155 | | { |
| 0 | 156 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 157 | | } |
| 3 | 158 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 159 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 3 | 160 | | if (_shouldTrace) |
| | 161 | | { |
| 0 | 162 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 163 | | } |
| 3 | 164 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 3 | 165 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 166 | | string _responseContent = null; |
| 3 | 167 | | if ((int)_statusCode != 201) |
| | 168 | | { |
| 0 | 169 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 170 | | try |
| | 171 | | { |
| 0 | 172 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 173 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 174 | | if (_errorBody != null) |
| | 175 | | { |
| 0 | 176 | | ex.Body = _errorBody; |
| | 177 | | } |
| 0 | 178 | | } |
| 0 | 179 | | catch (JsonException) |
| | 180 | | { |
| | 181 | | // Ignore the exception |
| 0 | 182 | | } |
| 0 | 183 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 184 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 185 | | if (_shouldTrace) |
| | 186 | | { |
| 0 | 187 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 188 | | } |
| 0 | 189 | | _httpRequest.Dispose(); |
| 0 | 190 | | if (_httpResponse != null) |
| | 191 | | { |
| 0 | 192 | | _httpResponse.Dispose(); |
| | 193 | | } |
| 0 | 194 | | throw ex; |
| | 195 | | } |
| | 196 | | // Create Result |
| 3 | 197 | | var _result = new HttpOperationResponse<PatternRuleInfo>(); |
| 3 | 198 | | _result.Request = _httpRequest; |
| 3 | 199 | | _result.Response = _httpResponse; |
| | 200 | | // Deserialize Response |
| 3 | 201 | | if ((int)_statusCode == 201) |
| | 202 | | { |
| 3 | 203 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 204 | | try |
| | 205 | | { |
| 3 | 206 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PatternRuleInfo>(_responseConten |
| 3 | 207 | | } |
| 0 | 208 | | catch (JsonException ex) |
| | 209 | | { |
| 0 | 210 | | _httpRequest.Dispose(); |
| 0 | 211 | | if (_httpResponse != null) |
| | 212 | | { |
| 0 | 213 | | _httpResponse.Dispose(); |
| | 214 | | } |
| 0 | 215 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 216 | | } |
| | 217 | | } |
| 3 | 218 | | if (_shouldTrace) |
| | 219 | | { |
| 0 | 220 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 221 | | } |
| 3 | 222 | | return _result; |
| 3 | 223 | | } |
| | 224 | |
|
| | 225 | | /// <summary> |
| | 226 | | /// Gets patterns in a version of the application. |
| | 227 | | /// </summary> |
| | 228 | | /// <param name='appId'> |
| | 229 | | /// The application ID. |
| | 230 | | /// </param> |
| | 231 | | /// <param name='versionId'> |
| | 232 | | /// The version ID. |
| | 233 | | /// </param> |
| | 234 | | /// <param name='skip'> |
| | 235 | | /// The number of entries to skip. Default value is 0. |
| | 236 | | /// </param> |
| | 237 | | /// <param name='take'> |
| | 238 | | /// The number of entries to return. Maximum page size is 500. Default is 100. |
| | 239 | | /// </param> |
| | 240 | | /// <param name='customHeaders'> |
| | 241 | | /// Headers that will be added to request. |
| | 242 | | /// </param> |
| | 243 | | /// <param name='cancellationToken'> |
| | 244 | | /// The cancellation token. |
| | 245 | | /// </param> |
| | 246 | | /// <exception cref="ErrorResponseException"> |
| | 247 | | /// Thrown when the operation returned an invalid status code |
| | 248 | | /// </exception> |
| | 249 | | /// <exception cref="SerializationException"> |
| | 250 | | /// Thrown when unable to deserialize the response |
| | 251 | | /// </exception> |
| | 252 | | /// <exception cref="ValidationException"> |
| | 253 | | /// Thrown when a required parameter is null |
| | 254 | | /// </exception> |
| | 255 | | /// <exception cref="System.ArgumentNullException"> |
| | 256 | | /// Thrown when a required parameter is null |
| | 257 | | /// </exception> |
| | 258 | | /// <return> |
| | 259 | | /// A response object containing the response body and response headers. |
| | 260 | | /// </return> |
| | 261 | | public async Task<HttpOperationResponse<IList<PatternRuleInfo>>> ListPatternsWithHttpMessagesAsync(System.Guid a |
| | 262 | | { |
| 3 | 263 | | if (Client.Endpoint == null) |
| | 264 | | { |
| 0 | 265 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 266 | | } |
| 3 | 267 | | if (versionId == null) |
| | 268 | | { |
| 0 | 269 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 270 | | } |
| 3 | 271 | | if (skip < 0) |
| | 272 | | { |
| 0 | 273 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "skip", 0); |
| | 274 | | } |
| 3 | 275 | | if (take > 500) |
| | 276 | | { |
| 0 | 277 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 500); |
| | 278 | | } |
| 3 | 279 | | if (take < 0) |
| | 280 | | { |
| 0 | 281 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0); |
| | 282 | | } |
| | 283 | | // Tracing |
| 3 | 284 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 3 | 285 | | string _invocationId = null; |
| 3 | 286 | | if (_shouldTrace) |
| | 287 | | { |
| 0 | 288 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 289 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 290 | | tracingParameters.Add("appId", appId); |
| 0 | 291 | | tracingParameters.Add("versionId", versionId); |
| 0 | 292 | | tracingParameters.Add("skip", skip); |
| 0 | 293 | | tracingParameters.Add("take", take); |
| 0 | 294 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 295 | | ServiceClientTracing.Enter(_invocationId, this, "ListPatterns", tracingParameters); |
| | 296 | | } |
| | 297 | | // Construct URL |
| 3 | 298 | | var _baseUrl = Client.BaseUri; |
| 3 | 299 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules" |
| 3 | 300 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 3 | 301 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 3 | 302 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| 3 | 303 | | List<string> _queryParameters = new List<string>(); |
| 3 | 304 | | if (skip != null) |
| | 305 | | { |
| 3 | 306 | | _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 307 | | } |
| 3 | 308 | | if (take != null) |
| | 309 | | { |
| 3 | 310 | | _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 311 | | } |
| 3 | 312 | | if (_queryParameters.Count > 0) |
| | 313 | | { |
| 3 | 314 | | _url += "?" + string.Join("&", _queryParameters); |
| | 315 | | } |
| | 316 | | // Create HTTP transport objects |
| 3 | 317 | | var _httpRequest = new HttpRequestMessage(); |
| 3 | 318 | | HttpResponseMessage _httpResponse = null; |
| 3 | 319 | | _httpRequest.Method = new HttpMethod("GET"); |
| 3 | 320 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 321 | | // Set Headers |
| | 322 | |
|
| | 323 | |
|
| 3 | 324 | | if (customHeaders != null) |
| | 325 | | { |
| 0 | 326 | | foreach(var _header in customHeaders) |
| | 327 | | { |
| 0 | 328 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 329 | | { |
| 0 | 330 | | _httpRequest.Headers.Remove(_header.Key); |
| | 331 | | } |
| 0 | 332 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 333 | | } |
| | 334 | | } |
| | 335 | |
|
| | 336 | | // Serialize Request |
| 3 | 337 | | string _requestContent = null; |
| | 338 | | // Set Credentials |
| 3 | 339 | | if (Client.Credentials != null) |
| | 340 | | { |
| 3 | 341 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 342 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 343 | | } |
| | 344 | | // Send Request |
| 3 | 345 | | if (_shouldTrace) |
| | 346 | | { |
| 0 | 347 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 348 | | } |
| 3 | 349 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 350 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 3 | 351 | | if (_shouldTrace) |
| | 352 | | { |
| 0 | 353 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 354 | | } |
| 3 | 355 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 3 | 356 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 357 | | string _responseContent = null; |
| 3 | 358 | | if ((int)_statusCode != 200) |
| | 359 | | { |
| 0 | 360 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 361 | | try |
| | 362 | | { |
| 0 | 363 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 364 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 365 | | if (_errorBody != null) |
| | 366 | | { |
| 0 | 367 | | ex.Body = _errorBody; |
| | 368 | | } |
| 0 | 369 | | } |
| 0 | 370 | | catch (JsonException) |
| | 371 | | { |
| | 372 | | // Ignore the exception |
| 0 | 373 | | } |
| 0 | 374 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 375 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 376 | | if (_shouldTrace) |
| | 377 | | { |
| 0 | 378 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 379 | | } |
| 0 | 380 | | _httpRequest.Dispose(); |
| 0 | 381 | | if (_httpResponse != null) |
| | 382 | | { |
| 0 | 383 | | _httpResponse.Dispose(); |
| | 384 | | } |
| 0 | 385 | | throw ex; |
| | 386 | | } |
| | 387 | | // Create Result |
| 3 | 388 | | var _result = new HttpOperationResponse<IList<PatternRuleInfo>>(); |
| 3 | 389 | | _result.Request = _httpRequest; |
| 3 | 390 | | _result.Response = _httpResponse; |
| | 391 | | // Deserialize Response |
| 3 | 392 | | if ((int)_statusCode == 200) |
| | 393 | | { |
| 3 | 394 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 395 | | try |
| | 396 | | { |
| 3 | 397 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PatternRuleInfo>>(_respons |
| 3 | 398 | | } |
| 0 | 399 | | catch (JsonException ex) |
| | 400 | | { |
| 0 | 401 | | _httpRequest.Dispose(); |
| 0 | 402 | | if (_httpResponse != null) |
| | 403 | | { |
| 0 | 404 | | _httpResponse.Dispose(); |
| | 405 | | } |
| 0 | 406 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 407 | | } |
| | 408 | | } |
| 3 | 409 | | if (_shouldTrace) |
| | 410 | | { |
| 0 | 411 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 412 | | } |
| 3 | 413 | | return _result; |
| 3 | 414 | | } |
| | 415 | |
|
| | 416 | | /// <summary> |
| | 417 | | /// Updates patterns in a version of the application. |
| | 418 | | /// </summary> |
| | 419 | | /// <param name='appId'> |
| | 420 | | /// The application ID. |
| | 421 | | /// </param> |
| | 422 | | /// <param name='versionId'> |
| | 423 | | /// The version ID. |
| | 424 | | /// </param> |
| | 425 | | /// <param name='patterns'> |
| | 426 | | /// An array represents the patterns. |
| | 427 | | /// </param> |
| | 428 | | /// <param name='customHeaders'> |
| | 429 | | /// Headers that will be added to request. |
| | 430 | | /// </param> |
| | 431 | | /// <param name='cancellationToken'> |
| | 432 | | /// The cancellation token. |
| | 433 | | /// </param> |
| | 434 | | /// <exception cref="ErrorResponseException"> |
| | 435 | | /// Thrown when the operation returned an invalid status code |
| | 436 | | /// </exception> |
| | 437 | | /// <exception cref="SerializationException"> |
| | 438 | | /// Thrown when unable to deserialize the response |
| | 439 | | /// </exception> |
| | 440 | | /// <exception cref="ValidationException"> |
| | 441 | | /// Thrown when a required parameter is null |
| | 442 | | /// </exception> |
| | 443 | | /// <exception cref="System.ArgumentNullException"> |
| | 444 | | /// Thrown when a required parameter is null |
| | 445 | | /// </exception> |
| | 446 | | /// <return> |
| | 447 | | /// A response object containing the response body and response headers. |
| | 448 | | /// </return> |
| | 449 | | public async Task<HttpOperationResponse<IList<PatternRuleInfo>>> UpdatePatternsWithHttpMessagesAsync(System.Guid |
| | 450 | | { |
| 1 | 451 | | if (Client.Endpoint == null) |
| | 452 | | { |
| 0 | 453 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 454 | | } |
| 1 | 455 | | if (versionId == null) |
| | 456 | | { |
| 0 | 457 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 458 | | } |
| 1 | 459 | | if (patterns == null) |
| | 460 | | { |
| 0 | 461 | | throw new ValidationException(ValidationRules.CannotBeNull, "patterns"); |
| | 462 | | } |
| | 463 | | // Tracing |
| 1 | 464 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 465 | | string _invocationId = null; |
| 1 | 466 | | if (_shouldTrace) |
| | 467 | | { |
| 0 | 468 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 469 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 470 | | tracingParameters.Add("appId", appId); |
| 0 | 471 | | tracingParameters.Add("versionId", versionId); |
| 0 | 472 | | tracingParameters.Add("patterns", patterns); |
| 0 | 473 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 474 | | ServiceClientTracing.Enter(_invocationId, this, "UpdatePatterns", tracingParameters); |
| | 475 | | } |
| | 476 | | // Construct URL |
| 1 | 477 | | var _baseUrl = Client.BaseUri; |
| 1 | 478 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules" |
| 1 | 479 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 480 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 1 | 481 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 482 | | // Create HTTP transport objects |
| 1 | 483 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 484 | | HttpResponseMessage _httpResponse = null; |
| 1 | 485 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 1 | 486 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 487 | | // Set Headers |
| | 488 | |
|
| | 489 | |
|
| 1 | 490 | | if (customHeaders != null) |
| | 491 | | { |
| 0 | 492 | | foreach(var _header in customHeaders) |
| | 493 | | { |
| 0 | 494 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 495 | | { |
| 0 | 496 | | _httpRequest.Headers.Remove(_header.Key); |
| | 497 | | } |
| 0 | 498 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 499 | | } |
| | 500 | | } |
| | 501 | |
|
| | 502 | | // Serialize Request |
| 1 | 503 | | string _requestContent = null; |
| 1 | 504 | | if(patterns != null) |
| | 505 | | { |
| 1 | 506 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(patterns, Client.SerializationSetti |
| 1 | 507 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 508 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 509 | | } |
| | 510 | | // Set Credentials |
| 1 | 511 | | if (Client.Credentials != null) |
| | 512 | | { |
| 1 | 513 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 514 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 515 | | } |
| | 516 | | // Send Request |
| 1 | 517 | | if (_shouldTrace) |
| | 518 | | { |
| 0 | 519 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 520 | | } |
| 1 | 521 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 522 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 523 | | if (_shouldTrace) |
| | 524 | | { |
| 0 | 525 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 526 | | } |
| 1 | 527 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 528 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 529 | | string _responseContent = null; |
| 1 | 530 | | if ((int)_statusCode != 200) |
| | 531 | | { |
| 0 | 532 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 533 | | try |
| | 534 | | { |
| 0 | 535 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 536 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 537 | | if (_errorBody != null) |
| | 538 | | { |
| 0 | 539 | | ex.Body = _errorBody; |
| | 540 | | } |
| 0 | 541 | | } |
| 0 | 542 | | catch (JsonException) |
| | 543 | | { |
| | 544 | | // Ignore the exception |
| 0 | 545 | | } |
| 0 | 546 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 547 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 548 | | if (_shouldTrace) |
| | 549 | | { |
| 0 | 550 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 551 | | } |
| 0 | 552 | | _httpRequest.Dispose(); |
| 0 | 553 | | if (_httpResponse != null) |
| | 554 | | { |
| 0 | 555 | | _httpResponse.Dispose(); |
| | 556 | | } |
| 0 | 557 | | throw ex; |
| | 558 | | } |
| | 559 | | // Create Result |
| 1 | 560 | | var _result = new HttpOperationResponse<IList<PatternRuleInfo>>(); |
| 1 | 561 | | _result.Request = _httpRequest; |
| 1 | 562 | | _result.Response = _httpResponse; |
| | 563 | | // Deserialize Response |
| 1 | 564 | | if ((int)_statusCode == 200) |
| | 565 | | { |
| 1 | 566 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 567 | | try |
| | 568 | | { |
| 1 | 569 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PatternRuleInfo>>(_respons |
| 1 | 570 | | } |
| 0 | 571 | | catch (JsonException ex) |
| | 572 | | { |
| 0 | 573 | | _httpRequest.Dispose(); |
| 0 | 574 | | if (_httpResponse != null) |
| | 575 | | { |
| 0 | 576 | | _httpResponse.Dispose(); |
| | 577 | | } |
| 0 | 578 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 579 | | } |
| | 580 | | } |
| 1 | 581 | | if (_shouldTrace) |
| | 582 | | { |
| 0 | 583 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 584 | | } |
| 1 | 585 | | return _result; |
| 1 | 586 | | } |
| | 587 | |
|
| | 588 | | /// <summary> |
| | 589 | | /// Adds a batch of patterns in a version of the application. |
| | 590 | | /// </summary> |
| | 591 | | /// <param name='appId'> |
| | 592 | | /// The application ID. |
| | 593 | | /// </param> |
| | 594 | | /// <param name='versionId'> |
| | 595 | | /// The version ID. |
| | 596 | | /// </param> |
| | 597 | | /// <param name='patterns'> |
| | 598 | | /// A JSON array containing patterns. |
| | 599 | | /// </param> |
| | 600 | | /// <param name='customHeaders'> |
| | 601 | | /// Headers that will be added to request. |
| | 602 | | /// </param> |
| | 603 | | /// <param name='cancellationToken'> |
| | 604 | | /// The cancellation token. |
| | 605 | | /// </param> |
| | 606 | | /// <exception cref="ErrorResponseException"> |
| | 607 | | /// Thrown when the operation returned an invalid status code |
| | 608 | | /// </exception> |
| | 609 | | /// <exception cref="SerializationException"> |
| | 610 | | /// Thrown when unable to deserialize the response |
| | 611 | | /// </exception> |
| | 612 | | /// <exception cref="ValidationException"> |
| | 613 | | /// Thrown when a required parameter is null |
| | 614 | | /// </exception> |
| | 615 | | /// <exception cref="System.ArgumentNullException"> |
| | 616 | | /// Thrown when a required parameter is null |
| | 617 | | /// </exception> |
| | 618 | | /// <return> |
| | 619 | | /// A response object containing the response body and response headers. |
| | 620 | | /// </return> |
| | 621 | | public async Task<HttpOperationResponse<IList<PatternRuleInfo>>> BatchAddPatternsWithHttpMessagesAsync(System.Gu |
| | 622 | | { |
| 5 | 623 | | if (Client.Endpoint == null) |
| | 624 | | { |
| 0 | 625 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 626 | | } |
| 5 | 627 | | if (versionId == null) |
| | 628 | | { |
| 0 | 629 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 630 | | } |
| 5 | 631 | | if (patterns == null) |
| | 632 | | { |
| 0 | 633 | | throw new ValidationException(ValidationRules.CannotBeNull, "patterns"); |
| | 634 | | } |
| | 635 | | // Tracing |
| 5 | 636 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 5 | 637 | | string _invocationId = null; |
| 5 | 638 | | if (_shouldTrace) |
| | 639 | | { |
| 0 | 640 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 641 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 642 | | tracingParameters.Add("appId", appId); |
| 0 | 643 | | tracingParameters.Add("versionId", versionId); |
| 0 | 644 | | tracingParameters.Add("patterns", patterns); |
| 0 | 645 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 646 | | ServiceClientTracing.Enter(_invocationId, this, "BatchAddPatterns", tracingParameters); |
| | 647 | | } |
| | 648 | | // Construct URL |
| 5 | 649 | | var _baseUrl = Client.BaseUri; |
| 5 | 650 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules" |
| 5 | 651 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 5 | 652 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 5 | 653 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 654 | | // Create HTTP transport objects |
| 5 | 655 | | var _httpRequest = new HttpRequestMessage(); |
| 5 | 656 | | HttpResponseMessage _httpResponse = null; |
| 5 | 657 | | _httpRequest.Method = new HttpMethod("POST"); |
| 5 | 658 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 659 | | // Set Headers |
| | 660 | |
|
| | 661 | |
|
| 5 | 662 | | if (customHeaders != null) |
| | 663 | | { |
| 0 | 664 | | foreach(var _header in customHeaders) |
| | 665 | | { |
| 0 | 666 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 667 | | { |
| 0 | 668 | | _httpRequest.Headers.Remove(_header.Key); |
| | 669 | | } |
| 0 | 670 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 671 | | } |
| | 672 | | } |
| | 673 | |
|
| | 674 | | // Serialize Request |
| 5 | 675 | | string _requestContent = null; |
| 5 | 676 | | if(patterns != null) |
| | 677 | | { |
| 5 | 678 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(patterns, Client.SerializationSetti |
| 5 | 679 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 5 | 680 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 681 | | } |
| | 682 | | // Set Credentials |
| 5 | 683 | | if (Client.Credentials != null) |
| | 684 | | { |
| 5 | 685 | | cancellationToken.ThrowIfCancellationRequested(); |
| 5 | 686 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 687 | | } |
| | 688 | | // Send Request |
| 5 | 689 | | if (_shouldTrace) |
| | 690 | | { |
| 0 | 691 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 692 | | } |
| 5 | 693 | | cancellationToken.ThrowIfCancellationRequested(); |
| 5 | 694 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 5 | 695 | | if (_shouldTrace) |
| | 696 | | { |
| 0 | 697 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 698 | | } |
| 5 | 699 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 5 | 700 | | cancellationToken.ThrowIfCancellationRequested(); |
| 5 | 701 | | string _responseContent = null; |
| 5 | 702 | | if ((int)_statusCode != 201) |
| | 703 | | { |
| 0 | 704 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 705 | | try |
| | 706 | | { |
| 0 | 707 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 708 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 709 | | if (_errorBody != null) |
| | 710 | | { |
| 0 | 711 | | ex.Body = _errorBody; |
| | 712 | | } |
| 0 | 713 | | } |
| 0 | 714 | | catch (JsonException) |
| | 715 | | { |
| | 716 | | // Ignore the exception |
| 0 | 717 | | } |
| 0 | 718 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 719 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 720 | | if (_shouldTrace) |
| | 721 | | { |
| 0 | 722 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 723 | | } |
| 0 | 724 | | _httpRequest.Dispose(); |
| 0 | 725 | | if (_httpResponse != null) |
| | 726 | | { |
| 0 | 727 | | _httpResponse.Dispose(); |
| | 728 | | } |
| 0 | 729 | | throw ex; |
| | 730 | | } |
| | 731 | | // Create Result |
| 5 | 732 | | var _result = new HttpOperationResponse<IList<PatternRuleInfo>>(); |
| 5 | 733 | | _result.Request = _httpRequest; |
| 5 | 734 | | _result.Response = _httpResponse; |
| | 735 | | // Deserialize Response |
| 5 | 736 | | if ((int)_statusCode == 201) |
| | 737 | | { |
| 5 | 738 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 739 | | try |
| | 740 | | { |
| 5 | 741 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PatternRuleInfo>>(_respons |
| 5 | 742 | | } |
| 0 | 743 | | catch (JsonException ex) |
| | 744 | | { |
| 0 | 745 | | _httpRequest.Dispose(); |
| 0 | 746 | | if (_httpResponse != null) |
| | 747 | | { |
| 0 | 748 | | _httpResponse.Dispose(); |
| | 749 | | } |
| 0 | 750 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 751 | | } |
| | 752 | | } |
| 5 | 753 | | if (_shouldTrace) |
| | 754 | | { |
| 0 | 755 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 756 | | } |
| 5 | 757 | | return _result; |
| 5 | 758 | | } |
| | 759 | |
|
| | 760 | | /// <summary> |
| | 761 | | /// Deletes a list of patterns in a version of the application. |
| | 762 | | /// </summary> |
| | 763 | | /// <param name='appId'> |
| | 764 | | /// The application ID. |
| | 765 | | /// </param> |
| | 766 | | /// <param name='versionId'> |
| | 767 | | /// The version ID. |
| | 768 | | /// </param> |
| | 769 | | /// <param name='patternIds'> |
| | 770 | | /// The patterns IDs. |
| | 771 | | /// </param> |
| | 772 | | /// <param name='customHeaders'> |
| | 773 | | /// Headers that will be added to request. |
| | 774 | | /// </param> |
| | 775 | | /// <param name='cancellationToken'> |
| | 776 | | /// The cancellation token. |
| | 777 | | /// </param> |
| | 778 | | /// <exception cref="ErrorResponseException"> |
| | 779 | | /// Thrown when the operation returned an invalid status code |
| | 780 | | /// </exception> |
| | 781 | | /// <exception cref="SerializationException"> |
| | 782 | | /// Thrown when unable to deserialize the response |
| | 783 | | /// </exception> |
| | 784 | | /// <exception cref="ValidationException"> |
| | 785 | | /// Thrown when a required parameter is null |
| | 786 | | /// </exception> |
| | 787 | | /// <exception cref="System.ArgumentNullException"> |
| | 788 | | /// Thrown when a required parameter is null |
| | 789 | | /// </exception> |
| | 790 | | /// <return> |
| | 791 | | /// A response object containing the response body and response headers. |
| | 792 | | /// </return> |
| | 793 | | public async Task<HttpOperationResponse<OperationStatus>> DeletePatternsWithHttpMessagesAsync(System.Guid appId, |
| | 794 | | { |
| 5 | 795 | | if (Client.Endpoint == null) |
| | 796 | | { |
| 0 | 797 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 798 | | } |
| 5 | 799 | | if (versionId == null) |
| | 800 | | { |
| 0 | 801 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 802 | | } |
| 5 | 803 | | if (patternIds == null) |
| | 804 | | { |
| 0 | 805 | | throw new ValidationException(ValidationRules.CannotBeNull, "patternIds"); |
| | 806 | | } |
| | 807 | | // Tracing |
| 5 | 808 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 5 | 809 | | string _invocationId = null; |
| 5 | 810 | | if (_shouldTrace) |
| | 811 | | { |
| 0 | 812 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 813 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 814 | | tracingParameters.Add("appId", appId); |
| 0 | 815 | | tracingParameters.Add("versionId", versionId); |
| 0 | 816 | | tracingParameters.Add("patternIds", patternIds); |
| 0 | 817 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 818 | | ServiceClientTracing.Enter(_invocationId, this, "DeletePatterns", tracingParameters); |
| | 819 | | } |
| | 820 | | // Construct URL |
| 5 | 821 | | var _baseUrl = Client.BaseUri; |
| 5 | 822 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules" |
| 5 | 823 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 5 | 824 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 5 | 825 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 826 | | // Create HTTP transport objects |
| 5 | 827 | | var _httpRequest = new HttpRequestMessage(); |
| 5 | 828 | | HttpResponseMessage _httpResponse = null; |
| 5 | 829 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 5 | 830 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 831 | | // Set Headers |
| | 832 | |
|
| | 833 | |
|
| 5 | 834 | | if (customHeaders != null) |
| | 835 | | { |
| 0 | 836 | | foreach(var _header in customHeaders) |
| | 837 | | { |
| 0 | 838 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 839 | | { |
| 0 | 840 | | _httpRequest.Headers.Remove(_header.Key); |
| | 841 | | } |
| 0 | 842 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 843 | | } |
| | 844 | | } |
| | 845 | |
|
| | 846 | | // Serialize Request |
| 5 | 847 | | string _requestContent = null; |
| 5 | 848 | | if(patternIds != null) |
| | 849 | | { |
| 5 | 850 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(patternIds, Client.SerializationSet |
| 5 | 851 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 5 | 852 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 853 | | } |
| | 854 | | // Set Credentials |
| 5 | 855 | | if (Client.Credentials != null) |
| | 856 | | { |
| 5 | 857 | | cancellationToken.ThrowIfCancellationRequested(); |
| 5 | 858 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 859 | | } |
| | 860 | | // Send Request |
| 5 | 861 | | if (_shouldTrace) |
| | 862 | | { |
| 0 | 863 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 864 | | } |
| 5 | 865 | | cancellationToken.ThrowIfCancellationRequested(); |
| 5 | 866 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 5 | 867 | | if (_shouldTrace) |
| | 868 | | { |
| 0 | 869 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 870 | | } |
| 5 | 871 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 5 | 872 | | cancellationToken.ThrowIfCancellationRequested(); |
| 5 | 873 | | string _responseContent = null; |
| 5 | 874 | | if ((int)_statusCode != 200) |
| | 875 | | { |
| 0 | 876 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 877 | | try |
| | 878 | | { |
| 0 | 879 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 880 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 881 | | if (_errorBody != null) |
| | 882 | | { |
| 0 | 883 | | ex.Body = _errorBody; |
| | 884 | | } |
| 0 | 885 | | } |
| 0 | 886 | | catch (JsonException) |
| | 887 | | { |
| | 888 | | // Ignore the exception |
| 0 | 889 | | } |
| 0 | 890 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 891 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 892 | | if (_shouldTrace) |
| | 893 | | { |
| 0 | 894 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 895 | | } |
| 0 | 896 | | _httpRequest.Dispose(); |
| 0 | 897 | | if (_httpResponse != null) |
| | 898 | | { |
| 0 | 899 | | _httpResponse.Dispose(); |
| | 900 | | } |
| 0 | 901 | | throw ex; |
| | 902 | | } |
| | 903 | | // Create Result |
| 5 | 904 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 5 | 905 | | _result.Request = _httpRequest; |
| 5 | 906 | | _result.Response = _httpResponse; |
| | 907 | | // Deserialize Response |
| 5 | 908 | | if ((int)_statusCode == 200) |
| | 909 | | { |
| 5 | 910 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 911 | | try |
| | 912 | | { |
| 5 | 913 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 5 | 914 | | } |
| 0 | 915 | | catch (JsonException ex) |
| | 916 | | { |
| 0 | 917 | | _httpRequest.Dispose(); |
| 0 | 918 | | if (_httpResponse != null) |
| | 919 | | { |
| 0 | 920 | | _httpResponse.Dispose(); |
| | 921 | | } |
| 0 | 922 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 923 | | } |
| | 924 | | } |
| 5 | 925 | | if (_shouldTrace) |
| | 926 | | { |
| 0 | 927 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 928 | | } |
| 5 | 929 | | return _result; |
| 5 | 930 | | } |
| | 931 | |
|
| | 932 | | /// <summary> |
| | 933 | | /// Updates a pattern in a version of the application. |
| | 934 | | /// </summary> |
| | 935 | | /// <param name='appId'> |
| | 936 | | /// The application ID. |
| | 937 | | /// </param> |
| | 938 | | /// <param name='versionId'> |
| | 939 | | /// The version ID. |
| | 940 | | /// </param> |
| | 941 | | /// <param name='patternId'> |
| | 942 | | /// The pattern ID. |
| | 943 | | /// </param> |
| | 944 | | /// <param name='pattern'> |
| | 945 | | /// An object representing a pattern. |
| | 946 | | /// </param> |
| | 947 | | /// <param name='customHeaders'> |
| | 948 | | /// Headers that will be added to request. |
| | 949 | | /// </param> |
| | 950 | | /// <param name='cancellationToken'> |
| | 951 | | /// The cancellation token. |
| | 952 | | /// </param> |
| | 953 | | /// <exception cref="ErrorResponseException"> |
| | 954 | | /// Thrown when the operation returned an invalid status code |
| | 955 | | /// </exception> |
| | 956 | | /// <exception cref="SerializationException"> |
| | 957 | | /// Thrown when unable to deserialize the response |
| | 958 | | /// </exception> |
| | 959 | | /// <exception cref="ValidationException"> |
| | 960 | | /// Thrown when a required parameter is null |
| | 961 | | /// </exception> |
| | 962 | | /// <exception cref="System.ArgumentNullException"> |
| | 963 | | /// Thrown when a required parameter is null |
| | 964 | | /// </exception> |
| | 965 | | /// <return> |
| | 966 | | /// A response object containing the response body and response headers. |
| | 967 | | /// </return> |
| | 968 | | public async Task<HttpOperationResponse<PatternRuleInfo>> UpdatePatternWithHttpMessagesAsync(System.Guid appId, |
| | 969 | | { |
| 1 | 970 | | if (Client.Endpoint == null) |
| | 971 | | { |
| 0 | 972 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 973 | | } |
| 1 | 974 | | if (versionId == null) |
| | 975 | | { |
| 0 | 976 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 977 | | } |
| 1 | 978 | | if (pattern == null) |
| | 979 | | { |
| 0 | 980 | | throw new ValidationException(ValidationRules.CannotBeNull, "pattern"); |
| | 981 | | } |
| | 982 | | // Tracing |
| 1 | 983 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 984 | | string _invocationId = null; |
| 1 | 985 | | if (_shouldTrace) |
| | 986 | | { |
| 0 | 987 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 988 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 989 | | tracingParameters.Add("appId", appId); |
| 0 | 990 | | tracingParameters.Add("versionId", versionId); |
| 0 | 991 | | tracingParameters.Add("patternId", patternId); |
| 0 | 992 | | tracingParameters.Add("pattern", pattern); |
| 0 | 993 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 994 | | ServiceClientTracing.Enter(_invocationId, this, "UpdatePattern", tracingParameters); |
| | 995 | | } |
| | 996 | | // Construct URL |
| 1 | 997 | | var _baseUrl = Client.BaseUri; |
| 1 | 998 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules/ |
| 1 | 999 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 1000 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 1 | 1001 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| 1 | 1002 | | _url = _url.Replace("{patternId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO |
| | 1003 | | // Create HTTP transport objects |
| 1 | 1004 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 1005 | | HttpResponseMessage _httpResponse = null; |
| 1 | 1006 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 1 | 1007 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1008 | | // Set Headers |
| | 1009 | |
|
| | 1010 | |
|
| 1 | 1011 | | if (customHeaders != null) |
| | 1012 | | { |
| 0 | 1013 | | foreach(var _header in customHeaders) |
| | 1014 | | { |
| 0 | 1015 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1016 | | { |
| 0 | 1017 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1018 | | } |
| 0 | 1019 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1020 | | } |
| | 1021 | | } |
| | 1022 | |
|
| | 1023 | | // Serialize Request |
| 1 | 1024 | | string _requestContent = null; |
| 1 | 1025 | | if(pattern != null) |
| | 1026 | | { |
| 1 | 1027 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(pattern, Client.SerializationSettin |
| 1 | 1028 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 1 | 1029 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1030 | | } |
| | 1031 | | // Set Credentials |
| 1 | 1032 | | if (Client.Credentials != null) |
| | 1033 | | { |
| 1 | 1034 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1035 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1036 | | } |
| | 1037 | | // Send Request |
| 1 | 1038 | | if (_shouldTrace) |
| | 1039 | | { |
| 0 | 1040 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1041 | | } |
| 1 | 1042 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1043 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 1044 | | if (_shouldTrace) |
| | 1045 | | { |
| 0 | 1046 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1047 | | } |
| 1 | 1048 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 1049 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1050 | | string _responseContent = null; |
| 1 | 1051 | | if ((int)_statusCode != 200) |
| | 1052 | | { |
| 0 | 1053 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1054 | | try |
| | 1055 | | { |
| 0 | 1056 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1057 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1058 | | if (_errorBody != null) |
| | 1059 | | { |
| 0 | 1060 | | ex.Body = _errorBody; |
| | 1061 | | } |
| 0 | 1062 | | } |
| 0 | 1063 | | catch (JsonException) |
| | 1064 | | { |
| | 1065 | | // Ignore the exception |
| 0 | 1066 | | } |
| 0 | 1067 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1068 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1069 | | if (_shouldTrace) |
| | 1070 | | { |
| 0 | 1071 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1072 | | } |
| 0 | 1073 | | _httpRequest.Dispose(); |
| 0 | 1074 | | if (_httpResponse != null) |
| | 1075 | | { |
| 0 | 1076 | | _httpResponse.Dispose(); |
| | 1077 | | } |
| 0 | 1078 | | throw ex; |
| | 1079 | | } |
| | 1080 | | // Create Result |
| 1 | 1081 | | var _result = new HttpOperationResponse<PatternRuleInfo>(); |
| 1 | 1082 | | _result.Request = _httpRequest; |
| 1 | 1083 | | _result.Response = _httpResponse; |
| | 1084 | | // Deserialize Response |
| 1 | 1085 | | if ((int)_statusCode == 200) |
| | 1086 | | { |
| 1 | 1087 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1088 | | try |
| | 1089 | | { |
| 1 | 1090 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PatternRuleInfo>(_responseConten |
| 1 | 1091 | | } |
| 0 | 1092 | | catch (JsonException ex) |
| | 1093 | | { |
| 0 | 1094 | | _httpRequest.Dispose(); |
| 0 | 1095 | | if (_httpResponse != null) |
| | 1096 | | { |
| 0 | 1097 | | _httpResponse.Dispose(); |
| | 1098 | | } |
| 0 | 1099 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1100 | | } |
| | 1101 | | } |
| 1 | 1102 | | if (_shouldTrace) |
| | 1103 | | { |
| 0 | 1104 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1105 | | } |
| 1 | 1106 | | return _result; |
| 1 | 1107 | | } |
| | 1108 | |
|
| | 1109 | | /// <summary> |
| | 1110 | | /// Deletes the pattern with the specified ID from a version of the |
| | 1111 | | /// application.. |
| | 1112 | | /// </summary> |
| | 1113 | | /// <param name='appId'> |
| | 1114 | | /// The application ID. |
| | 1115 | | /// </param> |
| | 1116 | | /// <param name='versionId'> |
| | 1117 | | /// The version ID. |
| | 1118 | | /// </param> |
| | 1119 | | /// <param name='patternId'> |
| | 1120 | | /// The pattern ID. |
| | 1121 | | /// </param> |
| | 1122 | | /// <param name='customHeaders'> |
| | 1123 | | /// Headers that will be added to request. |
| | 1124 | | /// </param> |
| | 1125 | | /// <param name='cancellationToken'> |
| | 1126 | | /// The cancellation token. |
| | 1127 | | /// </param> |
| | 1128 | | /// <exception cref="ErrorResponseException"> |
| | 1129 | | /// Thrown when the operation returned an invalid status code |
| | 1130 | | /// </exception> |
| | 1131 | | /// <exception cref="SerializationException"> |
| | 1132 | | /// Thrown when unable to deserialize the response |
| | 1133 | | /// </exception> |
| | 1134 | | /// <exception cref="ValidationException"> |
| | 1135 | | /// Thrown when a required parameter is null |
| | 1136 | | /// </exception> |
| | 1137 | | /// <exception cref="System.ArgumentNullException"> |
| | 1138 | | /// Thrown when a required parameter is null |
| | 1139 | | /// </exception> |
| | 1140 | | /// <return> |
| | 1141 | | /// A response object containing the response body and response headers. |
| | 1142 | | /// </return> |
| | 1143 | | public async Task<HttpOperationResponse<OperationStatus>> DeletePatternWithHttpMessagesAsync(System.Guid appId, |
| | 1144 | | { |
| 3 | 1145 | | if (Client.Endpoint == null) |
| | 1146 | | { |
| 0 | 1147 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1148 | | } |
| 3 | 1149 | | if (versionId == null) |
| | 1150 | | { |
| 0 | 1151 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 1152 | | } |
| | 1153 | | // Tracing |
| 3 | 1154 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 3 | 1155 | | string _invocationId = null; |
| 3 | 1156 | | if (_shouldTrace) |
| | 1157 | | { |
| 0 | 1158 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1159 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1160 | | tracingParameters.Add("appId", appId); |
| 0 | 1161 | | tracingParameters.Add("versionId", versionId); |
| 0 | 1162 | | tracingParameters.Add("patternId", patternId); |
| 0 | 1163 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1164 | | ServiceClientTracing.Enter(_invocationId, this, "DeletePattern", tracingParameters); |
| | 1165 | | } |
| | 1166 | | // Construct URL |
| 3 | 1167 | | var _baseUrl = Client.BaseUri; |
| 3 | 1168 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules/ |
| 3 | 1169 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 3 | 1170 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 3 | 1171 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| 3 | 1172 | | _url = _url.Replace("{patternId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO |
| | 1173 | | // Create HTTP transport objects |
| 3 | 1174 | | var _httpRequest = new HttpRequestMessage(); |
| 3 | 1175 | | HttpResponseMessage _httpResponse = null; |
| 3 | 1176 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 3 | 1177 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1178 | | // Set Headers |
| | 1179 | |
|
| | 1180 | |
|
| 3 | 1181 | | if (customHeaders != null) |
| | 1182 | | { |
| 0 | 1183 | | foreach(var _header in customHeaders) |
| | 1184 | | { |
| 0 | 1185 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1186 | | { |
| 0 | 1187 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1188 | | } |
| 0 | 1189 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1190 | | } |
| | 1191 | | } |
| | 1192 | |
|
| | 1193 | | // Serialize Request |
| 3 | 1194 | | string _requestContent = null; |
| | 1195 | | // Set Credentials |
| 3 | 1196 | | if (Client.Credentials != null) |
| | 1197 | | { |
| 3 | 1198 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 1199 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1200 | | } |
| | 1201 | | // Send Request |
| 3 | 1202 | | if (_shouldTrace) |
| | 1203 | | { |
| 0 | 1204 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1205 | | } |
| 3 | 1206 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 1207 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 3 | 1208 | | if (_shouldTrace) |
| | 1209 | | { |
| 0 | 1210 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1211 | | } |
| 3 | 1212 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 3 | 1213 | | cancellationToken.ThrowIfCancellationRequested(); |
| 3 | 1214 | | string _responseContent = null; |
| 3 | 1215 | | if ((int)_statusCode != 200) |
| | 1216 | | { |
| 0 | 1217 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1218 | | try |
| | 1219 | | { |
| 0 | 1220 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1221 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1222 | | if (_errorBody != null) |
| | 1223 | | { |
| 0 | 1224 | | ex.Body = _errorBody; |
| | 1225 | | } |
| 0 | 1226 | | } |
| 0 | 1227 | | catch (JsonException) |
| | 1228 | | { |
| | 1229 | | // Ignore the exception |
| 0 | 1230 | | } |
| 0 | 1231 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1232 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1233 | | if (_shouldTrace) |
| | 1234 | | { |
| 0 | 1235 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1236 | | } |
| 0 | 1237 | | _httpRequest.Dispose(); |
| 0 | 1238 | | if (_httpResponse != null) |
| | 1239 | | { |
| 0 | 1240 | | _httpResponse.Dispose(); |
| | 1241 | | } |
| 0 | 1242 | | throw ex; |
| | 1243 | | } |
| | 1244 | | // Create Result |
| 3 | 1245 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 3 | 1246 | | _result.Request = _httpRequest; |
| 3 | 1247 | | _result.Response = _httpResponse; |
| | 1248 | | // Deserialize Response |
| 3 | 1249 | | if ((int)_statusCode == 200) |
| | 1250 | | { |
| 3 | 1251 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1252 | | try |
| | 1253 | | { |
| 3 | 1254 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 3 | 1255 | | } |
| 0 | 1256 | | catch (JsonException ex) |
| | 1257 | | { |
| 0 | 1258 | | _httpRequest.Dispose(); |
| 0 | 1259 | | if (_httpResponse != null) |
| | 1260 | | { |
| 0 | 1261 | | _httpResponse.Dispose(); |
| | 1262 | | } |
| 0 | 1263 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1264 | | } |
| | 1265 | | } |
| 3 | 1266 | | if (_shouldTrace) |
| | 1267 | | { |
| 0 | 1268 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1269 | | } |
| 3 | 1270 | | return _result; |
| 3 | 1271 | | } |
| | 1272 | |
|
| | 1273 | | /// <summary> |
| | 1274 | | /// Returns patterns for the specific intent in a version of the application. |
| | 1275 | | /// </summary> |
| | 1276 | | /// <param name='appId'> |
| | 1277 | | /// The application ID. |
| | 1278 | | /// </param> |
| | 1279 | | /// <param name='versionId'> |
| | 1280 | | /// The version ID. |
| | 1281 | | /// </param> |
| | 1282 | | /// <param name='intentId'> |
| | 1283 | | /// The intent classifier ID. |
| | 1284 | | /// </param> |
| | 1285 | | /// <param name='skip'> |
| | 1286 | | /// The number of entries to skip. Default value is 0. |
| | 1287 | | /// </param> |
| | 1288 | | /// <param name='take'> |
| | 1289 | | /// The number of entries to return. Maximum page size is 500. Default is 100. |
| | 1290 | | /// </param> |
| | 1291 | | /// <param name='customHeaders'> |
| | 1292 | | /// Headers that will be added to request. |
| | 1293 | | /// </param> |
| | 1294 | | /// <param name='cancellationToken'> |
| | 1295 | | /// The cancellation token. |
| | 1296 | | /// </param> |
| | 1297 | | /// <exception cref="ErrorResponseException"> |
| | 1298 | | /// Thrown when the operation returned an invalid status code |
| | 1299 | | /// </exception> |
| | 1300 | | /// <exception cref="SerializationException"> |
| | 1301 | | /// Thrown when unable to deserialize the response |
| | 1302 | | /// </exception> |
| | 1303 | | /// <exception cref="ValidationException"> |
| | 1304 | | /// Thrown when a required parameter is null |
| | 1305 | | /// </exception> |
| | 1306 | | /// <exception cref="System.ArgumentNullException"> |
| | 1307 | | /// Thrown when a required parameter is null |
| | 1308 | | /// </exception> |
| | 1309 | | /// <return> |
| | 1310 | | /// A response object containing the response body and response headers. |
| | 1311 | | /// </return> |
| | 1312 | | public async Task<HttpOperationResponse<IList<PatternRuleInfo>>> ListIntentPatternsWithHttpMessagesAsync(System. |
| | 1313 | | { |
| 1 | 1314 | | if (Client.Endpoint == null) |
| | 1315 | | { |
| 0 | 1316 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1317 | | } |
| 1 | 1318 | | if (versionId == null) |
| | 1319 | | { |
| 0 | 1320 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 1321 | | } |
| 1 | 1322 | | if (skip < 0) |
| | 1323 | | { |
| 0 | 1324 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "skip", 0); |
| | 1325 | | } |
| 1 | 1326 | | if (take > 500) |
| | 1327 | | { |
| 0 | 1328 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 500); |
| | 1329 | | } |
| 1 | 1330 | | if (take < 0) |
| | 1331 | | { |
| 0 | 1332 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0); |
| | 1333 | | } |
| | 1334 | | // Tracing |
| 1 | 1335 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 1 | 1336 | | string _invocationId = null; |
| 1 | 1337 | | if (_shouldTrace) |
| | 1338 | | { |
| 0 | 1339 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1340 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1341 | | tracingParameters.Add("appId", appId); |
| 0 | 1342 | | tracingParameters.Add("versionId", versionId); |
| 0 | 1343 | | tracingParameters.Add("intentId", intentId); |
| 0 | 1344 | | tracingParameters.Add("skip", skip); |
| 0 | 1345 | | tracingParameters.Add("take", take); |
| 0 | 1346 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1347 | | ServiceClientTracing.Enter(_invocationId, this, "ListIntentPatterns", tracingParameters); |
| | 1348 | | } |
| | 1349 | | // Construct URL |
| 1 | 1350 | | var _baseUrl = Client.BaseUri; |
| 1 | 1351 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/intents/{inte |
| 1 | 1352 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 1 | 1353 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 1 | 1354 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| 1 | 1355 | | _url = _url.Replace("{intentId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb |
| 1 | 1356 | | List<string> _queryParameters = new List<string>(); |
| 1 | 1357 | | if (skip != null) |
| | 1358 | | { |
| 1 | 1359 | | _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 1360 | | } |
| 1 | 1361 | | if (take != null) |
| | 1362 | | { |
| 1 | 1363 | | _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | 1364 | | } |
| 1 | 1365 | | if (_queryParameters.Count > 0) |
| | 1366 | | { |
| 1 | 1367 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1368 | | } |
| | 1369 | | // Create HTTP transport objects |
| 1 | 1370 | | var _httpRequest = new HttpRequestMessage(); |
| 1 | 1371 | | HttpResponseMessage _httpResponse = null; |
| 1 | 1372 | | _httpRequest.Method = new HttpMethod("GET"); |
| 1 | 1373 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1374 | | // Set Headers |
| | 1375 | |
|
| | 1376 | |
|
| 1 | 1377 | | if (customHeaders != null) |
| | 1378 | | { |
| 0 | 1379 | | foreach(var _header in customHeaders) |
| | 1380 | | { |
| 0 | 1381 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1382 | | { |
| 0 | 1383 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1384 | | } |
| 0 | 1385 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1386 | | } |
| | 1387 | | } |
| | 1388 | |
|
| | 1389 | | // Serialize Request |
| 1 | 1390 | | string _requestContent = null; |
| | 1391 | | // Set Credentials |
| 1 | 1392 | | if (Client.Credentials != null) |
| | 1393 | | { |
| 1 | 1394 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1395 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1396 | | } |
| | 1397 | | // Send Request |
| 1 | 1398 | | if (_shouldTrace) |
| | 1399 | | { |
| 0 | 1400 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1401 | | } |
| 1 | 1402 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1403 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 1 | 1404 | | if (_shouldTrace) |
| | 1405 | | { |
| 0 | 1406 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1407 | | } |
| 1 | 1408 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 1 | 1409 | | cancellationToken.ThrowIfCancellationRequested(); |
| 1 | 1410 | | string _responseContent = null; |
| 1 | 1411 | | if ((int)_statusCode != 200) |
| | 1412 | | { |
| 0 | 1413 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1414 | | try |
| | 1415 | | { |
| 0 | 1416 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1417 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1418 | | if (_errorBody != null) |
| | 1419 | | { |
| 0 | 1420 | | ex.Body = _errorBody; |
| | 1421 | | } |
| 0 | 1422 | | } |
| 0 | 1423 | | catch (JsonException) |
| | 1424 | | { |
| | 1425 | | // Ignore the exception |
| 0 | 1426 | | } |
| 0 | 1427 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1428 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1429 | | if (_shouldTrace) |
| | 1430 | | { |
| 0 | 1431 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1432 | | } |
| 0 | 1433 | | _httpRequest.Dispose(); |
| 0 | 1434 | | if (_httpResponse != null) |
| | 1435 | | { |
| 0 | 1436 | | _httpResponse.Dispose(); |
| | 1437 | | } |
| 0 | 1438 | | throw ex; |
| | 1439 | | } |
| | 1440 | | // Create Result |
| 1 | 1441 | | var _result = new HttpOperationResponse<IList<PatternRuleInfo>>(); |
| 1 | 1442 | | _result.Request = _httpRequest; |
| 1 | 1443 | | _result.Response = _httpResponse; |
| | 1444 | | // Deserialize Response |
| 1 | 1445 | | if ((int)_statusCode == 200) |
| | 1446 | | { |
| 1 | 1447 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1448 | | try |
| | 1449 | | { |
| 1 | 1450 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PatternRuleInfo>>(_respons |
| 1 | 1451 | | } |
| 0 | 1452 | | catch (JsonException ex) |
| | 1453 | | { |
| 0 | 1454 | | _httpRequest.Dispose(); |
| 0 | 1455 | | if (_httpResponse != null) |
| | 1456 | | { |
| 0 | 1457 | | _httpResponse.Dispose(); |
| | 1458 | | } |
| 0 | 1459 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1460 | | } |
| | 1461 | | } |
| 1 | 1462 | | if (_shouldTrace) |
| | 1463 | | { |
| 0 | 1464 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1465 | | } |
| 1 | 1466 | | return _result; |
| 1 | 1467 | | } |
| | 1468 | |
|
| | 1469 | | } |
| | 1470 | | } |