127 lines
3.8 KiB
C#
127 lines
3.8 KiB
C#
///
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Xml.Serialization;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.DataContainers.BackupAndSecurityOptions
|
|
{
|
|
/// <summary>
|
|
/// Holds backup and security options - 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 int MinPasswdLength;
|
|
public int PasswdExpirationPeriodDays; /// 0 = validity is not limited
|
|
|
|
/// Private parameterless constructor invoked by all other (public) constructors
|
|
ComponentCfg() {}
|
|
|
|
public ComponentCfg(IComponentFactory factory)
|
|
: this()
|
|
{
|
|
Factory = factory;
|
|
Name = "BackupAndSecurity";
|
|
ParentName = string.Empty;
|
|
InitializeAll();
|
|
}
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
public void InitializeAll()
|
|
{
|
|
MinPasswdLength = 6;
|
|
PasswdExpirationPeriodDays = 0;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"Minimum password length (characters)",
|
|
"Password expiration period (days)",
|
|
};
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
public ICollection<string> ParamValues(int i)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public string ToString(int i)
|
|
{
|
|
if (i == -1)
|
|
{
|
|
return string.Format("{0}: Min. password length = {1} characters, Password expiration period = {2} days", Name, MinPasswdLength, PasswdExpirationPeriodDays);
|
|
}
|
|
|
|
switch (i)
|
|
{
|
|
case 0: return MinPasswdLength.ToString();
|
|
case 1: return PasswdExpirationPeriodDays.ToString();;
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: MinPasswdLength = int.Parse(strValue); return CfgUpdateFlags.RestartRqrd;
|
|
case 1: PasswdExpirationPeriodDays = int.Parse(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 1:
|
|
/// Positive integers and zero are allowed
|
|
if (int.TryParse(strValue, out idummy) && (idummy >= 0)) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(ComponentCfg prms)
|
|
{
|
|
prms.MinPasswdLength = this.MinPasswdLength;
|
|
prms.PasswdExpirationPeriodDays = this.PasswdExpirationPeriodDays;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
ComponentCfg pars = new ComponentCfg();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true; /// =OK, do nothing
|
|
}
|
|
}
|
|
}
|