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

85 lines
2.7 KiB
C#

///
/// Copyright (c) 2019 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using Common;
using Config.Entities;
namespace TBF.Rig.TestMethods.Q2CorrectionFromHistory
{
public class Component : ComponentBase, GenericDevices.ISimultTestMethod
{
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)
{
message = string.Format("{0}: CheckDeviceCaps() is not implemented yet", Name);
return false;
}
public bool SimultWithPrevious { get { return false; } }
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.UseWebService = tmpcfg.UseWebService;
cfg.BaseUrl = tmpcfg.BaseUrl;
cfg.RelativeUrl = tmpcfg.RelativeUrl;
cfg.UseLocalDB = tmpcfg.UseLocalDB;
cfg.ProcedureName = tmpcfg.ProcedureName;
cfg.ProcedureNameAlt1 = tmpcfg.ProcedureNameAlt1;
cfg.ProcedureNameAlt2 = tmpcfg.ProcedureNameAlt2;
cfg.UseDefaultValues = tmpcfg.UseDefaultValues;
}
}
};
}
#endregion Configuration Change Handling
readonly FromHistoryCfg cfg;
public Component() { }
///
public Component(Generic.IComponentCfg cfg)
: base(cfg)
{
this.cfg = cfg as FromHistoryCfg;
log.Warn(this.ToString());
}
///
public override void Initialize() { }
public IList<Event> Execute(Test test, int repetitionNr, bool isLastRepetition)
{
return (new FromHistorySeq()).Execute(test, repetitionNr, cfg);
}
}
}