| | 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.Knowledge.QnAMaker |
| | 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 | | /// Knowledgebase operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class Knowledgebase : IServiceOperations<QnAMakerClient>, IKnowledgebase |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the Knowledgebase 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> |
| 0 | 39 | | public Knowledgebase(QnAMakerClient client) |
| | 40 | | { |
| 0 | 41 | | if (client == null) |
| | 42 | | { |
| 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | 44 | | } |
| 0 | 45 | | Client = client; |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Gets a reference to the QnAMakerClient |
| | 50 | | /// </summary> |
| 0 | 51 | | public QnAMakerClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Gets all knowledgebases for a user. |
| | 55 | | /// </summary> |
| | 56 | | /// <param name='customHeaders'> |
| | 57 | | /// Headers that will be added to request. |
| | 58 | | /// </param> |
| | 59 | | /// <param name='cancellationToken'> |
| | 60 | | /// The cancellation token. |
| | 61 | | /// </param> |
| | 62 | | /// <exception cref="ErrorResponseException"> |
| | 63 | | /// Thrown when the operation returned an invalid status code |
| | 64 | | /// </exception> |
| | 65 | | /// <exception cref="SerializationException"> |
| | 66 | | /// Thrown when unable to deserialize the response |
| | 67 | | /// </exception> |
| | 68 | | /// <exception cref="ValidationException"> |
| | 69 | | /// Thrown when a required parameter is null |
| | 70 | | /// </exception> |
| | 71 | | /// <exception cref="System.ArgumentNullException"> |
| | 72 | | /// Thrown when a required parameter is null |
| | 73 | | /// </exception> |
| | 74 | | /// <return> |
| | 75 | | /// A response object containing the response body and response headers. |
| | 76 | | /// </return> |
| | 77 | | public async Task<HttpOperationResponse<KnowledgebasesDTO>> ListAllWithHttpMessagesAsync(Dictionary<string, List |
| | 78 | | { |
| 0 | 79 | | if (Client.Endpoint == null) |
| | 80 | | { |
| 0 | 81 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 82 | | } |
| | 83 | | // Tracing |
| 0 | 84 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 85 | | string _invocationId = null; |
| 0 | 86 | | if (_shouldTrace) |
| | 87 | | { |
| 0 | 88 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 89 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 90 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 91 | | ServiceClientTracing.Enter(_invocationId, this, "ListAll", tracingParameters); |
| | 92 | | } |
| | 93 | | // Construct URL |
| 0 | 94 | | var _baseUrl = Client.BaseUri; |
| 0 | 95 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases"; |
| 0 | 96 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 97 | | // Create HTTP transport objects |
| 0 | 98 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 99 | | HttpResponseMessage _httpResponse = null; |
| 0 | 100 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 101 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 102 | | // Set Headers |
| | 103 | |
|
| | 104 | |
|
| 0 | 105 | | if (customHeaders != null) |
| | 106 | | { |
| 0 | 107 | | foreach(var _header in customHeaders) |
| | 108 | | { |
| 0 | 109 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 110 | | { |
| 0 | 111 | | _httpRequest.Headers.Remove(_header.Key); |
| | 112 | | } |
| 0 | 113 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 114 | | } |
| | 115 | | } |
| | 116 | |
|
| | 117 | | // Serialize Request |
| 0 | 118 | | string _requestContent = null; |
| | 119 | | // Set Credentials |
| 0 | 120 | | if (Client.Credentials != null) |
| | 121 | | { |
| 0 | 122 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 123 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 124 | | } |
| | 125 | | // Send Request |
| 0 | 126 | | if (_shouldTrace) |
| | 127 | | { |
| 0 | 128 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 129 | | } |
| 0 | 130 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 131 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 132 | | if (_shouldTrace) |
| | 133 | | { |
| 0 | 134 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 135 | | } |
| 0 | 136 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 137 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 138 | | string _responseContent = null; |
| 0 | 139 | | if ((int)_statusCode != 200) |
| | 140 | | { |
| 0 | 141 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 142 | | try |
| | 143 | | { |
| 0 | 144 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 145 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 146 | | if (_errorBody != null) |
| | 147 | | { |
| 0 | 148 | | ex.Body = _errorBody; |
| | 149 | | } |
| 0 | 150 | | } |
| 0 | 151 | | catch (JsonException) |
| | 152 | | { |
| | 153 | | // Ignore the exception |
| 0 | 154 | | } |
| 0 | 155 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 156 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 157 | | if (_shouldTrace) |
| | 158 | | { |
| 0 | 159 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 160 | | } |
| 0 | 161 | | _httpRequest.Dispose(); |
| 0 | 162 | | if (_httpResponse != null) |
| | 163 | | { |
| 0 | 164 | | _httpResponse.Dispose(); |
| | 165 | | } |
| 0 | 166 | | throw ex; |
| | 167 | | } |
| | 168 | | // Create Result |
| 0 | 169 | | var _result = new HttpOperationResponse<KnowledgebasesDTO>(); |
| 0 | 170 | | _result.Request = _httpRequest; |
| 0 | 171 | | _result.Response = _httpResponse; |
| | 172 | | // Deserialize Response |
| 0 | 173 | | if ((int)_statusCode == 200) |
| | 174 | | { |
| 0 | 175 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 176 | | try |
| | 177 | | { |
| 0 | 178 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<KnowledgebasesDTO>(_responseCont |
| 0 | 179 | | } |
| 0 | 180 | | catch (JsonException ex) |
| | 181 | | { |
| 0 | 182 | | _httpRequest.Dispose(); |
| 0 | 183 | | if (_httpResponse != null) |
| | 184 | | { |
| 0 | 185 | | _httpResponse.Dispose(); |
| | 186 | | } |
| 0 | 187 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 188 | | } |
| | 189 | | } |
| 0 | 190 | | if (_shouldTrace) |
| | 191 | | { |
| 0 | 192 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 193 | | } |
| 0 | 194 | | return _result; |
| 0 | 195 | | } |
| | 196 | |
|
| | 197 | | /// <summary> |
| | 198 | | /// Gets details of a specific knowledgebase. |
| | 199 | | /// </summary> |
| | 200 | | /// <param name='kbId'> |
| | 201 | | /// Knowledgebase id. |
| | 202 | | /// </param> |
| | 203 | | /// <param name='customHeaders'> |
| | 204 | | /// Headers that will be added to request. |
| | 205 | | /// </param> |
| | 206 | | /// <param name='cancellationToken'> |
| | 207 | | /// The cancellation token. |
| | 208 | | /// </param> |
| | 209 | | /// <exception cref="ErrorResponseException"> |
| | 210 | | /// Thrown when the operation returned an invalid status code |
| | 211 | | /// </exception> |
| | 212 | | /// <exception cref="SerializationException"> |
| | 213 | | /// Thrown when unable to deserialize the response |
| | 214 | | /// </exception> |
| | 215 | | /// <exception cref="ValidationException"> |
| | 216 | | /// Thrown when a required parameter is null |
| | 217 | | /// </exception> |
| | 218 | | /// <exception cref="System.ArgumentNullException"> |
| | 219 | | /// Thrown when a required parameter is null |
| | 220 | | /// </exception> |
| | 221 | | /// <return> |
| | 222 | | /// A response object containing the response body and response headers. |
| | 223 | | /// </return> |
| | 224 | | public async Task<HttpOperationResponse<KnowledgebaseDTO>> GetDetailsWithHttpMessagesAsync(string kbId, Dictiona |
| | 225 | | { |
| 0 | 226 | | if (Client.Endpoint == null) |
| | 227 | | { |
| 0 | 228 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 229 | | } |
| 0 | 230 | | if (kbId == null) |
| | 231 | | { |
| 0 | 232 | | throw new ValidationException(ValidationRules.CannotBeNull, "kbId"); |
| | 233 | | } |
| | 234 | | // Tracing |
| 0 | 235 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 236 | | string _invocationId = null; |
| 0 | 237 | | if (_shouldTrace) |
| | 238 | | { |
| 0 | 239 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 240 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 241 | | tracingParameters.Add("kbId", kbId); |
| 0 | 242 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 243 | | ServiceClientTracing.Enter(_invocationId, this, "GetDetails", tracingParameters); |
| | 244 | | } |
| | 245 | | // Construct URL |
| 0 | 246 | | var _baseUrl = Client.BaseUri; |
| 0 | 247 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}"; |
| 0 | 248 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 249 | | _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId)); |
| | 250 | | // Create HTTP transport objects |
| 0 | 251 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 252 | | HttpResponseMessage _httpResponse = null; |
| 0 | 253 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 254 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 255 | | // Set Headers |
| | 256 | |
|
| | 257 | |
|
| 0 | 258 | | if (customHeaders != null) |
| | 259 | | { |
| 0 | 260 | | foreach(var _header in customHeaders) |
| | 261 | | { |
| 0 | 262 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 263 | | { |
| 0 | 264 | | _httpRequest.Headers.Remove(_header.Key); |
| | 265 | | } |
| 0 | 266 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 267 | | } |
| | 268 | | } |
| | 269 | |
|
| | 270 | | // Serialize Request |
| 0 | 271 | | string _requestContent = null; |
| | 272 | | // Set Credentials |
| 0 | 273 | | if (Client.Credentials != null) |
| | 274 | | { |
| 0 | 275 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 276 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 277 | | } |
| | 278 | | // Send Request |
| 0 | 279 | | if (_shouldTrace) |
| | 280 | | { |
| 0 | 281 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 282 | | } |
| 0 | 283 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 284 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 285 | | if (_shouldTrace) |
| | 286 | | { |
| 0 | 287 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 288 | | } |
| 0 | 289 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 290 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 291 | | string _responseContent = null; |
| 0 | 292 | | if ((int)_statusCode != 200) |
| | 293 | | { |
| 0 | 294 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 295 | | try |
| | 296 | | { |
| 0 | 297 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 298 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 299 | | if (_errorBody != null) |
| | 300 | | { |
| 0 | 301 | | ex.Body = _errorBody; |
| | 302 | | } |
| 0 | 303 | | } |
| 0 | 304 | | catch (JsonException) |
| | 305 | | { |
| | 306 | | // Ignore the exception |
| 0 | 307 | | } |
| 0 | 308 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 309 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 310 | | if (_shouldTrace) |
| | 311 | | { |
| 0 | 312 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 313 | | } |
| 0 | 314 | | _httpRequest.Dispose(); |
| 0 | 315 | | if (_httpResponse != null) |
| | 316 | | { |
| 0 | 317 | | _httpResponse.Dispose(); |
| | 318 | | } |
| 0 | 319 | | throw ex; |
| | 320 | | } |
| | 321 | | // Create Result |
| 0 | 322 | | var _result = new HttpOperationResponse<KnowledgebaseDTO>(); |
| 0 | 323 | | _result.Request = _httpRequest; |
| 0 | 324 | | _result.Response = _httpResponse; |
| | 325 | | // Deserialize Response |
| 0 | 326 | | if ((int)_statusCode == 200) |
| | 327 | | { |
| 0 | 328 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 329 | | try |
| | 330 | | { |
| 0 | 331 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<KnowledgebaseDTO>(_responseConte |
| 0 | 332 | | } |
| 0 | 333 | | catch (JsonException ex) |
| | 334 | | { |
| 0 | 335 | | _httpRequest.Dispose(); |
| 0 | 336 | | if (_httpResponse != null) |
| | 337 | | { |
| 0 | 338 | | _httpResponse.Dispose(); |
| | 339 | | } |
| 0 | 340 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 341 | | } |
| | 342 | | } |
| 0 | 343 | | if (_shouldTrace) |
| | 344 | | { |
| 0 | 345 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 346 | | } |
| 0 | 347 | | return _result; |
| 0 | 348 | | } |
| | 349 | |
|
| | 350 | | /// <summary> |
| | 351 | | /// Deletes the knowledgebase and all its data. |
| | 352 | | /// </summary> |
| | 353 | | /// <param name='kbId'> |
| | 354 | | /// Knowledgebase id. |
| | 355 | | /// </param> |
| | 356 | | /// <param name='customHeaders'> |
| | 357 | | /// Headers that will be added to request. |
| | 358 | | /// </param> |
| | 359 | | /// <param name='cancellationToken'> |
| | 360 | | /// The cancellation token. |
| | 361 | | /// </param> |
| | 362 | | /// <exception cref="ErrorResponseException"> |
| | 363 | | /// Thrown when the operation returned an invalid status code |
| | 364 | | /// </exception> |
| | 365 | | /// <exception cref="ValidationException"> |
| | 366 | | /// Thrown when a required parameter is null |
| | 367 | | /// </exception> |
| | 368 | | /// <exception cref="System.ArgumentNullException"> |
| | 369 | | /// Thrown when a required parameter is null |
| | 370 | | /// </exception> |
| | 371 | | /// <return> |
| | 372 | | /// A response object containing the response body and response headers. |
| | 373 | | /// </return> |
| | 374 | | public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(string kbId, Dictionary<string, List<string |
| | 375 | | { |
| 0 | 376 | | if (Client.Endpoint == null) |
| | 377 | | { |
| 0 | 378 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 379 | | } |
| 0 | 380 | | if (kbId == null) |
| | 381 | | { |
| 0 | 382 | | throw new ValidationException(ValidationRules.CannotBeNull, "kbId"); |
| | 383 | | } |
| | 384 | | // Tracing |
| 0 | 385 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 386 | | string _invocationId = null; |
| 0 | 387 | | if (_shouldTrace) |
| | 388 | | { |
| 0 | 389 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 390 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 391 | | tracingParameters.Add("kbId", kbId); |
| 0 | 392 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 393 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 394 | | } |
| | 395 | | // Construct URL |
| 0 | 396 | | var _baseUrl = Client.BaseUri; |
| 0 | 397 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}"; |
| 0 | 398 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 399 | | _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId)); |
| | 400 | | // Create HTTP transport objects |
| 0 | 401 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 402 | | HttpResponseMessage _httpResponse = null; |
| 0 | 403 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 404 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 405 | | // Set Headers |
| | 406 | |
|
| | 407 | |
|
| 0 | 408 | | if (customHeaders != null) |
| | 409 | | { |
| 0 | 410 | | foreach(var _header in customHeaders) |
| | 411 | | { |
| 0 | 412 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 413 | | { |
| 0 | 414 | | _httpRequest.Headers.Remove(_header.Key); |
| | 415 | | } |
| 0 | 416 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 417 | | } |
| | 418 | | } |
| | 419 | |
|
| | 420 | | // Serialize Request |
| 0 | 421 | | string _requestContent = null; |
| | 422 | | // Set Credentials |
| 0 | 423 | | if (Client.Credentials != null) |
| | 424 | | { |
| 0 | 425 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 426 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 427 | | } |
| | 428 | | // Send Request |
| 0 | 429 | | if (_shouldTrace) |
| | 430 | | { |
| 0 | 431 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 432 | | } |
| 0 | 433 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 434 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 435 | | if (_shouldTrace) |
| | 436 | | { |
| 0 | 437 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 438 | | } |
| 0 | 439 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 440 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 441 | | string _responseContent = null; |
| 0 | 442 | | if ((int)_statusCode != 204) |
| | 443 | | { |
| 0 | 444 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 445 | | try |
| | 446 | | { |
| 0 | 447 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 448 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 449 | | if (_errorBody != null) |
| | 450 | | { |
| 0 | 451 | | ex.Body = _errorBody; |
| | 452 | | } |
| 0 | 453 | | } |
| 0 | 454 | | catch (JsonException) |
| | 455 | | { |
| | 456 | | // Ignore the exception |
| 0 | 457 | | } |
| 0 | 458 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 459 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 460 | | if (_shouldTrace) |
| | 461 | | { |
| 0 | 462 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 463 | | } |
| 0 | 464 | | _httpRequest.Dispose(); |
| 0 | 465 | | if (_httpResponse != null) |
| | 466 | | { |
| 0 | 467 | | _httpResponse.Dispose(); |
| | 468 | | } |
| 0 | 469 | | throw ex; |
| | 470 | | } |
| | 471 | | // Create Result |
| 0 | 472 | | var _result = new HttpOperationResponse(); |
| 0 | 473 | | _result.Request = _httpRequest; |
| 0 | 474 | | _result.Response = _httpResponse; |
| 0 | 475 | | if (_shouldTrace) |
| | 476 | | { |
| 0 | 477 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 478 | | } |
| 0 | 479 | | return _result; |
| 0 | 480 | | } |
| | 481 | |
|
| | 482 | | /// <summary> |
| | 483 | | /// Publishes all changes in test index of a knowledgebase to its prod index. |
| | 484 | | /// </summary> |
| | 485 | | /// <param name='kbId'> |
| | 486 | | /// Knowledgebase id. |
| | 487 | | /// </param> |
| | 488 | | /// <param name='customHeaders'> |
| | 489 | | /// Headers that will be added to request. |
| | 490 | | /// </param> |
| | 491 | | /// <param name='cancellationToken'> |
| | 492 | | /// The cancellation token. |
| | 493 | | /// </param> |
| | 494 | | /// <exception cref="ErrorResponseException"> |
| | 495 | | /// Thrown when the operation returned an invalid status code |
| | 496 | | /// </exception> |
| | 497 | | /// <exception cref="ValidationException"> |
| | 498 | | /// Thrown when a required parameter is null |
| | 499 | | /// </exception> |
| | 500 | | /// <exception cref="System.ArgumentNullException"> |
| | 501 | | /// Thrown when a required parameter is null |
| | 502 | | /// </exception> |
| | 503 | | /// <return> |
| | 504 | | /// A response object containing the response body and response headers. |
| | 505 | | /// </return> |
| | 506 | | public async Task<HttpOperationResponse> PublishWithHttpMessagesAsync(string kbId, Dictionary<string, List<strin |
| | 507 | | { |
| 0 | 508 | | if (Client.Endpoint == null) |
| | 509 | | { |
| 0 | 510 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 511 | | } |
| 0 | 512 | | if (kbId == null) |
| | 513 | | { |
| 0 | 514 | | throw new ValidationException(ValidationRules.CannotBeNull, "kbId"); |
| | 515 | | } |
| | 516 | | // Tracing |
| 0 | 517 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 518 | | string _invocationId = null; |
| 0 | 519 | | if (_shouldTrace) |
| | 520 | | { |
| 0 | 521 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 522 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 523 | | tracingParameters.Add("kbId", kbId); |
| 0 | 524 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 525 | | ServiceClientTracing.Enter(_invocationId, this, "Publish", tracingParameters); |
| | 526 | | } |
| | 527 | | // Construct URL |
| 0 | 528 | | var _baseUrl = Client.BaseUri; |
| 0 | 529 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}"; |
| 0 | 530 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 531 | | _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId)); |
| | 532 | | // Create HTTP transport objects |
| 0 | 533 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 534 | | HttpResponseMessage _httpResponse = null; |
| 0 | 535 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 536 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 537 | | // Set Headers |
| | 538 | |
|
| | 539 | |
|
| 0 | 540 | | if (customHeaders != null) |
| | 541 | | { |
| 0 | 542 | | foreach(var _header in customHeaders) |
| | 543 | | { |
| 0 | 544 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 545 | | { |
| 0 | 546 | | _httpRequest.Headers.Remove(_header.Key); |
| | 547 | | } |
| 0 | 548 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 549 | | } |
| | 550 | | } |
| | 551 | |
|
| | 552 | | // Serialize Request |
| 0 | 553 | | string _requestContent = null; |
| | 554 | | // Set Credentials |
| 0 | 555 | | if (Client.Credentials != null) |
| | 556 | | { |
| 0 | 557 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 558 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 559 | | } |
| | 560 | | // Send Request |
| 0 | 561 | | if (_shouldTrace) |
| | 562 | | { |
| 0 | 563 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 564 | | } |
| 0 | 565 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 566 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 567 | | if (_shouldTrace) |
| | 568 | | { |
| 0 | 569 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 570 | | } |
| 0 | 571 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 572 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 573 | | string _responseContent = null; |
| 0 | 574 | | if ((int)_statusCode != 204) |
| | 575 | | { |
| 0 | 576 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 577 | | try |
| | 578 | | { |
| 0 | 579 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 580 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 581 | | if (_errorBody != null) |
| | 582 | | { |
| 0 | 583 | | ex.Body = _errorBody; |
| | 584 | | } |
| 0 | 585 | | } |
| 0 | 586 | | catch (JsonException) |
| | 587 | | { |
| | 588 | | // Ignore the exception |
| 0 | 589 | | } |
| 0 | 590 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 591 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 592 | | if (_shouldTrace) |
| | 593 | | { |
| 0 | 594 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 595 | | } |
| 0 | 596 | | _httpRequest.Dispose(); |
| 0 | 597 | | if (_httpResponse != null) |
| | 598 | | { |
| 0 | 599 | | _httpResponse.Dispose(); |
| | 600 | | } |
| 0 | 601 | | throw ex; |
| | 602 | | } |
| | 603 | | // Create Result |
| 0 | 604 | | var _result = new HttpOperationResponse(); |
| 0 | 605 | | _result.Request = _httpRequest; |
| 0 | 606 | | _result.Response = _httpResponse; |
| 0 | 607 | | if (_shouldTrace) |
| | 608 | | { |
| 0 | 609 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 610 | | } |
| 0 | 611 | | return _result; |
| 0 | 612 | | } |
| | 613 | |
|
| | 614 | | /// <summary> |
| | 615 | | /// Replace knowledgebase contents. |
| | 616 | | /// </summary> |
| | 617 | | /// <param name='kbId'> |
| | 618 | | /// Knowledgebase id. |
| | 619 | | /// </param> |
| | 620 | | /// <param name='replaceKb'> |
| | 621 | | /// An instance of ReplaceKbDTO which contains list of qnas to be uploaded |
| | 622 | | /// </param> |
| | 623 | | /// <param name='customHeaders'> |
| | 624 | | /// Headers that will be added to request. |
| | 625 | | /// </param> |
| | 626 | | /// <param name='cancellationToken'> |
| | 627 | | /// The cancellation token. |
| | 628 | | /// </param> |
| | 629 | | /// <exception cref="ErrorResponseException"> |
| | 630 | | /// Thrown when the operation returned an invalid status code |
| | 631 | | /// </exception> |
| | 632 | | /// <exception cref="ValidationException"> |
| | 633 | | /// Thrown when a required parameter is null |
| | 634 | | /// </exception> |
| | 635 | | /// <exception cref="System.ArgumentNullException"> |
| | 636 | | /// Thrown when a required parameter is null |
| | 637 | | /// </exception> |
| | 638 | | /// <return> |
| | 639 | | /// A response object containing the response body and response headers. |
| | 640 | | /// </return> |
| | 641 | | public async Task<HttpOperationResponse> ReplaceWithHttpMessagesAsync(string kbId, ReplaceKbDTO replaceKb, Dicti |
| | 642 | | { |
| 0 | 643 | | if (Client.Endpoint == null) |
| | 644 | | { |
| 0 | 645 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 646 | | } |
| 0 | 647 | | if (kbId == null) |
| | 648 | | { |
| 0 | 649 | | throw new ValidationException(ValidationRules.CannotBeNull, "kbId"); |
| | 650 | | } |
| 0 | 651 | | if (replaceKb == null) |
| | 652 | | { |
| 0 | 653 | | throw new ValidationException(ValidationRules.CannotBeNull, "replaceKb"); |
| | 654 | | } |
| 0 | 655 | | if (replaceKb != null) |
| | 656 | | { |
| 0 | 657 | | replaceKb.Validate(); |
| | 658 | | } |
| | 659 | | // Tracing |
| 0 | 660 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 661 | | string _invocationId = null; |
| 0 | 662 | | if (_shouldTrace) |
| | 663 | | { |
| 0 | 664 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 665 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 666 | | tracingParameters.Add("kbId", kbId); |
| 0 | 667 | | tracingParameters.Add("replaceKb", replaceKb); |
| 0 | 668 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 669 | | ServiceClientTracing.Enter(_invocationId, this, "Replace", tracingParameters); |
| | 670 | | } |
| | 671 | | // Construct URL |
| 0 | 672 | | var _baseUrl = Client.BaseUri; |
| 0 | 673 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}"; |
| 0 | 674 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 675 | | _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId)); |
| | 676 | | // Create HTTP transport objects |
| 0 | 677 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 678 | | HttpResponseMessage _httpResponse = null; |
| 0 | 679 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 0 | 680 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 681 | | // Set Headers |
| | 682 | |
|
| | 683 | |
|
| 0 | 684 | | if (customHeaders != null) |
| | 685 | | { |
| 0 | 686 | | foreach(var _header in customHeaders) |
| | 687 | | { |
| 0 | 688 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 689 | | { |
| 0 | 690 | | _httpRequest.Headers.Remove(_header.Key); |
| | 691 | | } |
| 0 | 692 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 693 | | } |
| | 694 | | } |
| | 695 | |
|
| | 696 | | // Serialize Request |
| 0 | 697 | | string _requestContent = null; |
| 0 | 698 | | if(replaceKb != null) |
| | 699 | | { |
| 0 | 700 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(replaceKb, Client.SerializationSett |
| 0 | 701 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 702 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 703 | | } |
| | 704 | | // Set Credentials |
| 0 | 705 | | if (Client.Credentials != null) |
| | 706 | | { |
| 0 | 707 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 708 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 709 | | } |
| | 710 | | // Send Request |
| 0 | 711 | | if (_shouldTrace) |
| | 712 | | { |
| 0 | 713 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 714 | | } |
| 0 | 715 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 716 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 717 | | if (_shouldTrace) |
| | 718 | | { |
| 0 | 719 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 720 | | } |
| 0 | 721 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 722 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 723 | | string _responseContent = null; |
| 0 | 724 | | if ((int)_statusCode != 204) |
| | 725 | | { |
| 0 | 726 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 727 | | try |
| | 728 | | { |
| 0 | 729 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 730 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 731 | | if (_errorBody != null) |
| | 732 | | { |
| 0 | 733 | | ex.Body = _errorBody; |
| | 734 | | } |
| 0 | 735 | | } |
| 0 | 736 | | catch (JsonException) |
| | 737 | | { |
| | 738 | | // Ignore the exception |
| 0 | 739 | | } |
| 0 | 740 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 741 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 742 | | if (_shouldTrace) |
| | 743 | | { |
| 0 | 744 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 745 | | } |
| 0 | 746 | | _httpRequest.Dispose(); |
| 0 | 747 | | if (_httpResponse != null) |
| | 748 | | { |
| 0 | 749 | | _httpResponse.Dispose(); |
| | 750 | | } |
| 0 | 751 | | throw ex; |
| | 752 | | } |
| | 753 | | // Create Result |
| 0 | 754 | | var _result = new HttpOperationResponse(); |
| 0 | 755 | | _result.Request = _httpRequest; |
| 0 | 756 | | _result.Response = _httpResponse; |
| 0 | 757 | | if (_shouldTrace) |
| | 758 | | { |
| 0 | 759 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 760 | | } |
| 0 | 761 | | return _result; |
| 0 | 762 | | } |
| | 763 | |
|
| | 764 | | /// <summary> |
| | 765 | | /// Asynchronous operation to modify a knowledgebase. |
| | 766 | | /// </summary> |
| | 767 | | /// <param name='kbId'> |
| | 768 | | /// Knowledgebase id. |
| | 769 | | /// </param> |
| | 770 | | /// <param name='updateKb'> |
| | 771 | | /// Post body of the request. |
| | 772 | | /// </param> |
| | 773 | | /// <param name='customHeaders'> |
| | 774 | | /// Headers that will be added to request. |
| | 775 | | /// </param> |
| | 776 | | /// <param name='cancellationToken'> |
| | 777 | | /// The cancellation token. |
| | 778 | | /// </param> |
| | 779 | | /// <exception cref="ErrorResponseException"> |
| | 780 | | /// Thrown when the operation returned an invalid status code |
| | 781 | | /// </exception> |
| | 782 | | /// <exception cref="SerializationException"> |
| | 783 | | /// Thrown when unable to deserialize the response |
| | 784 | | /// </exception> |
| | 785 | | /// <exception cref="ValidationException"> |
| | 786 | | /// Thrown when a required parameter is null |
| | 787 | | /// </exception> |
| | 788 | | /// <exception cref="System.ArgumentNullException"> |
| | 789 | | /// Thrown when a required parameter is null |
| | 790 | | /// </exception> |
| | 791 | | /// <return> |
| | 792 | | /// A response object containing the response body and response headers. |
| | 793 | | /// </return> |
| | 794 | | public async Task<HttpOperationResponse<Operation,KnowledgebaseUpdateHeaders>> UpdateWithHttpMessagesAsync(strin |
| | 795 | | { |
| 0 | 796 | | if (Client.Endpoint == null) |
| | 797 | | { |
| 0 | 798 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 799 | | } |
| 0 | 800 | | if (kbId == null) |
| | 801 | | { |
| 0 | 802 | | throw new ValidationException(ValidationRules.CannotBeNull, "kbId"); |
| | 803 | | } |
| 0 | 804 | | if (updateKb == null) |
| | 805 | | { |
| 0 | 806 | | throw new ValidationException(ValidationRules.CannotBeNull, "updateKb"); |
| | 807 | | } |
| | 808 | | // Tracing |
| 0 | 809 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 810 | | string _invocationId = null; |
| 0 | 811 | | if (_shouldTrace) |
| | 812 | | { |
| 0 | 813 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 814 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 815 | | tracingParameters.Add("kbId", kbId); |
| 0 | 816 | | tracingParameters.Add("updateKb", updateKb); |
| 0 | 817 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 818 | | ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); |
| | 819 | | } |
| | 820 | | // Construct URL |
| 0 | 821 | | var _baseUrl = Client.BaseUri; |
| 0 | 822 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}"; |
| 0 | 823 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 824 | | _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId)); |
| | 825 | | // Create HTTP transport objects |
| 0 | 826 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 827 | | HttpResponseMessage _httpResponse = null; |
| 0 | 828 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 829 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 830 | | // Set Headers |
| | 831 | |
|
| | 832 | |
|
| 0 | 833 | | if (customHeaders != null) |
| | 834 | | { |
| 0 | 835 | | foreach(var _header in customHeaders) |
| | 836 | | { |
| 0 | 837 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 838 | | { |
| 0 | 839 | | _httpRequest.Headers.Remove(_header.Key); |
| | 840 | | } |
| 0 | 841 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 842 | | } |
| | 843 | | } |
| | 844 | |
|
| | 845 | | // Serialize Request |
| 0 | 846 | | string _requestContent = null; |
| 0 | 847 | | if(updateKb != null) |
| | 848 | | { |
| 0 | 849 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(updateKb, Client.SerializationSetti |
| 0 | 850 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 851 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 852 | | } |
| | 853 | | // Set Credentials |
| 0 | 854 | | if (Client.Credentials != null) |
| | 855 | | { |
| 0 | 856 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 857 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 858 | | } |
| | 859 | | // Send Request |
| 0 | 860 | | if (_shouldTrace) |
| | 861 | | { |
| 0 | 862 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 863 | | } |
| 0 | 864 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 865 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 866 | | if (_shouldTrace) |
| | 867 | | { |
| 0 | 868 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 869 | | } |
| 0 | 870 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 871 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 872 | | string _responseContent = null; |
| 0 | 873 | | if ((int)_statusCode != 202) |
| | 874 | | { |
| 0 | 875 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 876 | | try |
| | 877 | | { |
| 0 | 878 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 879 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 880 | | if (_errorBody != null) |
| | 881 | | { |
| 0 | 882 | | ex.Body = _errorBody; |
| | 883 | | } |
| 0 | 884 | | } |
| 0 | 885 | | catch (JsonException) |
| | 886 | | { |
| | 887 | | // Ignore the exception |
| 0 | 888 | | } |
| 0 | 889 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 890 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 891 | | if (_shouldTrace) |
| | 892 | | { |
| 0 | 893 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 894 | | } |
| 0 | 895 | | _httpRequest.Dispose(); |
| 0 | 896 | | if (_httpResponse != null) |
| | 897 | | { |
| 0 | 898 | | _httpResponse.Dispose(); |
| | 899 | | } |
| 0 | 900 | | throw ex; |
| | 901 | | } |
| | 902 | | // Create Result |
| 0 | 903 | | var _result = new HttpOperationResponse<Operation,KnowledgebaseUpdateHeaders>(); |
| 0 | 904 | | _result.Request = _httpRequest; |
| 0 | 905 | | _result.Response = _httpResponse; |
| | 906 | | // Deserialize Response |
| 0 | 907 | | if ((int)_statusCode == 202) |
| | 908 | | { |
| 0 | 909 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 910 | | try |
| | 911 | | { |
| 0 | 912 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Operation>(_responseContent, Cli |
| 0 | 913 | | } |
| 0 | 914 | | catch (JsonException ex) |
| | 915 | | { |
| 0 | 916 | | _httpRequest.Dispose(); |
| 0 | 917 | | if (_httpResponse != null) |
| | 918 | | { |
| 0 | 919 | | _httpResponse.Dispose(); |
| | 920 | | } |
| 0 | 921 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 922 | | } |
| | 923 | | } |
| | 924 | | try |
| | 925 | | { |
| 0 | 926 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<KnowledgebaseUpdateHeaders>(JsonSerializer.C |
| 0 | 927 | | } |
| 0 | 928 | | catch (JsonException ex) |
| | 929 | | { |
| 0 | 930 | | _httpRequest.Dispose(); |
| 0 | 931 | | if (_httpResponse != null) |
| | 932 | | { |
| 0 | 933 | | _httpResponse.Dispose(); |
| | 934 | | } |
| 0 | 935 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 936 | | } |
| 0 | 937 | | if (_shouldTrace) |
| | 938 | | { |
| 0 | 939 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 940 | | } |
| 0 | 941 | | return _result; |
| 0 | 942 | | } |
| | 943 | |
|
| | 944 | | /// <summary> |
| | 945 | | /// Asynchronous operation to create a new knowledgebase. |
| | 946 | | /// </summary> |
| | 947 | | /// <param name='createKbPayload'> |
| | 948 | | /// Post body of the request. |
| | 949 | | /// </param> |
| | 950 | | /// <param name='customHeaders'> |
| | 951 | | /// Headers that will be added to request. |
| | 952 | | /// </param> |
| | 953 | | /// <param name='cancellationToken'> |
| | 954 | | /// The cancellation token. |
| | 955 | | /// </param> |
| | 956 | | /// <exception cref="ErrorResponseException"> |
| | 957 | | /// Thrown when the operation returned an invalid status code |
| | 958 | | /// </exception> |
| | 959 | | /// <exception cref="SerializationException"> |
| | 960 | | /// Thrown when unable to deserialize the response |
| | 961 | | /// </exception> |
| | 962 | | /// <exception cref="ValidationException"> |
| | 963 | | /// Thrown when a required parameter is null |
| | 964 | | /// </exception> |
| | 965 | | /// <exception cref="System.ArgumentNullException"> |
| | 966 | | /// Thrown when a required parameter is null |
| | 967 | | /// </exception> |
| | 968 | | /// <return> |
| | 969 | | /// A response object containing the response body and response headers. |
| | 970 | | /// </return> |
| | 971 | | public async Task<HttpOperationResponse<Operation>> CreateWithHttpMessagesAsync(CreateKbDTO createKbPayload, Dic |
| | 972 | | { |
| 0 | 973 | | if (Client.Endpoint == null) |
| | 974 | | { |
| 0 | 975 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 976 | | } |
| 0 | 977 | | if (createKbPayload == null) |
| | 978 | | { |
| 0 | 979 | | throw new ValidationException(ValidationRules.CannotBeNull, "createKbPayload"); |
| | 980 | | } |
| 0 | 981 | | if (createKbPayload != null) |
| | 982 | | { |
| 0 | 983 | | createKbPayload.Validate(); |
| | 984 | | } |
| | 985 | | // Tracing |
| 0 | 986 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 987 | | string _invocationId = null; |
| 0 | 988 | | if (_shouldTrace) |
| | 989 | | { |
| 0 | 990 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 991 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 992 | | tracingParameters.Add("createKbPayload", createKbPayload); |
| 0 | 993 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 994 | | ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters); |
| | 995 | | } |
| | 996 | | // Construct URL |
| 0 | 997 | | var _baseUrl = Client.BaseUri; |
| 0 | 998 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/create"; |
| 0 | 999 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 1000 | | // Create HTTP transport objects |
| 0 | 1001 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1002 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1003 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1004 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1005 | | // Set Headers |
| | 1006 | |
|
| | 1007 | |
|
| 0 | 1008 | | if (customHeaders != null) |
| | 1009 | | { |
| 0 | 1010 | | foreach(var _header in customHeaders) |
| | 1011 | | { |
| 0 | 1012 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1013 | | { |
| 0 | 1014 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1015 | | } |
| 0 | 1016 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1017 | | } |
| | 1018 | | } |
| | 1019 | |
|
| | 1020 | | // Serialize Request |
| 0 | 1021 | | string _requestContent = null; |
| 0 | 1022 | | if(createKbPayload != null) |
| | 1023 | | { |
| 0 | 1024 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(createKbPayload, Client.Serializati |
| 0 | 1025 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1026 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1027 | | } |
| | 1028 | | // Set Credentials |
| 0 | 1029 | | if (Client.Credentials != null) |
| | 1030 | | { |
| 0 | 1031 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1032 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1033 | | } |
| | 1034 | | // Send Request |
| 0 | 1035 | | if (_shouldTrace) |
| | 1036 | | { |
| 0 | 1037 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1038 | | } |
| 0 | 1039 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1040 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1041 | | if (_shouldTrace) |
| | 1042 | | { |
| 0 | 1043 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1044 | | } |
| 0 | 1045 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1046 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1047 | | string _responseContent = null; |
| 0 | 1048 | | if ((int)_statusCode != 202) |
| | 1049 | | { |
| 0 | 1050 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1051 | | try |
| | 1052 | | { |
| 0 | 1053 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1054 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1055 | | if (_errorBody != null) |
| | 1056 | | { |
| 0 | 1057 | | ex.Body = _errorBody; |
| | 1058 | | } |
| 0 | 1059 | | } |
| 0 | 1060 | | catch (JsonException) |
| | 1061 | | { |
| | 1062 | | // Ignore the exception |
| 0 | 1063 | | } |
| 0 | 1064 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1065 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1066 | | if (_shouldTrace) |
| | 1067 | | { |
| 0 | 1068 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1069 | | } |
| 0 | 1070 | | _httpRequest.Dispose(); |
| 0 | 1071 | | if (_httpResponse != null) |
| | 1072 | | { |
| 0 | 1073 | | _httpResponse.Dispose(); |
| | 1074 | | } |
| 0 | 1075 | | throw ex; |
| | 1076 | | } |
| | 1077 | | // Create Result |
| 0 | 1078 | | var _result = new HttpOperationResponse<Operation>(); |
| 0 | 1079 | | _result.Request = _httpRequest; |
| 0 | 1080 | | _result.Response = _httpResponse; |
| | 1081 | | // Deserialize Response |
| 0 | 1082 | | if ((int)_statusCode == 202) |
| | 1083 | | { |
| 0 | 1084 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1085 | | try |
| | 1086 | | { |
| 0 | 1087 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Operation>(_responseContent, Cli |
| 0 | 1088 | | } |
| 0 | 1089 | | catch (JsonException ex) |
| | 1090 | | { |
| 0 | 1091 | | _httpRequest.Dispose(); |
| 0 | 1092 | | if (_httpResponse != null) |
| | 1093 | | { |
| 0 | 1094 | | _httpResponse.Dispose(); |
| | 1095 | | } |
| 0 | 1096 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1097 | | } |
| | 1098 | | } |
| 0 | 1099 | | if (_shouldTrace) |
| | 1100 | | { |
| 0 | 1101 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1102 | | } |
| 0 | 1103 | | return _result; |
| 0 | 1104 | | } |
| | 1105 | |
|
| | 1106 | | /// <summary> |
| | 1107 | | /// Download the knowledgebase. |
| | 1108 | | /// </summary> |
| | 1109 | | /// <param name='kbId'> |
| | 1110 | | /// Knowledgebase id. |
| | 1111 | | /// </param> |
| | 1112 | | /// <param name='environment'> |
| | 1113 | | /// Specifies whether environment is Test or Prod. Possible values include: |
| | 1114 | | /// 'Prod', 'Test' |
| | 1115 | | /// </param> |
| | 1116 | | /// <param name='customHeaders'> |
| | 1117 | | /// Headers that will be added to request. |
| | 1118 | | /// </param> |
| | 1119 | | /// <param name='cancellationToken'> |
| | 1120 | | /// The cancellation token. |
| | 1121 | | /// </param> |
| | 1122 | | /// <exception cref="ErrorResponseException"> |
| | 1123 | | /// Thrown when the operation returned an invalid status code |
| | 1124 | | /// </exception> |
| | 1125 | | /// <exception cref="SerializationException"> |
| | 1126 | | /// Thrown when unable to deserialize the response |
| | 1127 | | /// </exception> |
| | 1128 | | /// <exception cref="ValidationException"> |
| | 1129 | | /// Thrown when a required parameter is null |
| | 1130 | | /// </exception> |
| | 1131 | | /// <exception cref="System.ArgumentNullException"> |
| | 1132 | | /// Thrown when a required parameter is null |
| | 1133 | | /// </exception> |
| | 1134 | | /// <return> |
| | 1135 | | /// A response object containing the response body and response headers. |
| | 1136 | | /// </return> |
| | 1137 | | public async Task<HttpOperationResponse<QnADocumentsDTO>> DownloadWithHttpMessagesAsync(string kbId, string envi |
| | 1138 | | { |
| 0 | 1139 | | if (Client.Endpoint == null) |
| | 1140 | | { |
| 0 | 1141 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1142 | | } |
| 0 | 1143 | | if (kbId == null) |
| | 1144 | | { |
| 0 | 1145 | | throw new ValidationException(ValidationRules.CannotBeNull, "kbId"); |
| | 1146 | | } |
| 0 | 1147 | | if (environment == null) |
| | 1148 | | { |
| 0 | 1149 | | throw new ValidationException(ValidationRules.CannotBeNull, "environment"); |
| | 1150 | | } |
| | 1151 | | // Tracing |
| 0 | 1152 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1153 | | string _invocationId = null; |
| 0 | 1154 | | if (_shouldTrace) |
| | 1155 | | { |
| 0 | 1156 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1157 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1158 | | tracingParameters.Add("kbId", kbId); |
| 0 | 1159 | | tracingParameters.Add("environment", environment); |
| 0 | 1160 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1161 | | ServiceClientTracing.Enter(_invocationId, this, "Download", tracingParameters); |
| | 1162 | | } |
| | 1163 | | // Construct URL |
| 0 | 1164 | | var _baseUrl = Client.BaseUri; |
| 0 | 1165 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}/{environment}/qna"; |
| 0 | 1166 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1167 | | _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId)); |
| 0 | 1168 | | _url = _url.Replace("{environment}", System.Uri.EscapeDataString(environment)); |
| | 1169 | | // Create HTTP transport objects |
| 0 | 1170 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1171 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1172 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1173 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1174 | | // Set Headers |
| | 1175 | |
|
| | 1176 | |
|
| 0 | 1177 | | if (customHeaders != null) |
| | 1178 | | { |
| 0 | 1179 | | foreach(var _header in customHeaders) |
| | 1180 | | { |
| 0 | 1181 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1182 | | { |
| 0 | 1183 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1184 | | } |
| 0 | 1185 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1186 | | } |
| | 1187 | | } |
| | 1188 | |
|
| | 1189 | | // Serialize Request |
| 0 | 1190 | | string _requestContent = null; |
| | 1191 | | // Set Credentials |
| 0 | 1192 | | if (Client.Credentials != null) |
| | 1193 | | { |
| 0 | 1194 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1195 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1196 | | } |
| | 1197 | | // Send Request |
| 0 | 1198 | | if (_shouldTrace) |
| | 1199 | | { |
| 0 | 1200 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1201 | | } |
| 0 | 1202 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1203 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1204 | | if (_shouldTrace) |
| | 1205 | | { |
| 0 | 1206 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1207 | | } |
| 0 | 1208 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1209 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1210 | | string _responseContent = null; |
| 0 | 1211 | | if ((int)_statusCode != 200) |
| | 1212 | | { |
| 0 | 1213 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 1214 | | try |
| | 1215 | | { |
| 0 | 1216 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1217 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 1218 | | if (_errorBody != null) |
| | 1219 | | { |
| 0 | 1220 | | ex.Body = _errorBody; |
| | 1221 | | } |
| 0 | 1222 | | } |
| 0 | 1223 | | catch (JsonException) |
| | 1224 | | { |
| | 1225 | | // Ignore the exception |
| 0 | 1226 | | } |
| 0 | 1227 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1228 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1229 | | if (_shouldTrace) |
| | 1230 | | { |
| 0 | 1231 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1232 | | } |
| 0 | 1233 | | _httpRequest.Dispose(); |
| 0 | 1234 | | if (_httpResponse != null) |
| | 1235 | | { |
| 0 | 1236 | | _httpResponse.Dispose(); |
| | 1237 | | } |
| 0 | 1238 | | throw ex; |
| | 1239 | | } |
| | 1240 | | // Create Result |
| 0 | 1241 | | var _result = new HttpOperationResponse<QnADocumentsDTO>(); |
| 0 | 1242 | | _result.Request = _httpRequest; |
| 0 | 1243 | | _result.Response = _httpResponse; |
| | 1244 | | // Deserialize Response |
| 0 | 1245 | | if ((int)_statusCode == 200) |
| | 1246 | | { |
| 0 | 1247 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1248 | | try |
| | 1249 | | { |
| 0 | 1250 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<QnADocumentsDTO>(_responseConten |
| 0 | 1251 | | } |
| 0 | 1252 | | catch (JsonException ex) |
| | 1253 | | { |
| 0 | 1254 | | _httpRequest.Dispose(); |
| 0 | 1255 | | if (_httpResponse != null) |
| | 1256 | | { |
| 0 | 1257 | | _httpResponse.Dispose(); |
| | 1258 | | } |
| 0 | 1259 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1260 | | } |
| | 1261 | | } |
| 0 | 1262 | | if (_shouldTrace) |
| | 1263 | | { |
| 0 | 1264 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1265 | | } |
| 0 | 1266 | | return _result; |
| 0 | 1267 | | } |
| | 1268 | |
|
| | 1269 | | } |
| | 1270 | | } |