-
Notifications
You must be signed in to change notification settings - Fork 2
/
AsyncPolicyEngineWithCompoundInputPoliciesExample.cs
40 lines (36 loc) · 1.73 KB
/
AsyncPolicyEngineWithCompoundInputPoliciesExample.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
38
39
40
using System.Threading.Tasks;
using Atrea.PolicyEngine.Builders;
using Atrea.PolicyEngine.Examples.Mocks.Domain;
using Atrea.PolicyEngine.Policies.Input;
namespace Atrea.PolicyEngine.Examples.Examples;
public class AsyncPolicyEngineWithCompoundInputPoliciesExample : BaseAsyncExample
{
public override async Task RunAsync()
{
// Configure the engine with the desired input policies, processors, and output policies.
var engine = AsyncPolicyEngineBuilder<TranslatableItem>
.Configure()
.WithAsyncInputPolicies(
// 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))
).WithParallelProcessors(
// Use the SingleWordTranslator and DictionaryTranslator to perform translations.
// Note: translators will run in parallel.
SingleWordTranslator,
DictionaryTranslator
).WithParallelOutputPolicies(
// After processing, publish the translation, mark the item as translated, and
// send a translation success email to the user who requested it.
// Note: output policies will run in parallel.
PublishTranslation,
MarkItemTranslated,
SendTranslationSuccessEmail
).Build();
var translatableItem = new TranslatableItem();
// Process the item.
await engine.ProcessAsync(translatableItem);
}
}