Methods CreateDbEntity and CreateFromDbEntity moved from XyzCfg to ComponentCfgBase, factories modified accordingly.
This commit is contained in:
@@ -12,44 +12,25 @@ namespace TBF.BenchControl.Elde.Pump
|
||||
/// Parameterless constructor
|
||||
public PumpCfg()
|
||||
{
|
||||
Name = "Pump";
|
||||
ParentName = "CB";
|
||||
BitPosition = 0;
|
||||
Delay = 1;
|
||||
}
|
||||
|
||||
/// Constructor
|
||||
public PumpCfg(IComponentFactory factory, string name, string parentName, int bitPosition, int delay)
|
||||
: base(factory, name, parentName)
|
||||
public PumpCfg(IComponentFactory factory)
|
||||
: this()
|
||||
{
|
||||
this.BitPosition = bitPosition;
|
||||
this.Delay = delay;
|
||||
}
|
||||
this.Factory = factory;
|
||||
}
|
||||
|
||||
public IComponentCfg Clone()
|
||||
{
|
||||
return new PumpCfg(Factory, Name, ParentName, BitPosition, Delay);
|
||||
}
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("bit={0}, delay={1}s", BitPosition, Delay);
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
PumpCfg config = (PumpCfg)(new XmlSerializer(typeof(PumpCfg))).Deserialize(reader);
|
||||
config.InitCfgBaseFromEntity(component, factory);
|
||||
return config;
|
||||
}
|
||||
}
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("Name={0}, Parent={1}, Bit={2}, Delay={3}",
|
||||
Name,
|
||||
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName),
|
||||
BitPosition,
|
||||
Delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user