Пример #1
0
        public void ParseRuleWithDecmalAndActionToAllRelatedCommand()
        {
            string input = @"for Activity with Subject = 24 do set Document.Category = 'Debel' ToAllRelated Activities";

            var mockCommand = new ActionExpression()
            {
                Command = Command.Set,
                Action  = new BinaryExpression()
                {
                    @operator = Operators.ToAllRelated,
                    Left      = new BinaryExpression()
                    {
                        @operator = Operators.@is,
                        Left      = new Target()
                        {
                            EntityName   = "Document",
                            PropertyName = "Category"
                        },
                        Right = new ConststantExpression()
                        {
                            Value = "Debel"
                        }
                    },
                    Right = new ConststantExpression()
                    {
                        Value = "Activities"
                    }
                }
            };
            var mockCommandList = new List <Expression>();

            mockCommandList.Add(mockCommand);

            var mockTarget = new BinaryExpression()
            {
                @operator = Operators.@is,
                Left      = new Target()
                {
                    EntityName   = "Activity",
                    PropertyName = "Subject"
                },
                Right = new ConststantExpression()
                {
                    Value = 24.ToString()
                }
            };

            var mockrule = new Rule()
            {
                Actions = mockCommandList,
                Target  = mockTarget
            };

            var output = Grammar.Rule.Parse(input);

            Assert.AreEqual(mockrule.ToString().Trim(), output.ToString().Trim());
        }
Пример #2
0
        public void Is_Should_Invoke_Action_When_Called()
        {
            const string original = "bla";
            string expected = null;

            var actionExpression = new ActionExpression<string>(x => expected = x);
            actionExpression.Is(original);
            
            Assert.AreEqual(original, expected);
        }
Пример #3
0
        private static void IndividualFactTest()
        {
            DateTime end;
            DateTime start;
            TimeSpan diff;
            Xml      x;
            int      total;

            ROM rom = new ROM();

            //set up out facts
            Fact F1 = new Fact("F1", 1, new Naked("1", typeof(double)), typeof(double));
            Fact F2 = new Fact("F2", 1, new Naked("1", typeof(double)), typeof(double));
            Fact F3 = new Fact("F3", 1, new Naked(null, typeof(double)), typeof(double));

            rom.AddEvidence(F1);
            rom.AddEvidence(F2);
            rom.AddEvidence(F3);

            //set up our assignments
            ActionExpression A1 = new ActionExpression("1", "F1", "2", 2);
            ActionExpression A2 = new ActionExpression("2", "F2", "2", 2);

            rom.AddEvidence(A1);
            rom.AddEvidence(A2);

            List <EvidenceSpecifier> list = new List <EvidenceSpecifier>();

            list.Add(new EvidenceSpecifier(true, "1"));
            list.Add(new EvidenceSpecifier(true, "2"));

            //create a rule
            Rule R1 = new Rule("R1", "1==1", list, 500, true);

            rom.AddEvidence(R1);
            rom.Evaluate();


            Console.WriteLine("Starting Test:" + DateTime.Now);
            total = 50000;
            start = DateTime.Now;
            for (int counter = 0; counter < total; counter++)
            {
                //cause rules to evaluate
                rom.Evaluate();
            }
            end  = DateTime.Now;
            diff = end - start;
            Console.WriteLine("Total ms: " + diff.TotalMilliseconds);
            Console.WriteLine("milliseconds per rule: " + (diff.TotalMilliseconds / (total * 8d))); //eight rules per run
        }
Пример #4
0
        public void ParseSimpleRuleSuccessfull()
        {
            string input = @"for Activity with Subject = 'Lorena' do set Subject = 'Lararea'";


            var mockCommand = new ActionExpression()
            {
                Command = Command.Set,
                Action  = new BinaryExpression()
                {
                    @operator = Operators.@is,
                    Left      = new Target()
                    {
                        PropertyName = "Subject"
                    },
                    Right = new ConststantExpression()
                    {
                        Value = "Lararea"
                    }
                }
            };
            var mockCommandList = new List <Expression>();

            mockCommandList.Add(mockCommand);

            var mockTarget = new BinaryExpression()
            {
                @operator = Operators.@is,
                Left      = new Target()
                {
                    EntityName   = "Activity",
                    PropertyName = "Subject"
                },
                Right = new ConststantExpression()
                {
                    Value = "Lorena"
                }
            };

            var rule = new Rule()
            {
                Actions = mockCommandList,
                Target  = mockTarget
            };

            var output = Grammar.Rule.Parse(input);

            Assert.AreEqual(rule.ToString(), output.ToString());
        }
Пример #5
0
        public void ParseRuleWithNoCondition()
        {
            string input = @"for Activity do set Activity.Body = 'Debel'";


            var mockCommand = new ActionExpression()
            {
                Command = Command.Set,
                Action  = new BinaryExpression()
                {
                    @operator = Operators.@is,
                    Left      = new Target()
                    {
                        EntityName   = "Activity",
                        PropertyName = "Body"
                    },
                    Right = new ConststantExpression()
                    {
                        Value = "Debel"
                    }
                }
            };
            var mockCommandList = new List <Expression>();

            mockCommandList.Add(mockCommand);

            var mockTarget = new Target()
            {
                EntityName = "Activity",
            };

            var rule = new Rule()
            {
                Actions = mockCommandList,
                Target  = mockTarget
            };

            var output = Grammar.Rule.Parse(input);

            Assert.AreEqual(rule.ToString(), output.ToString());
        }
