public void XBusinessRulesStreamDriver() { FileStream fs = new FileStream(testFile, FileMode.Open, FileAccess.Read); breTest = new BREFactoryConsole(0, 0).NewBRE(new XBusinessRulesStreamDriver(fs)); Assert.IsNotNull(breTest, "XBRE Stream System"); }
public void NegativeResolutions() { IFlowEngine transientFlowEngine = (IFlowEngine)flowEngine.Clone(); transientFlowEngine.RuleContext.SetObject("TotalIncome", 11000.0); transientFlowEngine.RuleContext.SetObject("MonthlyInstallments", 5500.0); transientFlowEngine.RuleContext.SetObject("AgeOfApplicant", 27); transientFlowEngine.RuleContext.SetObject("IsCebEmployee", true); transientFlowEngine.RuleContext.SetObject("ApplicantIsWorking", true); transientFlowEngine.RuleContext.SetObject("TimeAtCurrentJob", 13); transientFlowEngine.RuleContext.SetObject("CitizenshipOfApplicant", "French"); Assert.IsNull(backwardChainer.Resolve("ApproveCarLoan")); transientFlowEngine = (IFlowEngine)flowEngine.Clone(); transientFlowEngine.RuleContext.SetObject("TotalIncome", 11000.0); transientFlowEngine.RuleContext.SetObject("MonthlyInstallments", 5500.0); transientFlowEngine.RuleContext.SetObject("AgeOfApplicant", 27); transientFlowEngine.RuleContext.SetObject("IsCebEmployee", true); transientFlowEngine.RuleContext.SetObject("ApplicantIsWorking", true); transientFlowEngine.RuleContext.SetObject("TimeAtCurrentJob", 10); transientFlowEngine.RuleContext.SetObject("CitizenshipOfApplicant", "Dutch"); Assert.IsNull(backwardChainer.Resolve("ApproveCarLoan")); transientFlowEngine = (IFlowEngine)flowEngine.Clone(); transientFlowEngine.RuleContext.SetObject("TotalIncome", 11000.0); transientFlowEngine.RuleContext.SetObject("MonthlyInstallments", 5500.0); transientFlowEngine.RuleContext.SetObject("AgeOfApplicant", 27); transientFlowEngine.RuleContext.SetObject("IsCebEmployee", false); transientFlowEngine.RuleContext.SetObject("ApplicantIsWorking", true); transientFlowEngine.RuleContext.SetObject("TimeAtCurrentJob", 15); transientFlowEngine.RuleContext.SetObject("CitizenshipOfApplicant", "Dutch"); Assert.IsNull(backwardChainer.Resolve("ApproveCarLoan")); }
public bool ProcessRule(string ruleName, Dictionary <string, object> contextObjects, out IBRERuleResult ruleResult) { ruleResult = null; bool processed = false; if (myRules.ContainsKey(ruleName)) { string rulePath = Path.Combine(this.sourceDir.FullName, myRules[ruleName].RuleFile); XBusinessRulesFileDriver driver = new XBusinessRulesFileDriver(rulePath); IFlowEngine flowEngine = theEngineFactory.NewBRE(driver); flowEngine.ResultHandlers += new DispatchRuleResult(flowEngine_ResultHandlers); foreach (string ruleKey in contextObjects.Keys) { flowEngine.RuleContext.SetObject(ruleKey, contextObjects[ruleKey]); } this.ruleResult = null; processed = flowEngine.Process(); ruleResult = this.ruleResult; } return(processed); }
public void XBusinessRulesStringDriver() { string xmlRules = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<xBusinessRules xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://nxbre.org/xBusinessRules.xsd\">" + "<Logic>" + " <If>" + " <And>"+ " <GreaterThanEqualTo leftId=\"Incrementor\" rightId=\"MaxAttempts\">"+ " <Evaluate id=\"Incrementor\"/>"+ " <Integer id=\"MaxAttempts\" value=\"3\"/>"+ " </GreaterThanEqualTo>"+ " </And>"+ " <Do>"+ " <False id=\"LoginResult\"/>"+ " </Do>"+ " </If>" + " <Else>" + " <Evaluate id=\"Incrementor\">"+ " <Parameter name=\"Increment\" value=\"1\"/>"+ " </Evaluate>"+ " </Else>" + "</Logic>" + "</xBusinessRules>"; breTest = new BREFactoryConsole(0, 0).NewBRE(new XBusinessRulesStringDriver(xmlRules)); Assert.IsNotNull(breTest, "XBRE String"); }
private void NewWorkingBRE() { if (prepared_bre == null) { PrepareBRE(); } working_bre = (IFlowEngine)prepared_bre.Clone(); }
public BackwardChainer(IFlowEngine flowEngine) { this.flowEngine = flowEngine; this.setIdsFromTargetObjectId = new Dictionary <string, IList <string> >(); this.sourceObjectIdsFromSetId = new Dictionary <string, IList <string> >(); ValidateXmlDocumentRules(); }
public BackwardChainer(IFlowEngine flowEngine) { this.flowEngine = flowEngine; this.setIdsFromTargetObjectId = new Dictionary<string, IList<string>>(); this.sourceObjectIdsFromSetId = new Dictionary<string, IList<string>>(); ValidateXmlDocumentRules(); }
public void InvalidRuleBase() { Assert.Throws <BREException>(() => { flowEngine = new BREImpl(); flowEngine.Init( new XBusinessRulesFileDriver(Parameter.GetString("unittest.inputfile"))); backwardChainer = new BackwardChainer(flowEngine); }); }
private void Init(IRulesDriver driver) { bre = new BREFactory(new DispatchException(HandleExceptionEvent)).NewBRE(driver); prepared_bre = null; if (bre == null) { throw new BREException("The initialization of the Flow Engine Binder failed."); } }
public void CircularityDetection() { flowEngine = new BREImpl(); flowEngine.Init(new XBusinessRulesFileDriver(ruleFilesFolder + "/circularity.xbre")); backwardChainer = new BackwardChainer(flowEngine); Stack<string> resolutionPath = new Stack<string>(); Assert.IsNull(backwardChainer.Resolve("A", resolutionPath)); Assert.IsTrue(resolutionPath.Contains("{Circularity}")); }
public void TestCancelWhile() { IFlowEngine flowEngine = NewEngine(); flowEngine.RuleContext.SetObject("FlowEngine", flowEngine); flowEngine.Process("CANCEL-WHILE"); // random test an object in the context Assert.AreEqual(10, flowEngine.RuleContext.GetObject("10i")); }
public void CircularityDetection() { flowEngine = new BREImpl(); flowEngine.Init(new XBusinessRulesFileDriver(ruleFilesFolder + "/circularity.xbre")); backwardChainer = new BackwardChainer(flowEngine); Stack <string> resolutionPath = new Stack <string>(); Assert.IsNull(backwardChainer.Resolve("A", resolutionPath)); Assert.IsTrue(resolutionPath.Contains("{Circularity}")); }
public CalculateDiscount(Basket basket) { _flowEngine = new BREFactoryConsole(SourceLevels.Error, SourceLevels.All).NewBRE(new XBusinessRulesFileDriver(AXmlFile)); if (_flowEngine == null) { throw new Exception("BRE Not Properly Initialized!"); } _flowEngine.RuleContext.SetObject("currentBasket", basket); _flowEngine.RuleContext.SetObject("currentCustomer", basket.Customer); _flowEngine.RuleContext.SetFactory("AddRule", new BRERuleFactory(AddRule)); }
private void PrepareBRE() { prepared_bre = (IFlowEngine)bre.Clone(); if (businessObjectsMap != null) { foreach (object key in BusinessObjects.Keys) { prepared_bre.RuleContext.SetObject(key, BusinessObjects[key]); } } }
public ShopFactory() { var aXMLFile = "ShopRule.xbre"; flowEngine = new BREFactoryConsole(SourceLevels.ActivityTracing, SourceLevels.Warning).NewBRE(new XBusinessRulesFileDriver(aXMLFile)); if (flowEngine == null) { throw new System.Exception("BRE Not Properly Initialized!"); } flowEngine.RuleContext.SetFactory("SetShop", new BRERuleFactory(SetShop)); }
public IFlowEngine NewBRE() { if (bref == null) throw new BREException("BRECloneFactory is not correctly initialized."); if (bre == null) bre = bref.NewBRE(rulesDriver); if (bre == null) throw new BREException("BRECloneFactory could not instantiate an valid IBRE implementation."); return (IFlowEngine)bre.Clone(); }
public CalculateTotal(string aXMLFile, SourceLevels engineTraceLevel, SourceLevels ruleBaseTraceLevel) { bre = new BREFactoryConsole(engineTraceLevel, ruleBaseTraceLevel).NewBRE(new XBusinessRulesFileDriver(aXMLFile)); if (bre == null) throw new System.Exception("BRE Not Properly Initialized!"); bre.RuleContext.SetFactory(APPLIED_DISCOUNT, new BRERuleFactory(new ExecuteRuleDelegate(AppliedDiscount))); // example on how to export native rules file FileStream fs = new FileStream("discount.bre", FileMode.Create); Xml.IdentityXSLT.Transform(bre.XmlDocumentRules, null, fs); fs.Flush(); fs.Close(); }
private void Init(IRulesDriver driver) { // listen to events from Flow Engine and Flow Engine Rule Base TraceListener tl = new FEBErrorListener(); Logger.FlowEngineSource.Listeners.Add(tl); Logger.FlowEngineRuleBaseSource.Listeners.Add(tl); // instantiate the rule engine bre = new BREFactory().NewBRE(driver); prepared_bre = null; if (bre == null) { throw new BREException("The initialization of the Flow Engine Binder failed."); } }
public CalculateTotal(string aXMLFile, SourceLevels engineTraceLevel, SourceLevels ruleBaseTraceLevel) { bre = new BREFactoryConsole(engineTraceLevel, ruleBaseTraceLevel).NewBRE(new XBusinessRulesFileDriver(aXMLFile)); if (bre == null) { throw new System.Exception("BRE Not Properly Initialized!"); } bre.RuleContext.SetFactory(APPLIED_DISCOUNT, new BRERuleFactory(new ExecuteRuleDelegate(AppliedDiscount))); // example on how to export native rules file FileStream fs = new FileStream("discount.bre", FileMode.Create); Xml.IdentityXSLT.Transform(bre.XmlDocumentRules, null, fs); fs.Flush(); fs.Close(); }
public IFlowEngine NewBRE() { if (bref == null) { throw new BREException("BRECloneFactory is not correctly initialized."); } if (bre == null) { bre = bref.NewBRE(rulesDriver); } if (bre == null) { throw new BREException("BRECloneFactory could not instantiate an valid IBRE implementation."); } return((IFlowEngine)bre.Clone()); }
public void XSLTRulesFileDriver_XSLTObject() { breTest = new BREFactoryConsole(0, 0).NewBRE(new XSLTRulesFileDriver(testNative, Misc.IdentityXSLT)); Assert.IsNotNull(breTest, "XslTransform Object"); }
public void BusinessRulesFileDriver() { breTest = new BREFactoryConsole(0, 0).NewBRE(new BusinessRulesFileDriver(testNative)); Assert.IsNotNull(breTest, "File System"); }
public void ResetBRE() { breTest = null; }
public void InitTest() { testFile = Parameter.GetString("unittest.inputfile"); // I could have used BREFactory or BREFactoryConsole but I just wanted // to show what's behind the scenes and how it is possible to register // many handler for each event. bre = new BREImpl(); // Force all Flow Engine traces to be active Logger.FlowEngineSource.Switch.Level = SourceLevels.All; Logger.FlowEngineRuleBaseSource.Switch.Level = SourceLevels.All; Logger.RefreshBooleanSwitches(); // Lets register the handlers... ptl = new ProbeTraceListener(); Logger.FlowEngineSource.Listeners.Add(ptl); Logger.FlowEngineRuleBaseSource.Listeners.Add(ptl); resultCount = 0; bre.ResultHandlers += new DispatchRuleResult(HandleBRERuleResult); // Reset the other counters globalCount = 0; if (bre.Init(new XBusinessRulesFileDriver(testFile))) { // This loads-up rules in the rule context that will be evaluated bre.RuleContext.SetFactory("50i", new BRERuleFactory(new ExecuteRuleDelegate(ContextlessDelegate))); bre.RuleContext.SetFactory("WhileCounter", new BRERuleFactory(new ExecuteRuleDelegate(WhileCounter))); bre.RuleContext.SetFactory("GlobalCounter", new BRERuleFactory(new ExecuteRuleDelegate(GlobalCounter))); bre.RuleContext.SetFactory("GetEnumerable", new BRERuleFactory(new ExecuteRuleDelegate(GetEnumerable))); bre.RuleContext.SetFactory("ForEachTester", new BRERuleFactory(new ExecuteRuleDelegate(ForEachTester))); // This alternate syntax is based on reflection thus carries performance issues // and prevents compile time checking. // It can be usefull to establish bindings on the fly. bre.RuleContext.SetFactory("mulBy5i", new BRERuleFactory(this, "ContextfullDelegate")); // Add a custom operator to the context bre.RuleContext.SetOperator("StringContains", new StringContainsOperator()); // This first process should only load-up some values, that we quickly reset. // The objective is to test that processing with no parameter works. bre.Process(); bre.Reset(); // We also want to ensure that cloning is harmless! bre = (IFlowEngine)bre.Clone(); // Let's add test objects to = new TestObject(true, 10, "hello"); bre.RuleContext.SetObject("TestObject", to); ht = new Hashtable(); ht.Add("one", "first"); ht.Add("two", "second"); ht.Add("three", "third"); bre.RuleContext.SetObject("TestHashtable", ht); TestDataSet.Table1DataTable dt = new TestDataSet.Table1DataTable(); row = dt.NewTable1Row(); row.col1 = "foo"; row.col2 = 2004; bre.RuleContext.SetObject("TestRowSet", row); bre.RuleContext.SetObject("ReferenceAssertVersion", new Version()); // this processes all global rules and the rules in the set named "Workingset" whileCount = 0; forEachProbe = 0; forEachError = ""; bre.Process("WORKINGSET"); } }
public void InitTest() { testFile = Parameter.GetString("unittest.inputfile"); try { // I could have used BREFactory or BREFactoryConsole but I just wanted // to show what's behind the scenes and how it is possible to register // many handler for each event. bre = new BREImpl(); // Lets register the handlers... logCount = 0; foundDynamicLog = false; bre.LogHandlers += new DispatchLog(handleLogEvent); foundDynamicException = false; exceptionCount = 0; bre.ExceptionHandlers += new DispatchException(handleExceptionEvent); resultCount = 0; bre.ResultHandlers += new DispatchRuleResult(handleBRERuleResult); // Reset the other counters globalCount = 0; if (bre.Init(new XBusinessRulesFileDriver(testFile))) { // This loads-up rules in the rule context that will be evaluated bre.RuleContext.SetFactory("50i", new BRERuleFactory(new ExecuteRuleDelegate(ContextlessDelegate))); bre.RuleContext.SetFactory("WhileCounter", new BRERuleFactory(new ExecuteRuleDelegate(WhileCounter))); bre.RuleContext.SetFactory("GlobalCounter", new BRERuleFactory(new ExecuteRuleDelegate(GlobalCounter))); bre.RuleContext.SetFactory("GetEnumerable", new BRERuleFactory(new ExecuteRuleDelegate(GetEnumerable))); bre.RuleContext.SetFactory("ForEachTester", new BRERuleFactory(new ExecuteRuleDelegate(ForEachTester))); // This alternate syntax is based on reflection thus carries performance issues // and prevents compile time checking. // It can be usefull to establish bindings on the fly. bre.RuleContext.SetFactory("mulBy5i", new BRERuleFactory(this, "ContextfullDelegate")); // This first process should only load-up some values, that we quickly reset. // The objective is to test that processing with no parameter works. bre.Process(); bre.Reset(); // We also want to ensure that cloning is harmless! bre = (IFlowEngine) bre.Clone(); // Let's add test objects to = new TestObject(true, 10, "hello"); bre.RuleContext.SetObject("TestObject", to); ht = new Hashtable(); ht.Add("one", "first"); ht.Add("two", "second"); ht.Add("three", "third"); bre.RuleContext.SetObject("TestHashtable", ht); TestDataSet.Table1DataTable dt = new TestDataSet.Table1DataTable(); row = dt.NewTable1Row(); row.col1="foo"; row.col2=2004; bre.RuleContext.SetObject("TestRowSet", row); bre.RuleContext.SetObject("ReferenceAssertVersion", new Version()); // this processes all global rules and the rules in the set named "Workingset" whileCount = 0; forEachProbe = 0; forEachError = ""; bre.Process("WORKINGSET"); } } catch (Exception e) { Console.Error.Write(e); Assert.Fail(e.Message); } }
private void Init(IRulesDriver driver) { // listen to events from Flow Engine and Flow Engine Rule Base TraceListener tl = new FEBErrorListener(); Logger.FlowEngineSource.Listeners.Add(tl); Logger.FlowEngineRuleBaseSource.Listeners.Add(tl); // instantiate the rule engine bre = new BREFactory().NewBRE(driver); prepared_bre = null; if (bre == null) throw new BREException("The initialization of the Flow Engine Binder failed."); }
public void InitializeChainer() { flowEngine = new BREImpl(); flowEngine.Init(new XBusinessRulesFileDriver(ruleFilesFolder + "/car-loan-rules.xbre")); backwardChainer = new BackwardChainer(flowEngine); }
public Stresser(int stresserID, IFlowEngine bre, MainClass mc) { this.stresserID = stresserID; this.mc = mc; this.bre = bre; }
public void XSLTRulesFileDriver_FS() { breTest = new BREFactoryConsole(0,0).NewBRE(new XSLTRulesFileDriver(testNative, identityXSL)); Assert.IsNotNull(breTest, "XSLT File System"); }
/// <summary>This is what your code would call to check the login /// </summary> public virtual bool CheckLogin(IFlowEngine aBRE) { aBRE.Process(); return(lockLogin); }
public void XSLTRulesFileDriver_XSLTObject() { breTest = new BREFactoryConsole(0,0).NewBRE(new XSLTRulesFileDriver(testNative, Xml.IdentityXSLT)); Assert.IsNotNull(breTest, "XslTransform Object"); }
public void XSLTRulesFileDriver_FS() { breTest = new BREFactoryConsole(0, 0).NewBRE(new XSLTRulesFileDriver(testNative, identityXSL)); Assert.IsNotNull(breTest, "XSLT File System"); }
private void PrepareBRE() { prepared_bre = (IFlowEngine)bre.Clone(); if (businessObjectsMap != null) foreach(object key in BusinessObjects.Keys) prepared_bre.RuleContext.SetObject(key, BusinessObjects[key]); }
public void XBusinessRulesFileDriver_FS() { breTest = new BREFactoryConsole(0, 0).NewBRE(new XBusinessRulesFileDriver(testFile)); Assert.IsNotNull(breTest, "XBRE File System"); }
private void NewWorkingBRE() { if (prepared_bre == null) PrepareBRE(); working_bre = (IFlowEngine)prepared_bre.Clone(); }
public void XBusinessRulesFileDriver_FS() { breTest = new BREFactoryConsole(0,0).NewBRE(new XBusinessRulesFileDriver(testFile)); Assert.IsNotNull(breTest, "XBRE File System"); }
public void BusinessRulesFileDriver() { breTest = new BREFactoryConsole(0,0).NewBRE(new BusinessRulesFileDriver(testNative)); Assert.IsNotNull(breTest, "File System"); }
public void XBusinessRulesStreamDriver() { FileStream fs = new FileStream(testFile, FileMode.Open, FileAccess.Read); breTest = new BREFactoryConsole(0,0).NewBRE(new XBusinessRulesStreamDriver(fs)); Assert.IsNotNull(breTest, "XBRE Stream System"); }
public void XBusinessRulesStringDriver() { string xmlRules = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<xBusinessRules xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://nxbre.org/xBusinessRules.xsd\">" + "<Logic>" + " <If>" + " <And>" + " <GreaterThanEqualTo leftId=\"Incrementor\" rightId=\"MaxAttempts\">" + " <Evaluate id=\"Incrementor\"/>" + " <Integer id=\"MaxAttempts\" value=\"3\"/>" + " </GreaterThanEqualTo>" + " </And>" + " <Do>" + " <False id=\"LoginResult\"/>" + " </Do>" + " </If>" + " <Else>" + " <Evaluate id=\"Incrementor\">" + " <Parameter name=\"Increment\" value=\"1\"/>" + " </Evaluate>" + " </Else>" + "</Logic>" + "</xBusinessRules>"; breTest = new BREFactoryConsole(0,0).NewBRE(new XBusinessRulesStringDriver(xmlRules)); Assert.IsNotNull(breTest, "XBRE String"); }
/// <summary>This is what your code would call to check the login /// </summary> public virtual bool checkLogin(IFlowEngine aBRE) { aBRE.Process(); return lockLogin; }
public void InvalidRuleBase() { flowEngine = new BREImpl(); flowEngine.Init(new XBusinessRulesFileDriver(Parameter.GetString("unittest.inputfile"))); backwardChainer = new BackwardChainer(flowEngine); }