コード例 #1
0
        /// <summary>
        /// Read pages until the <paramref name="limit"/> number of items have been read (or the pages are exhausted) and return the result.
        /// </summary>
        /// <param name="readMethodDelegateAsync">A method that returns one page at the time</param>
        /// <param name="limit">The maximum number of items to return.</param>
        /// <param name="token">Propagates notification that operations should be canceled</param>
        /// <typeparam name="TModel">The type of the items.</typeparam>
        public static async Task <IEnumerable <TModel> > ReadPagesAsync <TModel>(
            PageEnvelopeEnumeratorAsync <TModel> .ReadMethodDelegate readMethodDelegateAsync, int limit = int.MaxValue, CancellationToken token = default)
        {
            var result     = new List <TModel>();
            var enumerator = new PageEnvelopeEnumeratorAsync <TModel>(readMethodDelegateAsync, token);
            var count      = 0;

            while (count < limit && await enumerator.MoveNextAsync())
            {
                result.Add(enumerator.Current);
                count++;
            }
            return(result);
        }
コード例 #2
0
 /// <summary>
 /// Create a new PageEnvelopeEnumerable which will get its values by calling the <paramref name="readMethodDelegate"/> method.
 /// </summary>
 /// <param name="readMethodDelegate">A method that returns a new page of answers for a specific offset.</param>
 /// <param name="token">Propagates notification that operations should be canceled</param>
 public PageEnvelopeEnumerableAsync(PageEnvelopeEnumeratorAsync <T> .ReadMethodDelegate readMethodDelegate, CancellationToken token = default)
 {
     _enumerator = new PageEnvelopeEnumeratorAsync <T>(readMethodDelegate, token);
 }