コード例 #1
0
        /// <summary>
        /// Method to collect azure usage records from Azure APIs.
        /// </summary>
        /// <returns>Collection of Usage records.</returns>
        private IEnumerable <UsageInfoModel> GetUsageInfo()
        {
            // Loop for every subscription
            foreach (var subscription in this.subscriptions)
            {
                // Get usage details for subscription
                RateCardPayload rates = AzureResourceManagerUtil.GetRates(subscription.Id, org.Id, authResult);

                List <UsageAggregate> usageList = AzureResourceManagerUtil.GetUsage(
                    subscription.Id,
                    org.Id,
                    authResult,
                    this.startDate,
                    this.endDate);

                IEnumerable <string> projects = AzureResourceManagerUtil.GetUniqueProjects(usageList);
                subscription.Projects = projects;

                IEnumerable <ProjectUsage> projectTotals =
                    AzureResourceManagerUtil.GetProjectIDTotals(usageList, projects);
                subscription.ProjectTotals = projectTotals;

                IEnumerable <ProjectRate> projectRates = AzureResourceManagerUtil.GetProjectRates(
                    rates,
                    projectTotals);
                subscription.ProjectRates = projectRates;

                IEnumerable <ProjectEstimate> projectEstimateTotals =
                    AzureResourceManagerUtil.RatedEstimateForProject(projectRates);
                subscription.ProjectEstimateTotals = projectEstimateTotals;

                IEnumerable <string> resourceList = AzureResourceManagerUtil.GetResources(usageList);

                IEnumerable <ResourceUsage> resourceUsages =
                    AzureResourceManagerUtil.GetResourceUsage(usageList, resourceList);
                subscription.ResourceTotals = AzureResourceManagerUtil.GetResourceTotals(resourceList, usageList);

                IEnumerable <ResourceRate> resourceRates =
                    AzureResourceManagerUtil.GetResourceRates(rates, resourceUsages);

                IEnumerable <ResourceEstimate> resourceEstimates =
                    AzureResourceManagerUtil.RatedEstimateForResource(resourceRates);
                subscription.ResourceEstimates = resourceEstimates;

                subscription.MeterIdTotals = AzureResourceManagerUtil.GetMeterIdTotals(usageList);
                subscription.ServiceTotals = AzureResourceManagerUtil.GetServiceTotals(usageList);

                var result = JsonConvert.SerializeObject(subscription.MeterIdTotals); // Input to graphing solution
                subscription.UsageDetails = result;

                IEnumerable <RatedUsage> ratedUsageList =
                    AzureResourceManagerUtil.GetMeterIDRates(
                        AzureResourceManagerUtil.GetMeterIdTotals(usageList), rates);
                subscription.ratedUsage    = ratedUsageList;
                subscription.RatedEstimate = AzureResourceManagerUtil.RatedEstimate(ratedUsageList);

                foreach (var usg in usageList)
                {
                    double usgtot =
                        AzureResourceManagerUtil.ComputeRatedUsagePerMeter(
                            AzureResourceManagerUtil.GetRatesForMeterID(rates, usg.properties.meterId),
                            usg.properties.quantity);

                    this.usageInfo.Add(new UsageInfoModel()
                    {
                        OrganizationId     = org.Id,
                        SubceriptionId     = subscription.Id,
                        UsageStartTime     = usg.properties.usageStartTime,
                        UsageEndTime       = usg.properties.usageEndTime,
                        MeteredRegion      = usg.properties.infoFields.MeteredRegion,
                        MeterName          = usg.properties.meterName,
                        MeteredService     = usg.properties.infoFields.MeteredService,
                        MeteredServiceType = usg.properties.infoFields.MeteredServiceType,
                        MeterCategory      = usg.properties.meterCategory,
                        MeterSubCategory   = usg.properties.meterSubCategory,
                        UserProject        = usg.properties.infoFields.Project,
                        Quantity           = usg.properties.quantity,
                        ItemTotal          = usgtot
                    });
                }
            }

            return(this.usageInfo);
        }