110 lines
2.8 KiB
C#
110 lines
2.8 KiB
C#
///
|
|
/// 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;
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
ApplyConfig();
|
|
log.FatalFormat("{0} initialized: {1}", Name, this);
|
|
}
|
|
|
|
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<CfgChangeArgs> 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
|
|
|
|
|
|
/// <summary>
|
|
/// Writes the test cycle results into a file
|
|
/// Events:
|
|
/// Event.ResultsWritten
|
|
/// Event.Busy
|
|
/// </summary>
|
|
/// <param name="batch">Results to write into a file</param>
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ProcessResultsOp(Results.Entities.Batch batch)
|
|
{
|
|
this.batch = batch;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
Process(batch);
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
/// <returns>Event.ResultsProcessed</returns>
|
|
public Event Run()
|
|
{
|
|
return Event.ResultsProcessed;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
}
|
|
|
|
|
|
void Process(Results.Entities.Batch batch)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|