| | 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.ContainerRegistry |
| | 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 | | /// V2SupportOperations operations. |
| | 27 | | /// </summary> |
| | 28 | | internal partial class V2SupportOperations : IServiceOperations<AzureContainerRegistryClient>, IV2SupportOperations |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the V2SupportOperations 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> |
| 60 | 39 | | internal V2SupportOperations(AzureContainerRegistryClient client) |
| | 40 | | { |
| 60 | 41 | | if (client == null) |
| | 42 | | { |
| 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | 44 | | } |
| 60 | 45 | | Client = client; |
| 60 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Gets a reference to the AzureContainerRegistryClient |
| | 50 | | /// </summary> |
| 0 | 51 | | public AzureContainerRegistryClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Tells whether this Docker Registry instance supports Docker Registry HTTP |
| | 55 | | /// API v2 |
| | 56 | | /// </summary> |
| | 57 | | /// <param name='customHeaders'> |
| | 58 | | /// Headers that will be added to request. |
| | 59 | | /// </param> |
| | 60 | | /// <param name='cancellationToken'> |
| | 61 | | /// The cancellation token. |
| | 62 | | /// </param> |
| | 63 | | /// <exception cref="AcrErrorsException"> |
| | 64 | | /// Thrown when the operation returned an invalid status code |
| | 65 | | /// </exception> |
| | 66 | | /// <exception cref="ValidationException"> |
| | 67 | | /// Thrown when a required parameter is null |
| | 68 | | /// </exception> |
| | 69 | | /// <exception cref="System.ArgumentNullException"> |
| | 70 | | /// Thrown when a required parameter is null |
| | 71 | | /// </exception> |
| | 72 | | /// <return> |
| | 73 | | /// A response object containing the response body and response headers. |
| | 74 | | /// </return> |
| | 75 | | public async Task<AzureOperationResponse> CheckWithHttpMessagesAsync(Dictionary<string, List<string>> customHead |
| | 76 | | { |
| 0 | 77 | | if (Client.LoginUri == null) |
| | 78 | | { |
| 0 | 79 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri"); |
| | 80 | | } |
| | 81 | | // Tracing |
| 0 | 82 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 83 | | string _invocationId = null; |
| 0 | 84 | | if (_shouldTrace) |
| | 85 | | { |
| 0 | 86 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 87 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 88 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 89 | | ServiceClientTracing.Enter(_invocationId, this, "Check", tracingParameters); |
| | 90 | | } |
| | 91 | | // Construct URL |
| 0 | 92 | | var _baseUrl = Client.BaseUri; |
| 0 | 93 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v2/"; |
| 0 | 94 | | _url = _url.Replace("{url}", Client.LoginUri); |
| 0 | 95 | | List<string> _queryParameters = new List<string>(); |
| 0 | 96 | | if (_queryParameters.Count > 0) |
| | 97 | | { |
| 0 | 98 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 99 | | } |
| | 100 | | // Create HTTP transport objects |
| 0 | 101 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 102 | | HttpResponseMessage _httpResponse = null; |
| 0 | 103 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 104 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 105 | | // Set Headers |
| 0 | 106 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 107 | | { |
| 0 | 108 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 109 | | } |
| 0 | 110 | | if (Client.AcceptLanguage != null) |
| | 111 | | { |
| 0 | 112 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 113 | | { |
| 0 | 114 | | _httpRequest.Headers.Remove("accept-language"); |
| | 115 | | } |
| 0 | 116 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 117 | | } |
| | 118 | |
|
| | 119 | |
|
| 0 | 120 | | if (customHeaders != null) |
| | 121 | | { |
| 0 | 122 | | foreach(var _header in customHeaders) |
| | 123 | | { |
| 0 | 124 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 125 | | { |
| 0 | 126 | | _httpRequest.Headers.Remove(_header.Key); |
| | 127 | | } |
| 0 | 128 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 129 | | } |
| | 130 | | } |
| | 131 | |
|
| | 132 | | // Serialize Request |
| 0 | 133 | | string _requestContent = null; |
| | 134 | | // Set Credentials |
| 0 | 135 | | if (Client.Credentials != null) |
| | 136 | | { |
| 0 | 137 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 138 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 139 | | } |
| | 140 | | // Send Request |
| 0 | 141 | | if (_shouldTrace) |
| | 142 | | { |
| 0 | 143 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 144 | | } |
| 0 | 145 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 146 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 147 | | if (_shouldTrace) |
| | 148 | | { |
| 0 | 149 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 150 | | } |
| 0 | 151 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 152 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 153 | | string _responseContent = null; |
| 0 | 154 | | if ((int)_statusCode != 200) |
| | 155 | | { |
| 0 | 156 | | var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _status |
| | 157 | | try |
| | 158 | | { |
| 0 | 159 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 160 | | AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<AcrErrors>(_responseCon |
| 0 | 161 | | if (_errorBody != null) |
| | 162 | | { |
| 0 | 163 | | ex.Body = _errorBody; |
| | 164 | | } |
| 0 | 165 | | } |
| 0 | 166 | | catch (JsonException) |
| | 167 | | { |
| | 168 | | // Ignore the exception |
| 0 | 169 | | } |
| 0 | 170 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 171 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 172 | | if (_shouldTrace) |
| | 173 | | { |
| 0 | 174 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 175 | | } |
| 0 | 176 | | _httpRequest.Dispose(); |
| 0 | 177 | | if (_httpResponse != null) |
| | 178 | | { |
| 0 | 179 | | _httpResponse.Dispose(); |
| | 180 | | } |
| 0 | 181 | | throw ex; |
| | 182 | | } |
| | 183 | | // Create Result |
| 0 | 184 | | var _result = new AzureOperationResponse(); |
| 0 | 185 | | _result.Request = _httpRequest; |
| 0 | 186 | | _result.Response = _httpResponse; |
| 0 | 187 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 188 | | { |
| 0 | 189 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 190 | | } |
| 0 | 191 | | if (_shouldTrace) |
| | 192 | | { |
| 0 | 193 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 194 | | } |
| 0 | 195 | | return _result; |
| 0 | 196 | | } |
| | 197 | |
|
| | 198 | | } |
| | 199 | | } |