Beispiel #1
0
 public FilterContext(DataFilter owner, Resultset source, Object filterPredicate, QueryContext queryContext, Object[] parameters)
     : base(owner, source, queryContext, parameters)
 {
     _source = source;
     _compiledBody = new FunctionLink();
     List<ColumnBinding> bindings = new List<ColumnBinding>();
     ExpressionTransformer transformer = new ExpressionTransformer(bindings);
     foreach (RowType.TypeInfo ti in source.RowType.Fields)
         foreach (RowType.TypeInfo nested_ti in ti.NestedType.Fields)
             if (!nested_ti.IsHidden)
             {
                 ColumnBinding b = new ColumnBinding();
                 b.typecode = Type.GetTypeCode(nested_ti.DataType);
                 b.rnum = ti.Ordinal;
                 b.TableName = ti.Name;
                 b.Name = nested_ti.Name;
                 b.fieldType = nested_ti;
                 b.natural = nested_ti.IsNatural;
                 b.container = nested_ti.IsContainer;
                 b.caseSensitive = nested_ti.IsCaseSensitive;
                 b.data = new SymbolLink(nested_ti.DataType);
                 bindings.Add(b);
                 if (nested_ti.IsContainer)
                     transformer.NeedTransform = true;
             }
     LispExecutive.Enter(_resolver = new DataResolver(new Binder(bindings)));
     if (transformer.NeedTransform)
         _filterPredicate = transformer.Process(filterPredicate);
     else
         _filterPredicate = filterPredicate;
 }
 public IEnumerable<DalUser> GetByPredicate(Expression<Func<DalUser, bool>> f)
 {
     var transpormer = new ExpressionTransformer<DalUser, User>(Expression.Parameter(typeof(User), f.Parameters[0].Name));
     var expression = Expression.Lambda<Func<User, bool>>(transpormer.Visit(f.Body), transpormer.NewParamExpr);
     return context.Set<User>().Where(expression).Select(ormuser => new DalUser()
     {
         Id = ormuser.Id,
         Login = ormuser.Login,
         E_mail = ormuser.E_mail,
         Password = ormuser.Password,
         Role_Id = ormuser.Role_Id,
         RegistryDate = ormuser.RegistryDate,
         Products = ormuser.Products.Select(product => new DalProduct()
         {
             Id = product.Id,
             Auction_Cost = product.Auction_Cost,
             AuctionStart = product.AuctionStart,
             AuctionEnd = product.AuctionEnd,
             Seller_Id = product.Seller_Id,
             Buyer_Id = product.Buyer_Id,
             Description = product.Description
         }).ToList(),
         Products1 = ormuser.Products.Select(product => new DalProduct()
         {
             Id = product.Id,
             Auction_Cost = product.Auction_Cost,
             AuctionStart = product.AuctionStart,
             AuctionEnd = product.AuctionEnd,
             Seller_Id = product.Seller_Id,
             Buyer_Id = product.Buyer_Id,
             Description = product.Description
         }).ToList()
     });
 }
        public IEnumerable <AlbumEntity> GetByPredicate(Expression <Func <AlbumEntity, bool> > f)
        {
            var dalAlbums = albumRepository
                            .GetByPredicate(ExpressionTransformer <AlbumEntity, DalAlbum> .Tranform(f));

            return(dalAlbums.Select(album => album.ToBll()));
        }
Beispiel #4
0
        public void GetOperationElements_InvalidOperationString_ThrowsIncorrectOperationStringException()
        {
            var expressionTransformer = new ExpressionTransformer();

            TestDelegate t = () => expressionTransformer.GetOperationElements("2!2");

            Assert.Throws <IncorrectOperationStringException>(t);
        }
Beispiel #5
0
        public void SortElementsInOnpOrder_validOperationElements_ElementsInONPQueue(string expression, IEnumerable <string> expectedValues)
        {
            var algorithm             = new OnpAlgorithm();
            var expressionTransformer = new ExpressionTransformer();

            var result = algorithm.SortElementsInOnpOrder(expressionTransformer.GetOperationElements(expression));

            Assert.AreEqual(expectedValues, result.Select(r => r.Value));
        }
        /// <summary>
        /// Registers the transformation to apply.
        /// </summary>
        /// <param name="transformation">A method that transforms an <see cref="Expression"/>.</param>
        public void RegisterInterceptor(ExpressionTransformer transformation)
        {
            if (this.transformation != null)
            {
                throw new InvalidOperationException();
            }

            this.transformation = transformation;
        }
