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:
+29
-89
@@ -7,17 +7,23 @@ using TBF.Resources;
|
||||
|
||||
namespace TBF.BenchControl.Elde.FixedStartRegisterReader
|
||||
{
|
||||
public class RRProcedureParams : IParamsProvider, IProcedureParams
|
||||
public class RRProcedureParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
|
||||
{
|
||||
public float PulsesPerLtr; /// Target low limit of the flow increase or decrease
|
||||
|
||||
public override void InitializeAll()
|
||||
{
|
||||
PulsesPerLtr = 1.0f;
|
||||
}
|
||||
|
||||
string[] paramNames = new string[]
|
||||
{
|
||||
Strings.PulsesPerLtr,
|
||||
};
|
||||
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)
|
||||
{
|
||||
@@ -25,14 +31,6 @@ namespace TBF.BenchControl.Elde.FixedStartRegisterReader
|
||||
default: return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parameterless constructor - sets default values of parameters.
|
||||
/// </summary>
|
||||
public RRProcedureParams()
|
||||
{
|
||||
PulsesPerLtr = 1.0f;
|
||||
}
|
||||
|
||||
/// Retrieves parameters from UI controls
|
||||
public void UpdateParam(int i, string strValue)
|
||||
@@ -64,92 +62,34 @@ namespace TBF.BenchControl.Elde.FixedStartRegisterReader
|
||||
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 procedureParamsEntity; } }
|
||||
Entities.ComponentProcedure procedureParamsEntity;
|
||||
|
||||
[XmlIgnore]
|
||||
public string ComponentName { get { return componentName; } }
|
||||
string componentName;
|
||||
|
||||
[XmlIgnore]
|
||||
public Entities.Procedure Procedure { get { return procedure; } }
|
||||
Entities.Procedure procedure;
|
||||
|
||||
public RRProcedureParams(Entities.ComponentProcedure procedureParamsEntity, string componentName, Entities.Procedure procedure)
|
||||
: this()
|
||||
{
|
||||
this.procedureParamsEntity = procedureParamsEntity;
|
||||
this.componentName = componentName;
|
||||
this.procedure = procedure;
|
||||
}
|
||||
|
||||
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);
|
||||
procedureParamsEntity.Parameters = writer.ToString();
|
||||
procedureParamsEntity.CmpntName = componentName;
|
||||
procedureParamsEntity.Procedure = procedure;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParamsEntity)
|
||||
{
|
||||
if (procedureParamsEntity == null) return new RRProcedureParams();
|
||||
|
||||
RRProcedureParams procedureParams;
|
||||
if (dbEntity == null) return;
|
||||
try
|
||||
{
|
||||
procedureParams = (RRProcedureParams)(new XmlSerializer(typeof(RRProcedureParams)))
|
||||
.Deserialize(new StringReader(procedureParamsEntity.Parameters));
|
||||
RRProcedureParams tmp = (RRProcedureParams)(new XmlSerializer(typeof(RRProcedureParams)))
|
||||
.Deserialize(new StringReader(dbEntity.Parameters));
|
||||
|
||||
procedureParamsEntity = dbEntity;
|
||||
componentName = dbEntity.CmpntName;
|
||||
procedure = dbEntity.Procedure;
|
||||
|
||||
PulsesPerLtr = tmp.PulsesPerLtr;
|
||||
}
|
||||
catch
|
||||
{
|
||||
procedureParams = new RRProcedureParams();
|
||||
}
|
||||
procedureParams.procedureParamsEntity = procedureParamsEntity;
|
||||
procedureParams.componentName = procedureParamsEntity.CmpntName;
|
||||
procedureParams.procedure = procedureParamsEntity.Procedure;
|
||||
return procedureParams;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public RRProcedureParams()
|
||||
{
|
||||
}
|
||||
|
||||
public RRProcedureParams(Entities.ComponentProcedure procedureParamsEntity, string componentName, Entities.Procedure procedure)
|
||||
{
|
||||
this.procedureParamsEntity = procedureParamsEntity;
|
||||
this.componentName = componentName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user