forked from FrankPfattheicher/CodeArcKA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
72 lines (65 loc) · 2.33 KB
/
Program.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace EventSourcedActor
{
class Program
{
public static List<Activity> Activities = new List<Activity>();
public static EventStream Events = new EventStream();
// ReSharper disable once UnusedParameter.Local
static void Main(string[] args)
{
//var path = Path.GetDirectoryName(typeof(Activity).Assembly.Location) ?? ".";
var path = @"./Gebäude";
var files = Directory.EnumerateFiles(path, "*.puml", SearchOption.AllDirectories);
foreach (var file in files)
{
var activity = PumlActivityParser.ParseFile(file);
Activities.Add(activity);
Console.WriteLine($"Activity {activity.Name} (*) -> {activity.CurrentState}");
}
Console.WriteLine();
path = @"./Events";
Events.LoadFromDirectory(path);
foreach (var ev in Events.Events)
{
HandleEvent(ev);
Console.WriteLine();
}
Console.WriteLine("done.");
Console.ReadLine();
}
private static void HandleEvent(Event ev)
{
Console.WriteLine($"Event {ev}");
foreach (var act in Activities)
{
HandleEvent(act, ev);
}
}
private static void HandleEvent(Activity activity, Event ev)
{
var possibleTransitions = activity.Transitions
.Where(t => t.From == activity.CurrentState).ToList();
foreach (var transition in possibleTransitions)
{
if (transition.Conditions != null)
{
var allTrue = transition.Conditions
.All(cond => cond.IsMatch(activity, ev));
if (!allTrue) continue;
}
Console.WriteLine($"Activity {activity.Name}: {activity.CurrentState} -> {transition.To}");
activity.CurrentState = transition.To;
Events.InsertNext(new Event()
{
Context = activity.Name,
Type = "event",
Value = transition.To
});
}
}
}
}