/// <summary> /// Executes the operations associated with the cmdlet. /// </summary> public override void ExecuteCmdlet() { IResourceCollectionEnumerator <ResourceCollection <AzureUtilizationRecord> > enumerator; List <PSAzureUtilizationRecord> records; ResourceCollection <AzureUtilizationRecord> utilizationRecords; try { utilizationRecords = Partner.Customers[CustomerId] .Subscriptions[SubscriptionId] .Utilization.Azure.Query( StartDate, EndDate ?? DateTimeOffset.Now, Granularity ?? AzureUtilizationGranularity.Daily, (!ShowDetails.IsPresent) || ShowDetails.ToBool()); enumerator = Partner.Enumerators.Utilization.Azure.Create(utilizationRecords); records = new List <PSAzureUtilizationRecord>(); while (enumerator.HasValue) { records.AddRange(enumerator.Current.Items.Select(r => new PSAzureUtilizationRecord(r))); enumerator.Next(); } WriteObject(records, true); } finally { enumerator = null; records = null; utilizationRecords = null; } }
public async Task <List <PSAzureUtilizationRecord> > RunAsync() { IResourceCollectionEnumerator <ResourceCollection <AzureUtilizationRecord> > enumerator; List <PSAzureUtilizationRecord> records = new List <PSAzureUtilizationRecord>(); ResourceCollection <AzureUtilizationRecord> utilizationRecords; utilizationRecords = await Partner.Customers[CustomerId] .Subscriptions[SubscriptionId] .Utilization.Azure.QueryAsync( StartDate, EndDate ?? DateTimeOffset.UtcNow, Granularity ?? AzureUtilizationGranularity.Daily, !ShowDetails.IsPresent || ShowDetails.ToBool(), PageSize == null ? 1000 : PageSize.Value).ConfigureAwait(false); if (utilizationRecords?.TotalCount > 0) { enumerator = Partner.Enumerators.Utilization.Azure.Create(utilizationRecords); while (enumerator.HasValue) { records.AddRange(enumerator.Current.Items.Select(r => new PSAzureUtilizationRecord(r))); await enumerator.NextAsync().ConfigureAwait(false); } } return(records); }
/// <summary> /// Executes the operations associated with the cmdlet. /// </summary> public override void ExecuteCmdlet() { Scheduler.RunTask(async() => { IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync().ConfigureAwait(false); IResourceCollectionEnumerator <ResourceCollection <AzureUtilizationRecord> > enumerator; List <PSAzureUtilizationRecord> records = new List <PSAzureUtilizationRecord>(); ResourceCollection <AzureUtilizationRecord> utilizationRecords; utilizationRecords = await partner.Customers[CustomerId] .Subscriptions[SubscriptionId] .Utilization.Azure.QueryAsync( StartDate, EndDate ?? DateTimeOffset.UtcNow, Granularity ?? AzureUtilizationGranularity.Daily, !ShowDetails.IsPresent || ShowDetails.ToBool(), PageSize == null ? 1000 : PageSize.Value).ConfigureAwait(false); if (utilizationRecords?.TotalCount > 0) { enumerator = partner.Enumerators.Utilization.Azure.Create(utilizationRecords); while (enumerator.HasValue) { records.AddRange(enumerator.Current.Items.Select(r => new PSAzureUtilizationRecord(r))); await enumerator.NextAsync().ConfigureAwait(false); } } WriteObject(records, true); }, true); }