A rule is an automatic action that Community Server performs in response to platform triggers and conditions specified in the Rules tab of the Control Panel. They consist of three parts, a trigger (IRuleTrigger), a condition (IConfigurableRuleCondition) and an action (IConfigurableRuleAction).
When you want to allow users to setup actions that can be performed automatically without having to write code for an event handler then the solution would be to create a rule trigger, condition or action. Some of the out-of-the-box rules allow you to award a number of points for publishing a blog post. Or you could send a congratulatory email for liking a piece of content. There are many scenarios that can be accomplished with rules.
When the trigger occurs, the condition(s) is/are evaluated and then, if met, the action(s) are executed. In addition, a rule can enabled or disabled as necessary.
The rule trigger takes advantage of an event hander to fire the rule. In this sample the rule is triggered after a user is created. The two main factors in the trigger are the RuleTriggerExecutionContext and the IRuleController. The RuleTriggerExecutionContext collects and sets the data that will be passed along to the other parts of the rule. The IRuleController allows you to actually trigger the rule. This is typically used along with an event handler. You can think of the trigger as the When part of the rule statement.
This is a simple rule condition, it evaluates two strings and checks for equality. The condition has three main members. The
ConfigurableValues property which allows you to setup the controls that will be displayed in the UI for configuring the condition. This is followed by the
Evaluate method which determines if the rule should continue executing. It accepts an IRuleExecutionRuntime argument that is used to retrieve the
PropertyGroup array returned by the
ConfigurableValues. Finally you'll need to return a
PrimativeType in the
RequiredPrimitiveType property. You can think of the condition as the If part of the rule statement.
Once the rule trigger and condition are satisfied then the action can take place. The main section if the action is the
Execute method. It is what performs the action based on the
IRuleExecutionRuntime argument that was setup in the trigger. You can think of the action as the Then part of the rule statement.
Here is the result of the plugins displayed in the UI when creating a new rule.