private void LogEndGetMetricDefinitions(string invocationId, MetricDefinitionListResponse result)
 {
     if (TracingAdapter.IsEnabled)
     {
         TracingAdapter.Exit(invocationId, result);
     }
 }
Ejemplo n.º 2
0
 private void LogEndGetMetricDefinitions(string invocationId, MetricDefinitionListResponse result)
 {
     if (CloudContext.Configuration.Tracing.IsEnabled)
     {
         Tracing.Exit(invocationId, result);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        protected override void ProcessRecordInternal()
        {
            string queryFilter = this.ProcessParameters();
            bool   fullDetails = this.DetailedOutput.IsPresent;

            // Call the proper API methods to return a list of raw records.
            // If fullDetails is present full details of the records are displayed, otherwise only a summary of the records is displayed
            MetricDefinitionListResponse response = this.InsightsClient.MetricDefinitionOperations.GetMetricDefinitionsAsync(resourceUri: this.ResourceId, filterString: queryFilter, cancellationToken: CancellationToken.None).Result;
            var records = response.MetricDefinitionCollection.Value.Select(e => fullDetails ? (MetricDefinition) new PSMetricDefinition(e) : new PSMetricDefinitionNoDetails(e)).ToArray();

            WriteObject(sendToPipeline: records);
        }
        static void Main(string[] args)
        {
            _subscriptionId          = ConfigurationManager.AppSettings["AzureSubscriptionId"];
            _tenantId                = ConfigurationManager.AppSettings["AzureADTenantId"];
            _applicationId           = ConfigurationManager.AppSettings["AzureADApplicationId"];
            _applicationPwd          = ConfigurationManager.AppSettings["AzureADApplicationPassword"];
            _webAppResourceGroupName = ConfigurationManager.AppSettings["AzureWebAppResourceGroupName"];
            _siteName                = ConfigurationManager.AppSettings["AzureWebAppName"];
            _vmResourceGroupName     = ConfigurationManager.AppSettings["AzureClassicVmResourceGroupName"];
            _vmName = ConfigurationManager.AppSettings["AzureClassicVmName"];


            string webAppResourceUri    = string.Format(WebAppResourceUriFormat, _subscriptionId, _webAppResourceGroupName, _siteName);
            string classicVmResourceUri = string.Format(VirtualMachineResourceUriFormat, _subscriptionId, _vmResourceGroupName, _vmName);

            var token = GetAccessToken();
            var creds = new TokenCloudCredentials(_subscriptionId, token);

            /* Web App */
            Console.WriteLine("--------- List available Web App metric definitions ---------");

            MetricDefinitionListResponse webMetricDefinitions = GetAvailableMetricDefinitions(creds, webAppResourceUri);

            PrintMetricDefinitions(webMetricDefinitions);

            Console.WriteLine("--------- List Web App metrics ---------");

            MetricListResponse webMetricList = GetResourceMetrics(creds, webAppResourceUri, string.Empty, TimeSpan.FromHours(1), "PT1M");

            PrintMetricValues(webMetricList);


            /* Classic Virtual Machine */
            Console.WriteLine("--------- List Classic Compute metrics ---------");

            MetricDefinitionListResponse vmMetricDefinitions = GetAvailableMetricDefinitions(creds, classicVmResourceUri);

            PrintMetricDefinitions(vmMetricDefinitions);

            string             filter       = "(name.value eq 'Percentage CPU' or name.value eq 'Network In')";
            MetricListResponse vmMetricList = GetResourceMetrics(creds, classicVmResourceUri, filter, TimeSpan.FromHours(1), "PT5M");

            PrintMetricValues(vmMetricList);



            Console.WriteLine("Press any key to exit!");
            Console.ReadLine();
        }
        private static void PrintMetricDefinitions(MetricDefinitionListResponse definitions)
        {
            foreach (var d in definitions.MetricDefinitionCollection.Value)
            {
                Console.WriteLine("Metric: {0}", d.Name.Value);

                Console.WriteLine("    Time Grains");
                foreach (var x in d.MetricAvailabilities)
                {
                    Console.WriteLine("        {0}", x.TimeGrain);
                }

                Console.WriteLine();
            }
        }
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        protected override void ProcessRecordInternal()
        {
            string queryFilter = this.ProcessParameters();
            bool   fullDetails = this.DetailedOutput.IsPresent;

            WriteWarning("API deprecation: The use of the legacy metrics API will be discontinued in the next release. This implies a change in the output of this cmdlet.");
            using (var clientTemp = AzureSession.ClientFactory.CreateClient <InsightsClient>(DefaultProfile.Context, Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment.Endpoint.ResourceManager))
            {
                // Call the proper API methods to return a list of raw records.
                MetricDefinitionListResponse response = clientTemp.MetricDefinitionOperations.GetMetricDefinitionsAsync(resourceUri: this.ResourceId, filterString: queryFilter, cancellationToken: CancellationToken.None).Result;

                // If fullDetails is present full details of the records are displayed, otherwise only a summary of the records is displayed
                var records = response.MetricDefinitionCollection.Value.Select(e => fullDetails ? (MetricDefinition) new PSMetricDefinition(e) : new PSMetricDefinitionNoDetails(e)).ToArray();

                WriteObject(sendToPipeline: records);
            }
        }
        public void GetMetricDefinitionsTest()
        {
            MetricDefinitionCollection expectedMetricDefinitionCollection = GetMetricDefinitionCollection(ResourceUri);

            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedMetricDefinitionCollection.ToJson())
            };

            RecordedDelegatingHandler handler = new RecordedDelegatingHandler(response);
            var insightsClient = GetInsightsClient(handler);

            string filterString = "names eq 'CpuPercentage'";
            MetricDefinitionListResponse actualMetricDefinitions =
                (insightsClient.MetricDefinitionOperations as MetricDefinitionOperations)
                .GetMetricDefinitionsAsync(
                    ResourceUri,
                    filterString,
                    new CancellationToken()).Result;

            AreEqual(expectedMetricDefinitionCollection, actualMetricDefinitions.MetricDefinitionCollection);
        }
