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:
@@ -7,13 +7,21 @@ using TBF.Resources;
|
||||
|
||||
namespace TBF.BenchControl.WaterMeter
|
||||
{
|
||||
public class ProcParams : IParamsProvider, IProcedureParams
|
||||
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
|
||||
{
|
||||
public string Producer; /// Hersteller
|
||||
public float Qn;
|
||||
public string ApprovalInfo; /// Zulassungszeichen
|
||||
public string MetrologicalClass; /// Metr. Klasse
|
||||
|
||||
public override void InitializeAll()
|
||||
{
|
||||
Producer = "";
|
||||
Qn = 2.5f;
|
||||
ApprovalInfo = "";
|
||||
MetrologicalClass = "A";
|
||||
}
|
||||
|
||||
string[] paramNames = new string[]
|
||||
{
|
||||
Strings.Producer,
|
||||
@@ -21,9 +29,10 @@ namespace TBF.BenchControl.WaterMeter
|
||||
Strings.Approval_info,
|
||||
Strings.Metrological_class,
|
||||
};
|
||||
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)
|
||||
{
|
||||
@@ -70,101 +79,38 @@ namespace TBF.BenchControl.WaterMeter
|
||||
return false;
|
||||
}
|
||||
|
||||
#region Boilerplate code
|
||||
|
||||
public int ParamsCount() { return paramNames.Length; }
|
||||
|
||||
public override string ToString()
|
||||
public override void UpdateProcedureParams(Entities.ComponentProcedure dbEntity)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < ParamsCount(); i++)
|
||||
{
|
||||
if (i != 0) sb.Append("; ");
|
||||
sb.Append(ParamName(i));
|
||||
sb.Append("=");
|
||||
sb.Append(ToString(i));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public Entities.ComponentProcedure ProcedureParamsEntity { get { return procParamsEntity; } }
|
||||
Entities.ComponentProcedure procParamsEntity;
|
||||
|
||||
[XmlIgnore]
|
||||
public string ComponentName { get { return componentName; } }
|
||||
string componentName;
|
||||
|
||||
[XmlIgnore]
|
||||
public Entities.Procedure Test { get { return test; } }
|
||||
Entities.Procedure test;
|
||||
|
||||
/// Parameterless constructor
|
||||
public ProcParams()
|
||||
{
|
||||
Producer = "";
|
||||
Qn = 2.5f;
|
||||
ApprovalInfo = "";
|
||||
MetrologicalClass = "A";
|
||||
}
|
||||
|
||||
public ProcParams(Entities.ComponentProcedure procParamsEntity, string componentName, Entities.Procedure test)
|
||||
: this()
|
||||
{
|
||||
this.procParamsEntity = procParamsEntity;
|
||||
this.componentName = componentName;
|
||||
this.test = test;
|
||||
}
|
||||
|
||||
public TBF.Entities.ComponentProcedure ToDbEntity(IComponent component, Entities.Procedure procedure)
|
||||
{
|
||||
using (var writer = new StringWriter())
|
||||
{
|
||||
/// Serialize this class with parameters
|
||||
(new XmlSerializer(GetType())).Serialize(writer, this);
|
||||
|
||||
/// Create and return the ComponentProcedure entity
|
||||
TBF.Entities.ComponentProcedure entity = new TBF.Entities.ComponentProcedure();
|
||||
entity.CmpntName = component.Cfg.Name;
|
||||
entity.Parameters = writer.ToString();
|
||||
entity.Procedure = procedure;
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateDbEntity()
|
||||
{
|
||||
using (var writer = new StringWriter())
|
||||
{
|
||||
/// Serialize this class and update the entity
|
||||
(new XmlSerializer(GetType())).Serialize(writer, this);
|
||||
procParamsEntity.Parameters = writer.ToString();
|
||||
procParamsEntity.CmpntName = componentName;
|
||||
procParamsEntity.Procedure = test;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static IParamsProvider GetProcedureParams(Entities.ComponentProcedure procParamsEntity)
|
||||
{
|
||||
if (procParamsEntity == null) return new ProcParams();
|
||||
|
||||
ProcParams procParams;
|
||||
if (dbEntity == null) return;
|
||||
try
|
||||
{
|
||||
procParams = (ProcParams)(new XmlSerializer(typeof(ProcParams)))
|
||||
.Deserialize(new StringReader(procParamsEntity.Parameters));
|
||||
ProcParams tmp = (ProcParams)(new XmlSerializer(typeof(ProcParams)))
|
||||
.Deserialize(new StringReader(dbEntity.Parameters));
|
||||
|
||||
procedureParamsEntity = dbEntity;
|
||||
componentName = dbEntity.CmpntName;
|
||||
procedure = dbEntity.Procedure;
|
||||
|
||||
Producer = tmp.Producer;
|
||||
Qn = tmp.Qn;
|
||||
ApprovalInfo = tmp.ApprovalInfo;
|
||||
MetrologicalClass = tmp.MetrologicalClass;
|
||||
}
|
||||
catch
|
||||
{
|
||||
procParams = new ProcParams();
|
||||
}
|
||||
procParams.procParamsEntity = procParamsEntity;
|
||||
procParams.componentName = procParamsEntity.CmpntName;
|
||||
procParams.test = procParamsEntity.Procedure;
|
||||
return procParams;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public ProcParams()
|
||||
{
|
||||
}
|
||||
|
||||
public ProcParams(Entities.ComponentProcedure procParamsEntity, string componentName, Entities.Procedure procedure)
|
||||
{
|
||||
this.procedureParamsEntity = procParamsEntity;
|
||||
this.componentName = componentName;
|
||||
this.procedure = procedure;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using log4net;
|
||||
using TBF.BenchControl;
|
||||
|
||||
namespace TBF.BenchControl.WaterMeter
|
||||
@@ -7,35 +8,24 @@ namespace TBF.BenchControl.WaterMeter
|
||||
/// <summary>
|
||||
/// This component = instance of this class is a placeholder for a combined main watermeter
|
||||
/// </summary>
|
||||
public class WaterMeter : ComponentBase, Generic.IComponent, GenericDevices.IWaterMeter
|
||||
public class WaterMeter : ComponentBase, GenericDevices.IWaterMeter
|
||||
{
|
||||
readonly WaterMeterCfg combinedMainCfg;
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(WaterMeter));
|
||||
public override string ToString() { return string.Format("WaterMeter({0})", Cfg.ToString(1)); }
|
||||
|
||||
public static void ResetStaticProperties() { }
|
||||
readonly WaterMeterCfg waterMeterCfg;
|
||||
|
||||
/// <summary>WaterMeter producer</summary>
|
||||
public string Producer
|
||||
{
|
||||
get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Producer : ""; }
|
||||
}
|
||||
public string Producer { get { return waterMeterCfg. ProcParams.Producer; } }
|
||||
|
||||
/// <summary>Nominal water flow in [m3/h]</summary>
|
||||
public float Qn
|
||||
{
|
||||
get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Qn : 0; }
|
||||
}
|
||||
public float Qn { get { return waterMeterCfg. ProcParams.Qn; } }
|
||||
|
||||
/// <summary>WaterMeter approval information or signature</summary>
|
||||
public string ApprovalInfo
|
||||
{
|
||||
get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).ApprovalInfo : ""; }
|
||||
}
|
||||
public string ApprovalInfo { get { return waterMeterCfg. ProcParams.ApprovalInfo; } }
|
||||
|
||||
/// <summary>Metrological class</summary>
|
||||
public string MetrologicalClass
|
||||
{
|
||||
get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).MetrologicalClass : ""; }
|
||||
}
|
||||
public string MetrologicalClass { get { return waterMeterCfg. ProcParams.MetrologicalClass; } }
|
||||
|
||||
/// Properties set by the Begin and the End form
|
||||
public string SerialNr
|
||||
@@ -62,8 +52,8 @@ namespace TBF.BenchControl.WaterMeter
|
||||
public WaterMeter(WaterMeterCfg cfg)
|
||||
: base(cfg)
|
||||
{
|
||||
if (cfg == null) throw new ArgumentNullException("cfg");
|
||||
this.combinedMainCfg = cfg;
|
||||
waterMeterCfg = cfg;
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,24 @@ namespace TBF.BenchControl.WaterMeter
|
||||
{
|
||||
public class WaterMeterCfg : ComponentCfgBase, Generic.IComponentCfg
|
||||
{
|
||||
/// Parameterless constructor
|
||||
public WaterMeterCfg()
|
||||
/// <summary> Procedure parameters </summary>
|
||||
[XmlIgnore]
|
||||
public ProcParams ProcParams;
|
||||
public override IParamsProvider GetProcedureParams() { return ProcParams; }
|
||||
public override IParamsProvider CreateProcedureParams(Entities.Procedure procedure)
|
||||
{
|
||||
ProcParams procParams = new ProcParams();
|
||||
procParams.UpdateProcedureParams(Name, procedure);
|
||||
return procParams;
|
||||
}
|
||||
|
||||
/// Private parameterless constructor invoked by all other (public) constructors
|
||||
WaterMeterCfg()
|
||||
{
|
||||
Name = "WaterMeter";
|
||||
ParentName = string.Empty;
|
||||
}
|
||||
ProcParams = new ProcParams();
|
||||
}
|
||||
|
||||
public WaterMeterCfg(IComponentFactory factory)
|
||||
: this()
|
||||
|
||||
@@ -6,13 +6,6 @@ namespace TBF.BenchControl.WaterMeter
|
||||
public class WaterMeterFactory : IComponentFactory
|
||||
{
|
||||
public string ClassName { get { return "WaterMeter"; } }
|
||||
public bool HasProcedureParams { get { return true; } }
|
||||
public bool HasTestParams { get { return false; } }
|
||||
public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; }
|
||||
public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams)
|
||||
{
|
||||
return ProcParams.GetProcedureParams(procedureParams);
|
||||
}
|
||||
|
||||
/// <summary>Max. number of components of this class in the system</summary>
|
||||
public int MaxCount { get { return int.MaxValue; } }
|
||||
|
||||
Reference in New Issue
Block a user