StephaneLenclud@210: //
StephaneLenclud@210: 
StephaneLenclud@210: 
StephaneLenclud@210: using System;
StephaneLenclud@210: using System.Collections.Generic;
StephaneLenclud@253: using System.Diagnostics;
StephaneLenclud@265: using System.Linq;
StephaneLenclud@210: using System.Runtime.Serialization;
StephaneLenclud@258: using System.Threading.Tasks;
StephaneLenclud@210: 
StephaneLenclud@210: namespace SharpLib.Ear
StephaneLenclud@210: {
StephaneLenclud@210:     [DataContract]
StephaneLenclud@260:     [AttributeObject(Id = "Event", Name = "User Event", Description = "An event that can be triggered by users.")]
StephaneLenclud@260:     public class Event : Object
StephaneLenclud@210:     {
StephaneLenclud@231:         [DataMember]
StephaneLenclud@231:         [AttributeObjectProperty
StephaneLenclud@231:             (
StephaneLenclud@231:                 Id = "Event.Enabled",
StephaneLenclud@231:                 Name = "Enabled",
StephaneLenclud@231:                 Description = "When enabled an event instance can be triggered."
StephaneLenclud@231:             )
StephaneLenclud@231:         ]
Stephane@243:         public bool Enabled { get; set; } = true;
StephaneLenclud@210: 
StephaneLenclud@262: 
StephaneLenclud@210: 
StephaneLenclud@231: 
StephaneLenclud@231:         /// <summary>
StephaneLenclud@231:         /// Allows testing from generic edit dialog.
StephaneLenclud@231:         /// </summary>
StephaneLenclud@260:         public async void Test()
StephaneLenclud@231:         {
StephaneLenclud@253:             Trace.WriteLine("Event test");
StephaneLenclud@260:             await Trigger();
StephaneLenclud@231:         }
StephaneLenclud@231: 
StephaneLenclud@231: 
StephaneLenclud@258:         public async Task Trigger()
StephaneLenclud@210:         {
StephaneLenclud@260:             Trace.WriteLine("Event triggered: " + AttributeName);
StephaneLenclud@265:             foreach (Action action in Objects.OfType<Action>())
StephaneLenclud@210:             {
StephaneLenclud@258:                 await action.Execute();
StephaneLenclud@210:             }
StephaneLenclud@210:         }
StephaneLenclud@231: 
StephaneLenclud@237:         //
StephaneLenclud@237:         public override bool Equals(object obj)
StephaneLenclud@237:         {
StephaneLenclud@237:             //Default implementation assumes event are the same if types are the same
StephaneLenclud@237:             bool res=  obj.GetType() == GetType();
StephaneLenclud@237:             return res;
StephaneLenclud@237:         }
StephaneLenclud@231:     };
StephaneLenclud@210: 
StephaneLenclud@210: }