Ejemplo n.º 8
0
        public GetMetricDefinitionsCommandTests()
        {
            insightsMetricDefinitionOperationsMock = new Mock <IMetricDefinitionOperations>();
            insightsClientMock = new Mock <InsightsClient>();
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new GetMetricDefinitionsCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                InsightsClient = insightsClientMock.Object
            };

            response = Utilities.InitializeMetricDefinitionResponse();

            insightsMetricDefinitionOperationsMock.Setup(f => f.GetMetricDefinitionsAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <MetricDefinitionListResponse>(response))
            .Callback((string f, string s, CancellationToken t) =>
            {
                resourceId = f;
                filter     = s;
            });

            insightsClientMock.SetupGet(f => f.MetricDefinitionOperations).Returns(this.insightsMetricDefinitionOperationsMock.Object);
        }
Ejemplo n.º 9
0
        public GetAzureRmMetricDefinitionTests(Xunit.Abstractions.ITestOutputHelper output)
        {
            ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
            insightsMetricDefinitionOperationsMock = new Mock <IMetricDefinitionOperations>();
            insightsClientMock = new Mock <InsightsClient>();
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new GetAzureRmMetricDefinitionCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                //InsightsClient = insightsClientMock.Object
            };

            response = Utilities.InitializeMetricDefinitionResponse();

            insightsMetricDefinitionOperationsMock.Setup(f => f.GetMetricDefinitionsAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <MetricDefinitionListResponse>(response))
            .Callback((string f, string s, CancellationToken t) =>
            {
                resourceId = f;
                filter     = s;
            });

            insightsClientMock.SetupGet(f => f.MetricDefinitionOperations).Returns(this.insightsMetricDefinitionOperationsMock.Object);
        }
Ejemplo n.º 10
0
        /// <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();
                }
            }
        }
Ejemplo n.º 11
0
        public async Task <MetricDefinitionListResponse> GetMetricDefinitionsAsync(string resourceUri, string filterString, CancellationToken cancellationToken)
        {
            MetricDefinitionListResponse result;

            string invocationId = Tracing.NextInvocationId.ToString(CultureInfo.InvariantCulture);

            this.LogStartGetMetricDefinitions(invocationId, resourceUri, filterString);

            // Ensure exactly one '/' at the start
            resourceUri = '/' + resourceUri.TrimStart('/');
            IEnumerable <MetricDefinition> definitions;

            // If no filter string, must request all metric definiitons since we don't know if we have them all
            if (string.IsNullOrWhiteSpace(filterString))
            {
                // request all definitions
                definitions = (await this.GetMetricDefinitionsInternalAsync(resourceUri, string.Empty, CancellationToken.None).ConfigureAwait(false))
                              .MetricDefinitionCollection.Value;

                // cache definitions
                this.Client.Cache[resourceUri] = definitions;

                // wrap and return definitions
                result = new MetricDefinitionListResponse()
                {
                    StatusCode = HttpStatusCode.OK,
                    MetricDefinitionCollection = new MetricDefinitionCollection()
                    {
                        Value = definitions.ToList()
                    }
                };

                this.LogEndGetMetricDefinitions(invocationId, result);

                return(result);
            }

            // Parse the filter and retrieve cached definitions
            IEnumerable <string> names = MetricDefinitionFilterParser.Parse(filterString);

            definitions = this.Client.Cache[resourceUri];

            // Find the names in the filter that don't appear on any of the cached definitions
            IEnumerable <string> missing = definitions == null
                ? names
                : names.Where((n => !definitions.Any(d => string.Equals(d.Name.Value, n, StringComparison.OrdinalIgnoreCase))));

            // Request any missing definitions and update cache (if any)
            if (missing.Any())
            {
                string missingFilter = ShoeboxHelper.GenerateMetricDefinitionFilterString(missing);

                // Request missing definitions
                var missingDefinitions = (await this.GetMetricDefinitionsInternalAsync(resourceUri, missingFilter, cancellationToken).ConfigureAwait(false))
                                         .MetricDefinitionCollection.Value;

                // merge definitions
                definitions = (definitions ?? new MetricDefinition[0]).Union(missingDefinitions);

                // Store the new set of definitions
                this.Client.Cache[resourceUri] = definitions;
            }

            // Filter out the metrics that were cached but not requested and wrap
            result = new MetricDefinitionListResponse()
            {
                StatusCode = HttpStatusCode.OK,
                MetricDefinitionCollection = new MetricDefinitionCollection()
                {
                    Value = definitions.Where(d => names.Contains(d.Name.Value)).ToList()
                }
            };

            this.LogEndGetMetricDefinitions(invocationId, result);

            return(result);
        }
        /// <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();
                }
            }
        }