Exemplo n.º 1
0
        public Func <TEntity, bool> ParserRule(RuleEngineContext.RuleEngineContext contex, string propertyName, string ruleExpression)
        {
            IPlaceHolderParser <TEntity> placeHolderParser = RuleExpressionParserFactory.CreatePalceHolderParser <TEntity>();

            placeHolderParser.AddPlaceHolders(_placeholders);


            string strexpr = placeHolderParser.ParsePlaceHolder(contex, ruleExpression);


            string strexpression = "SetPropertyValue(" + "\"" + propertyName + "\","
                                   + strexpr + ")";


            try
            {
                var expression = DynamicExpressionParser.ParseLambda <TEntity, bool>
                                     (contex.EntityContextMetadata.GetRuleParserConfig(), true, strexpression);
                return(expression.Compile());
            }
            catch (Exception ex)
            {
                throw new ExpressionParserException("PropertyRuleExpressionParser", ruleExpression, strexpression, contex.RuleEngineId, ex);
            }
        }
        public Func <TEntity, TType> ParserRule(RuleEngineContext.RuleEngineContext contex, string ruleExpression)
        {
            IPlaceHolderParser <TEntity> placeHolderParser = RuleExpressionParserFactory.CreatePalceHolderParser <TEntity>();

            placeHolderParser.AddPlaceHolders(_placeholders);

            var strexpression = placeHolderParser.ParsePlaceHolder(contex, ruleExpression);

            try
            {
                var exprep = DynamicExpressionParser
                             .ParseLambda <TEntity, TType>(contex.EntityContextMetadata.GetRuleParserConfig(),
                                                           true, strexpression);

                return(exprep.Compile());
            }
            catch (Exception ex)
            {
                throw new ExpressionParserException("AggregateFunctionParser", ruleExpression, strexpression, contex.RuleEngineId, ex);
            }
        }
        public Delegate ParseGroupString(RuleEngineContext.RuleEngineContext contex, string placeHolderExpression)
        {
            IPlaceHolderParser <TEntity> placeHolderParser = RuleExpressionParserFactory.CreatePalceHolderParser <TEntity>();

            placeHolderParser.AddPlaceHolders(_placeholders);

            string[] expressions                 = placeHolderExpression.Split(',');
            int      propertyCounter             = 1;
            PlaceHolderTextParser place          = new PlaceHolderTextParser(placeHolderExpression);
            List <string>         lstExpressions = new List <string>();

            foreach (var expr in expressions)
            {
                try
                {
                    string parsedExpression = placeHolderParser.ParsePlaceHolder(contex, string.Format("({0}) as Prop{1}", expr,
                                                                                                       propertyCounter));
                    lstExpressions.Add(parsedExpression);
                    propertyCounter = propertyCounter + 1;
                }
                catch (System.Exception ex)
                {
                    throw new ExpressionParserException("GroupKeyExpressionParser", placeHolderExpression, contex.RuleEngineId, ex);
                }
            }

            var inputExpression = string.Format("new ({0})", string.Join(",", lstExpressions));

            try
            {
                var lamdaexpr = DynamicExpressionParser
                                .ParseLambda(contex.EntityContextMetadata.GetRuleParserConfig(), true, typeof(TEntity), null, inputExpression);

                return(lamdaexpr.Compile());
            }
            catch (Exception ex)
            {
                throw new ExpressionParserException("GroupKeyExpressionParser", placeHolderExpression, inputExpression, contex.RuleEngineId, ex);
            }
        }