/// /// Copyright (c) 2018-2021 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using System.Xml.Serialization; using Common; using Config.Entities; using TBF.Rig.Generic; namespace TBF.Rig.DataContainer.BenchInfo { /// /// Holds information identifying the test bench - serializable configuration. /// public class ComponentCfg : ComponentCfgBase, Generic.IComponentCfg, IParamsProvider { public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ComponentCfg) })[0]; public override XmlSerializer GetSerializer() { return Serializer; } public IComponentCfgCtrl GetControl(IList cmpntEntities) { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); } /// /// Serialized parameters /// public string TestBenchName; /// 0 public int TestBenchId; /// 1 public string Address1; /// 2 public string Address2; /// 3 public string Address3; /// 4 public string Address4; /// 5 public string Address5; /// 6 public string ApprovalId; /// 7 public string ApprovalDate; /// 8 public string ApprovedBy; /// 9 public int WaterMetersCount; /// 10 public int LinesCount; /// 11 public int CompoundMetersCount; /// 12 public Unit VolumeUnit; /// 13 public Unit FlowUnit; /// 14 public Unit MassUnit; /// 15 public Unit TempUnit; /// 16 public Unit PressUnit; /// 17 public Unit LenghtUnit; /// 18 public ProcedureSelection Source1; /// 19 public ProcedureSelection Source2; /// 20 public ProcedureSelection Source3; /// 21 public ProcedureSelection Source4; /// 22 /// Private parameterless constructor invoked by all other (public) constructors ComponentCfg() {} public ComponentCfg(string name, IComponentFactory factory) : this() { Name = name; Factory = factory; ParentName = string.Empty; InitializeAll(); } public string ComponentName { get { return Name; } } public void InitializeAll() { TestBenchName = "1"; TestBenchId = 1; Address1 = string.Empty; Address2 = string.Empty; Address3 = string.Empty; Address4 = string.Empty; Address5 = string.Empty; ApprovalId = string.Empty; ApprovalDate = string.Empty; ApprovedBy = string.Empty; WaterMetersCount = 20; LinesCount = 2; CompoundMetersCount = 1; VolumeUnit = Unit.l; FlowUnit = Unit.m3ph; MassUnit = Unit.kg; TempUnit = Unit.C; PressUnit = Unit.bar; LenghtUnit = Unit.mm; Source1 = ProcedureSelection.FromLocalDB; Source2 = ProcedureSelection.None; Source3 = ProcedureSelection.None; Source4 = ProcedureSelection.None; } string[] paramNames = new string[] { "Test bench name", /// 0 "Test bench ID", /// 1 "Address 1", /// 2 "Address 2", /// 3 "Address 3", /// 4 "Address 4", /// 5 "Address 5", /// 6 "Approval", /// 7 "Approval date", /// 8 "Approved by", /// 9 "Water meters count", /// 10 "Lines count", /// 11 "Compound meters count", /// 12 "Preffered volume unit", "Preffered flow unit", "Preffered mass unit", "Preffered temperature unit", "Preffered pressure unit", "Preffered lenght unit", "Procedure selection source 1", /// 13 "Procedure selection source 2", /// 14 "Procedure selection source 3", /// 15 "Procedure selection source 4", /// 16 }; public string ParamName(int i) { return paramNames[i]; } public int ParamsCount() { return paramNames.Length; } public ICollection ParamValues(int i) { var list = new List(); switch (i) { case 10: return new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "10", "12", "14", "16", "18", "20" }; case 11: return new string[] { "1", "2", "3", "4" }; case 12: return new string[] { "0", "1", "2", "3" }; case 13: for (Unit unit = 0; unit < Unit.Count; unit++) if (Units.IsQuantity(unit, Quantity.Volume)) list.Add(unit.ToDescription()); return list; case 14: for (Unit unit = 0; unit < Unit.Count; unit++) if (Units.IsQuantity(unit, Quantity.Flow)) list.Add(unit.ToDescription()); return list; case 15: for (Unit unit = 0; unit < Unit.Count; unit++) if (Units.IsQuantity(unit, Quantity.Mass)) list.Add(unit.ToDescription()); return list; case 16: for (Unit unit = 0; unit < Unit.Count; unit++) if (Units.IsQuantity(unit, Quantity.Temperature)) list.Add(unit.ToDescription()); return list; case 17: for (Unit unit = 0; unit < Unit.Count; unit++) if (Units.IsQuantity(unit, Quantity.Pressure)) list.Add(unit.ToDescription()); return list; case 18: for (Unit unit = 0; unit < Unit.Count; unit++) if (Units.IsQuantity(unit, Quantity.Length)) list.Add(unit.ToDescription()); return list; case 19: case 20: case 21: case 22: for (ProcedureSelection src = 0; src < ProcedureSelection.Count; src++) list.Add(src.ToDescription()); return list; default: return null; } } public string ToString(int i) { switch (i) { case 0: return TestBenchName; case 1: return TestBenchId.ToString(); case 2: return Address1; case 3: return Address2; case 4: return Address3; case 5: return Address4; case 6: return Address5; case 7: return ApprovalId; case 8: return ApprovalDate; case 9: return ApprovedBy; case 10: return WaterMetersCount.ToString(); case 11: return LinesCount.ToString(); case 12: return CompoundMetersCount.ToString(); case 13: return VolumeUnit.ToDescription(); case 14: return FlowUnit.ToDescription(); case 15: return MassUnit.ToDescription(); case 16: return TempUnit.ToDescription(); case 17: return PressUnit.ToDescription(); case 18: return LenghtUnit.ToDescription(); case 19: return Source1.ToDescription(); case 20: return Source2.ToDescription(); case 21: return Source3.ToDescription(); case 22: return Source4.ToDescription(); default: return string.Format("{0}: Bench={1}, ID={2}, Mtrs={3}, Lines={4}, Compund mtrs={5}, S1={6}, S2={7}, S3={8}, S4={9}", Name, TestBenchName, TestBenchId, WaterMetersCount, LinesCount, CompoundMetersCount, Source1, Source2, Source3, Source4); } } public CfgUpdateFlags UpdateParam(int i, string str) { switch (i) { case 0: TestBenchName = str; return CfgUpdateFlags.RestartRqrd; case 1: TestBenchId = int.Parse(str); return CfgUpdateFlags.RestartRqrd; case 2: Address1 = str; return CfgUpdateFlags.RestartRqrd; case 3: Address2 = str; return CfgUpdateFlags.RestartRqrd; case 4: Address3 = str; return CfgUpdateFlags.RestartRqrd; case 5: Address4 = str; return CfgUpdateFlags.RestartRqrd; case 6: Address5 = str; return CfgUpdateFlags.RestartRqrd; case 7: ApprovalId = str; return CfgUpdateFlags.RestartRqrd; case 8: ApprovalDate = str; return CfgUpdateFlags.RestartRqrd; case 9: ApprovedBy = str; return CfgUpdateFlags.RestartRqrd; case 10: WaterMetersCount = int.Parse(str); return CfgUpdateFlags.RestartRqrd; case 11: LinesCount = int.Parse(str); return CfgUpdateFlags.RestartRqrd; case 12: CompoundMetersCount = int.Parse(str); return CfgUpdateFlags.RestartRqrd; case 13: VolumeUnit = Units.FromDescription(str); return CfgUpdateFlags.RestartRqrd; case 14: FlowUnit = Units.FromDescription(str); return CfgUpdateFlags.RestartRqrd; case 15: MassUnit = Units.FromDescription(str); return CfgUpdateFlags.RestartRqrd; case 16: TempUnit = Units.FromDescription(str); return CfgUpdateFlags.RestartRqrd; case 17: PressUnit = Units.FromDescription(str); return CfgUpdateFlags.RestartRqrd; case 18: LenghtUnit = Units.FromDescription(str); return CfgUpdateFlags.RestartRqrd; case 19: for (ProcedureSelection source = 0; source < ProcedureSelection.Count; source++) { if (str == source.ToDescription()) { Source1 = source; return CfgUpdateFlags.RestartRqrd; } } break; case 20: for (ProcedureSelection source = 0; source < ProcedureSelection.Count; source++) { if (str == source.ToDescription()) { Source2 = source; return CfgUpdateFlags.RestartRqrd; } } break; case 21: for (ProcedureSelection source = 0; source < ProcedureSelection.Count; source++) { if (str == source.ToDescription()) { Source3 = source; return CfgUpdateFlags.RestartRqrd; } } break; case 22: for (ProcedureSelection source = 0; source < ProcedureSelection.Count; source++) { if (str == source.ToDescription()) { Source4 = source; return CfgUpdateFlags.RestartRqrd; } } break; default: return CfgUpdateFlags.None; } return CfgUpdateFlags.Error; } public bool ValidateParam(int i, string str, out string message) { message = string.Empty; int idummy; switch (i) { case 0: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: return true; case 1: if (int.TryParse(str, out idummy) && (idummy >= 0)) return true; break; case 10: if (int.TryParse(str, out idummy) && idummy >= 1 && idummy <= 20) return true; break; case 11: if (int.TryParse(str, out idummy) && idummy >= 1 && idummy <= 4) return true; break; case 12: if (int.TryParse(str, out idummy) && idummy >= 0 && idummy <= 3) return true; break; case 13: case 14: case 15: case 16: case 17: case 18: if (ParamValues(i).Contains(str)) return true; break; case 19: case 20: case 21: case 22: for (ProcedureSelection source = 0; source < ProcedureSelection.Count; source++) { if (str == source.ToDescription()) return true; } break; default: message = "Invalid index"; return false; } message = ParamName(i) + " is invalid"; return false; } void CopyContentTo(ComponentCfg prms) { prms.TestBenchName = this.TestBenchName; prms.TestBenchId = this.TestBenchId; prms.Address1 = this.Address1; prms.Address2 = this.Address2; prms.Address3 = this.Address3; prms.Address4 = this.Address4; prms.Address5 = this.Address5; prms.ApprovalId = this.ApprovalId; prms.ApprovalDate = this.ApprovalDate; prms.ApprovedBy = this.ApprovedBy; prms.WaterMetersCount = this.WaterMetersCount; prms.LinesCount = this.LinesCount; prms.CompoundMetersCount = this.CompoundMetersCount; prms.VolumeUnit = this.VolumeUnit; prms.FlowUnit = this.FlowUnit; prms.MassUnit = this.MassUnit; prms.TempUnit = this.TempUnit; prms.PressUnit = this.PressUnit; prms.LenghtUnit = this.LenghtUnit; prms.Source1 = this.Source1; prms.Source2 = this.Source2; prms.Source3 = this.Source3; prms.Source4 = this.Source4; } public IParamsProvider Clone() { ComponentCfg pars = new ComponentCfg(); CopyContentTo(pars); return pars; } public bool UpdateEmbeddedDbEntity() { return true; /// =OK, do nothing } } }