-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExecutionState.cs
118 lines (100 loc) · 3.32 KB
/
ExecutionState.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.Text;
using MetaphysicsIndustries.Collections;
namespace MetaphysicsIndustries.Amethyst
{
class ExecutionState
{
public ExecutionState(AmethystControl control)
{
control.Entities.ItemAdded += Entities_ItemAdded;
control.Entities.ItemRemoved += Entities_ItemRemoved;
}
public ValueCache ValueCache = new ValueCache();
Dictionary<AmethystElement, bool> _isPaused = new Dictionary<AmethystElement, bool>();
public bool IsPaused(AmethystElement element)
{
if (!_isPaused.ContainsKey(element))
{
_isPaused[element] = false;
}
return _isPaused[element];
}
public void Pause(AmethystElement element)
{
_isPaused[element] = true;
}
public void Unpause(AmethystElement elements)
{
_isPaused[elements] = false;
}
Dictionary<AmethystElement, Exception> _lastException = new Dictionary<AmethystElement, Exception>();
public bool IsException(AmethystElement element)
{
return _lastException.ContainsKey(element);
}
public Exception GetLastException(AmethystElement element)
{
if (!_lastException.ContainsKey(element))
{
return null;
}
return _lastException[element];
}
public void ClearLastException(AmethystElement element)
{
if (_lastException.ContainsKey(element))
{
_lastException.Remove(element);
}
}
Set<OutputTerminal> _hasChanged = new Set<OutputTerminal>();
public void SetHasChanged(AmethystElement element)
{
foreach (OutputTerminal term in Collection.Extract<Terminal, OutputTerminal>(element.Terminals))
{
SetHasChanged(term);
}
}
public void SetHasChanged(OutputTerminal terminal)
{
_hasChanged.Add(terminal);
}
public void ClearHasChanged(AmethystElement element)
{
foreach (OutputTerminal term in Collection.Extract<Terminal, OutputTerminal>(element.Terminals))
{
ClearHasChanged(term);
}
}
public void ClearHasChanged(OutputTerminal terminal)
{
_hasChanged.Remove(terminal);
}
public void ClearAllHasChanged()
{
_hasChanged.Clear();
}
public bool GetHasChanged(OutputTerminal terminal)
{
return _hasChanged.Contains(terminal);
}
void Entities_ItemRemoved(Crystalline.Entity item)
{
if (item is AmethystElement)
{
AmethystElement element = (AmethystElement)item;
if (_isPaused.ContainsKey(element))
{
_isPaused.Remove(element);
}
ClearLastException(element);
ClearHasChanged(element);
}
}
void Entities_ItemAdded(Crystalline.Entity item)
{
}
}
}