diff --git a/TBF/Rig/TbfComponents.cs b/TBF/Rig/TbfComponents.cs index 39b3a0552..fde12b39f 100644 --- a/TBF/Rig/TbfComponents.cs +++ b/TBF/Rig/TbfComponents.cs @@ -100,6 +100,7 @@ namespace TBF.Rig Factories.Add(new TestMethods.LeakTest.Factory()); Factories.Add(new TestMethods.LiveStream.Factory()); Factories.Add(new TestMethods.ManualEntry.Factory()); + Factories.Add(new TestMethods.Message.Factory()); Factories.Add(new TestMethods.OuterLoop.Start.Factory()); Factories.Add(new TestMethods.OuterLoop.End.Factory()); Factories.Add(new TestMethods.PMaxTest.Factory()); diff --git a/TBF/Rig/TestMethods/Message/Factory.cs b/TBF/Rig/TestMethods/Message/Factory.cs new file mode 100644 index 000000000..302653941 --- /dev/null +++ b/TBF/Rig/TestMethods/Message/Factory.cs @@ -0,0 +1,24 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using System.Collections.Generic; +using TBF.Rig.Generic; + +namespace TBF.Rig.TestMethods.Message +{ + public class Factory : IComponentFactory + { + public string ClassName { get { return GetType().Namespace.Substring(8); } } + + public IComponent DummyComponent() { return new TestMethod(); } + + public IComponent GetComponent(IComponentCfg cfg, IList components) { return new TestMethod(cfg); } + + public IComponentCfg DefaultConfig() { return new TestMethodCfg(GetType().Namespace.Substring(20), this); } + + public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component) + { + return ComponentCfgBase.CreateFromDbEntity(TestMethodCfg.Serializer, component, this); + } + } +} diff --git a/TBF/Rig/TestMethods/Message/MessageSeq.cs b/TBF/Rig/TestMethods/Message/MessageSeq.cs new file mode 100644 index 000000000..d8db94aad --- /dev/null +++ b/TBF/Rig/TestMethods/Message/MessageSeq.cs @@ -0,0 +1,65 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using log4net; +using Common; +using Config.Entities; +using TBF.UiBridge; + +namespace TBF.Rig.TestMethods.Message +{ + public class MessageSeq : Sequences.SequenceBase + { + private static readonly ILog log = LogManager.GetLogger(typeof(MessageSeq)); + + /// + /// Message method sequence + /// + /// Test entity + /// + /// Event.Done . . . . . . . OK + /// Event.UiCmdStop . . . . Stopped by the user using the on-screen button STOP + /// Event.OpArgumentError . Target flow is out of range + /// Event.Error . . . . . . Unspecified error + /// + public IList Execute(Test test, int repetitionNr, bool isLastRepetition, DebugMode mode, TestMethodCfg cfg) + { + IList e = new List(); /// Events from currently running operations + checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state + + /// Start the test, initialize test results + Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, repetitionNr, inPath, benchPath, outPath, sensPath, heatMetersPath, 0)); + string testName = Common.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); + TestStartTime = DateTime.Now; + + /// + /// Show a dialog with OK button and an appropriate message + /// + Bridge.OnAdjustmentInProgress(this, new AdjustmentInProgressEventArgs(testName)); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Test)); + Bridge.OnActivity(this, test.Method); + State.Create(string.Format("{0}({1}) : Running Operations.MessageBoxOp", test.Method, test.Name)) + .AddOperation(checkUiOp) + .AddOperation(StateMachine.BenchWaitingOp) + .AddOperation(new Operations.MessageBoxOp(cfg.MessageStr.Replace("~", Environment.NewLine))) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, 1, Progress.Test)); + + if (e.Contains(Event.Error)) goto stopTest; + if (TestAndLogUiCmdStop(test, e)) goto stopTest; + } + while (!e.Contains(Event.OK)); + + return new List { Event.Done }; + + stopTest: + return new List { Event.UiCmdStop }; + } + } +} diff --git a/TBF/Rig/TestMethods/Message/TestMethod.cs b/TBF/Rig/TestMethods/Message/TestMethod.cs new file mode 100644 index 000000000..2553cea23 --- /dev/null +++ b/TBF/Rig/TestMethods/Message/TestMethod.cs @@ -0,0 +1,41 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using log4net; +using Common; +using Config.Entities; +using TBF.Rig; + +namespace TBF.Rig.TestMethods.Message +{ + public class TestMethod : ComponentBase, GenericDevices.ITestMethod + { + private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); + 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; } + + TestMethodCfg messageCfg; + + public TestMethod() { } + + public TestMethod(Generic.IComponentCfg cfg) + : base(cfg) + { + messageCfg = cfg as TestMethodCfg; + } + + public override void Initialize() + { + log.FatalFormat("{0} initialized: {1}", Name, this); + } + + public IList Execute(Test test, int repetNr, bool isLastRepetition) + { + return (new MessageSeq()).Execute(test, repetNr, isLastRepetition, DebugLevel, messageCfg); + } + } +} diff --git a/TBF/Rig/TestMethods/Message/TestMethodCfg.cs b/TBF/Rig/TestMethods/Message/TestMethodCfg.cs new file mode 100644 index 000000000..0c04412b0 --- /dev/null +++ b/TBF/Rig/TestMethods/Message/TestMethodCfg.cs @@ -0,0 +1,123 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Serialization; +using Common; +using Config.Entities; +using TBF.Resources; +using TBF.Rig.Generic; + +namespace TBF.Rig.TestMethods.Message +{ + public class TestMethodCfg : ComponentCfgBase, IChildComponentCfg, IParamsProvider + { + public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TestMethodCfg) })[0]; + public override XmlSerializer GetSerializer() { return Serializer; } + + public IComponentCfgCtrl GetControl(IList cmpntEntities) + { + return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); + } + + /// + /// Serialized parameters + /// + public string MessageStr { get; set; } /// 0 + + /// Private parameterless constructor invoked by all other (public) constructors + TestMethodCfg() { } + + public TestMethodCfg(string name, IComponentFactory factory) + : this() + { + this.Name = name; + this.Factory = factory; + InitializeAll(); + } + + public string ComponentName { get { return Name; } } + + public void InitializeAll() + { + MessageStr = "Trať je zavodnená"; + } + + string[] paramNames = new string[] + { + "Message", /// 0 + }; + public string ParamName(int i) { return paramNames[i]; } + public int ParamsCount() { return paramNames.Length; } + + public ICollection ParamValues(int i) + { + switch (i) + { + case 0: + default: + return null; + } + } + + + public string ToString(int i) + { + switch (i) + { + case 0: + return MessageStr; + default: + return string.Format("{0} message = {1}", Name, MessageStr); + } + } + + public CfgUpdateFlags UpdateParam(int i, string str) + { + switch (i) + { + case 0: + MessageStr = str; + return CfgUpdateFlags.RestartRqrd; + default: + return CfgUpdateFlags.None; + } + } + + public bool ValidateParam(int i, string str, out string message) + { + message = string.Empty; + + switch (i) + { + case 0: + return true; + default: + message = "Invalid index"; + return false; + } + + message = ParamName(i) + " is invalid"; + return false; + } + + void CopyContentTo(TestMethodCfg prms) + { + prms.MessageStr = MessageStr; + } + + public IParamsProvider Clone() + { + TestMethodCfg pars = new TestMethodCfg(); + CopyContentTo(pars); + return pars; + } + + public bool UpdateEmbeddedDbEntity() + { + return true; /// =OK, do nothing + } + } +} diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 11d3bec74..ccdec60bd 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -1653,6 +1653,10 @@ ManualEntryCfgCtrl.cs + + + +