Beispiel #7
0
        public static Expression <Func <T1, U> > ConvertExpressionType <T1, U>(Expression <Func <T, U> > filter)
        {
            if (filter == null)
            {
                return(null);
            }
            var newExpression = ExpressionTransformer <T, T1> .Tranform(filter);

            return(newExpression);
        }
 public IEnumerable<DalRole> GetByPredicate(Expression<Func<DalRole, bool>> f)
 {
     var transpormer = new ExpressionTransformer<DalRole, Role>(Expression.Parameter(typeof(Role), f.Parameters[0].Name));
     var expression = Expression.Lambda<Func<Role, bool>>(transpormer.Visit(f.Body), transpormer.NewParamExpr);
     
     return context.Set<Role>().Where(expression).Select(ormrole => new DalRole()
     {
         Id = ormrole.Id,
         Name = ormrole.Name            
     });
 }
        /// <summary>
        /// Creates a query that can transformation the <see cref="Expression"/>
        /// wen run.
        /// </summary>
        /// <typeparam name="T">The entity type.</typeparam>
        /// <param name="source">The source query.</param>
        /// <param name="transformation">The transformation to apply.</param>
        /// <returns>The new intercepting query.</returns>
        public static IQueryable <T> CreateInterceptedQueryable <T>(
            this IQueryable <T> source,
            ExpressionTransformer transformation)
        {
            var provider         = ServiceHost.GetService <IQueryInterceptingProvider <T> >(source);
            var interceptingHost = ServiceHost.GetService <IQueryHost <T, IQueryInterceptingProvider <T> > >(
                source.Expression, provider);

            provider.RegisterInterceptor(transformation);
            return(interceptingHost);
        }
Beispiel #10
0
        public override Expression <Func <TCandidate, bool> > GetSatisfiedExpression <TCandidate>()
        {
            Type candidateType = typeof(TCandidate);

            if (candidateType == typeof(Agreement))
            {
                Expression <Func <Agreement, bool> > sourceExpression = GetAgreementExpression();
                return(ExpressionTransformer.Transform <Agreement, TCandidate>(sourceExpression));
            }


            return(base.GetSatisfiedExpression <TCandidate>());
        }
Beispiel #11
0
        public void GetOperationElements_ValidOperationString_ElementsInQueue()
        {
            var expressionTransformer = new ExpressionTransformer();
            var expectation           = new OperationElementsHelper
            {
                { OperationElementType.Number, "3" },
                { OperationElementType.Operator, "+" },
                { OperationElementType.Number, "2" }
            }.Cast <OperationElement>();

            var result = expressionTransformer.GetOperationElements("3+2");

            Assert.AreEqual(expectation.Select(r => r.ToTestValue()), result.Select(r => r.ToTestValue()));
        }
        /// <summary>
        /// Registers the transformation to apply.
        /// </summary>
        /// <param name="transformation">A method that transforms an <see cref="Expression"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown when transformation is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown when interceptor already registered.</exception>
        public void RegisterInterceptor(ExpressionTransformer transformation)
        {
            Ensure.NotNull(() => transformation);
            if (this.transformation != null)
            {
                throw ExceptionHelper.InterceptorAlreadyRegistered.AsInvalidOperationException();
            }

            while (interceptors.Count > 0)
            {
                var child = interceptors.Pop();
                child.RegisterInterceptor(transformation);
            }

            this.transformation = transformation;
        }
        public IEnumerable<DalProduct> GetByPredicate(Expression<Func<DalProduct, bool>> f)
        {
            var transpormer = new ExpressionTransformer<DalProduct, Product>(Expression.Parameter(typeof(Product), f.Parameters[0].Name));
            var expression = Expression.Lambda<Func<Product, bool>>(transpormer.Visit(f.Body), transpormer.NewParamExpr);

            return context.Set<Product>().Where(expression).Select(ormproduct => new DalProduct()
            {
                Id = ormproduct.Id,
                Auction_Cost = ormproduct.Auction_Cost,
                AuctionStart = ormproduct.AuctionStart,
                AuctionEnd = ormproduct.AuctionEnd,
                Seller_Id = ormproduct.Seller_Id,
                Buyer_Id = ormproduct.Buyer_Id,
                Description = ormproduct.Description
            });
        }
