1.1 --- a/SharpLibEar/Event.cs Sun Jul 31 12:03:52 2016 +0200
1.2 +++ b/SharpLibEar/Event.cs Fri Aug 12 20:25:05 2016 +0200
1.3 @@ -8,26 +8,54 @@
1.4 namespace SharpLib.Ear
1.5 {
1.6 [DataContract]
1.7 - public abstract class MEvent
1.8 + [KnownType("DerivedTypes")]
1.9 + public abstract class Event
1.10 {
1.11 - public string Name { get; protected set; }
1.12 - public string Description { get; protected set; }
1.13 + [DataMember]
1.14 + [AttributeObjectProperty
1.15 + (
1.16 + Id = "Event.Enabled",
1.17 + Name = "Enabled",
1.18 + Description = "When enabled an event instance can be triggered."
1.19 + )
1.20 + ]
1.21 + public bool Enabled { get; set; }
1.22
1.23 - public abstract void Trigger();
1.24 - };
1.25 -
1.26 - [DataContract]
1.27 - public abstract class Event : MEvent
1.28 - {
1.29 [DataMember]
1.30 public List<Action> Actions = new List<Action>();
1.31
1.32 + public string Name
1.33 + {
1.34 + //Get the name of this object attribute
1.35 + get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Name; }
1.36 + private set { }
1.37 + }
1.38 +
1.39 + public string Description
1.40 + {
1.41 + //Get the description of this object attribute
1.42 + get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Description; }
1.43 + private set { }
1.44 + }
1.45 +
1.46 +
1.47 protected Event()
1.48 {
1.49 -
1.50 + Enabled = true;
1.51 }
1.52
1.53 - public override void Trigger()
1.54 +
1.55 + /// <summary>
1.56 + /// Allows testing from generic edit dialog.
1.57 + /// </summary>
1.58 + public void Test()
1.59 + {
1.60 + Console.WriteLine("Event test");
1.61 + Trigger();
1.62 + }
1.63 +
1.64 +
1.65 + public void Trigger()
1.66 {
1.67 Console.WriteLine("Event triggered: " + Name);
1.68 foreach (Action action in Actions)
1.69 @@ -35,6 +63,15 @@
1.70 action.Execute();
1.71 }
1.72 }
1.73 - }
1.74 +
1.75 + /// <summary>
1.76 + /// So that data contract knows all our types.
1.77 + /// </summary>
1.78 + /// <returns></returns>
1.79 + private static IEnumerable<Type> DerivedTypes()
1.80 + {
1.81 + return SharpLib.Utils.Reflection.GetDerivedTypes<Event>();
1.82 + }
1.83 + };
1.84
1.85 }
1.86 \ No newline at end of file