tbf/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlHead/ProcParams.cs

172 lines
4.4 KiB
C#

///
/// Copyright (c) 2015-2017 Sensus Metering Systems
///
using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.Resources;
namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
{
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0];
protected override XmlSerializer GetSerializer() { return Serializer; }
public MeterType MeterType;
public int FactorLimitLo; /// Lower limit for the calibration factor
public int FactorLimitHi; /// Upper limit for the calibration factor
#if ORACLE_DB
public int WMType_ID; /// Required for Oracle DB: ID_WZTyp in table VT_PRUEFPUNKT_SOLL_SD
public int WMType_Rev; /// Required for Oracle DB: Rev_WZTyp in table VT_PRUEFPUNKT_SOLL_SD
#endif
public override void InitializeAll()
{
MeterType = MeterType.AutoDetect;
FactorLimitLo = 1000;
FactorLimitHi = 8000;
#if ORACLE_DB
WMType_ID = 2; /// Value for iPerl DN15
WMType_Rev = 1; /// Value for iPerl DN15
#endif
}
string[] paramNames = new string[]
{
"iPerl type",
"Calib. factor Lo",
"Calib. factor Hi",
#if ORACLE_DB
"WMType ID",
"WMType Rev.",
#endif
};
public override string ParamName(int i) { return paramNames[i]; }
public override int ParamsCount() { return paramNames.Length; }
public override string ToString(int i)
{
switch (i)
{
case 0: return MeterType.ToString();
case 1: return FactorLimitLo.ToString();
case 2: return FactorLimitHi.ToString();
#if ORACLE_DB
case 3: return WMType_ID.ToString();
case 4: return WMType_Rev.ToString();
#endif
default: return string.Empty;
}
}
public void UpdateParam(int i, string strValue)
{
switch (i)
{
case 0:
for (MeterType mt = 0; mt < MeterType.Count; mt++)
{
if (mt.ToString().Equals(strValue)) { MeterType = mt; return; }
}
break;
case 1: FactorLimitLo = int.Parse(strValue); return;
case 2: FactorLimitHi = int.Parse(strValue); return;
#if ORACLE_DB
case 3: WMType_ID = int.Parse(strValue); return;
case 4: WMType_Rev = int.Parse(strValue); return;
#endif
default: return;
}
}
public bool ValidateParam(int i, string strValue, out string message)
{
message = string.Empty;
int iDummy;
switch (i)
{
case 0:
for (MeterType mt = 0; mt < MeterType.Count; mt++) if (mt.ToString().Equals(strValue)) return true;
break;
case 1:
case 2:
if (int.TryParse(strValue, out iDummy) && iDummy >= 1000 && iDummy <= 8000) return true;
break;
#if ORACLE_DB
case 3: /// WMType_ID
case 4: /// WMType_Rev
if (int.TryParse(strValue, out iDummy)) return true;
break;
#endif
default:
message = "Invalid index";
return false;
}
message = ParamName(i) + " is invalid";
return false;
}
void CopyContentTo(ProcParams prms)
{
prms.MeterType = this.MeterType;
prms.FactorLimitLo = this.FactorLimitLo;
prms.FactorLimitHi = this.FactorLimitHi;
#if ORACLE_DB
prms.WMType_ID = this.WMType_ID;
prms.WMType_Rev = this.WMType_Rev;
#endif
}
public IParamsProvider Clone()
{
ProcParams pars = new ProcParams();
CopyContentTo(pars);
return pars;
}
public override void UpdateProcedureParams(ComponentProcedure dbEntity)
{
if (dbEntity == null) return;
try
{
ProcParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as ProcParams;
procedureParamsEntity = dbEntity;
componentName = dbEntity.CmpntName;
procedure = dbEntity.Procedure;
if (tmp != null) tmp.CopyContentTo(this);
}
catch
{
}
}
public ProcParams()
{
}
public ProcParams(bool initialize)
{
if (initialize) InitializeAll();
}
public ProcParams(ComponentProcedure procParamsEntity, string componentName, Procedure procedure)
{
this.procedureParamsEntity = procParamsEntity;
this.componentName = componentName;
this.procedure = procedure;
}
}
}