Пример #1
0
        public virtual AsyncPageable <VpnSite> GetAllAsync(CancellationToken cancellationToken = default)
        {
            async Task <Page <VpnSite> > FirstPageFunc(int?pageSizeHint)
            {
                using var scope = _vpnSiteClientDiagnostics.CreateScope("VpnSiteCollection.GetAll");
                scope.Start();
                try
                {
                    var response = await _vpnSiteRestClient.ListByResourceGroupAsync(Id.SubscriptionId, Id.ResourceGroupName, cancellationToken : cancellationToken).ConfigureAwait(false);

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

            async Task <Page <VpnSite> > NextPageFunc(string nextLink, int?pageSizeHint)
            {
                using var scope = _vpnSiteClientDiagnostics.CreateScope("VpnSiteCollection.GetAll");
                scope.Start();
                try
                {
                    var response = await _vpnSiteRestClient.ListByResourceGroupNextPageAsync(nextLink, Id.SubscriptionId, Id.ResourceGroupName, cancellationToken : cancellationToken).ConfigureAwait(false);

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

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