-
Notifications
You must be signed in to change notification settings - Fork 2
/
SimpleAsyncPolicyEngineExample.cs
38 lines (34 loc) · 1.46 KB
/
SimpleAsyncPolicyEngineExample.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
using System.Threading.Tasks;
using Atrea.PolicyEngine.Builders;
using Atrea.PolicyEngine.Examples.Mocks.Domain;
namespace Atrea.PolicyEngine.Examples.Examples;
public class SimpleAsyncPolicyEngineExample : BaseAsyncExample
{
public override async Task RunAsync()
{
// Configure the engine with the desired input policies, processors, and output policies.
var engine = AsyncPolicyEngineBuilder<TranslatableItem>
.Configure()
.WithAsyncInputPolicies(
// Only process items that haven't yet be translated, and are translations from
// Canadian French to US english.
NotYetTranslated,
FromCanadianFrench,
ToUsEnglish
).WithParallelProcessors(
// Use GoogleTranslator, MicrosoftTranslator, and CacheTranslator to perform translations.
// Note: translators will run in parallel.
GoogleTranslator,
MicrosoftTranslator,
CacheTranslator
).WithParallelOutputPolicies(
// After processing, publish the translation and mark the item as translated.
// Note: output policies will run in parallel.
PublishTranslation,
MarkItemTranslated
).Build();
var translatableItem = new TranslatableItem();
// Process the item.
await engine.ProcessAsync(translatableItem);
}
}