Пример #6
0
 protected internal virtual void PostWalk(ActionExpression node) { } 
Пример #7
0
      // *** BEGIN GENERATED CODE ***


#if FULL
        // ActionExpression
        protected internal virtual bool Walk(ActionExpression node) { return true; }
Пример #8
0
		/////////////////////////////////////////////////////////////////////////////

		public override object EvalActionExpression( object obj, ActionExpression exp )
		{
			throw new NotImplementedException();
		}
Пример #9
0
        public void ParseComplicatedRule()
        {
            string input = @"for ssad = 7777 or 
                    (((Activity with Subject = 'LUrena' or Body is 'HUR') or ((Name = 'smqh' or Body = 'smqh') or Karami contains 'parafin')) or sss = 'ss')
                    do set Activity.Body = 'Debel', set Subject = 'Lararea'";

            #region DEFINE
            var mockCommand = new ActionExpression()
            {
                Command = Command.Set,
                Action  = new BinaryExpression()
                {
                    @operator = Operators.@is,
                    Left      = new Target()
                    {
                        EntityName   = "Activity",
                        PropertyName = "Body"
                    },
                    Right = new ConststantExpression()
                    {
                        Value = "Debel"
                    }
                }
            };

            var mockCommandList = new List <Expression>();
            mockCommandList.Add(mockCommand);

            mockCommand = new ActionExpression()
            {
                Command = Command.Set,
                Action  = new BinaryExpression()
                {
                    @operator = Operators.@is,
                    Left      = new Target()
                    {
                        PropertyName = "Subject"
                    },
                    Right = new ConststantExpression()
                    {
                        Value = "Lararea"
                    }
                }
            };
            mockCommandList.Add(mockCommand);

            var mock = new BinaryExpression()
            {
                @operator = Operators.or,
                Left      = new BinaryExpression()
                {
                    Left = new Target()
                    {
                        PropertyName = "ssad"
                    },
                    @operator = Operators.@is,
                    Right     = new ConststantExpression()
                    {
                        Value = 7777.ToString()
                    }
                },
                Right = new BinaryExpression()
                {
                    @operator = Operators.or,
                    Right     = new BinaryExpression()
                    {
                        Left = new Target()
                        {
                            PropertyName = "sss"
                        },
                        @operator = Operators.@is,
                        Right     = new ConststantExpression()
                        {
                            Value = "ss"
                        }
                    },
                    Left = new BinaryExpression()
                    {
                        Left = new BinaryExpression()
                        {
                            Left = new BinaryExpression()
                            {
                                Left = new Target()
                                {
                                    EntityName   = "Activity",
                                    PropertyName = "Subject"
                                },
                                @operator = Operators.@is,
                                Right     = new ConststantExpression()
                                {
                                    Value = "LUrena"
                                }
                            },
                            @operator = Operators.or,
                            Right     = new BinaryExpression()
                            {
                                Left = new Target()
                                {
                                    PropertyName = "Body"
                                },
                                @operator = Operators.@is,
                                Right     = new ConststantExpression()
                                {
                                    Value = "HUR"
                                }
                            }
                        },
                        @operator = Operators.or,
                        Right     = new BinaryExpression()
                        {
                            Left = new BinaryExpression()
                            {
                                Left = new BinaryExpression()
                                {
                                    Left = new Target()
                                    {
                                        PropertyName = "Name"
                                    },
                                    @operator = Operators.@is,
                                    Right     = new ConststantExpression()
                                    {
                                        Value = "smqh"
                                    }
                                },
                                @operator = Operators.or,
                                Right     = new BinaryExpression()
                                {
                                    Left = new Target()
                                    {
                                        PropertyName = "Body"
                                    },
                                    @operator = Operators.@is,
                                    Right     = new ConststantExpression()
                                    {
                                        Value = "smqh"
                                    }
                                }
                            },
                            @operator = Operators.or,
                            Right     = new BinaryExpression()
                            {
                                Left = new Target()
                                {
                                    PropertyName = "Karami"
                                },
                                @operator = Operators.contains,
                                Right     = new ConststantExpression()
                                {
                                    Value = "parafin"
                                }
                            }
                        }
                    }
                }
            };

            var mockRule = new Rule()
            {
                Actions = mockCommandList,
                Target  = mock
            };
            #endregion

            var output = Grammar.Rule.Parse(input);

            Assert.AreEqual(mockRule.ToString().Trim(), output.ToString().Trim());
        }
Пример #10
0
		public abstract object EvalActionExpression( object obj, ActionExpression exp );
Пример #11
0
 protected internal virtual void PostWalk(ActionExpression node)
 {
 }
Пример #12
0
        // *** BEGIN GENERATED CODE ***


#if FULL
        // ActionExpression
        protected internal virtual bool Walk(ActionExpression node)
        {
            return(true);
        }
Пример #13
0
		public abstract string DumpActionExpression( ActionExpression exp );
Пример #14
0
		/////////////////////////////////////////////////////////////////////////////

		public override string DumpActionExpression( ActionExpression exp )
		{
			return string.Format( "ActionExpression\n" );
		}