public void TestStateWithAgendaGroup()
        {
            System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.StateExampleUsingAgendGroup.drl");
            PackageBuilder builder = new PackageBuilder();
            builder.AddPackageFromDrl(stream);
            Package pkg = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            workingMemory.addEventListener(new AnonymousClassDefaultAgendaEventListener());

            State a = new State("A");
            State b = new State("B");
            State c = new State("C");
            State d = new State("D");

            // By setting dynamic to TRUE, Drools will use JavaBean
            // PropertyChangeListeners so you don't have to call modifyObject().
            //UPGRADE_NOTE: Final was removed from the declaration of 'dynamic '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
            bool dynamic = true;

            workingMemory.assertObject(a, dynamic);
            workingMemory.assertObject(b, dynamic);
            workingMemory.assertObject(c, dynamic);
            workingMemory.assertObject(d, dynamic);

            workingMemory.fireAllRules();
        }
        public void TestExecute()
        {
            SpreadsheetCompiler converter = new SpreadsheetCompiler();
            System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.resources.data.IntegrationExampleTest.xls");
            System.String drl = converter.Compile(stream, InputType.XLS);
            Assert.IsNotNull(drl);
            //COMPILE
            PackageBuilder builder = new PackageBuilder();
            builder.AddPackageFromDrl(drl);

            Package pkg = builder.GetPackage();
            Assert.IsNotNull(pkg);
            System.Console.Out.WriteLine(pkg.GetErrorSummary());
            Assert.AreEqual(0, builder.GetErrors().Length);

            RuleBase rb = RuleBaseFactory.NewRuleBase();
            rb.AddPackage(pkg);

            WorkingMemory wm = rb.NewWorkingMemory();

            //ASSERT AND FIRE
            wm.assertObject(new Cheese("stilton", 42));
            wm.assertObject(new Person("michael", "stilton", 42));
            System.Collections.IList list = new System.Collections.ArrayList();
            wm.setGlobal("list", list);
            wm.fireAllRules();
            Assert.AreEqual(1, list.Count);
        }
예제 #3
0
 public void TestASaveRuleBase()
 {
     PackageBuilder builder = new PackageBuilder();
     System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.precompiled.HelloWorld.drl");
     builder.AddPackageFromDrl("HelloWorld.drl", stream);
     Package pkg = builder.GetPackage();
     RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
     ruleBase.AddPackage(pkg);
     FileStream fstream = new FileStream("HelloworldRuleBase.rlb", FileMode.Create);
     ruleBase.Save(fstream);
     fstream.Close();
 }
        public void TestTroubleTicketwithDSL()
        {
            System.IO.Stream source = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.TroubleTicketWithDSL.drl");
            System.IO.Stream dsl = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.ticketing.dsl");
            PackageBuilder builder = new PackageBuilder();
            builder.AddPackageFromDrl(source, dsl);

            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.AddPackage(builder.GetPackage());

            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            Customer a = new Customer("A", "Gold");
            Customer b = new Customer("B", "Platinum");
            Customer c = new Customer("C", "Silver");
            Customer d = new Customer("D", "Silver");

            Ticket t1 = new Ticket(a);
            Ticket t2 = new Ticket(b);
            Ticket t3 = new Ticket(c);
            Ticket t4 = new Ticket(d);

            FactHandle fa = workingMemory.assertObject(a);
            FactHandle fb = workingMemory.assertObject(b);
            FactHandle fc = workingMemory.assertObject(c);
            FactHandle fd = workingMemory.assertObject(d);

            FactHandle ft1 = workingMemory.assertObject(t1);
            FactHandle ft2 = workingMemory.assertObject(t2);
            FactHandle ft3 = workingMemory.assertObject(t3);
            FactHandle ft4 = workingMemory.assertObject(t4);

            workingMemory.fireAllRules();

            t3.Status = "Done";

            workingMemory.modifyObject(ft3, t3);

            try
            {
                System.Console.Error.WriteLine("[[ Sleeping 5 seconds ]]");
                System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 5000));
            }
            catch (System.Threading.ThreadInterruptedException e)
            {
                //SupportClass.WriteStackTrace(e, Console.Error);
            }

            workingMemory.fireAllRules();

            //logger.writeToDisk();
        }
