Methods CreateDbEntity and CreateFromDbEntity moved from XyzCfg to ComponentCfgBase, factories modified accordingly.

This commit is contained in:
Milan Hanajik
2014-12-29 18:33:27 +01:00
parent 8ef0cea1ff
commit 0ac7ba05d6
67 changed files with 540 additions and 1266 deletions
@@ -7,55 +7,31 @@ namespace TBF.BenchControl.Elde.FlowMeter
{
public class FlowMeterCfg : ComponentCfgBase, Generic.IChildComponentCfg
{
public int Idx1; /// 1..5
public int Idx1; /// 1..5
public float NominalFlow; /// Nominal flow in m3/h at output frequency 2000 Hz
/// Parameterless constructor
public FlowMeterCfg()
{
Name = "FlowMeter";
ParentName = "CB";
Idx1 = 1;
NominalFlow = 1;
}
/// <summary>
/// Flow meter configuration parameters
/// </summary>
/// <param name="name">Flow meter name</param>
/// <param name="idx1">Position on the control board 1..5</param>
public FlowMeterCfg(IComponentFactory factory, string name, string parentName, int idx1, float nominalFlow)
: base(factory, name, parentName)
public FlowMeterCfg(IComponentFactory factory)
: this()
{
if (idx1 < 1 || idx1 > 5) throw new ArgumentOutOfRangeException("idx1");
this.Idx1 = idx1;
this.NominalFlow = nominalFlow;
}
public IComponentCfg Clone()
{
return new FlowMeterCfg(Factory, Name, ParentName, Idx1, NominalFlow);
}
this.Factory = factory;
}
public string ToString(int i)
{
return string.Format("idx1={0}, nominalFlow={1}", Idx1, 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;
}
return string.Format("Name={0}, Parent={1}, Idx1={2}, NominalFlow={3}",
Name,
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName),
Idx1,
NominalFlow);
}
}
}
@@ -20,7 +20,7 @@ namespace TBF.BenchControl.Elde.FlowMeter
public IComponentCfg DefaultConfig(IList<Entities.Component> components)
{
return new FlowMeterCfg(this, "FlowMeter", "CB", 1, 1);
return new FlowMeterCfg(this);
}
public IComponentCfgCtrl CreateCfgCtrl()
@@ -35,7 +35,7 @@ namespace TBF.BenchControl.Elde.FlowMeter
public IComponentCfg CmpntCfgFromCmpntEntity(Entities.Component component)
{
return FlowMeterCfg.CreateFromDbEntity(component, this);
return ComponentCfgBase.CreateFromDbEntity(typeof(FlowMeterCfg), component, this);
}
public void ResetStaticProperties() { FlowMeter.ResetStaticProperties(); }