Beispiel #1
0
        public RuleConfigurator <T> Then(Expression <Action <RuleContext <T> > > action)
        {
            ConsequenceDeclaration consequence = Declaration.Consequence(action);

            _consequences.Add(consequence);

            return(this);
        }
Beispiel #2
0
        private RuleDeclaration CreatePreferredRule()
        {
            Expression <Func <Order, bool> > exp       = o => o.Customer.Preferred;
            ConditionDeclaration             condition = Declaration.Condition(exp);

            ConsequenceDeclaration consequence = Declaration.Consequence(() => Trace.WriteLine("Preferred Customer"));

            return(Declaration.Rule(new[] { condition }, new[] { consequence }));
        }
Beispiel #3
0
        private RuleDeclaration CreateCustomerExistsRule()
        {
            Expression <Func <Order, bool> > exp = o => o.Customer != null;

            ConditionDeclaration   condition   = Declaration.Condition(exp);
            ConsequenceDeclaration consequence = Declaration.Consequence(() => Trace.WriteLine("Customer Exists"));

            return(Declaration.Rule(new[] { condition }, new[] { consequence }));
        }
Beispiel #4
0
        private RuleDeclaration CreateOnlineOrderRule()
        {
            Expression <Func <Order, bool> > exp = o => o.Source == "Online";

            ConditionDeclaration   condition   = Declaration.Condition(exp);
            ConsequenceDeclaration consequence = Declaration.Consequence(() => Trace.WriteLine("Online Order"));

            return(Declaration.Rule(new[] { condition }, new[] { consequence }));
        }
Beispiel #5
0
        private RuleDeclaration CreatePreferredRule()
        {
            Expression <Func <Order, bool> > exp       = o => o.Customer.Preferred;
            ConditionDeclaration             condition = Declaration.Condition(exp);

            ConsequenceDeclaration consequence = Declaration.Consequence <Order>(x => x.IsPreferred());

            return(Declaration.Rule(new[] { condition }, new[] { consequence }));
        }
Beispiel #6
0
        private RuleDeclaration CustomerIsSpecified()
        {
            Expression <Func <Order, bool> > exp = o => o.Customer != null;

            ConditionDeclaration   condition   = Declaration.Condition(exp);
            ConsequenceDeclaration consequence = Declaration.Consequence <Order>(x => x.HasCustomer());

            return(Declaration.Rule(new[] { condition }, new[] { consequence }));
        }
Beispiel #7
0
        private RuleDeclaration CreateOnlineOrderRule()
        {
            Expression <Func <Order, bool> > exp = o => o.Source == "Online";

            ConditionDeclaration   condition   = Declaration.Condition(exp);
            ConsequenceDeclaration consequence = Declaration.Consequence <Order>(x => x.IsOnline());

            return(Declaration.Rule(new[] { condition }, new[] { consequence }));
        }
Beispiel #8
0
        public RuleConfigurator <T> Then <TConsequence>()
            where TConsequence : Consequence <T>, new()
        {
            ConsequenceDeclaration consequence = Declaration.Consequence <T>(x => new TConsequence().Execute(x));

            _consequences.Add(consequence);

            return(this);
        }
Beispiel #9
0
        private void AddUnderLimitRule()
        {
            Expression <Func <OrderSubmitted, bool> > exp = o => o.Amount < 50.00m;

            ConditionDeclaration condition = Declaration.Condition(exp);
            ConsequenceDeclaration <OrderSubmitted> consequence = Declaration.Consequence <OrderSubmitted>(o => _underLimit(o.Element.Object));

            RuleDeclaration rule = Declaration.Rule(new[] { condition }, new[] { consequence });

            _engine.Add(rule);
        }
Beispiel #10
0
        private RuleDeclaration CreateActiveNotPreferredRule()
        {
            Expression <Func <Order, bool> > exp       = o => o.Customer.Preferred == false;
            ConditionDeclaration             condition = Declaration.Condition(exp);

            Expression <Func <Order, bool> > exp2       = o => o.Customer.Active;
            ConditionDeclaration             condition2 = Declaration.Condition(exp2);

            ConsequenceDeclaration consequence = Declaration.Consequence(() => Trace.WriteLine("Active, Not Preferred"));

            return(Declaration.Rule(new[] { condition, condition2 }, new[] { consequence }));
        }
Beispiel #11
0
        private RuleDeclaration CreateActiveNotPreferredRule()
        {
            Expression <Func <Order, bool> > exp       = o => o.Customer.Preferred == false;
            ConditionDeclaration             condition = Declaration.Condition(exp);

            Expression <Func <Order, bool> > exp2       = o => o.Customer.Active;
            ConditionDeclaration             condition2 = Declaration.Condition(exp2);

            ConsequenceDeclaration consequence = Declaration.Consequence <Order>(x => x.IsActiveNotPreferred());

            return(Declaration.Rule(new[] { condition, condition2 }, new[] { consequence }));
        }
Beispiel #12
0
        private RuleDeclaration CreateOnlinePreferredOrderRule()
        {
            Expression <Func <Order, bool> > exp       = o => o.Source == "Online";
            ConditionDeclaration             condition = Declaration.Condition(exp);

            Expression <Func <Order, bool> > exp2       = o => o.Customer.Preferred;
            ConditionDeclaration             condition2 = Declaration.Condition(exp2);

            ConsequenceDeclaration consequence = Declaration.Consequence <Order>(x => x.IsOnlinePreferred());

            return(Declaration.Rule(new[] { condition, condition2 }, new[] { consequence }));
        }