SharpLibEar/Action.cs
changeset 265 82e87f4956ea
parent 264 4a08e1b7ba64
child 266 b11d7ebbdc7f
     1.1 --- a/SharpLibEar/Action.cs	Wed Aug 31 17:28:30 2016 +0200
     1.2 +++ b/SharpLibEar/Action.cs	Wed Aug 31 20:20:32 2016 +0200
     1.3 @@ -4,6 +4,7 @@
     1.4  using System;
     1.5  using System.Collections.Generic;
     1.6  using System.Diagnostics;
     1.7 +using System.Linq;
     1.8  using System.Runtime.Serialization;
     1.9  using System.Threading;
    1.10  using System.Threading.Tasks;
    1.11 @@ -11,7 +12,8 @@
    1.12  namespace SharpLib.Ear
    1.13  {
    1.14      [DataContract]
    1.15 -    public abstract class Action: Object
    1.16 +    [AttributeObject(Id = "Action", Name = "Action", Description = "An empty action.")]
    1.17 +    public class Action: Object
    1.18      {
    1.19          [DataMember]
    1.20          [AttributeObjectProperty
    1.21 @@ -34,7 +36,14 @@
    1.22              get { return Iterations > 0; }
    1.23          }
    1.24  
    1.25 -        protected abstract Task DoExecute();
    1.26 +        /// <summary>
    1.27 +        /// Basic action just does nothing
    1.28 +        /// </summary>
    1.29 +        /// <returns></returns>
    1.30 +        protected virtual async Task DoExecute()
    1.31 +        {
    1.32 +            
    1.33 +        }
    1.34  
    1.35          /// <summary>
    1.36          /// Allows testing from generic edit dialog.
    1.37 @@ -66,14 +75,25 @@
    1.38              for (int i = Iterations; i > 0; i--)
    1.39              {
    1.40                  Trace.WriteLine($"EAR: Action.Execute: [{Iterations - i + 1}/{Iterations}] - {BriefBase()}");
    1.41 +                //For each iteration
    1.42 +                //We first execute ourselves
    1.43                  await DoExecute();
    1.44 +
    1.45 +                //Then our children
    1.46 +                foreach (Action a in Objects.OfType<Action>())
    1.47 +                {
    1.48 +                    await a.Execute();
    1.49 +                }
    1.50              }            
    1.51          }
    1.52  
    1.53 -
    1.54 +        /// <summary>
    1.55 +        /// For inherited classes to override.
    1.56 +        /// </summary>
    1.57 +        /// <returns></returns>
    1.58          public virtual string BriefBase()
    1.59          {
    1.60 -            return base.Brief();
    1.61 +            return Name;
    1.62          }
    1.63  
    1.64          /// <summary>