/// <param name='resourceId'> /// Required. The resource id. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public async Task <SkuListResponse> ListAvailableSkusAsync(string resourceId, CancellationToken cancellationToken) { // Validate if (resourceId == null) { throw new ArgumentNullException("resourceId"); } // Confirm resourceId is supported if (!IsSupportedResourceType(resourceId)) { throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Manual scaling not currently supported for resourceId {0}", resourceId)); } // Antares does not currently support the new contract and has no API to get all valid SKUs so these are hardcoded for now. SkuListResponse response = new SkuListResponse { StatusCode = HttpStatusCode.OK, Skus = new SkuCollection { Value = new List <Sku> { new Sku { Name = "S1", Tier = "Standard", Capacity = new Capacity() { Minimum = 1, Maximum = 10, Default = 1, ScaleType = SupportedScaleType.Automatic } }, new Sku { Name = "S2", Tier = "Standard", Capacity = new Capacity() { Minimum = 1, Maximum = 10, Default = 1, ScaleType = SupportedScaleType.Automatic } }, new Sku { Name = "S3", Tier = "Standard", Capacity = new Capacity() { Minimum = 1, Maximum = 10, Default = 1, ScaleType = SupportedScaleType.Automatic } }, new Sku { Name = "B1", Tier = "Basic", Capacity = new Capacity() { Minimum = 1, Maximum = 3, Default = 1, ScaleType = SupportedScaleType.Manual } }, new Sku { Name = "B2", Tier = "Basic", Capacity = new Capacity() { Minimum = 1, Maximum = 3, Default = 1, ScaleType = SupportedScaleType.Manual } }, new Sku { Name = "B3", Tier = "Basic", Capacity = new Capacity() { Minimum = 1, Maximum = 3, Default = 1, ScaleType = SupportedScaleType.Manual } }, new Sku { Name = "D1", Tier = "Shared", Capacity = new Capacity() { ScaleType = SupportedScaleType.None } }, new Sku { Name = "F1", Tier = "Free", Capacity = new Capacity() { ScaleType = SupportedScaleType.None } }, } } }; return(response); }
/// <param name='resourceId'> /// Required. The resource id. /// </param> /// <param name='apiVersion'> /// Required. The resource provider api version. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public async Task <SkuListResponse> ListSkuDefinitionsInternalAsync(string resourceId, string apiVersion, CancellationToken cancellationToken) { // Validate if (resourceId == null) { throw new ArgumentNullException("resourceId"); } if (apiVersion == null) { throw new ArgumentNullException("apiVersion"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceId", resourceId); tracingParameters.Add("apiVersion", apiVersion); TracingAdapter.Enter(invocationId, this, "ListSkuDefinitionsInternalAsync", tracingParameters); } // Construct URL string url = "/" + Uri.EscapeDataString(resourceId) + "/skuDefinitions?"; url = url + "api-version=" + Uri.EscapeDataString(apiVersion); string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("Accept", "application/json"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result SkuListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new SkuListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { SkuDefinition skuDefinitionInstance = new SkuDefinition(); result.Value.Add(skuDefinitionInstance); JToken skuValue = valueValue["sku"]; if (skuValue != null && skuValue.Type != JTokenType.Null) { Sku skuInstance = new Sku(); skuDefinitionInstance.Sku = skuInstance; JToken nameValue = skuValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); skuInstance.Name = nameInstance; } JToken tierValue = skuValue["tier"]; if (tierValue != null && tierValue.Type != JTokenType.Null) { string tierInstance = ((string)tierValue); skuInstance.Tier = tierInstance; } } JToken capacityValue = valueValue["capacity"]; if (capacityValue != null && capacityValue.Type != JTokenType.Null) { Capacity capacityInstance = new Capacity(); skuDefinitionInstance.Capacity = capacityInstance; JToken minimumValue = capacityValue["minimum"]; if (minimumValue != null && minimumValue.Type != JTokenType.Null) { int minimumInstance = ((int)minimumValue); capacityInstance.Minimum = minimumInstance; } JToken maximumValue = capacityValue["maximum"]; if (maximumValue != null && maximumValue.Type != JTokenType.Null) { int maximumInstance = ((int)maximumValue); capacityInstance.Maximum = maximumInstance; } JToken defaultValue = capacityValue["default"]; if (defaultValue != null && defaultValue.Type != JTokenType.Null) { int defaultInstance = ((int)defaultValue); capacityInstance.Default = defaultInstance; } JToken scaleTypeValue = capacityValue["scaleType"]; if (scaleTypeValue != null && scaleTypeValue.Type != JTokenType.Null) { SupportedScaleType scaleTypeInstance = ((SupportedScaleType)Enum.Parse(typeof(SupportedScaleType), ((string)scaleTypeValue), true)); capacityInstance.ScaleType = scaleTypeInstance; } } JToken displayValue = valueValue["display"]; if (displayValue != null && displayValue.Type != JTokenType.Null) { Display displayInstance = new Display(); skuDefinitionInstance.Display = displayInstance; JToken titleValue = displayValue["title"]; if (titleValue != null && titleValue.Type != JTokenType.Null) { string titleInstance = ((string)titleValue); displayInstance.Title = titleInstance; } } } } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }