Here is a simple code snippet showing how one can use RuleCondition/RuleSet outside the Workflow scope:
WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
using (Stream s = typeof(Program).Assembly.GetManifestResourceStream("SimplePolicyWorkflow.rules"))
{
RuleDefinitions rd = (RuleDefinitions)serializer.Deserialize(XmlReader.Create(s));
RuleCondition c = rd.Conditions[0]; // or RuleSet
//typeof(rule context) should be passed
RuleValidation v = new RuleValidation(typeof(Program), null);
if (c.Validate(v))
{
//rule context instance should be passed
RuleExecution exe = new RuleExecution(v, new Program());
c.Evaluate(exe);
}
}
No comments:
Post a Comment