public object UpdateFacts(RuleSetInfo rulesetInfo, Microsoft.RuleEngine.RuleEngine engine, object factsHandleIn) { object factsHandleOut; if (factsHandleIn == null) { // create the database connection since it doesn't exist SqlConnection con1 = new SqlConnection("Initial Catalog=Northwind;Data Source=(local);Integrated Security=SSPI;"); DataConnection dc1 = new DataConnection("Northwind", "PolicyValidity", con1); factsHandleOut = dc1; } else { // reuse the database connection previously created factsHandleOut = factsHandleIn; } engine.Assert(factsHandleOut); return(factsHandleOut); }
public object UpdateFacts(RuleSetInfo rulesetInfo, Microsoft.RuleEngine.RuleEngine engine, object factsHandleIn) { object factsHandleOut; // The following logic asserts the required DB rows only once and always uses the the same values (cached) during the first retrieval in subsequent execution cycles if (factsHandleIn == null) { SqlConnection con1 = new SqlConnection("Initial Catalog=Northwind;Data Source=(local);Integrated Security=SSPI;"); DataConnection dc1 = new DataConnection("Northwind", "CustInfo", con1); engine.Assert(dc1); factsHandleOut = dc1; } else { factsHandleOut = factsHandleIn; } return(factsHandleOut); }
public object UpdateFacts(RuleSetInfo rulesetInfo, Microsoft.RuleEngine.RuleEngine engine, object factsHandleIn) { object factsHandleOut; // The following logic asserts the required DB rows only once and always uses the the same values (cached) during the first retrieval in subsequent execution cycles if (factsHandleIn == null) { string strCmd1 = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=jinli2000"; SqlConnection con1 = new SqlConnection(strCmd1); // Using data connection binding // DataConnection dc1 = new DataConnection("Northwind", "CustInfo", con1); // Using data table binding SqlDataAdapter dAdapt1 = new SqlDataAdapter(); dAdapt1.TableMappings.Add("Table", "CustInfo"); con1.Open(); SqlCommand myCommand = new SqlCommand("SELECT * FROM CustInfo", con1); myCommand.CommandType = CommandType.Text; dAdapt1.SelectCommand = myCommand; DataSet ds = new DataSet("Northwind"); dAdapt1.Fill(ds); TypedDataTable tdt1 = new TypedDataTable(ds.Tables["CustInfo"]); engine.Assert(tdt1); factsHandleOut = tdt1; } else { factsHandleOut = factsHandleIn; } return(factsHandleOut); }
static void Main(string[] args) { // create a ruleset Console.WriteLine("Creating a new ruleset ..."); RuleSet rs = CreateRuleset("SampleRuleset"); // save it to a file Console.WriteLine("Saving ruleset to " + RuleStoreFilename + " ..."); SaveToFile(RuleStoreFilename, rs); // load the same ruleset from the file Console.WriteLine("Loading ruleset ..."); RuleSet newRS = LoadFromFile(RuleStoreFilename, "SampleRuleset"); // create an engine for the ruleset Microsoft.RuleEngine.RuleEngine engine = new Microsoft.RuleEngine.RuleEngine((newRS), false); //create an instance of the XML object XmlDocument xd1 = new XmlDocument(); xd1.Load(@"..\..\SampleDocumentInstance.xml"); TypedXmlDocument doc1 = new TypedXmlDocument("SampleSchema", xd1); // create the array of short-term facts object[] shortTermFacts = new object[4]; shortTermFacts[0] = doc1; shortTermFacts[1] = new Microsoft.Samples.BizTalk.BusinessRulesHelloWorld1.MySampleLibrary.MySampleBusinessObject(1); shortTermFacts[2] = new Microsoft.Samples.BizTalk.BusinessRulesHelloWorld1.MySampleLibrary.MySampleBusinessObject(2); shortTermFacts[3] = new Microsoft.Samples.BizTalk.BusinessRulesHelloWorld1.MySampleLibrary.MySampleBusinessObject(3); try { // assert several objects Console.WriteLine("Asserting objects ..."); engine.Assert(shortTermFacts); // now execute to see what happens Console.WriteLine("Executing ..."); engine.Execute(); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Press any key to finish ..."); System.Console.Read(); // Clean up SampleRuleStore.xml CleanUp(); // there should be 2 lines output: // MySampleBusinessObject -- MySampleMethod executed for object 1 with parameter 5 // MySampleBusinessObject -- MySampleMethod executed for object 3 with parameter 5 //This is because: /* * The rule created programmatically within the CreateRuleset() method says: * * IF * * MySampleBusinessObject.MyValue is not equal to the value of the ID element in the XML document. * THEN * * Execute MySampleBusinessObject.MySampleMethod(int) with a hardcoded integer constant 5 ". * * In our case we assert 3 .NET objects with "MyValue" = 1,2, and 3 along with an XML document with ID = 1, as fact instances. * * Hence the rule fires twice for the 2 .NET property values that are != 1 * */ }
private static void ExecuteRulesEngine(IBaseMessage pInMsg, string rulesPolicy) { Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver rulesDriver = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver(); SqlRuleStore sqlRuleStore = (SqlRuleStore)rulesDriver.GetRuleStore(); RuleSetInfoCollection rsic = sqlRuleStore.GetRuleSets(rulesPolicy, RuleStore.Filter.All); RuleSet rs = sqlRuleStore.GetRuleSet(rsic[0]); Microsoft.RuleEngine.RuleEngine engine = new Microsoft.RuleEngine.RuleEngine(rs); engine.Assert(pInMsg); engine.Execute(); }