/// /// Copyright (c) 2021 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using System.Xml.Serialization; using Common; using Config.Entities; using TBF.Resources; using TBF.BenchControl.Generic; namespace TBF.BenchControl.TestMethods.S640Communication { /// /// Holds information identifying the test bench - serializable configuration. /// public class S640EndCfg : ComponentCfgBase, IComponentCfg, IParamsProvider, I640Cfg { public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(S640EndCfg) })[0]; public override XmlSerializer GetSerializer() { return Serializer; } public IComponentCfgCtrl GetControl(IList cmpntEntities) { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); } /// /// Serialized parameters /// public int OptoDataTimeout { get; set; } public string FileExchangePath { get; set; } public int FileExchangeTimeout { get; set; } public bool EnterSerialNumbers { get; set; } public bool SimultWithEvacuation { get; set; } /// Procedure parameters [XmlIgnore] public ProcParams ProcParams; public override IParamsProvider GetRuntimeProcParamsProvider() { return ProcParams; } public override IParamsProvider CreateProcParamsProvider() { return new ProcParams(true); } /// Private parameterless constructor invoked by all other (public) constructors S640EndCfg() { ProcParams = CreateProcParamsProvider() as ProcParams; } public S640EndCfg(string name, IComponentFactory factory) : this() { Name = name; Factory = factory; ParentName = string.Empty; InitializeAll(); } public string ComponentName { get { return Name; } } public void InitializeAll() { OptoDataTimeout = 180; FileExchangePath = "1"; FileExchangeTimeout = 60; EnterSerialNumbers = false; SimultWithEvacuation = true; } string[] paramNames = new string[] { "Awaiting optical data timeout [s] (0 = off)", "File exchange path", "File exchange timeout [s] (0 = off)", "Enter serial numbers", "Simultaneous with evacuation", }; public string ParamName(int i) { return paramNames[i]; } public int ParamsCount() { return paramNames.Length; } public ICollection ParamValues(int i) { switch (i) { case 3: case 4: return new List { Strings.yes, Strings.no }; default: return null; } } public string ToString(int i) { switch (i) { case 0: return OptoDataTimeout.ToString(); case 1: return FileExchangePath; case 2: return FileExchangeTimeout.ToString(); case 3: return EnterSerialNumbers ? Strings.yes : Strings.no; case 4: return SimultWithEvacuation ? Strings.yes : Strings.no; default: return string.Format("{0}: FileExchangePath = '{1}' FileExchangeTimeout = {2}s", Name, FileExchangePath, FileExchangeTimeout); } } public CfgUpdateFlags UpdateParam(int i, string strValue) { switch (i) { case 0: OptoDataTimeout = int.Parse(strValue); return CfgUpdateFlags.RestartRqrd; case 1: FileExchangePath = strValue; return CfgUpdateFlags.RestartRqrd; case 2: FileExchangeTimeout = int.Parse(strValue); return CfgUpdateFlags.RestartRqrd; case 3: EnterSerialNumbers = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd; case 4: SimultWithEvacuation = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd; default: return CfgUpdateFlags.None; } } public bool ValidateParam(int i, string strValue, out string message) { message = string.Empty; int idummy; switch (i) { case 0: case 2: if (int.TryParse(strValue, out idummy) && idummy >= 0 && idummy <= 300) return true; break; case 1: return true; case 3: case 4: if (ParamValues(i).Contains(strValue)) return true; break; default: message = "Invalid index"; return false; } message = ParamName(i) + " is invalid"; return false; } void CopyContentTo(S640EndCfg prms) { prms.OptoDataTimeout = this.OptoDataTimeout; prms.FileExchangePath = this.FileExchangePath; prms.FileExchangeTimeout = this.FileExchangeTimeout; prms.EnterSerialNumbers = this.EnterSerialNumbers; prms.SimultWithEvacuation = this.SimultWithEvacuation; } public IParamsProvider Clone() { S640EndCfg pars = new S640EndCfg(); CopyContentTo(pars); return pars; } public bool UpdateEmbeddedDbEntity() { return true; /// =OK, do nothing } } }