/// /// Copyright (c) 2015-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using Common; using Config.Entities; using log4net; using TBF.Resources; using TBF.Rig.GenericDevices; using TBF.Rig.Sequences; using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication; using TBF.UiBridge; namespace TBF.Rig.TestMethods.SmartMeterFlyingStartMassCollection { public class TestMethod : SmartComponentBase, ISimultTestMethod, ISequenceCondition, ISessionDataMngmnt { private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData"); public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); } public bool CanTest(MetersKind meters) { return meters == MetersKind.Single; } public bool DoTransitions() { return false; } public bool SimultWithPrevious { get { return _testMethodCfg.TestParams.SimultWithPrevious; } } public bool SimultWithNext { get { return _testMethodCfg.TestParams.SimultWithNext; } } #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) { TestMethodCfg tmpCfg = args.Cfg as TestMethodCfg; if (tmpCfg != null && tmpCfg.Name.Equals(Name)) { if (args.Command == CfgChangeCmd.CfgChange) { _testMethodCfg.CommTimeout = tmpCfg.CommTimeout; _testMethodCfg.DelayBetweenRetries = tmpCfg.DelayBetweenRetries; _testMethodCfg.MaxCommRetries = tmpCfg.MaxCommRetries; _testMethodCfg.IperlCheckErrorsToStop = tmpCfg.IperlCheckErrorsToStop; _testMethodCfg.UseWebService = tmpCfg.UseWebService; _testMethodCfg.BaseUrl = tmpCfg.BaseUrl; _testMethodCfg.RelativeUrl = tmpCfg.RelativeUrl; } } }; } #endregion Configuration Change Handling readonly TestMethodCfg _testMethodCfg; public bool[] IperlCommMilestone; IList sequenceConditionOps; public TestMethod() { CreateMilestonesAndConditions(); } public TestMethod(Generic.IComponentCfg cfg) : base(cfg) { _testMethodCfg = cfg as TestMethodCfg; CreateMilestonesAndConditions(); } void CreateMilestonesAndConditions() { // IperlCommMilestone = new bool[(int)ConditionID.Count]; // // sequenceConditionOps = new List(); // for (ConditionID id = ConditionID.A; id < ConditionID.Count; id++) // { // sequenceConditionOps.Add(new SequenceConditionOp(this, id)); // } } /// IDevice interface - only Initialize() is used public override void Initialize() { if (DebugLevel == DebugMode.Normal) { rfidDataLogger.Fatal("------------------------------------------------------------------------"); rfidDataLogger.FatalFormat("Test Bench Framework ver. {0}", Program.Version); log.FatalFormat("{0} initialized: {1}", Name, this); } else { log.FatalFormat("{0} simulated: {1}", Name, this); } } public IList Execute(Test test, int repetNr, bool isLastRepetition) { if (DebugLevel == DebugMode.Normal) { return (new SmartCommunicationSeq()).Execute(test, repetNr, this, _testMethodCfg.TestParams); } else { /// DebugLevel == DebugMode.Simulate (new SmartCommunicationSeq()).MakeSimulatedTrivial(test, repetNr, test.Part); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, 1, Progress.Completed)); Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, ProcessData.BatchRslts.GetTestRslt(Common.Utils.GetTestName(test.Name, 1, 1), 0))); return new List { Event.Done }; } } public int ConditionsCount { get { return 0; //return (int)ConditionID.Count; } } public string ConditionName(int i) { return String.Empty; //return (i >= 0 && i < (int)ConditionID.Count) ? ConditionOp(i).ToString() : string.Empty; } public IOperation ConditionOp(int i) { return null; //return (i >= 0 && i < (int)ConditionID.Count) ? sequenceConditionOps[i] : null; } public void StartSession() { /// Clear milestones if (IperlCommMilestone != null) { for (int i = 0; i < IperlCommMilestone.Length; i++) { IperlCommMilestone[i] = false; } } } public void SaveMark(object o) { /// No marks } public void EndSession() { /// Nothing at the end of session } public bool CheckDeviceCaps(Test test, OutputPath devices, out string message) { if (!(StateMachine.ControlBoardMain is ControlBoard.Uni.UniCB)) { /// Control board does not support this method message = string.Format("{0}: {1}", test.Name, Strings.Test_bench_does_not_suport_selected_test_method); return false; } if (!(devices.FlowMeter is TBF.Rig.GenericDevices.IFlowMeter)) { /// Flow meter is missing message = string.Format("{0}: {1}", test.Name, Strings.Missing_a_flow_meter); return false; } if (!(devices.RegValve is GenericDevices.IRegValve)) { /// Regulation valve is missing message = string.Format("{0}: {1}", test.Name, Strings.Missing_a_regulation_valve); return false; } message = string.Empty; return true; } public override void MeterCommMilestone(int iItem, bool bValue) { throw new NotImplementedException(); } public override bool IsMeterCommMilestone(int iItem) { throw new NotImplementedException(); } } }