Exemplo n.º 1
0
        public virtual AsyncPageable <CsmUsageQuota> GetUsagesAsync(string filter = null, CancellationToken cancellationToken = default)
        {
            async Task <Page <CsmUsageQuota> > FirstPageFunc(int?pageSizeHint)
            {
                using var scope = _appServicePlanClientDiagnostics.CreateScope("AppServicePlan.GetUsages");
                scope.Start();
                try
                {
                    var response = await _appServicePlanRestClient.ListUsagesAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, filter, cancellationToken : cancellationToken).ConfigureAwait(false);

                    return(Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            async Task <Page <CsmUsageQuota> > NextPageFunc(string nextLink, int?pageSizeHint)
            {
                using var scope = _appServicePlanClientDiagnostics.CreateScope("AppServicePlan.GetUsages");
                scope.Start();
                try
                {
                    var response = await _appServicePlanRestClient.ListUsagesNextPageAsync(nextLink, Id.SubscriptionId, Id.ResourceGroupName, Id.Name, filter, cancellationToken : cancellationToken).ConfigureAwait(false);

                    return(Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            return(PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc));
        }