tbf/TBF/BenchControl/TestMethods/Q2CorrectionFromHistory/Component.cs

75 lines
2.2 KiB
C#

///
/// Copyright (c) 2019 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using Config.Entities;
namespace TBF.BenchControl.TestMethods.Q2CorrectionFromHistory
{
public class Component : ComponentBase, GenericDevices.ISimultTestMethod, GenericDevices.ITestMethod
{
private static readonly ILog log = LogManager.GetLogger(typeof(Component));
public override string ToString() { return string.Format("TestMethods.GrabImage({0})", Cfg.ToString(1)); }
public bool CanTest(MetersKind meters) { return true; }
public bool DoTransitions() { return false; }
readonly FromHistoryCfg cfg;
public bool SimultWithPrevious { get { return true; } }
public bool SimultWithNext { get { return false; } }
#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)
{
FromHistoryCfg tmpcfg = args.Cfg as FromHistoryCfg;
if (tmpcfg != null && tmpcfg.Name.Equals(Name))
{
if (args.Command == CfgChangeCmd.CfgChange)
{
cfg.UseLocalDB = tmpcfg.UseLocalDB;
cfg.ProcedureName = tmpcfg.ProcedureName;
cfg.ProcedureNameAlt1 = tmpcfg.ProcedureNameAlt1;
cfg.ProcedureNameAlt2 = tmpcfg.ProcedureNameAlt2;
cfg.UseWebService = tmpcfg.UseWebService;
}
}
};
}
#endregion Configuration Change Handling
public Component()
{
}
public Component(Generic.IComponentCfg cfg)
: base(cfg)
{
this.cfg = cfg as FromHistoryCfg;
StartChangeHandler();
log.Debug(this.ToString());
}
public IList<Event> Execute(Test test, int repetitionNr, bool isLastRepetition)
{
return (new FromHistorySeq()).Execute(test, repetitionNr, isLastRepetition, cfg);
}
}
}