- generate available units using Units.IsQuantity(...) - use Quantity.MultiFunctionalVariables to populate supported units - centralize unit selection through Units.GetQuantity()
215 lines
5.6 KiB
C#
215 lines
5.6 KiB
C#
using Common;
|
|
using Config.Entities;
|
|
using log4net;
|
|
using SharedComponents;
|
|
|
|
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Xml.Serialization;
|
|
using TBF.Resources;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.RegisterReaders.StandingStartStop
|
|
{
|
|
public class RRProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(RRProcParams));
|
|
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(RRProcParams) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public double PulsesPerLtr;
|
|
public string Units;
|
|
|
|
public override void InitializeAll()
|
|
{
|
|
PulsesPerLtr = 1.0;
|
|
Units = "---";
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
//Strings.PulsesPerLtr,
|
|
Strings.PulsesPerUnit,
|
|
Strings.Units,
|
|
};
|
|
|
|
|
|
private void RefreshParamNames(int i)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
if (Units == "kg") paramNames[0] = Strings.PulsesPerKilogram;
|
|
else if (Units == "dm3") paramNames[0] = Strings.PulsesPerLtr;
|
|
else paramNames[0] = Strings.PulsesPerLtr;
|
|
}
|
|
}
|
|
|
|
public override string ParamName(int i) { return paramNames[i]; }
|
|
public override int ParamsCount() { return paramNames.Length; }
|
|
|
|
/*marek mareciinopublic ICollection<string> ParamValues(int ix)
|
|
{
|
|
var values = new List<string>();
|
|
switch (ix)
|
|
{
|
|
case 1:
|
|
for (PulsesTypeByQuantity m = 0; m < PulsesTypeByQuantity.Count; m++) values.Add(m.ToDescription());
|
|
return values;
|
|
default:
|
|
return null;
|
|
}
|
|
}*/
|
|
|
|
public ICollection<string> ParamValues(int ix)
|
|
{
|
|
switch (ix)
|
|
{
|
|
case 1:
|
|
{
|
|
var values = new List<string>
|
|
{
|
|
Unit.None.ToDescription()
|
|
};
|
|
|
|
for (Unit unit = (Unit)1; unit < Unit.Count; unit++)
|
|
{
|
|
if (Common.Units.IsQuantity(unit, Quantity.MultiFunctionalVariables))
|
|
{
|
|
values.Add(unit.ToDescription());
|
|
}
|
|
}
|
|
|
|
return values;
|
|
}
|
|
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public override string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return PulsesPerLtr.ToString();
|
|
case 1: return Units;
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
/// Retrieves parameters from UI controls
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: PulsesPerLtr = Utils.ParseUDouble(strValue); return CfgUpdateFlags.None;
|
|
case 1: Units = strValue; return CfgUpdateFlags.None;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
/// Verifies whether strings in UI controls represent valid parameters
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
|
|
double dummy;
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
if (Utils.TryParseUDouble(strValue, out dummy)) return true;
|
|
break;
|
|
case 1:
|
|
return true;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(RRProcParams prms)
|
|
{
|
|
prms.PulsesPerLtr = this.PulsesPerLtr;
|
|
prms.Units = this.Units;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
RRProcParams pars = new RRProcParams();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public override bool UpdateFromDbEntity(ComponentProcedure dbEntity)
|
|
{
|
|
if (dbEntity == null) return false;
|
|
try
|
|
{
|
|
RRProcParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as RRProcParams;
|
|
|
|
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 Procedure parameters deserialization. CmpntName='{0}', Procedure='{1}', Parameters='{2}', Exception: {3}",
|
|
dbEntity?.CmpntName,
|
|
dbEntity?.Procedure,
|
|
dbEntity?.Parameters,
|
|
ex
|
|
);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
public RRProcParams()
|
|
{
|
|
}
|
|
|
|
public RRProcParams(bool initialize)
|
|
{
|
|
if (initialize) InitializeAll();
|
|
}
|
|
|
|
public RRProcParams(ComponentProcedure procedureParamsEntity, string componentName, Procedure procedure)
|
|
{
|
|
this.procedureParamsEntity = procedureParamsEntity;
|
|
this.componentName = componentName;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Diagnostic logging MF
|
|
/// Activated by compilation condition: DIAG_ENDURANCE_xyz
|
|
/// </summary>
|
|
static class LiveLogDiag
|
|
{
|
|
[Conditional("DIAG_LOG_MASS1")]
|
|
public static void Log1(string format, params object[] args)
|
|
{
|
|
LiveLogCache.Instance.AddLog(string.Format(format, args));
|
|
}
|
|
}
|
|
}
|