EAR: Actions now support multiple iterations.
authorStephaneLenclud
Wed, 31 Aug 2016 17:28:30 +0200
changeset 2644a08e1b7ba64
parent 263 3ab73a2a72d8
child 265 82e87f4956ea
EAR: Actions now support multiple iterations.
Server/Actions/ActionCecActiveSource.cs
Server/Actions/ActionCecDevicePowerOn.cs
Server/Actions/ActionCecDeviceStandby.cs
Server/Actions/ActionCecUserControlPressed.cs
Server/Actions/ActionCecUserControlReleased.cs
Server/Actions/ActionDisplayMessage.cs
Server/Actions/ActionHarmonyCommand.cs
Server/FormMain.cs
SharpLibEar/Action.cs
SharpLibEar/ActionDelay.cs
SharpLibEar/ActionLaunchApp.cs
SharpLibEar/ActionOpticalDriveEject.cs
SharpLibEar/ActionSleep.cs
     1.1 --- a/Server/Actions/ActionCecActiveSource.cs	Wed Aug 31 16:24:33 2016 +0200
     1.2 +++ b/Server/Actions/ActionCecActiveSource.cs	Wed Aug 31 17:28:30 2016 +0200
     1.3 @@ -18,7 +18,7 @@
     1.4          /// Build a user readable string to describe this action.
     1.5          /// </summary>
     1.6          /// <returns></returns>
     1.7 -        public override string Brief()
     1.8 +        public override string BriefBase()
     1.9          {
    1.10              return "CEC Active Source to " + DeviceType.ToString();
    1.11          }
     2.1 --- a/Server/Actions/ActionCecDevicePowerOn.cs	Wed Aug 31 16:24:33 2016 +0200
     2.2 +++ b/Server/Actions/ActionCecDevicePowerOn.cs	Wed Aug 31 17:28:30 2016 +0200
     2.3 @@ -19,7 +19,7 @@
     2.4          /// 
     2.5          /// </summary>
     2.6          /// <returns></returns>
     2.7 -        public override string Brief()
     2.8 +        public override string BriefBase()
     2.9          {
    2.10              return "CEC Power On " + DeviceName;
    2.11          }
     3.1 --- a/Server/Actions/ActionCecDeviceStandby.cs	Wed Aug 31 16:24:33 2016 +0200
     3.2 +++ b/Server/Actions/ActionCecDeviceStandby.cs	Wed Aug 31 17:28:30 2016 +0200
     3.3 @@ -19,7 +19,7 @@
     3.4          /// Build a user readable string to describe this action.
     3.5          /// </summary>
     3.6          /// <returns></returns>
     3.7 -        public override string Brief()
     3.8 +        public override string BriefBase()
     3.9          {
    3.10              return "CEC Standby " + DeviceName;
    3.11          }
     4.1 --- a/Server/Actions/ActionCecUserControlPressed.cs	Wed Aug 31 16:24:33 2016 +0200
     4.2 +++ b/Server/Actions/ActionCecUserControlPressed.cs	Wed Aug 31 17:28:30 2016 +0200
     4.3 @@ -44,7 +44,7 @@
     4.4          /// 
     4.5          /// </summary>
     4.6          /// <returns></returns>
     4.7 -        public override string Brief()
     4.8 +        public override string BriefBase()
     4.9          {
    4.10              string brief = AttributeName + ": " + Code.ToString() + " to " + DeviceName;
    4.11              if (Wait)
     5.1 --- a/Server/Actions/ActionCecUserControlReleased.cs	Wed Aug 31 16:24:33 2016 +0200
     5.2 +++ b/Server/Actions/ActionCecUserControlReleased.cs	Wed Aug 31 17:28:30 2016 +0200
     5.3 @@ -36,7 +36,7 @@
     5.4          /// 
     5.5          /// </summary>
     5.6          /// <returns></returns>
     5.7 -        public override string Brief()
     5.8 +        public override string BriefBase()
     5.9          {
    5.10              string brief = AttributeName + " to " + DeviceName;
    5.11              if (Wait)
     6.1 --- a/Server/Actions/ActionDisplayMessage.cs	Wed Aug 31 16:24:33 2016 +0200
     6.2 +++ b/Server/Actions/ActionDisplayMessage.cs	Wed Aug 31 17:28:30 2016 +0200
     6.3 @@ -50,7 +50,7 @@
     6.4          /// 
     6.5          /// </summary>
     6.6          /// <returns></returns>
     6.7 -        public override string Brief()
     6.8 +        public override string BriefBase()
     6.9          {
    6.10              string brief = AttributeName + ": " + PrimaryText;
    6.11              if (!string.IsNullOrEmpty(SecondaryText))
     7.1 --- a/Server/Actions/ActionHarmonyCommand.cs	Wed Aug 31 16:24:33 2016 +0200
     7.2 +++ b/Server/Actions/ActionHarmonyCommand.cs	Wed Aug 31 17:28:30 2016 +0200
     7.3 @@ -34,7 +34,7 @@
     7.4          /// 
     7.5          /// </summary>
     7.6          /// <returns></returns>
     7.7 -        public override string Brief()
     7.8 +        public override string BriefBase()
     7.9          {
    7.10              string brief="Harmony: ";
    7.11  
     8.1 --- a/Server/FormMain.cs	Wed Aug 31 16:24:33 2016 +0200
     8.2 +++ b/Server/FormMain.cs	Wed Aug 31 17:28:30 2016 +0200
     8.3 @@ -360,7 +360,8 @@
     8.4                  {
     8.5                      TreeNode actionNode = actionsNodes.Nodes.Add(a.Brief());
     8.6                      actionNode.Tag = a;
     8.7 -                    actionNode.ForeColor = eventNode.ForeColor;
     8.8 +                    //Use color from event unless our action itself is disabled
     8.9 +                    actionNode.ForeColor = a.Enabled? eventNode.ForeColor: Color.DimGray;
    8.10                      if (a == currentAction)
    8.11                      {
    8.12                          treeNodeToSelect = actionNode;
     9.1 --- a/SharpLibEar/Action.cs	Wed Aug 31 16:24:33 2016 +0200
     9.2 +++ b/SharpLibEar/Action.cs	Wed Aug 31 17:28:30 2016 +0200
     9.3 @@ -13,6 +13,27 @@
     9.4      [DataContract]
     9.5      public abstract class Action: Object
     9.6      {
     9.7 +        [DataMember]
     9.8 +        [AttributeObjectProperty
     9.9 +            (
    9.10 +            Id = "Action.Iterations",
    9.11 +            Name = "Iterations",
    9.12 +            Description = "Specifies the number of time this action should execute.",
    9.13 +            Minimum = "0",
    9.14 +            Maximum = "10000",
    9.15 +            Increment = "1"
    9.16 +            )
    9.17 +        ]
    9.18 +        public int Iterations { get; set; } = 1;
    9.19 +
    9.20 +        /// <summary>
    9.21 +        /// 
    9.22 +        /// </summary>
    9.23 +        public bool Enabled
    9.24 +        {
    9.25 +            get { return Iterations > 0; }
    9.26 +        }
    9.27 +
    9.28          protected abstract Task DoExecute();
    9.29  
    9.30          /// <summary>
    9.31 @@ -24,18 +45,51 @@
    9.32              Execute();
    9.33          }
    9.34  
    9.35 +        /// <summary>
    9.36 +        /// Execute our action N times.
    9.37 +        /// </summary>
    9.38 +        /// <returns></returns>
    9.39          public async Task Execute()
    9.40          {
    9.41 -            Trace.WriteLine("Action executing: " + Brief());
    9.42              if (!IsValid())
    9.43              {
    9.44 -                Trace.WriteLine($"WARNING: action invalid, aborting execution.");
    9.45 +                Trace.WriteLine("EAR: Action.Execute: WARNING: Action invalid, aborting execution: " + Brief());
    9.46                  return;
    9.47              }
    9.48 -            
    9.49 -            await DoExecute();
    9.50 +
    9.51 +            if (!Enabled)
    9.52 +            {
    9.53 +                Trace.WriteLine("EAR: Action.Execute: Action disabled: " + Brief());
    9.54 +                return;
    9.55 +            }
    9.56 +
    9.57 +            for (int i = Iterations; i > 0; i--)
    9.58 +            {
    9.59 +                Trace.WriteLine($"EAR: Action.Execute: [{Iterations - i + 1}/{Iterations}] - {BriefBase()}");
    9.60 +                await DoExecute();
    9.61 +            }            
    9.62          }
    9.63  
    9.64 +
    9.65 +        public virtual string BriefBase()
    9.66 +        {
    9.67 +            return base.Brief();
    9.68 +        }
    9.69 +
    9.70 +        /// <summary>
    9.71 +        /// Dynamic object description.
    9.72 +        /// </summary>
    9.73 +        /// <returns></returns>
    9.74 +        public sealed override string Brief()
    9.75 +        {
    9.76 +            return Iterations > 1 ? $"{Iterations} x " + BriefBase():BriefBase();
    9.77 +        }
    9.78 +
    9.79 +
    9.80 +
    9.81 +
    9.82 +
    9.83 +
    9.84      }
    9.85  
    9.86  
    10.1 --- a/SharpLibEar/ActionDelay.cs	Wed Aug 31 16:24:33 2016 +0200
    10.2 +++ b/SharpLibEar/ActionDelay.cs	Wed Aug 31 17:28:30 2016 +0200
    10.3 @@ -35,7 +35,7 @@
    10.4              Milliseconds = aMillisecondsTimeout;
    10.5          }
    10.6  
    10.7 -        public override string Brief()
    10.8 +        public override string BriefBase()
    10.9          {
   10.10              return AttributeName + " for " + Milliseconds/1000.0 + " seconds";
   10.11          }
    11.1 --- a/SharpLibEar/ActionLaunchApp.cs	Wed Aug 31 16:24:33 2016 +0200
    11.2 +++ b/SharpLibEar/ActionLaunchApp.cs	Wed Aug 31 17:28:30 2016 +0200
    11.3 @@ -44,7 +44,7 @@
    11.4          ]
    11.5          public bool MultipleInstance { get; set; } = false;
    11.6  
    11.7 -        public override string Brief()
    11.8 +        public override string BriefBase()
    11.9          {
   11.10              return AttributeName + ": " + Path.GetFileName(File.FullPath);
   11.11          }
    12.1 --- a/SharpLibEar/ActionOpticalDriveEject.cs	Wed Aug 31 16:24:33 2016 +0200
    12.2 +++ b/SharpLibEar/ActionOpticalDriveEject.cs	Wed Aug 31 17:28:30 2016 +0200
    12.3 @@ -36,7 +36,7 @@
    12.4          }
    12.5  
    12.6  
    12.7 -        public override string Brief()
    12.8 +        public override string BriefBase()
    12.9          {
   12.10              return AttributeName + " " + Drive.CurrentItem ;
   12.11          }
    13.1 --- a/SharpLibEar/ActionSleep.cs	Wed Aug 31 16:24:33 2016 +0200
    13.2 +++ b/SharpLibEar/ActionSleep.cs	Wed Aug 31 17:28:30 2016 +0200
    13.3 @@ -37,7 +37,7 @@
    13.4              TimeoutInMilliseconds = aMillisecondsTimeout;
    13.5          }
    13.6  
    13.7 -        public override string Brief()
    13.8 +        public override string BriefBase()
    13.9          {
   13.10              return AttributeName + " for " + TimeoutInMilliseconds + " ms";
   13.11          }