| | 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 | | /// IndexesOperations operations. |
| | 27 | | /// </summary> |
| | 28 | | internal partial class IndexesOperations : IServiceOperations<SearchServiceClient>, IIndexesOperations |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the IndexesOperations 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 IndexesOperations(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> |
| 15754 | 51 | | public SearchServiceClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Creates a new search index. |
| | 55 | | /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/create-index">Create |
| | 56 | | /// </summary> |
| | 57 | | /// <param name='index'> |
| | 58 | | /// The definition of the index to create. |
| | 59 | | /// </param> |
| | 60 | | /// <param name='searchRequestOptions'> |
| | 61 | | /// Additional parameters for the operation |
| | 62 | | /// </param> |
| | 63 | | /// <param name='customHeaders'> |
| | 64 | | /// Headers that will be added to request. |
| | 65 | | /// </param> |
| | 66 | | /// <param name='cancellationToken'> |
| | 67 | | /// The cancellation token. |
| | 68 | | /// </param> |
| | 69 | | /// <exception cref="CloudException"> |
| | 70 | | /// Thrown when the operation returned an invalid status code |
| | 71 | | /// </exception> |
| | 72 | | /// <exception cref="SerializationException"> |
| | 73 | | /// Thrown when unable to deserialize the response |
| | 74 | | /// </exception> |
| | 75 | | /// <exception cref="ValidationException"> |
| | 76 | | /// Thrown when a required parameter is null |
| | 77 | | /// </exception> |
| | 78 | | /// <exception cref="System.ArgumentNullException"> |
| | 79 | | /// Thrown when a required parameter is null |
| | 80 | | /// </exception> |
| | 81 | | /// <return> |
| | 82 | | /// A response object containing the response body and response headers. |
| | 83 | | /// </return> |
| | 84 | | public async Task<AzureOperationResponse<Index>> CreateWithHttpMessagesAsync(Index index, SearchRequestOptions s |
| | 85 | | { |
| 550 | 86 | | if (Client.SearchServiceName == null) |
| | 87 | | { |
| 0 | 88 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName"); |
| | 89 | | } |
| 550 | 90 | | if (Client.SearchDnsSuffix == null) |
| | 91 | | { |
| 0 | 92 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix"); |
| | 93 | | } |
| 550 | 94 | | if (index == null) |
| | 95 | | { |
| 0 | 96 | | throw new ValidationException(ValidationRules.CannotBeNull, "index"); |
| | 97 | | } |
| 550 | 98 | | if (index != null) |
| | 99 | | { |
| 550 | 100 | | index.Validate(); |
| | 101 | | } |
| 550 | 102 | | if (Client.ApiVersion == null) |
| | 103 | | { |
| 0 | 104 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 105 | | } |
| 550 | 106 | | System.Guid? clientRequestId = default(System.Guid?); |
| 550 | 107 | | if (searchRequestOptions != null) |
| | 108 | | { |
| 0 | 109 | | clientRequestId = searchRequestOptions.ClientRequestId; |
| | 110 | | } |
| | 111 | | // Tracing |
| 550 | 112 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 550 | 113 | | string _invocationId = null; |
| 550 | 114 | | if (_shouldTrace) |
| | 115 | | { |
| 0 | 116 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 117 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 118 | | tracingParameters.Add("index", index); |
| 0 | 119 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 120 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 121 | | ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters); |
| | 122 | | } |
| | 123 | | // Construct URL |
| 550 | 124 | | var _baseUrl = Client.BaseUri; |
| 550 | 125 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes"; |
| 550 | 126 | | _url = _url.Replace("{searchServiceName}", Client.SearchServiceName); |
| 550 | 127 | | _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix); |
| 550 | 128 | | List<string> _queryParameters = new List<string>(); |
| 550 | 129 | | if (Client.ApiVersion != null) |
| | 130 | | { |
| 550 | 131 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 132 | | } |
| 550 | 133 | | if (_queryParameters.Count > 0) |
| | 134 | | { |
| 550 | 135 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 136 | | } |
| | 137 | | // Create HTTP transport objects |
| 550 | 138 | | var _httpRequest = new HttpRequestMessage(); |
| 550 | 139 | | HttpResponseMessage _httpResponse = null; |
| 550 | 140 | | _httpRequest.Method = new HttpMethod("POST"); |
| 550 | 141 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 142 | | // Set Headers |
| 550 | 143 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 144 | | { |
| 550 | 145 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 146 | | } |
| 550 | 147 | | if (Client.AcceptLanguage != null) |
| | 148 | | { |
| 550 | 149 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 150 | | { |
| 0 | 151 | | _httpRequest.Headers.Remove("accept-language"); |
| | 152 | | } |
| 550 | 153 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 154 | | } |
| 550 | 155 | | if (clientRequestId != null) |
| | 156 | | { |
| 0 | 157 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 158 | | { |
| 0 | 159 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 160 | | } |
| 0 | 161 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser |
| | 162 | | } |
| | 163 | |
|
| | 164 | |
|
| 550 | 165 | | if (customHeaders != null) |
| | 166 | | { |
| 0 | 167 | | foreach(var _header in customHeaders) |
| | 168 | | { |
| 0 | 169 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 170 | | { |
| 0 | 171 | | _httpRequest.Headers.Remove(_header.Key); |
| | 172 | | } |
| 0 | 173 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 174 | | } |
| | 175 | | } |
| | 176 | |
|
| | 177 | | // Serialize Request |
| 550 | 178 | | string _requestContent = null; |
| 550 | 179 | | if(index != null) |
| | 180 | | { |
| 550 | 181 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(index, Client.SerializationSettings |
| 550 | 182 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 550 | 183 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 184 | | } |
| | 185 | | // Set Credentials |
| 550 | 186 | | if (Client.Credentials != null) |
| | 187 | | { |
| 550 | 188 | | cancellationToken.ThrowIfCancellationRequested(); |
| 550 | 189 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 190 | | } |
| | 191 | | // Send Request |
| 550 | 192 | | if (_shouldTrace) |
| | 193 | | { |
| 0 | 194 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 195 | | } |
| 550 | 196 | | cancellationToken.ThrowIfCancellationRequested(); |
| 550 | 197 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 550 | 198 | | if (_shouldTrace) |
| | 199 | | { |
| 0 | 200 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 201 | | } |
| 550 | 202 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 550 | 203 | | cancellationToken.ThrowIfCancellationRequested(); |
| 550 | 204 | | string _responseContent = null; |
| 550 | 205 | | if ((int)_statusCode != 201) |
| | 206 | | { |
| 2 | 207 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 208 | | try |
| | 209 | | { |
| 2 | 210 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 2 | 211 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 2 | 212 | | if (_errorBody != null) |
| | 213 | | { |
| 2 | 214 | | ex = new CloudException(_errorBody.Message); |
| 2 | 215 | | ex.Body = _errorBody; |
| | 216 | | } |
| 2 | 217 | | } |
| 0 | 218 | | catch (JsonException) |
| | 219 | | { |
| | 220 | | // Ignore the exception |
| 0 | 221 | | } |
| 2 | 222 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 2 | 223 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 2 | 224 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 225 | | { |
| 2 | 226 | | ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 227 | | } |
| 2 | 228 | | if (_shouldTrace) |
| | 229 | | { |
| 0 | 230 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 231 | | } |
| 2 | 232 | | _httpRequest.Dispose(); |
| 2 | 233 | | if (_httpResponse != null) |
| | 234 | | { |
| 2 | 235 | | _httpResponse.Dispose(); |
| | 236 | | } |
| 2 | 237 | | throw ex; |
| | 238 | | } |
| | 239 | | // Create Result |
| 548 | 240 | | var _result = new AzureOperationResponse<Index>(); |
| 548 | 241 | | _result.Request = _httpRequest; |
| 548 | 242 | | _result.Response = _httpResponse; |
| 548 | 243 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 244 | | { |
| 548 | 245 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 246 | | } |
| | 247 | | // Deserialize Response |
| 548 | 248 | | if ((int)_statusCode == 201) |
| | 249 | | { |
| 548 | 250 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 251 | | try |
| | 252 | | { |
| 548 | 253 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Index>(_responseContent, Client. |
| 548 | 254 | | } |
| 0 | 255 | | catch (JsonException ex) |
| | 256 | | { |
| 0 | 257 | | _httpRequest.Dispose(); |
| 0 | 258 | | if (_httpResponse != null) |
| | 259 | | { |
| 0 | 260 | | _httpResponse.Dispose(); |
| | 261 | | } |
| 0 | 262 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 263 | | } |
| | 264 | | } |
| 548 | 265 | | if (_shouldTrace) |
| | 266 | | { |
| 0 | 267 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 268 | | } |
| 548 | 269 | | return _result; |
| 548 | 270 | | } |
| | 271 | |
|
| | 272 | | /// <summary> |
| | 273 | | /// Lists all indexes available for a search service. |
| | 274 | | /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/list-indexes">List In |
| | 275 | | /// </summary> |
| | 276 | | /// <param name='select'> |
| | 277 | | /// Selects which properties of the index definitions to retrieve. Specified as |
| | 278 | | /// a comma-separated list of JSON property names, or '*' for all properties. |
| | 279 | | /// The default is all properties. |
| | 280 | | /// </param> |
| | 281 | | /// <param name='searchRequestOptions'> |
| | 282 | | /// Additional parameters for the operation |
| | 283 | | /// </param> |
| | 284 | | /// <param name='customHeaders'> |
| | 285 | | /// Headers that will be added to request. |
| | 286 | | /// </param> |
| | 287 | | /// <param name='cancellationToken'> |
| | 288 | | /// The cancellation token. |
| | 289 | | /// </param> |
| | 290 | | /// <exception cref="CloudException"> |
| | 291 | | /// Thrown when the operation returned an invalid status code |
| | 292 | | /// </exception> |
| | 293 | | /// <exception cref="SerializationException"> |
| | 294 | | /// Thrown when unable to deserialize the response |
| | 295 | | /// </exception> |
| | 296 | | /// <exception cref="ValidationException"> |
| | 297 | | /// Thrown when a required parameter is null |
| | 298 | | /// </exception> |
| | 299 | | /// <exception cref="System.ArgumentNullException"> |
| | 300 | | /// Thrown when a required parameter is null |
| | 301 | | /// </exception> |
| | 302 | | /// <return> |
| | 303 | | /// A response object containing the response body and response headers. |
| | 304 | | /// </return> |
| | 305 | | public async Task<AzureOperationResponse<IndexListResult>> ListWithHttpMessagesAsync(string select = default(str |
| | 306 | | { |
| 6 | 307 | | if (Client.SearchServiceName == null) |
| | 308 | | { |
| 0 | 309 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName"); |
| | 310 | | } |
| 6 | 311 | | if (Client.SearchDnsSuffix == null) |
| | 312 | | { |
| 0 | 313 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix"); |
| | 314 | | } |
| 6 | 315 | | if (Client.ApiVersion == null) |
| | 316 | | { |
| 0 | 317 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 318 | | } |
| 6 | 319 | | System.Guid? clientRequestId = default(System.Guid?); |
| 6 | 320 | | if (searchRequestOptions != null) |
| | 321 | | { |
| 2 | 322 | | clientRequestId = searchRequestOptions.ClientRequestId; |
| | 323 | | } |
| | 324 | | // Tracing |
| 6 | 325 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 326 | | string _invocationId = null; |
| 6 | 327 | | if (_shouldTrace) |
| | 328 | | { |
| 0 | 329 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 330 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 331 | | tracingParameters.Add("select", select); |
| 0 | 332 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 333 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 334 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 335 | | } |
| | 336 | | // Construct URL |
| 6 | 337 | | var _baseUrl = Client.BaseUri; |
| 6 | 338 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes"; |
| 6 | 339 | | _url = _url.Replace("{searchServiceName}", Client.SearchServiceName); |
| 6 | 340 | | _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix); |
| 6 | 341 | | List<string> _queryParameters = new List<string>(); |
| 6 | 342 | | if (select != null) |
| | 343 | | { |
| 2 | 344 | | _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select))); |
| | 345 | | } |
| 6 | 346 | | if (Client.ApiVersion != null) |
| | 347 | | { |
| 6 | 348 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 349 | | } |
| 6 | 350 | | if (_queryParameters.Count > 0) |
| | 351 | | { |
| 6 | 352 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 353 | | } |
| | 354 | | // Create HTTP transport objects |
| 6 | 355 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 356 | | HttpResponseMessage _httpResponse = null; |
| 6 | 357 | | _httpRequest.Method = new HttpMethod("GET"); |
| 6 | 358 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 359 | | // Set Headers |
| 6 | 360 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 361 | | { |
| 6 | 362 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 363 | | } |
| 6 | 364 | | if (Client.AcceptLanguage != null) |
| | 365 | | { |
| 6 | 366 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 367 | | { |
| 0 | 368 | | _httpRequest.Headers.Remove("accept-language"); |
| | 369 | | } |
| 6 | 370 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 371 | | } |
| 6 | 372 | | if (clientRequestId != null) |
| | 373 | | { |
| 2 | 374 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 375 | | { |
| 2 | 376 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 377 | | } |
| 2 | 378 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser |
| | 379 | | } |
| | 380 | |
|
| | 381 | |
|
| 6 | 382 | | if (customHeaders != null) |
| | 383 | | { |
| 0 | 384 | | foreach(var _header in customHeaders) |
| | 385 | | { |
| 0 | 386 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 387 | | { |
| 0 | 388 | | _httpRequest.Headers.Remove(_header.Key); |
| | 389 | | } |
| 0 | 390 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 391 | | } |
| | 392 | | } |
| | 393 | |
|
| | 394 | | // Serialize Request |
| 6 | 395 | | string _requestContent = null; |
| | 396 | | // Set Credentials |
| 6 | 397 | | if (Client.Credentials != null) |
| | 398 | | { |
| 6 | 399 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 400 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 401 | | } |
| | 402 | | // Send Request |
| 6 | 403 | | if (_shouldTrace) |
| | 404 | | { |
| 0 | 405 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 406 | | } |
| 6 | 407 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 408 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 409 | | if (_shouldTrace) |
| | 410 | | { |
| 0 | 411 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 412 | | } |
| 6 | 413 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 414 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 415 | | string _responseContent = null; |
| 6 | 416 | | if ((int)_statusCode != 200) |
| | 417 | | { |
| 0 | 418 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 419 | | try |
| | 420 | | { |
| 0 | 421 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 422 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 423 | | if (_errorBody != null) |
| | 424 | | { |
| 0 | 425 | | ex = new CloudException(_errorBody.Message); |
| 0 | 426 | | ex.Body = _errorBody; |
| | 427 | | } |
| 0 | 428 | | } |
| 0 | 429 | | catch (JsonException) |
| | 430 | | { |
| | 431 | | // Ignore the exception |
| 0 | 432 | | } |
| 0 | 433 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 434 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 435 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 436 | | { |
| 0 | 437 | | ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 438 | | } |
| 0 | 439 | | if (_shouldTrace) |
| | 440 | | { |
| 0 | 441 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 442 | | } |
| 0 | 443 | | _httpRequest.Dispose(); |
| 0 | 444 | | if (_httpResponse != null) |
| | 445 | | { |
| 0 | 446 | | _httpResponse.Dispose(); |
| | 447 | | } |
| 0 | 448 | | throw ex; |
| | 449 | | } |
| | 450 | | // Create Result |
| 6 | 451 | | var _result = new AzureOperationResponse<IndexListResult>(); |
| 6 | 452 | | _result.Request = _httpRequest; |
| 6 | 453 | | _result.Response = _httpResponse; |
| 6 | 454 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 455 | | { |
| 6 | 456 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 457 | | } |
| | 458 | | // Deserialize Response |
| 6 | 459 | | if ((int)_statusCode == 200) |
| | 460 | | { |
| 6 | 461 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 462 | | try |
| | 463 | | { |
| 6 | 464 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IndexListResult>(_responseConten |
| 6 | 465 | | } |
| 0 | 466 | | catch (JsonException ex) |
| | 467 | | { |
| 0 | 468 | | _httpRequest.Dispose(); |
| 0 | 469 | | if (_httpResponse != null) |
| | 470 | | { |
| 0 | 471 | | _httpResponse.Dispose(); |
| | 472 | | } |
| 0 | 473 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 474 | | } |
| | 475 | | } |
| 6 | 476 | | if (_shouldTrace) |
| | 477 | | { |
| 0 | 478 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 479 | | } |
| 6 | 480 | | return _result; |
| 6 | 481 | | } |
| | 482 | |
|
| | 483 | | /// <summary> |
| | 484 | | /// Creates a new search index or updates an index if it already exists. |
| | 485 | | /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/update-index">Update |
| | 486 | | /// </summary> |
| | 487 | | /// <param name='indexName'> |
| | 488 | | /// The definition of the index to create or update. |
| | 489 | | /// </param> |
| | 490 | | /// <param name='index'> |
| | 491 | | /// The definition of the index to create or update. |
| | 492 | | /// </param> |
| | 493 | | /// <param name='allowIndexDowntime'> |
| | 494 | | /// Allows new analyzers, tokenizers, token filters, or char filters to be |
| | 495 | | /// added to an index by taking the index offline for at least a few seconds. |
| | 496 | | /// This temporarily causes indexing and query requests to fail. Performance |
| | 497 | | /// and write availability of the index can be impaired for several minutes |
| | 498 | | /// after the index is updated, or longer for very large indexes. |
| | 499 | | /// </param> |
| | 500 | | /// <param name='searchRequestOptions'> |
| | 501 | | /// Additional parameters for the operation |
| | 502 | | /// </param> |
| | 503 | | /// <param name='accessCondition'> |
| | 504 | | /// Additional parameters for the operation |
| | 505 | | /// </param> |
| | 506 | | /// <param name='customHeaders'> |
| | 507 | | /// Headers that will be added to request. |
| | 508 | | /// </param> |
| | 509 | | /// <param name='cancellationToken'> |
| | 510 | | /// The cancellation token. |
| | 511 | | /// </param> |
| | 512 | | /// <exception cref="CloudException"> |
| | 513 | | /// Thrown when the operation returned an invalid status code |
| | 514 | | /// </exception> |
| | 515 | | /// <exception cref="SerializationException"> |
| | 516 | | /// Thrown when unable to deserialize the response |
| | 517 | | /// </exception> |
| | 518 | | /// <exception cref="ValidationException"> |
| | 519 | | /// Thrown when a required parameter is null |
| | 520 | | /// </exception> |
| | 521 | | /// <exception cref="System.ArgumentNullException"> |
| | 522 | | /// Thrown when a required parameter is null |
| | 523 | | /// </exception> |
| | 524 | | /// <return> |
| | 525 | | /// A response object containing the response body and response headers. |
| | 526 | | /// </return> |
| | 527 | | public async Task<AzureOperationResponse<Index>> CreateOrUpdateWithHttpMessagesAsync(string indexName, Index ind |
| | 528 | | { |
| 44 | 529 | | if (Client.SearchServiceName == null) |
| | 530 | | { |
| 0 | 531 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName"); |
| | 532 | | } |
| 44 | 533 | | if (Client.SearchDnsSuffix == null) |
| | 534 | | { |
| 0 | 535 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix"); |
| | 536 | | } |
| 44 | 537 | | if (indexName == null) |
| | 538 | | { |
| 0 | 539 | | throw new ValidationException(ValidationRules.CannotBeNull, "indexName"); |
| | 540 | | } |
| 44 | 541 | | if (index == null) |
| | 542 | | { |
| 0 | 543 | | throw new ValidationException(ValidationRules.CannotBeNull, "index"); |
| | 544 | | } |
| 44 | 545 | | if (index != null) |
| | 546 | | { |
| 44 | 547 | | index.Validate(); |
| | 548 | | } |
| 44 | 549 | | if (Client.ApiVersion == null) |
| | 550 | | { |
| 0 | 551 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 552 | | } |
| 44 | 553 | | string prefer = "return=representation"; |
| 44 | 554 | | System.Guid? clientRequestId = default(System.Guid?); |
| 44 | 555 | | if (searchRequestOptions != null) |
| | 556 | | { |
| 0 | 557 | | clientRequestId = searchRequestOptions.ClientRequestId; |
| | 558 | | } |
| 44 | 559 | | string ifMatch = default(string); |
| 44 | 560 | | if (accessCondition != null) |
| | 561 | | { |
| 22 | 562 | | ifMatch = accessCondition.IfMatch; |
| | 563 | | } |
| 44 | 564 | | string ifNoneMatch = default(string); |
| 44 | 565 | | if (accessCondition != null) |
| | 566 | | { |
| 22 | 567 | | ifNoneMatch = accessCondition.IfNoneMatch; |
| | 568 | | } |
| | 569 | | // Tracing |
| 44 | 570 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 44 | 571 | | string _invocationId = null; |
| 44 | 572 | | if (_shouldTrace) |
| | 573 | | { |
| 0 | 574 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 575 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 576 | | tracingParameters.Add("indexName", indexName); |
| 0 | 577 | | tracingParameters.Add("index", index); |
| 0 | 578 | | tracingParameters.Add("allowIndexDowntime", allowIndexDowntime); |
| 0 | 579 | | tracingParameters.Add("prefer", prefer); |
| 0 | 580 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 581 | | tracingParameters.Add("ifMatch", ifMatch); |
| 0 | 582 | | tracingParameters.Add("ifNoneMatch", ifNoneMatch); |
| 0 | 583 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 584 | | ServiceClientTracing.Enter(_invocationId, this, "CreateOrUpdate", tracingParameters); |
| | 585 | | } |
| | 586 | | // Construct URL |
| 44 | 587 | | var _baseUrl = Client.BaseUri; |
| 44 | 588 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes('{indexName}')"; |
| 44 | 589 | | _url = _url.Replace("{searchServiceName}", Client.SearchServiceName); |
| 44 | 590 | | _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix); |
| 44 | 591 | | _url = _url.Replace("{indexName}", System.Uri.EscapeDataString(indexName)); |
| 44 | 592 | | List<string> _queryParameters = new List<string>(); |
| 44 | 593 | | if (allowIndexDowntime != null) |
| | 594 | | { |
| 2 | 595 | | _queryParameters.Add(string.Format("allowIndexDowntime={0}", System.Uri.EscapeDataString(Rest.Serializat |
| | 596 | | } |
| 44 | 597 | | if (Client.ApiVersion != null) |
| | 598 | | { |
| 44 | 599 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 600 | | } |
| 44 | 601 | | if (_queryParameters.Count > 0) |
| | 602 | | { |
| 44 | 603 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 604 | | } |
| | 605 | | // Create HTTP transport objects |
| 44 | 606 | | var _httpRequest = new HttpRequestMessage(); |
| 44 | 607 | | HttpResponseMessage _httpResponse = null; |
| 44 | 608 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 44 | 609 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 610 | | // Set Headers |
| 44 | 611 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 612 | | { |
| 44 | 613 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 614 | | } |
| 44 | 615 | | if (prefer != null) |
| | 616 | | { |
| 44 | 617 | | if (_httpRequest.Headers.Contains("Prefer")) |
| | 618 | | { |
| 0 | 619 | | _httpRequest.Headers.Remove("Prefer"); |
| | 620 | | } |
| 44 | 621 | | _httpRequest.Headers.TryAddWithoutValidation("Prefer", prefer); |
| | 622 | | } |
| 44 | 623 | | if (Client.AcceptLanguage != null) |
| | 624 | | { |
| 44 | 625 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 626 | | { |
| 0 | 627 | | _httpRequest.Headers.Remove("accept-language"); |
| | 628 | | } |
| 44 | 629 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 630 | | } |
| 44 | 631 | | if (clientRequestId != null) |
| | 632 | | { |
| 0 | 633 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 634 | | { |
| 0 | 635 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 636 | | } |
| 0 | 637 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser |
| | 638 | | } |
| 44 | 639 | | if (ifMatch != null) |
| | 640 | | { |
| 8 | 641 | | if (_httpRequest.Headers.Contains("If-Match")) |
| | 642 | | { |
| 0 | 643 | | _httpRequest.Headers.Remove("If-Match"); |
| | 644 | | } |
| 8 | 645 | | _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch); |
| | 646 | | } |
| 44 | 647 | | if (ifNoneMatch != null) |
| | 648 | | { |
| 4 | 649 | | if (_httpRequest.Headers.Contains("If-None-Match")) |
| | 650 | | { |
| 0 | 651 | | _httpRequest.Headers.Remove("If-None-Match"); |
| | 652 | | } |
| 4 | 653 | | _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch); |
| | 654 | | } |
| | 655 | |
|
| | 656 | |
|
| 44 | 657 | | if (customHeaders != null) |
| | 658 | | { |
| 0 | 659 | | foreach(var _header in customHeaders) |
| | 660 | | { |
| 0 | 661 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 662 | | { |
| 0 | 663 | | _httpRequest.Headers.Remove(_header.Key); |
| | 664 | | } |
| 0 | 665 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 666 | | } |
| | 667 | | } |
| | 668 | |
|
| | 669 | | // Serialize Request |
| 44 | 670 | | string _requestContent = null; |
| 44 | 671 | | if(index != null) |
| | 672 | | { |
| 44 | 673 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(index, Client.SerializationSettings |
| 44 | 674 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 44 | 675 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 676 | | } |
| | 677 | | // Set Credentials |
| 44 | 678 | | if (Client.Credentials != null) |
| | 679 | | { |
| 44 | 680 | | cancellationToken.ThrowIfCancellationRequested(); |
| 44 | 681 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 682 | | } |
| | 683 | | // Send Request |
| 44 | 684 | | if (_shouldTrace) |
| | 685 | | { |
| 0 | 686 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 687 | | } |
| 44 | 688 | | cancellationToken.ThrowIfCancellationRequested(); |
| 44 | 689 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 44 | 690 | | if (_shouldTrace) |
| | 691 | | { |
| 0 | 692 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 693 | | } |
| 44 | 694 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 44 | 695 | | cancellationToken.ThrowIfCancellationRequested(); |
| 44 | 696 | | string _responseContent = null; |
| 44 | 697 | | if ((int)_statusCode != 200 && (int)_statusCode != 201) |
| | 698 | | { |
| 8 | 699 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 700 | | try |
| | 701 | | { |
| 8 | 702 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 8 | 703 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 8 | 704 | | if (_errorBody != null) |
| | 705 | | { |
| 8 | 706 | | ex = new CloudException(_errorBody.Message); |
| 8 | 707 | | ex.Body = _errorBody; |
| | 708 | | } |
| 8 | 709 | | } |
| 0 | 710 | | catch (JsonException) |
| | 711 | | { |
| | 712 | | // Ignore the exception |
| 0 | 713 | | } |
| 8 | 714 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 8 | 715 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 8 | 716 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 717 | | { |
| 8 | 718 | | ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 719 | | } |
| 8 | 720 | | if (_shouldTrace) |
| | 721 | | { |
| 0 | 722 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 723 | | } |
| 8 | 724 | | _httpRequest.Dispose(); |
| 8 | 725 | | if (_httpResponse != null) |
| | 726 | | { |
| 8 | 727 | | _httpResponse.Dispose(); |
| | 728 | | } |
| 8 | 729 | | throw ex; |
| | 730 | | } |
| | 731 | | // Create Result |
| 36 | 732 | | var _result = new AzureOperationResponse<Index>(); |
| 36 | 733 | | _result.Request = _httpRequest; |
| 36 | 734 | | _result.Response = _httpResponse; |
| 36 | 735 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 736 | | { |
| 36 | 737 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 738 | | } |
| | 739 | | // Deserialize Response |
| 36 | 740 | | if ((int)_statusCode == 200) |
| | 741 | | { |
| 20 | 742 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 743 | | try |
| | 744 | | { |
| 20 | 745 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Index>(_responseContent, Client. |
| 20 | 746 | | } |
| 0 | 747 | | catch (JsonException ex) |
| | 748 | | { |
| 0 | 749 | | _httpRequest.Dispose(); |
| 0 | 750 | | if (_httpResponse != null) |
| | 751 | | { |
| 0 | 752 | | _httpResponse.Dispose(); |
| | 753 | | } |
| 0 | 754 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 755 | | } |
| | 756 | | } |
| | 757 | | // Deserialize Response |
| 36 | 758 | | if ((int)_statusCode == 201) |
| | 759 | | { |
| 16 | 760 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 761 | | try |
| | 762 | | { |
| 16 | 763 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Index>(_responseContent, Client. |
| 16 | 764 | | } |
| 0 | 765 | | catch (JsonException ex) |
| | 766 | | { |
| 0 | 767 | | _httpRequest.Dispose(); |
| 0 | 768 | | if (_httpResponse != null) |
| | 769 | | { |
| 0 | 770 | | _httpResponse.Dispose(); |
| | 771 | | } |
| 0 | 772 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 773 | | } |
| | 774 | | } |
| 36 | 775 | | if (_shouldTrace) |
| | 776 | | { |
| 0 | 777 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 778 | | } |
| 36 | 779 | | return _result; |
| 36 | 780 | | } |
| | 781 | |
|
| | 782 | | /// <summary> |
| | 783 | | /// Deletes a search index and all the documents it contains. |
| | 784 | | /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/delete-index">Delete |
| | 785 | | /// </summary> |
| | 786 | | /// <param name='indexName'> |
| | 787 | | /// The name of the index to delete. |
| | 788 | | /// </param> |
| | 789 | | /// <param name='searchRequestOptions'> |
| | 790 | | /// Additional parameters for the operation |
| | 791 | | /// </param> |
| | 792 | | /// <param name='accessCondition'> |
| | 793 | | /// Additional parameters for the operation |
| | 794 | | /// </param> |
| | 795 | | /// <param name='customHeaders'> |
| | 796 | | /// Headers that will be added to request. |
| | 797 | | /// </param> |
| | 798 | | /// <param name='cancellationToken'> |
| | 799 | | /// The cancellation token. |
| | 800 | | /// </param> |
| | 801 | | /// <exception cref="CloudException"> |
| | 802 | | /// Thrown when the operation returned an invalid status code |
| | 803 | | /// </exception> |
| | 804 | | /// <exception cref="ValidationException"> |
| | 805 | | /// Thrown when a required parameter is null |
| | 806 | | /// </exception> |
| | 807 | | /// <exception cref="System.ArgumentNullException"> |
| | 808 | | /// Thrown when a required parameter is null |
| | 809 | | /// </exception> |
| | 810 | | /// <return> |
| | 811 | | /// A response object containing the response body and response headers. |
| | 812 | | /// </return> |
| | 813 | | public async Task<AzureOperationResponse> DeleteWithHttpMessagesAsync(string indexName, SearchRequestOptions sea |
| | 814 | | { |
| 42 | 815 | | if (Client.SearchServiceName == null) |
| | 816 | | { |
| 0 | 817 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName"); |
| | 818 | | } |
| 42 | 819 | | if (Client.SearchDnsSuffix == null) |
| | 820 | | { |
| 0 | 821 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix"); |
| | 822 | | } |
| 42 | 823 | | if (indexName == null) |
| | 824 | | { |
| 0 | 825 | | throw new ValidationException(ValidationRules.CannotBeNull, "indexName"); |
| | 826 | | } |
| 42 | 827 | | if (Client.ApiVersion == null) |
| | 828 | | { |
| 0 | 829 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 830 | | } |
| 42 | 831 | | System.Guid? clientRequestId = default(System.Guid?); |
| 42 | 832 | | if (searchRequestOptions != null) |
| | 833 | | { |
| 0 | 834 | | clientRequestId = searchRequestOptions.ClientRequestId; |
| | 835 | | } |
| 42 | 836 | | string ifMatch = default(string); |
| 42 | 837 | | if (accessCondition != null) |
| | 838 | | { |
| 8 | 839 | | ifMatch = accessCondition.IfMatch; |
| | 840 | | } |
| 42 | 841 | | string ifNoneMatch = default(string); |
| 42 | 842 | | if (accessCondition != null) |
| | 843 | | { |
| 8 | 844 | | ifNoneMatch = accessCondition.IfNoneMatch; |
| | 845 | | } |
| | 846 | | // Tracing |
| 42 | 847 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 42 | 848 | | string _invocationId = null; |
| 42 | 849 | | if (_shouldTrace) |
| | 850 | | { |
| 0 | 851 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 852 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 853 | | tracingParameters.Add("indexName", indexName); |
| 0 | 854 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 855 | | tracingParameters.Add("ifMatch", ifMatch); |
| 0 | 856 | | tracingParameters.Add("ifNoneMatch", ifNoneMatch); |
| 0 | 857 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 858 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 859 | | } |
| | 860 | | // Construct URL |
| 42 | 861 | | var _baseUrl = Client.BaseUri; |
| 42 | 862 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes('{indexName}')"; |
| 42 | 863 | | _url = _url.Replace("{searchServiceName}", Client.SearchServiceName); |
| 42 | 864 | | _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix); |
| 42 | 865 | | _url = _url.Replace("{indexName}", System.Uri.EscapeDataString(indexName)); |
| 42 | 866 | | List<string> _queryParameters = new List<string>(); |
| 42 | 867 | | if (Client.ApiVersion != null) |
| | 868 | | { |
| 42 | 869 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 870 | | } |
| 42 | 871 | | if (_queryParameters.Count > 0) |
| | 872 | | { |
| 42 | 873 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 874 | | } |
| | 875 | | // Create HTTP transport objects |
| 42 | 876 | | var _httpRequest = new HttpRequestMessage(); |
| 42 | 877 | | HttpResponseMessage _httpResponse = null; |
| 42 | 878 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 42 | 879 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 880 | | // Set Headers |
| 42 | 881 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 882 | | { |
| 42 | 883 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 884 | | } |
| 42 | 885 | | if (Client.AcceptLanguage != null) |
| | 886 | | { |
| 42 | 887 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 888 | | { |
| 0 | 889 | | _httpRequest.Headers.Remove("accept-language"); |
| | 890 | | } |
| 42 | 891 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 892 | | } |
| 42 | 893 | | if (clientRequestId != null) |
| | 894 | | { |
| 0 | 895 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 896 | | { |
| 0 | 897 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 898 | | } |
| 0 | 899 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser |
| | 900 | | } |
| 42 | 901 | | if (ifMatch != null) |
| | 902 | | { |
| 8 | 903 | | if (_httpRequest.Headers.Contains("If-Match")) |
| | 904 | | { |
| 0 | 905 | | _httpRequest.Headers.Remove("If-Match"); |
| | 906 | | } |
| 8 | 907 | | _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch); |
| | 908 | | } |
| 42 | 909 | | if (ifNoneMatch != null) |
| | 910 | | { |
| 0 | 911 | | if (_httpRequest.Headers.Contains("If-None-Match")) |
| | 912 | | { |
| 0 | 913 | | _httpRequest.Headers.Remove("If-None-Match"); |
| | 914 | | } |
| 0 | 915 | | _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch); |
| | 916 | | } |
| | 917 | |
|
| | 918 | |
|
| 42 | 919 | | if (customHeaders != null) |
| | 920 | | { |
| 0 | 921 | | foreach(var _header in customHeaders) |
| | 922 | | { |
| 0 | 923 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 924 | | { |
| 0 | 925 | | _httpRequest.Headers.Remove(_header.Key); |
| | 926 | | } |
| 0 | 927 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 928 | | } |
| | 929 | | } |
| | 930 | |
|
| | 931 | | // Serialize Request |
| 42 | 932 | | string _requestContent = null; |
| | 933 | | // Set Credentials |
| 42 | 934 | | if (Client.Credentials != null) |
| | 935 | | { |
| 42 | 936 | | cancellationToken.ThrowIfCancellationRequested(); |
| 42 | 937 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 938 | | } |
| | 939 | | // Send Request |
| 42 | 940 | | if (_shouldTrace) |
| | 941 | | { |
| 0 | 942 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 943 | | } |
| 42 | 944 | | cancellationToken.ThrowIfCancellationRequested(); |
| 42 | 945 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 42 | 946 | | if (_shouldTrace) |
| | 947 | | { |
| 0 | 948 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 949 | | } |
| 42 | 950 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 42 | 951 | | cancellationToken.ThrowIfCancellationRequested(); |
| 42 | 952 | | string _responseContent = null; |
| 42 | 953 | | if ((int)_statusCode != 204 && (int)_statusCode != 404) |
| | 954 | | { |
| 4 | 955 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 956 | | try |
| | 957 | | { |
| 4 | 958 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 4 | 959 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 4 | 960 | | if (_errorBody != null) |
| | 961 | | { |
| 4 | 962 | | ex = new CloudException(_errorBody.Message); |
| 4 | 963 | | ex.Body = _errorBody; |
| | 964 | | } |
| 4 | 965 | | } |
| 0 | 966 | | catch (JsonException) |
| | 967 | | { |
| | 968 | | // Ignore the exception |
| 0 | 969 | | } |
| 4 | 970 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 4 | 971 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 4 | 972 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 973 | | { |
| 4 | 974 | | ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 975 | | } |
| 4 | 976 | | if (_shouldTrace) |
| | 977 | | { |
| 0 | 978 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 979 | | } |
| 4 | 980 | | _httpRequest.Dispose(); |
| 4 | 981 | | if (_httpResponse != null) |
| | 982 | | { |
| 4 | 983 | | _httpResponse.Dispose(); |
| | 984 | | } |
| 4 | 985 | | throw ex; |
| | 986 | | } |
| | 987 | | // Create Result |
| 38 | 988 | | var _result = new AzureOperationResponse(); |
| 38 | 989 | | _result.Request = _httpRequest; |
| 38 | 990 | | _result.Response = _httpResponse; |
| 38 | 991 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 992 | | { |
| 38 | 993 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 994 | | } |
| 38 | 995 | | if (_shouldTrace) |
| | 996 | | { |
| 0 | 997 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 998 | | } |
| 38 | 999 | | return _result; |
| 38 | 1000 | | } |
| | 1001 | |
|
| | 1002 | | /// <summary> |
| | 1003 | | /// Retrieves an index definition. |
| | 1004 | | /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/get-index">Get Index< |
| | 1005 | | /// </summary> |
| | 1006 | | /// <param name='indexName'> |
| | 1007 | | /// The name of the index to retrieve. |
| | 1008 | | /// </param> |
| | 1009 | | /// <param name='searchRequestOptions'> |
| | 1010 | | /// Additional parameters for the operation |
| | 1011 | | /// </param> |
| | 1012 | | /// <param name='customHeaders'> |
| | 1013 | | /// Headers that will be added to request. |
| | 1014 | | /// </param> |
| | 1015 | | /// <param name='cancellationToken'> |
| | 1016 | | /// The cancellation token. |
| | 1017 | | /// </param> |
| | 1018 | | /// <exception cref="CloudException"> |
| | 1019 | | /// Thrown when the operation returned an invalid status code |
| | 1020 | | /// </exception> |
| | 1021 | | /// <exception cref="SerializationException"> |
| | 1022 | | /// Thrown when unable to deserialize the response |
| | 1023 | | /// </exception> |
| | 1024 | | /// <exception cref="ValidationException"> |
| | 1025 | | /// Thrown when a required parameter is null |
| | 1026 | | /// </exception> |
| | 1027 | | /// <exception cref="System.ArgumentNullException"> |
| | 1028 | | /// Thrown when a required parameter is null |
| | 1029 | | /// </exception> |
| | 1030 | | /// <return> |
| | 1031 | | /// A response object containing the response body and response headers. |
| | 1032 | | /// </return> |
| | 1033 | | public async Task<AzureOperationResponse<Index>> GetWithHttpMessagesAsync(string indexName, SearchRequestOptions |
| | 1034 | | { |
| 22 | 1035 | | if (Client.SearchServiceName == null) |
| | 1036 | | { |
| 0 | 1037 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName"); |
| | 1038 | | } |
| 22 | 1039 | | if (Client.SearchDnsSuffix == null) |
| | 1040 | | { |
| 0 | 1041 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix"); |
| | 1042 | | } |
| 22 | 1043 | | if (indexName == null) |
| | 1044 | | { |
| 0 | 1045 | | throw new ValidationException(ValidationRules.CannotBeNull, "indexName"); |
| | 1046 | | } |
| 22 | 1047 | | if (Client.ApiVersion == null) |
| | 1048 | | { |
| 0 | 1049 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1050 | | } |
| 22 | 1051 | | System.Guid? clientRequestId = default(System.Guid?); |
| 22 | 1052 | | if (searchRequestOptions != null) |
| | 1053 | | { |
| 0 | 1054 | | clientRequestId = searchRequestOptions.ClientRequestId; |
| | 1055 | | } |
| | 1056 | | // Tracing |
| 22 | 1057 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 22 | 1058 | | string _invocationId = null; |
| 22 | 1059 | | if (_shouldTrace) |
| | 1060 | | { |
| 0 | 1061 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1062 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1063 | | tracingParameters.Add("indexName", indexName); |
| 0 | 1064 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1065 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1066 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 1067 | | } |
| | 1068 | | // Construct URL |
| 22 | 1069 | | var _baseUrl = Client.BaseUri; |
| 22 | 1070 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes('{indexName}')"; |
| 22 | 1071 | | _url = _url.Replace("{searchServiceName}", Client.SearchServiceName); |
| 22 | 1072 | | _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix); |
| 22 | 1073 | | _url = _url.Replace("{indexName}", System.Uri.EscapeDataString(indexName)); |
| 22 | 1074 | | List<string> _queryParameters = new List<string>(); |
| 22 | 1075 | | if (Client.ApiVersion != null) |
| | 1076 | | { |
| 22 | 1077 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1078 | | } |
| 22 | 1079 | | if (_queryParameters.Count > 0) |
| | 1080 | | { |
| 22 | 1081 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1082 | | } |
| | 1083 | | // Create HTTP transport objects |
| 22 | 1084 | | var _httpRequest = new HttpRequestMessage(); |
| 22 | 1085 | | HttpResponseMessage _httpResponse = null; |
| 22 | 1086 | | _httpRequest.Method = new HttpMethod("GET"); |
| 22 | 1087 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1088 | | // Set Headers |
| 22 | 1089 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1090 | | { |
| 22 | 1091 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1092 | | } |
| 22 | 1093 | | if (Client.AcceptLanguage != null) |
| | 1094 | | { |
| 22 | 1095 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1096 | | { |
| 0 | 1097 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1098 | | } |
| 22 | 1099 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1100 | | } |
| 22 | 1101 | | if (clientRequestId != null) |
| | 1102 | | { |
| 0 | 1103 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1104 | | { |
| 0 | 1105 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1106 | | } |
| 0 | 1107 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser |
| | 1108 | | } |
| | 1109 | |
|
| | 1110 | |
|
| 22 | 1111 | | if (customHeaders != null) |
| | 1112 | | { |
| 0 | 1113 | | foreach(var _header in customHeaders) |
| | 1114 | | { |
| 0 | 1115 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1116 | | { |
| 0 | 1117 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1118 | | } |
| 0 | 1119 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1120 | | } |
| | 1121 | | } |
| | 1122 | |
|
| | 1123 | | // Serialize Request |
| 22 | 1124 | | string _requestContent = null; |
| | 1125 | | // Set Credentials |
| 22 | 1126 | | if (Client.Credentials != null) |
| | 1127 | | { |
| 22 | 1128 | | cancellationToken.ThrowIfCancellationRequested(); |
| 22 | 1129 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1130 | | } |
| | 1131 | | // Send Request |
| 22 | 1132 | | if (_shouldTrace) |
| | 1133 | | { |
| 0 | 1134 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1135 | | } |
| 22 | 1136 | | cancellationToken.ThrowIfCancellationRequested(); |
| 22 | 1137 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 22 | 1138 | | if (_shouldTrace) |
| | 1139 | | { |
| 0 | 1140 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1141 | | } |
| 22 | 1142 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 22 | 1143 | | cancellationToken.ThrowIfCancellationRequested(); |
| 22 | 1144 | | string _responseContent = null; |
| 22 | 1145 | | if ((int)_statusCode != 200) |
| | 1146 | | { |
| 6 | 1147 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 1148 | | try |
| | 1149 | | { |
| 6 | 1150 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 6 | 1151 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 6 | 1152 | | if (_errorBody != null) |
| | 1153 | | { |
| 6 | 1154 | | ex = new CloudException(_errorBody.Message); |
| 6 | 1155 | | ex.Body = _errorBody; |
| | 1156 | | } |
| 6 | 1157 | | } |
| 0 | 1158 | | catch (JsonException) |
| | 1159 | | { |
| | 1160 | | // Ignore the exception |
| 0 | 1161 | | } |
| 6 | 1162 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 6 | 1163 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 6 | 1164 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1165 | | { |
| 6 | 1166 | | ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1167 | | } |
| 6 | 1168 | | if (_shouldTrace) |
| | 1169 | | { |
| 0 | 1170 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1171 | | } |
| 6 | 1172 | | _httpRequest.Dispose(); |
| 6 | 1173 | | if (_httpResponse != null) |
| | 1174 | | { |
| 6 | 1175 | | _httpResponse.Dispose(); |
| | 1176 | | } |
| 6 | 1177 | | throw ex; |
| | 1178 | | } |
| | 1179 | | // Create Result |
| 16 | 1180 | | var _result = new AzureOperationResponse<Index>(); |
| 16 | 1181 | | _result.Request = _httpRequest; |
| 16 | 1182 | | _result.Response = _httpResponse; |
| 16 | 1183 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1184 | | { |
| 16 | 1185 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1186 | | } |
| | 1187 | | // Deserialize Response |
| 16 | 1188 | | if ((int)_statusCode == 200) |
| | 1189 | | { |
| 16 | 1190 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1191 | | try |
| | 1192 | | { |
| 16 | 1193 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Index>(_responseContent, Client. |
| 16 | 1194 | | } |
| 0 | 1195 | | catch (JsonException ex) |
| | 1196 | | { |
| 0 | 1197 | | _httpRequest.Dispose(); |
| 0 | 1198 | | if (_httpResponse != null) |
| | 1199 | | { |
| 0 | 1200 | | _httpResponse.Dispose(); |
| | 1201 | | } |
| 0 | 1202 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1203 | | } |
| | 1204 | | } |
| 16 | 1205 | | if (_shouldTrace) |
| | 1206 | | { |
| 0 | 1207 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1208 | | } |
| 16 | 1209 | | return _result; |
| 16 | 1210 | | } |
| | 1211 | |
|
| | 1212 | | /// <summary> |
| | 1213 | | /// Returns statistics for the given index, including a document count and |
| | 1214 | | /// storage usage. |
| | 1215 | | /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/get-index-statistics" |
| | 1216 | | /// </summary> |
| | 1217 | | /// <param name='indexName'> |
| | 1218 | | /// The name of the index for which to retrieve statistics. |
| | 1219 | | /// </param> |
| | 1220 | | /// <param name='searchRequestOptions'> |
| | 1221 | | /// Additional parameters for the operation |
| | 1222 | | /// </param> |
| | 1223 | | /// <param name='customHeaders'> |
| | 1224 | | /// Headers that will be added to request. |
| | 1225 | | /// </param> |
| | 1226 | | /// <param name='cancellationToken'> |
| | 1227 | | /// The cancellation token. |
| | 1228 | | /// </param> |
| | 1229 | | /// <exception cref="CloudException"> |
| | 1230 | | /// Thrown when the operation returned an invalid status code |
| | 1231 | | /// </exception> |
| | 1232 | | /// <exception cref="SerializationException"> |
| | 1233 | | /// Thrown when unable to deserialize the response |
| | 1234 | | /// </exception> |
| | 1235 | | /// <exception cref="ValidationException"> |
| | 1236 | | /// Thrown when a required parameter is null |
| | 1237 | | /// </exception> |
| | 1238 | | /// <exception cref="System.ArgumentNullException"> |
| | 1239 | | /// Thrown when a required parameter is null |
| | 1240 | | /// </exception> |
| | 1241 | | /// <return> |
| | 1242 | | /// A response object containing the response body and response headers. |
| | 1243 | | /// </return> |
| | 1244 | | public async Task<AzureOperationResponse<IndexGetStatisticsResult>> GetStatisticsWithHttpMessagesAsync(string in |
| | 1245 | | { |
| 2 | 1246 | | if (Client.SearchServiceName == null) |
| | 1247 | | { |
| 0 | 1248 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName"); |
| | 1249 | | } |
| 2 | 1250 | | if (Client.SearchDnsSuffix == null) |
| | 1251 | | { |
| 0 | 1252 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix"); |
| | 1253 | | } |
| 2 | 1254 | | if (indexName == null) |
| | 1255 | | { |
| 0 | 1256 | | throw new ValidationException(ValidationRules.CannotBeNull, "indexName"); |
| | 1257 | | } |
| 2 | 1258 | | if (Client.ApiVersion == null) |
| | 1259 | | { |
| 0 | 1260 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1261 | | } |
| 2 | 1262 | | System.Guid? clientRequestId = default(System.Guid?); |
| 2 | 1263 | | if (searchRequestOptions != null) |
| | 1264 | | { |
| 0 | 1265 | | clientRequestId = searchRequestOptions.ClientRequestId; |
| | 1266 | | } |
| | 1267 | | // Tracing |
| 2 | 1268 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 1269 | | string _invocationId = null; |
| 2 | 1270 | | if (_shouldTrace) |
| | 1271 | | { |
| 0 | 1272 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1273 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1274 | | tracingParameters.Add("indexName", indexName); |
| 0 | 1275 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1276 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1277 | | ServiceClientTracing.Enter(_invocationId, this, "GetStatistics", tracingParameters); |
| | 1278 | | } |
| | 1279 | | // Construct URL |
| 2 | 1280 | | var _baseUrl = Client.BaseUri; |
| 2 | 1281 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes('{indexName}')/search.stats"; |
| 2 | 1282 | | _url = _url.Replace("{searchServiceName}", Client.SearchServiceName); |
| 2 | 1283 | | _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix); |
| 2 | 1284 | | _url = _url.Replace("{indexName}", System.Uri.EscapeDataString(indexName)); |
| 2 | 1285 | | List<string> _queryParameters = new List<string>(); |
| 2 | 1286 | | if (Client.ApiVersion != null) |
| | 1287 | | { |
| 2 | 1288 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1289 | | } |
| 2 | 1290 | | if (_queryParameters.Count > 0) |
| | 1291 | | { |
| 2 | 1292 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1293 | | } |
| | 1294 | | // Create HTTP transport objects |
| 2 | 1295 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 1296 | | HttpResponseMessage _httpResponse = null; |
| 2 | 1297 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 1298 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1299 | | // Set Headers |
| 2 | 1300 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1301 | | { |
| 2 | 1302 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1303 | | } |
| 2 | 1304 | | if (Client.AcceptLanguage != null) |
| | 1305 | | { |
| 2 | 1306 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1307 | | { |
| 0 | 1308 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1309 | | } |
| 2 | 1310 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1311 | | } |
| 2 | 1312 | | if (clientRequestId != null) |
| | 1313 | | { |
| 0 | 1314 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1315 | | { |
| 0 | 1316 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1317 | | } |
| 0 | 1318 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser |
| | 1319 | | } |
| | 1320 | |
|
| | 1321 | |
|
| 2 | 1322 | | if (customHeaders != null) |
| | 1323 | | { |
| 0 | 1324 | | foreach(var _header in customHeaders) |
| | 1325 | | { |
| 0 | 1326 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1327 | | { |
| 0 | 1328 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1329 | | } |
| 0 | 1330 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1331 | | } |
| | 1332 | | } |
| | 1333 | |
|
| | 1334 | | // Serialize Request |
| 2 | 1335 | | string _requestContent = null; |
| | 1336 | | // Set Credentials |
| 2 | 1337 | | if (Client.Credentials != null) |
| | 1338 | | { |
| 2 | 1339 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1340 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1341 | | } |
| | 1342 | | // Send Request |
| 2 | 1343 | | if (_shouldTrace) |
| | 1344 | | { |
| 0 | 1345 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1346 | | } |
| 2 | 1347 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1348 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 1349 | | if (_shouldTrace) |
| | 1350 | | { |
| 0 | 1351 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1352 | | } |
| 2 | 1353 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 1354 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1355 | | string _responseContent = null; |
| 2 | 1356 | | if ((int)_statusCode != 200) |
| | 1357 | | { |
| 0 | 1358 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 1359 | | try |
| | 1360 | | { |
| 0 | 1361 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1362 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 1363 | | if (_errorBody != null) |
| | 1364 | | { |
| 0 | 1365 | | ex = new CloudException(_errorBody.Message); |
| 0 | 1366 | | ex.Body = _errorBody; |
| | 1367 | | } |
| 0 | 1368 | | } |
| 0 | 1369 | | catch (JsonException) |
| | 1370 | | { |
| | 1371 | | // Ignore the exception |
| 0 | 1372 | | } |
| 0 | 1373 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1374 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1375 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1376 | | { |
| 0 | 1377 | | ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1378 | | } |
| 0 | 1379 | | if (_shouldTrace) |
| | 1380 | | { |
| 0 | 1381 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1382 | | } |
| 0 | 1383 | | _httpRequest.Dispose(); |
| 0 | 1384 | | if (_httpResponse != null) |
| | 1385 | | { |
| 0 | 1386 | | _httpResponse.Dispose(); |
| | 1387 | | } |
| 0 | 1388 | | throw ex; |
| | 1389 | | } |
| | 1390 | | // Create Result |
| 2 | 1391 | | var _result = new AzureOperationResponse<IndexGetStatisticsResult>(); |
| 2 | 1392 | | _result.Request = _httpRequest; |
| 2 | 1393 | | _result.Response = _httpResponse; |
| 2 | 1394 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1395 | | { |
| 2 | 1396 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1397 | | } |
| | 1398 | | // Deserialize Response |
| 2 | 1399 | | if ((int)_statusCode == 200) |
| | 1400 | | { |
| 2 | 1401 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1402 | | try |
| | 1403 | | { |
| 2 | 1404 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IndexGetStatisticsResult>(_respo |
| 2 | 1405 | | } |
| 0 | 1406 | | catch (JsonException ex) |
| | 1407 | | { |
| 0 | 1408 | | _httpRequest.Dispose(); |
| 0 | 1409 | | if (_httpResponse != null) |
| | 1410 | | { |
| 0 | 1411 | | _httpResponse.Dispose(); |
| | 1412 | | } |
| 0 | 1413 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1414 | | } |
| | 1415 | | } |
| 2 | 1416 | | if (_shouldTrace) |
| | 1417 | | { |
| 0 | 1418 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1419 | | } |
| 2 | 1420 | | return _result; |
| 2 | 1421 | | } |
| | 1422 | |
|
| | 1423 | | /// <summary> |
| | 1424 | | /// Shows how an analyzer breaks text into tokens. |
| | 1425 | | /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/test-analyzer">Analyz |
| | 1426 | | /// </summary> |
| | 1427 | | /// <param name='indexName'> |
| | 1428 | | /// The name of the index for which to test an analyzer. |
| | 1429 | | /// </param> |
| | 1430 | | /// <param name='request'> |
| | 1431 | | /// The text and analyzer or analysis components to test. |
| | 1432 | | /// </param> |
| | 1433 | | /// <param name='searchRequestOptions'> |
| | 1434 | | /// Additional parameters for the operation |
| | 1435 | | /// </param> |
| | 1436 | | /// <param name='customHeaders'> |
| | 1437 | | /// Headers that will be added to request. |
| | 1438 | | /// </param> |
| | 1439 | | /// <param name='cancellationToken'> |
| | 1440 | | /// The cancellation token. |
| | 1441 | | /// </param> |
| | 1442 | | /// <exception cref="CloudException"> |
| | 1443 | | /// Thrown when the operation returned an invalid status code |
| | 1444 | | /// </exception> |
| | 1445 | | /// <exception cref="SerializationException"> |
| | 1446 | | /// Thrown when unable to deserialize the response |
| | 1447 | | /// </exception> |
| | 1448 | | /// <exception cref="ValidationException"> |
| | 1449 | | /// Thrown when a required parameter is null |
| | 1450 | | /// </exception> |
| | 1451 | | /// <exception cref="System.ArgumentNullException"> |
| | 1452 | | /// Thrown when a required parameter is null |
| | 1453 | | /// </exception> |
| | 1454 | | /// <return> |
| | 1455 | | /// A response object containing the response body and response headers. |
| | 1456 | | /// </return> |
| | 1457 | | public async Task<AzureOperationResponse<AnalyzeResult>> AnalyzeWithHttpMessagesAsync(string indexName, AnalyzeR |
| | 1458 | | { |
| 218 | 1459 | | if (Client.SearchServiceName == null) |
| | 1460 | | { |
| 0 | 1461 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName"); |
| | 1462 | | } |
| 218 | 1463 | | if (Client.SearchDnsSuffix == null) |
| | 1464 | | { |
| 0 | 1465 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix"); |
| | 1466 | | } |
| 218 | 1467 | | if (indexName == null) |
| | 1468 | | { |
| 0 | 1469 | | throw new ValidationException(ValidationRules.CannotBeNull, "indexName"); |
| | 1470 | | } |
| 218 | 1471 | | if (request == null) |
| | 1472 | | { |
| 0 | 1473 | | throw new ValidationException(ValidationRules.CannotBeNull, "request"); |
| | 1474 | | } |
| 218 | 1475 | | if (request != null) |
| | 1476 | | { |
| 218 | 1477 | | request.Validate(); |
| | 1478 | | } |
| 218 | 1479 | | if (Client.ApiVersion == null) |
| | 1480 | | { |
| 0 | 1481 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1482 | | } |
| 218 | 1483 | | System.Guid? clientRequestId = default(System.Guid?); |
| 218 | 1484 | | if (searchRequestOptions != null) |
| | 1485 | | { |
| 0 | 1486 | | clientRequestId = searchRequestOptions.ClientRequestId; |
| | 1487 | | } |
| | 1488 | | // Tracing |
| 218 | 1489 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 218 | 1490 | | string _invocationId = null; |
| 218 | 1491 | | if (_shouldTrace) |
| | 1492 | | { |
| 0 | 1493 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1494 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1495 | | tracingParameters.Add("indexName", indexName); |
| 0 | 1496 | | tracingParameters.Add("request", request); |
| 0 | 1497 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1498 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1499 | | ServiceClientTracing.Enter(_invocationId, this, "Analyze", tracingParameters); |
| | 1500 | | } |
| | 1501 | | // Construct URL |
| 218 | 1502 | | var _baseUrl = Client.BaseUri; |
| 218 | 1503 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes('{indexName}')/search.analyze"; |
| 218 | 1504 | | _url = _url.Replace("{searchServiceName}", Client.SearchServiceName); |
| 218 | 1505 | | _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix); |
| 218 | 1506 | | _url = _url.Replace("{indexName}", System.Uri.EscapeDataString(indexName)); |
| 218 | 1507 | | List<string> _queryParameters = new List<string>(); |
| 218 | 1508 | | if (Client.ApiVersion != null) |
| | 1509 | | { |
| 218 | 1510 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1511 | | } |
| 218 | 1512 | | if (_queryParameters.Count > 0) |
| | 1513 | | { |
| 218 | 1514 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1515 | | } |
| | 1516 | | // Create HTTP transport objects |
| 218 | 1517 | | var _httpRequest = new HttpRequestMessage(); |
| 218 | 1518 | | HttpResponseMessage _httpResponse = null; |
| 218 | 1519 | | _httpRequest.Method = new HttpMethod("POST"); |
| 218 | 1520 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1521 | | // Set Headers |
| 218 | 1522 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1523 | | { |
| 218 | 1524 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1525 | | } |
| 218 | 1526 | | if (Client.AcceptLanguage != null) |
| | 1527 | | { |
| 218 | 1528 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1529 | | { |
| 0 | 1530 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1531 | | } |
| 218 | 1532 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1533 | | } |
| 218 | 1534 | | if (clientRequestId != null) |
| | 1535 | | { |
| 0 | 1536 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1537 | | { |
| 0 | 1538 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1539 | | } |
| 0 | 1540 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser |
| | 1541 | | } |
| | 1542 | |
|
| | 1543 | |
|
| 218 | 1544 | | if (customHeaders != null) |
| | 1545 | | { |
| 0 | 1546 | | foreach(var _header in customHeaders) |
| | 1547 | | { |
| 0 | 1548 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1549 | | { |
| 0 | 1550 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1551 | | } |
| 0 | 1552 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1553 | | } |
| | 1554 | | } |
| | 1555 | |
|
| | 1556 | | // Serialize Request |
| 218 | 1557 | | string _requestContent = null; |
| 218 | 1558 | | if(request != null) |
| | 1559 | | { |
| 218 | 1560 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(request, Client.SerializationSettin |
| 218 | 1561 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 218 | 1562 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1563 | | } |
| | 1564 | | // Set Credentials |
| 218 | 1565 | | if (Client.Credentials != null) |
| | 1566 | | { |
| 218 | 1567 | | cancellationToken.ThrowIfCancellationRequested(); |
| 218 | 1568 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1569 | | } |
| | 1570 | | // Send Request |
| 218 | 1571 | | if (_shouldTrace) |
| | 1572 | | { |
| 0 | 1573 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1574 | | } |
| 218 | 1575 | | cancellationToken.ThrowIfCancellationRequested(); |
| 218 | 1576 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 218 | 1577 | | if (_shouldTrace) |
| | 1578 | | { |
| 0 | 1579 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1580 | | } |
| 218 | 1581 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 218 | 1582 | | cancellationToken.ThrowIfCancellationRequested(); |
| 218 | 1583 | | string _responseContent = null; |
| 218 | 1584 | | if ((int)_statusCode != 200) |
| | 1585 | | { |
| 0 | 1586 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 1587 | | try |
| | 1588 | | { |
| 0 | 1589 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1590 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 1591 | | if (_errorBody != null) |
| | 1592 | | { |
| 0 | 1593 | | ex = new CloudException(_errorBody.Message); |
| 0 | 1594 | | ex.Body = _errorBody; |
| | 1595 | | } |
| 0 | 1596 | | } |
| 0 | 1597 | | catch (JsonException) |
| | 1598 | | { |
| | 1599 | | // Ignore the exception |
| 0 | 1600 | | } |
| 0 | 1601 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1602 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1603 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1604 | | { |
| 0 | 1605 | | ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1606 | | } |
| 0 | 1607 | | if (_shouldTrace) |
| | 1608 | | { |
| 0 | 1609 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1610 | | } |
| 0 | 1611 | | _httpRequest.Dispose(); |
| 0 | 1612 | | if (_httpResponse != null) |
| | 1613 | | { |
| 0 | 1614 | | _httpResponse.Dispose(); |
| | 1615 | | } |
| 0 | 1616 | | throw ex; |
| | 1617 | | } |
| | 1618 | | // Create Result |
| 218 | 1619 | | var _result = new AzureOperationResponse<AnalyzeResult>(); |
| 218 | 1620 | | _result.Request = _httpRequest; |
| 218 | 1621 | | _result.Response = _httpResponse; |
| 218 | 1622 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1623 | | { |
| 218 | 1624 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1625 | | } |
| | 1626 | | // Deserialize Response |
| 218 | 1627 | | if ((int)_statusCode == 200) |
| | 1628 | | { |
| 218 | 1629 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1630 | | try |
| | 1631 | | { |
| 218 | 1632 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AnalyzeResult>(_responseContent, |
| 218 | 1633 | | } |
| 0 | 1634 | | catch (JsonException ex) |
| | 1635 | | { |
| 0 | 1636 | | _httpRequest.Dispose(); |
| 0 | 1637 | | if (_httpResponse != null) |
| | 1638 | | { |
| 0 | 1639 | | _httpResponse.Dispose(); |
| | 1640 | | } |
| 0 | 1641 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1642 | | } |
| | 1643 | | } |
| 218 | 1644 | | if (_shouldTrace) |
| | 1645 | | { |
| 0 | 1646 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1647 | | } |
| 218 | 1648 | | return _result; |
| 218 | 1649 | | } |
| | 1650 | |
|
| | 1651 | | } |
| | 1652 | | } |