-
Notifications
You must be signed in to change notification settings - Fork 586
/
Copy pathNestedInputDemo.cs
84 lines (72 loc) · 2.57 KB
/
NestedInputDemo.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Newtonsoft.Json;
using RulesEngine.Extensions;
using RulesEngine.Models;
using System;
using System.Collections.Generic;
using System.IO;
namespace DemoApp
{
internal class ListItem
{
public int Id { get; set; }
public string Value { get; set; }
}
public class NestedInputDemo
{
public void Run()
{
Console.WriteLine($"Running {nameof(NestedInputDemo)}....");
var nestedInput = new {
SimpleProp = "simpleProp",
NestedProp = new {
SimpleProp = "nestedSimpleProp",
ListProp = new List<ListItem>
{
new ListItem
{
Id = 1,
Value = "first"
},
new ListItem
{
Id = 2,
Value = "second"
}
}
}
};
var files = Directory.GetFiles(Directory.GetCurrentDirectory(), "NestedInputDemo.json", SearchOption.AllDirectories);
if (files == null || files.Length == 0)
{
throw new Exception("Rules not found.");
}
var fileData = File.ReadAllText(files[0]);
var Workflows = JsonConvert.DeserializeObject<List<Workflow>>(fileData);
var executionRules = new ReSettings();
executionRules.NestedRuleExecutionMode = NestedRuleExecutionMode.Performance;
executionRules.CustomTypes = new Type[] { typeof(pep) };
var bre = new RulesEngine.RulesEngine(Workflows.ToArray(), executionRules);
foreach (var workflow in Workflows)
{
var resultList = bre.ExecuteAllRulesAsync(workflow.WorkflowName, nestedInput).Result;
resultList.OnSuccess((eventName) => {
Console.WriteLine($"{workflow.WorkflowName} evaluation resulted in success - {eventName}");
}).OnFail(() => {
Console.WriteLine($"{workflow.WorkflowName} evaluation resulted in failure");
});
}
}
public class pep
{
public string Key;
public object Value;
public pep(string key, object value)
{
this.Key = key;
this.Value = value;
}
}
}
}