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
@@ -13,51 +13,25 @@ namespace TBF.BenchControl.Elde.PressureMeter
/// Parameterless constructor
public PressureMeterCfg()
{
}
/// <summary>
/// Regulation valve configuration parameters
/// </summary>
/// <param name="name">Regulation valve name</param>
/// <param name="idx0">Position on the control board 0..3</param>
/// <param name="dacValueClosed">0..1023</param>
/// <param name="dacValueOpen">0..1023</param>
public PressureMeterCfg(IComponentFactory factory, string name, string parentName, int idx0, byte rs485Address)
: base(factory, name, parentName)
Name = "PressureMeter";
ParentName = "CB";
Idx0 = 0;
RS485Address = 99;
}
public PressureMeterCfg(IComponentFactory factory)
: this()
{
if (idx0 < 0 || idx0 > 3) throw new ArgumentOutOfRangeException("Index (0-based)");
this.Idx0 = idx0;
if (rs485Address < 0 || rs485Address > 255) throw new ArgumentOutOfRangeException("RS485Address");
this.RS485Address = rs485Address;
}
public IComponentCfg Clone()
{
return new PressureMeterCfg(Factory, Name, ParentName, Idx0, RS485Address);
}
this.Factory = factory;
}
public string ToString(int i)
{
return string.Format("idx0={0}, RS485 address={1}", Idx0, RS485Address);
}
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))
{
PressureMeterCfg config = (PressureMeterCfg)(new XmlSerializer(typeof(PressureMeterCfg))).Deserialize(reader);
config.InitCfgBaseFromEntity(component, factory);
return config;
}
return string.Format("Name={0}, Parent={1}, Idx0={2}, Address={3}",
Name,
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName),
Idx0,
RS485Address);
}
}
}