tbf/TBF/Rig/TestMethods/FlyingStartMassCollComparative/Compound/TestParams.cs
2021-06-18 15:35:46 +02:00

148 lines
4.5 KiB
C#

///
/// Copyright (c) 2018 Sensus Slovensko a.s.
///
using System;
using System.IO;
using System.Xml.Serialization;
using Common;
using Config.Entities;
using TBF.Rig.Generic;
using TBF.Resources;
namespace TBF.Rig.TestMethods.FlyingStartMassCollComparative.Compound
{
public class TestParams : TestParamsBase, IParamsProvider, ITestParams
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TestParams) })[0];
public override XmlSerializer GetSerializer() { return Serializer; }
public string ValveName;
public double RefMass; /// [kg] Reference mass
public int StabTime; /// [s] Delay between valve change and mass measurement
public bool SupressTrills; /// Main meter readings are ignored during test (suitable for small flows)
public override void InitializeAll()
{
ValveName = "M1";
RefMass = 10; /// [kg]
StabTime = 10; /// [s]
SupressTrills = false;
}
string[] paramNames = new string[]
{
"Valve name",
"Reference mass",
"Stability time",
Strings.SupressWMTrills,
};
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 ValveName;
case 1: return RefMass.ToString();
case 2: return StabTime.ToString();
case 3: return SupressTrills ? Strings.yes : Strings.no;
default: return string.Empty;
}
}
public CfgUpdateFlags UpdateParam(int i, string strValue)
{
switch (i)
{
case 0: ValveName = strValue; return CfgUpdateFlags.None;
case 1: RefMass = Utils.ParseUDouble(strValue); return CfgUpdateFlags.None;
case 2: StabTime = int.Parse(strValue); return CfgUpdateFlags.None;
case 3: SupressTrills = strValue.Equals(Strings.yes); return CfgUpdateFlags.None;
default: return CfgUpdateFlags.None;
}
}
public bool ValidateParam(int i, string strValue, out string message)
{
message = string.Empty;
double dummy;
int iDummy;
switch (i)
{
case 0:
return true;
case 1:
if (Utils.TryParseUDouble(strValue, out dummy)) return true;
break;
case 2:
if (int.TryParse(strValue, out iDummy) && (iDummy > 0)) return true;
break;
case 3:
if (strValue.Equals(Strings.yes) || strValue.Equals(Strings.no)) return true;
break;
default:
message = "Invalid index";
return false;
}
message = ParamName(i) + " is invalid";
return false;
}
void CopyContentTo(TestParams prms)
{
prms.ValveName = ValveName;
prms.RefMass = RefMass;
prms.StabTime = StabTime;
prms.SupressTrills = SupressTrills;
}
public IParamsProvider Clone()
{
TestParams pars = new TestParams();
CopyContentTo(pars);
return pars;
}
public override void UpdateFromDbEntity(ComponentTest dbEntity)
{
if (dbEntity == null) return;
try
{
TestParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as TestParams;
testParamsEntity = dbEntity;
componentName = dbEntity.CmpntName;
test = dbEntity.Test;
if (tmp != null) tmp.CopyContentTo(this);
}
catch
{
}
}
/// <summary>
/// Parameterless constructor initializes the parameters
/// </summary>
public TestParams()
{
}
public TestParams(bool initialize)
{
if (initialize) InitializeAll();
}
public TestParams(ComponentTest testParamsEntity, string componentName, Test test)
{
this.testParamsEntity = testParamsEntity;
this.componentName = componentName;
this.test = test;
}
}
}