2019-09-14 08:44:20 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
using Config.Entities;
|
|
|
|
|
|
using TBF.BenchControl.Generic;
|
|
|
|
|
|
|
2019-09-18 07:09:00 +00:00
|
|
|
|
namespace TBF.BenchControl.DataContainers.Buoyancy
|
2019-09-14 08:44:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Holds backup and security options - serializable configuration.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class ComponentCfg : ComponentCfgBase, Generic.IComponentCfg, Config.Entities.IParamsProvider
|
|
|
|
|
|
{
|
|
|
|
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ComponentCfg) })[0];
|
|
|
|
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
|
|
|
|
|
|
|
|
public IComponentCfgCtrl GetControl() { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); }
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Serialized parameters
|
|
|
|
|
|
///
|
2019-09-18 07:09:00 +00:00
|
|
|
|
public double Buoyancy;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
|
|
|
|
|
|
/// Private parameterless constructor invoked by all other (public) constructors
|
|
|
|
|
|
ComponentCfg() {}
|
|
|
|
|
|
|
2019-09-18 07:09:00 +00:00
|
|
|
|
public ComponentCfg(string name, IComponentFactory factory)
|
2019-09-14 08:44:20 +00:00
|
|
|
|
: this()
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
Name = name;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
Factory = factory;
|
|
|
|
|
|
ParentName = string.Empty;
|
|
|
|
|
|
InitializeAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
|
|
|
|
|
|
|
|
public void InitializeAll()
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
Buoyancy = 1.00103;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string[] paramNames = new string[]
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
"Buoyancy",
|
2019-09-14 08:44:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
|
|
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
|
|
|
|
|
|
|
|
public IList<string> ParamValues(int i)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string ToString(int i)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (i == -1)
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
return string.Format("{0}: Buoyancy = {1}", Name, Buoyancy);
|
2019-09-14 08:44:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
case 0: return Buoyancy.ToString();
|
2019-09-14 08:44:20 +00:00
|
|
|
|
default: return string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (i)
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
case 0: Buoyancy = Utils.ParseUDouble(strValue); return CfgUpdateFlags.RestartRqrd;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
default: return CfgUpdateFlags.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
message = string.Empty;
|
2019-09-18 07:09:00 +00:00
|
|
|
|
double dummy;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
2019-09-18 07:09:00 +00:00
|
|
|
|
/// Real number between 0.8 and 1.2 expected
|
|
|
|
|
|
if (Utils.TryParseUDouble(strValue, out dummy) && (dummy >= 0.8) && (dummy <= 1.2)) return true;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
message = "Invalid index";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CopyContentTo(ComponentCfg prms)
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
prms.Buoyancy = this.Buoyancy;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Config.Entities.IParamsProvider Clone()
|
|
|
|
|
|
{
|
|
|
|
|
|
ComponentCfg pars = new ComponentCfg();
|
|
|
|
|
|
CopyContentTo(pars);
|
|
|
|
|
|
return pars;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true; /// =OK, do nothing
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|