public IMultiLevelCursorIterator<TInput, TOutput> Create<TDTO, TInput, TOutput>(
            ITwitterPageIterator<ITwitterResult<TDTO>> pageIterator,
            Func<TDTO, TInput[]> transform,
            Func<TInput[], Task<TOutput[]>> getChildItems,
            int maxPageSize)
        {
            var iterator = new MultiLevelCursorIterator<TInput, TOutput>(
                async () =>
                {
                    var userIdsPage = await pageIterator.NextPageAsync().ConfigureAwait(false);

                    return new CursorPageResult<TInput, string>
                    {
                        Items = transform(userIdsPage.Content.Model),
                        NextCursor = userIdsPage.NextCursor,
                        IsLastPage = userIdsPage.IsLastPage
                    };
                }, async inputs =>
                {
                    var userIdsToAnalyze = inputs.Take(maxPageSize).ToArray();
                    var friends = await getChildItems(userIdsToAnalyze).ConfigureAwait(false);

                    return new MultiLevelPageProcessingResult<TInput, TOutput>
                    {
                        Items = friends,
                        AssociatedParentItems = userIdsToAnalyze,
                    };
                });

            return iterator;
        }
Ejemplo n.º 2
0
        public async Task <IIteratorPageResult <TOutput, TCursor> > NextPageAsync()
        {
            var page = await _source.NextPageAsync().ConfigureAwait(false);

            var output = _transform(page.Content);

            NextCursor = page.NextCursor;
            Completed  = page.IsLastPage;

            return(new IteratorPageResult <TOutput, TCursor>(output, page.NextCursor, page.IsLastPage));
        }
        public async Task ActAsync()
        {
            if (_iterator.NextCursor != null)
            {
                throw new InvalidOperationException("Cannot run with pre executed iterator");
            }

            while (!_iterator.Completed)
            {
                var page = await _iterator.NextPageAsync();

                _resultPages.Add(page);
            }
        }