using System; using System.IO; using System.Xml.Serialization; using TBF.BenchControl.Generic; namespace TBF.BenchControl.Elde.FlowMeter { public class FlowMeterCfg : ComponentCfgBase, Generic.IChildComponentCfg { public int Position; /// 1..5 public float NominalFlow; /// Nominal flow in m3/h at output frequency 2000 Hz /// Parameterless constructor public FlowMeterCfg() { } /// /// Flow meter configuration parameters /// /// Flow meter name /// Position on the control board 1..5 public FlowMeterCfg(IComponentFactory factory, string name, string parentName, int position, float nominalFlow) : base(factory, name, parentName) { if (position < 1 || position > 5) throw new ArgumentOutOfRangeException("position"); this.Position = position; this.NominalFlow = nominalFlow; } public IComponentCfg Clone() { return new FlowMeterCfg(Factory, Name, ParentName, Position, NominalFlow); } public string ToString(int i) { return string.Format("position={0}, nominalFlow={1}", Position, NominalFlow); } public TBF.Entities.Component CreateDbEntity() { using (var writer = new StringWriter()) { (new XmlSerializer(GetType())).Serialize(writer, this); return Entities.Component.CreateFromCfg(Name, Factory.ClassName, ParentName, ItemNr, DebugLevel, LogLevel, writer.ToString()); } } public static IComponentCfg CreateFromDbEntity(Entities.Component component, IComponentFactory factory) { using (var reader = new StringReader(component.Parameters)) { FlowMeterCfg config = (FlowMeterCfg)(new XmlSerializer(typeof(FlowMeterCfg))).Deserialize(reader); config.InitCfgBaseFromEntity(component, factory); return config; } } } }