Пример #1
0
        private static Expression CreateExpression(Container container)
        {
            var expression = ExpressionBinaryOperation.CreateExpressionBinaryOperation(
                ExpressionBinaryOperator.And,
                ExpressionBinaryOperation.CreateExpressionBinaryOperation(
                    ExpressionBinaryOperator.Or,
                    ExpressionVariable.CreateExpressionVariable(CreateRuleVariable(container)),
                    ExpressionVariable.CreateExpressionVariable(CreateRuleVariable(container))
                    ),
                ExpressionUnaryOperation.CreateExpressionUnaryOperation(
                    ExpressionUnaryOperator.Not,
                    ExpressionVariable.CreateExpressionVariable(CreateRuleVariable(container))
                    )
                );

            return(expression);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            Uri serviceUri = new Uri("http://localhost:38054");
            var container  = new Container(serviceUri);

            var firstRuleVariableId  = CreateRuleVariable(container);
            var secondRuleVariableId = CreateRuleVariable(container);
            var thirdRuleVariableId  = CreateRuleVariable(container);

            var expression = ExpressionBinaryOperation.CreateExpressionBinaryOperation(
                ExpressionBinaryOperator.And,
                ExpressionBinaryOperation.CreateExpressionBinaryOperation(
                    ExpressionBinaryOperator.Or,
                    ExpressionVariable.CreateExpressionVariable(firstRuleVariableId),
                    ExpressionVariable.CreateExpressionVariable(secondRuleVariableId)
                    ),
                ExpressionUnaryOperation.CreateExpressionUnaryOperation(
                    ExpressionUnaryOperator.Not,
                    ExpressionVariable.CreateExpressionVariable(thirdRuleVariableId)
                    )
                );

            var rule = Rule.CreateRule(int.MaxValue, "My Rule");

            rule.Expression = expression;
            container.AddToRules(rule);
            container.SaveChanges();
            Console.Out.WriteLine(rule.ToString());

            var ruleVariables     = container.Rules.ByKey(rule.Id).Variables.ToList();
            var firstRuleVariable = ruleVariables.Find(rv => rv.Id == firstRuleVariableId);

            Console.Out.WriteLine(firstRuleVariable.ToString());
            var secondRuleVariable = ruleVariables.Find(rv => rv.Id == firstRuleVariableId);

            Console.Out.WriteLine(secondRuleVariable.ToString());
            var thirdRuleVariable = ruleVariables.Find(rv => rv.Id == firstRuleVariableId);

            Console.Out.WriteLine(thirdRuleVariable.ToString());
        }