/// /// Copyright (c) 2020 Sensus Slovensko a.s. /// using System; using log4net; namespace TBF.BenchControl.Output.EventTriggers.Iperl { public class Trigger : ComponentBase, IOperation, GenericDevices.IEventTrigger { private static readonly ILog log = LogManager.GetLogger(typeof(Trigger)); public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(1)); } readonly TriggerCfg triggerCfg; Results.Entities.Batch batch; public Trigger() {} public Trigger(Generic.IComponentCfg cfg) : base(cfg) { triggerCfg = cfg as TriggerCfg; ApplyConfig(); log.Debug(this.ToString()); } void ApplyConfig() { } #region Configuration Change Handling public static void OnCfgChange(object sender, CfgChangeArgs args) { if (CfgChangeHandler == null) return; try { CfgChangeHandler(sender, args); } catch (Exception e) { log.Error("CfgChangeHandler(...) failed", e); } } public static event EventHandler CfgChangeHandler; public override void StartChangeHandler() { CfgChangeHandler += delegate(object sender, CfgChangeArgs args) { TriggerCfg newCfg = args.Cfg as TriggerCfg; if (newCfg != null && newCfg.Name.Equals(Name)) { if (args.Command == CfgChangeCmd.CfgChange) { triggerCfg.EventSource = newCfg.EventSource; triggerCfg.Culture = newCfg.Culture; triggerCfg.EliminateSpaces = newCfg.EliminateSpaces; triggerCfg.PrintCaption = newCfg.PrintCaption; ApplyConfig(); } } }; } #endregion Configuration Change Handling /// /// Writes the test cycle results into a file /// Events: /// Event.ResultsWritten /// Event.Busy /// /// Results to write into a file /// Reference to the operation public IOperation ProcessResultsOp(Results.Entities.Batch batch) { this.batch = batch; return this; } /// Start this operation public void Start() { Process(batch); } /// Run this operation /// Event.ResultsProcessed public Event Run() { return Event.ResultsProcessed; } /// Stop this operation public void Stop() { } void Process(Results.Entities.Batch batch) { return; } } }