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