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
@@ -2,18 +2,17 @@
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using log4net;
using TBF.BenchControl;
namespace TBF.BenchControl.ResultsPrinters.Basic
{
public class Printer : Generic.IComponent, IOperation, GenericDevices.IResultsPrinter
public class Printer : ComponentBase, IOperation, GenericDevices.IResultsPrinter
{
private static readonly ILog log = LogManager.GetLogger(typeof(Printer));
public override string ToString() { return string.Format("ResultsPrinters.Basic({0})", Cfg.ToString(1)); }
readonly PrinterCfg printerCfg;
public Generic.IComponentCfg Cfg { get { return printerCfg; } }
public static void ResetStaticProperties() { }
public string Name { get { return printerCfg.Name; } }
/// <summary>
/// Data to print
@@ -24,9 +23,10 @@ namespace TBF.BenchControl.ResultsPrinters.Basic
string title;
public Printer(PrinterCfg cfg)
: base(cfg)
{
if (cfg == null) throw new ArgumentNullException("cfg");
this.printerCfg = cfg;
printerCfg = cfg;
log.Debug(this.ToString());
}
/// <summary>
@@ -7,8 +7,8 @@ namespace TBF.BenchControl.ResultsPrinters.Basic
{
public class PrinterCfg : ComponentCfgBase, Generic.IComponentCfg
{
/// Parameterless constructor
public PrinterCfg()
/// Private parameterless constructor invoked by all other (public) constructors
PrinterCfg()
{
Name = "BasicResultsPrinter";
ParentName = string.Empty;
@@ -6,10 +6,6 @@ namespace TBF.BenchControl.ResultsPrinters.Basic
public class PrinterFactory : IComponentFactory
{
public string ClassName { get { return "BasicResultsPrinter"; } }
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; } }
@@ -2,15 +2,17 @@
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using log4net;
using TBF.BenchControl;
namespace TBF.BenchControl.ResultsPrinters.Munich
{
public class Printer : ComponentBase, Generic.IComponent, IOperation, GenericDevices.IResultsPrinter
public class Printer : ComponentBase, IOperation, GenericDevices.IResultsPrinter
{
readonly PrinterCfg printerCfg;
private static readonly ILog log = LogManager.GetLogger(typeof(Printer));
public override string ToString() { return string.Format("ResultsPrinters.Munich({0})", Cfg.ToString(1)); }
public static void ResetStaticProperties() { }
readonly PrinterCfg printerCfg;
/// <summary>
/// Data to print
@@ -19,32 +21,17 @@ namespace TBF.BenchControl.ResultsPrinters.Munich
public IList<GenericDevices.IWaterMeter> WaterMeters;
public IList<Entities.TestResult> Results;
public string Title;
public string Version { get { return printerCfg. ProcParams.Version; } }
public string Zaehlertyp { get { return printerCfg. ProcParams.Zaehlertyp; } }
public string Pruefvorlage { get { return printerCfg. ProcParams.Pruefvorlage; } }
public string Eichjahr { get { return printerCfg. ProcParams.Eichjahr; } }
public string Version
{
get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Version : ""; }
}
public string Zaehlertyp
{
get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Zaehlertyp : ""; }
}
public string Pruefvorlage
{
get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Pruefvorlage : ""; }
}
public string Eichjahr
{
get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Eichjahr : ""; }
}
public Printer(PrinterCfg cfg)
: base(cfg)
{
if (cfg == null) throw new ArgumentNullException("cfg");
this.printerCfg = cfg;
printerCfg = cfg;
log.Debug(this.ToString());
}
/// <summary>Events: ResultsPrinted</summary>
@@ -7,11 +7,23 @@ namespace TBF.BenchControl.ResultsPrinters.Munich
{
public class PrinterCfg : ComponentCfgBase, Generic.IComponentCfg
{
/// Parameterless constructor
public PrinterCfg()
/// <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
PrinterCfg()
{
Name = "PrintedProtocol";
ParentName = string.Empty;
ProcParams = new ProcParams();
}
public PrinterCfg(IComponentFactory factory)
@@ -6,13 +6,6 @@ namespace TBF.BenchControl.ResultsPrinters.Munich
public class PrinterFactory : IComponentFactory
{
public string ClassName { get { return "ResultsPrinter4Munich"; } }
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 1; } }
@@ -6,13 +6,21 @@ using TBF.Resources;
namespace TBF.BenchControl.ResultsPrinters.Munich
{
public class ProcParams : IParamsProvider, IProcedureParams
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
{
public string Version;
public string Zaehlertyp;
public string Pruefvorlage;
public string Eichjahr;
public override void InitializeAll()
{
Version = "4/13";
Zaehlertyp = "";
Pruefvorlage = "";
Eichjahr = "2014";
}
string[] paramNames = new string[]
{
Strings.Version,
@@ -20,9 +28,10 @@ namespace TBF.BenchControl.ResultsPrinters.Munich
"Prüfvorlage",
"Eichjahr",
};
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)
{
@@ -63,101 +72,38 @@ namespace TBF.BenchControl.ResultsPrinters.Munich
}
}
#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()
{
Version = "4/13";
Zaehlertyp = "";
Pruefvorlage = "";
Eichjahr = "2014";
}
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;
Version = tmp.Version;
Zaehlertyp = tmp.Zaehlertyp;
Pruefvorlage = tmp.Pruefvorlage;
Eichjahr = tmp.Eichjahr;
}
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;
}
}
}