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

236 lines
7.3 KiB
C#

///
/// Copyright (c) 2015-2018 Sensus Slovensko a.s.
///
using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.BenchControl.Output;
using TBF.Resources;
using System.Collections.Generic;
namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
{
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0];
public override XmlSerializer GetSerializer() { return Serializer; }
public MeterType MeterType;
public float CalibTarget; /// Target error after calibration in [%]
public int FactorLimitLo; /// Lower limit for the calibration factor
public int FactorLimitHi; /// Upper limit for the calibration factor
public FlowDir FlowDir; /// Initial iPerl flow direction (R_L or L_R)
public LogType LogType;
#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;
CalibTarget = 0;
FactorLimitLo = 1000;
FactorLimitHi = 8000;
FlowDir = FlowDir.R_L;
LogType = LogType.Just_Q1Q2Q3;
#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. target [%]",
"Calib. factor Lo",
"Calib. factor Hi",
"Flow direction",
"Log type",
#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 IList<string> ParamValues(int i)
{
if (i == 0)
{
IList<string> retVal = new List<string>();
for (MeterType mt = 0; mt < MeterType.Count; mt++) retVal.Add(mt.ToString());
return retVal;
}
else if (i == 4)
{
IList<string> retVal = new List<string>();
for (FlowDir fd = 0; fd < FlowDir.Count; fd++) retVal.Add(fd.ToString());
return retVal;
}
else if (i == 5)
{
IList<string> retVal = new List<string>();
for (LogType lt = 0; lt < LogType.Count; lt++) retVal.Add(lt.ToString());
return retVal;
}
return null;
}
public override string ToString(int i)
{
switch (i)
{
case 0: return MeterType.ToString();
case 1: return CalibTarget.ToString();
case 2: return FactorLimitLo.ToString();
case 3: return FactorLimitHi.ToString();
case 4: return FlowDir.ToString();
case 5: return LogType.ToString();
#if ORACLE_DB
case 6: return WMType_ID.ToString();
case 7: return WMType_Rev.ToString();
#endif
default: return string.Empty;
}
}
public CfgUpdateFlags 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 CfgUpdateFlags.None; }
}
break;
case 1: CalibTarget = Utils.ParseSFloat(strValue); return CfgUpdateFlags.None;
case 2: FactorLimitLo = int.Parse(strValue); return CfgUpdateFlags.None;
case 3: FactorLimitHi = int.Parse(strValue); return CfgUpdateFlags.None;
case 4:
for (FlowDir fd = 0; fd < FlowDir.Count; fd++)
{
if (fd.ToString().Equals(strValue)) { FlowDir = fd; return CfgUpdateFlags.None; }
}
break;
case 5:
for (LogType lt = 0; lt < LogType.Count; lt++)
{
if (lt.ToString().Equals(strValue)) { LogType = lt; return CfgUpdateFlags.None; }
}
break;
#if ORACLE_DB
case 6: WMType_ID = int.Parse(strValue); return CfgUpdateFlags.None;
case 7: WMType_Rev = int.Parse(strValue); return CfgUpdateFlags.None;
#endif
default: return CfgUpdateFlags.None;
}
return CfgUpdateFlags.None;
}
public bool ValidateParam(int i, string strValue, out string message)
{
message = string.Empty;
int iDummy;
float fDummy;
switch (i)
{
case 0:
for (MeterType mt = 0; mt < MeterType.Count; mt++) if (mt.ToString().Equals(strValue)) return true;
break;
case 1:
if (Utils.TryParseSFloat(strValue, out fDummy) && fDummy >= -10.0f && fDummy <= 10.0f) return true;
break;
case 2:
case 3:
if (int.TryParse(strValue, out iDummy) && iDummy >= 1000 && iDummy <= 8000) return true;
break;
case 4:
for (FlowDir fd = 0; fd < FlowDir.Count; fd++) if (fd.ToString().Equals(strValue)) return true;
break;
case 5:
for (LogType lt = 0; lt < LogType.Count; lt++) if (lt.ToString().Equals(strValue)) return true;
break;
#if ORACLE_DB
case 6: /// WMType_ID
case 7: /// 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.CalibTarget = this.CalibTarget;
prms.FactorLimitLo = this.FactorLimitLo;
prms.FactorLimitHi = this.FactorLimitHi;
prms.FlowDir = this.FlowDir;
prms.LogType = this.LogType;
#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 UpdateFromDbEntity(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;
}
}
}