Dependency Injection Style

AOT Compiling
Switched to Secret from Development json file
Added Kanbn
Humanizer
HelperCreateNoteFiles.CleanExistingFiles
HelperPackageFilesByDate
Added SRP
Helper Hardcoded File Search and Sort
Set Date from Zip Entry
This commit is contained in:
2023-07-08 10:05:52 -07:00
parent 81472165f7
commit 229b508ae1
39 changed files with 1584 additions and 781 deletions

View File

@ -0,0 +1,82 @@
using Microsoft.Extensions.Logging;
namespace File_Folder_Helper.Helpers;
internal static class HelperKanbanMetadata
{
private static List<(int, int, string, FileInfo)> GetCollectionFromIndex(string sourceDirectory, string[] lines)
{
List<(int, int, string, FileInfo)> results = new();
string line;
FileInfo fileInfo;
string[] segments;
int groupCount = 0;
string? group = null;
for (int i = 0; i < lines.Length; i++)
{
line = lines[i];
if (line.Length < 4)
continue;
if (line[..3] == "## ")
{
group = line[3..];
groupCount += 1;
continue;
}
if (group is null || line[..3] != "- [" || line[^1] != ')')
continue;
segments = line.Split("](");
if (segments.Length != 2)
continue;
fileInfo = new(Path.Combine(sourceDirectory, segments[1][..^1]));
if (!fileInfo.Exists)
continue;
results.Add((groupCount, i, group, fileInfo));
}
return results;
}
internal static void SetMetadata(ILogger log, Models.AppSettings appSettings, string sourceDirectory)
{
string statusLine;
List<string> lines;
LineNumber lineNumber;
if (log is null)
throw new NullReferenceException();
string fullPath = Path.GetFullPath(sourceDirectory);
if (!Directory.Exists(fullPath))
_ = Directory.CreateDirectory(fullPath);
List<(MarkdownFile, string[])> collection;
collection = HelperMarkdown.GetCollection(appSettings, HelperMarkdown.GetFiles(appSettings, fullPath));
string indexFile = Path.Combine(fullPath, "index.md");
if (File.Exists(indexFile))
{
string[] indexFileLines = File.ReadAllLines(indexFile);
List<(int, int, string, FileInfo)> collectionFromIndex = GetCollectionFromIndex(sourceDirectory, indexFileLines);
foreach ((int groupCount, int itemLineNumber, string group, FileInfo fileInfo) in collectionFromIndex)
{
if (itemLineNumber == 0)
throw new NotSupportedException();
(lines, lineNumber) = HelperMarkdown.GetStatusAndMetaEndLineNumbers(fileInfo);
if (!lines.Any())
continue;
statusLine = $"status: \"{groupCount}-{group}\"";
indexFileLines[itemLineNumber] = $"{fileInfo.LastWriteTime.Ticks}~~~{indexFileLines[itemLineNumber]}";
if (lineNumber.MetaEnd is null)
throw new NotSupportedException($"{nameof(SetMetadata)} must be executed first!");
if (lineNumber.Status is null)
lines.Insert(lineNumber.MetaEnd.Value, statusLine);
else
{
if (lines[lineNumber.Status.Value] == statusLine)
continue;
lines[lineNumber.Status.Value] = statusLine;
}
File.WriteAllLines(fileInfo.FullName, lines);
}
File.WriteAllLines(indexFile, indexFileLines);
}
}
}