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(); }
//********************************************************** // workingObj is set by the button click method //********************************************************** private void TestRules(RuleBase ruleBase, Form1 F1) { F1.debugOutput.Text += "\nRule Run: "; if (_currentCust == null) { _currentCust = F1.workingMemory.assertObject(workingObj); } else { F1.workingMemory.modifyObject(_currentCust, workingObj); } if (secondWorkingObj != null) { F1.workingMemory.assertObject(secondWorkingObj); } F1.workingMemory.fireAllRules(); CustomerRecord customer = (CustomerRecord)F1.workingMemory.getObject(_currentCust); F1.debugOutput.Text += "\nCustomer: " + customer.Id + " | Qty: " + customer.Value + " | STATUS: " + customer.Status; if (secondWorkingObj != null) { F1.debugOutput.Text += "\n 2nd Customer: " + secondWorkingObj.Id + " | Qty: " + secondWorkingObj.Value + " | STATUS: " + secondWorkingObj.Status; } }
private void Form1_Shown(object sender, EventArgs e) { _thisForm = this; debugOutput.Text += "\nLoading Rule Base: "; _thisForm.Refresh(); PackageBuilder builder = new PackageBuilder(); Stream stream = new FileStream(@"C:\Documents and Settings\TricolorerVirtual\Escritorio\MinimalDroolsForm.rar\MinimalDroolsForm\SimpleRulesExt.drl", FileMode.Open); debugOutput.Text += "\nStream Set "; _thisForm.Refresh(); debugOutput.Text += "\nReading DRL (Please wait... this may take a few moments...) "; _thisForm.Refresh(); builder.AddPackageFromDrl("MinimalDroolsForm.SimpleRules.drl", stream); debugOutput.Text += "... Finished "; _thisForm.Refresh(); Package pkg = builder.GetPackage(); debugOutput.Text += "\nPackage Added "; _thisForm.Refresh(); ruleBase = RuleBaseFactory.NewRuleBase(); ruleBase.AddPackage(pkg); debugOutput.Text += "\nRule Base Set "; _thisForm.Refresh(); workingMemory = ruleBase.NewWorkingMemory(); workingObj = new CustomerRecord(); secondWorkingObj = null; }
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); }
/// <summary> /// Convert all different types of rules to DTOs /// </summary> /// <param name="rule">entity</param> /// <returns>DTO</returns> /// <exception cref="FormatException">Subclass is not recognized.</exception> public static TriggerRuleBase ConvertRule(RuleBase rule) { switch (rule) { case ContextCollectionRule dto: return(new TriggerContextRule { ContextName = dto.ContextName, Filter = ConvertFilterCondition(dto.Condition), PropertyName = dto.PropertyName, PropertyValue = dto.PropertyValue, ResultToUse = ConvertFilterResult(dto.ResultToUse) }); case ExceptionRule dto1: return(new TriggerExceptionRule { FieldName = dto1.FieldName, Filter = ConvertFilterCondition(dto1.Condition), ResultToUse = ConvertFilterResult(dto1.ResultToUse), Value = dto1.Value }); } throw new FormatException("Failed to convert " + rule); }
public void Simulate(Simulation formSimulation, SimulationDebug formDebug) { _formDebug = formDebug; _formSimulation = formSimulation; formDebug.Show(); //Imprimo this para saber sobre que objeto operaran las reglas FallasI.Simulator.ImprimirEnDebug(this); //Inicio la carga de drools formDebug.debugTxtBox.Text += "\nLoading Rule Base: "; formDebug.debugTxtBox.Refresh(); PackageBuilder builder = new PackageBuilder(); Stream stream = new FileStream(FallasI.Src.App.Default.PATH_ARCHIVO_REGLAS, FileMode.Open); formDebug.debugTxtBox.Text += "\nStream Set "; formDebug.debugTxtBox.Refresh(); formDebug.debugTxtBox.Text += "\nReading DRL (Please wait... this may take a few moments...) "; formDebug.debugTxtBox.Refresh(); builder.AddPackageFromDrl("FallasI.Rules.drl", stream); formDebug.debugTxtBox.Text += "... Finished "; formDebug.debugTxtBox.Refresh(); Package pkg = builder.GetPackage(); formDebug.debugTxtBox.Text += "\nPackage Added "; formDebug.debugTxtBox.Refresh(); ruleBase = RuleBaseFactory.NewRuleBase(); ruleBase.AddPackage(pkg); formDebug.debugTxtBox.Text += "\nRule Base Set "; formDebug.debugTxtBox.Refresh(); workingMemory = ruleBase.NewWorkingMemory(); workingObj = this; formDebug.debugTxtBox.Text += "\nWorking Object Set "; formDebug.debugTxtBox.Refresh(); //Inicio la ejecucion de drool formDebug.debugTxtBox.Text += "\nRule Runing... "; formDebug.debugTxtBox.Refresh(); if (_currentCust == null) { _currentCust = workingMemory.assertObject(workingObj); } else { workingMemory.modifyObject(_currentCust, workingObj); } workingMemory.fireAllRules(); formDebug.debugTxtBox.Text += "\nFin "; formDebug.debugTxtBox.Refresh(); // llamo a simular _formSimulation.DibujarSimulacion(); //formDebug.Close(); }
public decimal GetTravelInsurancePrice(TravelRiskItem riskItem) { string assemblyPath = AppDomain.CurrentDomain.RelativeSearchPath; System.IO.Stream stream = new FileStream(Path.Combine(assemblyPath, @"Rules\", "TravelInsurancePrice.drl"), FileMode.Open); try { var region = _riskItemRepository.GetById(riskItem.RegionID); var sport = riskItem.SportId.HasValue ? _riskItemRepository.GetById(riskItem.SportId.Value) : null; PackageBuilder builder = new PackageBuilder(); builder.AddPackageFromDrl("TravelInsurancePrice.drl", stream); Package pkg = builder.GetPackage(); RuleBase ruleBase = RuleBaseFactory.NewRuleBase(); ruleBase.AddPackage(pkg); WorkingMemory workingMemory = ruleBase.NewWorkingMemory(); workingMemory.assertObject(region); workingMemory.assertObject(sport); workingMemory.assertObject(riskItem); return(riskItem.RuleAmmount); } finally { stream.Close(); } }
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 TestLoadState() { FileStream fstream = new FileStream("StateDynamic.rlb", FileMode.Open); RuleBase ruleBase = RuleBaseFactory.NewRuleBase(); ruleBase.Load(fstream); 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(); }
public void Sprawdzamy_Wnioskowania() { GatheredBases bases = new GatheredBases(); RuleBase rules = new RuleBase(); Rule r = new Rule(1, "Wniosek", new List <string>() { "Wniosek1" }, true); Rule r1 = new Rule(2, "Wniosek1", new List <string>() { "Wniosek2" }, true); Rule r2 = new Rule(3, "Wniosek2", new List <string>() { "Wniosek3" }, true); Rule r22 = new Rule(5, "Wniosek2", new List <string>() { "Wniosek6" }, true); Rule r3 = new Rule(4, "Wniose3", new List <string>() { "Wniosek4" }, true); rules.RulesList.Add(r); rules.RulesList.Add(r1); rules.RulesList.Add(r2); rules.RulesList.Add(r3); rules.RulesList.Add(r22); bases.RuleBase = rules; TreeOperations.ReturnComplexTreeAndDifferences(bases, r); Assert.AreEqual(true, true); }
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); }
/// <summary> /// Checks an anonymous rule (build on the fly from an expression) with a parameter. /// </summary> /// <typeparam name="TParameter">The type of the parameter for the check.</typeparam> /// <param name="rule">The method that returns true or false and accepts the data (of type <see cref="TData"/>) and a check parameter <paramref name="ruleParameter"/>.</param> /// <param name="ruleParameter">The parameter for rule checking (the second parameter of the <paramref name="rule"/>).</param> /// <returns>The class instance this method belongs to. This way you can invoke multiple methods of this class in one line of code.</returns> public TResultClass Assert <TParameter>(Func <TData, TParameter, bool> rule, TParameter ruleParameter) { var ruleClass = new RuleBase <TData, object> { CheckExpression = (data, parameter) => rule.Invoke(data, ruleParameter) }; return(this.Assert(ruleClass, ruleParameter)); }
protected void SetRuleLegendProperties(RuleBase coreRule) { SetLegendText(coreRule); if (m_mapRule.LegendName != null) { coreRule.ShowInLegend = m_mapRule.LegendName; } }
public ResultItem(RuleBase rule) { Rule = rule.Name; Description = rule.Description; Details = rule.Details; Severity = rule.Severity; Value = null; }
public ResultItem(RuleBase rule, string resultText) { Rule = rule.Name; Description = rule.Description; Details = rule.Details; Severity = rule.Severity; Value = resultText; }
public Message(RuleBase parent, string text, params DataEntry[][] data) : base(text) { this.parent = parent; this.data.Add(new DataEntryCollection(parent, data)); SubItems.Add(parent.FullPath); }
private static RuleBase <TTarget> CreateRuleBase(List <RuleSet <TTarget> > ruleSets, List <RuleExpression <TTarget> > ruleExpressions) { var ruleBase = new RuleBase <TTarget>(); AddDefaultRuleSet(ruleExpressions, ruleBase); ruleSets.ForEach(ruleBase.AddRuleSet); return(ruleBase); }
/// <summary> /// Strong typed rule invocation. /// </summary> /// <typeparam name="TParameter">The type of the rule parameter.</typeparam> /// <param name="rule">The rule to be evaluated.</param> /// <param name="ruleParameter">The parameter for invoking the rule.</param> /// <param name="valueName">The name of the data to be checked.</param> /// <returns>True if the rule check is ok, false if the rule is violated.</returns> public bool ExecuteRuleExpression <TParameter>(RuleBase <TData, TParameter> rule, TParameter ruleParameter, string valueName) { // if there is no rule, we cannot say that the rule is validated if (rule == null) { return(true); } // let the concrete execution class decide if we want to execute the expression if (!this.BeforeInvoke(rule, ruleParameter, valueName)) { return(true); } var validationResult = false; try { // execute the expression validationResult = rule.CheckExpression(this.Value, ruleParameter); } catch (NullReferenceException) { } catch (Exception ex) { if (!this.HandleInvokeException(ex, rule, ruleParameter, valueName)) { throw; } } var ruleType = rule.GetType(); var result = new RuleValidationResult( ruleType, string.Format( CultureInfo.CurrentCulture, Resources.RuleValidationResultStandardMessage, ruleType.Namespace + "." + ruleType.Name, valueName, string.Format(CultureInfo.CurrentCulture, rule.Message, ruleParameter, valueName)), valueName, validationResult); foreach (var action in Bouncer.GetAfterInvokeActions()) { action.Invoke(result); } this.AfterInvoke(result); if (this.PreviousExecuter != null) { this.PreviousExecuter.AssertAll(); } return(validationResult); }
public List <Rule> Match(WorkingMemory workingMemory, RuleBase ruleBase) { var matchingRules = ruleBase.Rules .Where(x => !x.Triggered) .Where(rule => rule.EvaluatePreconditions(workingMemory.Facts)) .ToList(); return(matchingRules); }
/// <summary> /// Add the rules in the order that they should be check in. the first rule added is the first rule that will decide /// which action to take. /// </summary> /// <param name="rule">Rule to add</param> public void AddRule(RuleBase rule) { if (rule == null) { throw new ArgumentNullException("rule"); } _rules.Add(rule); }
protected InferenceEngine(WorkingMemory workingMemory, RuleBase ruleBase) { _workingMemory = workingMemory; _ruleBase = ruleBase; _matcher = new RuleMatcherService(); _resolver = new RuleResolverService(); _executer = new RuleExecuterService(); }
private static Rule Rule() { string ruleFromDoc = "reguła(1,\"otrzymuje wpis\",[\"ocena z przedmiotów A,B,C >=3 \",\"zapłacił czesne\"], 1) "; var NewRuleBase = new RuleBase(); var rule = NewRuleBase.CreateRule(ruleFromDoc); return(rule); }
public DataEntryCollection(RuleBase parent, params DataEntry[][] entries) { this.parent = parent; foreach (DataEntry[] array in entries) { AddRange(array); } }
internal void CheckHRESULT(RuleBase parent, WinCodecError error, Exception e, string param, params DataEntry[] de) { if (Marshal.GetHRForException(e) != (int)error) { string text = param == null?e.TargetSite.ToString(Resources._0_FailedWithIncorrectHRESULT) : e.TargetSite.ToString(Resources._0_FailedWithIncorrectHRESULT, param); Add(parent, text, de, new DataEntry(Resources.Actual, e), new DataEntry(Resources.Expected, error)); } }
private RuleBase readPrecompiled(string fileName) { RuleBase ruleBase = RuleBaseFactory.NewRuleBase(); FileStream fstream = new FileStream(fileName, FileMode.Open); ruleBase.Load(fstream); fstream.Close(); return(ruleBase); }
internal virtual SymbolRule CreateSymbolRule() { SymbolRule symbolRule = (SymbolRule)(m_coreRule = new SymbolRule()); symbolRule.Category = m_mapVectorLayer.Name; symbolRule.Field = ""; m_coreMap.SymbolRules.Add(symbolRule); SetRuleFieldName(); return(symbolRule); }
public Parser() { builder = new PackageBuilder(); stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("Sensip.Language.LanguageRules.drl"); builder.AddPackageFromDrl("Language.LanguageRules.drl", stream); pkg = builder.GetPackage(); ruleBase = RuleBaseFactory.NewRuleBase(); ruleBase.AddPackage(pkg); message = new Message(); }
public virtual SymbolRule CreateSymbolRule() { SymbolRule symbolRule = (SymbolRule)(this.m_coreRule = new SymbolRule()); symbolRule.Category = this.m_mapVectorLayer.Name; symbolRule.Field = ""; this.m_coreMap.SymbolRules.Add(symbolRule); this.SetRuleFieldName(); return(symbolRule); }
public static void CleanMappingList <TC, TR>(RuleBase <TC, TR> rule) where TC : QueryCriteriaItem, IDicomMappingItem, new() where TR : QueryResultItem, IDicomMappingItem, new() { if (rule == null) { return; } CleanQCMappingList <TC>(rule.QueryCriteria.MappingList); CleanQRMappingList <TR>(rule.QueryResult.MappingList); }
public override bool IsValidate(out string message, IRuleBaseProperties properties, RuleBase rule) { var existedNames = base.GetReadableVariants(); if (existedNames != null) { if (existedNames.Any(x => x.CodeVariant == this.CodeVariant)) { message = "�Ѿ����ڴ˱�������,����!"; return false; } } return base.IsValidate(out message, properties, rule); }
public void ShouldForwardChainRules() { var ruleBase = new RuleBase<Target>(); var ruleSet = new RuleSet<Target>(); var rule = new Rule<Target>("rule 1", "description of rule 1", t => t.Number == 0, t => t.Number = 1); var rule2 = new Rule<Target>("rule 2", "", t => t.Number == 1, t => t.Number = 2); ruleSet.AddRule(rule); ruleSet.AddRule(rule2); ruleBase.AddRuleSet(ruleSet); var target = new Target(); var ruleEngine = new RuleEngine<Target>(ruleBase); ruleEngine.Execute(target); Assert.Equal(2, target.Number); }
public void ShouldExecuteRuleEngineOnSeveralTargets() { var ruleBase = new RuleBase<Target>(); var ruleSet = new RuleSet<Target>(); var rule = new Rule<Target>("rule 1", "", t => t.Number == 0, t => t.Number = 1); ruleSet.AddRule(rule); ruleBase.AddRuleSet(ruleSet); var ruleEngine = new RuleEngine<Target>(ruleBase); var target = new Target(); ruleEngine.Execute(target); Assert.Equal(1, target.Number); var newTarget = new Target(); ruleEngine.Execute(newTarget); Assert.Equal(1, newTarget.Number); }
float unitsW = 0.4f; // Factor #endregion Fields #region Methods public void Awake() { selStrings = new string[maxUnits]; for(int i=0;i<maxUnits;i++){ selStrings[i] = "unit"+i; } contentH = 1-titleH; ruleTextW = 1-ruleButtonW; //unitCommands = new UnitOrders[maxUnits]; ruleBases = new RuleBase[maxUnits]; for(int i=0;i<maxUnits;i++){ ruleBases[i] = new RuleBase(); //ruleBases[i].setOwner(i); ruleBases[i].addRule(new FuzzyRule("AA",Random.Range(1,10))); ruleBases[i].addRule(new FuzzyRule("BB",Random.Range(1,10))); ruleBases[i].addRule(new FuzzyRule("CC",Random.Range(1,10))); } /*rules = new Rule[maxRules]; for(int i=0;i<maxRules;i++){ rules[i] = new Rule("aa"); }*/ }
public CoverageAIsCarriedAndCoverageBIsCarriedAndCoverageAIsGreaterThanCoverageB() { CoverageAIsCarried = new CoverageIsCarried().SetCoverage("PD"); CoverageBIsCarried = new CoverageIsCarried().SetCoverage("UMPDNonStacked"); CoverageAIsGreaterThanCoverageB = new CoverageMustBeGreaterThanCoverageB().SetCoverageA("UMPDNonStacked").SetCoverageB("PD"); }
public Coverage007() { NoneAreCarried = new NoneAreCarried().AddCoverage("BI", "PD", "COMP", "Coll"); TOWIsCarried = new CoverageIsCarried().SetCoverage("TOW"); ERSIsCarried = new CoverageIsNotCarried().SetCoverage("UMBI+Stacked"); }