tbf/TBF/Rig/TestMethods/GrabImage/Component.cs
2021-10-26 19:38:09 +02:00

75 lines
1.9 KiB
C#

///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using log4net;
using Common;
using Config.Entities;
using TBF.Rig;
namespace TBF.Rig.TestMethods.GrabImage
{
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)); }
public bool CanTest(MetersKind meters) { return true; }
public bool DoTransitions() { return false; }
readonly GrabImageCfg cfg;
#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)
{
GrabImageCfg tmpcfg = args.Cfg as GrabImageCfg;
if (tmpcfg != null && tmpcfg.Name.Equals(Name))
{
if (args.Command == CfgChangeCmd.CfgChange)
{
cfg.ImageFileName = tmpcfg.ImageFileName;
cfg.BlackAndWhite = tmpcfg.BlackAndWhite;
cfg.LowResolution = tmpcfg.LowResolution;
cfg.ImageRotation = tmpcfg.ImageRotation;
}
}
};
}
#endregion Configuration Change Handling
public Component() { }
public Component(Generic.IComponentCfg cfg)
: base(cfg)
{
this.cfg = cfg as GrabImageCfg;
}
public override void Initialize()
{
log.FatalFormat("{0} initialized: {1}", Name, this);
}
public IList<Event> Execute(Test test, int idummy, bool bdummy)
{
return (new GrabImageSeq()).Execute(test, cfg);
}
}
}