private static void AreEqual(MetricAvailability exp, MetricAvailability act) { if (exp != null) { Assert.AreEqual(exp.Retention, act.Retention); Assert.AreEqual(exp.TimeGrain, act.TimeGrain); } }
private static bool IsShoebox(MetricDefinition definition, TimeSpan timeGrain) { MetricAvailability availability = definition.MetricAvailabilities.FirstOrDefault(a => a.TimeGrain.Equals(timeGrain)); if (availability == null) { throw new InvalidOperationException(string.Format( CultureInfo.InvariantCulture, "MetricDefinition for {0} does not contain an availability with timegrain {1}", definition.Name.Value, timeGrain)); } return(availability.Location != null); }
/// <summary> /// A string representation of the MetricAvailability including indentation /// </summary> /// <param name="metricAvailability">The MetricAvailability object</param> /// <param name="indentationTabs">The number of tabs to insert in front of each member</param> /// <returns>A string representation of the MetricAvailability including indentation</returns> public static string ToString(this MetricAvailability metricAvailability, int indentationTabs) { StringBuilder output = new StringBuilder(); if (metricAvailability != null) { output.AppendLine(); output.AddSpacesInFront(indentationTabs).AppendLine("Location : " + metricAvailability.Location.ToString(indentationTabs: indentationTabs + 1)); output.AddSpacesInFront(indentationTabs).AppendLine("Retention : " + metricAvailability.Retention); output.AddSpacesInFront(indentationTabs).Append("Values : " + metricAvailability.TimeGrain); } return(output.ToString()); }
private static bool IsBlobSasMetric(MetricDefinition definition, TimeSpan timeGrain) { MetricAvailability availability = definition.MetricAvailabilities.FirstOrDefault(a => a.TimeGrain.Equals(timeGrain)); // Definition has requested availability, Location is null (non-SAS) or contains SAS key if (availability != null) { return(availability.BlobLocation != null); } // Definition has availabilities, but none with the requested timegrain (Bad request) if (definition.MetricAvailabilities.Any()) { throw new InvalidOperationException(string.Format( CultureInfo.InvariantCulture, "MetricDefinition for {0} does not contain an availability with timegrain {1}", definition.Name.Value, timeGrain)); } // Definition has no availablilities (metrics are not configured for this resource), return empty metrics (non-SAS) return(false); }
/// <summary> /// The List Metric Definitions operation lists the metric definitions /// for the resource. /// </summary> /// <param name='resourceId'> /// Required. The id of the resource.The resource id can be built using /// the resource id builder class under utilities /// </param> /// <param name='metricNames'> /// Optional. The names of the metrics. /// </param> /// <param name='metricNamespace'> /// Required. The namespace of the metrics.The value is either null or /// WindowsAzure.Availability.WindowsAzure.Availability returns the /// metric definitions for endpoint monitoring metrics /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The List Metric Definitions operation response. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.Monitoring.Metrics.Models.MetricDefinitionListResponse> ListAsync(string resourceId, IList <string> metricNames, string metricNamespace, CancellationToken cancellationToken) { // Validate if (resourceId == null) { throw new ArgumentNullException("resourceId"); } // 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("resourceId", resourceId); tracingParameters.Add("metricNames", metricNames); tracingParameters.Add("metricNamespace", metricNamespace); Tracing.Enter(invocationId, this, "ListAsync", tracingParameters); } // Construct URL string baseUrl = this.Client.BaseUri.AbsoluteUri; string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/monitoring/metricdefinitions/query?"; url = url + "&resourceId=" + Uri.EscapeUriString(resourceId.Trim()); if (metricNamespace != null) { url = url + "&namespace=" + Uri.EscapeUriString(metricNamespace != null ? metricNamespace.Trim() : ""); } if (metricNames != null && metricNames.Count > 0) { url = url + "&names=" + Uri.EscapeUriString(string.Join(",", metricNames)); } // 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; // 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"); httpRequest.Headers.Add("x-ms-version", "2013-10-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.Json); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result MetricDefinitionListResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new MetricDefinitionListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { MetricDefinitionCollection metricDefinitionCollectionInstance = new MetricDefinitionCollection(); result.MetricDefinitionCollection = metricDefinitionCollectionInstance; JToken valueArray = responseDoc["Value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { MetricDefinition metricDefinitionInstance = new MetricDefinition(); metricDefinitionCollectionInstance.Value.Add(metricDefinitionInstance); JToken nameValue = valueValue["Name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); metricDefinitionInstance.Name = nameInstance; } JToken namespaceValue = valueValue["Namespace"]; if (namespaceValue != null && namespaceValue.Type != JTokenType.Null) { string namespaceInstance = ((string)namespaceValue); metricDefinitionInstance.Namespace = namespaceInstance; } JToken resourceIdSuffixValue = valueValue["ResourceIdSuffix"]; if (resourceIdSuffixValue != null && resourceIdSuffixValue.Type != JTokenType.Null) { string resourceIdSuffixInstance = ((string)resourceIdSuffixValue); metricDefinitionInstance.ResourceIdSuffix = resourceIdSuffixInstance; } JToken displayNameValue = valueValue["DisplayName"]; if (displayNameValue != null && displayNameValue.Type != JTokenType.Null) { string displayNameInstance = ((string)displayNameValue); metricDefinitionInstance.DisplayName = displayNameInstance; } JToken unitValue = valueValue["Unit"]; if (unitValue != null && unitValue.Type != JTokenType.Null) { string unitInstance = ((string)unitValue); metricDefinitionInstance.Unit = unitInstance; } JToken primaryAggregationValue = valueValue["PrimaryAggregation"]; if (primaryAggregationValue != null && primaryAggregationValue.Type != JTokenType.Null) { string primaryAggregationInstance = ((string)primaryAggregationValue); metricDefinitionInstance.PrimaryAggregation = primaryAggregationInstance; } JToken metricAvailabilitiesArray = valueValue["MetricAvailabilities"]; if (metricAvailabilitiesArray != null && metricAvailabilitiesArray.Type != JTokenType.Null) { foreach (JToken metricAvailabilitiesValue in ((JArray)metricAvailabilitiesArray)) { MetricAvailability metricAvailabilityInstance = new MetricAvailability(); metricDefinitionInstance.MetricAvailabilities.Add(metricAvailabilityInstance); JToken timeGrainValue = metricAvailabilitiesValue["TimeGrain"]; if (timeGrainValue != null && timeGrainValue.Type != JTokenType.Null) { TimeSpan timeGrainInstance = TypeConversion.From8601TimeSpan(((string)timeGrainValue)); metricAvailabilityInstance.TimeGrain = timeGrainInstance; } JToken retentionValue = metricAvailabilitiesValue["Retention"]; if (retentionValue != null && retentionValue.Type != JTokenType.Null) { TimeSpan retentionInstance = TypeConversion.From8601TimeSpan(((string)retentionValue)); metricAvailabilityInstance.Retention = retentionInstance; } } } JToken minimumAlertableTimeWindowValue = valueValue["MinimumAlertableTimeWindow"]; if (minimumAlertableTimeWindowValue != null && minimumAlertableTimeWindowValue.Type != JTokenType.Null) { TimeSpan minimumAlertableTimeWindowInstance = TypeConversion.From8601TimeSpan(((string)minimumAlertableTimeWindowValue)); metricDefinitionInstance.MinimumAlertableTimeWindow = minimumAlertableTimeWindowInstance; } JToken isAlertableValue = valueValue["IsAlertable"]; if (isAlertableValue != null && isAlertableValue.Type != JTokenType.Null) { bool isAlertableInstance = ((bool)isAlertableValue); metricDefinitionInstance.IsAlertable = isAlertableInstance; } } } } 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(); } } }
/// <summary> /// The List Metric Definitions operation lists the metric definitions /// for the resource. /// </summary> /// <param name='resourceUri'> /// Required. The resource identifier of the target resource to get /// metrics for. /// </param> /// <param name='filterString'> /// Optional. An OData $filter expression that supports querying by the /// name of the metric definition. For example, "name.value eq /// 'Percentage CPU'". Name is optional, meaning the expression may be /// "". /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The List Metric Definitions operation response. /// </returns> public async Task <MetricDefinitionListResponse> GetMetricDefinitionsAsync(string resourceUri, string filterString, CancellationToken cancellationToken) { // Validate if (resourceUri == null) { throw new ArgumentNullException("resourceUri"); } // 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("resourceUri", resourceUri); tracingParameters.Add("filterString", filterString); Tracing.Enter(invocationId, this, "GetMetricDefinitionsAsync", tracingParameters); } // Construct URL string url = "/" + resourceUri.Trim() + "/metricDefinitions?"; url = url + "api-version=2014-04-01"; if (filterString != null) { url = url + "&$filter=" + Uri.EscapeDataString(filterString != null ? filterString.Trim() : ""); } 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"); httpRequest.Headers.Add("x-ms-version", "2014-04-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)); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result MetricDefinitionListResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new MetricDefinitionListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { MetricDefinitionCollection metricDefinitionCollectionInstance = new MetricDefinitionCollection(); result.MetricDefinitionCollection = metricDefinitionCollectionInstance; JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { MetricDefinition metricDefinitionInstance = new MetricDefinition(); metricDefinitionCollectionInstance.Value.Add(metricDefinitionInstance); JToken nameValue = valueValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { LocalizableString nameInstance = new LocalizableString(); metricDefinitionInstance.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; } } JToken unitValue = valueValue["unit"]; if (unitValue != null && unitValue.Type != JTokenType.Null) { Unit unitInstance = ((Unit)Enum.Parse(typeof(Unit), ((string)unitValue), true)); metricDefinitionInstance.Unit = unitInstance; } JToken primaryAggregationTypeValue = valueValue["primaryAggregationType"]; if (primaryAggregationTypeValue != null && primaryAggregationTypeValue.Type != JTokenType.Null) { AggregationType primaryAggregationTypeInstance = ((AggregationType)Enum.Parse(typeof(AggregationType), ((string)primaryAggregationTypeValue), true)); metricDefinitionInstance.PrimaryAggregationType = primaryAggregationTypeInstance; } JToken resourceUriValue = valueValue["resourceUri"]; if (resourceUriValue != null && resourceUriValue.Type != JTokenType.Null) { string resourceUriInstance = ((string)resourceUriValue); metricDefinitionInstance.ResourceUri = resourceUriInstance; } JToken metricAvailabilitiesArray = valueValue["metricAvailabilities"]; if (metricAvailabilitiesArray != null && metricAvailabilitiesArray.Type != JTokenType.Null) { foreach (JToken metricAvailabilitiesValue in ((JArray)metricAvailabilitiesArray)) { MetricAvailability metricAvailabilityInstance = new MetricAvailability(); metricDefinitionInstance.MetricAvailabilities.Add(metricAvailabilityInstance); JToken timeGrainValue = metricAvailabilitiesValue["timeGrain"]; if (timeGrainValue != null && timeGrainValue.Type != JTokenType.Null) { TimeSpan timeGrainInstance = TypeConversion.From8601TimeSpan(((string)timeGrainValue)); metricAvailabilityInstance.TimeGrain = timeGrainInstance; } JToken retentionValue = metricAvailabilitiesValue["retention"]; if (retentionValue != null && retentionValue.Type != JTokenType.Null) { TimeSpan retentionInstance = TypeConversion.From8601TimeSpan(((string)retentionValue)); metricAvailabilityInstance.Retention = retentionInstance; } JToken locationValue = metricAvailabilitiesValue["location"]; if (locationValue != null && locationValue.Type != JTokenType.Null) { MetricLocation locationInstance = new MetricLocation(); metricAvailabilityInstance.Location = locationInstance; JToken tableEndpointValue = locationValue["tableEndpoint"]; if (tableEndpointValue != null && tableEndpointValue.Type != JTokenType.Null) { string tableEndpointInstance = ((string)tableEndpointValue); locationInstance.TableEndpoint = tableEndpointInstance; } JToken tableInfoArray = locationValue["tableInfo"]; if (tableInfoArray != null && tableInfoArray.Type != JTokenType.Null) { foreach (JToken tableInfoValue in ((JArray)tableInfoArray)) { MetricTableInfo metricTableInfoInstance = new MetricTableInfo(); locationInstance.TableInfo.Add(metricTableInfoInstance); JToken tableNameValue = tableInfoValue["tableName"]; if (tableNameValue != null && tableNameValue.Type != JTokenType.Null) { string tableNameInstance = ((string)tableNameValue); metricTableInfoInstance.TableName = tableNameInstance; } JToken startTimeValue = tableInfoValue["startTime"]; if (startTimeValue != null && startTimeValue.Type != JTokenType.Null) { DateTime startTimeInstance = ((DateTime)startTimeValue); metricTableInfoInstance.StartTime = startTimeInstance; } JToken endTimeValue = tableInfoValue["endTime"]; if (endTimeValue != null && endTimeValue.Type != JTokenType.Null) { DateTime endTimeInstance = ((DateTime)endTimeValue); metricTableInfoInstance.EndTime = endTimeInstance; } JToken sasTokenValue = tableInfoValue["sasToken"]; if (sasTokenValue != null && sasTokenValue.Type != JTokenType.Null) { string sasTokenInstance = ((string)sasTokenValue); metricTableInfoInstance.SasToken = sasTokenInstance; } JToken sasTokenExpirationTimeValue = tableInfoValue["sasTokenExpirationTime"]; if (sasTokenExpirationTimeValue != null && sasTokenExpirationTimeValue.Type != JTokenType.Null) { DateTime sasTokenExpirationTimeInstance = ((DateTime)sasTokenExpirationTimeValue); metricTableInfoInstance.SasTokenExpirationTime = sasTokenExpirationTimeInstance; } } } JToken partitionKeyValue = locationValue["partitionKey"]; if (partitionKeyValue != null && partitionKeyValue.Type != JTokenType.Null) { string partitionKeyInstance = ((string)partitionKeyValue); locationInstance.PartitionKey = partitionKeyInstance; } } } } JToken propertiesSequenceElement = ((JToken)valueValue["properties"]); if (propertiesSequenceElement != null && propertiesSequenceElement.Type != JTokenType.Null) { foreach (JProperty property in propertiesSequenceElement) { string propertiesKey = ((string)property.Name); string propertiesValue = ((string)property.Value); metricDefinitionInstance.Properties.Add(propertiesKey, propertiesValue); } } } } } 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(); } } }
/// <summary> /// The List Metric Definitions operation lists the metric definitions /// for the resource. /// </summary> /// <param name='resourceUri'> /// Required. The resource identifier of the target resource to get /// metrics for. /// </param> /// <param name='filterString'> /// Optional. An OData $filter expression that supports querying by the /// name of the metric definition. For example, "name.value eq /// 'Percentage CPU'". Name is optional, meaning the expression may be /// "". /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The List Metric Definitions operation response. /// </returns> internal async Task <MetricDefinitionListResponse> GetMetricDefinitionsInternalAsync(string resourceUri, string filterString, CancellationToken cancellationToken) { // Validate if (resourceUri == null) { throw new ArgumentNullException("resourceUri"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceUri", resourceUri); tracingParameters.Add("filterString", filterString); TracingAdapter.Enter(invocationId, this, "GetMetricDefinitionsAsync", tracingParameters); } #region Manually added // We need to handle document db differently for now until they onboard to shoebox. // Construct URL string url = ""; url = url + "/"; url = url + resourceUri; List <string> queryParameters = new List <string>(); if (Util.IsLegacyResource(resourceUri)) { url = url + "/metricDefinitions"; queryParameters.Add("api-version=2014-04-01"); } else { url = url + "/providers/microsoft.insights/metricDefinitions"; queryParameters.Add("api-version=2015-07-01"); } #endregion List <string> odataFilter = new List <string>(); if (filterString != null) { odataFilter.Add(Uri.EscapeDataString(filterString)); } if (odataFilter.Count > 0) { queryParameters.Add("$filter=" + string.Join(null, odataFilter)); } 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 httpRequest.Headers.Add("Accept", "application/json"); httpRequest.Headers.Add("x-ms-version", "2014-04-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 MetricDefinitionListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new MetricDefinitionListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { MetricDefinitionCollection metricDefinitionCollectionInstance = new MetricDefinitionCollection(); result.MetricDefinitionCollection = metricDefinitionCollectionInstance; JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { MetricDefinition metricDefinitionInstance = new MetricDefinition(); metricDefinitionCollectionInstance.Value.Add(metricDefinitionInstance); JToken nameValue = valueValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { LocalizableString nameInstance = new LocalizableString(); metricDefinitionInstance.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; } } JToken unitValue = valueValue["unit"]; if (unitValue != null && unitValue.Type != JTokenType.Null) { Unit unitInstance = ((Unit)Enum.Parse(typeof(Unit), ((string)unitValue), true)); metricDefinitionInstance.Unit = unitInstance; } JToken primaryAggregationTypeValue = valueValue["primaryAggregationType"]; if (primaryAggregationTypeValue != null && primaryAggregationTypeValue.Type != JTokenType.Null) { AggregationType primaryAggregationTypeInstance = ((AggregationType)Enum.Parse(typeof(AggregationType), ((string)primaryAggregationTypeValue), true)); metricDefinitionInstance.PrimaryAggregationType = primaryAggregationTypeInstance; } JToken resourceUriValue = valueValue["resourceUri"]; if (resourceUriValue != null && resourceUriValue.Type != JTokenType.Null) { string resourceUriInstance = ((string)resourceUriValue); metricDefinitionInstance.ResourceId = resourceUriInstance; } JToken metricAvailabilitiesArray = valueValue["metricAvailabilities"]; if (metricAvailabilitiesArray != null && metricAvailabilitiesArray.Type != JTokenType.Null) { foreach (JToken metricAvailabilitiesValue in ((JArray)metricAvailabilitiesArray)) { MetricAvailability metricAvailabilityInstance = new MetricAvailability(); metricDefinitionInstance.MetricAvailabilities.Add(metricAvailabilityInstance); JToken timeGrainValue = metricAvailabilitiesValue["timeGrain"]; if (timeGrainValue != null && timeGrainValue.Type != JTokenType.Null) { TimeSpan timeGrainInstance = XmlConvert.ToTimeSpan(((string)timeGrainValue)); metricAvailabilityInstance.TimeGrain = timeGrainInstance; } JToken retentionValue = metricAvailabilitiesValue["retention"]; if (retentionValue != null && retentionValue.Type != JTokenType.Null) { TimeSpan retentionInstance = XmlConvert.ToTimeSpan(((string)retentionValue)); metricAvailabilityInstance.Retention = retentionInstance; } JToken locationValue = metricAvailabilitiesValue["location"]; if (locationValue != null && locationValue.Type != JTokenType.Null) { MetricLocation locationInstance = new MetricLocation(); metricAvailabilityInstance.Location = locationInstance; JToken tableEndpointValue = locationValue["tableEndpoint"]; if (tableEndpointValue != null && tableEndpointValue.Type != JTokenType.Null) { string tableEndpointInstance = ((string)tableEndpointValue); locationInstance.TableEndpoint = tableEndpointInstance; } JToken tableInfoArray = locationValue["tableInfo"]; if (tableInfoArray != null && tableInfoArray.Type != JTokenType.Null) { foreach (JToken tableInfoValue in ((JArray)tableInfoArray)) { MetricTableInfo metricTableInfoInstance = new MetricTableInfo(); locationInstance.TableInfo.Add(metricTableInfoInstance); JToken tableNameValue = tableInfoValue["tableName"]; if (tableNameValue != null && tableNameValue.Type != JTokenType.Null) { string tableNameInstance = ((string)tableNameValue); metricTableInfoInstance.TableName = tableNameInstance; } JToken startTimeValue = tableInfoValue["startTime"]; if (startTimeValue != null && startTimeValue.Type != JTokenType.Null) { DateTime startTimeInstance = ((DateTime)startTimeValue); metricTableInfoInstance.StartTime = startTimeInstance; } JToken endTimeValue = tableInfoValue["endTime"]; if (endTimeValue != null && endTimeValue.Type != JTokenType.Null) { DateTime endTimeInstance = ((DateTime)endTimeValue); metricTableInfoInstance.EndTime = endTimeInstance; } JToken sasTokenValue = tableInfoValue["sasToken"]; if (sasTokenValue != null && sasTokenValue.Type != JTokenType.Null) { string sasTokenInstance = ((string)sasTokenValue); metricTableInfoInstance.SasToken = sasTokenInstance; } JToken sasTokenExpirationTimeValue = tableInfoValue["sasTokenExpirationTime"]; if (sasTokenExpirationTimeValue != null && sasTokenExpirationTimeValue.Type != JTokenType.Null) { DateTime sasTokenExpirationTimeInstance = ((DateTime)sasTokenExpirationTimeValue); metricTableInfoInstance.SasTokenExpirationTime = sasTokenExpirationTimeInstance; } } } JToken partitionKeyValue = locationValue["partitionKey"]; if (partitionKeyValue != null && partitionKeyValue.Type != JTokenType.Null) { string partitionKeyInstance = ((string)partitionKeyValue); locationInstance.PartitionKey = partitionKeyInstance; } } JToken blobLocationValue = metricAvailabilitiesValue["blobLocation"]; if (blobLocationValue != null && blobLocationValue.Type != JTokenType.Null) { BlobLocation blobLocationInstance = new BlobLocation(); metricAvailabilityInstance.BlobLocation = blobLocationInstance; JToken blobEndpointValue = blobLocationValue["blobEndpoint"]; if (blobEndpointValue != null && blobEndpointValue.Type != JTokenType.Null) { string blobEndpointInstance = ((string)blobEndpointValue); blobLocationInstance.BlobEndpoint = blobEndpointInstance; } JToken blobInfoArray = blobLocationValue["blobInfo"]; if (blobInfoArray != null && blobInfoArray.Type != JTokenType.Null) { foreach (JToken blobInfoValue in ((JArray)blobInfoArray)) { BlobInfo blobInfoInstance = new BlobInfo(); blobLocationInstance.BlobInfo.Add(blobInfoInstance); JToken blobUriValue = blobInfoValue["blobUri"]; if (blobUriValue != null && blobUriValue.Type != JTokenType.Null) { string blobUriInstance = ((string)blobUriValue); blobInfoInstance.BlobUri = blobUriInstance; } JToken startTimeValue2 = blobInfoValue["startTime"]; if (startTimeValue2 != null && startTimeValue2.Type != JTokenType.Null) { DateTime startTimeInstance2 = ((DateTime)startTimeValue2); blobInfoInstance.StartTime = startTimeInstance2; } JToken endTimeValue2 = blobInfoValue["endTime"]; if (endTimeValue2 != null && endTimeValue2.Type != JTokenType.Null) { DateTime endTimeInstance2 = ((DateTime)endTimeValue2); blobInfoInstance.EndTime = endTimeInstance2; } JToken sasTokenValue2 = blobInfoValue["sasToken"]; if (sasTokenValue2 != null && sasTokenValue2.Type != JTokenType.Null) { string sasTokenInstance2 = ((string)sasTokenValue2); blobInfoInstance.SasToken = sasTokenInstance2; } } } } } } JToken propertiesSequenceElement = ((JToken)valueValue["properties"]); if (propertiesSequenceElement != null && propertiesSequenceElement.Type != JTokenType.Null) { foreach (JProperty property in propertiesSequenceElement) { string propertiesKey = ((string)property.Name); string propertiesValue = ((string)property.Value); metricDefinitionInstance.Properties.Add(propertiesKey, propertiesValue); } } JToken dimensionsArray = valueValue["dimensions"]; if (dimensionsArray != null && dimensionsArray.Type != JTokenType.Null) { foreach (JToken dimensionsValue in ((JArray)dimensionsArray)) { Dimension dimensionInstance = new Dimension(); metricDefinitionInstance.Dimensions.Add(dimensionInstance); JToken nameValue2 = dimensionsValue["name"]; if (nameValue2 != null && nameValue2.Type != JTokenType.Null) { LocalizableString nameInstance2 = new LocalizableString(); dimensionInstance.Name = nameInstance2; JToken valueValue3 = nameValue2["value"]; if (valueValue3 != null && valueValue3.Type != JTokenType.Null) { string valueInstance2 = ((string)valueValue3); nameInstance2.Value = valueInstance2; } JToken localizedValueValue2 = nameValue2["localizedValue"]; if (localizedValueValue2 != null && localizedValueValue2.Type != JTokenType.Null) { string localizedValueInstance2 = ((string)localizedValueValue2); nameInstance2.LocalizedValue = localizedValueInstance2; } } JToken valuesArray = dimensionsValue["values"]; if (valuesArray != null && valuesArray.Type != JTokenType.Null) { foreach (JToken valuesValue in ((JArray)valuesArray)) { LocalizableString localizableStringInstance = new LocalizableString(); dimensionInstance.Values.Add(localizableStringInstance); JToken valueValue4 = valuesValue["value"]; if (valueValue4 != null && valueValue4.Type != JTokenType.Null) { string valueInstance3 = ((string)valueValue4); localizableStringInstance.Value = valueInstance3; } JToken localizedValueValue3 = valuesValue["localizedValue"]; if (localizedValueValue3 != null && localizedValueValue3.Type != JTokenType.Null) { string localizedValueInstance3 = ((string)localizedValueValue3); localizableStringInstance.LocalizedValue = localizedValueInstance3; } } } } } } } } } 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> /// Initializes an new instance of the PSMetricAvailability class /// </summary> /// <param name="metricAvailability">The metric availability</param> public PSMetricAvailability(MetricAvailability metricAvailability) : base(timeGrain: metricAvailability.TimeGrain, retention: metricAvailability.Retention) { }
///GENMHASH:CB47DF12EC83BDE4688FAE5A72C984E6:C0C35E00AF4E17F141675A2C05C7067B public SqlDatabaseMetricAvailabilityImpl(MetricAvailability innerObject) : base(innerObject) { }