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