172 lines
5.4 KiB
C#
172 lines
5.4 KiB
C#
///
|
|
/// Copyright (c) 2020 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Xml.Serialization;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Resources;
|
|
using System.Collections.Generic;
|
|
|
|
namespace TBF.Rig.Output.EventTriggers.Iperl
|
|
{
|
|
/// <summary>
|
|
/// Serializable configuration of Output.EventTriggers.Standard component.
|
|
/// </summary>
|
|
public class TriggerCfg : ComponentCfgBase, Generic.IComponentCfg, Config.Entities.IParamsProvider
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TriggerCfg) })[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 EventSource;
|
|
public Culture Culture;
|
|
public bool EliminateSpaces;
|
|
public bool PrintCaption;
|
|
|
|
/// Private parameterless constructor invoked by all other (public) constructors
|
|
TriggerCfg() {}
|
|
|
|
public TriggerCfg(string name, IComponentFactory factory)
|
|
: this()
|
|
{
|
|
Name = name;
|
|
Factory = factory;
|
|
ParentName = string.Empty;
|
|
InitializeAll();
|
|
}
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
public void InitializeAll()
|
|
{
|
|
EventSource = "Výsledky iPERL";
|
|
Culture = Culture.EN;
|
|
EliminateSpaces = false;
|
|
PrintCaption = false;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"Event source",
|
|
"Culture",
|
|
"Eliminate spaces",
|
|
"Print caption",
|
|
};
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
public ICollection<string> ParamValues(int i)
|
|
{
|
|
IList<string> listOfValues = new List<string>();
|
|
if (i == 1)
|
|
{
|
|
for (Culture cu = 0; cu < Culture.Count; cu++) listOfValues.Add(cu.ToString());
|
|
return listOfValues;
|
|
}
|
|
else if (i == 2)
|
|
{
|
|
listOfValues.Add(Strings.yes);
|
|
listOfValues.Add(Strings.no);
|
|
return listOfValues;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case -1: return string.Format("Name={0}, FNameFmt={1}, NoSpaces={2}", Name, EventSource, EliminateSpaces);
|
|
case 0: return EventSource;
|
|
case 1: return Culture.ToString();
|
|
case 2: return EliminateSpaces ? Strings.yes : Strings.no;
|
|
case 3: return PrintCaption ? Strings.yes : Strings.no;
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: EventSource = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
case 1:
|
|
for (Culture cu = 0; cu < Culture.Count; cu++)
|
|
{
|
|
if (strValue == cu.ToString())
|
|
{
|
|
if (Culture != cu)
|
|
{
|
|
Culture = cu;
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
else
|
|
{
|
|
return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
}
|
|
return CfgUpdateFlags.Error;
|
|
case 2: EliminateSpaces = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd;
|
|
case 3: PrintCaption = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
|
|
switch (i)
|
|
{
|
|
case 0: return true;
|
|
case 1:
|
|
for (Culture cu = 0; cu < Culture.Count; cu++)
|
|
{
|
|
if (strValue == cu.ToString()) return true;
|
|
}
|
|
break;
|
|
case 2:
|
|
case 3:
|
|
if (strValue == Strings.yes || strValue == Strings.no) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(TriggerCfg prms)
|
|
{
|
|
prms.EventSource = this.EventSource;
|
|
prms.Culture = this.Culture;
|
|
prms.EliminateSpaces = this.EliminateSpaces;
|
|
prms.PrintCaption = this.PrintCaption;
|
|
}
|
|
|
|
public Config.Entities.IParamsProvider Clone()
|
|
{
|
|
TriggerCfg pars = new TriggerCfg();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true; /// =OK, do nothing
|
|
}
|
|
}
|
|
}
|