-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlantumlStateMachineReport.cs
99 lines (87 loc) · 3.08 KB
/
PlantumlStateMachineReport.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.IO;
using System.Collections.Generic;
using Appccelerate.StateMachine;
using Appccelerate.StateMachine.Machine;
using Appccelerate.StateMachine.Machine.States;
namespace appccelerate_statemachine_plantuml_rapport
{
public class PlantumlStateMachineReport<TState, TEvent> : IStateMachineReport<TState, TEvent>
where TState : IComparable
where TEvent : IComparable
{
private PlantumlStateMachineReport()
{
}
public PlantumlStateMachineReport(TextWriter textWriter)
{
this.textWriter = textWriter;
}
TextWriter textWriter;
public void Report(string name, IEnumerable<IStateDefinition<TState, TEvent>> states, TState initialStateId)
{
textWriter.WriteLine("@startuml " + name);
textWriter.WriteLine("[*] --> " + initialStateId);
foreach (var state in states)
{
if (state.Level != 1)
{
continue;
}
WriteState(state);
}
textWriter.WriteLine("@enduml");
textWriter.Close();
}
void WriteState(IStateDefinition<TState, TEvent> state)
{
textWriter.WriteLine("state " + state.Id + " {");
if (state.HistoryType == HistoryType.Shallow)
{
textWriter.WriteLine("[H] -left> " + state.Id + " : shallow");
}
if (state.HistoryType == HistoryType.Deep)
{
textWriter.WriteLine("[H] -left> " + state.Id + " : deep");
}
if (state.InitialState != null)
{
textWriter.WriteLine("[*] -> " + state.InitialState.Id);
}
foreach (var subState in state.SubStates)
{
WriteState(subState);
}
textWriter.WriteLine("}");
foreach (var action in state.EntryActions)
{
textWriter.WriteLine(state.Id + " : entry / " + action.Describe());
}
foreach (var action in state.ExitActions)
{
textWriter.WriteLine(state.Id + " : exit / " + action.Describe());
}
foreach (var transitionInfo in state.TransitionInfos)
{
String text = transitionInfo.Source.Id.ToString();
if (transitionInfo.Target != null)
{
text += " --> " + transitionInfo.Target.Id;
}
if (transitionInfo.EventId != null)
{
text += " : " + transitionInfo.EventId;
if (transitionInfo.Guard != null)
{
text += " [" + transitionInfo.Guard.Describe() + "]";
}
foreach (var action in transitionInfo.Actions)
{
text += " / " + action.Describe();
}
}
textWriter.WriteLine(text);
}
}
}
}