/// /// Copyright (c) 2017-2019 Sensus Slovensko a.s. /// using System.IO; using System.Xml.Serialization; using Config.Entities; using TBF.BenchControl.Generic; using TBF.Resources; namespace TBF.BenchControl.Various.ErrorFlags { public class TestParams : TestParamsBase, IParamsProvider, ITestParams { public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TestParams) })[0]; public override XmlSerializer GetSerializer() { return Serializer; } public ErrorFlagsMode Mode; /// 0 = Off, 1 = Info (show only), 2 = On (show and evaluate) public bool E1; public bool E2; public bool E3; public bool E4; public bool E5; public bool E6; public bool E7; public bool E8; public bool E9; public bool E10; public bool E11; public bool E12; public bool E13; public bool E14; public bool E15; public bool E16; public bool E21; public float Delta_Q_pct; /// [%] max deviation from the mean flow public float Delta_T; /// [°C] max. T_up or T_down deviation from the mean temperature public float Delta_Tup_Tdn; /// [°C] max. difference abs(T_up - T_down) public float TestTime_min; /// [s] public float TestTime_max; /// [s] public float AmbTemp_min; /// [°C] min. ambient temperature public float AmbTemp_max; /// [°C] max. ambient temperature public float Pressure_min; /// [bar] min. water pressure public float Pressure_max; /// [bar] max. water pressure public float Coef_E9; /// Coefficient used in E9, default 0.025 public float Coef_E10; /// Coefficient used in E10, default 0.04 public float Coef_E11; /// Coefficient used in E11, default 0.1 public float Coef_E12; /// Coefficient used in E12, default 1 public float Offset_E9; /// [s] default 0 (no offset) public float Offset_E12; /// [s] default 0 (no offset) #if IPERL public bool E25; /// MaxProefindex verification public bool E26; /// Q2 factors verification (saved from production == current) public bool E27; /// Direction verification public bool E28; /// Previous workflow step verification #endif public override void InitializeAll() { Mode = ErrorFlagsMode.Info; #if IPERL E1 = true; E2 = false; E3 = true; E4 = false; E5 = false; E6 = false; E7 = false; E8 = false; E9 = false; E10 = false; E11 = false; E12 = false; E13 = false; E14 = false; E15 = false; E16 = false; E21 = true; E25 = true; /// MaxPruefindex verification E26 = false; /// Q2 factors verification (saved from production == current) E27 = false; /// Direction verification E28 = true; /// Previous workflow step verification #else E1 = true; E2 = true; E3 = true; E4 = true; E5 = true; E6 = true; E7 = true; E8 = true; E9 = true; E10 = true; E11 = true; E12 = true; E13 = true; E14 = true; E15 = true; E16 = true; E21 = true; #endif Delta_Q_pct = 5.0f; /// [%] Delta_T = 10.0f; /// [°C] Delta_Tup_Tdn = 10.0f; /// [°C] TestTime_min = 0; /// [s] TestTime_max = 99999; /// [s] AmbTemp_min = 5.0f; /// [°C] AmbTemp_max = 95.0f; /// [°C] Pressure_min = 0; /// [bar] Pressure_max = 16.0f; /// [bar] Coef_E9 = 0.025f; Coef_E10 = 0.04f; Coef_E11 = 0.1f; Coef_E12 = 1.0f; Offset_E9 = 0; /// [s] Offset_E12 = 0; /// [s] } string[] paramNames = new string[] { Strings.Mode, "E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", "E10", "E11", "E12", "E13", "E14", "E15", "E16", "E21", "Delta Q [%]", "Delta T [°C]", "max. Abs(Tup - Tdn) [°C]", string.Format("min. {0}", Strings.Test_time_s_chdr), string.Format("max. {0}", Strings.Test_time_s_chdr), string.Format("min. {0} [°C]", Strings.Air_temperature), string.Format("max. {0} [°C]", Strings.Air_temperature), string.Format("min. {0} [bar]", Strings.Pressure), string.Format("max. {0} [bar]", Strings.Pressure), "Coef.E9", "Coef.E10", "Coef.E11", "Coef.E12", "Offset E9 [s]", "Offset E12 [s]", #if IPERL "E25", "E26", "E27", "E28", #endif }; 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 Mode.ToDescription(); case 1: return (E1 ? Strings.yes : Strings.no); case 2: return (E2 ? Strings.yes : Strings.no); case 3: return (E3 ? Strings.yes : Strings.no); case 4: return (E4 ? Strings.yes : Strings.no); case 5: return (E5 ? Strings.yes : Strings.no); case 6: return (E6 ? Strings.yes : Strings.no); case 7: return (E7 ? Strings.yes : Strings.no); case 8: return (E8 ? Strings.yes : Strings.no); case 9: return (E9 ? Strings.yes : Strings.no); case 10: return (E10 ? Strings.yes : Strings.no); case 11: return (E11 ? Strings.yes : Strings.no); case 12: return (E12 ? Strings.yes : Strings.no); case 13: return (E13 ? Strings.yes : Strings.no); case 14: return (E14 ? Strings.yes : Strings.no); case 15: return (E15 ? Strings.yes : Strings.no); case 16: return (E16 ? Strings.yes : Strings.no); case 17: return (E21 ? Strings.yes : Strings.no); case 18: return Delta_Q_pct.ToString(); case 19: return Delta_T.ToString(); case 20: return Delta_Tup_Tdn.ToString(); case 21: return TestTime_min.ToString(); case 22: return TestTime_max.ToString(); case 23: return AmbTemp_min.ToString(); case 24: return AmbTemp_max.ToString(); case 25: return Pressure_min.ToString(); case 26: return Pressure_max.ToString(); case 27: return Coef_E9.ToString(); case 28: return Coef_E10.ToString(); case 29: return Coef_E11.ToString(); case 30: return Coef_E12.ToString(); case 31: return Offset_E9.ToString(); case 32: return Offset_E12.ToString(); #if IPERL case 33: return (E25 ? Strings.yes : Strings.no); case 34: return (E26 ? Strings.yes : Strings.no); case 35: return (E27 ? Strings.yes : Strings.no); case 36: return (E28 ? Strings.yes : Strings.no); #endif default: return string.Empty; } } /// Retrieves parameters from UI controls public CfgUpdateFlags UpdateParam(int i, string strValue) { switch (i) { case 0: for (ErrorFlagsMode m = 0; m < ErrorFlagsMode.Count; m++) { if (m.ToDescription() == strValue) { Mode = m; return CfgUpdateFlags.None; } } return CfgUpdateFlags.None; case 1: E1 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 2: E2 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 3: E3 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 4: E4 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 5: E5 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 6: E6 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 7: E7 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 8: E8 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 9: E9 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 10: E10 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 11: E11 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 12: E12 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 13: E13 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 14: E14 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 15: E15 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 16: E16 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 17: E21 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 18: Delta_Q_pct = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 19: Delta_T = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 20: Delta_Tup_Tdn = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 21: TestTime_min = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 22: TestTime_max = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 23: AmbTemp_min = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 24: AmbTemp_max = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 25: Pressure_min = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 26: Pressure_max = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 27: Coef_E9 = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 28: Coef_E10 = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 29: Coef_E11 = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 30: Coef_E12 = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 31: Offset_E9 = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; case 32: Offset_E12 = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None; #if IPERL case 33: E25 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 34: E26 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 35: E27 = (strValue == Strings.yes); return CfgUpdateFlags.None; case 36: E28 = (strValue == Strings.yes); return CfgUpdateFlags.None; #endif default: return CfgUpdateFlags.None; } } /// Verifies whether strings in UI controls represent valid parameters public bool ValidateParam(int i, string strValue, out string message) { message = string.Empty; float fdummy; switch (i) { case 0: for (ErrorFlagsMode m = 0; m < ErrorFlagsMode.Count; m++) { if (m.ToDescription() == strValue) return true; } break; case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 33: case 34: case 35: case 36: if (strValue == Strings.yes || strValue == Strings.no) return true; break; case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: case 32: if (Utils.TryParseUFloat(strValue, out fdummy)) return true; break; default: message = "Invalid index"; return false; } message = ParamName(i) + " is invalid"; return false; } void CopyContentTo(TestParams prms) { prms.Mode = this.Mode; prms.E1 = this.E1; prms.E2 = this.E2; prms.E3 = this.E3; prms.E4 = this.E4; prms.E5 = this.E5; prms.E6 = this.E6; prms.E7 = this.E7; prms.E8 = this.E8; prms.E9 = this.E9; prms.E10 = this.E10; prms.E11 = this.E11; prms.E12 = this.E12; prms.E13 = this.E13; prms.E14 = this.E14; prms.E15 = this.E15; prms.E16 = this.E16; prms.E21 = this.E21; prms.Delta_Q_pct = this.Delta_Q_pct; prms.Delta_T = this.Delta_T; prms.Delta_Tup_Tdn = this.Delta_Tup_Tdn; prms.TestTime_min = this.TestTime_min; prms.TestTime_max = this.TestTime_max; prms.AmbTemp_min = this.AmbTemp_min; prms.AmbTemp_max = this.AmbTemp_max; prms.Pressure_min = this.Pressure_min; prms.Pressure_max = this.Pressure_max; prms.Coef_E9 = this.Coef_E9; prms.Coef_E10 = this.Coef_E10; prms.Coef_E11 = this.Coef_E11; prms.Coef_E12 = this.Coef_E12; prms.Offset_E9 = this.Offset_E9; prms.Offset_E12 = this.Offset_E12; #if IPERL prms.E25 = this.E25; prms.E26 = this.E26; prms.E27 = this.E27; prms.E28 = this.E28; #endif } 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 { } } public TestParams() { } public TestParams(bool initialize) { if (initialize) InitializeAll(); } public TestParams(ComponentProcedure procedureParamsEntity, string componentName, Test test) { this.testParamsEntity = testParamsEntity; this.componentName = componentName; this.test = test; } } }