/// /// Copyright (c) 2019 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using log4net; using Common; using Config.Entities; using TBF.BenchControl; namespace TBF.BenchControl.TestMethods.ManualEntry { public class Component : ComponentBase, GenericDevices.ITestMethod { private static readonly ILog log = LogManager.GetLogger(typeof(Component)); public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); } readonly ManualEntryCfg myCfg; public bool CanTest(MetersKind meters) { return true; } public bool DoTransitions() { return false; } public Component() { } public Component(Generic.IComponentCfg cfg) : base(cfg) { myCfg = cfg as ManualEntryCfg; } public override void Initialize() { log.FatalFormat("{0} initialized: {1}", Name, this); } public IList Execute(Test test, int repetNr, bool isLastRepetition) { return (new ManualEntrySeq()).Execute(test, repetNr, isLastRepetition, myCfg, DebugLevel); } #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) { ManualEntryCfg newCfg = args.Cfg as ManualEntryCfg; if ((newCfg != null) && newCfg.Name.Equals(Name)) { if (args.Command == CfgChangeCmd.CfgChange) { myCfg.Culture = newCfg.Culture; myCfg.Prompt = newCfg.Prompt; myCfg.Items = newCfg.Items; } } }; } #endregion Configuration Change Handling } }