156 lines
4.0 KiB
C#
156 lines
4.0 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Xml.Serialization;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.Elde.RegisterReader
|
|
{
|
|
public class RRProcedureParams : IParamsProvider, IProcedureParams
|
|
{
|
|
public float PulsesPerLtr; /// Target low limit of the flow increase or decrease
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
Strings.PulsesPerLtr,
|
|
};
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
|
|
public string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return PulsesPerLtr.ToString();
|
|
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)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: PulsesPerLtr = Utils.ParseUFloat(strValue); return;
|
|
default: return;
|
|
}
|
|
}
|
|
|
|
/// Verifies whether strings in UI controls represent valid parameters
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
|
|
float dummy;
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
if (Utils.TryParseUFloat(strValue, out dummy)) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
#region Boilerplate code
|
|
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
public override string ToString()
|
|
{
|
|
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;
|
|
try
|
|
{
|
|
procedureParams = (RRProcedureParams)(new XmlSerializer(typeof(RRProcedureParams)))
|
|
.Deserialize(new StringReader(procedureParamsEntity.Parameters));
|
|
}
|
|
catch
|
|
{
|
|
procedureParams = new RRProcedureParams();
|
|
}
|
|
procedureParams.procedureParamsEntity = procedureParamsEntity;
|
|
procedureParams.componentName = procedureParamsEntity.CmpntName;
|
|
procedureParams.procedure = procedureParamsEntity.Procedure;
|
|
return procedureParams;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|