Methods CreateDbEntity and CreateFromDbEntity moved from XyzCfg to ComponentCfgBase, factories modified accordingly.
This commit is contained in:
@@ -15,58 +15,34 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
public Handshake Handshake;
|
||||
public float Capacity; /// Max. water mass in 'kg' or volume in 'l'
|
||||
public float Empty; /// 'Empty' water mass in 'kg' or volume in 'l'
|
||||
public int EmptyTimeSec;
|
||||
public int EmptyTimeSec; /// s
|
||||
|
||||
/// Parameterless constructor
|
||||
public BalanceCfg()
|
||||
{
|
||||
Name = "Balance";
|
||||
ParentName = string.Empty;
|
||||
ComPortNr = 3;
|
||||
BaudRate = 2400;
|
||||
Parity = System.IO.Ports.Parity.Even;
|
||||
DataBits = 7;
|
||||
StopBits = System.IO.Ports.StopBits.One;
|
||||
Handshake = System.IO.Ports.Handshake.XOnXOff;
|
||||
Capacity = 200.0f;
|
||||
Empty = 20.0f;
|
||||
EmptyTimeSec = 180;
|
||||
}
|
||||
|
||||
/// Constructor
|
||||
public BalanceCfg(IComponentFactory factory, string name, int comPortNr, int baudRate, Parity parity, int dataBits, StopBits stopBits, Handshake handshake, float capacity, float empty, int emptyTimeSec)
|
||||
: base(factory, name)
|
||||
{
|
||||
this.ComPortNr = comPortNr;
|
||||
this.BaudRate = baudRate;
|
||||
this.Parity = parity;
|
||||
this.DataBits = dataBits;
|
||||
this.StopBits = stopBits;
|
||||
this.Handshake = handshake;
|
||||
this.Capacity = capacity;
|
||||
this.Empty = empty;
|
||||
this.EmptyTimeSec = emptyTimeSec;
|
||||
public BalanceCfg(IComponentFactory factory)
|
||||
: this()
|
||||
{
|
||||
this.Factory = factory;
|
||||
}
|
||||
|
||||
public IComponentCfg Clone()
|
||||
{
|
||||
return new BalanceCfg(Factory, Name, ComPortNr, BaudRate, Parity, DataBits, StopBits, Handshake, Capacity, Empty, EmptyTimeSec);
|
||||
}
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("COM{0}, {1}Bd, {2}bits, parity={3}, stopBits={4}, {5}, capacity={6}kg, empty={7}kg, emptyTime={8}s",
|
||||
ComPortNr, BaudRate, DataBits, Parity, StopBits, Handshake, Capacity, Empty, EmptyTimeSec);
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
BalanceCfg config = (BalanceCfg)(new XmlSerializer(typeof(BalanceCfg))).Deserialize(reader);
|
||||
config.InitCfgBaseFromEntity(component, factory);
|
||||
return config;
|
||||
}
|
||||
return string.Format("Name={0}, COM{1}, {2}Bd, {3}-bits, parity={4}, stopBits={5}, {6}, capacity={7}kg, empty={8}kg, emptyTime={9}s",
|
||||
Name, ComPortNr, BaudRate, DataBits, Parity, StopBits, Handshake, Capacity, Empty, EmptyTimeSec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,7 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
|
||||
public IComponentCfg DefaultConfig(IList<Entities.Component> components)
|
||||
{
|
||||
return new BalanceCfg(this, "Balance1", 3, 2400, System.IO.Ports.Parity.Even, 7,
|
||||
System.IO.Ports.StopBits.One, System.IO.Ports.Handshake.XOnXOff,
|
||||
200.0f, 20.0f, 180); // kg, kg, s
|
||||
return new BalanceCfg(this);
|
||||
}
|
||||
|
||||
public IComponentCfgCtrl CreateCfgCtrl()
|
||||
@@ -33,7 +31,7 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
|
||||
public IComponentCfg CmpntCfgFromCmpntEntity(Entities.Component component)
|
||||
{
|
||||
return MettlerToledo.BalanceCfg.CreateFromDbEntity(component, this);
|
||||
return ComponentCfgBase.CreateFromDbEntity(typeof(BalanceCfg), component, this);
|
||||
}
|
||||
|
||||
public void ResetStaticProperties() { BalanceDev.ResetStaticProperties(); }
|
||||
|
||||
@@ -16,9 +16,7 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
|
||||
public IComponentCfg DefaultConfig(IList<Entities.Component> components)
|
||||
{
|
||||
return new BalanceCfg(this, "Balance1", 3, 2400, System.IO.Ports.Parity.Even, 7,
|
||||
System.IO.Ports.StopBits.One, System.IO.Ports.Handshake.XOnXOff,
|
||||
200.0f, 20.0f, 180); // kg, kg, s
|
||||
return new BalanceCfg(this);
|
||||
}
|
||||
|
||||
public IComponentCfgCtrl CreateCfgCtrl()
|
||||
@@ -33,7 +31,7 @@ namespace TBF.BenchControl.MettlerToledo
|
||||
|
||||
public IComponentCfg CmpntCfgFromCmpntEntity(Entities.Component component)
|
||||
{
|
||||
return MettlerToledo.BalanceCfg.CreateFromDbEntity(component, this);
|
||||
return ComponentCfgBase.CreateFromDbEntity(typeof(BalanceCfg), component, this);
|
||||
}
|
||||
|
||||
public void ResetStaticProperties() { BalanceNewDev.ResetStaticProperties(); }
|
||||
|
||||
Reference in New Issue
Block a user