这是FactCreator
:
public class MyFactCreator : IFactCreator
{
private object[] myFacts;
public MyFactCreator()
{
}
public object[] CreateFacts ( RuleSetInfo rulesetInfo )
{
myFacts = new object[1];
myFacts.SetValue(new MySampleBusinessObject(),0);
return myFacts;
}
public Type[] GetFactTypes (RuleSetInfo rulesetInfo)
{
return null;
}
}
这是FactRetriever
的代码:
public class MyFactRetriever:IFactRetriever
{
public object UpdateFacts(RuleSetInfo rulesetInfo, Microsoft.RuleEngine.RuleEngine engine, object factsHandleIn)
{
object factsHandleOut;
if (factsHandleIn == null)
{
SqlDataAdapter dAdapt = new SqlDataAdapter();
dAdapt.TableMappings.Add("Table", "CustInfo");
SqlConnection conn = new SqlConnection("Initial Catalog=Northwind;Data Source=(local);Integrated Security=SSPI;");
conn.Open();
SqlCommand myCommand = new SqlCommand("SELECT * FROM CustInfo", conn);
myCommand.CommandType = CommandType.Text;
dAdapt.SelectCommand = myCommand;
DataSet ds = new DataSet("Northwind");
dAdapt.Fill(ds);
TypedDataTable tdt = new TypedDataTable(ds.Tables["CustInfo"]);
engine.Assert(tdt);
factsHandleOut = tdt;
}
else
factsHandleOut = factsHandleIn;
return factsHandleOut;
}
由于他们都提供了政策事实清单,为什么他们不一样?它们之间的区别是什么?
答案 0 :(得分:2)
FactCreater是一个专门用于Business Rules Composer的帮助程序类,当您在Composer中执行测试策略时,它可以使您能够使用Assert,Short Term,非TypedXmlDocument事实,例如.Net类的实例。它不在Composer之外使用。
FactRetriever用于Assert Facts,称为Long Term,在幕后购买引擎。每当执行策略时都会使用它,包括由Composer执行。
FactCreator实际上是作为Orchestration中CallRules Shape的Composer的等效物,您可以在其中指定短期事实。