| | 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 | | /// PrivateLinkResourcesOperations operations. |
| | 27 | | /// </summary> |
| | 28 | | internal partial class PrivateLinkResourcesOperations : IServiceOperations<SearchManagementClient>, IPrivateLinkReso |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the PrivateLinkResourcesOperations 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 PrivateLinkResourcesOperations(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> |
| 0 | 51 | | public SearchManagementClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Gets a list of all supported private link resource types for the given |
| | 55 | | /// service. |
| | 56 | | /// <see href="https://aka.ms/search-manage" /> |
| | 57 | | /// </summary> |
| | 58 | | /// <param name='resourceGroupName'> |
| | 59 | | /// The name of the resource group within the current subscription. You can |
| | 60 | | /// obtain this value from the Azure Resource Manager API or the portal. |
| | 61 | | /// </param> |
| | 62 | | /// <param name='searchServiceName'> |
| | 63 | | /// The name of the Azure Cognitive Search service associated with the |
| | 64 | | /// specified resource group. |
| | 65 | | /// </param> |
| | 66 | | /// <param name='searchManagementRequestOptions'> |
| | 67 | | /// Additional parameters for the operation |
| | 68 | | /// </param> |
| | 69 | | /// <param name='customHeaders'> |
| | 70 | | /// Headers that will be added to request. |
| | 71 | | /// </param> |
| | 72 | | /// <param name='cancellationToken'> |
| | 73 | | /// The cancellation token. |
| | 74 | | /// </param> |
| | 75 | | /// <exception cref="CloudException"> |
| | 76 | | /// Thrown when the operation returned an invalid status code |
| | 77 | | /// </exception> |
| | 78 | | /// <exception cref="SerializationException"> |
| | 79 | | /// Thrown when unable to deserialize the response |
| | 80 | | /// </exception> |
| | 81 | | /// <exception cref="ValidationException"> |
| | 82 | | /// Thrown when a required parameter is null |
| | 83 | | /// </exception> |
| | 84 | | /// <exception cref="System.ArgumentNullException"> |
| | 85 | | /// Thrown when a required parameter is null |
| | 86 | | /// </exception> |
| | 87 | | /// <return> |
| | 88 | | /// A response object containing the response body and response headers. |
| | 89 | | /// </return> |
| | 90 | | public async Task<AzureOperationResponse<IEnumerable<PrivateLinkResource>>> ListSupportedWithHttpMessagesAsync(s |
| | 91 | | { |
| 0 | 92 | | if (Client.ApiVersion == null) |
| | 93 | | { |
| 0 | 94 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 95 | | } |
| 0 | 96 | | if (Client.SubscriptionId == null) |
| | 97 | | { |
| 0 | 98 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); |
| | 99 | | } |
| 0 | 100 | | if (resourceGroupName == null) |
| | 101 | | { |
| 0 | 102 | | throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); |
| | 103 | | } |
| 0 | 104 | | if (searchServiceName == null) |
| | 105 | | { |
| 0 | 106 | | throw new ValidationException(ValidationRules.CannotBeNull, "searchServiceName"); |
| | 107 | | } |
| 0 | 108 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 109 | | if (searchManagementRequestOptions != null) |
| | 110 | | { |
| 0 | 111 | | clientRequestId = searchManagementRequestOptions.ClientRequestId; |
| | 112 | | } |
| | 113 | | // Tracing |
| 0 | 114 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 115 | | string _invocationId = null; |
| 0 | 116 | | if (_shouldTrace) |
| | 117 | | { |
| 0 | 118 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 119 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 120 | | tracingParameters.Add("resourceGroupName", resourceGroupName); |
| 0 | 121 | | tracingParameters.Add("searchServiceName", searchServiceName); |
| 0 | 122 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 123 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 124 | | ServiceClientTracing.Enter(_invocationId, this, "ListSupported", tracingParameters); |
| | 125 | | } |
| | 126 | | // Construct URL |
| 0 | 127 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 128 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{su |
| 0 | 129 | | _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); |
| 0 | 130 | | _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); |
| 0 | 131 | | _url = _url.Replace("{searchServiceName}", System.Uri.EscapeDataString(searchServiceName)); |
| 0 | 132 | | List<string> _queryParameters = new List<string>(); |
| 0 | 133 | | if (Client.ApiVersion != null) |
| | 134 | | { |
| 0 | 135 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 136 | | } |
| 0 | 137 | | if (_queryParameters.Count > 0) |
| | 138 | | { |
| 0 | 139 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 140 | | } |
| | 141 | | // Create HTTP transport objects |
| 0 | 142 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 143 | | HttpResponseMessage _httpResponse = null; |
| 0 | 144 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 145 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 146 | | // Set Headers |
| 0 | 147 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 148 | | { |
| 0 | 149 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 150 | | } |
| 0 | 151 | | if (Client.AcceptLanguage != null) |
| | 152 | | { |
| 0 | 153 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 154 | | { |
| 0 | 155 | | _httpRequest.Headers.Remove("accept-language"); |
| | 156 | | } |
| 0 | 157 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 158 | | } |
| 0 | 159 | | if (clientRequestId != null) |
| | 160 | | { |
| 0 | 161 | | if (_httpRequest.Headers.Contains("x-ms-client-request-id")) |
| | 162 | | { |
| 0 | 163 | | _httpRequest.Headers.Remove("x-ms-client-request-id"); |
| | 164 | | } |
| 0 | 165 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Rest.Serialization.SafeJsonConver |
| | 166 | | } |
| | 167 | |
|
| | 168 | |
|
| 0 | 169 | | if (customHeaders != null) |
| | 170 | | { |
| 0 | 171 | | foreach(var _header in customHeaders) |
| | 172 | | { |
| 0 | 173 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 174 | | { |
| 0 | 175 | | _httpRequest.Headers.Remove(_header.Key); |
| | 176 | | } |
| 0 | 177 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 178 | | } |
| | 179 | | } |
| | 180 | |
|
| | 181 | | // Serialize Request |
| 0 | 182 | | string _requestContent = null; |
| | 183 | | // Set Credentials |
| 0 | 184 | | if (Client.Credentials != null) |
| | 185 | | { |
| 0 | 186 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 187 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 188 | | } |
| | 189 | | // Send Request |
| 0 | 190 | | if (_shouldTrace) |
| | 191 | | { |
| 0 | 192 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 193 | | } |
| 0 | 194 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 195 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 196 | | if (_shouldTrace) |
| | 197 | | { |
| 0 | 198 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 199 | | } |
| 0 | 200 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 201 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 202 | | string _responseContent = null; |
| 0 | 203 | | if ((int)_statusCode != 200) |
| | 204 | | { |
| 0 | 205 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 206 | | try |
| | 207 | | { |
| 0 | 208 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 209 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 210 | | if (_errorBody != null) |
| | 211 | | { |
| 0 | 212 | | ex = new CloudException(_errorBody.Message); |
| 0 | 213 | | ex.Body = _errorBody; |
| | 214 | | } |
| 0 | 215 | | } |
| 0 | 216 | | catch (JsonException) |
| | 217 | | { |
| | 218 | | // Ignore the exception |
| 0 | 219 | | } |
| 0 | 220 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 221 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 222 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 223 | | { |
| 0 | 224 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 225 | | } |
| 0 | 226 | | if (_shouldTrace) |
| | 227 | | { |
| 0 | 228 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 229 | | } |
| 0 | 230 | | _httpRequest.Dispose(); |
| 0 | 231 | | if (_httpResponse != null) |
| | 232 | | { |
| 0 | 233 | | _httpResponse.Dispose(); |
| | 234 | | } |
| 0 | 235 | | throw ex; |
| | 236 | | } |
| | 237 | | // Create Result |
| 0 | 238 | | var _result = new AzureOperationResponse<IEnumerable<PrivateLinkResource>>(); |
| 0 | 239 | | _result.Request = _httpRequest; |
| 0 | 240 | | _result.Response = _httpResponse; |
| 0 | 241 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 242 | | { |
| 0 | 243 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 244 | | } |
| | 245 | | // Deserialize Response |
| 0 | 246 | | if ((int)_statusCode == 200) |
| | 247 | | { |
| 0 | 248 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 249 | | try |
| | 250 | | { |
| 0 | 251 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<PrivateLinkResource>>(_resp |
| 0 | 252 | | } |
| 0 | 253 | | catch (JsonException ex) |
| | 254 | | { |
| 0 | 255 | | _httpRequest.Dispose(); |
| 0 | 256 | | if (_httpResponse != null) |
| | 257 | | { |
| 0 | 258 | | _httpResponse.Dispose(); |
| | 259 | | } |
| 0 | 260 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 261 | | } |
| | 262 | | } |
| 0 | 263 | | if (_shouldTrace) |
| | 264 | | { |
| 0 | 265 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 266 | | } |
| 0 | 267 | | return _result; |
| 0 | 268 | | } |
| | 269 | |
|
| | 270 | | } |
| | 271 | | } |