430 lines
17 KiB
C#
430 lines
17 KiB
C#
using Common;
|
|
using Config.Entities;
|
|
using log4net;
|
|
///
|
|
/// Copyright (c) 2013-2023 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Xml.Serialization;
|
|
using TBF.Resources;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.WaterMeters.WaterMeter
|
|
{
|
|
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(ProcParams));
|
|
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
|
|
public string ProductName; /// 0 Znak fabryczny (PL)
|
|
public string Producer; /// 1 Producent (PL), Hersteller (D)
|
|
|
|
public float DN; /// 2
|
|
public float L; /// 3 stavebná dĺžka [mm]
|
|
public Mounting Mounting; /// 4
|
|
|
|
public FlowNames Qnames; /// 5 QnQtQmin, Q3Q2Q1 or QpQi
|
|
public double Qmax; /// 6 [m3/h]
|
|
public double Qn; /// 7 [m3/h]
|
|
public double Qt; /// 8 [m3/h]
|
|
public double Qmin; /// 9 [m3/h]
|
|
public double ErrLimHiQ; /// 10 [%]
|
|
public double ErrLimLoQ; /// 11 [%]
|
|
|
|
public string MetrologicalClass; /// 12 Metr. Klasse
|
|
public TemperatureClass TemperatureClass; /// 13
|
|
public PressureLossClass PressureLossClass; /// 14
|
|
public MaxAdmissiblePressure MaxAdmissiblePressure; /// 15
|
|
public FlowProfileSensitivityClass FlowProfileSensitivityClass; /// 16
|
|
|
|
public string ApprovalInfo; /// 17 Zulassungszeichen, WE (PL)
|
|
public string Certificate; /// 18
|
|
|
|
public double PulsesPerLtr; /// 19 Target low limit of the flow increase or decrease
|
|
|
|
public string Text1; /// 20
|
|
public string Text2; /// 21
|
|
public string Text3; /// 22
|
|
public string Text4; /// 23
|
|
public string Text5; /// 24
|
|
|
|
public Medium WaterTemp; /// 25 Woda: zimna / tepla (PL)
|
|
|
|
|
|
public override void InitializeAll()
|
|
{
|
|
ProductName = string.Empty;
|
|
Producer = string.Empty;
|
|
DN = 0;
|
|
L = 0;
|
|
Mounting = Mounting.NotSpecified;
|
|
Qnames = FlowNames.Q3Q2Q1;
|
|
Qmax = 3.125;
|
|
Qn = 2.5;
|
|
Qt = 0.005;
|
|
Qmin = 0.003125;
|
|
ErrLimHiQ = 2.0;
|
|
ErrLimLoQ = 5.0;
|
|
MetrologicalClass = "A";
|
|
TemperatureClass = TemperatureClass.NotSpecified;
|
|
PressureLossClass = PressureLossClass.NotSpecified;
|
|
MaxAdmissiblePressure = MaxAdmissiblePressure.NotSpecified;
|
|
FlowProfileSensitivityClass = FlowProfileSensitivityClass.NotSpecified;
|
|
ApprovalInfo = string.Empty;
|
|
Certificate = string.Empty;
|
|
PulsesPerLtr = 1.0;
|
|
Text1 = string.Empty;
|
|
Text2 = string.Empty;
|
|
Text3 = string.Empty;
|
|
Text4 = string.Empty;
|
|
Text5 = string.Empty;
|
|
WaterTemp = Medium.ColdWater;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
Strings.Product_name,
|
|
Strings.Producer,
|
|
"DN",
|
|
Strings.L,
|
|
Strings.Mounting,
|
|
"Q desig.",
|
|
"Q4",
|
|
"Q3",
|
|
"Q2",
|
|
"Q1",
|
|
"Err.lim. Hi Q",
|
|
"Err.lim. Lo Q",
|
|
Strings.Metrological_class,
|
|
Strings.Temperature_class,
|
|
Strings.Pressure_loss_class,
|
|
Strings.Maximum_admissible_pressure,
|
|
Strings.Flow_profile_sensitivity_class,
|
|
Strings.Approval_info,
|
|
Strings.Certificate,
|
|
Strings.PulsesPerLtr,
|
|
"Text1",
|
|
"Text2",
|
|
"Text3",
|
|
"Text4",
|
|
"Text5",
|
|
Strings.Water, /// "Woda"
|
|
};
|
|
public override string ParamName(int i)
|
|
{
|
|
switch (Qnames)
|
|
{
|
|
case FlowNames.Q3Q2Q1:
|
|
if (i == 6) return "Q4 [m3/h]";
|
|
if (i == 7) return "Q3 [m3/h]";
|
|
if (i == 8) return "Q2 [m3/h]";
|
|
if (i == 9) return "Q1 [m3/h]";
|
|
break;
|
|
case FlowNames.QnQtQmin:
|
|
if (i == 6) return "Qmax [m3/h]";
|
|
if (i == 7) return "Qn [m3/h]";
|
|
if (i == 8) return "Qt [m3/h]";
|
|
if (i == 9) return "Qmin [m3/h]";
|
|
break;
|
|
case FlowNames.QpQi:
|
|
if (i == 6) return "N/A";
|
|
if (i == 7) return "Qp [m3/h]";
|
|
if (i == 8) return "Qi [m3/h]";
|
|
if (i == 9) return "N/A";
|
|
break;
|
|
}
|
|
|
|
return paramNames[i];
|
|
}
|
|
|
|
public override int ParamsCount() { return paramNames.Length; }
|
|
|
|
public ICollection<string> ParamValues(int ix)
|
|
{
|
|
var values = new List<string>();
|
|
switch (ix)
|
|
{
|
|
case 4:
|
|
for (Mounting m = 0; m < Mounting.Count; m++) values.Add(m.ToDescription());
|
|
return values;
|
|
case 5:
|
|
for (FlowNames q = 0; q < FlowNames.Count; q++) values.Add(q.ToString());
|
|
return values;
|
|
case 13:
|
|
for (TemperatureClass tc = 0; tc < TemperatureClass.Count; tc++) values.Add(tc.ToDescription());
|
|
return values;
|
|
case 14:
|
|
for (PressureLossClass dp = 0; dp < PressureLossClass.Count; dp++) values.Add(dp.ToDescription());
|
|
return values;
|
|
case 15:
|
|
for (MaxAdmissiblePressure map = 0; map < MaxAdmissiblePressure.Count; map++) values.Add(map.ToDescription());
|
|
return values;
|
|
case 16:
|
|
for (FlowProfileSensitivityClass fps = 0; fps < FlowProfileSensitivityClass.Count; fps++) values.Add(fps.ToDescription());
|
|
return values;
|
|
case 25:
|
|
for (Medium m = 0; m < Medium.Count; m++) values.Add(m.ToDescription());
|
|
return values;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public override string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return ProductName;
|
|
case 1: return Producer;
|
|
case 2: return DN.ToString();
|
|
case 3: return L.ToString();
|
|
case 4: return Mounting.ToDescription();
|
|
case 5: return Qnames.ToString();
|
|
case 6: return Qmax.ToString();
|
|
case 7: return Qn.ToString();
|
|
case 8: return Qt.ToString();
|
|
case 9: return Qmin.ToString();
|
|
case 10: return ErrLimHiQ.ToString();
|
|
case 11: return ErrLimLoQ.ToString();
|
|
case 12: return MetrologicalClass;
|
|
case 13: return TemperatureClass.ToDescription();
|
|
case 14: return PressureLossClass.ToDescription();
|
|
case 15: return MaxAdmissiblePressure.ToDescription();
|
|
case 16: return FlowProfileSensitivityClass.ToDescription();
|
|
case 17: return ApprovalInfo;
|
|
case 18: return Certificate;
|
|
case 19: return PulsesPerLtr.ToString();
|
|
case 20: return Text1;
|
|
case 21: return Text2;
|
|
case 22: return Text3;
|
|
case 23: return Text4;
|
|
case 24: return Text5;
|
|
case 25: return (WaterTemp == Medium.HotWater) ? Medium.HotWater.ToDescription() : Medium.ColdWater.ToDescription(); /// "tepla" : "zimna";
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: ProductName = strValue; return CfgUpdateFlags.None;
|
|
case 1: Producer = strValue; return CfgUpdateFlags.None;
|
|
case 2: DN = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None;
|
|
case 3: L = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None;
|
|
case 4:
|
|
for (Mounting m = 0; m < Mounting.Count; m++)
|
|
{
|
|
if (m.ToDescription().Equals(strValue)) { Mounting = m; return CfgUpdateFlags.None; }
|
|
}
|
|
break;
|
|
case 5:
|
|
for (FlowNames q = 0; q < FlowNames.Count; q++)
|
|
{
|
|
if (q.ToDescription().Equals(strValue)) { Qnames = q; return CfgUpdateFlags.None; }
|
|
}
|
|
break;
|
|
case 6: Qmax = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None;
|
|
case 7: Qn = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None;
|
|
case 8: Qt = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None;
|
|
case 9: Qmin = Utils.ParseUFloat(strValue); return CfgUpdateFlags.None;
|
|
case 12: MetrologicalClass = strValue; return CfgUpdateFlags.None;
|
|
case 13:
|
|
for (TemperatureClass tc = 0; tc < TemperatureClass.Count; tc++)
|
|
{
|
|
if (tc.ToDescription().Equals(strValue)) { TemperatureClass = tc; return CfgUpdateFlags.None; }
|
|
}
|
|
break;
|
|
case 14:
|
|
for (PressureLossClass dp = 0; dp < PressureLossClass.Count; dp++)
|
|
{
|
|
if (dp.ToDescription().Equals(strValue)) { PressureLossClass = dp; return CfgUpdateFlags.None; }
|
|
}
|
|
break;
|
|
case 15:
|
|
for (MaxAdmissiblePressure map = 0; map < MaxAdmissiblePressure.Count; map++)
|
|
{
|
|
if (map.ToDescription().Equals(strValue)) { MaxAdmissiblePressure = map; return CfgUpdateFlags.None; }
|
|
}
|
|
break;
|
|
case 16:
|
|
for (FlowProfileSensitivityClass fps = 0; fps < FlowProfileSensitivityClass.Count; fps++)
|
|
{
|
|
if (fps.ToDescription().Equals(strValue)) { FlowProfileSensitivityClass = fps; return CfgUpdateFlags.None; }
|
|
}
|
|
break;
|
|
case 17: ApprovalInfo = strValue; return CfgUpdateFlags.None;
|
|
case 18: Certificate = strValue; return CfgUpdateFlags.None;
|
|
case 19: PulsesPerLtr = Utils.ParseUDouble(strValue); return CfgUpdateFlags.None;
|
|
case 20: Text1 = strValue; return CfgUpdateFlags.None;
|
|
case 21: Text2 = strValue; return CfgUpdateFlags.None;
|
|
case 22: Text3 = strValue; return CfgUpdateFlags.None;
|
|
case 23: Text4 = strValue; return CfgUpdateFlags.None;
|
|
case 24: Text5 = strValue; return CfgUpdateFlags.None;
|
|
case 25:
|
|
for (Medium m = 0; m < Medium.Count; m++)
|
|
{
|
|
if (m.ToDescription().Equals(strValue)) { WaterTemp = m; return CfgUpdateFlags.None; }
|
|
}
|
|
break;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
|
|
return CfgUpdateFlags.None;
|
|
}
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
|
|
double dummy;
|
|
switch (i)
|
|
{
|
|
case 0: /// ProductName
|
|
case 1: /// Producer
|
|
case 12: /// MetrologicalClass
|
|
case 17: /// ApprovalInfo
|
|
case 18: /// Certificate
|
|
case 20: /// Text1
|
|
case 21: /// Text2
|
|
case 22: /// Text3
|
|
case 23: /// Text4
|
|
case 24: /// Text5
|
|
return true;
|
|
case 5:
|
|
if (strValue.Equals(FlowNames.Q3Q2Q1.ToString()) ||
|
|
strValue.Equals(FlowNames.QnQtQmin.ToString()) ||
|
|
strValue.Equals(FlowNames.QpQi.ToString())) return true;
|
|
break;
|
|
case 2: /// DN
|
|
case 3: /// L
|
|
case 6: /// Qmax
|
|
case 7: /// Qn
|
|
case 8: /// Qt
|
|
case 9: /// Qmin
|
|
case 19: /// PulsesPerLtr
|
|
if (Utils.TryParseUDouble(strValue, out dummy)) return true;
|
|
break;
|
|
case 4:
|
|
for (Mounting tc = 0; tc < Mounting.Count; tc++) if (tc.ToDescription().Equals(strValue)) return true;
|
|
break;
|
|
case 13:
|
|
for (TemperatureClass tc = 0; tc < TemperatureClass.Count; tc++) if (tc.ToDescription().Equals(strValue)) return true;
|
|
break;
|
|
case 14:
|
|
for (PressureLossClass tc = 0; tc < PressureLossClass.Count; tc++) if (tc.ToDescription().Equals(strValue)) return true;
|
|
break;
|
|
case 15:
|
|
for (MaxAdmissiblePressure map = 0; map < MaxAdmissiblePressure.Count; map++) if (map.ToDescription().Equals(strValue)) return true;
|
|
break;
|
|
case 16:
|
|
for (FlowProfileSensitivityClass tc = 0; tc < FlowProfileSensitivityClass.Count; tc++) if (tc.ToDescription().Equals(strValue)) return true;
|
|
break;
|
|
case 25:
|
|
if (strValue.Equals(Medium.ColdWater.ToDescription()) || strValue.Equals(Medium.HotWater.ToDescription())) return true; /// "zimna", "tepla"
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(ProcParams prms)
|
|
{
|
|
prms.ProductName = this.ProductName;
|
|
prms.Producer = this.Producer;
|
|
prms.DN = this.DN;
|
|
prms.L = this.L;
|
|
prms.Mounting = this.Mounting;
|
|
prms.Qnames = this.Qnames;
|
|
prms.Qmax = this.Qmax;
|
|
prms.Qn = this.Qn;
|
|
prms.Qt = this.Qt;
|
|
prms.Qmin = this.Qmin;
|
|
prms.ErrLimHiQ = this.ErrLimHiQ;
|
|
prms.ErrLimLoQ = this.ErrLimLoQ;
|
|
prms.MetrologicalClass = this.MetrologicalClass;
|
|
prms.TemperatureClass = this.TemperatureClass;
|
|
prms.PressureLossClass = this.PressureLossClass;
|
|
prms.MaxAdmissiblePressure = this.MaxAdmissiblePressure;
|
|
prms.FlowProfileSensitivityClass = this.FlowProfileSensitivityClass;
|
|
prms.ApprovalInfo = this.ApprovalInfo;
|
|
prms.Certificate = this.Certificate;
|
|
prms.PulsesPerLtr = this.PulsesPerLtr;
|
|
prms.Text1 = this.Text1;
|
|
prms.Text2 = this.Text2;
|
|
prms.Text3 = this.Text3;
|
|
prms.Text4 = this.Text4;
|
|
prms.Text5 = this.Text5;
|
|
prms.WaterTemp = this.WaterTemp;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
ProcParams pars = new ProcParams();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public override bool UpdateFromDbEntity(ComponentProcedure dbEntity)
|
|
{
|
|
if (dbEntity == null) return false;
|
|
try
|
|
{
|
|
ProcParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as ProcParams;
|
|
|
|
procedureParamsEntity = dbEntity;
|
|
componentName = dbEntity.CmpntName;
|
|
procedure = dbEntity.Procedure;
|
|
|
|
if (tmp != null)
|
|
{
|
|
tmp.CopyContentTo(this);
|
|
return true;
|
|
}
|
|
else return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.DebugFormat(
|
|
"Error during RRProcParams deserialization. CmpntName='{0}', Procedure='{1}', Parameters='{2}', Exception: {3}",
|
|
dbEntity?.CmpntName,
|
|
dbEntity?.Procedure,
|
|
dbEntity?.Parameters,
|
|
ex
|
|
);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parameterless constructor initializes the parameters
|
|
/// </summary>
|
|
public ProcParams()
|
|
{
|
|
}
|
|
|
|
public ProcParams(bool initialize)
|
|
{
|
|
if (initialize) InitializeAll();
|
|
}
|
|
|
|
public ProcParams(ComponentProcedure procParamsEntity, string componentName, Procedure procedure)
|
|
{
|
|
this.procedureParamsEntity = procParamsEntity;
|
|
this.componentName = componentName;
|
|
this.procedure = procedure;
|
|
}
|
|
}
|
|
}
|