Learning notes for ruleengine in winsows Workflow Foundation

Source: Internet
Author: User
The ruleengine in a workflow is a very important function used to calculate the true and false values of some expressions.
Some other workflows generally use the plug-in ruleengine or implement their own specific engine.

WWF integrates a powerful ruleenggine. Here is EnglishArticleHttp://msdn.microsoft.com/windowsvista/default.aspx? Pull =/library/en-US/dnlong/html/intwf_fndrlseng.asp

WWF has two types of rules: Condition and forward chaining.

1: Condition
Condtion is a simple logical expression, such as "If (A> 5) then B = 6 ;"
Condtion is generally used in ifelsebranch; while; replicator; condition activety Group
Condtion has two expressions: codecondtion, as its name implies, is to write and judge by yourselfCodeThe second is rulecondtionrefernce, which is defined in an XML file (XXX. Rules file ). The second type is recommended because the logic can be modified at any time. This is an example of a rule XML file.

XML
< Ruledefinitions. Conditions >
< Ruleexpressioncondition name = " Condition1 " >
< Ruleexpressioncondition. Expression >
< Ns0: codebinaryoperatorexpression Operator = " Valueequality " Xmlns: ns0 = " CLR-namespace: system. codedom; Assembly = system, version = 2.0.0.0, culture = neutral, publickeytoken = b77a5c561934e089 " >
< Ns0: codebinaryoperatorexpression. Left >
< Ns0: codepropertyreferenceexpression propertyname = " Wasexecuting " >
< Ns0: codepropertyreferenceexpression. targetobject >
< Ns0: codethisreferenceexpression />
</ Ns0: codepropertyreferenceexpression. targetobject >
</ Ns0: codepropertyreferenceexpression >
</ Ns0: codebinaryoperatorexpression. Left >
< Ns0: codebinaryoperatorexpression. Right >
< Ns0: codeprimitiveexpression >
< Ns0: codeprimitiveexpression. Value >
< NS1: Boolean xmlns: NS1 = " CLR-namespace: system; Assembly = mscorlib, version = 2.0.0.0, culture = neutral, publickeytoken = b77a5c561934e089 " > True </ NS1: Boolean >
</ Ns0: codeprimitiveexpression. Value >
</ Ns0: codeprimitiveexpression >
</ Ns0: codebinaryoperatorexpression. Right >
</ Ns0: codebinaryoperatorexpression >
</ Ruleexpressioncondition. Expression >
</ Ruleexpressioncondition >
</ Ruledefinitions. Conditions >

Ruleset is a set of rule. The difference is that these rule have a priority. It can be used in files such as filterpolicy.
The calculation of these rule in ruleset is also characteristic: re-calculation is performed at runtime based on the "associativity" of priority and judgment conditions. The meaning of re-calculation is that the highest priority is calculated once, instead of returning to the origin for further calculation after the association is calculated..
For example, there are now four conditions

Rule4 (Priority =   4 )

If =   15
Then B =   5
Rule3 (P = 3 )

If C =   5
Then B =   10

Rule2 (P = 2 )

If D =   2
Then =   15

Rule1 (P = 1 )

If B =   5
Then E =   7

The initial data is as follows:

    • A = 0
    • B = 0
    • C = 5
    • D = 2
    • E = 0

The result is as follows:

    • A = 15
    • B = 5
    • C = 5
    • D = 2
    • E = 7

The running logic is as follows: first run rule4, not compliant; execute rule3, Set B = 10; execute rule2, set a = 15; because the value of a has changed, therefore, return rule4 again, execute settings B = 5, check in turn do not meet the conditions, execute rule1, set E = 7.

2: forwardchaining
There are three methods:Inplicit; attributed-based; explicit
Inplicit: implicit expression.Implicit expression is the relationship between non-naming condition variables and is directly written. For example

Rule1 If ( = 3 )
B = 2 ;
Rule2 If (B = 2 )
C = 4 ;

Condition variable B in rule2 is implicitly related to rule1. Every time rule1 sets the value of B, rule needs to be recalculated. This write is automatically completed.
Attributed-based:Attribute to indicate which conditions are modified. There are three types of attributes: ruleread, rulewrite, and ruleinvoke.
For example, in the above example, if rule1 does not directly set B = 2, but calls a function F1 and F1 sets the value of B, then, we need to give F1 a property rulewrite:

Rule1
If ( = 2 )
F1 ()

Rule2
If (B = 2 )
C = 5

[Rulewrite ( " B " )]
F1 ()
{
B=2;
}

If the call is more complex, and F1 calls another function F2, F2 will actually modify B, then it will have to use the ruleinvoke attribute, such

Rule 1
If ( = 2 )
F1 ()
Rule 2
If (B = 2 )
C = 5 ;

[Ruleinvoke ( " F2 " )]
F1 ()
{
F2 ();
}

[Rulewrite ( " B " )]
F2 ()
{
B=2;
}

AsExpicit explicit declaration, Can be combined with the first two methods, usually used less. Expicit uses the update () method to update the value of a variable.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.