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