/// <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;
            }
        }
Example #2
0
        /// <summary>Executes the strongly-typed query represented by a specified expression tree.</summary>
        /// <param name="expression">An expression tree that represents a LINQ query.</param>
        /// <typeparam name="TResult">The type of the value that results from executing the query.</typeparam>
        /// <returns>The value that results from executing the specified query.</returns>
        public TResult Execute <TResult>(Expression expression)
        {
            var p = Aspect.Context.Promise <TResult>();

            ExpressionHashData hash = null;

            if (p is Containing <TResult> || p is Demanding <TResult> )
            {
                hash = expression.CalculateHash();
            }

            try
            {
                if (p is Containing <TResult> c)
                {
                    return(c.Get(hash.Hash, Description.Description));
                }

                var result = Original.Execute <TResult>(hash == null ? expression : hash.ModifiedExpression);
                if (p is NotifyCompleted <TResult> nc)
                {
                    nc.Fulfill(Description.Description);
                }

                if (p is Demanding <TResult> d)
                {
                    d.Fulfill(result, hash.Hash, Description.Description);
                }

                return(result);
            }
            catch (Exception ex)
            {
                if (p is Catching <TResult> d)
                {
                    d.Fulfill(ex, Description.Description);
                }
                throw;
            }
        }