SharpLibEar/Action.cs
author StephaneLenclud
Wed, 31 Aug 2016 16:24:33 +0200
changeset 263 3ab73a2a72d8
parent 253 2dae7a163fff
child 264 4a08e1b7ba64
permissions -rw-r--r--
Adding Delay action to replace our Sleep action.
StephaneLenclud@210
     1
//
StephaneLenclud@210
     2
StephaneLenclud@210
     3
StephaneLenclud@210
     4
using System;
Stephane@212
     5
using System.Collections.Generic;
StephaneLenclud@253
     6
using System.Diagnostics;
StephaneLenclud@210
     7
using System.Runtime.Serialization;
StephaneLenclud@210
     8
using System.Threading;
StephaneLenclud@258
     9
using System.Threading.Tasks;
StephaneLenclud@210
    10
StephaneLenclud@210
    11
namespace SharpLib.Ear
StephaneLenclud@210
    12
{
StephaneLenclud@210
    13
    [DataContract]
StephaneLenclud@238
    14
    public abstract class Action: Object
StephaneLenclud@210
    15
    {
StephaneLenclud@258
    16
        protected abstract Task DoExecute();
StephaneLenclud@223
    17
StephaneLenclud@231
    18
        /// <summary>
StephaneLenclud@231
    19
        /// Allows testing from generic edit dialog.
StephaneLenclud@231
    20
        /// </summary>
StephaneLenclud@231
    21
        public void Test()
StephaneLenclud@231
    22
        {
StephaneLenclud@253
    23
            Trace.WriteLine("Action test");
StephaneLenclud@231
    24
            Execute();
StephaneLenclud@231
    25
        }
StephaneLenclud@231
    26
StephaneLenclud@258
    27
        public async Task Execute()
StephaneLenclud@223
    28
        {
StephaneLenclud@253
    29
            Trace.WriteLine("Action executing: " + Brief());
StephaneLenclud@239
    30
            if (!IsValid())
StephaneLenclud@239
    31
            {
StephaneLenclud@253
    32
                Trace.WriteLine($"WARNING: action invalid, aborting execution.");
StephaneLenclud@239
    33
                return;
StephaneLenclud@239
    34
            }
StephaneLenclud@239
    35
            
StephaneLenclud@258
    36
            await DoExecute();
StephaneLenclud@223
    37
        }
StephaneLenclud@210
    38
StephaneLenclud@210
    39
    }
StephaneLenclud@210
    40
StephaneLenclud@210
    41
StephaneLenclud@210
    42
}