///
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using Common;
using Config.Entities;
using TBF.Rig.Generic;
using TBF.Resources;
namespace TBF.Rig.DataEntry.DataStream
{
///
/// Holds DataEntry.DataStream configuration.
///
public class EntryFormCfg : ComponentCfgBase, Generic.IChildComponentCfg, IParamsProvider
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(EntryFormCfg) })[0];
public override XmlSerializer GetSerializer() { return Serializer; }
public IComponentCfgCtrl GetControl(IList cmpntEntities)
{
IList parents = new List();
parents.Add("MefImport");
return new Configs.ParamsProvider.ComponentCfgCtrl(this, parents);
}
///
/// Serialized parameters
///
public bool ShowCycleEndForm;
/// Private parameterless constructor invoked by all other (public) constructors
EntryFormCfg() {}
public EntryFormCfg(IComponentFactory factory, string name)
: this()
{
Factory = factory;
Name = name;
ParentName = "MefImport";
InitializeAll();
}
public string ComponentName { get { return Name; } }
public void InitializeAll()
{
ShowCycleEndForm = false;
}
string[] paramNames = new string[]
{
"Show form at the end of cycle",
};
public string ParamName(int i) { return paramNames[i]; }
public int ParamsCount() { return paramNames.Length; }
public ICollection ParamValues(int i)
{
switch (i)
{
case 0:
return new List() { Strings.yes, Strings.no };
default:
return null;
}
}
public string ToString(int i)
{
switch (i)
{
case 0:
return ShowCycleEndForm ? Strings.yes : Strings.no;
default:
return string.Format("{0}: ShowEndForm={1}", Name, ShowCycleEndForm);
}
}
public CfgUpdateFlags UpdateParam(int i, string strValue)
{
switch (i)
{
case 0:
ShowCycleEndForm = (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:
if (ParamValues(i).Contains(strValue)) return true;
break;
default:
message = "Invalid index";
return false;
}
message = ParamName(i) + " is invalid";
return false;
}
void CopyContentTo(EntryFormCfg prms)
{
prms.ShowCycleEndForm = this.ShowCycleEndForm;
}
public IParamsProvider Clone()
{
EntryFormCfg pars = new EntryFormCfg();
CopyContentTo(pars);
return pars;
}
public bool UpdateEmbeddedDbEntity()
{
return true; /// =OK, do nothing
}
}
}