-
Notifications
You must be signed in to change notification settings - Fork 2
/
PolicyEngineWithCompoundInputPoliciesExample.cs
37 lines (33 loc) · 1.52 KB
/
PolicyEngineWithCompoundInputPoliciesExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Atrea.PolicyEngine.Builders;
using Atrea.PolicyEngine.Examples.Mocks.Domain;
using Atrea.PolicyEngine.Policies.Input;
namespace Atrea.PolicyEngine.Examples.Examples;
public class PolicyEngineWithCompoundInputPoliciesExample : BaseExample
{
public override void Run()
{
// Configure the engine with the desired input policies, processors, and output policies.
var engine = PolicyEngineBuilder<TranslatableItem>
.Configure()
.WithInputPolicies(
// Ensure that the item has not yet been translated.
NotYetTranslated,
// The engine should process items if the translation being performed is for
// items from US English to UK English OR from UK English to US English.
FromUsEnglish.And(ToUkEnglish).Or(FromUkEnglish.And(ToUsEnglish))
).WithProcessors(
// Use the SingleWordTranslator and DictionaryTranslator to perform translations.
SingleWordTranslator,
DictionaryTranslator
).WithOutputPolicies(
// After processing, publish the translation, mark the item as translated, and
// send a translation success email to the user who requested it.
PublishTranslation,
MarkItemTranslated,
SendTranslationSuccessEmail
).Build();
var translatableItem = new TranslatableItem();
// Process the item.
engine.Process(translatableItem);
}
}