private static void ExampleTest() { //规则 XmlDocument rules = new XmlDocument(); string directory = AppDomain.CurrentDomain.BaseDirectory + @"\RuleExample.xml";//规则链条 rules.Load(directory); ROM rom = Compiler.Compile(rules); //模型 XmlDocument model = new XmlDocument(); model.LoadXml("<a><number1>10</number1><number2>1</number2><result2/></a>"); rom.AddModel("bob", model); Console.WriteLine("Starting Test:" + DateTime.Now); //解析全部规则计算 rom.Evaluate(); }
private XmlDocument LoadAndEvaluateRules(string xml) { string directory = AppDomain.CurrentDomain.BaseDirectory + @"\" + XML_FILE_NAME; // Load rules XmlDocument rules = new XmlDocument(); rules.Load(directory); // Load cart model XmlDocument model = new XmlDocument(); model.LoadXml(xml); // Evaluate rules ROM rom = Compiler.Compile(rules); rom.AddModel(CART_TAG, model); rom.Evaluate(); return(model); }
private static void FactTest() { DateTime end; DateTime start; TimeSpan diff; Console.WriteLine("Loading and Compiling ruleset: " + DateTime.Now); //rules XmlDocument rules = new XmlDocument(); string directory = AppDomain.CurrentDomain.BaseDirectory + "ChainedRules.xml"; rules.Load(directory); ROM rom = Compiler.Compile(rules); //model XmlDocument model = new XmlDocument(); model.LoadXml("<a><result1/><result2/></a>"); rom.AddModel("bob", model); //set default values for rom Console.WriteLine("Starting Test:" + DateTime.Now); int total = 5000; start = DateTime.Now; for (int counter = 0; counter < total; counter++) { //cause all rules to evaluate rom.Evaluate(); } end = DateTime.Now; diff = end - start; Console.WriteLine("Total ms: " + diff.TotalMilliseconds); Console.WriteLine("milliseconds per ruleset: " + ((TimeSpan)(end - start)).TotalMilliseconds / (total * 10d)); }
public void ExecuteTaxRules() { XmlDocument rules = new XmlDocument(); string directory = AppDomain.CurrentDomain.BaseDirectory + @"\ACA.xml"; string inBond, inFavorite, inCity ; bool isNumeric = true; int n; rules.Load(directory); //model XmlDocument model = new XmlDocument(); model.LoadXml(@"<Courier><Bond>500000</Bond><City>Taguig</City><Favorite>1</Favorite><CourierID></CourierID></Courier>"); ROM rom = Compiler.Compile(rules); rom.AddModel("Courier", model); // rom.Evaluate(); var CID = model["Courier"]["CourierID"].InnerText; var message = string.Format("Assigned to courier id {0}", CID); // Console.WriteLine(message); do { do { if (isNumeric == false) Console.Write("Input is invalid; re-input bond: "); else Console.Write("Input bond: "); inBond = Console.ReadLine(); isNumeric = int.TryParse(inBond, out n); } while (isNumeric != true); isNumeric = true; do { if (isNumeric == false) Console.Write("Input is invalid; re-input Favorite: "); else Console.Write("Input Favorite: "); inFavorite = Console.ReadLine(); isNumeric = int.TryParse(inFavorite, out n); } while (isNumeric != true); Console.Write("Input City: "); inCity = Console.ReadLine(); if (inCity == "x") break; model["Courier"]["Bond"].InnerText = inBond; model["Courier"]["Favorite"].InnerText = inFavorite; model["Courier"]["City"].InnerText = inCity; rom.Evaluate(); CID = model["Courier"]["CourierID"].InnerText; message = string.Format("Assigned to courier id {0}", CID); Console.WriteLine(message); } while (inCity != "X"); }