/// /// Copyright (c) 2020 Sensus Slovensko a.s. /// using System; using System.Xml.Serialization; using Config.Entities; using TBF.BenchControl.Generic; using TBF.Resources; using System.Collections.Generic; namespace TBF.BenchControl.Various.StatisticsMonitoring { /// /// Serializable configuration of Various.StatisticsMonitoring component. /// public class StatisticsCfg : ComponentCfgBase, Generic.IComponentCfg, Config.Entities.IParamsProvider { public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(StatisticsCfg) })[0]; public override XmlSerializer GetSerializer() { return Serializer; } public IComponentCfgCtrl GetControl() { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); } /// /// Serialized parameters /// public string EventSource; public int iPerlHeadFailureRateThreshold; /// 0 = off, 1..100% event is triggered when percentage reaches this level /// Private parameterless constructor invoked by all other (public) constructors StatisticsCfg() { } public StatisticsCfg(string name, IComponentFactory factory) : this() { Name = name; Factory = factory; ParentName = string.Empty; InitializeAll(); } public string ComponentName { get { return Name; } } public void InitializeAll() { EventSource = "Štatistiky"; /// 0 iPerlHeadFailureRateThreshold = 20; /// 1 } string[] paramNames = new string[] { "Event source", /// 0 "Threshold for iPERL head failure rate [%] (0=off)", /// 1 }; 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) { switch (i) { case -1: return string.Format("Name={0}, EventSource={1}, FailureRatePct={2}, ...", Name, EventSource, iPerlHeadFailureRateThreshold); case 0: return EventSource; case 1: return iPerlHeadFailureRateThreshold.ToString(); default: return string.Empty; } } public CfgUpdateFlags UpdateParam(int i, string strValue) { switch (i) { case 0: EventSource = strValue; return CfgUpdateFlags.AnyChange; case 1: iPerlHeadFailureRateThreshold = int.Parse(strValue); return CfgUpdateFlags.AnyChange; default: return CfgUpdateFlags.None; } } /// /// Validate string form of a parameter value /// /// Parameter index /// String form of a parameter /// Message in case value is not valid /// true when string form of a parameter is OK public bool ValidateParam(int i, string strValue, out string message) { message = string.Empty; int percentage; switch (i) { case 0: return true; case 1: if (int.TryParse(strValue, out percentage) && (0 <= percentage) && (percentage <= 100)) return true; message = "Threshold for iPERL head failure rate in % (0 = off)"; return false; default: message = "Invalid index"; return false; } } void CopyContentTo(StatisticsCfg prms) { prms.EventSource = this.EventSource; /// 0 prms.iPerlHeadFailureRateThreshold = this.iPerlHeadFailureRateThreshold; /// 1 } public Config.Entities.IParamsProvider Clone() { StatisticsCfg pars = new StatisticsCfg(); CopyContentTo(pars); return pars; } public bool UpdateEmbeddedDbEntity() { return true; /// =OK, do nothing } } }