Workflow Foundation Rule Engine – Part I

Posted: March 15, 2009 in WF
Tags:

In my post on Business Rules and Rule Engine I have explained about Business Rules,Business Processes and what actually a Rule Engine does.In this post I will be discussing about the Rule Engine that comes with Windows Workflow Foundation(WF).

First let us explore the important classes related to Rule Engine and how they provide abstraction for the various components required for rule processing.All the classes are present within the namespace System.Workflow.Activities.Rules.

  • Rule – This class represents a Rule which is nothing but an if-then-else construct.So each Rule is composed of a condition and associated if-then and else actions.Rule class has the properties
    • Condition – This property is of type RuleCondition.This is the base class and actual implementation is provided by the RuleConditionExpression class.This class represents a condition as System.CodeDom.CodeExpression.The list of expression supported by WF is listed in MSDN
    • ElseActions/ThenActions – These are collection of type RuleAction.RuleAction is an abstract base class and actual implementation is provided by the classes:
      • RuleStatementAction – Modifies a property or calls a method.
      • RuleHaltAction – Halts the execution of the RuleEngine and returns the control to the calling code.
      • RuleUpdateAction – This class is used to indicate that a rule is updating a variable on which other rules are dependent.This causes reevaluation of the dependent rules.
  • RuleSet – This is a collection of Rule objects.
  • RuleEngine – This evaluates the RuleSet via it’s Execute method.

Now let’s quickly summarize the basic flow operation for the WF Rules Engine:

  • We have to define the RuleSet and associated Rules using Visual Studio 2005/2008.We can develop our WinForms application as well to create/edit the rules.The basic functionality of RuleEditor is exposed by the class System.Workflow.Activities.Rules.Design.RuleSetDialog.We can invoke this UI from our own application very easily.I will discuss about this in more details along with WF Rules Externalization.
  • The RuleSet editor create the RuleSet objects in memory and finally serialized and stored in some persistence storage.Visual Studio Editor stores them in .rules files.The structure of the .rules files is as shown below.Note how closely it resembles the object model we have discussed above.
  • <RuleDefinitions xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/workflow”>
      <RuleDefinitions.RuleSets>
        <RuleSet Name=”SampleRuleSet” ChainingBehavior=”Full” Description=”{p3:Null}” xmlns:p3=”
    http://schemas.microsoft.com/winfx/2006/xaml”>
          <RuleSet.Rules>
            <Rule Name=”SampleRule” ReevaluationBehavior=”Always” Priority=”0″ Description=”{p3:Null}” Active=”True”>
              <Rule.ThenActions>
                <RuleStatementAction>
                  ………………..
                </RuleStatementAction>
              </Rule.ThenActions>
              <Rule.Condition>
                <RuleExpressionCondition Name=”{p3:Null}”>
                  <RuleExpressionCondition.Expression>
                   ……………
                  </RuleExpressionCondition.Expression>
                </RuleExpressionCondition>
              </Rule.Condition>
            </Rule>
          </RuleSet.Rules>
        </RuleSet>
      </RuleDefinitions.RuleSets>
    </RuleDefinitions>

  • During execution time these .rules files are read and the RuleSet object is deserialized from xml data.The RuleEngine then executes and evaluates the RuleSets

In my next post I will explain with examples how we can use RuleSet along with PolicyActivity of WF.

Advertisements
Comments
  1. FleermPeesugs says:

    I’m new to this blog. Apologize for asking this though, but to OP…
    Do you know if this can be true;
    http://www.bluestickers.info/ringtones.php ?
    it came off http://ringtonecarrier.com
    Thanks 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s