Skip to content

Commit 4a2b345

Browse files
authored
updated package version and documentation update (#289)
1 parent fa9c512 commit 4a2b345

4 files changed

Lines changed: 85 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [3.5.0]
6+
- `EvaluateRule` action now support custom inputs and filtered inputs
7+
- Added `ContainsWorkflow` method in RulesEngine (by @okolobaxa)
8+
- Fixed minor bugs (#258 & #259)
59

610
## [3.4.0]
711
- Made RulesEngine Strong Name and Authenticode signed

demo/DemoApp.EFDataExample/RulesEngineContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
3737
v => JsonSerializer.Serialize(v, null),
3838
v => JsonSerializer.Deserialize<RuleActions>(v, null));
3939

40-
entity.Ignore(b => b.WorkflowRulesToInject);
4140
entity.Ignore(b => b.WorkflowsToInject);
4241
});
4342
}

docs/index.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ RulesEngine is a highly extensible library to build rule based system using C# e
2828
- [Inbuilt Actions](#inbuilt-actions)
2929
- [OutputExpression](#outputexpression)
3030
- [Usage](#usage)
31+
- [EvaluateRule](#evaluaterule)
32+
- [Usage](#usage-1)
3133
- [Custom Actions](#custom-actions)
3234
- [Steps to use a custom Action](#steps-to-use-a-custom-action)
3335

@@ -320,6 +322,83 @@ Call `ExecuteAllRulesAsync` with the workflowName, ruleName and ruleParameters
320322

321323
```
322324

325+
#### EvaluateRule
326+
This action allows chaining of rules along with their actions. It also supports filtering inputs provided to chained rule as well as providing custom inputs
327+
328+
##### Usage
329+
Define OnSuccess or OnFailure Action for your Rule:
330+
```jsonc
331+
{
332+
"WorkflowName": "inputWorkflow",
333+
"Rules": [
334+
{
335+
"RuleName": "GiveDiscount20Percent",
336+
"Expression": "input1.couy == \"india\" AND input1.loyalityFactor <= 5 AND input1.totalPurchasesToDate >= 20000",
337+
"Actions": {
338+
"OnSuccess": {
339+
"Name": "OutputExpression", //Name of action you want to call
340+
"Context": { //This is passed to the action as action context
341+
"Expression": "input1.TotalBilled * 0.8"
342+
}
343+
},
344+
"OnFailure": { // This will execute if the Rule evaluates to failure
345+
"Name": "EvaluateRule",
346+
"Context": {
347+
"WorkflowName": "inputWorkflow",
348+
"ruleName": "GiveDiscount10Percent"
349+
}
350+
}
351+
}
352+
},
353+
{
354+
"RuleName": "GiveDiscount10Percent",
355+
"SuccessEvent": "10",
356+
"ErrorMessage": "One or more adjust rules failed.",
357+
"ErrorType": "Error",
358+
"RuleExpressionType": "LambdaExpression",
359+
"Expression": "input1.couy == \"india\" AND input1.loyalityFactor <= 2 AND input1.totalPurchasesToDate >= 5000 AND input2.totalOrders > 2 AND input2.noOfVisitsPerMonth > 2",
360+
"Actions": {
361+
"OnSuccess": {
362+
"Name": "OutputExpression", //Name of action you want to call
363+
"Context": { //This is passed to the action as action context
364+
"Expression": "input1.TotalBilled * 0.9"
365+
}
366+
}
367+
}
368+
}
369+
]
370+
}
371+
```
372+
Call `ExecuteActionWorkflowAsync` with the workflowName, ruleName and ruleParameters
373+
```c#
374+
var result = await rulesEngine.ExecuteActionWorkflowAsync("inputWorkflow","GiveDiscount20Percent",ruleParameters);
375+
Console.WriteLine(result.Output); //result.Output contains the evaluated value of the action
376+
```
377+
378+
In the above scenario if `GiveDiscount20Percent` succeeds, it will return 20 percent discount in output. If it fails, `EvaluateRule` action will call `GiveDiscount10Percent` internally and if it succeeds, it will return 10 percent discount in output.
379+
380+
EvaluateRule also supports passing filtered inputs and computed inputs to chained rule
381+
```jsonc
382+
"Actions": {
383+
"OnSuccess": {
384+
"Name": "EvaluateRule",
385+
"Context": {
386+
"WorkflowName": "inputWorkflow",
387+
"ruleName": "GiveDiscount10Percent",
388+
"inputFilter": ["input2"], //will only pass input2 from existing inputs,scopedparams to the chained rule
389+
"additionalInputs":[ // will pass a new input named currentDiscount with the result of the expression to the chained rule
390+
{
391+
"Name": "currentDiscount",
392+
"Expression": "input1.TotalBilled * 0.9"
393+
}
394+
]
395+
}
396+
}
397+
}
398+
399+
```
400+
401+
323402
### Custom Actions
324403
RulesEngine allows registering custom actions which can be used in the rules workflow.
325404

src/RulesEngine/RulesEngine.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Version>3.4.0</Version>
5+
<Version>3.5.0</Version>
66
<Copyright>Copyright (c) Microsoft Corporation.</Copyright>
77
<PackageLicenseFile>LICENSE</PackageLicenseFile>
88
<PackageProjectUrl>https://github.com/microsoft/RulesEngine</PackageProjectUrl>
9-
<Authors>Abbas Cyclewala, Dishant Munjal, Yogesh Prajapati</Authors>
9+
<Authors>Abbas Cyclewala</Authors>
1010
<Description>Rules Engine is a package for abstracting business logic/rules/policies out of the system. This works in a very simple way by giving you an ability to put your rules in a store outside the core logic of the system thus ensuring that any change in rules doesn't affect the core system.</Description>
1111
<PackageReleaseNotes>https://github.com/microsoft/RulesEngine/blob/main/CHANGELOG.md</PackageReleaseNotes>
1212
<PackageTags>BRE, Rules Engine, Abstraction</PackageTags>

0 commit comments

Comments
 (0)