Server/Slions/Ear/Event.cs
author StephaneLenclud
Fri, 22 Jul 2016 18:19:49 +0200
changeset 209 fef4ca058087
permissions -rw-r--r--
Prototype for event and action framework.
StephaneLenclud@209
     1
//
StephaneLenclud@209
     2
StephaneLenclud@209
     3
StephaneLenclud@209
     4
using System;
StephaneLenclud@209
     5
using System.Collections.Generic;
StephaneLenclud@209
     6
using System.Runtime.Serialization;
StephaneLenclud@209
     7
StephaneLenclud@209
     8
namespace Slions.Ear
StephaneLenclud@209
     9
{
StephaneLenclud@209
    10
    [DataContract]
StephaneLenclud@209
    11
    abstract class MEvent
StephaneLenclud@209
    12
    {
StephaneLenclud@209
    13
        [DataMember]
StephaneLenclud@209
    14
        public string Name { get; protected set; }
StephaneLenclud@209
    15
StephaneLenclud@209
    16
        [DataMember]
StephaneLenclud@209
    17
        public string Description { get; protected set; }
StephaneLenclud@209
    18
StephaneLenclud@209
    19
        public abstract void Trigger();
StephaneLenclud@209
    20
    };
StephaneLenclud@209
    21
StephaneLenclud@209
    22
    [DataContract]
StephaneLenclud@209
    23
    abstract class Event : MEvent
StephaneLenclud@209
    24
    {
StephaneLenclud@209
    25
        List<Action> iActions;
StephaneLenclud@209
    26
StephaneLenclud@209
    27
        protected Event()
StephaneLenclud@209
    28
        {
StephaneLenclud@209
    29
            iActions = new List<Action>();
StephaneLenclud@209
    30
        }
StephaneLenclud@209
    31
StephaneLenclud@209
    32
        public override void Trigger()
StephaneLenclud@209
    33
        {
StephaneLenclud@209
    34
            Console.WriteLine("Event '" + Name + "' triggered.");
StephaneLenclud@209
    35
            foreach (Action action in iActions)
StephaneLenclud@209
    36
            {
StephaneLenclud@209
    37
                action.Execute();
StephaneLenclud@209
    38
            }
StephaneLenclud@209
    39
        }
StephaneLenclud@209
    40
    }
StephaneLenclud@209
    41
StephaneLenclud@209
    42
}