Пример #1
0
        public virtual AsyncPageable <DataCollectionRuleAssociationResource> GetAllAsync(CancellationToken cancellationToken = default)
        {
            async Task <Page <DataCollectionRuleAssociationResource> > FirstPageFunc(int?pageSizeHint)
            {
                using var scope = _dataCollectionRuleAssociationClientDiagnostics.CreateScope("DataCollectionRuleAssociationCollection.GetAll");
                scope.Start();
                try
                {
                    var response = await _dataCollectionRuleAssociationRestClient.ListByResourceAsync(Id, cancellationToken : cancellationToken).ConfigureAwait(false);

                    return(Page.FromValues(response.Value.Value.Select(value => new DataCollectionRuleAssociationResource(Client, value)), response.Value.NextLink, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            async Task <Page <DataCollectionRuleAssociationResource> > NextPageFunc(string nextLink, int?pageSizeHint)
            {
                using var scope = _dataCollectionRuleAssociationClientDiagnostics.CreateScope("DataCollectionRuleAssociationCollection.GetAll");
                scope.Start();
                try
                {
                    var response = await _dataCollectionRuleAssociationRestClient.ListByResourceNextPageAsync(nextLink, Id, cancellationToken : cancellationToken).ConfigureAwait(false);

                    return(Page.FromValues(response.Value.Value.Select(value => new DataCollectionRuleAssociationResource(Client, value)), response.Value.NextLink, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

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