public static IEnumerable <IEnumerable <T> > AsPaged <T>(this IEnumerable <T> items,
                                                          int pageLength = 10)
 {
     using (var enumerator = new WrappedEnumerator <T>(items.GetEnumerator()))
         while (!enumerator.IsDone)
         {
             yield return(enumerator.GetNextPage(pageLength));
         }
 }
        /// <summary>Returns an enumerator that iterates through the collection.</summary>
        /// <returns>An enumerator that can be used to iterate through the collection.</returns>
        public IEnumerator <T> GetEnumerator()
        {
            var p = Aspect.Context.Promise <IEnumerable <T> >();

            ExpressionHashData hash = null;

            if (p is Containing <IEnumerable <T> > || p is Demanding <IEnumerable <T> > )
            {
                hash = Expression.CalculateHash();
            }
            try
            {
                if (p is Containing <IEnumerable <T> > c)
                {
                    var td = c.Get(hash.Hash, Description.Description);
                    return(td.GetEnumerator());
                }

                var tran = Aspect.Context.GetQueryTransaction();
                var originalEnumerator = CreateNewOriginal(hash?.ModifiedExpression).GetEnumerator();
                if (p is NotifyCompleted <IEnumerable <T> > nc)
                {
                    nc.Fulfill(Description.Description);
                }


                if (p is Demanding <IEnumerable <T> > d)
                {
                    var result = new WrappedEnumerator <T>(originalEnumerator, tran);
                    result.Demands(d, hash.Hash, Description);
                    return(result);
                }

                return(originalEnumerator);
            }
            catch (Exception ex)
            {
                if (p is Catching <IEnumerable <T> > d)
                {
                    d.Fulfill(ex, Description.Description);
                }
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>Returns an enumerator that iterates through the collection.</summary>
        /// <returns>An enumerator that can be used to iterate through the collection.</returns>
        public IEnumerator GetEnumerator()
        {
            var p = Aspect.Aux.Promise <IEnumerable <object> >();

            if (p is Containing <IEnumerable <object> > c)
            {
                var td = c.Get(Expression.CalculateHash(), Description.Description);
                return(td.GetEnumerator());
            }

            var tran = Aspect.Aux.GetQueryTransaction();
            var originalEnumerator = Original.GetEnumerator();
            var result             = new WrappedEnumerator(originalEnumerator, tran);

            if (p is Demanding <IEnumerable <object> > d)
            {
                result.Demands(d, Expression.CalculateHash(), Description);
            }

            return(result);
        }