Partager via


Using the PolicyActivity Activity

You can use the PolicyActivity activity to represent a collection of rules. A rule consists of conditions and resulting actions. You can think of a rule as an IF-THEN-ELSE statement, with the condition corresponding to the IF, and the actions defining the behavior of the THEN and ELSE clauses.

An action can do the following:

  • Set a field or property on a workflow.

  • Call a method on a workflow or objects in a workflow.

  • Call static methods on types in referenced assemblies.

  • Perform a Halt or an Update statement.

Rule Set Conditions and Actions

You create expressions for rule set conditions and Then and Else actions. For more information about conditions, see Using Conditions in Workflows.

Conditions support the same expression operators as actions, with the exception that the "=" operator is used for assignment rather than equality.

Halt and Update

You can also use the Halt and Update functions in expressions that are used with actions. The Halt action causes rule set execution to stop immediately, and returns control to the calling code. You use the Update function with forward chaining. For more information about how to use Update with forward chaining, see the "Explicit Forward Chaining" section later in this topic.

PolicyActivity and RuleSet Classes

To use a PolicyActivity activity in a workflow, add a PolicyActivity class to the workflow code. Then configure the RuleSetReference property on the PolicyActivity to point to a RuleSet by name in a RuleSetCollection. The PolicyActivity activity creates an instance of the RuleSet class; it is the RuleSet class that executes the rules. The PolicyActivity activity contains the properties that the rules operate on. When the condition of a rule evaluates to true, its Then actions execute. When the condition evaluates to false, the Else actions execute.

Each rule has a Priority property that governs the order in which the rules are evaluated and their actions are executed. The Windows Workflow Foundation rules evaluator evaluates rules individually and executes the rule’s actions based on the results of the rule’s condition evaluation. Higher-priority rules execute before lower-priority rules; rules with the same priority execute in alphabetical order by rule name. Priorities can be both positive and negative. The default priority for a rule is zero. For more information about priority of rules within a RuleSet, see Rules Evaluation in RuleSets and Priority-based Execution of RuleSets.

Each rule has a Rule Active property that determines whether the rule should be evaluated.

See Also

Reference

PolicyActivity
Rule
RuleSet
RuleSetCollection
RuleAttributeTarget
RuleReadAttribute
RuleWriteAttribute
RuleInvokeAttribute

Concepts

How to: Use Rule Conditions in Workflows
Rules Evaluation in RuleSets
Priority-based Execution of RuleSets
Rules and Conditions Overview

Other Resources

Simple Policy Sample
Advanced Policy Sample
Tutorial: Use Rules and Conditions in WF
Windows Workflow Foundation Activities