tbf/TBF/BenchControl/TestMethods/LeakTest/LeakTestParams.cs

170 lines
5.2 KiB
C#

///
/// Copyright (c) 2013-2019 Sensus Slovensko a.s.
///
using System;
using System.IO;
using System.Xml.Serialization;
using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.Resources;
namespace TBF.BenchControl.TestMethods.LeakTest
{
public class LeakTestParams : TestParamsBase, IParamsProvider, ITestParams
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(LeakTestParams) })[0];
public override XmlSerializer GetSerializer() { return Serializer; }
public float PressureLo; /// [bar] Presure range low limit
public float PressureHi; /// [bar] Presure range high limit
public int DurationPMax; /// [s] Duration of PMax test
public int DurationLeak; /// [s] Duration of Leak test
public bool IsPumpRunning; /// true = pump is running during complete test
public float MaxPressureDrop; /// [bar] Max. drop of pressure at the end of test, 0 disables pressure drop test
public float MaxMassIncrease; /// [kg] Max. increase of the mass on the scale at the end of test, 0 disables mass increase test
public override void InitializeAll()
{
PressureLo = 5.0f; /// [bar]
PressureHi = 6.0f; /// [bar]
DurationPMax = 10; /// [s]
DurationLeak = 60; /// [s]
IsPumpRunning = false;
MaxPressureDrop = 0; /// [bar]
MaxMassIncrease = 0; /// [kg]
}
string[] paramNames = new string[]
{
Strings.Pressure_lo_bar,
Strings.Pressure_hi_bar,
Strings.Duration_PMax_s,
Strings.Duration_Leak_s,
Strings.Pump_is_running,
Strings.Max_pressure_drop_bar,
Strings.Max_mass_increase_kg,
};
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();
case 1: return PressureHi.ToString();
case 2: return DurationPMax.ToString();
case 3: return DurationLeak.ToString();
case 4: return IsPumpRunning ? Strings.yes : Strings.no;
case 5: return MaxPressureDrop.ToString();
case 6: return MaxMassIncrease.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.ParseUFloat(strValue); return CfgUpdateFlags.None;
case 2: DurationPMax = int.Parse(strValue); return CfgUpdateFlags.None;
case 3: DurationLeak = int.Parse(strValue); return CfgUpdateFlags.None;
case 4: IsPumpRunning = strValue.Equals(Strings.yes); return CfgUpdateFlags.None;
case 5: MaxPressureDrop = Utils.ParseSFloat(strValue); return CfgUpdateFlags.None;
case 6: MaxMassIncrease = Utils.ParseUFloat(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:
case 6:
if (Utils.TryParseUFloat(strValue, out dummy)) return true;
break;
case 2:
case 3:
if (int.TryParse(strValue, out iDummy)) return true;
break;
case 4:
if (strValue.Equals(Strings.yes) || strValue.Equals(Strings.no)) return true;
break;
case 5:
if (Utils.TryParseSFloat(strValue, out dummy)) return true;
break;
default:
message = "Invalid index";
return false;
}
message = ParamName(i) + " is invalid";
return false;
}
void CopyContentTo(LeakTestParams prms)
{
prms.PressureLo = this.PressureLo;
prms.PressureHi = this.PressureHi;
prms.DurationPMax = this.DurationPMax;
prms.DurationLeak = this.DurationLeak;
prms.IsPumpRunning = this.IsPumpRunning;
prms.MaxPressureDrop = this.MaxPressureDrop;
prms.MaxMassIncrease = this.MaxMassIncrease;
}
public IParamsProvider Clone()
{
LeakTestParams pars = new LeakTestParams();
CopyContentTo(pars);
return pars;
}
public override void UpdateFromDbEntity(ComponentTest dbEntity)
{
if (dbEntity == null) return;
try
{
LeakTestParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as LeakTestParams;
testParamsEntity = dbEntity;
componentName = dbEntity.CmpntName;
test = dbEntity.Test;
if (tmp != null) tmp.CopyContentTo(this);
}
catch
{
}
}
/// <summary>
/// Parameterless constructor initializes the parameters
/// </summary>
public LeakTestParams()
{
}
public LeakTestParams(bool initialize)
{
if (initialize) InitializeAll();
}
public LeakTestParams(ComponentTest testParamsEntity, string componentName, Test test)
{
this.testParamsEntity = testParamsEntity;
this.componentName = componentName;
this.test = test;
}
}
}