문제

This is an instance of a 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;
     }
 }

and this is a code for a 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;
  }

As they're both providing a list of facts for policies, why aren't they same? What's the difference between them?

도움이 되었습니까?

해결책

A FactCreater is a helper class specifically for the Business Rules Composer that give you the ability to Assert, Short Term, non TypedXmlDocument facts, such as instances of .Net Classes, when you do Test Policy in the Composer. It is not used outside of the Composer.

A FactRetriever is used to Assert Facts, called Long Term, behind the scene buy the engine. It is used whenever the Policy is executed, including by the Composer.

A FactCreator is effectively the Composer's equivalent of the CallRules Shape in an Orchestration, where you specify the Short Term facts.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top