182 lines
5.7 KiB
C#
182 lines
5.7 KiB
C#
///
|
|
/// Copyright (c) 2018 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Xml.Serialization;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.Output.FileWriters.IperlLogger
|
|
{
|
|
public class WriterCfg : ComponentCfgBase, Generic.IComponentCfg, Config.Entities.IParamsProvider
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(WriterCfg) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public IComponentCfgCtrl GetControl() { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); }
|
|
|
|
public LogType LogType;
|
|
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()
|
|
{
|
|
LogType = LogType.Just_Q1Q2Q3;
|
|
DestinationPath = Program.HomeDir + "Logs\\";
|
|
YearFolders = true;
|
|
MonthFolders = true;
|
|
DayFolders = true;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"Log type",
|
|
"Destination path",
|
|
"Year folders",
|
|
"Month folders",
|
|
"Day folders",
|
|
};
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
public IList<string> ParamValues(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
IList<string> list1 = new List<string>();
|
|
for (LogType lt = 0; lt < LogType.Count; lt++) list1.Add(lt.ToString());
|
|
return list1;
|
|
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
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}: LogType={1}, Dest.={2}, Y={3}, M={4}, D={5}",
|
|
Name,
|
|
LogType,
|
|
DestinationPath,
|
|
YearFolders,
|
|
MonthFolders,
|
|
DayFolders);
|
|
}
|
|
|
|
switch (i)
|
|
{
|
|
case 0: return LogType.ToString();
|
|
case 1: return DestinationPath;
|
|
case 2: return YearFolders ? Strings.yes : Strings.no;
|
|
case 3: return MonthFolders ? Strings.yes : Strings.no;
|
|
case 4: return DayFolders ? Strings.yes : Strings.no;
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
for (LogType lt = 0; lt < LogType.Count; lt++)
|
|
{
|
|
if (lt.ToString() == strValue)
|
|
{
|
|
LogType = lt;
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
}
|
|
return CfgUpdateFlags.None;
|
|
|
|
case 1: DestinationPath = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
case 2: YearFolders = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd;
|
|
case 3: MonthFolders = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd;
|
|
case 4: 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:
|
|
for (LogType lt = 0; lt < LogType.Count; lt++)
|
|
{
|
|
if (lt.ToString() == strValue) return true;
|
|
}
|
|
break;
|
|
case 1:
|
|
return true;
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
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.LogType = this.LogType;
|
|
prms.DestinationPath = this.DestinationPath;
|
|
prms.YearFolders = this.YearFolders;
|
|
prms.MonthFolders = this.MonthFolders;
|
|
prms.DayFolders = this.DayFolders;
|
|
}
|
|
|
|
public Config.Entities.IParamsProvider Clone()
|
|
{
|
|
WriterCfg pars = new WriterCfg();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true; /// =OK, do nothing
|
|
}
|
|
}
|
|
}
|