/// /// Copyright (c) 2019 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using System.Xml.Serialization; using Config.Entities; using TBF.BenchControl.Generic; namespace TBF.BenchControl.DataContainers.Buoyancy { /// /// Holds backup and security options - serializable configuration. /// public class ComponentCfg : ComponentCfgBase, Generic.IComponentCfg, Config.Entities.IParamsProvider { public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ComponentCfg) })[0]; public override XmlSerializer GetSerializer() { return Serializer; } public IComponentCfgCtrl GetControl() { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); } /// /// Serialized parameters /// public double Buoyancy; /// 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() { Buoyancy = 1.00103; } string[] paramNames = new string[] { "Buoyancy", }; public string ParamName(int i) { return paramNames[i]; } public int ParamsCount() { return paramNames.Length; } public IList ParamValues(int i) { return null; } public string ToString(int i) { if (i == -1) { return string.Format("{0}: Buoyancy = {1}", Name, Buoyancy); } switch (i) { case 0: return Buoyancy.ToString(); default: return string.Empty; } } public CfgUpdateFlags UpdateParam(int i, string strValue) { switch (i) { case 0: Buoyancy = Utils.ParseUDouble(strValue); return CfgUpdateFlags.RestartRqrd; default: return CfgUpdateFlags.None; } } public bool ValidateParam(int i, string strValue, out string message) { message = string.Empty; double dummy; switch (i) { case 0: /// Real number between 0.8 and 1.2 expected if (Utils.TryParseUDouble(strValue, out dummy) && (dummy >= 0.8) && (dummy <= 1.2)) return true; break; default: message = "Invalid index"; return false; } message = ParamName(i) + " is invalid"; return false; } void CopyContentTo(ComponentCfg prms) { prms.Buoyancy = this.Buoyancy; } public Config.Entities.IParamsProvider Clone() { ComponentCfg pars = new ComponentCfg(); CopyContentTo(pars); return pars; } public bool UpdateEmbeddedDbEntity() { return true; /// =OK, do nothing } } }