tbf/TBF/Rig/TestMethods/GrabImage/Component.cs

78 lines
2.1 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 FlowType MethodFlowType => FlowType.volume;
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; }
public bool CheckDeviceCaps(Test test, OutputPath devices, out string message)
{
return GrabImageSeq.CheckDeviceCaps(test, devices, out message);
}
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;
log.Warn(this.ToString());
}
///
public override void Initialize() { }
public IList<Event> Execute(Test test, int idummy, bool bdummy)
{
return (new GrabImageSeq()).Execute(test, cfg);
}
}
}