Beispiel #14
0
 public override Resultset Get(QueryContext queryContext, object[] parameters)
 {
     // Prepare bindings
     Resultset source = ChildNodes[0].Get(queryContext, parameters);
     List<ColumnBinding> bindings = new List<ColumnBinding>();            
     ExpressionTransformer transformer = new ExpressionTransformer(bindings);
     foreach (RowType.TypeInfo ti in source.RowType.Fields)
         foreach (RowType.TypeInfo nested_ti in ti.NestedType.Fields)
             if (!nested_ti.IsHidden && nested_ti.IsNatural)
             {
                 ColumnBinding b = new ColumnBinding();
                 b.typecode = Type.GetTypeCode(nested_ti.DataType);
                 b.rnum = ti.Ordinal;
                 b.TableName = ti.Name;
                 b.Name = nested_ti.Name;
                 b.fieldType = nested_ti;
                 b.natural = nested_ti.IsNatural;
                 b.container = nested_ti.IsContainer;
                 b.caseSensitive = nested_ti.IsCaseSensitive;
                 b.data = new SymbolLink(nested_ti.DataType);
                 bindings.Add(b);
                 if (nested_ti.IsContainer)
                     transformer.NeedTransform = true;
             }
     foreach (RowType.TypeInfo ti in source.RowType.Fields)
         foreach (RowType.TypeInfo nested_ti in ti.NestedType.Fields)
             if (!nested_ti.IsHidden && !nested_ti.IsNatural)
             {
                 ColumnBinding b = new ColumnBinding();
                 b.typecode = Type.GetTypeCode(nested_ti.DataType);
                 b.rnum = ti.Ordinal;
                 b.TableName = ti.Name;
                 b.Name = nested_ti.Name;
                 b.fieldType = nested_ti;
                 b.natural = nested_ti.IsNatural;
                 b.container = nested_ti.IsContainer;
                 b.caseSensitive = nested_ti.IsCaseSensitive;
                 b.data = new SymbolLink(nested_ti.DataType);
                 bindings.Add(b);
                 if (nested_ti.IsContainer)
                     transformer.NeedTransform = true;
             }
     // Expand columns.
     // On this step we transform select table.* and select * to select field1,...
     List<Column> columns = new List<Column>();
     if (_targets == null) // Select fields from all selected tables
     {
         foreach (ColumnBinding b in bindings)
             columns.Add(new Column(ATOM.Create(null, new string[] { b.TableName, b.Name }, false)));
     }
     else
         foreach (Column col in _targets)
         {
             if (Lisp.IsFunctor(col.Expr, Table)) // Select fields from specified table
             {
                 bool found = false;
                 String name = (String)Lisp.Second(col.Expr);
                 var tableBindings =
                         from b in bindings
                         where b.TableName == name
                         select b;
                 foreach (ColumnBinding b in tableBindings)
                 {
                     columns.Add(new Column(ATOM.Create(null, new string[] { b.TableName, b.Name }, false)));
                     found = true;
                 }
                 if (!found)
                     throw new ESQLException(Properties.Resources.InvalidIdentifier, name);
             }
             else // Select expression specified
                 if (transformer.NeedTransform)
                 {
                     Column c = new Column();
                     c.Alias = col.Alias;
                     c.Expr = transformer.Process(col.Expr);
                     columns.Add(c);
                 }
                 else
                     columns.Add(col);
         }
     // Create demand context   
     FunctionLink[] compiledBody = new FunctionLink[columns.Count];
     SelectorResolver resolver = new SelectorResolver(new Binder(bindings));
     SelectorContext context = new SelectorContext(this, _distinct, columns.ToArray(),
         resolver, source, queryContext, parameters, compiledBody);
     // Create columns type info and generate unique column names by field name and alias
     RowType.TypeInfo[] fields = new RowType.TypeInfo[columns.Count];
     List<String> fieldNames = new List<string>();
     int p = 1;
     for (int k = 0; k < fields.Length; k++)
     {
         String name;
         RowType.TypeInfo fieldType = null;                
         object expr = columns[k].Expr;
         compiledBody[k] = new FunctionLink();
         Type resType = context.LispExecutive.Compile(null, expr, compiledBody[k]);                
         if (Lisp.IsAtom(expr))
         {
             ColumnBinding b = resolver.GetBinding(expr);
             if (b != null)
                 fieldType = b.fieldType;
         }
         else if (Lisp.IsNode(expr) && expr is String)
         {
             fieldType = new RowType.TypeInfo(null, typeof(String),
                 TypeConverter.GetValueSize(expr));
         }
         else if (Lisp.IsFunctor(expr, ID.ParamRef))
         {
             object value = parameters[(int)Lisp.Arg1(expr)];
             fieldType = new RowType.TypeInfo(null, value.GetType(),
                 TypeConverter.GetValueSize(value));
         }
         else if (Lisp.IsFunctor(expr, ID.ToString))
         {
             if (Lisp.Length(expr) == 3)
                 fieldType = new RowType.TypeInfo(null, typeof(String), (int)Lisp.Arg2(expr));
             else
                 fieldType = new RowType.TypeInfo(null, typeof(String), 0);
         }
         else if (Lisp.IsFunctor(expr, ID.ToInt16))
             fieldType = new RowType.TypeInfo(null, typeof(Int16), 0);
         else if (Lisp.IsFunctor(expr, ID.ToInt32))
             fieldType = new RowType.TypeInfo(null, typeof(Int32), 0);
         else if (Lisp.IsFunctor(expr, ID.ToInt64))
             fieldType = new RowType.TypeInfo(null, typeof(Int64), 0);
         else if (Lisp.IsFunctor(expr, ID.ToSingle))
             fieldType = new RowType.TypeInfo(null, typeof(Single), 0);
         else if (Lisp.IsFunctor(expr, ID.ToDouble))
             fieldType = new RowType.TypeInfo(null, typeof(Double), 0);
         else if (Lisp.IsFunctor(expr, ID.ToDecimal))
             fieldType = new RowType.TypeInfo(null, typeof(Decimal), 0);
         else if (Lisp.IsFunctor(expr, ID.ToDateTime))
             fieldType = new RowType.TypeInfo(null, typeof(DateTime), 0);
         else
             fieldType = new RowType.TypeInfo(null, resType, 0);
         if (!String.IsNullOrEmpty(columns[k].Alias))
             name = columns[k].Alias;
         else
             if (fieldType.Name == null)
                 name = String.Format("Expr{0}", p++);
             else
                 name = fieldType.Name;                
         fields[k] = new RowType.TypeInfo(k, 
             Util.CreateUniqueName(fieldNames, name), fieldType);                
     }
     ScanDynatableAccessors(ChildNodes[0], resolver);
     return new Resultset(new RowType(fields), context);            
 }        
 public IEnumerable<ProductEntity> GetByPredicate(Expression<Func<ProductEntity, bool>> p)
 {
     var transpormer = new ExpressionTransformer<ProductEntity, DalProduct>(Expression.Parameter(typeof(DalProduct), p.Parameters[0].Name));
     var expression = Expression.Lambda<Func<DalProduct, bool>>(transpormer.Visit(p.Body), transpormer.NewParamExpr);
     return productRepository.GetByPredicate(expression).Select(product => product.ToBllProduct());
 }
 public IEnumerable<RoleEntity> GetByPredicate(Expression<Func<RoleEntity, bool>> p)
 {
     var transpormer = new ExpressionTransformer<RoleEntity, DalRole>(Expression.Parameter(typeof(DalRole), p.Parameters[0].Name));
     var expression = Expression.Lambda<Func<DalRole, bool>>(transpormer.Visit(p.Body), transpormer.NewParamExpr);
     return roleRepository.GetByPredicate(expression).Select(role => role.ToBllRole());
 }        
Beispiel #17
0
 public void Initialize()
 {
     this.transformer = new ExpressionTransformer();
 }
Beispiel #18
0
 public Calculator(ExpressionTransformer expressionTransformer, IOnpAlgorithm onpAlgorithm)
 {
     this.expressionTransformer = expressionTransformer;
     this.onpAlgorithm          = onpAlgorithm;
 }
 public IEnumerable<UserEntity> GetByPredicate(Expression<Func<UserEntity, bool>> f)
 {
     var transpormer = new ExpressionTransformer<UserEntity, DalUser>(Expression.Parameter(typeof(DalUser), f.Parameters[0].Name));
     var expression = Expression.Lambda<Func<DalUser, bool>>(transpormer.Visit(f.Body), transpormer.NewParamExpr);
     return userRepository.GetByPredicate(expression).Select(user => user.ToBllUser());
 }