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
@@ -6,9 +6,9 @@ namespace TBF.BenchControl.Elde.Valve
{
public class ValveCfg : ComponentCfgBase, IChildComponentCfg
{
public int OpenCloseTime; /// Delay for SetValvesOp operations
public int BitPosition; /// Bit-position
public ValveCategory Category; /// None, Feeding, Bench or Output
public int OpenCloseTime; /// Delay for SetValvesOp operations
public bool Inverted; /// The valve is inverted: 0=open, 1=closed
///
public string CoupledToName; /// Name of the coupled valve or null
@@ -20,65 +20,37 @@ namespace TBF.BenchControl.Elde.Valve
/// Parameterless constructor
public ValveCfg()
{
OpenCloseTime = 1; /// Defaut value
}
/// Constructor 1
public ValveCfg(IComponentFactory factory, string name, string parentName, int bitPosition, bool inverted, int openCloseTime,
ValveCategory category, string coupledToName, bool invertCouple, int lagOpening, int lagClosing)
: base(factory, name, parentName)
{
this.OpenCloseTime = openCloseTime;
this.BitPosition = bitPosition;
this.Category = category;
this.Inverted = inverted;
Name = "V";
ParentName = "CB";
BitPosition = 0;
Category = ValveCategory.None;
OpenCloseTime = 1;
Inverted = false;
CoupledToName = string.Empty;
InvertCouple = false;
LagOpening = 0;
LagClosing = 0;
}
this.CoupledToName = coupledToName;
this.InvertCouple = invertCouple;
this.LagOpening = lagOpening;
this.LagClosing = lagClosing;
}
/// Constructor 2 without CoupledTo valve
public ValveCfg(IComponentFactory factory, string name, string parentName, int bitPosition, bool inverted, int openCloseTime, ValveCategory category)
: this(factory, name, parentName, bitPosition, inverted, openCloseTime, category, null, false, 0, 0)
{
}
public IComponentCfg Clone()
{
return new ValveCfg(Factory, Name, ParentName, BitPosition, Inverted, OpenCloseTime, Category, CoupledToName, InvertCouple, LagOpening, LagClosing);
}
public ValveCfg(IComponentFactory factory)
: this()
{
this.Factory = factory;
}
public string ToString(int i)
{
return string.Format("bit={0}, inv.={1}, delay={2}s, cat.={3}, coupledTo={4}, inv.Couple={5}, lagOpen={6}s, lagClose={7}s",
return string.Format("Name={0}, Parent={1}, Bit={2}, Inv.={3}, Delay={4}s, Cat.={5}, CoupledTo={6}, Inv.Couple={7}, LagOpen={8}s, LagClose={9}s",
Name,
string.IsNullOrEmpty(ParentName) ? "-" : ParentName,
BitPosition,
(Inverted ? "yes" : "no"),
Inverted ? "yes" : "no",
OpenCloseTime,
Category,
(string.IsNullOrEmpty(CoupledToName) ? "---" : CoupledToName),
(InvertCouple ? "yes" : "no"),
string.IsNullOrEmpty(CoupledToName) ? "-" : CoupledToName,
InvertCouple ? "yes" : "no",
LagOpening,
LagClosing);
}
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))
{
ValveCfg config = (ValveCfg)(new XmlSerializer(typeof(ValveCfg))).Deserialize(reader);
config.InitCfgBaseFromEntity(component, factory);
return config;
}
}
}
}