320 lines
11 KiB
C#
320 lines
11 KiB
C#
///
|
|
/// Copyright (c) 2018 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Xml.Serialization;
|
|
using Common;
|
|
using Config;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.DataContainers.BenchInfo.Extended
|
|
{
|
|
/// <summary>
|
|
/// Holds information identifying the test bench - serializable configuration.
|
|
/// </summary>
|
|
public class ComponentCfg : ComponentCfgBase, Generic.IComponentCfg, IParamsProvider
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ComponentCfg) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities)
|
|
{
|
|
return new Configs.ParamsProvider.ComponentCfgCtrl(this, null);
|
|
}
|
|
|
|
///
|
|
/// Serialized parameters
|
|
///
|
|
public string TestBenchName;
|
|
public int TestBenchId;
|
|
public string Address1;
|
|
public string Address2;
|
|
public string Address3;
|
|
public string Address4;
|
|
public string Address5;
|
|
public string ApprovalId;
|
|
public string ApprovalDate;
|
|
public string ApprovedBy;
|
|
public RemoteDBUse RemoteDBUse;
|
|
public Unit VolumeUnit;
|
|
public Unit FlowUnit;
|
|
public Unit MassUnit;
|
|
public Unit TempUnit;
|
|
public Unit PressUnit;
|
|
public Unit LenghtUnit;
|
|
|
|
/// Private parameterless constructor invoked by all other (public) constructors
|
|
ComponentCfg() {}
|
|
|
|
public ComponentCfg(IComponentFactory factory)
|
|
: this()
|
|
{
|
|
Factory = factory;
|
|
Name = "BenchInfoEx";
|
|
ParentName = string.Empty;
|
|
InitializeAll();
|
|
}
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
public void InitializeAll()
|
|
{
|
|
TestBenchName = "1";
|
|
TestBenchId = 1;
|
|
|
|
Address1 = string.Empty;
|
|
Address2 = string.Empty;
|
|
Address3 = string.Empty;
|
|
Address4 = string.Empty;
|
|
Address5 = string.Empty;
|
|
|
|
ApprovalId = string.Empty;
|
|
ApprovalDate = string.Empty;
|
|
ApprovedBy = string.Empty;
|
|
|
|
RemoteDBUse = RemoteDBUse.LocalDBOnly;
|
|
|
|
VolumeUnit = Unit.l;
|
|
FlowUnit = Unit.m3ph;
|
|
MassUnit = Unit.kg;
|
|
TempUnit = Unit.C;
|
|
PressUnit = Unit.bar;
|
|
LenghtUnit = Unit.mm;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"Test bench name",
|
|
"Test bench ID",
|
|
"Address 1",
|
|
"Address 2",
|
|
"Address 3",
|
|
"Address 4",
|
|
"Address 5",
|
|
"Approval",
|
|
"Approval date",
|
|
"Approved by",
|
|
"Remote DB use",
|
|
"Preffered volume unit",
|
|
"Preffered flow unit",
|
|
"Preffered mass unit",
|
|
"Preffered temperature unit",
|
|
"Preffered pressure unit",
|
|
"Preffered lenght unit",
|
|
};
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
public ICollection<string> ParamValues(int i)
|
|
{
|
|
var list = new List<string>();
|
|
|
|
switch (i)
|
|
{
|
|
case 10:
|
|
for (RemoteDBUse rdbu = 0; rdbu < RemoteDBUse.Count; rdbu++)
|
|
list.Add(rdbu.ToDescription());
|
|
return list;
|
|
case 11:
|
|
for (Unit unit = 0; unit < Unit.Count; unit++)
|
|
if (Units.IsQuantity(unit, Quantity.Volume))
|
|
list.Add(unit.ToDescription());
|
|
return list;
|
|
case 12:
|
|
for (Unit unit = 0; unit < Unit.Count; unit++)
|
|
if (Units.IsQuantity(unit, Quantity.Flow))
|
|
list.Add(unit.ToDescription());
|
|
return list;
|
|
case 13:
|
|
for (Unit unit = 0; unit < Unit.Count; unit++)
|
|
if (Units.IsQuantity(unit, Quantity.Mass))
|
|
list.Add(unit.ToDescription());
|
|
return list;
|
|
case 14:
|
|
for (Unit unit = 0; unit < Unit.Count; unit++)
|
|
if (Units.IsQuantity(unit, Quantity.Temperature))
|
|
list.Add(unit.ToDescription());
|
|
return list;
|
|
case 15:
|
|
for (Unit unit = 0; unit < Unit.Count; unit++)
|
|
if (Units.IsQuantity(unit, Quantity.Pressure))
|
|
list.Add(unit.ToDescription());
|
|
return list;
|
|
case 16:
|
|
for (Unit unit = 0; unit < Unit.Count; unit++)
|
|
if (Units.IsQuantity(unit, Quantity.Length))
|
|
list.Add(unit.ToDescription());
|
|
return list;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return TestBenchName;
|
|
case 1: return TestBenchId.ToString();
|
|
case 2: return Address1;
|
|
case 3: return Address2;
|
|
case 4: return Address3;
|
|
case 5: return Address4;
|
|
case 6: return Address5;
|
|
case 7: return ApprovalId;
|
|
case 8: return ApprovalDate;
|
|
case 9: return ApprovedBy;
|
|
case 10: return RemoteDBUse.ToDescription();
|
|
case 11: return VolumeUnit.ToDescription();
|
|
case 12: return FlowUnit.ToDescription();
|
|
case 13: return MassUnit.ToDescription();
|
|
case 14: return TempUnit.ToDescription();
|
|
case 15: return PressUnit.ToDescription();
|
|
case 16: return LenghtUnit.ToDescription();
|
|
default:
|
|
return string.Format("{0}: Bench name={1}, Bench Id={2}, Procedures={3}", Name, TestBenchName, TestBenchId, RemoteDBUse.ToDescription());
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: TestBenchName = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
case 1: TestBenchId = int.Parse(strValue); return CfgUpdateFlags.RestartRqrd;
|
|
case 2: Address1 = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
case 3: Address2 = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
case 4: Address3 = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
case 5: Address4 = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
case 6: Address5 = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
case 7: ApprovalId = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
case 8: ApprovalDate = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
case 9: ApprovedBy = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
|
|
case 10:
|
|
for (RemoteDBUse rdbu = 0; rdbu < RemoteDBUse.Count; rdbu++)
|
|
{
|
|
if (strValue == rdbu.ToDescription())
|
|
{
|
|
if (RemoteDBUse != rdbu)
|
|
{
|
|
RemoteDBUse = rdbu;
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
else
|
|
{
|
|
return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
}
|
|
return CfgUpdateFlags.Error;
|
|
|
|
case 11:
|
|
VolumeUnit = Units.FromDescription(strValue);
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
|
|
case 12:
|
|
FlowUnit = Units.FromDescription(strValue);
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
|
|
case 13:
|
|
MassUnit = Units.FromDescription(strValue);
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
|
|
case 14:
|
|
TempUnit = Units.FromDescription(strValue);
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
|
|
case 15:
|
|
PressUnit = Units.FromDescription(strValue);
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
|
|
case 16:
|
|
LenghtUnit = Units.FromDescription(strValue);
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
|
|
default:
|
|
return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
int idummy;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
case 5:
|
|
case 6:
|
|
case 7:
|
|
case 8:
|
|
case 9:
|
|
return true;
|
|
case 1:
|
|
if (int.TryParse(strValue, out idummy) && (idummy >= 0)) return true;
|
|
break;
|
|
case 10:
|
|
for (RemoteDBUse rdbu = 0; rdbu < RemoteDBUse.Count; rdbu++)
|
|
{
|
|
if (strValue == rdbu.ToDescription()) return true;
|
|
}
|
|
return false;
|
|
case 11:
|
|
case 12:
|
|
case 13:
|
|
case 14:
|
|
case 15:
|
|
case 16:
|
|
if (ParamValues(i).Contains(strValue)) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(ComponentCfg prms)
|
|
{
|
|
prms.TestBenchName = this.TestBenchName;
|
|
prms.TestBenchId = this.TestBenchId;
|
|
prms.Address1 = this.Address1;
|
|
prms.Address2 = this.Address2;
|
|
prms.Address3 = this.Address3;
|
|
prms.Address4 = this.Address4;
|
|
prms.Address5 = this.Address5;
|
|
prms.ApprovalId = this.ApprovalId;
|
|
prms.ApprovalDate = this.ApprovalDate;
|
|
prms.ApprovedBy = this.ApprovedBy;
|
|
prms.RemoteDBUse = this.RemoteDBUse;
|
|
prms.VolumeUnit = this.VolumeUnit;
|
|
prms.FlowUnit = this.FlowUnit;
|
|
prms.MassUnit = this.MassUnit;
|
|
prms.TempUnit = this.TempUnit;
|
|
prms.PressUnit = this.PressUnit;
|
|
prms.LenghtUnit = this.LenghtUnit;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
ComponentCfg pars = new ComponentCfg();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true; /// =OK, do nothing
|
|
}
|
|
}
|
|
}
|