SharpLibEar/Event.cs
author StephaneLenclud
Thu, 18 Aug 2016 14:35:50 +0200
changeset 238 c92587ddabcd
parent 237 1a1c2ae3a29c
child 243 cc2251d065db
permissions -rw-r--r--
Support for launch action and WMC HID events.
     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     public abstract class Event : Object
    12     {
    13         [DataMember]
    14         [AttributeObjectProperty
    15             (
    16                 Id = "Event.Enabled",
    17                 Name = "Enabled",
    18                 Description = "When enabled an event instance can be triggered."
    19             )
    20         ]
    21         public bool Enabled { get; set; }
    22 
    23         [DataMember]
    24         public List<Action> Actions = new List<Action>();
    25 
    26 
    27 
    28         protected Event()
    29         {
    30             Enabled = true;
    31         }
    32 
    33 
    34         /// <summary>
    35         /// Allows testing from generic edit dialog.
    36         /// </summary>
    37         public void Test()
    38         {
    39             Console.WriteLine("Event test");
    40             Trigger();
    41         }
    42 
    43 
    44         public void Trigger()
    45         {
    46             Console.WriteLine("Event triggered: " + Name);
    47             foreach (Action action in Actions)
    48             {
    49                 action.Execute();
    50             }
    51         }
    52 
    53         //
    54         public override bool Equals(object obj)
    55         {
    56             //Default implementation assumes event are the same if types are the same
    57             bool res=  obj.GetType() == GetType();
    58             return res;
    59         }
    60     };
    61 
    62 }