// // Code generated by https://github.com/kubernetes-client/csharp/tree/master/gen/KubernetesGenerator // Changes may cause incorrect behavior and will be lost if the code is // regenerated. // namespace k8s { using Microsoft.Rest; using Microsoft.Rest.Serialization; using Models; using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using System.IO; using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; public partial class Kubernetes : ServiceClient, IKubernetes { /// /// The base URI of the service. /// public System.Uri BaseUri { get; set; } /// /// Gets or sets json serialization settings. /// public JsonSerializerSettings SerializationSettings { get; private set; } /// /// Gets or sets json deserialization settings. /// public JsonSerializerSettings DeserializationSettings { get; private set; } /// /// Subscription credentials which uniquely identify client subscription. /// public ServiceClientCredentials Credentials { get; private set; } /// /// Initializes a new instance of the Kubernetes class. /// /// /// HttpClient to be used /// /// /// True: will dispose the provided httpClient on calling Kubernetes.Dispose(). False: will not dispose provided httpClient protected Kubernetes(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClient) { Initialize(); } /// /// Initializes a new instance of the Kubernetes class. /// /// /// Optional. The delegating handlers to add to the http client pipeline. /// protected Kubernetes(params DelegatingHandler[] handlers) : base(handlers) { Initialize(); } /// /// Initializes a new instance of the Kubernetes class. /// /// /// Optional. The http client handler used to handle http transport. /// /// /// Optional. The delegating handlers to add to the http client pipeline. /// protected Kubernetes(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHandler, handlers) { Initialize(); } /// /// Initializes a new instance of the Kubernetes class. /// /// /// Optional. The base URI of the service. /// /// /// Optional. The delegating handlers to add to the http client pipeline. /// /// /// Thrown when a required parameter is null /// protected Kubernetes(System.Uri baseUri, params DelegatingHandler[] handlers) : this(handlers) { if (baseUri == null) { throw new System.ArgumentNullException("baseUri"); } BaseUri = baseUri; } /// /// Initializes a new instance of the Kubernetes class. /// /// /// Optional. The base URI of the service. /// /// /// Optional. The http client handler used to handle http transport. /// /// /// Optional. The delegating handlers to add to the http client pipeline. /// /// /// Thrown when a required parameter is null /// protected Kubernetes(System.Uri baseUri, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers) { if (baseUri == null) { throw new System.ArgumentNullException("baseUri"); } BaseUri = baseUri; } /// /// Initializes a new instance of the Kubernetes class. /// /// /// Required. Subscription credentials which uniquely identify client subscription. /// /// /// Optional. The delegating handlers to add to the http client pipeline. /// /// /// Thrown when a required parameter is null /// public Kubernetes(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(handlers) { if (credentials == null) { throw new System.ArgumentNullException("credentials"); } Credentials = credentials; if (Credentials != null) { Credentials.InitializeServiceClient(this); } } /// /// Initializes a new instance of the Kubernetes class. /// /// /// Required. Subscription credentials which uniquely identify client subscription. /// /// /// HttpClient to be used /// /// /// True: will dispose the provided httpClient on calling Kubernetes.Dispose(). False: will not dispose provided httpClient /// /// Thrown when a required parameter is null /// public Kubernetes(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient) : this(httpClient, disposeHttpClient) { if (credentials == null) { throw new System.ArgumentNullException("credentials"); } Credentials = credentials; if (Credentials != null) { Credentials.InitializeServiceClient(this); } } /// /// Initializes a new instance of the Kubernetes class. /// /// /// Required. Subscription credentials which uniquely identify client subscription. /// /// /// Optional. The http client handler used to handle http transport. /// /// /// Optional. The delegating handlers to add to the http client pipeline. /// /// /// Thrown when a required parameter is null /// public Kubernetes(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers) { if (credentials == null) { throw new System.ArgumentNullException("credentials"); } Credentials = credentials; if (Credentials != null) { Credentials.InitializeServiceClient(this); } } /// /// Initializes a new instance of the Kubernetes class. /// /// /// Optional. The base URI of the service. /// /// /// Required. Subscription credentials which uniquely identify client subscription. /// /// /// Optional. The delegating handlers to add to the http client pipeline. /// /// /// Thrown when a required parameter is null /// public Kubernetes(System.Uri baseUri, ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(handlers) { if (baseUri == null) { throw new System.ArgumentNullException("baseUri"); } if (credentials == null) { throw new System.ArgumentNullException("credentials"); } BaseUri = baseUri; Credentials = credentials; if (Credentials != null) { Credentials.InitializeServiceClient(this); } } /// /// Initializes a new instance of the Kubernetes class. /// /// /// Optional. The base URI of the service. /// /// /// Required. Subscription credentials which uniquely identify client subscription. /// /// /// Optional. The http client handler used to handle http transport. /// /// /// Optional. The delegating handlers to add to the http client pipeline. /// /// /// Thrown when a required parameter is null /// public Kubernetes(System.Uri baseUri, ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers) { if (baseUri == null) { throw new System.ArgumentNullException("baseUri"); } if (credentials == null) { throw new System.ArgumentNullException("credentials"); } BaseUri = baseUri; Credentials = credentials; if (Credentials != null) { Credentials.InitializeServiceClient(this); } } /// /// An optional partial-method to perform custom initialization. /// partial void CustomInitialize(); /// /// Initializes client properties. /// private void Initialize() { BaseUri = new System.Uri("http://localhost"); SerializationSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List { new Iso8601TimeSpanConverter() } }; DeserializationSettings = new JsonSerializerSettings { DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List { new Iso8601TimeSpanConverter() } }; CustomInitialize(); } {{#.}} /// public async Task"}}> {{GetMethodName operation "WithHttpMessagesAsync"}}( {{#operation.parameters}} {{GetDotNetType .}} {{GetDotNetName . "true"}}, {{/operation.parameters}} Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { {{#operation.parameters}} {{#isRequired}} if ({{GetDotNetName name}} == null) { throw new ValidationException(ValidationRules.CannotBeNull, "{{GetDotNetName name}}"); } {{/isRequired}} {{/operation.parameters}} // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary tracingParameters = new Dictionary(); {{#operation.parameters}} tracingParameters.Add("{{GetDotNetName name}}", {{GetDotNetName name}}); {{/operation.parameters}} tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "{{GetMethodName operation ""}}", tracingParameters); } // Construct URL var _baseUrl = BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{{path}}").ToString(); _url = _url.Replace("/apis//", "/api/"); {{#operation.parameters}} {{#IfKindIs . "path"}} _url = _url.Replace("{{AddCurly name}}", {{GetDotNetName name}}); {{/IfKindIs . "path"}} {{/operation.parameters}} List _queryParameters = new List(); {{#operation.parameters}} {{#IfKindIs . "query"}} if ({{GetDotNetName name}} != null) { _queryParameters.Add(string.Format("{{name}}={0}", {{EscapeDataString name type}})); } {{/IfKindIs . "query"}} {{/operation.parameters}} if (_queryParameters.Count > 0) { _url += "?" + string.Join("&", _queryParameters); } // Create HTTP transport var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = HttpMethod.{{Method}}; _httpRequest.RequestUri = new System.Uri(_url); _httpRequest.Version = HttpVersion.Version20; // Set Headers if (customHeaders != null) { foreach(var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; {{#operation.requestBody.isRequired}} if(body != null) { _requestContent = SafeJsonConvert.SerializeObject(body, SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = GetHeader(body); } {{/operation.requestBody.isRequired}} // Set Credentials if (Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await HttpClient.SendAsync(_httpRequest, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200 && (int)_statusCode != 201 && (int)_statusCode != 202) { var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); if (_httpResponse.Content != null) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); } else { _responseContent = string.Empty; } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse{{GetReturnType operation "<>"}}(); _result.Request = _httpRequest; _result.Response = _httpResponse; {{#IfReturnType operation "any"}} // Deserialize Response if ((int)_statusCode == 200 || (int)_statusCode == 201 || (int)_statusCode == 202) { {{#IfReturnType operation "stream"}} _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); {{/IfReturnType operation "stream"}} {{#IfReturnType operation "obj"}} {{#IfParamCotains operation "watch"}} if (watch == true) { _httpResponse.Content = new LineSeparatedHttpContent(_httpResponse.Content, cancellationToken); } {{/IfParamCotains operation "watch"}} _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = SafeJsonConvert.DeserializeObject{{GetReturnType operation "<>"}}(_responseContent, DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } {{/IfReturnType operation "obj"}} } {{/IfReturnType operation "any"}} if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return _result; } {{/.}} } }