Refactorization : BenchControl -> Rig
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2016 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using Config.Entities;
|
||||
using TBF.Rig.Generic;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.Rig.TestMethods.PMaxTest
|
||||
{
|
||||
public class PMaxTestParams : TestParamsBase, IParamsProvider, ITestParams
|
||||
{
|
||||
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(PMaxTestParams) })[0];
|
||||
public override XmlSerializer GetSerializer() { return Serializer; }
|
||||
|
||||
public float PressureLo; /// Presure range low limit in [bar]
|
||||
public float PressureHi; /// Presure range high limit in [bar]
|
||||
public int DurationPMax; /// Duration of the test in [s]
|
||||
|
||||
public override void InitializeAll()
|
||||
{
|
||||
PressureLo = 5.0f; /// [bar]
|
||||
PressureHi = 6.0f; /// [bar]
|
||||
DurationPMax = 60;
|
||||
}
|
||||
|
||||
|
||||
string[] paramNames = new string[]
|
||||
{
|
||||
Strings.Pressure_lo_bar,
|
||||
Strings.Pressure_hi_bar,
|
||||
Strings.Duration_s,
|
||||
};
|
||||
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 PressureLo.ToString(); /// [bar]
|
||||
case 1: return PressureHi.ToString(); /// [bar]
|
||||
case 2: return DurationPMax.ToString();
|
||||
default: return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0: PressureLo = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None;
|
||||
case 1: PressureHi = Utils.ParseSFloat(strValue); return CfgUpdateFlags.None;
|
||||
case 2: DurationPMax = int.Parse(strValue); return CfgUpdateFlags.None;
|
||||
default: return CfgUpdateFlags.None;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidateParam(int i, string strValue, out string message)
|
||||
{
|
||||
message = string.Empty;
|
||||
|
||||
float dummy;
|
||||
int iDummy;
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
if (Utils.TryParseUFloat(strValue, out dummy)) return true;
|
||||
break;
|
||||
case 2:
|
||||
if (int.TryParse(strValue, out iDummy)) return true;
|
||||
break;
|
||||
default:
|
||||
message = "Invalid index";
|
||||
return false;
|
||||
}
|
||||
|
||||
message = ParamName(i) + " is invalid";
|
||||
return false;
|
||||
}
|
||||
|
||||
void CopyContentTo(PMaxTestParams prms)
|
||||
{
|
||||
prms.PressureLo = this.PressureLo;
|
||||
prms.PressureHi = this.PressureHi;
|
||||
prms.DurationPMax = this.DurationPMax;
|
||||
}
|
||||
|
||||
public IParamsProvider Clone()
|
||||
{
|
||||
PMaxTestParams pars = new PMaxTestParams();
|
||||
CopyContentTo(pars);
|
||||
return pars;
|
||||
}
|
||||
|
||||
public override void UpdateFromDbEntity(ComponentTest dbEntity)
|
||||
{
|
||||
if (dbEntity == null) return;
|
||||
try
|
||||
{
|
||||
PMaxTestParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as PMaxTestParams;
|
||||
|
||||
testParamsEntity = dbEntity;
|
||||
componentName = dbEntity.CmpntName;
|
||||
test = dbEntity.Test;
|
||||
|
||||
if (tmp != null) tmp.CopyContentTo(this);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parameterless constructor initializes the parameters
|
||||
/// </summary>
|
||||
public PMaxTestParams()
|
||||
{
|
||||
}
|
||||
|
||||
public PMaxTestParams(bool initialize)
|
||||
{
|
||||
if (initialize) InitializeAll();
|
||||
}
|
||||
|
||||
public PMaxTestParams(ComponentTest testParamsEntity, string componentName, Test test)
|
||||
{
|
||||
this.testParamsEntity = testParamsEntity;
|
||||
this.componentName = componentName;
|
||||
this.test = test;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user