예제 #1
0
        private static void ValidateProperties(PriceSheetResult item, bool checkTop = false, bool checkMeterDetails = false)
        {
            Assert.NotNull(item);
            Assert.NotNull(item.Id);
            Assert.NotNull(item.Name);
            Assert.NotNull(item.Type);
            Assert.NotNull(item.NextLink);
            Assert.NotNull(item.Pricesheets);

            Assert.True(item.Pricesheets.Any());

            if (checkTop)
            {
                Assert.Equal(top, item.Pricesheets.Count);
            }

            foreach (var p in item.Pricesheets)
            {
                Assert.NotNull(p.BillingPeriodId);
                Assert.NotNull(p.CurrencyCode);
                Assert.NotNull(p.MeterId);
                Assert.NotNull(p.PartNumber);
                Assert.NotNull(p.UnitOfMeasure);

                if (checkMeterDetails)
                {
                    Assert.NotNull(p.MeterDetails);
                    Assert.NotNull(p.MeterDetails.MeterCategory);
                    Assert.NotNull(p.MeterDetails.MeterLocation);
                    Assert.NotNull(p.MeterDetails.MeterName);
                    Assert.NotNull(p.MeterDetails.MeterSubCategory);
                    Assert.NotNull(p.MeterDetails.Unit);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Method that queries to obtain the full price sheet.
        /// </summary>
        /// <param name="consumptionClient"></param>
        static void GetFullPriceSheet(ConsumptionManagementClient consumptionClient)
        {
            Console.WriteLine("Querying the Consumption API to get the Price Sheet for you!");
            Console.WriteLine("");

            //Get price first price sheet result and put the properties into a list
            PriceSheetResult priceSheetResult = consumptionClient.PriceSheet.Get();

            foreach (PriceSheetProperties properties in priceSheetResult.Pricesheets)
            {
                priceSheet.Add(properties);
            }

            //Process subsequest price sheet results
            while (priceSheetResult.NextLink != "")
            {
                Uri    nextPriceSheetLink = new Uri(priceSheetResult.NextLink);
                var    query     = HttpUtility.ParseQueryString(nextPriceSheetLink.Query);
                string skipToken = query.Get("$skiptoken");

                priceSheetResult = consumptionClient.PriceSheet.Get(null, skipToken);
                foreach (PriceSheetProperties properties in priceSheetResult.Pricesheets)
                {
                    priceSheet.Add(properties);
                }
            }

            Console.WriteLine("Obtained the price sheet! There are currently " + priceSheet.Count + " different meter rates!");
            Console.WriteLine("");
        }
예제 #3
0
 private void UpdateResult(PSPriceSheet result, PriceSheetResult priceSheet)
 {
     if (priceSheet != null)
     {
         result.Id   = priceSheet.Id;
         result.Name = priceSheet.Name;
         result.Tag  = priceSheet.Tags;
         result.Type = priceSheet.Type;
         result.PriceSheets.AddRange(priceSheet.Pricesheets.Select(x => new PSPriceSheetProperty(x)));
     }
 }
예제 #4
0
        public override void ExecuteCmdlet()
        {
            var expand = default(string);

            if (this.ExpandMeterDetail.IsPresent)
            {
                expand = "properties/meterDetails";
            }

            int numberToFetch = MaxNumberToFetch;

            if (this.Top.HasValue)
            {
                numberToFetch = this.Top.Value;
            }

            PriceSheetResult priceSheet = null;
            PSPriceSheet     result     = new PSPriceSheet();

            try
            {
                string skipToken = null;
                string nextLink  = null;
                if (!string.IsNullOrWhiteSpace(this.BillingPeriodName))
                {
                    do
                    {
                        priceSheet = ConsumptionManagementClient.PriceSheet.GetByBillingPeriod(this.BillingPeriodName,
                                                                                               expand, skipToken, numberToFetch);
                        UpdateResult(result, priceSheet);
                        nextLink = priceSheet?.NextLink;
                        if (!string.IsNullOrWhiteSpace(nextLink))
                        {
                            skipToken =
                                nextLink.Substring(
                                    nextLink.LastIndexOf("skiptoken", StringComparison.InvariantCultureIgnoreCase) + 10);
                            skipToken = skipToken.Substring(0, 12);
                        }
                    } while (!this.Top.HasValue && !string.IsNullOrWhiteSpace(nextLink));
                }
                else
                {
                    do
                    {
                        priceSheet = ConsumptionManagementClient.PriceSheet.Get(expand, skipToken, numberToFetch);
                        UpdateResult(result, priceSheet);
                        nextLink = priceSheet?.NextLink;
                        if (!string.IsNullOrWhiteSpace(nextLink))
                        {
                            skipToken =
                                nextLink.Substring(
                                    nextLink.LastIndexOf("skiptoken", StringComparison.InvariantCultureIgnoreCase) + 10);
                            skipToken = skipToken.Substring(0, 12);
                        }
                    } while (!this.Top.HasValue && !string.IsNullOrWhiteSpace(nextLink));
                }
            }
            catch (ErrorResponseException e)
            {
                WriteExceptionError(e);
            }

            WriteObject(result);
        }