public PSQuota(SubscriptionQuotas subscriptionQuotas) { if (subscriptionQuotas == null) { throw new ArgumentNullException("subscriptionQuotas"); } this.subscriptionQuotas = subscriptionQuotas; }
/// <summary> /// Get the stream analytics quotas of a subscription. /// </summary> /// <param name='location'> /// Required. The region that you want to check the quotas. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The response of the get stream analytics quotas operation. /// </returns> public async Task <SubscriptionQuotasGetResponse> GetQuotasAsync(string location, CancellationToken cancellationToken) { // Validate if (location == null) { throw new ArgumentNullException("location"); } // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("location", location); Tracing.Enter(invocationId, this, "GetQuotasAsync", tracingParameters); } // Construct URL string url = "/subscriptions/" + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId) + "/providers/Microsoft.StreamAnalytics/locations/" + Uri.EscapeDataString(location) + "/quotas?"; url = url + "api-version=2014-12-01-preview"; 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-client-request-id", Guid.NewGuid().ToString()); // 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)); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result SubscriptionQuotasGetResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new SubscriptionQuotasGetResponse(); 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)) { SubscriptionQuotas subscriptionQuotasInstance = new SubscriptionQuotas(); result.Value.Add(subscriptionQuotasInstance); JToken nameValue = valueValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); subscriptionQuotasInstance.Name = nameInstance; } JToken propertiesValue = valueValue["properties"]; if (propertiesValue != null && propertiesValue.Type != JTokenType.Null) { SubscriptionQuotasProperties propertiesInstance = new SubscriptionQuotasProperties(); subscriptionQuotasInstance.Properties = propertiesInstance; JToken maxCountValue = propertiesValue["maxCount"]; if (maxCountValue != null && maxCountValue.Type != JTokenType.Null) { int maxCountInstance = ((int)maxCountValue); propertiesInstance.MaxCount = maxCountInstance; } JToken currentCountValue = propertiesValue["currentCount"]; if (currentCountValue != null && currentCountValue.Type != JTokenType.Null) { int currentCountInstance = ((int)currentCountValue); propertiesInstance.CurrentCount = currentCountInstance; } } } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("Date")) { result.Date = DateTime.Parse(httpResponse.Headers.GetValues("Date").FirstOrDefault(), CultureInfo.InvariantCulture); } 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(); } } }
public PSQuota() { subscriptionQuotas = new SubscriptionQuotas(); }