Everything works OK after serious changes:

- all components, componentCfg-s and parameter providers use base classes
 - less boilerplate code, simpler access to test/procedure parameters from code
 - CreateTestParams(test), CreateProcedureParams(procedure) methods added
 - TestBenchSim class is made static, it is not inheritted by any device anymore
This commit is contained in:
Milan Hanajik
2015-01-02 12:51:27 +01:00
parent 752719bd62
commit 94de991bf6
126 changed files with 1117 additions and 1629 deletions
@@ -7,17 +7,24 @@ using TBF.Resources;
namespace TBF.BenchControl.Elde.PumpWithFM
{
public class FMPumpTestParams : IParamsProvider, ITestParams
public class FMPumpTestParams : TestParamsBase, IParamsProvider, ITestParams
{
public float Power; /// Target=terminal flow durning detection when increasing or decreasing the flow
public override void InitializeAll()
{
Power = 50.0f;
}
string[] paramNames = new string[]
{
Strings.PowerPct,
};
public string ParamName(int i) { return paramNames[i]; }
public override string ParamName(int i) { return paramNames[i]; }
public override int ParamsCount() { return paramNames.Length; }
public string ToString(int i)
public override string ToString(int i)
{
switch (i)
{
@@ -54,98 +61,35 @@ namespace TBF.BenchControl.Elde.PumpWithFM
return false;
}
#region Boilerplate code
public int ParamsCount() { return paramNames.Length; }
public override string ToString()
public override void UpdateTestParams(Entities.ComponentTest dbEntity)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ParamsCount(); i++)
if (dbEntity == null) return;
try
{
FMPumpTestParams tmp = (FMPumpTestParams)(new XmlSerializer(typeof(FMPumpTestParams)))
.Deserialize(new StringReader(dbEntity.Parameters));
testParamsEntity = dbEntity;
componentName = dbEntity.CmpntName;
test = dbEntity.Test;
Power = tmp.Power;
}
catch
{
if (i != 0) sb.Append("; ");
sb.Append(ParamName(i));
sb.Append("=");
sb.Append(ToString(i));
}
return sb.ToString();
}
[XmlIgnore]
public Entities.ComponentTest TestParamsEntity { get { return testParamsEntity; } }
Entities.ComponentTest testParamsEntity;
[XmlIgnore]
public string ComponentName { get { return componentName; } }
string componentName;
[XmlIgnore]
public Entities.Test Test { get { return test; } }
Entities.Test test;
/// Parameterless constructor
public FMPumpTestParams()
{
Power = 50.0f;
}
public FMPumpTestParams(Entities.ComponentTest testParamsEntity, string componentName, Entities.Test test)
: this()
{
this.testParamsEntity = testParamsEntity;
this.componentName = componentName;
this.test = test;
}
public TBF.Entities.ComponentTest ToDbEntity(IComponent component, Entities.Test test)
{
using (var writer = new StringWriter())
{
/// Serialize this class with parameters
(new XmlSerializer(GetType())).Serialize(writer, this);
/// Create and return the ComponentTest entity
TBF.Entities.ComponentTest entity = new TBF.Entities.ComponentTest();
entity.CmpntName = component.Cfg.Name;
entity.Parameters = writer.ToString();
entity.Test = test;
return entity;
}
}
public void UpdateDbEntity()
{
using (var writer = new StringWriter())
{
/// Serialize this class and update the entity
(new XmlSerializer(GetType())).Serialize(writer, this);
testParamsEntity.Parameters = writer.ToString();
testParamsEntity.CmpntName = componentName;
testParamsEntity.Test = test;
}
}
public static IParamsProvider GetTestParams(Entities.ComponentTest testParamsEntity)
{
if (testParamsEntity == null) return new FMPumpTestParams();
FMPumpTestParams testParams;
try
{
testParams = (FMPumpTestParams)(new XmlSerializer(typeof(FMPumpTestParams)))
.Deserialize(new StringReader(testParamsEntity.Parameters));
}
catch
{
testParams = new FMPumpTestParams();
}
testParams.testParamsEntity = testParamsEntity;
testParams.componentName = testParamsEntity.CmpntName;
testParams.test = testParamsEntity.Test;
return testParams;
}
#endregion
}
}
@@ -6,24 +6,14 @@ namespace TBF.BenchControl.Elde.PumpWithFM
{
public class Pump : ComponentBase, GenericDevices.IPumpFM, GenericDevices.IValve, IOperation
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(Pump));
public override string ToString()
{
return string.Format("Pump(name={0}, bit={1}, idx={2})", Name, bitPosition, FMIndex);
}
private static readonly ILog log = LogManager.GetLogger(typeof(Pump));
public override string ToString() { return string.Format("PumpWithFM({0})", Cfg.ToString(1)); }
public static void ResetStaticProperties() { }
public int Delay { get { return (Cfg as PumpCfg).Delay; } }
readonly PumpCfg pumpCfg;
public int Delay { get { return pumpCfg.Delay; } }
public ValveCategory Category { get { return ValveCategory.Feeding; } } /// Pump category is Feeding
public float Power { get { return (TestParams is FMPumpTestParams) ? (TestParams as FMPumpTestParams).Power : 0; } }
public float Power { get { return pumpCfg.TestParams.Power; } }
public GenericDevices.IValve CoupledTo { get { return null; } }
public bool InvertCouple { get { return false; } }
public int LagOpening { get { return 0; } }
@@ -45,14 +35,14 @@ namespace TBF.BenchControl.Elde.PumpWithFM
public Pump(PumpCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
if (cfg == null) throw new ArgumentNullException("cfg");
pumpCfg = cfg;
controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components);
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
this.bitPosition = cfg.BitPosition;
this.Mask = (((ulong)1) << bitPosition);
this.FMIndex = cfg.FMIndex;
bitPosition = pumpCfg.BitPosition;
Mask = (((ulong)1) << pumpCfg.BitPosition);
FMIndex = pumpCfg.FMIndex;
log.Debug(this.ToString());
}
@@ -10,14 +10,26 @@ namespace TBF.BenchControl.Elde.PumpWithFM
public int FMIndex;
public int Delay;
/// Parameterless constructor
public PumpCfg()
/// <summary> Test parameters </summary>
[XmlIgnore]
public FMPumpTestParams TestParams;
public override IParamsProvider GetTestParams() { return TestParams; }
public override IParamsProvider CreateTestParams(Entities.Test test)
{
FMPumpTestParams testParams = new FMPumpTestParams();
testParams.UpdateTestParams(Name, test);
return testParams;
}
/// Private parameterless constructor invoked by all other (public) constructors
PumpCfg()
{
Name = "Pump";
ParentName = "CB";
BitPosition = 0;
FMIndex = 0;
Delay = 1;
TestParams = new FMPumpTestParams();
}
public PumpCfg(IComponentFactory factory)
@@ -6,13 +6,6 @@ namespace TBF.BenchControl.Elde.PumpWithFM
public class PumpFactory : IComponentFactory
{
public string ClassName { get { return "PumpWithFM"; } }
public bool HasProcedureParams { get { return false; } }
public bool HasTestParams { get { return true; } }
public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; }
public IParamsProvider GetTestParams(Entities.ComponentTest testParams)
{
return FMPumpTestParams.GetTestParams(testParams);
}
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return int.MaxValue; } }