tbf/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetTestParams.cs

160 lines
4.5 KiB
C#

///
/// Copyright (c) 2013-2015 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.CombinedWithDetection
{
public class CombinedWithDetTestParams : TestParamsBase, IParamsProvider, ITestParams
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(CombinedWithDetTestParams) })[0];
protected override XmlSerializer GetSerializer() { return Serializer; }
public float TargetQ; /// Target=terminal flow durning detection when increasing or decreasing the flow
public float RelativeQfrom; /// Tested flow low range related to the detected flow
public float RelativeQto; /// Tested flow high range related to the detected flow
public float RateOfChange; /// Each step is calculated as (TargetQfrom - Qfrom) * RateOfChange, text form is displayed in % (*100)
public float DetectionThreshold; /// Drop of frequency for the detection, text form is displayed in % (*100)
public bool SupressTrills; /// Main meter readings are ignored during test (suitable for small flows)
public override void InitializeAll()
{
TargetQ = 3.0f;
RelativeQfrom = -0.4f;
RelativeQto = -0.2f;
RateOfChange = 0.05f;
DetectionThreshold = 0.25f;
SupressTrills = false;
}
string[] paramNames = new string[]
{
Strings.TargetQ,
Strings.RelativeQfrom,
Strings.RelativeQto,
Strings.RateOfChangePct,
Strings.DetectionThresholdPct,
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 TargetQ.ToString();
case 1: return RelativeQfrom.ToString();
case 2: return RelativeQto.ToString();
case 3: return (100.0f * RateOfChange).ToString();
case 4: return (100.0f * DetectionThreshold).ToString();
case 5: return (SupressTrills ? Strings.yes : Strings.no);
default: return string.Empty;
}
}
public void UpdateParam(int i, string strValue)
{
switch (i)
{
case 0: TargetQ = Utils.ParseUFloat(strValue); return;
case 1: RelativeQfrom = Utils.ParseSFloat(strValue); return;
case 2: RelativeQto = Utils.ParseSFloat(strValue); return;
case 3: RateOfChange = Utils.ParseUFloat(strValue) / 100.0f; return;
case 4: DetectionThreshold = Utils.ParseUFloat(strValue) / 100.0f; return;
case 5: SupressTrills = strValue.Equals(Strings.yes); return;
default: return;
}
}
public bool ValidateParam(int i, string strValue, out string message)
{
message = string.Empty;
float dummy;
switch (i)
{
case 0:
case 3:
case 4:
if (Utils.TryParseUFloat(strValue, out dummy)) return true;
break;
case 1:
case 2:
if (Utils.TryParseSFloat(strValue, out dummy)) return true;
break;
case 5:
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(CombinedWithDetTestParams prms)
{
prms.TargetQ = this.TargetQ;
prms.RelativeQfrom = this.RelativeQfrom;
prms.RelativeQto = this.RelativeQto;
prms.RateOfChange = this.RateOfChange;
prms.DetectionThreshold = this.DetectionThreshold;
prms.SupressTrills = this.SupressTrills;
}
public IParamsProvider Clone()
{
CombinedWithDetTestParams pars = new CombinedWithDetTestParams();
CopyContentTo(pars);
return pars;
}
public override void UpdateTestParams(ComponentTest dbEntity)
{
if (dbEntity == null) return;
try
{
CombinedWithDetTestParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as CombinedWithDetTestParams;
testParamsEntity = dbEntity;
componentName = dbEntity.CmpntName;
test = dbEntity.Test;
if (tmp != null) tmp.CopyContentTo(this);
}
catch
{
}
}
/// <summary>
/// Parameterless constructor initializes the parameters
/// </summary>
public CombinedWithDetTestParams()
{
}
public CombinedWithDetTestParams(bool initialize)
{
if (initialize) InitializeAll();
}
public CombinedWithDetTestParams(ComponentTest testParamsEntity, string componentName, Test test)
{
this.testParamsEntity = testParamsEntity;
this.componentName = componentName;
this.test = test;
}
}
}