Beispiel #1
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)));
     }
 }
Beispiel #2
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);
        }