# HG changeset patch # User StephaneLenclud # Date 1472657310 -7200 # Node ID 4a08e1b7ba64a64cd45e0a51ce09a45e1716ce26 # Parent 3ab73a2a72d8a6da84549446617294c2f08a3a69 EAR: Actions now support multiple iterations. diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 Server/Actions/ActionCecActiveSource.cs --- a/Server/Actions/ActionCecActiveSource.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/Server/Actions/ActionCecActiveSource.cs Wed Aug 31 17:28:30 2016 +0200 @@ -18,7 +18,7 @@ /// Build a user readable string to describe this action. /// /// - public override string Brief() + public override string BriefBase() { return "CEC Active Source to " + DeviceType.ToString(); } diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 Server/Actions/ActionCecDevicePowerOn.cs --- a/Server/Actions/ActionCecDevicePowerOn.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/Server/Actions/ActionCecDevicePowerOn.cs Wed Aug 31 17:28:30 2016 +0200 @@ -19,7 +19,7 @@ /// /// /// - public override string Brief() + public override string BriefBase() { return "CEC Power On " + DeviceName; } diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 Server/Actions/ActionCecDeviceStandby.cs --- a/Server/Actions/ActionCecDeviceStandby.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/Server/Actions/ActionCecDeviceStandby.cs Wed Aug 31 17:28:30 2016 +0200 @@ -19,7 +19,7 @@ /// Build a user readable string to describe this action. /// /// - public override string Brief() + public override string BriefBase() { return "CEC Standby " + DeviceName; } diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 Server/Actions/ActionCecUserControlPressed.cs --- a/Server/Actions/ActionCecUserControlPressed.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/Server/Actions/ActionCecUserControlPressed.cs Wed Aug 31 17:28:30 2016 +0200 @@ -44,7 +44,7 @@ /// /// /// - public override string Brief() + public override string BriefBase() { string brief = AttributeName + ": " + Code.ToString() + " to " + DeviceName; if (Wait) diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 Server/Actions/ActionCecUserControlReleased.cs --- a/Server/Actions/ActionCecUserControlReleased.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/Server/Actions/ActionCecUserControlReleased.cs Wed Aug 31 17:28:30 2016 +0200 @@ -36,7 +36,7 @@ /// /// /// - public override string Brief() + public override string BriefBase() { string brief = AttributeName + " to " + DeviceName; if (Wait) diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 Server/Actions/ActionDisplayMessage.cs --- a/Server/Actions/ActionDisplayMessage.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/Server/Actions/ActionDisplayMessage.cs Wed Aug 31 17:28:30 2016 +0200 @@ -50,7 +50,7 @@ /// /// /// - public override string Brief() + public override string BriefBase() { string brief = AttributeName + ": " + PrimaryText; if (!string.IsNullOrEmpty(SecondaryText)) diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 Server/Actions/ActionHarmonyCommand.cs --- a/Server/Actions/ActionHarmonyCommand.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/Server/Actions/ActionHarmonyCommand.cs Wed Aug 31 17:28:30 2016 +0200 @@ -34,7 +34,7 @@ /// /// /// - public override string Brief() + public override string BriefBase() { string brief="Harmony: "; diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 Server/FormMain.cs --- a/Server/FormMain.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/Server/FormMain.cs Wed Aug 31 17:28:30 2016 +0200 @@ -360,7 +360,8 @@ { TreeNode actionNode = actionsNodes.Nodes.Add(a.Brief()); actionNode.Tag = a; - actionNode.ForeColor = eventNode.ForeColor; + //Use color from event unless our action itself is disabled + actionNode.ForeColor = a.Enabled? eventNode.ForeColor: Color.DimGray; if (a == currentAction) { treeNodeToSelect = actionNode; diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 SharpLibEar/Action.cs --- a/SharpLibEar/Action.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/SharpLibEar/Action.cs Wed Aug 31 17:28:30 2016 +0200 @@ -13,6 +13,27 @@ [DataContract] public abstract class Action: Object { + [DataMember] + [AttributeObjectProperty + ( + Id = "Action.Iterations", + Name = "Iterations", + Description = "Specifies the number of time this action should execute.", + Minimum = "0", + Maximum = "10000", + Increment = "1" + ) + ] + public int Iterations { get; set; } = 1; + + /// + /// + /// + public bool Enabled + { + get { return Iterations > 0; } + } + protected abstract Task DoExecute(); /// @@ -24,18 +45,51 @@ Execute(); } + /// + /// Execute our action N times. + /// + /// public async Task Execute() { - Trace.WriteLine("Action executing: " + Brief()); if (!IsValid()) { - Trace.WriteLine($"WARNING: action invalid, aborting execution."); + Trace.WriteLine("EAR: Action.Execute: WARNING: Action invalid, aborting execution: " + Brief()); return; } - - await DoExecute(); + + if (!Enabled) + { + Trace.WriteLine("EAR: Action.Execute: Action disabled: " + Brief()); + return; + } + + for (int i = Iterations; i > 0; i--) + { + Trace.WriteLine($"EAR: Action.Execute: [{Iterations - i + 1}/{Iterations}] - {BriefBase()}"); + await DoExecute(); + } } + + public virtual string BriefBase() + { + return base.Brief(); + } + + /// + /// Dynamic object description. + /// + /// + public sealed override string Brief() + { + return Iterations > 1 ? $"{Iterations} x " + BriefBase():BriefBase(); + } + + + + + + } diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 SharpLibEar/ActionDelay.cs --- a/SharpLibEar/ActionDelay.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/SharpLibEar/ActionDelay.cs Wed Aug 31 17:28:30 2016 +0200 @@ -35,7 +35,7 @@ Milliseconds = aMillisecondsTimeout; } - public override string Brief() + public override string BriefBase() { return AttributeName + " for " + Milliseconds/1000.0 + " seconds"; } diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 SharpLibEar/ActionLaunchApp.cs --- a/SharpLibEar/ActionLaunchApp.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/SharpLibEar/ActionLaunchApp.cs Wed Aug 31 17:28:30 2016 +0200 @@ -44,7 +44,7 @@ ] public bool MultipleInstance { get; set; } = false; - public override string Brief() + public override string BriefBase() { return AttributeName + ": " + Path.GetFileName(File.FullPath); } diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 SharpLibEar/ActionOpticalDriveEject.cs --- a/SharpLibEar/ActionOpticalDriveEject.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/SharpLibEar/ActionOpticalDriveEject.cs Wed Aug 31 17:28:30 2016 +0200 @@ -36,7 +36,7 @@ } - public override string Brief() + public override string BriefBase() { return AttributeName + " " + Drive.CurrentItem ; } diff -r 3ab73a2a72d8 -r 4a08e1b7ba64 SharpLibEar/ActionSleep.cs --- a/SharpLibEar/ActionSleep.cs Wed Aug 31 16:24:33 2016 +0200 +++ b/SharpLibEar/ActionSleep.cs Wed Aug 31 17:28:30 2016 +0200 @@ -37,7 +37,7 @@ TimeoutInMilliseconds = aMillisecondsTimeout; } - public override string Brief() + public override string BriefBase() { return AttributeName + " for " + TimeoutInMilliseconds + " ms"; }