/// <summary> /// Initializes a new instance of the Usage class. /// </summary> /// <param name="unit">Gets the unit of measurement. Possible values include: 'Count', 'Bytes', 'Seconds', 'Percent', 'CountsPerSecond', 'BytesPerSecond'</param> /// <param name="currentValue">Gets the current count of the allocated resources in the subscription.</param> /// <param name="limit">Gets the maximum count of the resources that can be allocated in the subscription.</param> /// <param name="name">Gets the name of the type of usage.</param> public Usage(UsageUnit unit, int currentValue, int limit, UsageName name) { Unit = unit; CurrentValue = currentValue; Limit = limit; Name = name; }
/// <summary> /// Initializes a new instance of the Usage class. /// </summary> /// <param name="unit">Gets the unit of measurement. Possible values /// include: 'Count', 'Bytes', 'Seconds', 'Percent', 'CountsPerSecond', /// 'BytesPerSecond'</param> /// <param name="currentValue">Gets the current count of the allocated /// resources in the subscription.</param> /// <param name="limit">Gets the maximum count of the resources that /// can be allocated in the subscription.</param> /// <param name="name">Gets the name of the type of usage.</param> public Usage(UsageUnit unit, int currentValue, int limit, UsageName name) { Unit = unit; CurrentValue = currentValue; Limit = limit; Name = name; }
internal static string ToSerializedValue(this UsageUnit value) { switch (value) { case UsageUnit.Count: return("Count"); case UsageUnit.Bytes: return("Bytes"); case UsageUnit.Seconds: return("Seconds"); case UsageUnit.Percent: return("Percent"); case UsageUnit.CountsPerSecond: return("CountsPerSecond"); case UsageUnit.BytesPerSecond: return("BytesPerSecond"); } return(null); }
/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param> /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param> /// <param name="formatProvider">not used by this TypeConverter.</param> /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param> /// <returns> /// an instance of <see cref="UsageUnit" />, or <c>null</c> if there is no suitable conversion. /// </returns> public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => UsageUnit.CreateFrom(sourceValue);
/// <summary> /// Lists compute usages for a subscription. /// </summary> /// <param name='location'> /// Required. The location upon which resource usage is queried. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The List Usages operation response. /// </returns> public async Task <ListUsagesResponse> ListAsync(string location, CancellationToken cancellationToken) { // Validate if (location == null) { throw new ArgumentNullException("location"); } if (location != null && location.Length > 1000) { throw new ArgumentOutOfRangeException("location"); } if (Regex.IsMatch(location, "^[-\\w\\._]+$") == false) { throw new ArgumentOutOfRangeException("location"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("location", location); TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/subscriptions/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/providers/"; url = url + "Microsoft.Compute"; url = url + "/locations/"; url = url + Uri.EscapeDataString(location); url = url + "/usages"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2015-06-15"); if (queryParameters.Count > 0) { url = url + "?" + string.Join("&", queryParameters); } 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 // 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 ListUsagesResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new ListUsagesResponse(); 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)) { Usage usageInstance = new Usage(); result.Usages.Add(usageInstance); JToken unitValue = valueValue["unit"]; if (unitValue != null && unitValue.Type != JTokenType.Null) { UsageUnit unitInstance = ((UsageUnit)Enum.Parse(typeof(UsageUnit), ((string)unitValue), true)); usageInstance.Unit = unitInstance; } JToken currentValueValue = valueValue["currentValue"]; if (currentValueValue != null && currentValueValue.Type != JTokenType.Null) { int currentValueInstance = ((int)currentValueValue); usageInstance.CurrentValue = currentValueInstance; } JToken limitValue = valueValue["limit"]; if (limitValue != null && limitValue.Type != JTokenType.Null) { uint limitInstance = ((uint)limitValue); usageInstance.Limit = limitInstance; } JToken nameValue = valueValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { UsageName nameInstance = new UsageName(); usageInstance.Name = nameInstance; JToken valueValue2 = nameValue["value"]; if (valueValue2 != null && valueValue2.Type != JTokenType.Null) { string valueInstance = ((string)valueValue2); nameInstance.Value = valueInstance; } JToken localizedValueValue = nameValue["localizedValue"]; if (localizedValueValue != null && localizedValueValue.Type != JTokenType.Null) { string localizedValueInstance = ((string)localizedValueValue); nameInstance.LocalizedValue = localizedValueInstance; } } } } } } 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(); } } }
public static string ToSerialString(this UsageUnit value) => value switch {