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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user