Minor changes

Empty file ISO
Add date back for just .kanbn
Removed HardcodedFileSearchAndSort
Sync with 01-23
JsonToTsv
System.Text.Json
White-List
Ready to move to Move Helper
Remove Whitelist
Force Start At
Check for .git directory before ls
Optional
Allow root for unc path
nuget bump
PreVerify
EnforceCodeStyleInBuild
dotnet_analyzer_diagnostic
HelperGit
searchDelegate
Host File
AlertIfNewDeviceIsConnected
AOT
SetFrontMatterAndH1
Match Error
Unknown with better logging
Undo 04-05
WriteAppendToHostConfFile
MonA
IsKanbanIndex
Dotnet Format Pre-commit
NPM
CreateWindowsShortcut
Working directory
Split description
Copy tests
Ready to test
Delete after a couple of days
GitConfigCleanUp
knb Files
This commit is contained in:
2024-01-08 13:57:27 -07:00
parent 84ad97ac6e
commit 4e3f06bb44
35 changed files with 1914 additions and 884 deletions

View File

@ -1,5 +1,6 @@
using File_Folder_Helper.Models;
using Microsoft.Extensions.Logging;
using System.Collections.ObjectModel;
using System.Text;
using System.Text.RegularExpressions;
@ -14,6 +15,11 @@ internal static partial class HelperKanbanMetadata
[GeneratedRegex("[\\s!?.,@:;|\\\\/\"'`£$%\\^&*{}[\\]()<>~#+\\-=_¬]+")]
private static partial Regex InvalidCharacter();
private record Record(FileInfo FileInfo,
string Group,
int GroupCount,
int ItemLineNumber);
private static string GetParamCase(string value)
{
string result;
@ -64,15 +70,15 @@ internal static partial class HelperKanbanMetadata
throw new Exception("я надеюсь, что это сработает");
}
private static List<(int, int, string, FileInfo)> GetCollectionFromIndex(string sourceDirectory, string[] lines)
private static List<Record> GetCollectionFromIndex(string sourceDirectory, ReadOnlyCollection<string> lines)
{
List<(int, int, string, FileInfo)> results = [];
List<Record> results = [];
string line;
FileInfo fileInfo;
string[] segments;
int groupCount = 0;
string? group = null;
for (int i = 0; i < lines.Length; i++)
for (int i = 0; i < lines.Count; i++)
{
line = lines[i];
if (line.Length < 4)
@ -91,12 +97,30 @@ internal static partial class HelperKanbanMetadata
fileInfo = new(Path.Combine(sourceDirectory, segments[1][..^1]));
if (!fileInfo.Exists)
continue;
results.Add((groupCount, i, group, fileInfo));
results.Add(new(fileInfo, group, groupCount, i));
}
return results;
}
internal static void SetMetadata(ILogger log, AppSettings appSettings, string sourceDirectory, bool addTicks)
private static void WriteKanbanBoardFile(string fullPath, List<Record> records, string h1)
{
string? last = null;
List<string> lines = [h1, string.Empty];
foreach (Record record in records)
{
if (last is null || record.Group != last)
{
lines.Add(string.Empty);
lines.Add($"## {record.Group}");
lines.Add(string.Empty);
}
lines.Add($"- [ ] {Path.GetFileNameWithoutExtension(record.FileInfo.Name)}");
last = record.Group;
}
File.WriteAllLines(Path.Combine(fullPath, "index.knb.md"), lines);
}
internal static void SetMetadata(ILogger log, AppSettings appSettings, string sourceDirectory)
{
bool? match;
string? paramCase;
@ -112,20 +136,22 @@ internal static partial class HelperKanbanMetadata
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)
FileInfo fileInfo = new(indexFile);
(lines, lineNumber) = HelperMarkdown.GetStatusAndFrontMatterYamlEndLineNumbers(fileInfo);
ReadOnlyCollection<string> indexFileLines = new(lines);
List<Record> records = GetCollectionFromIndex(sourceDirectory, indexFileLines);
if (lineNumber.H1 is not null)
WriteKanbanBoardFile(fullPath, records, indexFileLines[lineNumber.H1.Value]);
foreach (Record record in records)
{
if (itemLineNumber == 0)
if (record.ItemLineNumber == 0)
throw new NotSupportedException();
(lines, lineNumber) = HelperMarkdown.GetStatusAndFrontMatterYamlEndLineNumbers(fileInfo);
(lines, lineNumber) = HelperMarkdown.GetStatusAndFrontMatterYamlEndLineNumbers(record.FileInfo);
if (lines.Count == 0)
continue;
statusLine = $"status: \"{groupCount}-{group}\"";
statusLine = $"status: \"{record.GroupCount}-{record.Group}\"";
paramCase = lineNumber.H1 is null ? null : GetParamCase(lines[lineNumber.H1.Value]);
if (addTicks)
indexFileLines[itemLineNumber] = $"{fileInfo.LastWriteTime.Ticks}~~~{indexFileLines[itemLineNumber]}";
match = lineNumber.H1 is null || paramCase is null ? null : Path.GetFileNameWithoutExtension(fileInfo.Name) == paramCase;
match = lineNumber.H1 is null || paramCase is null ? null : Path.GetFileNameWithoutExtension(record.FileInfo.Name) == paramCase;
if (lineNumber.FrontMatterYamlEnd is null)
throw new NotSupportedException($"{nameof(SetMetadata)} must be executed first!");
if (lineNumber.H1 is not null && paramCase is not null && match is not null && !match.Value)
@ -138,10 +164,8 @@ internal static partial class HelperKanbanMetadata
continue;
lines[lineNumber.Status.Value] = statusLine;
}
File.WriteAllLines(fileInfo.FullName, lines);
File.WriteAllLines(record.FileInfo.FullName, lines);
}
if (addTicks)
File.WriteAllLines(indexFile, indexFileLines);
}
}