1
//
2
3
4
using System;
5
using System.Collections.Generic;
6
using System.Runtime.Serialization;
7
8
namespace SharpLib.Ear
9
{
10
[DataContract]
11
[KnownType("DerivedTypes")]
12
public abstract class Event
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; }
23
24
25
public List<Action> Actions = new List<Action>();
26
27
public string Name
28
29
//Get the name of this object attribute
30
get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Name; }
31
private set { }
32
}
33
34
public string Description
35
36
//Get the description of this object attribute
37
get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Description; }
38
39
40
41
public virtual string Brief()
42
43
return Name;
44
45
46
protected Event()
47
48
Enabled = true;
49
50
51
52
/// <summary>
53
/// Allows testing from generic edit dialog.
54
/// </summary>
55
public void Test()
56
57
Console.WriteLine("Event test");
58
Trigger();
59
60
61
62
public void Trigger()
63
64
Console.WriteLine("Event triggered: " + Name);
65
foreach (Action action in Actions)
66
67
action.Execute();
68
69
70
71
72
/// So that data contract knows all our types.
73
74
/// <returns></returns>
75
private static IEnumerable<Type> DerivedTypes()
76
77
return SharpLib.Utils.Reflection.GetDerivedTypes<Event>();
78
79
80
81
public override bool Equals(object obj)
82
83
//Default implementation assumes event are the same if types are the same
84
bool res= obj.GetType() == GetType();
85
return res;
86
87
};
88
89