diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - BackupPackageManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - BackupPackageManager.cs index 7ea2f97..743b8c4 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - BackupPackageManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - BackupPackageManager.cs @@ -79,6 +79,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS var vars = new Dictionary(); vars.Add("PACKAGENAME", bp.Xml_PackageName); vars.Add("PACKAGETS", packagets); + vars.Add("PACKAGEKEY", bp.Xml_Key); var destinationfolder = Path.GetDirectoryName(bp.Xml_PackageFilePath); if (!Path.IsPathRooted(destinationfolder)) { destinationfolder = Path.Combine(Directory.GetCurrentDirectory(), destinationfolder); } @@ -87,8 +88,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS var destinationfilename = Path.GetFileNameWithoutExtension(bp.Xml_PackageFilePath); //string tempfolderpath = Tools.GetTemporaryFoldername(destinationfolder); - destinationfilename = StringConstructor.ResolveConstructor(vars, destinationfilename, "{}@@"); - destinationfolder = StringConstructor.ResolveConstructor(vars, destinationfolder, "{}@@"); + destinationfilename = StringConstructor.ResolveConstructorR(vars, destinationfilename, "{}@@"); + destinationfolder = StringConstructor.ResolveConstructorR(vars, destinationfolder, "{}@@"); var temprootfolder=string.IsNullOrEmpty(bp.Xml_TempDirectoryPath) ? destinationfolder : bp.Xml_TempDirectoryPath; string tempfolderpath = Path.Combine(temprootfolder, destinationfilename); @@ -197,7 +198,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS var destinationext = Path.GetExtension(destinationbackupfile); if (string.IsNullOrWhiteSpace(destinationext)) { destinationext = ".zip"; } destinationbackupfile = Path.Combine(destinationfolderpath, destinationfile+destinationext); - destinationbackupfile = VRH.Common.StringConstructor.ResolveConstructor(vars, destinationbackupfile, "{}@@"); + destinationbackupfile = VRH.Common.StringConstructor.ResolveConstructorR(vars, destinationbackupfile, "{}@@"); if (File.Exists(destinationbackupfile)) { File.Delete(destinationbackupfile); } @@ -227,7 +228,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS destinationfilename = destinationfilename??Path.GetFileNameWithoutExtension(sourcedirectorypath); string package___filepath = Path.Combine(destinationfolder, destinationfilename); - package___filepath=VRH.Common.StringConstructor.ResolveConstructor(vars, package___filepath, "{}@@"); + package___filepath=VRH.Common.StringConstructor.ResolveConstructorR(vars, package___filepath, "{}@@"); string packageEXEfilepath = package___filepath + ".exe"; string packageZIPfilepath = package___filepath + ".zip"; @@ -331,16 +332,24 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS #region BackupPackageManagerXmlProcessor class public class BackupPackageManagerXmlProcessor : XmlParser { - private List _backuppackagelist; + private List _backuppackagelist= new List(); #region constructor public BackupPackageManagerXmlProcessor(string xmlcs, string basefolder, string lcid) : base(xmlcs, basefolder, lcid, null) { - _backuppackagelist = new List(); - var tmpdirpath = GetValue(nameof(BackupPackage.XmlStructure.Attributes.TempDirectoryPath), GetRootElement(),""); + string tmpdirpath="", packagefilepath="", packagename="", createexe=""; + var ca = GetXElement(nameof(BackupPackage.XmlStructure.CommonAttributes)); + if (ca != null) + { + tmpdirpath = GetValue(nameof(BackupPackage.XmlStructure.CommonAttributes.Attributes.TempDirectoryPath), ca, ""); + packagefilepath = GetValue(nameof(BackupPackage.XmlStructure.CommonAttributes.Attributes.PackageFilePath), ca, ""); + packagename = GetValue(nameof(BackupPackage.XmlStructure.CommonAttributes.Attributes.PackageName), ca, ""); + createexe = GetValue(nameof(BackupPackage.XmlStructure.CommonAttributes.Attributes.CreateExe), ca, ""); + } + var bpxmllist = GetAllXElements(nameof(BackupPackage.XmlStructure.BackupPackage)); if (bpxmllist != null && bpxmllist.Any()) { - foreach (var bpxml in bpxmllist) { var bp = new BackupPackage(bpxml, tmpdirpath); if (bp.Valid) { _backuppackagelist.Add(bp); } } + foreach (var bpxml in bpxmllist) { var bp = new BackupPackage(bpxml, tmpdirpath, packagefilepath, packagename, createexe); if (bp.Valid) { _backuppackagelist.Add(bp); } } } } #endregion constructor @@ -373,24 +382,31 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS #endregion basic constructor #region xml constructor - public BackupPackage(XElement backupackagexml,string tmpdirectorypath) + public BackupPackage(XElement backupackagexml,string commontmpdirectorypath,string commonpackagefilepath=null,string commonpackagename=null,string commoncreateexe=null) { Valid = true; string ATTRIBUTEMANDATORY = nameof(XmlStructure.BackupPackage) + " attribute is mandatory! Name: {0}"; - Xml_Key = GetValue(nameof(XmlStructure.BackupPackage.Attributes.Key), backupackagexml, XmlStructure.BackupPackage.Attributes.Key.Values.DEFAULT); + Xml_PackageName = backupackagexml.Attribute(XName.Get(nameof(XmlStructure.BackupPackage.Attributes.Name)))?.Value; + if (string.IsNullOrWhiteSpace(Xml_PackageName)) { Xml_PackageName=commonpackagename; } if (string.IsNullOrWhiteSpace(Xml_PackageName)) { throw new ApplicationException(string.Format(ATTRIBUTEMANDATORY, nameof(XmlStructure.BackupPackage.Attributes.Name))); } - Xml_Description = GetValue(nameof(XmlStructure.BackupPackage.Attributes.Description), backupackagexml, Xml_PackageName); + Xml_PackageFilePath = GetValue(nameof(XmlStructure.BackupPackage.Attributes.PackageFilePath), backupackagexml, ""); + if (string.IsNullOrWhiteSpace(Xml_PackageFilePath)) { Xml_PackageFilePath= commonpackagefilepath; } if (string.IsNullOrWhiteSpace(Xml_PackageFilePath)) { throw new ApplicationException(string.Format(ATTRIBUTEMANDATORY, XmlStructure.BackupPackage.Attributes.PackageFilePath.Values.DEFAULT)); } - Xml_TempDirectoryPath = tmpdirectorypath; - Xml_SourceIncludeFilenameMaskList = GetValue(nameof(XmlStructure.BackupPackage.Attributes.IncludeFilenameMaskList), backupackagexml, XmlStructure.BackupPackage.Attributes.IncludeFilenameMaskList.Values.DEFAULT); + Xml_TempDirectoryPath =GetValue(nameof(XmlStructure.BackupPackage.Attributes.TempDirectoryPath), backupackagexml, ""); + if (string.IsNullOrWhiteSpace(Xml_TempDirectoryPath)) { Xml_TempDirectoryPath= commontmpdirectorypath; } string XmlCreateExestring = GetValue(nameof(XmlStructure.BackupPackage.Attributes.CreateExe), backupackagexml, XmlStructure.BackupPackage.Attributes.CreateExe.Values.DEFAULT.ToString()); + if (string.IsNullOrWhiteSpace(XmlCreateExestring)) { XmlCreateExestring = commoncreateexe; } if (string.IsNullOrWhiteSpace(XmlCreateExestring)) { XmlCreateExestring = XmlStructure.BackupPackage.Attributes.CreateExe.Values.DEFAULT.ToString(); } Xml_CreateExe = bool.Parse(XmlCreateExestring); + Xml_Key = GetValue(nameof(XmlStructure.BackupPackage.Attributes.Key), backupackagexml, XmlStructure.BackupPackage.Attributes.Key.Values.DEFAULT); + Xml_Description = GetValue(nameof(XmlStructure.BackupPackage.Attributes.Description), backupackagexml, Xml_PackageName); + Xml_SourceIncludeFilenameMaskList = GetValue(nameof(XmlStructure.BackupPackage.Attributes.IncludeFilenameMaskList), backupackagexml, XmlStructure.BackupPackage.Attributes.IncludeFilenameMaskList.Values.DEFAULT); + Xml_BackupFolderList = new List(); //var conditionxmlList = GetAllXElements(foldertocleanxml, nameof(XmlStructure.FolderToClean.Conditions), nameof(XmlStructure.FolderToClean.Conditions.Condition)); var backupfolderxmlList = backupackagexml.Elements(XName.Get(nameof(XmlStructure.BackupPackage.BackupFolder))); @@ -426,9 +442,16 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS #region XmlStructure public static class XmlStructure { - public static class Attributes + + public static class CommonAttributes { - public static class TempDirectoryPath { public static class Values { public const string DEFAULT = ""; } } + public static class Attributes + { + public static class TempDirectoryPath { public static class Values { public const string DEFAULT = ""; } } + public static class PackageFilePath { public static class Values { public const string DEFAULT = ""; } } + public static class PackageName { public static class Values { public const string DEFAULT = ""; } } + public static class CreateExe { public static class Values { public const string DEFAULT = ""; } } + } } public static class BackupPackage { @@ -440,6 +463,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS public static class CreateExe { public static class Values { public const bool DEFAULT = true; } } public static class IncludeFilenameMaskList { public static class Values { public const string DEFAULT = "*"; } } public static class PackageFilePath{ public static class Values { public const string DEFAULT = "BackupPackage_{TIMESTAMP}_{PACKAGENAME}"; } } + public static class TempDirectoryPath { public static class Values { public const string DEFAULT = ""; } } } public static class BackupFolder { diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - FileCleanerManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - FileCleanerManager.cs index 46cf050..7d0adcf 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - FileCleanerManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - FileCleanerManager.cs @@ -124,9 +124,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS } else if (lineix == 2) { - ColorConsole.Write($"{ws.Xml_CleanupDays}", ConsoleColor.Yellow, prefix: "Cleanup days:", bracket: "[]"); var fc2 = ws.Xml_Recurse ? ConsoleColor.Green : ConsoleColor.Yellow; - ColorConsole.Write($"{ws.Xml_Recurse}", fc2, prefix: ", Recurse:", bracket: "[]"); + ColorConsole.Write($"{ws.Xml_Recurse}", fc2, prefix: "Recurse:", bracket: "[]"); var fc0 = ws.Xml_RemoveEmptyFolder ? ConsoleColor.Green : ConsoleColor.Yellow; ColorConsole.Write($"{ws.Xml_RemoveEmptyFolder}", fc0, prefix: ", Remove empty folder:", bracket: "[]"); ColorConsole.WriteLine(ws.Xml_IncludeMask, ConsoleColor.Yellow, prefix: ", Include mask:"); @@ -142,8 +141,18 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS if (lineix != INDEXBASE) { ColorConsole.Write(ws.Xml_OrConditionList ? "OR" : "AND", ConsoleColor.Yellow,suffix:" "); } ColorConsole.Write("Condition:"); ColorConsole.Write(c.Type.ToString(),ConsoleColor.Yellow, prefix: " Type:"); - if (c.Type==FolderToClean.ConditionType.TimeStampInName) { ColorConsole.Write(c.TimestampConstructor, ConsoleColor.Yellow, prefix: ", TS constructor:"); } - ColorConsole.Write(c.Limit.ToString(), ConsoleColor.Yellow, prefix: ", Limit:",suffix: c.Type == FolderToClean.ConditionType.Length ? "bytes" : "days"); + if (c.Type==FolderToClean.ConditionType.Length) //hossz alapján + { + int climit = c.Limit.HasValue ? c.Limit.Value : ws.common_limitbytes.HasValue ? ws.common_limitbytes.Value: FolderToClean.XmlStructure.CommonAttributes.Attributes.LimitBytes.Values.DEFAULT; + ColorConsole.Write(climit.ToString(), ConsoleColor.Yellow, prefix: ", Limit:", suffix: "bytes"); + } + else // időbélyeg alapján + { + var ctsc = !string.IsNullOrWhiteSpace(c.TimestampConstructor) ? c.TimestampConstructor : !string.IsNullOrWhiteSpace(ws.common_timestampconstructor) ? ws.common_timestampconstructor : FolderToClean.XmlStructure.CommonAttributes.Attributes.TimestampConstructor.Values.DEFAULT; + ColorConsole.Write(ctsc, ConsoleColor.Yellow, prefix: ", TS constructor:"); + int climit = c.Limit.HasValue ? c.Limit.Value : ws.common_limitdays.HasValue ? ws.common_limitdays.Value : FolderToClean.XmlStructure.CommonAttributes.Attributes.LimitDays.Values.DEFAULT; + ColorConsole.Write(climit.ToString(), ConsoleColor.Yellow, prefix: ", Limit:", suffix: "days"); + } ColorConsole.WriteLine(); return " "; } @@ -198,7 +207,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS var rgxmatch = rgx.Match(fi.FullName); if (rgxmatch.Success) { - var daystodelete = ftc.Xml_CleanupDays; var conditionlist = ftc.Xml_ConditionList; if (conditionlist == null || !conditionlist.Any()) { return true; } @@ -213,18 +221,22 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS bool conditionresult = false; if (c.Type == FolderToClean.ConditionType.TimeStampInName) { - var fileTSstr = VRH.Common.StringConstructor.ResolveConstructor(groupnamevalues, c.TimestampConstructor, "{}@@"); + var fileTSstr = VRH.Common.StringConstructor.ResolveConstructorR(groupnamevalues, c.TimestampConstructor, "{}@@"); try { var fileTS = DateTime.Parse(fileTSstr); conditionresult = DateTime.Now.Subtract(fileTS).TotalDays > c.Limit; } catch { var tscn = nameof(FolderToClean.XmlStructure.FolderToClean.Conditions.Condition.Attributes.TimestampConstructor); var fprn = nameof(FolderToClean.XmlStructure.FolderToClean.IncludeFullpathRegexp); - throw new Exception( - $"Error in condition, type {FolderToClean.ConditionType.TimeStampInName}. {tscn} or {fprn} value incorrect!" + string exmsg = $"Error in condition, type {FolderToClean.ConditionType.TimeStampInName}. {tscn} or {fprn} value incorrect!" + $"\n Folder: {ftc.Xml_DirectoryPath}" + + $"\n File: {fi.Name}" + $"\n {tscn} : {c.TimestampConstructor}" - + $"\n {tscn} after substitution: {fileTSstr}"); + + $"\n {tscn} after substitution: {fileTSstr}" + + $"\n CONDITION RESULT FALSE IS USED!"; + //throw new Exception(exmsg); + ColorConsole.WriteLine(exmsg, ConsoleColor.Yellow); + conditionresult = false; // ha nincs benne timestamp, akkor nem teljesül } } else if (c.Type == FolderToClean.ConditionType.CreationTime) @@ -255,7 +267,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS #region public CleanFiles public static long CleanFolderFiles(DirectoryInfo d,FolderToClean ftc, bool delete) { - int daystodelete = ftc.Xml_CleanupDays; long cleanedsize = 0; // Add file sizes. FileInfo[] fis = d.GetFiles(ftc.Xml_IncludeMask, SearchOption.TopDirectoryOnly); @@ -291,16 +302,28 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS public class FileCleanerManagerXmlProcessor : XmlParser { private List _foldertocleanlist; - private int commoncleanupdays; #region constructor public FileCleanerManagerXmlProcessor(string xmlcs, string basefolder, string lcid) : base(xmlcs, basefolder, lcid, null) { _foldertocleanlist = new List(); - commoncleanupdays = GetValue(nameof(FolderToClean.XmlStructure.Attributes.CleanupDays),this.RootElement, FolderToClean.XmlStructure.Attributes.CleanupDays.Values.DEFAULT); + var commonattributeselement = GetXElement(nameof(FolderToClean.XmlStructure.CommonAttributes)); + string commonlimitdaysstring = GetValue(nameof(FolderToClean.XmlStructure.CommonAttributes.Attributes.LimitDays), commonattributeselement, (string)null); + int? commonlimitdays = + string.IsNullOrWhiteSpace(commonlimitdaysstring) ? (int?)null + : int.TryParse(commonlimitdaysstring, out int _commonlimitdays) ? _commonlimitdays + : (int?)null; // ha hibás a megadott érték, akkor olyan, mintha nem is lenne megadva + + string commonlimitbytessstring = GetValue(nameof(FolderToClean.XmlStructure.CommonAttributes.Attributes.LimitBytes), commonattributeselement, (string)null); + int? commonlimitbytes = + string.IsNullOrWhiteSpace(commonlimitbytessstring) ? (int?)null + : int.TryParse(commonlimitbytessstring, out int _commonlimitbytes) ? _commonlimitbytes + : (int?)null; // ha hibás a megadott érték, akkor olyan, mintha nem is lenne megadva + + string commontimestampconstructor = GetValue(nameof(FolderToClean.XmlStructure.CommonAttributes.Attributes.TimestampConstructor), commonattributeselement, (string)null); var ftcxmllist = GetAllXElements(nameof(FolderToClean.XmlStructure.FolderToClean)); if (ftcxmllist != null && ftcxmllist.Any()) { - foreach (var ftcxml in ftcxmllist) { var ws = new FolderToClean(ftcxml, commoncleanupdays); if (ws.Valid) { _foldertocleanlist.Add(ws); } } + foreach (var ftcxml in ftcxmllist) { var ws = new FolderToClean(ftcxml, commonlimitdays, commonlimitbytes,commontimestampconstructor); if (ws.Valid) { _foldertocleanlist.Add(ws); } } } } #endregion constructor @@ -323,21 +346,28 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS public string Xml_IncludeFullpathRegexp; public bool Xml_OrConditionList = true; public List Xml_ConditionList; - public int Xml_CleanupDays; public bool FolderExists; public long SizeFolderTotal; public long SizeSelectedBeforeClean; public long SizeSelectedAfterClean { get { return SizeSelectedBeforeClean - SizeSelectedCleaned; } } public long SizeSelectedCleaned; + + public int? common_limitdays; + public int? common_limitbytes; + public string common_timestampconstructor; + #endregion fields #region basic constructor public FolderToClean() { } #endregion basic constructor #region xml constructor - public FolderToClean(XElement foldertocleanxml,int commoncleanupdays) + public FolderToClean(XElement foldertocleanxml,int? commonlimitdays,int? commonlimitbytes,string commontimestampconstructor) { + common_limitdays = commonlimitdays; + common_limitbytes = commonlimitbytes; + common_timestampconstructor = commontimestampconstructor; Valid = true; string ATTRIBUTEMANDATORY = nameof(XmlStructure.FolderToClean) + " attribute is mandatory! Name: {0}"; Xml_Key = GetValue(nameof(XmlStructure.FolderToClean.Attributes.Key), foldertocleanxml, XmlStructure.FolderToClean.Attributes.Key.Values.DEFAULT); @@ -347,7 +377,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS Xml_RemoveEmptyFolder = GetValue(nameof(XmlStructure.FolderToClean.Attributes.RemoveEmptyFolder), foldertocleanxml, XmlStructure.FolderToClean.Attributes.RemoveEmptyFolder.Values.DEFAULT); Xml_IncludeMask = GetValue(nameof(XmlStructure.FolderToClean.Attributes.IncludeMask), foldertocleanxml, XmlStructure.FolderToClean.Attributes.IncludeMask.Values.DEFAULT); Xml_IncludeFullpathRegexp = GetValue(GetXElement(foldertocleanxml,nameof(XmlStructure.FolderToClean.IncludeFullpathRegexp)), XmlStructure.FolderToClean.IncludeFullpathRegexp.Values.DEFAULT); - Xml_CleanupDays = GetValue(GetXElement(foldertocleanxml,nameof(XmlStructure.FolderToClean.Attributes.CleanupDays)), commoncleanupdays); Xml_ConditionList = new List(); //var conditionxmlList = GetAllXElements(foldertocleanxml, nameof(XmlStructure.FolderToClean.Conditions), nameof(XmlStructure.FolderToClean.Conditions.Condition)); var conditionsxml = foldertocleanxml.Element(XName.Get(nameof(XmlStructure.FolderToClean.Conditions))); @@ -355,7 +384,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS if (conditionxmlList!=null && conditionxmlList.Any()) { Xml_OrConditionList = GetValue(nameof(XmlStructure.FolderToClean.Conditions.Attributes.OrConditionList), conditionsxml, XmlStructure.FolderToClean.Conditions.Attributes.OrConditionList.Values.DEFAULT); - foreach (var conditionxml in conditionxmlList) { Xml_ConditionList.Add(new Condition(conditionxml)); } + foreach (var conditionxml in conditionxmlList) { Xml_ConditionList.Add(new Condition(conditionxml, commontimestampconstructor, commonlimitdays, commonlimitbytes)); } } } #endregion xml constructor @@ -370,7 +399,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS Xml_IncludeMask = ftc.Xml_IncludeMask; Xml_IncludeFullpathRegexp = ftc.Xml_IncludeFullpathRegexp; Xml_OrConditionList = ftc.Xml_OrConditionList; - Xml_CleanupDays = ftc.Xml_CleanupDays; Xml_ConditionList = ftc.Xml_ConditionList.Select(c=>new Condition(c)).ToList(); ; } #endregion cloner constructor @@ -387,30 +415,36 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS } #endregion cloner constructor #region constructor - public Condition(XElement cxml) + public Condition(XElement cxml, string commontimestampconstructor,int? commonlimitdays,int? commonlimitbytes) { var typestr = GetValue(nameof(XmlStructure.FolderToClean.Conditions.Condition.Attributes.Type), cxml, XmlStructure.FolderToClean.Conditions.Condition.Attributes.Type.Values.DEFAULT); this.Type = (ConditionType)Enum.Parse(typeof(ConditionType),typestr); - TimestampConstructor = GetValue(nameof(XmlStructure.FolderToClean.Conditions.Condition.Attributes.TimestampConstructor), cxml, XmlStructure.FolderToClean.Conditions.Condition.Attributes.TimestampConstructor.Values.DEFAULT); - Limit = GetValue(nameof(XmlStructure.FolderToClean.Conditions.Condition.Attributes.Limit), cxml, XmlStructure.FolderToClean.Conditions.Condition.Attributes.Limit.Values.DEFAULT); + + TimestampConstructor = GetValue(nameof(XmlStructure.FolderToClean.Conditions.Condition.Attributes.TimestampConstructor), cxml, commontimestampconstructor); + if (string.IsNullOrWhiteSpace(TimestampConstructor)) { TimestampConstructor = XmlStructure.CommonAttributes.Attributes.TimestampConstructor.Values.DEFAULT; } + + string limitstring = GetValue(nameof(XmlStructure.FolderToClean.Conditions.Condition.Attributes.Limit), cxml, null); + if (string.IsNullOrWhiteSpace(limitstring)) { Limit = this.Type == ConditionType.Length ? commonlimitbytes: commonlimitdays; } + else if (!string.IsNullOrWhiteSpace(limitstring) && int.TryParse(limitstring, out int _limit)) { Limit = _limit; } + + if (!Limit.HasValue) { Limit = this.Type == ConditionType.Length ? XmlStructure.CommonAttributes.Attributes.LimitBytes.Values.DEFAULT : XmlStructure.CommonAttributes.Attributes.LimitDays.Values.DEFAULT; } } #endregion constructor public ConditionType Type; public string TimestampConstructor; - public int Limit; + public int? Limit; } #endregion Condition #region XmlStructure public static class XmlStructure { - public static class Attributes + public static class CommonAttributes { - public static class CleanupDays + public static class Attributes { - public static class Values - { - public const int DEFAULT = 7; - } + public static class LimitDays { public static class Values { public const int DEFAULT = 7; } } + public static class LimitBytes { public static class Values { public const int DEFAULT = 500000; } } + public static class TimestampConstructor { public static class Values { public const string DEFAULT = "{YEAR}.{MONTH}.{DAY} {HOUR}:{MINUTE}:{SECOND}"; } } } } public static class FolderToClean @@ -419,13 +453,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS { public static class Key { public static class Values { public const string DEFAULT = ""; } } public static class Directory { } - public static class CleanupDays - { - public static class Values - { - public const int DEFAULT = XmlStructure.Attributes.CleanupDays.Values.DEFAULT; - } - } + public static class LimitDays { public static class Values { public const int DEFAULT = XmlStructure.CommonAttributes.Attributes.LimitDays.Values.DEFAULT; } } public static class Recurse { public static class Values @@ -483,20 +511,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS public static class CreationTime { } } } - public static class TimestampConstructor - { - public static class Values - { - public const string DEFAULT = "{YEAR}.{MONTH}.{DAY} {HOUR}:{MINUTE}:{SECOND}"; - } - } - public static class Limit - { - public static class Values - { - public const int DEFAULT = XmlStructure.Attributes.CleanupDays.Values.DEFAULT; - } - } + public static class TimestampConstructor { } + public static class Limit { } } } } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs index dc77bc0..0097e58 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs @@ -403,7 +403,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS vars.Add(nameof(DBSubstitutionName.DBDATAGROUP), ""); vars.Add(nameof(DBSubstitutionName.BACKUPTS), backupts); - backupfileNameOnly = VRH.Common.StringConstructor.ResolveConstructor(vars, backupfileNameOnly, "{}@@"); + backupfileNameOnly = VRH.Common.StringConstructor.ResolveConstructorR(vars, backupfileNameOnly, "{}@@"); string backupfilename = backupfileNameOnly + ".bak"; string backupFullName = Path.Combine(backupdirectorypath, backupfilename); @@ -443,7 +443,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS vars.Add(nameof(DBSubstitutionName.DBONAME), ""); vars.Add(nameof(DBSubstitutionName.DBDATAGROUP), ""); vars.Add(nameof(DBSubstitutionName.BACKUPTS), "*"); - filenamemask = VRH.Common.StringConstructor.ResolveConstructor(vars, filenamemask, "{}@@"); + filenamemask = VRH.Common.StringConstructor.ResolveConstructorR(vars, filenamemask, "{}@@"); var filelist = new DirectoryInfo(sqld.Xml_BackupTargetDirectoryPath)?.GetFiles(filenamemask)?.ToList(); var filelistordered = filelist?.OrderByDescending(x => x.CreationTime).ToList(); return filelistordered; @@ -590,7 +590,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS { var sqlc = new Microsoft.Data.SqlClient.SqlConnection(sqlconnectionstring); - sqltxt = VRH.Common.StringConstructor.ResolveConstructor(vars, sqltxt, "{}@@"); + sqltxt = VRH.Common.StringConstructor.ResolveConstructorR(vars, sqltxt, "{}@@"); sqlc.Open(); string SQLBatchTxt = ""; // ebben lesznek az sql script-en belüli batch-ek összerakva @@ -731,7 +731,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS { vars[nameof(DBSubstitutionName.DBONAME)] = ""; vars[nameof(DBSubstitutionName.DBDATAGROUP)] = ""; - string zipfilename = VRH.Common.StringConstructor.ResolveConstructor(vars, backupfilenamemask, "{}@@") + ".zip"; + string zipfilename = VRH.Common.StringConstructor.ResolveConstructorR(vars, backupfilenamemask, "{}@@") + ".zip"; zipfilefullpath = Path.Combine(backupdirectorypath, zipfilename); tempbackupdirectorypath = Path.Combine(backupdirectorypath, "TEMP_" + Path.GetFileNameWithoutExtension(zipfilename)); if (Directory.Exists(tempbackupdirectorypath)) { Directory.Delete(tempbackupdirectorypath, recursive: true); } @@ -776,7 +776,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS vars[nameof(DBSubstitutionName.DBONAME)]=namevalue; vars[nameof(DBSubstitutionName.DBDATAGROUP)]=sqldbobj.GetType().Name; - string filename = VRH.Common.StringConstructor.ResolveConstructor(vars, backupfilenamemask, "{}@@"); + string filename = VRH.Common.StringConstructor.ResolveConstructorR(vars, backupfilenamemask, "{}@@"); if (lastfilename!=filename) { var i = 2; @@ -849,7 +849,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS { vars[nameof(DBSubstitutionName.DBONAME)] = ""; vars[nameof(DBSubstitutionName.DBDATAGROUP)] = ""; - string zipfilename = VRH.Common.StringConstructor.ResolveConstructor(vars, backupfilenamemask, "{}@@") + ".zip"; + string zipfilename = VRH.Common.StringConstructor.ResolveConstructorR(vars, backupfilenamemask, "{}@@") + ".zip"; tempbackupdirectorypath = Path.Combine(backupdirectorypath, "TEMP_"+Path.GetFileNameWithoutExtension(zipfilename)); zipfilefullpath = Path.Combine(backupdirectorypath, zipfilename); if (Directory.Exists(tempbackupdirectorypath)) { Directory.Delete(tempbackupdirectorypath, recursive: true); } @@ -911,7 +911,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS string tn_schemaname = tn.Split('.')[1]; string tn_name = tn.Split('.')[2]; vars[nameof(DBSubstitutionName.DBONAME)] = $"{tn_schemaname}.{tn_name}"; - filename = VRH.Common.StringConstructor.ResolveConstructor(vars, backupfilenamemask, "{}@@"); + filename = VRH.Common.StringConstructor.ResolveConstructorR(vars, backupfilenamemask, "{}@@"); filefullname = Path.Combine(backupdirectorypath, filename); if (lastfilefullname!=filefullname && lastfilefullname!=null) { diff --git a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs index 702760c..2cc3c83 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.4.0")] -[assembly: AssemblyFileVersion("1.2.4.0")] +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")] diff --git a/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj b/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj index 12559ec..b7d3e26 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj +++ b/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj @@ -336,14 +336,14 @@ - - ..\packages\VRH.Common.2.20.1\lib\net45\VRH.Common.dll + + ..\packages\VRH.Common.2.21.2\lib\net45\VRH.Common.dll ..\packages\VRH.Web.Providers.2.0.2\lib\net452\Vrh.Web.Providers.dll - - ..\packages\Vrh.XmlProcessing.1.26.1\lib\net45\Vrh.XmlProcessing.dll + + ..\packages\Vrh.XmlProcessing.1.27.0\lib\net45\Vrh.XmlProcessing.dll diff --git a/Vrh.Log4Pro.MaintenanceConsole/packages.config b/Vrh.Log4Pro.MaintenanceConsole/packages.config index 910a05b..8a15381 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/packages.config +++ b/Vrh.Log4Pro.MaintenanceConsole/packages.config @@ -71,7 +71,7 @@ - + - + \ No newline at end of file -- libgit2 0.21.2