1
//
2
3
4
using System;
5
using System.Collections.Generic;
6
using System.Diagnostics;
7
using System.Runtime.Serialization;
8
9
namespace SharpLib.Ear
10
{
11
[DataContract]
12
public abstract class Event : Object
13
14
[DataMember]
15
[AttributeObjectProperty
16
(
17
Id = "Event.Enabled",
18
Name = "Enabled",
19
Description = "When enabled an event instance can be triggered."
20
)
21
]
22
public bool Enabled { get; set; } = true;
23
24
25
public List<Action> Actions = new List<Action>();
26
27
28
protected override void DoConstruct()
29
30
base.DoConstruct();
31
32
// TODO: Construct properties too
33
foreach (Action a in Actions)
34
35
a.Construct();
36
}
37
38
39
40
41
/// <summary>
42
/// Allows testing from generic edit dialog.
43
/// </summary>
44
public void Test()
45
46
Trace.WriteLine("Event test");
47
Trigger();
48
49
50
51
public void Trigger()
52
53
Trace.WriteLine("Event triggered: " + Name);
54
foreach (Action action in Actions)
55
56
action.Execute();
57
58
59
60
61
public override bool Equals(object obj)
62
63
//Default implementation assumes event are the same if types are the same
64
bool res= obj.GetType() == GetType();
65
return res;
66
67
};
68
69