tbf/TestBenchFramework/BenchControl/Modbus/TankSelector/ProcParams.cs

142 lines
3.8 KiB
C#
Raw Normal View History

///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.Resources;
namespace TBF.BenchControl.Modbus.TankSelector
{
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
{
public float TempHotHeating; /// [°C] target temperature for hot water heating
public float TempHotCooling; /// [°C] target temperature for hot water cooling
public float TempWarmHeating; /// [°C] target temperature for warm water heating
public float TempWarmCooling; /// [°C] target temperature for warm water cooling
public float TempColdCooling; /// [°C] target temperature for cold water cooling
public override void InitializeAll()
{
TempHotHeating = 20.0f;
TempHotCooling = 20.0f;
TempWarmHeating = 20.0f;
TempWarmCooling = 20.0f;
TempColdCooling = 20.0f;
}
string[] paramNames = new string[]
{
Strings.T_hot_heating,
Strings.T_hot_cooling,
Strings.T_warm_heating,
Strings.T_warm_cooling,
Strings.T_cold_cooling,
};
public override string ParamName(int i) { return paramNames[i]; }
public override int ParamsCount() { return paramNames.Length; }
public override string ToString(int i)
{
switch (i)
{
case 0: return TempHotHeating.ToString();
case 1: return TempHotCooling.ToString();
case 2: return TempWarmHeating.ToString();
case 3: return TempWarmCooling.ToString();
case 4: return TempColdCooling.ToString();
default: return string.Empty;
}
}
public void UpdateParam(int i, string strValue)
{
switch (i)
{
case 0: TempHotHeating = Utils.ParseUFloat(strValue); return;
case 1: TempHotCooling = Utils.ParseUFloat(strValue); return;
case 2: TempWarmHeating = Utils.ParseUFloat(strValue); return;
case 3: TempWarmCooling = Utils.ParseUFloat(strValue); return;
case 4: TempColdCooling = Utils.ParseUFloat(strValue); return;
default: return;
}
}
public bool ValidateParam(int i, string strValue, out string message)
{
message = string.Empty;
float dummy;
switch (i)
{
case 0: /// T_hot_heating
case 1: /// T_hot_cooling
case 2: /// T_warm_heating
case 3: /// T_warm_cooling
case 4: /// T_cold_cooling
if (Utils.TryParseUFloat(strValue, out dummy)) return true;
break;
default:
message = "Invalid index";
return false;
}
message = ParamName(i) + " is invalid";
return false;
}
void CopyContentTo(ProcParams prms)
{
prms.TempHotHeating = this.TempHotHeating;
prms.TempHotCooling = this.TempHotCooling;
prms.TempWarmHeating = this.TempWarmHeating;
prms.TempWarmCooling = this.TempWarmCooling;
prms.TempColdCooling = this.TempColdCooling;
}
public IParamsProvider Clone()
{
ProcParams pars = new ProcParams();
CopyContentTo(pars);
return pars;
}
public override void UpdateProcedureParams(ComponentProcedure dbEntity)
{
if (dbEntity == null) return;
try
{
ProcParams tmp = (ProcParams)(new XmlSerializer(typeof(ProcParams)))
.Deserialize(new StringReader(dbEntity.Parameters));
procedureParamsEntity = dbEntity;
componentName = dbEntity.CmpntName;
procedure = dbEntity.Procedure;
tmp.CopyContentTo(this);
}
catch
{
}
}
/// <summary>
/// Parameterless constructor initializes the parameters
/// </summary>
public ProcParams()
{
}
public ProcParams(ComponentProcedure procParamsEntity, string componentName, Procedure procedure)
{
this.procedureParamsEntity = procParamsEntity;
this.componentName = componentName;
this.procedure = procedure;
}
}
}