| | 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 | | /// AzureAccounts operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class AzureAccounts : IServiceOperations<LUISAuthoringClient>, IAzureAccounts |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the AzureAccounts 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 AzureAccounts(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 | | /// apps - Assign a LUIS Azure account to an application |
| | 55 | | /// </summary> |
| | 56 | | /// <remarks> |
| | 57 | | /// Assigns an Azure account to the application. |
| | 58 | | /// </remarks> |
| | 59 | | /// <param name='appId'> |
| | 60 | | /// The application ID. |
| | 61 | | /// </param> |
| | 62 | | /// <param name='armToken'> |
| | 63 | | /// The custom arm token header to use; containing the user's ARM token used to |
| | 64 | | /// validate azure accounts information. |
| | 65 | | /// </param> |
| | 66 | | /// <param name='azureAccountInfoObject'> |
| | 67 | | /// The Azure account information object. |
| | 68 | | /// </param> |
| | 69 | | /// <param name='customHeaders'> |
| | 70 | | /// Headers that will be added to request. |
| | 71 | | /// </param> |
| | 72 | | /// <param name='cancellationToken'> |
| | 73 | | /// The cancellation token. |
| | 74 | | /// </param> |
| | 75 | | /// <exception cref="ErrorResponseException"> |
| | 76 | | /// Thrown when the operation returned an invalid status code |
| | 77 | | /// </exception> |
| | 78 | | /// <exception cref="SerializationException"> |
| | 79 | | /// Thrown when unable to deserialize the response |
| | 80 | | /// </exception> |
| | 81 | | /// <exception cref="ValidationException"> |
| | 82 | | /// Thrown when a required parameter is null |
| | 83 | | /// </exception> |
| | 84 | | /// <exception cref="System.ArgumentNullException"> |
| | 85 | | /// Thrown when a required parameter is null |
| | 86 | | /// </exception> |
| | 87 | | /// <return> |
| | 88 | | /// A response object containing the response body and response headers. |
| | 89 | | /// </return> |
| | 90 | | public async Task<HttpOperationResponse<OperationStatus>> AssignToAppWithHttpMessagesAsync(System.Guid appId, st |
| | 91 | | { |
| 0 | 92 | | if (Client.Endpoint == null) |
| | 93 | | { |
| 0 | 94 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 95 | | } |
| 0 | 96 | | if (azureAccountInfoObject != null) |
| | 97 | | { |
| 0 | 98 | | azureAccountInfoObject.Validate(); |
| | 99 | | } |
| | 100 | | // Tracing |
| 0 | 101 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 102 | | string _invocationId = null; |
| 0 | 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("armToken", armToken); |
| 0 | 109 | | tracingParameters.Add("azureAccountInfoObject", azureAccountInfoObject); |
| 0 | 110 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 111 | | ServiceClientTracing.Enter(_invocationId, this, "AssignToApp", tracingParameters); |
| | 112 | | } |
| | 113 | | // Construct URL |
| 0 | 114 | | var _baseUrl = Client.BaseUri; |
| 0 | 115 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/azureaccounts"; |
| 0 | 116 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 117 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 118 | | // Create HTTP transport objects |
| 0 | 119 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 120 | | HttpResponseMessage _httpResponse = null; |
| 0 | 121 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 122 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 123 | | // Set Headers |
| 0 | 124 | | if (armToken != null) |
| | 125 | | { |
| 0 | 126 | | if (_httpRequest.Headers.Contains("ArmToken")) |
| | 127 | | { |
| 0 | 128 | | _httpRequest.Headers.Remove("ArmToken"); |
| | 129 | | } |
| 0 | 130 | | _httpRequest.Headers.TryAddWithoutValidation("ArmToken", armToken); |
| | 131 | | } |
| | 132 | |
|
| | 133 | |
|
| 0 | 134 | | if (customHeaders != null) |
| | 135 | | { |
| 0 | 136 | | foreach(var _header in customHeaders) |
| | 137 | | { |
| 0 | 138 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 139 | | { |
| 0 | 140 | | _httpRequest.Headers.Remove(_header.Key); |
| | 141 | | } |
| 0 | 142 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 143 | | } |
| | 144 | | } |
| | 145 | |
|
| | 146 | | // Serialize Request |
| 0 | 147 | | string _requestContent = null; |
| 0 | 148 | | if(azureAccountInfoObject != null) |
| | 149 | | { |
| 0 | 150 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(azureAccountInfoObject, Client.Seri |
| 0 | 151 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 152 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 153 | | } |
| | 154 | | // Set Credentials |
| 0 | 155 | | if (Client.Credentials != null) |
| | 156 | | { |
| 0 | 157 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 158 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 159 | | } |
| | 160 | | // Send Request |
| 0 | 161 | | if (_shouldTrace) |
| | 162 | | { |
| 0 | 163 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 164 | | } |
| 0 | 165 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 166 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 167 | | if (_shouldTrace) |
| | 168 | | { |
| 0 | 169 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 170 | | } |
| 0 | 171 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 172 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 173 | | string _responseContent = null; |
| 0 | 174 | | if ((int)_statusCode != 201) |
| | 175 | | { |
| 0 | 176 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 177 | | try |
| | 178 | | { |
| 0 | 179 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 180 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 181 | | if (_errorBody != null) |
| | 182 | | { |
| 0 | 183 | | ex.Body = _errorBody; |
| | 184 | | } |
| 0 | 185 | | } |
| 0 | 186 | | catch (JsonException) |
| | 187 | | { |
| | 188 | | // Ignore the exception |
| 0 | 189 | | } |
| 0 | 190 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 191 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 192 | | if (_shouldTrace) |
| | 193 | | { |
| 0 | 194 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 195 | | } |
| 0 | 196 | | _httpRequest.Dispose(); |
| 0 | 197 | | if (_httpResponse != null) |
| | 198 | | { |
| 0 | 199 | | _httpResponse.Dispose(); |
| | 200 | | } |
| 0 | 201 | | throw ex; |
| | 202 | | } |
| | 203 | | // Create Result |
| 0 | 204 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 0 | 205 | | _result.Request = _httpRequest; |
| 0 | 206 | | _result.Response = _httpResponse; |
| | 207 | | // Deserialize Response |
| 0 | 208 | | if ((int)_statusCode == 201) |
| | 209 | | { |
| 0 | 210 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 211 | | try |
| | 212 | | { |
| 0 | 213 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 0 | 214 | | } |
| 0 | 215 | | catch (JsonException ex) |
| | 216 | | { |
| 0 | 217 | | _httpRequest.Dispose(); |
| 0 | 218 | | if (_httpResponse != null) |
| | 219 | | { |
| 0 | 220 | | _httpResponse.Dispose(); |
| | 221 | | } |
| 0 | 222 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 223 | | } |
| | 224 | | } |
| 0 | 225 | | if (_shouldTrace) |
| | 226 | | { |
| 0 | 227 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 228 | | } |
| 0 | 229 | | return _result; |
| 0 | 230 | | } |
| | 231 | |
|
| | 232 | | /// <summary> |
| | 233 | | /// apps - Get LUIS Azure accounts assigned to the application |
| | 234 | | /// </summary> |
| | 235 | | /// <remarks> |
| | 236 | | /// Gets the LUIS Azure accounts assigned to the application for the user using |
| | 237 | | /// his ARM token. |
| | 238 | | /// </remarks> |
| | 239 | | /// <param name='appId'> |
| | 240 | | /// The application ID. |
| | 241 | | /// </param> |
| | 242 | | /// <param name='armToken'> |
| | 243 | | /// The custom arm token header to use; containing the user's ARM token used to |
| | 244 | | /// validate azure accounts information. |
| | 245 | | /// </param> |
| | 246 | | /// <param name='customHeaders'> |
| | 247 | | /// Headers that will be added to request. |
| | 248 | | /// </param> |
| | 249 | | /// <param name='cancellationToken'> |
| | 250 | | /// The cancellation token. |
| | 251 | | /// </param> |
| | 252 | | /// <exception cref="ErrorResponseException"> |
| | 253 | | /// Thrown when the operation returned an invalid status code |
| | 254 | | /// </exception> |
| | 255 | | /// <exception cref="SerializationException"> |
| | 256 | | /// Thrown when unable to deserialize the response |
| | 257 | | /// </exception> |
| | 258 | | /// <exception cref="ValidationException"> |
| | 259 | | /// Thrown when a required parameter is null |
| | 260 | | /// </exception> |
| | 261 | | /// <exception cref="System.ArgumentNullException"> |
| | 262 | | /// Thrown when a required parameter is null |
| | 263 | | /// </exception> |
| | 264 | | /// <return> |
| | 265 | | /// A response object containing the response body and response headers. |
| | 266 | | /// </return> |
| | 267 | | public async Task<HttpOperationResponse<IList<AzureAccountInfoObject>>> GetAssignedWithHttpMessagesAsync(System. |
| | 268 | | { |
| 0 | 269 | | if (Client.Endpoint == null) |
| | 270 | | { |
| 0 | 271 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 272 | | } |
| | 273 | | // Tracing |
| 0 | 274 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 275 | | string _invocationId = null; |
| 0 | 276 | | if (_shouldTrace) |
| | 277 | | { |
| 0 | 278 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 279 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 280 | | tracingParameters.Add("appId", appId); |
| 0 | 281 | | tracingParameters.Add("armToken", armToken); |
| 0 | 282 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 283 | | ServiceClientTracing.Enter(_invocationId, this, "GetAssigned", tracingParameters); |
| | 284 | | } |
| | 285 | | // Construct URL |
| 0 | 286 | | var _baseUrl = Client.BaseUri; |
| 0 | 287 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/azureaccounts"; |
| 0 | 288 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 289 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 290 | | // Create HTTP transport objects |
| 0 | 291 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 292 | | HttpResponseMessage _httpResponse = null; |
| 0 | 293 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 294 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 295 | | // Set Headers |
| 0 | 296 | | if (armToken != null) |
| | 297 | | { |
| 0 | 298 | | if (_httpRequest.Headers.Contains("ArmToken")) |
| | 299 | | { |
| 0 | 300 | | _httpRequest.Headers.Remove("ArmToken"); |
| | 301 | | } |
| 0 | 302 | | _httpRequest.Headers.TryAddWithoutValidation("ArmToken", armToken); |
| | 303 | | } |
| | 304 | |
|
| | 305 | |
|
| 0 | 306 | | if (customHeaders != null) |
| | 307 | | { |
| 0 | 308 | | foreach(var _header in customHeaders) |
| | 309 | | { |
| 0 | 310 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 311 | | { |
| 0 | 312 | | _httpRequest.Headers.Remove(_header.Key); |
| | 313 | | } |
| 0 | 314 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 315 | | } |
| | 316 | | } |
| | 317 | |
|
| | 318 | | // Serialize Request |
| 0 | 319 | | string _requestContent = null; |
| | 320 | | // Set Credentials |
| 0 | 321 | | if (Client.Credentials != null) |
| | 322 | | { |
| 0 | 323 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 324 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 325 | | } |
| | 326 | | // Send Request |
| 0 | 327 | | if (_shouldTrace) |
| | 328 | | { |
| 0 | 329 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 330 | | } |
| 0 | 331 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 332 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 333 | | if (_shouldTrace) |
| | 334 | | { |
| 0 | 335 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 336 | | } |
| 0 | 337 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 338 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 339 | | string _responseContent = null; |
| 0 | 340 | | if ((int)_statusCode != 200) |
| | 341 | | { |
| 0 | 342 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 343 | | try |
| | 344 | | { |
| 0 | 345 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 346 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 347 | | if (_errorBody != null) |
| | 348 | | { |
| 0 | 349 | | ex.Body = _errorBody; |
| | 350 | | } |
| 0 | 351 | | } |
| 0 | 352 | | catch (JsonException) |
| | 353 | | { |
| | 354 | | // Ignore the exception |
| 0 | 355 | | } |
| 0 | 356 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 357 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 358 | | if (_shouldTrace) |
| | 359 | | { |
| 0 | 360 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 361 | | } |
| 0 | 362 | | _httpRequest.Dispose(); |
| 0 | 363 | | if (_httpResponse != null) |
| | 364 | | { |
| 0 | 365 | | _httpResponse.Dispose(); |
| | 366 | | } |
| 0 | 367 | | throw ex; |
| | 368 | | } |
| | 369 | | // Create Result |
| 0 | 370 | | var _result = new HttpOperationResponse<IList<AzureAccountInfoObject>>(); |
| 0 | 371 | | _result.Request = _httpRequest; |
| 0 | 372 | | _result.Response = _httpResponse; |
| | 373 | | // Deserialize Response |
| 0 | 374 | | if ((int)_statusCode == 200) |
| | 375 | | { |
| 0 | 376 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 377 | | try |
| | 378 | | { |
| 0 | 379 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<AzureAccountInfoObject>>(_ |
| 0 | 380 | | } |
| 0 | 381 | | catch (JsonException ex) |
| | 382 | | { |
| 0 | 383 | | _httpRequest.Dispose(); |
| 0 | 384 | | if (_httpResponse != null) |
| | 385 | | { |
| 0 | 386 | | _httpResponse.Dispose(); |
| | 387 | | } |
| 0 | 388 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 389 | | } |
| | 390 | | } |
| 0 | 391 | | if (_shouldTrace) |
| | 392 | | { |
| 0 | 393 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 394 | | } |
| 0 | 395 | | return _result; |
| 0 | 396 | | } |
| | 397 | |
|
| | 398 | | /// <summary> |
| | 399 | | /// apps - Removes an assigned LUIS Azure account from an application |
| | 400 | | /// </summary> |
| | 401 | | /// <remarks> |
| | 402 | | /// Removes assigned Azure account from the application. |
| | 403 | | /// </remarks> |
| | 404 | | /// <param name='appId'> |
| | 405 | | /// The application ID. |
| | 406 | | /// </param> |
| | 407 | | /// <param name='armToken'> |
| | 408 | | /// The custom arm token header to use; containing the user's ARM token used to |
| | 409 | | /// validate azure accounts information. |
| | 410 | | /// </param> |
| | 411 | | /// <param name='azureAccountInfoObject'> |
| | 412 | | /// The Azure account information object. |
| | 413 | | /// </param> |
| | 414 | | /// <param name='customHeaders'> |
| | 415 | | /// Headers that will be added to request. |
| | 416 | | /// </param> |
| | 417 | | /// <param name='cancellationToken'> |
| | 418 | | /// The cancellation token. |
| | 419 | | /// </param> |
| | 420 | | /// <exception cref="ErrorResponseException"> |
| | 421 | | /// Thrown when the operation returned an invalid status code |
| | 422 | | /// </exception> |
| | 423 | | /// <exception cref="SerializationException"> |
| | 424 | | /// Thrown when unable to deserialize the response |
| | 425 | | /// </exception> |
| | 426 | | /// <exception cref="ValidationException"> |
| | 427 | | /// Thrown when a required parameter is null |
| | 428 | | /// </exception> |
| | 429 | | /// <exception cref="System.ArgumentNullException"> |
| | 430 | | /// Thrown when a required parameter is null |
| | 431 | | /// </exception> |
| | 432 | | /// <return> |
| | 433 | | /// A response object containing the response body and response headers. |
| | 434 | | /// </return> |
| | 435 | | public async Task<HttpOperationResponse<OperationStatus>> RemoveFromAppWithHttpMessagesAsync(System.Guid appId, |
| | 436 | | { |
| 0 | 437 | | if (Client.Endpoint == null) |
| | 438 | | { |
| 0 | 439 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 440 | | } |
| 0 | 441 | | if (azureAccountInfoObject != null) |
| | 442 | | { |
| 0 | 443 | | azureAccountInfoObject.Validate(); |
| | 444 | | } |
| | 445 | | // Tracing |
| 0 | 446 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 447 | | string _invocationId = null; |
| 0 | 448 | | if (_shouldTrace) |
| | 449 | | { |
| 0 | 450 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 451 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 452 | | tracingParameters.Add("appId", appId); |
| 0 | 453 | | tracingParameters.Add("armToken", armToken); |
| 0 | 454 | | tracingParameters.Add("azureAccountInfoObject", azureAccountInfoObject); |
| 0 | 455 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 456 | | ServiceClientTracing.Enter(_invocationId, this, "RemoveFromApp", tracingParameters); |
| | 457 | | } |
| | 458 | | // Construct URL |
| 0 | 459 | | var _baseUrl = Client.BaseUri; |
| 0 | 460 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/azureaccounts"; |
| 0 | 461 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 462 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 463 | | // Create HTTP transport objects |
| 0 | 464 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 465 | | HttpResponseMessage _httpResponse = null; |
| 0 | 466 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 467 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 468 | | // Set Headers |
| 0 | 469 | | if (armToken != null) |
| | 470 | | { |
| 0 | 471 | | if (_httpRequest.Headers.Contains("ArmToken")) |
| | 472 | | { |
| 0 | 473 | | _httpRequest.Headers.Remove("ArmToken"); |
| | 474 | | } |
| 0 | 475 | | _httpRequest.Headers.TryAddWithoutValidation("ArmToken", armToken); |
| | 476 | | } |
| | 477 | |
|
| | 478 | |
|
| 0 | 479 | | if (customHeaders != null) |
| | 480 | | { |
| 0 | 481 | | foreach(var _header in customHeaders) |
| | 482 | | { |
| 0 | 483 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 484 | | { |
| 0 | 485 | | _httpRequest.Headers.Remove(_header.Key); |
| | 486 | | } |
| 0 | 487 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 488 | | } |
| | 489 | | } |
| | 490 | |
|
| | 491 | | // Serialize Request |
| 0 | 492 | | string _requestContent = null; |
| 0 | 493 | | if(azureAccountInfoObject != null) |
| | 494 | | { |
| 0 | 495 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(azureAccountInfoObject, Client.Seri |
| 0 | 496 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 497 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 498 | | } |
| | 499 | | // Set Credentials |
| 0 | 500 | | if (Client.Credentials != null) |
| | 501 | | { |
| 0 | 502 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 503 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 504 | | } |
| | 505 | | // Send Request |
| 0 | 506 | | if (_shouldTrace) |
| | 507 | | { |
| 0 | 508 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 509 | | } |
| 0 | 510 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 511 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 512 | | if (_shouldTrace) |
| | 513 | | { |
| 0 | 514 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 515 | | } |
| 0 | 516 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 517 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 518 | | string _responseContent = null; |
| 0 | 519 | | if ((int)_statusCode != 200) |
| | 520 | | { |
| 0 | 521 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 522 | | try |
| | 523 | | { |
| 0 | 524 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 525 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 526 | | if (_errorBody != null) |
| | 527 | | { |
| 0 | 528 | | ex.Body = _errorBody; |
| | 529 | | } |
| 0 | 530 | | } |
| 0 | 531 | | catch (JsonException) |
| | 532 | | { |
| | 533 | | // Ignore the exception |
| 0 | 534 | | } |
| 0 | 535 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 536 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 537 | | if (_shouldTrace) |
| | 538 | | { |
| 0 | 539 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 540 | | } |
| 0 | 541 | | _httpRequest.Dispose(); |
| 0 | 542 | | if (_httpResponse != null) |
| | 543 | | { |
| 0 | 544 | | _httpResponse.Dispose(); |
| | 545 | | } |
| 0 | 546 | | throw ex; |
| | 547 | | } |
| | 548 | | // Create Result |
| 0 | 549 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| 0 | 550 | | _result.Request = _httpRequest; |
| 0 | 551 | | _result.Response = _httpResponse; |
| | 552 | | // Deserialize Response |
| 0 | 553 | | if ((int)_statusCode == 200) |
| | 554 | | { |
| 0 | 555 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 556 | | try |
| | 557 | | { |
| 0 | 558 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| 0 | 559 | | } |
| 0 | 560 | | catch (JsonException ex) |
| | 561 | | { |
| 0 | 562 | | _httpRequest.Dispose(); |
| 0 | 563 | | if (_httpResponse != null) |
| | 564 | | { |
| 0 | 565 | | _httpResponse.Dispose(); |
| | 566 | | } |
| 0 | 567 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 568 | | } |
| | 569 | | } |
| 0 | 570 | | if (_shouldTrace) |
| | 571 | | { |
| 0 | 572 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 573 | | } |
| 0 | 574 | | return _result; |
| 0 | 575 | | } |
| | 576 | |
|
| | 577 | | /// <summary> |
| | 578 | | /// user - Get LUIS Azure accounts |
| | 579 | | /// </summary> |
| | 580 | | /// <remarks> |
| | 581 | | /// Gets the LUIS Azure accounts for the user using his ARM token. |
| | 582 | | /// </remarks> |
| | 583 | | /// <param name='armToken'> |
| | 584 | | /// The custom arm token header to use; containing the user's ARM token used to |
| | 585 | | /// validate azure accounts information. |
| | 586 | | /// </param> |
| | 587 | | /// <param name='customHeaders'> |
| | 588 | | /// Headers that will be added to request. |
| | 589 | | /// </param> |
| | 590 | | /// <param name='cancellationToken'> |
| | 591 | | /// The cancellation token. |
| | 592 | | /// </param> |
| | 593 | | /// <exception cref="ErrorResponseException"> |
| | 594 | | /// Thrown when the operation returned an invalid status code |
| | 595 | | /// </exception> |
| | 596 | | /// <exception cref="SerializationException"> |
| | 597 | | /// Thrown when unable to deserialize the response |
| | 598 | | /// </exception> |
| | 599 | | /// <exception cref="ValidationException"> |
| | 600 | | /// Thrown when a required parameter is null |
| | 601 | | /// </exception> |
| | 602 | | /// <exception cref="System.ArgumentNullException"> |
| | 603 | | /// Thrown when a required parameter is null |
| | 604 | | /// </exception> |
| | 605 | | /// <return> |
| | 606 | | /// A response object containing the response body and response headers. |
| | 607 | | /// </return> |
| | 608 | | public async Task<HttpOperationResponse<IList<AzureAccountInfoObject>>> ListUserLUISAccountsWithHttpMessagesAsyn |
| | 609 | | { |
| 0 | 610 | | if (Client.Endpoint == null) |
| | 611 | | { |
| 0 | 612 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 613 | | } |
| | 614 | | // Tracing |
| 0 | 615 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 616 | | string _invocationId = null; |
| 0 | 617 | | if (_shouldTrace) |
| | 618 | | { |
| 0 | 619 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 620 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 621 | | tracingParameters.Add("armToken", armToken); |
| 0 | 622 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 623 | | ServiceClientTracing.Enter(_invocationId, this, "ListUserLUISAccounts", tracingParameters); |
| | 624 | | } |
| | 625 | | // Construct URL |
| 0 | 626 | | var _baseUrl = Client.BaseUri; |
| 0 | 627 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "azureaccounts"; |
| 0 | 628 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 629 | | // Create HTTP transport objects |
| 0 | 630 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 631 | | HttpResponseMessage _httpResponse = null; |
| 0 | 632 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 633 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 634 | | // Set Headers |
| 0 | 635 | | if (armToken != null) |
| | 636 | | { |
| 0 | 637 | | if (_httpRequest.Headers.Contains("ArmToken")) |
| | 638 | | { |
| 0 | 639 | | _httpRequest.Headers.Remove("ArmToken"); |
| | 640 | | } |
| 0 | 641 | | _httpRequest.Headers.TryAddWithoutValidation("ArmToken", armToken); |
| | 642 | | } |
| | 643 | |
|
| | 644 | |
|
| 0 | 645 | | if (customHeaders != null) |
| | 646 | | { |
| 0 | 647 | | foreach(var _header in customHeaders) |
| | 648 | | { |
| 0 | 649 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 650 | | { |
| 0 | 651 | | _httpRequest.Headers.Remove(_header.Key); |
| | 652 | | } |
| 0 | 653 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 654 | | } |
| | 655 | | } |
| | 656 | |
|
| | 657 | | // Serialize Request |
| 0 | 658 | | string _requestContent = null; |
| | 659 | | // Set Credentials |
| 0 | 660 | | if (Client.Credentials != null) |
| | 661 | | { |
| 0 | 662 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 663 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 664 | | } |
| | 665 | | // Send Request |
| 0 | 666 | | if (_shouldTrace) |
| | 667 | | { |
| 0 | 668 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 669 | | } |
| 0 | 670 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 671 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 672 | | if (_shouldTrace) |
| | 673 | | { |
| 0 | 674 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 675 | | } |
| 0 | 676 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 677 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 678 | | string _responseContent = null; |
| 0 | 679 | | if ((int)_statusCode != 200) |
| | 680 | | { |
| 0 | 681 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 682 | | try |
| | 683 | | { |
| 0 | 684 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 685 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 686 | | if (_errorBody != null) |
| | 687 | | { |
| 0 | 688 | | ex.Body = _errorBody; |
| | 689 | | } |
| 0 | 690 | | } |
| 0 | 691 | | catch (JsonException) |
| | 692 | | { |
| | 693 | | // Ignore the exception |
| 0 | 694 | | } |
| 0 | 695 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 696 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 697 | | if (_shouldTrace) |
| | 698 | | { |
| 0 | 699 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 700 | | } |
| 0 | 701 | | _httpRequest.Dispose(); |
| 0 | 702 | | if (_httpResponse != null) |
| | 703 | | { |
| 0 | 704 | | _httpResponse.Dispose(); |
| | 705 | | } |
| 0 | 706 | | throw ex; |
| | 707 | | } |
| | 708 | | // Create Result |
| 0 | 709 | | var _result = new HttpOperationResponse<IList<AzureAccountInfoObject>>(); |
| 0 | 710 | | _result.Request = _httpRequest; |
| 0 | 711 | | _result.Response = _httpResponse; |
| | 712 | | // Deserialize Response |
| 0 | 713 | | if ((int)_statusCode == 200) |
| | 714 | | { |
| 0 | 715 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 716 | | try |
| | 717 | | { |
| 0 | 718 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<AzureAccountInfoObject>>(_ |
| 0 | 719 | | } |
| 0 | 720 | | catch (JsonException ex) |
| | 721 | | { |
| 0 | 722 | | _httpRequest.Dispose(); |
| 0 | 723 | | if (_httpResponse != null) |
| | 724 | | { |
| 0 | 725 | | _httpResponse.Dispose(); |
| | 726 | | } |
| 0 | 727 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 728 | | } |
| | 729 | | } |
| 0 | 730 | | if (_shouldTrace) |
| | 731 | | { |
| 0 | 732 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 733 | | } |
| 0 | 734 | | return _result; |
| 0 | 735 | | } |
| | 736 | |
|
| | 737 | | } |
| | 738 | | } |