1
//
2
3
4
using System;
5
using System.Collections.Generic;
6
using System.Diagnostics;
7
using System.Linq;
8
using System.Runtime.Serialization;
9
using System.Threading.Tasks;
10
11
namespace SharpLib.Ear
12
{
13
[DataContract]
14
[AttributeObject(Id = "Event", Name = "User Event", Description = "An event that can be triggered by users.")]
15
public class Event : Object
16
17
[DataMember]
18
[AttributeObjectProperty
19
(
20
Id = "Event.Enabled",
21
Name = "Enabled",
22
Description = "When enabled an event instance can be triggered."
23
)
24
]
25
public bool Enabled { get; set; } = true;
26
27
28
29
30
/// <summary>
31
/// Allows testing from generic edit dialog.
32
/// </summary>
33
public async void Test()
34
35
Trace.WriteLine("Event test");
36
await Trigger();
37
}
38
39
40
public async Task Trigger()
41
42
Trace.WriteLine("Event triggered: " + AttributeName);
43
foreach (Action action in Objects.OfType<Action>())
44
45
await action.Execute();
46
47
48
49
50
public override bool Equals(object obj)
51
52
//Default implementation assumes event are the same if types are the same
53
bool res= obj.GetType() == GetType();
54
return res;
55
56
};
57
58