Esempio n. 1
0
        public async Task <IActionResult> Get7([FromBody] ConditionsRequest request)
        {
            List <Entity>    listTest       = request.entities;
            ListOfConditions conditionsList = request.ListOfConditions;

            foreach (var item in conditionsList.conditions)
            {
                item.result = validateCondition(entities: listTest, condition: item);
            }

            string[] arrayOfResult = conditionsList.conditions.Select(c => c.result.ToString().ToLower()).ToArray();
            string   newResult     = string.Format(conditionsList.fullCondition, arrayOfResult);

            var              ep = new ExprParser();
            string           lambdaExpression = newResult.Replace("OR", "||").Replace("AND", "&&");
            LambdaExpression lambda;                                                     // = ep.Parse(lambdaExpression);

            lambda = ep.Parse("(10 * 15 – 11) > 100 ? 'right result' : 'wrong result'"); // string constant is enclosed by either ‘ or \”
            int result = (int)ep.Run(lambda);

            //string result = (string)ep.Run(lambda);

            _presenter.Populate(result.ToString());
            return(_presenter.ViewModel);
        }
Esempio n. 2
0
        public async Task <IActionResult> Get6(string fileId)
        {
            var listTest = new List <Entity>()
            {
                new Entity("EXTENDED_FIELD1", "value1"),
                new Entity("EXTENDED_FIELD2", "0"),
                new Entity("EXTENDED_FIELD3", "50")
            };

            var conditionsList = new ListOfConditions()
            {
                conditions =
                    new List <Condition>()
                {
                    new Condition("EXTENDED_FIELD1", "value1", "=="),
                    new Condition("EXTENDED_FIELD2", "1", "=="),
                    new Condition("EXTENDED_FIELD3", "25", "==")
                },
                fullCondition = "(({0} OR {1}) AND ({2}))"
            };

            foreach (var item in conditionsList.conditions)
            {
                item.result = validateCondition(entities: listTest, condition: item);
            }

            string[] arrayOfResult = conditionsList.conditions.Select(c => c.result.ToString().ToLower()).ToArray();
            string   newResult     = string.Format(conditionsList.fullCondition, arrayOfResult);

            var ep = new ExprParser();

            string lambdaExpression = newResult.Replace("OR", "||").Replace("AND", "&&");

            LambdaExpression lambda = ep.Parse(lambdaExpression);
            bool             result = (bool)ep.Run(lambda);

            _presenter.Populate(result.ToString());
            return(_presenter.ViewModel);
        }