예제 #5
0
파일: MyClass.cs 프로젝트: milosh/rezolucja
 public WorkingMemory Laduj(string drlname)
 {
     System.Console.WriteLine("Kompilacja regul.
     Prosze czekac ...");
     System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream(drlname);
     PackageBuilder builder = new PackageBuilder();
     builder.AddPackageFromDrl(stream);
     Package pkg = builder.GetPackage();
     RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
     ruleBase.AddPackage(pkg);
     WorkingMemory workingMemory = ruleBase.NewWorkingMemory();
     return workingMemory;
 }
 public void TestASavePkg()
 {
     System.IO.Stream stream =      Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.TroubleTicket.drl");
     PackageBuilder builder = new PackageBuilder();
     builder.AddPackageFromDrl(stream);
     Package pkg = builder.GetPackage();
     RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
     ruleBase.AddPackage(pkg);
     FileStream fstream = new FileStream("TroubleticketRuleBase.rlb", FileMode.Create);
     ruleBase.Save(fstream);
     fstream.Close();
     stream.Close();
 }
예제 #7
0
        public void TestWaltzBenchmark()
        {
            System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.benchmark.waltz.waltz.drl");
            PackageBuilder builder = new PackageBuilder();
            builder.AddPackageFromDrl(stream);
            Package pkg = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            //this.loadLines( workingMemory, "waltz12.dat" );

            Stage stage = new Stage(Stage.START);
            workingMemory.assertObject(stage);
            workingMemory.fireAllRules();
        }
예제 #8
0
        public void TestHelloWorldExample()
        {
            PackageBuilder builder = new PackageBuilder();
            System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.HelloWorld.drl");
            builder.AddPackageFromDrl("HelloWorld.drl",stream);
            Package pkg = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            //go !
            Message message = new Message();
            message.message = "Hello World";
            message.status = Message.HELLO;
            workingMemory.assertObject(message);
            workingMemory.fireAllRules();
        }
        public void TestHonestPolitician()
        {
            System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.HonestPolitician.drl");
            PackageBuilder builder = new PackageBuilder();
            builder.AddPackageFromDrl(stream);
            Package pkg = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            Politician blair = new Politician("blair", true);
            Politician bush = new Politician("bush", true);
            Politician chirac = new Politician("chirac", true);
            Politician schroder = new Politician("schroder", true);

            workingMemory.assertObject(blair);
            workingMemory.assertObject(bush);
            workingMemory.assertObject(chirac);
            workingMemory.assertObject(schroder);

            workingMemory.fireAllRules();
        }
예제 #10
0
        public void TestMannerBenchmark()
        {
            System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.benchmark.manners.manners.drl");
            PackageBuilder builder = new PackageBuilder();
            builder.AddPackageFromDrl(stream);
            Package pkg = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            System.IO.Stream inStr = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.resources.benchmark.manners.manners64.dat");
            System.Collections.IList list = getInputObjects(inStr);
            for (System.Collections.IEnumerator it = list.GetEnumerator(); it.MoveNext(); )
            {
                System.Object obj = it.Current;
                workingMemory.assertObject(obj);
            }

            workingMemory.assertObject(new Count(1));

            long start = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
            workingMemory.fireAllRules();
            System.Console.Out.WriteLine((System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start);
        }
 private RuleBase readRule(string file)
 {
     System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.benchmark." + file);
     PackageBuilder builder = new PackageBuilder();
     builder.AddPackageFromDrl(stream);
     Package pkg = builder.GetPackage();
     RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
     ruleBase.AddPackage(pkg);
     return ruleBase;
 }
예제 #12
0
        public void TestFibonacciExample()
        {
            System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.Fibonacci.drl");
            PackageBuilder builder = new PackageBuilder();
            builder.AddPackageFromDrl(stream);
            Package pkg = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.AddPackage(pkg);

            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            // By setting dynamic to TRUE, Drools will use JavaBean
            // PropertyChangeListeners so you don't have to call modifyObject().
            //UPGRADE_NOTE: Final was removed from the declaration of 'dynamic '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
            bool dynamic = false;

            workingMemory.assertObject(new Fibonacci(50), dynamic);
            workingMemory.fireAllRules();
        }
예제 #13
0
 private RuleBase readRule(System.String file)
 {
     System.IO.Stream stream = new System.IO.FileStream(file, FileMode.Open);
     PackageBuilder builder = new PackageBuilder();
     builder.AddPackageFromDrl(stream);
     Package pkg = builder.GetPackage();
     RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
     ruleBase.AddPackage(pkg);
     return ruleBase;
 }
예제 #14
0
        public void TestGolfingExample()
        {
            System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.golf.drl");
            PackageBuilder builder = new PackageBuilder();

            builder.AddPackageFromDrl(stream);
            Package pkg = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            string[] names = new string[]{"Fred", "Joe", "Bob", "Tom"};
            string[] colors = new string[]{"red", "blue", "plaid", "orange"};
            int[] positions = new int[]{1, 2, 3, 4};

            for (int n = 0; n < names.Length; n++)
            {
                for (int c = 0; c < colors.Length; c++)
                {
                    for (int p = 0; p < positions.Length; p++)
                    {
                        workingMemory.assertObject(new Golfer(names[n], colors[c], positions[p]));

                    }
                }
            }

            workingMemory.fireAllRules();
        }
        public void TestBLoadAndChangeSavedState()
        {
            FileStream fstream = new FileStream("StateDynamic.rlb", FileMode.Open);
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.Load(fstream);
            fstream.Close();
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();
            State a = new State("A");
            State b = new State("B");
            State c = new State("C");
            State d = new State("D");
            State e = new State("E");

            // By setting dynamic to TRUE, Drools will use JavaBean
            // PropertyChangeListeners so you don't have to call modifyObject().
            //UPGRADE_NOTE: Final was removed from the declaration of 'dynamic '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
            bool dynamic = true;

            workingMemory.assertObject(a, dynamic);
            workingMemory.assertObject(b, dynamic);
            workingMemory.assertObject(c, dynamic);
            workingMemory.assertObject(d, dynamic);
            workingMemory.assertObject(e, dynamic);

            workingMemory.fireAllRules();

            Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.StateExampleDynamicRule.drl");
            PackageBuilder builder = new PackageBuilder();
            builder.AddPackageFromDrl(stream);
            Package pkg = builder.GetPackage();
            ruleBase.AddPackage(pkg);

            fstream = new FileStream("StateDynamic.rlb", FileMode.Create);
            ruleBase.Save(fstream);

            stream.Close();
            fstream.Close();
        }