private async Task AddCollection(IPage <InnerResourceT> currentPage, PagedCollection <IFluentResourceT, InnerResourceT> pagedCollection, CancellationToken cancellationToken) { if (currentPage != null && currentPage.Any()) { pagedCollection.NextPageLink = currentPage.NextPageLink; var resources = await Task.WhenAll(currentPage.Select(async(inner) => await this.WrapModelAsyncDelegate(inner, cancellationToken))); ((List <IFluentResourceT>)pagedCollection.innerCollection).AddRange(resources); } }
public async Task <IPagedCollection <IFluentResourceT> > GetNextPageAsync(CancellationToken cancellationToken = default(CancellationToken)) { if (NextPageLink == null) { return(null); } var currentPage = await ListInnerNextAsyncDelegate(NextPageLink, cancellationToken); var pagedCollection = new PagedCollection <IFluentResourceT, InnerResourceT>() { WrapModelAsyncDelegate = this.WrapModelAsyncDelegate, ListInnerNextAsyncDelegate = this.ListInnerNextAsyncDelegate }; await AddCollection(currentPage, pagedCollection, cancellationToken); return(pagedCollection); }
public static async Task <IPagedCollection <IFluentResourceT> > LoadPageWithWrapModelAsync( Func <CancellationToken, Task <IPage <InnerResourceT> > > listInnerAsync, Func <string, CancellationToken, Task <IPage <InnerResourceT> > > listInnerNext, Func <InnerResourceT, CancellationToken, Task <IFluentResourceT> > wrapModelAsync, bool loadAllPages, CancellationToken cancellationToken) { var pagedCollection = new PagedCollection <IFluentResourceT, InnerResourceT>() { WrapModelAsyncDelegate = wrapModelAsync, ListInnerNextAsyncDelegate = listInnerNext }; var currentPage = await listInnerAsync(cancellationToken); do { await pagedCollection.AddCollection(currentPage, pagedCollection, cancellationToken); } while (loadAllPages && currentPage?.NextPageLink != null && !cancellationToken.IsCancellationRequested && (currentPage = await pagedCollection.ListInnerNextAsyncDelegate(pagedCollection.NextPageLink, cancellationToken)) != null); return(pagedCollection); }
public virtual async Task <IPagedCollection <IFluentResourceT> > ListByResourceGroupAsync(string resourceGroupName, bool loadAllPages = true, CancellationToken cancellationToken = default(CancellationToken)) { return(await PagedCollection <IFluentResourceT, InnerResourceT> .LoadPage( async(cancellation) => await ListInnerByGroupAsync(resourceGroupName, cancellation), ListInnerByGroupNextAsync, WrapModel, loadAllPages, cancellationToken)); }
public virtual async Task <IPagedCollection <IFluentResourceT> > ListAsync(bool loadAllPages = true, CancellationToken cancellationToken = default(CancellationToken)) { return(await PagedCollection <IFluentResourceT, InnerResourceT> .LoadPage(ListInnerAsync, ListInnerNextAsync, WrapModel, loadAllPages, cancellationToken)); }