167 lines
5.5 KiB
C#
167 lines
5.5 KiB
C#
///
|
|
/// 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
|
|
{
|
|
/// <summary>
|
|
/// Holds information identifying the test bench - serializable configuration.
|
|
/// </summary>
|
|
public class S640StartCfg : ComponentCfgBase, IComponentCfg, IParamsProvider, I640Cfg
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(S640StartCfg) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> 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 SimultWithPurging { get; set; }
|
|
|
|
/// <summary> Procedure parameters </summary>
|
|
[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
|
|
S640StartCfg()
|
|
{
|
|
ProcParams = CreateProcParamsProvider() as ProcParams;
|
|
}
|
|
|
|
public S640StartCfg(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 = true;
|
|
SimultWithPurging = 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 purging",
|
|
};
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
public ICollection<string> ParamValues(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 3:
|
|
case 4:
|
|
return new List<string> { 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 SimultWithPurging ? 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: SimultWithPurging = (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(S640StartCfg prms)
|
|
{
|
|
prms.OptoDataTimeout = this.OptoDataTimeout;
|
|
prms.FileExchangePath = this.FileExchangePath;
|
|
prms.FileExchangeTimeout = this.FileExchangeTimeout;
|
|
prms.EnterSerialNumbers = this.EnterSerialNumbers;
|
|
prms.SimultWithPurging = this.SimultWithPurging;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
S640StartCfg pars = new S640StartCfg();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true; /// =OK, do nothing
|
|
}
|
|
}
|
|
}
|