| | 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 | | /// Settings operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class Settings : IServiceOperations<LUISAuthoringClient>, ISettings |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the Settings 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 Settings(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> |
| 0 | 51 | | public LUISAuthoringClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Gets the settings 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='customHeaders'> |
| | 63 | | /// Headers that will be added to request. |
| | 64 | | /// </param> |
| | 65 | | /// <param name='cancellationToken'> |
| | 66 | | /// The cancellation token. |
| | 67 | | /// </param> |
| | 68 | | /// <exception cref="ErrorResponseException"> |
| | 69 | | /// Thrown when the operation returned an invalid status code |
| | 70 | | /// </exception> |
| | 71 | | /// <exception cref="SerializationException"> |
| | 72 | | /// Thrown when unable to deserialize the response |
| | 73 | | /// </exception> |
| | 74 | | /// <exception cref="ValidationException"> |
| | 75 | | /// Thrown when a required parameter is null |
| | 76 | | /// </exception> |
| | 77 | | /// <exception cref="System.ArgumentNullException"> |
| | 78 | | /// Thrown when a required parameter is null |
| | 79 | | /// </exception> |
| | 80 | | /// <return> |
| | 81 | | /// A response object containing the response body and response headers. |
| | 82 | | /// </return> |
| | 83 | | public async Task<HttpOperationResponse<IList<AppVersionSettingObject>>> ListWithHttpMessagesAsync(System.Guid a |
| | 84 | | { |
| 0 | 85 | | if (Client.Endpoint == null) |
| | 86 | | { |
| 0 | 87 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 88 | | } |
| 0 | 89 | | if (versionId == null) |
| | 90 | | { |
| 0 | 91 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 92 | | } |
| | 93 | | // Tracing |
| 0 | 94 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 95 | | string _invocationId = null; |
| 0 | 96 | | if (_shouldTrace) |
| | 97 | | { |
| 0 | 98 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 99 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 100 | | tracingParameters.Add("appId", appId); |
| 0 | 101 | | tracingParameters.Add("versionId", versionId); |
| 0 | 102 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 103 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 104 | | } |
| | 105 | | // Construct URL |
| 0 | 106 | | var _baseUrl = Client.BaseUri; |
| 0 | 107 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/settings"; |
| 0 | 108 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 109 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 0 | 110 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 111 | | // Create HTTP transport objects |
| 0 | 112 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 113 | | HttpResponseMessage _httpResponse = null; |
| 0 | 114 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 115 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 116 | | // Set Headers |
| | 117 | |
|
| | 118 | |
|
| 0 | 119 | | if (customHeaders != null) |
| | 120 | | { |
| 0 | 121 | | foreach(var _header in customHeaders) |
| | 122 | | { |
| 0 | 123 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 124 | | { |
| 0 | 125 | | _httpRequest.Headers.Remove(_header.Key); |
| | 126 | | } |
| 0 | 127 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 128 | | } |
| | 129 | | } |
| | 130 | |
|
| | 131 | | // Serialize Request |
| 0 | 132 | | string _requestContent = null; |
| | 133 | | // Set Credentials |
| 0 | 134 | | if (Client.Credentials != null) |
| | 135 | | { |
| 0 | 136 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 137 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 138 | | } |
| | 139 | | // Send Request |
| 0 | 140 | | if (_shouldTrace) |
| | 141 | | { |
| 0 | 142 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 143 | | } |
| 0 | 144 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 145 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 146 | | if (_shouldTrace) |
| | 147 | | { |
| 0 | 148 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 149 | | } |
| 0 | 150 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 151 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 152 | | string _responseContent = null; |
| 0 | 153 | | if ((int)_statusCode != 200) |
| | 154 | | { |
| 0 | 155 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 156 | | try |
| | 157 | | { |
| 0 | 158 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 159 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 160 | | if (_errorBody != null) |
| | 161 | | { |
| 0 | 162 | | ex.Body = _errorBody; |
| | 163 | | } |
| 0 | 164 | | } |
| 0 | 165 | | catch (JsonException) |
| | 166 | | { |
| | 167 | | // Ignore the exception |
| 0 | 168 | | } |
| 0 | 169 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 170 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 171 | | if (_shouldTrace) |
| | 172 | | { |
| 0 | 173 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 174 | | } |
| 0 | 175 | | _httpRequest.Dispose(); |
| 0 | 176 | | if (_httpResponse != null) |
| | 177 | | { |
| 0 | 178 | | _httpResponse.Dispose(); |
| | 179 | | } |
| 0 | 180 | | throw ex; |
| | 181 | | } |
| | 182 | | // Create Result |
| 0 | 183 | | var _result = new HttpOperationResponse<IList<AppVersionSettingObject>>(); |
| 0 | 184 | | _result.Request = _httpRequest; |
| 0 | 185 | | _result.Response = _httpResponse; |
| | 186 | | // Deserialize Response |
| 0 | 187 | | if ((int)_statusCode == 200) |
| | 188 | | { |
| 0 | 189 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 190 | | try |
| | 191 | | { |
| 0 | 192 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<AppVersionSettingObject>>( |
| 0 | 193 | | } |
| 0 | 194 | | catch (JsonException ex) |
| | 195 | | { |
| 0 | 196 | | _httpRequest.Dispose(); |
| 0 | 197 | | if (_httpResponse != null) |
| | 198 | | { |
| 0 | 199 | | _httpResponse.Dispose(); |
| | 200 | | } |
| 0 | 201 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 202 | | } |
| | 203 | | } |
| 0 | 204 | | if (_shouldTrace) |
| | 205 | | { |
| 0 | 206 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 207 | | } |
| 0 | 208 | | return _result; |
| 0 | 209 | | } |
| | 210 | |
|
| | 211 | | /// <summary> |
| | 212 | | /// Updates the settings in a version of the application. |
| | 213 | | /// </summary> |
| | 214 | | /// <param name='appId'> |
| | 215 | | /// The application ID. |
| | 216 | | /// </param> |
| | 217 | | /// <param name='versionId'> |
| | 218 | | /// The version ID. |
| | 219 | | /// </param> |
| | 220 | | /// <param name='listOfAppVersionSettingObject'> |
| | 221 | | /// A list of the updated application version settings. |
| | 222 | | /// </param> |
| | 223 | | /// <param name='customHeaders'> |
| | 224 | | /// Headers that will be added to request. |
| | 225 | | /// </param> |
| | 226 | | /// <param name='cancellationToken'> |
| | 227 | | /// The cancellation token. |
| | 228 | | /// </param> |
| | 229 | | /// <exception cref="ErrorResponseException"> |
| | 230 | | /// Thrown when the operation returned an invalid status code |
| | 231 | | /// </exception> |
| | 232 | | /// <exception cref="SerializationException"> |
| | 233 | | /// Thrown when unable to deserialize the response |
| | 234 | | /// </exception> |
| | 235 | | /// <exception cref="ValidationException"> |
| | 236 | | /// Thrown when a required parameter is null |
| | 237 | | /// </exception> |
| | 238 | | /// <exception cref="System.ArgumentNullException"> |
| | 239 | | /// Thrown when a required parameter is null |
| | 240 | | /// </exception> |
| | 241 | | /// <return> |
| | 242 | | /// A response object containing the response body and response headers. |
| | 243 | | /// </return> |
| | 244 | | public async Task<HttpOperationResponse<OperationStatus>> UpdateWithHttpMessagesAsync(System.Guid appId, string |
| | 245 | | { |
| 0 | 246 | | if (Client.Endpoint == null) |
| | 247 | | { |
| 0 | 248 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 249 | | } |
| 0 | 250 | | if (versionId == null) |
| | 251 | | { |
| 0 | 252 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | 253 | | } |
| 0 | 254 | | if (listOfAppVersionSettingObject == null) |
| | 255 | | { |
| 0 | 256 | | throw new ValidationException(ValidationRules.CannotBeNull, "listOfAppVersionSettingObject"); |
| | 257 | | } |
| | 258 | | // Tracing |
| 0 | 259 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 260 | | string _invocationId = null; |
| 0 | 261 | | if (_shouldTrace) |
| | 262 | | { |
| 0 | 263 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 264 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 265 | | tracingParameters.Add("appId", appId); |
| 0 | 266 | | tracingParameters.Add("versionId", versionId); |
| 0 | 267 | | tracingParameters.Add("listOfAppVersionSettingObject", listOfAppVersionSettingObject); |
| 0 | 268 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 269 | | ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); |
| | 270 | | } |
| | 271 | | // Construct URL |
| 0 | 272 | | var _baseUrl = Client.BaseUri; |
| 0 | 273 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/settings"; |
| 0 | 274 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 275 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| 0 | 276 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 277 | | // Create HTTP transport objects |
| 0 | 278 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 279 | | HttpResponseMessage _httpResponse = null; |
| 0 | 280 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 0 | 281 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 282 | | // Set Headers |
| | 283 | |
|
| | 284 | |
|
| 0 | 285 | | if (customHeaders != null) |
| | 286 | | { |
| 0 | 287 | | foreach(var _header in customHeaders) |
| | 288 | | { |
| 0 | 289 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 290 | | { |
| 0 | 291 | | _httpRequest.Headers.Remove(_header.Key); |
| | 292 | | } |
| 0 | 293 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 294 | | } |
| | 295 | | } |
| | 296 | |
|
| | 297 | | // Serialize Request |
| 0 | 298 | | string _requestContent = null; |
| 0 | 299 | | if(listOfAppVersionSettingObject != null) |
| | 300 | | { |
| 0 | 301 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(listOfAppVersionSettingObject, Clie |
| 0 | 302 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 303 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 304 | | } |
| | 305 | | // Set Credentials |
| 0 | 306 | | if (Client.Credentials != null) |
| | 307 | | { |
| 0 | 308 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 309 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 310 | | } |
| | 311 | | // Send Request |
| 0 | 312 | | if (_shouldTrace) |
| | 313 | | { |
| 0 | 314 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 315 | | } |
| 0 | 316 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 317 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 318 | | if (_shouldTrace) |
| | 319 | | { |
| 0 | 320 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 321 | | } |
| 0 | 322 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 323 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 324 | | string _responseContent = null; |
| 0 | 325 | | if ((int)_statusCode != 200) |
| | 326 | | { |
| 0 | 327 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 328 | | try |
| | 329 | | { |
| 0 | 330 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 331 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 332 | | if (_errorBody != null) |
| | 333 | | { |
| 0 | 334 | | ex.Body = _errorBody; |
| | 335 | | } |
| 0 | 336 | | } |
| 0 | 337 | | catch (JsonException) |
| | 338 | | { |
| | 339 | | // Ignore the exception |
| 0 | 340 | | } |
| 0 | 341 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 342 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 343 | | if (_shouldTrace) |
| | 344 | | { |
| 0 | 345 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 346 | | } |
| 0 | 347 | | _httpRequest.Dispose(); |
| 0 | 348 | | if (_httpResponse != null) |
| | 349 | | { |
| 0 | 350 | | _httpResponse.Dispose(); |
| | 351 | | } |
| 0 | 352 | | throw ex; |
| | 353 | | } |
| | 354 | | // Create Result |
| 0 | 355 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 0 | 356 | | _result.Request = _httpRequest; |
| 0 | 357 | | _result.Response = _httpResponse; |
| | 358 | | // Deserialize Response |
| 0 | 359 | | if ((int)_statusCode == 200) |
| | 360 | | { |
| 0 | 361 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 362 | | try |
| | 363 | | { |
| 0 | 364 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 0 | 365 | | } |
| 0 | 366 | | catch (JsonException ex) |
| | 367 | | { |
| 0 | 368 | | _httpRequest.Dispose(); |
| 0 | 369 | | if (_httpResponse != null) |
| | 370 | | { |
| 0 | 371 | | _httpResponse.Dispose(); |
| | 372 | | } |
| 0 | 373 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 374 | | } |
| | 375 | | } |
| 0 | 376 | | if (_shouldTrace) |
| | 377 | | { |
| 0 | 378 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 379 | | } |
| 0 | 380 | | return _result; |
| 0 | 381 | | } |
| | 382 | |
|
| | 383 | | } |
| | 384 | | } |