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