/// /// Copyright (c) 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.Resources; namespace TBF.BenchControl.TestMethods.FlyingStartFirstRepetWithMassColl.Single { public class TestParams : TestParamsBase, IParamsProvider, ITestParams { public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TestParams) })[0]; protected override XmlSerializer GetSerializer() { return Serializer; } public float NextTestVolume; /// [l] public override void InitializeAll() { NextTestVolume = 10; } string[] paramNames = new string[] { string.Format("{0} [l]", Strings.Next_test_volume), }; 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 NextTestVolume.ToString(); default: return string.Empty; } } public void UpdateParam(int i, string strValue) { switch (i) { case 0: NextTestVolume = Utils.ParseUFloat(strValue); return; default: return; } } public bool ValidateParam(int i, string strValue, out string message) { message = string.Empty; float volumeToTank; switch (i) { case 0: if (Utils.TryParseUFloat(strValue, out volumeToTank) && volumeToTank >= 0.1f) return true; break; default: message = "Invalid index"; return false; } message = ParamName(i) + " is invalid"; return false; } void CopyContentTo(TestParams prms) { prms.NextTestVolume = this.NextTestVolume; } public IParamsProvider Clone() { TestParams pars = new TestParams(); CopyContentTo(pars); return pars; } public override void UpdateTestParams(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 { } } /// /// Parameterless constructor initializes the parameters /// 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; } } }