/// <summary> /// The List Role Sizes operation lists all of the role sizes that are /// valid for your subscription. /// </summary> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The List Role Sizes operation response. /// </returns> public async Task <RoleSizeListResponse> ListAsync(CancellationToken cancellationToken) { // Validate // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/rolesizes"; 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("x-ms-version", "2018-06-01"); // 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 RoleSizeListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new RoleSizeListResponse(); XDocument responseDoc = XDocument.Parse(responseContent); XElement roleSizesSequenceElement = responseDoc.Element(XName.Get("RoleSizes", "http://schemas.microsoft.com/windowsazure")); if (roleSizesSequenceElement != null) { foreach (XElement roleSizesElement in roleSizesSequenceElement.Elements(XName.Get("RoleSize", "http://schemas.microsoft.com/windowsazure"))) { RoleSizeListResponse.RoleSize roleSizeInstance = new RoleSizeListResponse.RoleSize(); result.RoleSizes.Add(roleSizeInstance); XElement nameElement = roleSizesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")); if (nameElement != null) { string nameInstance = nameElement.Value; roleSizeInstance.Name = nameInstance; } XElement labelElement = roleSizesElement.Element(XName.Get("Label", "http://schemas.microsoft.com/windowsazure")); if (labelElement != null) { string labelInstance = labelElement.Value; roleSizeInstance.Label = labelInstance; } XElement coresElement = roleSizesElement.Element(XName.Get("Cores", "http://schemas.microsoft.com/windowsazure")); if (coresElement != null) { int coresInstance = int.Parse(coresElement.Value, CultureInfo.InvariantCulture); roleSizeInstance.Cores = coresInstance; } XElement memoryInMbElement = roleSizesElement.Element(XName.Get("MemoryInMb", "http://schemas.microsoft.com/windowsazure")); if (memoryInMbElement != null) { int memoryInMbInstance = int.Parse(memoryInMbElement.Value, CultureInfo.InvariantCulture); roleSizeInstance.MemoryInMb = memoryInMbInstance; } XElement supportedByWebWorkerRolesElement = roleSizesElement.Element(XName.Get("SupportedByWebWorkerRoles", "http://schemas.microsoft.com/windowsazure")); if (supportedByWebWorkerRolesElement != null) { bool supportedByWebWorkerRolesInstance = bool.Parse(supportedByWebWorkerRolesElement.Value); roleSizeInstance.SupportedByWebWorkerRoles = supportedByWebWorkerRolesInstance; } XElement supportedByVirtualMachinesElement = roleSizesElement.Element(XName.Get("SupportedByVirtualMachines", "http://schemas.microsoft.com/windowsazure")); if (supportedByVirtualMachinesElement != null) { bool supportedByVirtualMachinesInstance = bool.Parse(supportedByVirtualMachinesElement.Value); roleSizeInstance.SupportedByVirtualMachines = supportedByVirtualMachinesInstance; } XElement maxDataDiskCountElement = roleSizesElement.Element(XName.Get("MaxDataDiskCount", "http://schemas.microsoft.com/windowsazure")); if (maxDataDiskCountElement != null) { int maxDataDiskCountInstance = int.Parse(maxDataDiskCountElement.Value, CultureInfo.InvariantCulture); roleSizeInstance.MaxDataDiskCount = maxDataDiskCountInstance; } XElement webWorkerResourceDiskSizeInMbElement = roleSizesElement.Element(XName.Get("WebWorkerResourceDiskSizeInMb", "http://schemas.microsoft.com/windowsazure")); if (webWorkerResourceDiskSizeInMbElement != null) { int webWorkerResourceDiskSizeInMbInstance = int.Parse(webWorkerResourceDiskSizeInMbElement.Value, CultureInfo.InvariantCulture); roleSizeInstance.WebWorkerResourceDiskSizeInMb = webWorkerResourceDiskSizeInMbInstance; } XElement virtualMachineResourceDiskSizeInMbElement = roleSizesElement.Element(XName.Get("VirtualMachineResourceDiskSizeInMb", "http://schemas.microsoft.com/windowsazure")); if (virtualMachineResourceDiskSizeInMbElement != null) { int virtualMachineResourceDiskSizeInMbInstance = int.Parse(virtualMachineResourceDiskSizeInMbElement.Value, CultureInfo.InvariantCulture); roleSizeInstance.VirtualMachineResourceDiskSizeInMb = virtualMachineResourceDiskSizeInMbInstance; } } } } 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(); } } }
/// <summary> /// The List Role Sizes operation lists all of the role sizes that are /// valid for your subscription. /// </summary> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The List Role Sizes operation response. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.Models.RoleSizeListResponse> ListAsync(CancellationToken cancellationToken) { // Validate // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); Tracing.Enter(invocationId, this, "ListAsync", tracingParameters); } // Construct URL string url = new Uri(this.Client.BaseUri, "/").AbsoluteUri + this.Client.Credentials.SubscriptionId + "/rolesizes"; // 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("x-ms-version", "2013-03-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { Tracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { Tracing.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), CloudExceptionType.Xml); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result RoleSizeListResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new RoleSizeListResponse(); XDocument responseDoc = XDocument.Parse(responseContent); XElement roleSizesSequenceElement = responseDoc.Element(XName.Get("RoleSizes", "http://schemas.microsoft.com/windowsazure")); if (roleSizesSequenceElement != null) { foreach (XElement roleSizesElement in roleSizesSequenceElement.Elements(XName.Get("RoleSize", "http://schemas.microsoft.com/windowsazure"))) { RoleSizeListResponse.RoleSize roleSizeInstance = new RoleSizeListResponse.RoleSize(); result.RoleSizes.Add(roleSizeInstance); XElement nameElement = roleSizesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")); if (nameElement != null) { string nameInstance = nameElement.Value; roleSizeInstance.Name = nameInstance; } XElement labelElement = roleSizesElement.Element(XName.Get("Label", "http://schemas.microsoft.com/windowsazure")); if (labelElement != null) { string labelInstance = labelElement.Value; roleSizeInstance.Label = labelInstance; } XElement coresElement = roleSizesElement.Element(XName.Get("Cores", "http://schemas.microsoft.com/windowsazure")); if (coresElement != null) { int coresInstance = int.Parse(coresElement.Value, CultureInfo.InvariantCulture); roleSizeInstance.Cores = coresInstance; } XElement memoryInMbElement = roleSizesElement.Element(XName.Get("MemoryInMb", "http://schemas.microsoft.com/windowsazure")); if (memoryInMbElement != null) { int memoryInMbInstance = int.Parse(memoryInMbElement.Value, CultureInfo.InvariantCulture); roleSizeInstance.MemoryInMb = memoryInMbInstance; } XElement supportedByWebWorkerRolesElement = roleSizesElement.Element(XName.Get("SupportedByWebWorkerRoles", "http://schemas.microsoft.com/windowsazure")); if (supportedByWebWorkerRolesElement != null) { bool supportedByWebWorkerRolesInstance = bool.Parse(supportedByWebWorkerRolesElement.Value); roleSizeInstance.SupportedByWebWorkerRoles = supportedByWebWorkerRolesInstance; } XElement supportedByVirtualMachinesElement = roleSizesElement.Element(XName.Get("SupportedByVirtualMachines", "http://schemas.microsoft.com/windowsazure")); if (supportedByVirtualMachinesElement != null) { bool supportedByVirtualMachinesInstance = bool.Parse(supportedByVirtualMachinesElement.Value); roleSizeInstance.SupportedByVirtualMachines = supportedByVirtualMachinesInstance; } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { Tracing.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }