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
@@ -1,22 +1,19 @@
using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl;
namespace TBF.BenchControl.TestMethods.CameraRoiDetection
{
public class RoiDetection : Generic.IComponent, GenericDevices.ITestMethod, ISequence
public class RoiDetection : ComponentBase, GenericDevices.ITestMethod, ISequence
{
readonly RoiDetectionCfg roiDetectionCfg;
public Generic.IComponentCfg Cfg { get { return roiDetectionCfg; } }
public static void ResetStaticProperties() { }
public string Name { get { return roiDetectionCfg.Name; } }
private static readonly ILog log = LogManager.GetLogger(typeof(RoiDetection));
public override string ToString() { return string.Format("TestMethods.CameraRoiDetection({0})", Cfg.ToString(1)); }
public RoiDetection(RoiDetectionCfg cfg)
: base(cfg)
{
if (cfg == null) throw new ArgumentNullException("cfg");
this.roiDetectionCfg = cfg;
log.Debug(this.ToString());
}
public IList<Event> Execute(Entities.Test test)
@@ -7,8 +7,8 @@ namespace TBF.BenchControl.TestMethods.CameraRoiDetection
{
public class RoiDetectionCfg : ComponentCfgBase, Generic.IComponentCfg
{
/// Parameterless constructor
public RoiDetectionCfg()
/// Private parameterless constructor invoked by all other (public) constructors
RoiDetectionCfg()
{
Name = "RoiDetection";
ParentName = string.Empty;
@@ -6,10 +6,6 @@ namespace TBF.BenchControl.TestMethods.CameraRoiDetection
public class RoiDetectionFactory : IComponentFactory
{
public string ClassName { get { return "ROI Detection"; } }
public bool HasProcedureParams { get { return false; } }
public bool HasTestParams { get { return false; } }
public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; }
public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }
@@ -1,22 +1,19 @@
using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl;
namespace TBF.BenchControl.TestMethods.CombinedMeters
{
public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence
public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence
{
readonly TestMethodCfg testMethodCfg;
public Generic.IComponentCfg Cfg { get { return testMethodCfg; } }
public static void ResetStaticProperties() { }
public string Name { get { return testMethodCfg.Name; } }
private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod));
public override string ToString() { return string.Format("TestMethods.CombinedMeters({0})", Cfg.ToString(1)); }
public TestMethod(TestMethodCfg cfg)
: base(cfg)
{
if (cfg == null) throw new ArgumentNullException("cfg");
this.testMethodCfg = cfg;
log.Debug(this.ToString());
}
public IList<Event> Execute(Entities.Test test)
@@ -7,8 +7,8 @@ namespace TBF.BenchControl.TestMethods.CombinedMeters
{
public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg
{
/// Parameterless constructor
public TestMethodCfg()
/// Private parameterless constructor invoked by all other (public) constructors
TestMethodCfg()
{
Name = "CombinedMeters";
ParentName = string.Empty;
@@ -7,11 +7,6 @@ namespace TBF.BenchControl.TestMethods.CombinedMeters
{
public string ClassName { get { return "CombinedMeters"; } }
public bool HasProcedureParams { get { return false; } }
public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; }
public bool HasTestParams { get { return false; } }
public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }
@@ -7,14 +7,23 @@ using TBF.Resources;
namespace TBF.BenchControl.TestMethods.CombinedWithDetection
{
public class CombinedWithDetTestParams : IParamsProvider, ITestParams
public class CombinedWithDetTestParams : TestParamsBase, IParamsProvider, ITestParams
{
public float TargetQ; /// Target=terminal flow durning detection when increasing or decreasing the flow
public float RelativeQfrom; /// Tested flow low range related to the detected flow
public float RelativeQto; /// Tested flow high range related to the detected flow
public float RateOfChange; /// Each step is calculated as (TargetQfrom - Qfrom) * RateOfChange, text form is displayed in % (*100)
public float DetectionThreshold;/// Drop of frequency for the detection, text form is displayed in % (*100)
public int SupressTrills;
public int SupressTrills;
public override void InitializeAll()
{
TargetQ = 3.0f;
RelativeQfrom = -0.4f;
RelativeQto = -0.2f;
RateOfChange = 0.05f;
DetectionThreshold = 0.25f;
}
string[] paramNames = new string[]
{
@@ -25,9 +34,10 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection
Strings.DetectionThresholdPct,
Strings.SupressWMTrills,
};
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)
{
@@ -84,102 +94,43 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection
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
{
CombinedWithDetTestParams tmp = (CombinedWithDetTestParams)(new XmlSerializer(typeof(CombinedWithDetTestParams)))
.Deserialize(new StringReader(dbEntity.Parameters));
testParamsEntity = dbEntity;
componentName = dbEntity.CmpntName;
test = dbEntity.Test;
TargetQ = tmp.TargetQ;
RelativeQfrom = tmp.RelativeQfrom;
RelativeQto = tmp.RelativeQto;
RateOfChange = tmp.RateOfChange;
DetectionThreshold = tmp.DetectionThreshold;
SupressTrills = tmp.SupressTrills;
}
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
/// <summary>
/// Parameterless constructor initializes the parameters
/// </summary>
public CombinedWithDetTestParams()
{
TargetQ = 3.0f;
RelativeQfrom = -0.4f;
RelativeQto = -0.2f;
RateOfChange = 0.05f;
DetectionThreshold = 0.25f;
}
public CombinedWithDetTestParams(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 CombinedWithDetTestParams();
CombinedWithDetTestParams testParams;
try
{
testParams = (CombinedWithDetTestParams)(new XmlSerializer(typeof(CombinedWithDetTestParams)))
.Deserialize(new StringReader(testParamsEntity.Parameters));
}
catch
{
testParams = new CombinedWithDetTestParams();
}
testParams.testParamsEntity = testParamsEntity;
testParams.componentName = testParamsEntity.CmpntName;
testParams.test = testParamsEntity.Test;
return testParams;
}
#endregion
}
}
@@ -1,29 +1,27 @@
using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.TestMethods.CombinedWithDetection
{
public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence
public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence
{
private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod));
public override string ToString() { return string.Format("TestMethods.CombinedWithDetection({0})", Cfg.ToString(1)); }
readonly TestMethodCfg testMethodCfg;
public Generic.IComponentCfg Cfg { get { return testMethodCfg; } }
public static void ResetStaticProperties() { }
public string Name { get { return testMethodCfg.Name; } }
public TestMethod(TestMethodCfg cfg)
: base(cfg)
{
if (cfg == null) throw new ArgumentNullException("cfg");
this.testMethodCfg = cfg;
testMethodCfg = cfg;
log.Debug(this.ToString());
}
public IList<Event> Execute(Entities.Test test)
{
IParamsProvider testParams = BenchControl.TbfComponents.GetTestParams(this, test);
return (new CombinedWithDetectionSeq()).Execute(test, testParams as CombinedWithDetTestParams);
return (new CombinedWithDetectionSeq()).Execute(test, testMethodCfg.TestParams);
}
}
}
@@ -7,11 +7,23 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection
{
public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg
{
/// Parameterless constructor
public TestMethodCfg()
/// <summary> Test parameters </summary>
[XmlIgnore]
public CombinedWithDetTestParams TestParams;
public override IParamsProvider GetTestParams() { return TestParams; }
public override IParamsProvider CreateTestParams(Entities.Test test)
{
CombinedWithDetTestParams testParams = new CombinedWithDetTestParams();
testParams.UpdateTestParams(Name, test);
return testParams;
}
/// Private parameterless constructor invoked by all other (public) constructors
TestMethodCfg()
{
Name = "CombinedWithDetection";
ParentName = string.Empty;
TestParams = new CombinedWithDetTestParams();
}
public TestMethodCfg(IComponentFactory factory)
@@ -31,15 +31,6 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection
return ComponentCfgBase.CreateFromDbEntity(typeof(TestMethodCfg), component, this);
}
public bool HasProcedureParams { get { return false; } }
public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; }
public bool HasTestParams { get { return true; } }
public IParamsProvider GetTestParams(Entities.ComponentTest testParams)
{
return CombinedWithDetTestParams.GetTestParams(testParams);
}
public void ResetStaticProperties() { TestMethod.ResetStaticProperties(); }
}
}
@@ -1,22 +1,19 @@
using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl;
namespace TBF.BenchControl.TestMethods.FixedStartMassCollection
{
public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence
public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence
{
readonly TestMethodCfg testMethodCfg;
public Generic.IComponentCfg Cfg { get { return testMethodCfg; } }
public static void ResetStaticProperties() { }
public string Name { get { return testMethodCfg.Name; } }
private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod));
public override string ToString() { return string.Format("TestMethods.FixedStartMassCollection({0})", Cfg.ToString(1)); }
public TestMethod(TestMethodCfg cfg)
{
if (cfg == null) throw new ArgumentNullException("cfg");
this.testMethodCfg = cfg;
: base(cfg)
{
log.Debug(this.ToString());
}
public IList<Event> Execute(Entities.Test test)
@@ -7,8 +7,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection
{
public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg
{
/// Parameterless constructor
public TestMethodCfg()
/// Private parameterless constructor invoked by all other (public) constructors
TestMethodCfg()
{
Name = "FixedStartMassCollection";
ParentName = string.Empty;
@@ -6,10 +6,6 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection
public class TestMethodFactory : IComponentFactory
{
public string ClassName { get { return "FixedStartMassCollection"; } }
public bool HasProcedureParams { get { return false; } }
public bool HasTestParams { get { return false; } }
public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; }
public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }
@@ -1,22 +1,19 @@
using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl;
namespace TBF.BenchControl.TestMethods.FlyingStart
{
public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence
public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence
{
readonly TestMethodCfg testMethodCfg;
public Generic.IComponentCfg Cfg { get { return testMethodCfg; } }
public static void ResetStaticProperties() { }
public string Name { get { return testMethodCfg.Name; } }
private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod));
public override string ToString() { return string.Format("TestMethods.FlyingStart({0})", Cfg.ToString(1)); }
public TestMethod(TestMethodCfg cfg)
{
if (cfg == null) throw new ArgumentNullException("cfg");
this.testMethodCfg = cfg;
: base(cfg)
{
log.Debug(this.ToString());
}
public IList<Event> Execute(Entities.Test test)
@@ -7,8 +7,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStart
{
public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg
{
/// Parameterless constructor
public TestMethodCfg()
/// Private parameterless constructor invoked by all other (public) constructors
TestMethodCfg()
{
Name = "FlyingStart";
ParentName = string.Empty;
@@ -6,10 +6,6 @@ namespace TBF.BenchControl.TestMethods.FlyingStart
public class TestMethodFactory : IComponentFactory
{
public string ClassName { get { return "FlyingStart"; } }
public bool HasProcedureParams { get { return false; } }
public bool HasTestParams { get { return false; } }
public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; }
public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }
@@ -1,22 +1,19 @@
using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl;
namespace TBF.BenchControl.TestMethods.FlyingStartCollectionMethod
{
public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence
public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence
{
readonly TestMethodCfg testMethodCfg;
public Generic.IComponentCfg Cfg { get { return testMethodCfg; } }
public static void ResetStaticProperties() { }
public string Name { get { return testMethodCfg.Name; } }
private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod));
public override string ToString() { return string.Format("TestMethods.FlyingStartCollectionMethod({0})", Cfg.ToString(1)); }
public TestMethod(TestMethodCfg cfg)
{
if (cfg == null) throw new ArgumentNullException("cfg");
this.testMethodCfg = cfg;
: base(cfg)
{
log.Debug(this.ToString());
}
public IList<Event> Execute(Entities.Test test)
@@ -7,9 +7,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartCollectionMethod
{
public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg
{
/// Parameterless constructor
/// Parameterless constructor
public TestMethodCfg()
/// Private parameterless constructor invoked by all other (public) constructors
TestMethodCfg()
{
Name = "FlyingStartCollection";
ParentName = string.Empty;
@@ -6,10 +6,6 @@ namespace TBF.BenchControl.TestMethods.FlyingStartCollectionMethod
public class TestMethodFactory : IComponentFactory
{
public string ClassName { get { return "Flying-Start-Collection"; } }
public bool HasProcedureParams { get { return false; } }
public bool HasTestParams { get { return false; } }
public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; }
public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }
@@ -1,22 +1,19 @@
using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl;
namespace TBF.BenchControl.TestMethods.ReferenceFlowmeterCalibration
{
public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence
public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence
{
readonly TestMethodCfg testMethodCfg;
public Generic.IComponentCfg Cfg { get { return testMethodCfg; } }
public static void ResetStaticProperties() { }
public string Name { get { return testMethodCfg.Name; } }
private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod));
public override string ToString() { return string.Format("TestMethods.ReferenceFlowmeterCalibration({0})", Cfg.ToString(1)); }
public TestMethod(TestMethodCfg cfg)
{
if (cfg == null) throw new ArgumentNullException("cfg");
this.testMethodCfg = cfg;
: base(cfg)
{
log.Debug(this.ToString());
}
public IList<Event> Execute(Entities.Test test)
@@ -7,8 +7,8 @@ namespace TBF.BenchControl.TestMethods.ReferenceFlowmeterCalibration
{
public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg
{
/// Parameterless constructor
public TestMethodCfg()
/// Private parameterless constructor invoked by all other (public) constructors
TestMethodCfg()
{
Name = "ReferenceFlowmeterCalibration";
ParentName = string.Empty;
@@ -6,10 +6,6 @@ namespace TBF.BenchControl.TestMethods.ReferenceFlowmeterCalibration
public class TestMethodFactory : IComponentFactory
{
public string ClassName { get { return "ReferenceFlowmeterCalibration"; } }
public bool HasProcedureParams { get { return false; } }
public bool HasTestParams { get { return false; } }
public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; }
public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }