SharpLibEar/Event.cs
author StephaneLenclud
Thu, 18 Aug 2016 17:43:03 +0200
changeset 240 5c4f1e2bf29a
parent 237 1a1c2ae3a29c
child 243 cc2251d065db
permissions -rw-r--r--
Adding empty class for eject optical drive action.
StephaneLenclud@210
     1
//
StephaneLenclud@210
     2
StephaneLenclud@210
     3
StephaneLenclud@210
     4
using System;
StephaneLenclud@210
     5
using System.Collections.Generic;
StephaneLenclud@210
     6
using System.Runtime.Serialization;
StephaneLenclud@210
     7
StephaneLenclud@210
     8
namespace SharpLib.Ear
StephaneLenclud@210
     9
{
StephaneLenclud@210
    10
    [DataContract]
StephaneLenclud@238
    11
    public abstract class Event : Object
StephaneLenclud@210
    12
    {
StephaneLenclud@231
    13
        [DataMember]
StephaneLenclud@231
    14
        [AttributeObjectProperty
StephaneLenclud@231
    15
            (
StephaneLenclud@231
    16
                Id = "Event.Enabled",
StephaneLenclud@231
    17
                Name = "Enabled",
StephaneLenclud@231
    18
                Description = "When enabled an event instance can be triggered."
StephaneLenclud@231
    19
            )
StephaneLenclud@231
    20
        ]
StephaneLenclud@231
    21
        public bool Enabled { get; set; }
StephaneLenclud@210
    22
Stephane@212
    23
        [DataMember]
Stephane@212
    24
        public List<Action> Actions = new List<Action>();
StephaneLenclud@210
    25
StephaneLenclud@231
    26
StephaneLenclud@231
    27
StephaneLenclud@210
    28
        protected Event()
StephaneLenclud@210
    29
        {
StephaneLenclud@231
    30
            Enabled = true;
StephaneLenclud@210
    31
        }
StephaneLenclud@210
    32
StephaneLenclud@231
    33
StephaneLenclud@231
    34
        /// <summary>
StephaneLenclud@231
    35
        /// Allows testing from generic edit dialog.
StephaneLenclud@231
    36
        /// </summary>
StephaneLenclud@231
    37
        public void Test()
StephaneLenclud@231
    38
        {
StephaneLenclud@231
    39
            Console.WriteLine("Event test");
StephaneLenclud@231
    40
            Trigger();
StephaneLenclud@231
    41
        }
StephaneLenclud@231
    42
StephaneLenclud@231
    43
StephaneLenclud@231
    44
        public void Trigger()
StephaneLenclud@210
    45
        {
StephaneLenclud@229
    46
            Console.WriteLine("Event triggered: " + Name);
StephaneLenclud@210
    47
            foreach (Action action in Actions)
StephaneLenclud@210
    48
            {
StephaneLenclud@210
    49
                action.Execute();
StephaneLenclud@210
    50
            }
StephaneLenclud@210
    51
        }
StephaneLenclud@231
    52
StephaneLenclud@237
    53
        //
StephaneLenclud@237
    54
        public override bool Equals(object obj)
StephaneLenclud@237
    55
        {
StephaneLenclud@237
    56
            //Default implementation assumes event are the same if types are the same
StephaneLenclud@237
    57
            bool res=  obj.GetType() == GetType();
StephaneLenclud@237
    58
            return res;
StephaneLenclud@237
    59
        }
StephaneLenclud@231
    60
    };
StephaneLenclud@210
    61
StephaneLenclud@210
    62
}