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