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