Actions can now have children.
5 using System.Collections.Generic;
6 using System.Diagnostics;
8 using System.Runtime.Serialization;
9 using System.Threading;
10 using System.Threading.Tasks;
12 namespace SharpLib.Ear
15 [AttributeObject(Id = "Action", Name = "Action", Description = "An empty action.")]
16 public class Action: Object
19 [AttributeObjectProperty
21 Id = "Action.Iterations",
23 Description = "Specifies the number of time this action should execute.",
29 public int Iterations { get; set; } = 1;
36 get { return Iterations > 0; }
40 /// Basic action just does nothing
42 /// <returns></returns>
43 protected virtual async Task DoExecute()
49 /// Allows testing from generic edit dialog.
53 Trace.WriteLine("Action test");
58 /// Execute our action N times.
60 /// <returns></returns>
61 public async Task Execute()
65 Trace.WriteLine("EAR: Action.Execute: WARNING: Action invalid, aborting execution: " + Brief());
71 Trace.WriteLine("EAR: Action.Execute: Action disabled: " + Brief());
75 for (int i = Iterations; i > 0; i--)
77 Trace.WriteLine($"EAR: Action.Execute: [{Iterations - i + 1}/{Iterations}] - {BriefBase()}");
79 //We first execute ourselves
83 foreach (Action a in Objects.OfType<Action>())
91 /// For inherited classes to override.
93 /// <returns></returns>
94 public virtual string BriefBase()
100 /// Dynamic object description.
102 /// <returns></returns>
103 public sealed override string Brief()
105 return Iterations > 1 ? $"{Iterations} x " + BriefBase():BriefBase();