locked
Policy rules execution results RRS feed

  • Question

  • Using Feb CTP.

    I defined a Policy which reads its rules from XML. After Execution of the Policy it correctly maps the result of the ThenAction of the rules to properties defined in the workflows. This works fine.

    However, I do not want the make the code in the workflow aware of the name of the thenaction. If I have a new rule, I the have to change and compile the code again. I rather want to check the results after policy execution and loop through the thenaction results.

    Is this possible?

     

    Tuesday, May 30, 2006 9:08 AM

Answers

  • So you do not want to define the _policyresult1, _policyresult2, etc. fields on the workflow in order to see what rules executed, is that correct?  What actions would the rules have in this case? 

    One option is to use the tracking service.  Rule evaluation results are sent to the tracking service via a UserTrackingRecord.  See the RuleActionTrackingEventSample in the SDK for an example.

    Alternatively, if you want some result fields to be available for inspection after the policy executes, but do not want to modify the workflow itself, you could wrap the ruleset execution in a custom activity that has the appopriate properties defined - either a basic activity that directly executes the ruleset, or a composite activity that contains the Policy activity.

     

    Wednesday, May 31, 2006 4:11 PM
  • In that case, another option, beyond those above, might be to just set the "master" boolean in the rules themselves.  For example, define the boolean on the workflow and give it a default of True.  If any of the conditions in the Policy evaluate to false, set the "master" boolean to False.
    Thursday, June 1, 2006 6:14 PM

All replies

  • I'm afraid I'm not clear on what you are trying to achieve.  Can you provide an example of the rules you are creating and the behavior you want to see?
    Wednesday, May 31, 2006 1:36 AM
  • Hi Jurgen,

    Very pleased to see that you are trying to help.

    The code underneath already works, it may help to clarify my needs further. I strive to make the workflow code unaware of the actual rules that should be validated. Authorname and username are domain logic properties that I make available in my workflow.

    Now, the rules engine fills the boolean variables. What I rather want is to query the Policy what the results of the evaluated conditions are. Is this possible?

     

    public sealed partial class Workflow1: SequentialWorkflowActivity

    {

    string _authorname = string.Empty;

    string _supervisorname = string.Empty;

    bool _policyresult1 = true;

    bool _policyresult2 = true;

    bool _policyresult3 = true;

    bool _policyresult4 = true;

    bool _policyresult5 = true;

    public Workflow1()

    {

    InitializeComponent();

    BuildRuleSet();

    }

    private void BuildRuleSet()

    {

    RuleSet ruleSet = null;

    using ( XmlReader xomlReader = new XmlTextReader("MyRuleSet.xml"))

    {

    ruleSet = (RuleSet)new WorkflowMarkupSerializer().Deserialize(xomlReader);

    }

    RuleDefinitions definitions = new RuleDefinitions();

    definitions.RuleSets.Add(ruleSet);

    SetValue(RuleDefinitions.RuleDefinitionsProperty, definitions);

    }

    private void OnPreparePolicy(object sender, EventArgs e)

    {

    _authorname = "Foo";

    _supervisorname = "Foo";

    }

    private void OnEvaluatePolicyResults(object sender, EventArgs e)

    {

    bool totalResult = true;

    if( _policyresult1 == false || _policyresult2 == false || _policyresult3 == false ||

    _policyresult4 == false || _policyresult5 == false )

    totalResult = false;

    Console.WriteLine("Policy result: {0}", totalResult.ToString());

    }

    }

    Wednesday, May 31, 2006 9:08 AM
  • So you do not want to define the _policyresult1, _policyresult2, etc. fields on the workflow in order to see what rules executed, is that correct?  What actions would the rules have in this case? 

    One option is to use the tracking service.  Rule evaluation results are sent to the tracking service via a UserTrackingRecord.  See the RuleActionTrackingEventSample in the SDK for an example.

    Alternatively, if you want some result fields to be available for inspection after the policy executes, but do not want to modify the workflow itself, you could wrap the ruleset execution in a custom activity that has the appopriate properties defined - either a basic activity that directly executes the ruleset, or a composite activity that contains the Policy activity.

     

    Wednesday, May 31, 2006 4:11 PM
  • So you do not want to define the _policyresult1, _policyresult2, etc. fields on the workflow in order to see what rules executed, is that correct?  What actions would the rules have in this case? 

    That is correct. The only actions they would perform is to check a condition and return a boolean condition if that condition was valid. In the workflow I then loop through all executed conditions and set a "master" boolean if all checks are ok. Based on that boolean I proceed, or not.

    Thursday, June 1, 2006 1:35 PM
  • In that case, another option, beyond those above, might be to just set the "master" boolean in the rules themselves.  For example, define the boolean on the workflow and give it a default of True.  If any of the conditions in the Policy evaluate to false, set the "master" boolean to False.
    Thursday, June 1, 2006 6:14 PM