tbf/TBF/Rig/Output/FileWriters/IperlLogger/WriterCfg.cs

152 lines
4.7 KiB
C#

///
/// Copyright (c) 2018-2022 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.Output.FileWriters.IperlLogger
{
public class WriterCfg : ComponentCfgBase, IComponentCfg, IParamsProvider
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(WriterCfg) })[0];
public override XmlSerializer GetSerializer() { return Serializer; }
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities) { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); }
public string DestinationPath; /// Directory path into which the logs will be saved
public bool YearFolders;
public bool MonthFolders;
public bool DayFolders;
/// Private parameterless constructor invoked by all other (public) constructors
WriterCfg() { }
public WriterCfg(string name, IComponentFactory factory)
: this()
{
Name = name;
Factory = factory;
ParentName = string.Empty;
InitializeAll();
}
public string ComponentName { get { return Name; } }
public void InitializeAll()
{
DestinationPath = Program.HomeDir + "Logs\\";
YearFolders = true;
MonthFolders = true;
DayFolders = true;
}
string[] paramNames = new string[]
{
"Destination path",
"Year folders",
"Month folders",
"Day folders",
};
public string ParamName(int i) { return paramNames[i]; }
public int ParamsCount() { return paramNames.Length; }
public ICollection<string> ParamValues(int i)
{
switch (i)
{
case 1:
case 2:
case 3:
IList<string> list2 = new List<string>();
list2.Add(Strings.yes);
list2.Add(Strings.no);
return list2;
default:
return null;
}
}
public string ToString(int i)
{
if (i == -1)
{
return string.Format("{0}: Dest.={1}, Y={2}, M={3}, D={4}",
Name,
DestinationPath,
YearFolders,
MonthFolders,
DayFolders);
}
switch (i)
{
case 0: return DestinationPath;
case 1: return YearFolders ? Strings.yes : Strings.no;
case 2: return MonthFolders ? Strings.yes : Strings.no;
case 3: return DayFolders ? Strings.yes : Strings.no;
default: return string.Empty;
}
}
public CfgUpdateFlags UpdateParam(int i, string strValue)
{
switch (i)
{
case 0: DestinationPath = strValue; return CfgUpdateFlags.RestartRqrd;
case 1: YearFolders = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 2: MonthFolders = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 3: DayFolders = (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:
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(WriterCfg prms)
{
prms.DestinationPath = this.DestinationPath;
prms.YearFolders = this.YearFolders;
prms.MonthFolders = this.MonthFolders;
prms.DayFolders = this.DayFolders;
}
public IParamsProvider Clone()
{
WriterCfg pars = new WriterCfg();
CopyContentTo(pars);
return pars;
}
public bool UpdateEmbeddedDbEntity()
{
return true; /// =OK, do nothing
}
}
}