People
log pattern
This commit is contained in:
parent
79b9daedfa
commit
e6a70130c7
13
.vscode/settings.json
vendored
13
.vscode/settings.json
vendored
@ -11,13 +11,26 @@
|
|||||||
},
|
},
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"ASPNETCORE",
|
"ASPNETCORE",
|
||||||
|
"BIRT",
|
||||||
|
"CHIL",
|
||||||
|
"DEAT",
|
||||||
"endianness",
|
"endianness",
|
||||||
|
"FAMC",
|
||||||
|
"FAMS",
|
||||||
|
"GIVN",
|
||||||
|
"HUSB",
|
||||||
|
"INDI",
|
||||||
"Infineon",
|
"Infineon",
|
||||||
"Kanban",
|
"Kanban",
|
||||||
"kanbn",
|
"kanbn",
|
||||||
|
"NSFX",
|
||||||
|
"OBJE",
|
||||||
"onenote",
|
"onenote",
|
||||||
|
"pged",
|
||||||
"Phares",
|
"Phares",
|
||||||
"Serilog",
|
"Serilog",
|
||||||
|
"SUBM",
|
||||||
|
"SURN",
|
||||||
"SYSLIB"
|
"SYSLIB"
|
||||||
]
|
]
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
@ -76,7 +76,7 @@ internal static class HelperHardcodedFileSearchAndSort
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.LogInformation(sourceDirectory);
|
log.LogInformation("{sourceDirectory}", sourceDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -41,7 +41,7 @@ internal static class HelperLogMerge
|
|||||||
continue;
|
continue;
|
||||||
segment1 = segments[1];
|
segment1 = segments[1];
|
||||||
hour = int.Parse(sourceFileNameWithoutExtension.Substring(8, 2));
|
hour = int.Parse(sourceFileNameWithoutExtension.Substring(8, 2));
|
||||||
if (keyValuePairs[day].ContainsKey(hour))
|
if (keyValuePairs[day].TryGetValue(hour, out _))
|
||||||
continue;
|
continue;
|
||||||
keyValuePairs[day].Add(hour, File.ReadAllLines(sourceFile));
|
keyValuePairs[day].Add(hour, File.ReadAllLines(sourceFile));
|
||||||
moveFiles.Add(sourceFile);
|
moveFiles.Add(sourceFile);
|
||||||
|
@ -9,14 +9,14 @@ internal static class HelperRenameToOldMoveDeleteOldMerge
|
|||||||
{
|
{
|
||||||
string checkDirectory = argsZero[0..^1];
|
string checkDirectory = argsZero[0..^1];
|
||||||
if (!Directory.Exists(checkDirectory))
|
if (!Directory.Exists(checkDirectory))
|
||||||
log.LogInformation(string.Concat("<", checkDirectory, "> doesn't exist!"));
|
log.LogInformation("<{checkDirectory}> doesn't exist!", checkDirectory);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string renameFile;
|
string renameFile;
|
||||||
string destinationFile;
|
string destinationFile;
|
||||||
List<string> deleteFiles = new();
|
List<string> deleteFiles = new();
|
||||||
string[] moveFiles = Directory.GetFiles(argsZero, "*", SearchOption.TopDirectoryOnly);
|
string[] moveFiles = Directory.GetFiles(argsZero, "*", SearchOption.TopDirectoryOnly);
|
||||||
log.LogInformation(string.Concat("<", moveFiles.Length, "> to move"));
|
log.LogInformation("<{moveFiles.Length}> to move", moveFiles.Length);
|
||||||
foreach (string moveFile in moveFiles)
|
foreach (string moveFile in moveFiles)
|
||||||
{
|
{
|
||||||
destinationFile = string.Concat(checkDirectory, moveFile[argsZero.Length..]);
|
destinationFile = string.Concat(checkDirectory, moveFile[argsZero.Length..]);
|
||||||
@ -30,7 +30,7 @@ internal static class HelperRenameToOldMoveDeleteOldMerge
|
|||||||
deleteFiles.Add(renameFile);
|
deleteFiles.Add(renameFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.LogInformation(string.Concat("<", deleteFiles.Count, "> to delete"));
|
log.LogInformation("<{deleteFiles.Count}> to delete", deleteFiles.Count);
|
||||||
foreach (string deleteFile in deleteFiles)
|
foreach (string deleteFile in deleteFiles)
|
||||||
{
|
{
|
||||||
for (short i = 0; i < short.MaxValue; i++)
|
for (short i = 0; i < short.MaxValue; i++)
|
||||||
|
@ -5,30 +5,33 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
namespace File_Folder_Helper.Helpers;
|
namespace File_Folder_Helper.Helpers;
|
||||||
|
|
||||||
internal static class HelperZipFilesByDate
|
internal static partial class HelperZipFilesByDate
|
||||||
{
|
{
|
||||||
|
|
||||||
|
[GeneratedRegex("[a-zA-Z0-9]{1,}")]
|
||||||
|
private static partial Regex LowerAlphaAlphaAndNumber();
|
||||||
|
|
||||||
internal static bool ZipFilesByDate(ILogger log, string sourceDirectory, SearchOption searchOption = SearchOption.TopDirectoryOnly, string dayFormat = "")
|
internal static bool ZipFilesByDate(ILogger log, string sourceDirectory, SearchOption searchOption = SearchOption.TopDirectoryOnly, string dayFormat = "")
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
string key;
|
string key;
|
||||||
bool addFile;
|
bool addFile;
|
||||||
string? zipPath;
|
|
||||||
string fileName;
|
string fileName;
|
||||||
|
string? zipPath;
|
||||||
|
FileInfo fileInfo;
|
||||||
|
string weekOfYear;
|
||||||
string[] segments;
|
string[] segments;
|
||||||
string[] subFiles;
|
string[] subFiles;
|
||||||
string weekOfYear;
|
|
||||||
FileInfo fileInfo;
|
|
||||||
string zipDirectory;
|
string zipDirectory;
|
||||||
DateTime creationTime;
|
DateTime creationTime;
|
||||||
string? directoryName;
|
string? directoryName;
|
||||||
DateTime lastWriteTime;
|
DateTime lastWriteTime;
|
||||||
DateTime nowDateTime = DateTime.Now;
|
DateTime nowDateTime = DateTime.Now;
|
||||||
Regex regex = new("[a-zA-Z0-9]{1,}");
|
|
||||||
DateTime dateTime = DateTime.MinValue;
|
DateTime dateTime = DateTime.MinValue;
|
||||||
DateTime firstEmail = new(2019, 3, 8);
|
DateTime firstEmail = new(2019, 3, 8);
|
||||||
CultureInfo cultureInfo = new("en-US");
|
CultureInfo cultureInfo = new("en-US");
|
||||||
Calendar calendar = cultureInfo.Calendar;
|
Calendar calendar = cultureInfo.Calendar;
|
||||||
|
Regex regex = LowerAlphaAlphaAndNumber();
|
||||||
Dictionary<string, DateTime> weeks = new();
|
Dictionary<string, DateTime> weeks = new();
|
||||||
int ticksLength = nowDateTime.AddDays(-6).Ticks.ToString().Length;
|
int ticksLength = nowDateTime.AddDays(-6).Ticks.ToString().Length;
|
||||||
for (int i = 0; i < int.MaxValue; i++)
|
for (int i = 0; i < int.MaxValue; i++)
|
||||||
@ -107,14 +110,12 @@ internal static class HelperZipFilesByDate
|
|||||||
{
|
{
|
||||||
key = Path.Combine(zipDirectory, $"{element.Key}.zip");
|
key = Path.Combine(zipDirectory, $"{element.Key}.zip");
|
||||||
if (File.Exists(key))
|
if (File.Exists(key))
|
||||||
{
|
|
||||||
for (short i = 101; i < short.MaxValue; i++)
|
for (short i = 101; i < short.MaxValue; i++)
|
||||||
{
|
{
|
||||||
key = Path.Combine(zipDirectory, $"{element.Key}_{i}.zip");
|
key = Path.Combine(zipDirectory, $"{element.Key}_{i}.zip");
|
||||||
if (!File.Exists(key))
|
if (!File.Exists(key))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
using ZipArchive zip = ZipFile.Open(key, ZipArchiveMode.Create);
|
using ZipArchive zip = ZipFile.Open(key, ZipArchiveMode.Create);
|
||||||
foreach (string file in element.Value)
|
foreach (string file in element.Value)
|
||||||
{
|
{
|
||||||
@ -122,12 +123,10 @@ internal static class HelperZipFilesByDate
|
|||||||
File.Delete(file);
|
File.Delete(file);
|
||||||
}
|
}
|
||||||
if (zipPath is not null && Directory.Exists(zipPath) && !string.IsNullOrEmpty(directoryName))
|
if (zipPath is not null && Directory.Exists(zipPath) && !string.IsNullOrEmpty(directoryName))
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{ Directory.SetLastWriteTime(directoryName, DateTime.Now); }
|
{ Directory.SetLastWriteTime(directoryName, DateTime.Now); }
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
subFiles = Directory.GetFiles(zipDirectory, "*.zip", SearchOption.TopDirectoryOnly);
|
subFiles = Directory.GetFiles(zipDirectory, "*.zip", SearchOption.TopDirectoryOnly);
|
||||||
foreach (string subFile in subFiles)
|
foreach (string subFile in subFiles)
|
||||||
{
|
{
|
||||||
@ -136,7 +135,6 @@ internal static class HelperZipFilesByDate
|
|||||||
if (segments.Length > 2)
|
if (segments.Length > 2)
|
||||||
fileName = string.Concat(segments[0], '_', segments[1], '_', segments[2]);
|
fileName = string.Concat(segments[0], '_', segments[1], '_', segments[2]);
|
||||||
if (weeks.TryGetValue(fileName, out DateTime value))
|
if (weeks.TryGetValue(fileName, out DateTime value))
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!result)
|
if (!result)
|
||||||
@ -145,13 +143,10 @@ internal static class HelperZipFilesByDate
|
|||||||
}
|
}
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (topDirectory != sourceDirectory)
|
if (topDirectory != sourceDirectory)
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{ _ = HelperDeleteEmptyDirectories.DeleteEmptyDirectories(topDirectory); }
|
{ _ = HelperDeleteEmptyDirectories.DeleteEmptyDirectories(topDirectory); }
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
}
|
|
||||||
log.LogInformation("{topDirectory}", topDirectory);
|
log.LogInformation("{topDirectory}", topDirectory);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -166,7 +161,6 @@ internal static class HelperZipFilesByDate
|
|||||||
string? zipDirectory;
|
string? zipDirectory;
|
||||||
DateTimeOffset? dateTimeOffset;
|
DateTimeOffset? dateTimeOffset;
|
||||||
foreach (string zipFile in zipFiles)
|
foreach (string zipFile in zipFiles)
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
dateTimeOffset = null;
|
dateTimeOffset = null;
|
||||||
@ -240,7 +234,6 @@ internal static class HelperZipFilesByDate
|
|||||||
{ File.Move(zipFile, checkFile); }
|
{ File.Move(zipFile, checkFile); }
|
||||||
catch (Exception) { log.LogInformation("<{zipFile}> couldn't be moved!", zipFile); }
|
catch (Exception) { log.LogInformation("<{zipFile}> couldn't be moved!", zipFile); }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
Models/Birth.cs
Normal file
23
Models/Birth.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace File_Folder_Helper.Models;
|
||||||
|
|
||||||
|
public record Birth(DateOnly? Date,
|
||||||
|
string? Note,
|
||||||
|
List<string> Continue)
|
||||||
|
{
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
string result = JsonSerializer.Serialize(this, BirthSourceGenerationContext.Default.Birth);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
[JsonSerializable(typeof(Birth))]
|
||||||
|
internal partial class BirthSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
23
Models/Change.cs
Normal file
23
Models/Change.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace File_Folder_Helper.Models;
|
||||||
|
|
||||||
|
public record Change(DateOnly? Date,
|
||||||
|
string? Note,
|
||||||
|
List<string> Continue)
|
||||||
|
{
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
string result = JsonSerializer.Serialize(this, ChangeSourceGenerationContext.Default.Change);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
[JsonSerializable(typeof(Change))]
|
||||||
|
internal partial class ChangeSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
24
Models/Death.cs
Normal file
24
Models/Death.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace File_Folder_Helper.Models;
|
||||||
|
|
||||||
|
public record Death(bool? Is,
|
||||||
|
DateOnly? Date,
|
||||||
|
string? Note,
|
||||||
|
List<string> Continue)
|
||||||
|
{
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
string result = JsonSerializer.Serialize(this, DeathSourceGenerationContext.Default.Death);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
[JsonSerializable(typeof(Death))]
|
||||||
|
internal partial class DeathSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
25
Models/Name.cs
Normal file
25
Models/Name.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace File_Folder_Helper.Models;
|
||||||
|
|
||||||
|
public record Name(string? ForwardSlashFull,
|
||||||
|
string? Given,
|
||||||
|
string? Sur,
|
||||||
|
string? Nick,
|
||||||
|
string? Suffix)
|
||||||
|
{
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
string result = JsonSerializer.Serialize(this, NameSourceGenerationContext.Default.Name);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
[JsonSerializable(typeof(Name))]
|
||||||
|
internal partial class NameSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
34
Models/Person.cs
Normal file
34
Models/Person.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace File_Folder_Helper.Models;
|
||||||
|
|
||||||
|
public record Person(long Id,
|
||||||
|
Name? Name,
|
||||||
|
char? Sex,
|
||||||
|
string? UId,
|
||||||
|
Birth? Birth,
|
||||||
|
Death? Death,
|
||||||
|
Change? Change,
|
||||||
|
string[] Lines)
|
||||||
|
{
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
string result = JsonSerializer.Serialize(this, PersonSourceGenerationContext.Default.Person);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
[JsonSerializable(typeof(Person))]
|
||||||
|
internal partial class PersonSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
[JsonSerializable(typeof(Dictionary<long, Person>))]
|
||||||
|
internal partial class PeopleSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
@ -22,7 +22,7 @@ internal class Program
|
|||||||
_ = builder.Services.AddHostedService<Worker>();
|
_ = builder.Services.AddHostedService<Worker>();
|
||||||
using IHost host = builder.Build();
|
using IHost host = builder.Build();
|
||||||
ILogger<Program> logger = host.Services.GetRequiredService<ILogger<Program>>();
|
ILogger<Program> logger = host.Services.GetRequiredService<ILogger<Program>>();
|
||||||
logger.LogCritical(appSettings.Company);
|
logger.LogCritical("appSettings.Company", appSettings.Company);
|
||||||
host.Run();
|
host.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ public class Worker : BackgroundService
|
|||||||
throw new Exception(_Args[0]);
|
throw new Exception(_Args[0]);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{ _Logger.LogError(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace)); }
|
{ _Logger.LogError("{Message}{NewLine}{StackTrace}", ex.Message, Environment.NewLine, ex.StackTrace); }
|
||||||
if (_IsSilent)
|
if (_IsSilent)
|
||||||
_Logger.LogInformation("Done. Bye");
|
_Logger.LogInformation("Done. Bye");
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user