Push 07-18
This commit is contained in:
parent
b2ab434ec3
commit
2aa9c0f018
1
.gitignore
vendored
1
.gitignore
vendored
@ -335,3 +335,4 @@ ASALocalRun/
|
||||
.extensions-vscode
|
||||
.extensions-vscode-oss
|
||||
.extensions-vscode-insiders
|
||||
.vscode/.UserSecrets/secrets.json
|
||||
|
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
@ -16,7 +16,6 @@
|
||||
"L:/Git/Notes-Network/.Network/.vscode/helper",
|
||||
"Day-Helper-2024-07-18",
|
||||
"hosts.jsonl",
|
||||
"192.168.0.",
|
||||
"Network",
|
||||
"Wired",
|
||||
".md",
|
||||
|
4
.vscode/mklink.md
vendored
4
.vscode/mklink.md
vendored
@ -22,3 +22,7 @@ mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode" "C:\Users\ph
|
||||
mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode-oss" "C:\Users\phares\.vscode-oss\extensions\ifx.type-script-helper-1.6.2"
|
||||
mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode-insiders" "C:\Users\phares\.vscode-insiders\extensions\ifx.type-script-helper-1.6.2"
|
||||
```
|
||||
|
||||
```bash Thu Jul 18 2024 13:47:40 GMT-0700 (Mountain Standard Time)
|
||||
mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.vscode\.UserSecrets" "L:\Git\Notes-User-Secrets\.UserSecrets\8da397d4-13ec-4576-9722-3c79cad25563"
|
||||
```
|
||||
|
@ -1,3 +1,4 @@
|
||||
using File_Folder_Helper.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
@ -9,22 +10,6 @@ namespace File_Folder_Helper.Day;
|
||||
internal static partial class Helper20240106
|
||||
{
|
||||
|
||||
private record Host([property: JsonPropertyName("a")] string? Id,
|
||||
[property: JsonPropertyName("b")] string? Colon,
|
||||
[property: JsonPropertyName("c")] string? Hyphen,
|
||||
[property: JsonPropertyName("d")] string? Line,
|
||||
[property: JsonPropertyName("e")] string? Count,
|
||||
[property: JsonPropertyName("f")] string? Segments,
|
||||
[property: JsonPropertyName("g")] string? Type,
|
||||
[property: JsonPropertyName("h")] string? Device,
|
||||
[property: JsonPropertyName("i")] string? Name);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, AllowTrailingCommas = true)]
|
||||
[JsonSerializable(typeof(Host[]))]
|
||||
private partial class HostSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
private record Record(string Key, Dictionary<string, string> KeyValuePairs);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace File_Folder_Helper.Day;
|
||||
|
||||
@ -11,9 +12,9 @@ internal static partial class Helper20240623
|
||||
{
|
||||
List<Record> results = [];
|
||||
int? stopLine;
|
||||
string[] lines;
|
||||
int? subTasksLine;
|
||||
int? codeInsidersLine;
|
||||
string[] lines;
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
{
|
||||
@ -52,13 +53,41 @@ internal static partial class Helper20240623
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetSubTasks(string subTasks, string[] tasks, bool? foundDone, string fallbackLine, string checkFile)
|
||||
{
|
||||
List<string> results = [];
|
||||
string? h1 = null;
|
||||
bool foundSubTasks = false;
|
||||
int tasksZeroLength = tasks[0].Length;
|
||||
string[] lines = File.ReadAllLines(checkFile);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (line.StartsWith("# "))
|
||||
h1 = line[2..];
|
||||
if (!foundSubTasks && line == subTasks)
|
||||
foundSubTasks = true;
|
||||
if (!foundSubTasks)
|
||||
continue;
|
||||
if (line.Length <= tasksZeroLength || !line.StartsWith(tasks[0]) || line[tasksZeroLength] is not ' ' and not 'x' || line[tasksZeroLength + 1] != ']')
|
||||
continue;
|
||||
results.Add($" {line}");
|
||||
}
|
||||
if (h1 is null)
|
||||
results.Insert(0, fallbackLine);
|
||||
else
|
||||
results.Insert(0, foundDone is null || !foundDone.Value ? $"- [ ] {h1}" : $"- [x] {h1}");
|
||||
return new(results);
|
||||
}
|
||||
|
||||
internal static void UpdateSubTasksInMarkdownFiles(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
int lineCheck;
|
||||
bool? foundDone;
|
||||
string checkFile;
|
||||
string[] segments;
|
||||
List<string> lines;
|
||||
string[] indexLines;
|
||||
string fallbackLine;
|
||||
string checkDirectory;
|
||||
string done = args[7];
|
||||
List<string> indexFiles;
|
||||
@ -68,6 +97,7 @@ internal static partial class Helper20240623
|
||||
string indexFile = args[5];
|
||||
string searchPattern = args[2];
|
||||
string directoryFilter = args[8];
|
||||
ReadOnlyCollection<string> useLines;
|
||||
string[] tasks = args[6].Split(',');
|
||||
string codeInsiders = $"{args[4]} \"";
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
@ -109,6 +139,7 @@ internal static partial class Helper20240623
|
||||
newLines.Clear();
|
||||
oldLines.Clear();
|
||||
indexLines = File.ReadAllLines(indexFiles[0]);
|
||||
checkDirectory = Path.GetDirectoryName(indexFiles[0]) ?? throw new Exception();
|
||||
for (int i = 0; i < indexLines.Length; i++)
|
||||
{
|
||||
if (indexLines[i] == done)
|
||||
@ -116,10 +147,15 @@ internal static partial class Helper20240623
|
||||
segments = indexLines[i].Split(tasks[1]);
|
||||
if (segments.Length > 2 || !segments[0].StartsWith(tasks[0]))
|
||||
continue;
|
||||
if (foundDone is null || !foundDone.Value)
|
||||
newLines.Add($"- [ ] {segments[0][tasks[0].Length..]}");
|
||||
else
|
||||
newLines.Add($"- [x] {segments[0][tasks[0].Length..]}");
|
||||
fallbackLine = foundDone is null || !foundDone.Value ? $"- [ ] {segments[0][tasks[0].Length..]}" : $"- [x] {segments[0][tasks[0].Length..]}";
|
||||
checkFile = Path.GetFullPath(Path.Combine(checkDirectory, segments[1][..^1]));
|
||||
if (!File.Exists(checkFile))
|
||||
{
|
||||
newLines.Add(fallbackLine);
|
||||
continue;
|
||||
}
|
||||
useLines = GetSubTasks(subTasks, tasks, foundDone, fallbackLine, checkFile);
|
||||
newLines.AddRange(useLines);
|
||||
}
|
||||
if (newLines.Count == 0)
|
||||
continue;
|
||||
|
@ -1,53 +1,27 @@
|
||||
using File_Folder_Helper.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace File_Folder_Helper.Day;
|
||||
|
||||
internal static partial class Helper20240718
|
||||
{
|
||||
|
||||
private record Host([property: JsonPropertyName("a")] string? Id,
|
||||
[property: JsonPropertyName("b")] string? Colon,
|
||||
[property: JsonPropertyName("c")] string? Hyphen,
|
||||
[property: JsonPropertyName("d")] string? Line,
|
||||
[property: JsonPropertyName("e")] string? Count,
|
||||
[property: JsonPropertyName("f")] string? Segments,
|
||||
[property: JsonPropertyName("g")] string? Type,
|
||||
[property: JsonPropertyName("h")] string? Device,
|
||||
[property: JsonPropertyName("i")] string? Name);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, AllowTrailingCommas = true)]
|
||||
[JsonSerializable(typeof(Host[]))]
|
||||
private partial class HostBSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
private record Record(string Key, Dictionary<string, string> KeyValuePairs);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Dictionary<string, Dictionary<string, string>>))]
|
||||
private partial class DictionaryDictionaryBSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
private static Host[] GetHosts(ILogger<Worker> logger, string file)
|
||||
{
|
||||
Host[] results;
|
||||
string lines = File.ReadAllText(file);
|
||||
string json = $"[{lines.Replace("\r\n", ",")}]";
|
||||
logger.LogDebug(lines);
|
||||
JsonSerializerOptions jsonSerializerOptions = new() { AllowTrailingCommas = true };
|
||||
results = JsonSerializer.Deserialize<Host[]>(json, jsonSerializerOptions) ?? throw new NullReferenceException();
|
||||
results = JsonSerializer.Deserialize(json, HostSourceGenerationContext.Default.HostArray) ?? throw new NullReferenceException();
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetLines(Host[] hosts, string argsIP, string title, string wired)
|
||||
private static ReadOnlyCollection<string> GetLines(Host[] hosts, string title, string wired)
|
||||
{
|
||||
List<string> results = ["flowchart LR", $" subgraph {title}"];
|
||||
List<string> results = [$"# {title}", string.Empty, "```mermaid", "flowchart TB", $" subgraph {title}"];
|
||||
int id;
|
||||
string line;
|
||||
string check;
|
||||
List<int> distinct = [];
|
||||
string newLine = $"{Environment.NewLine} ";
|
||||
@ -60,32 +34,41 @@ internal static partial class Helper20240718
|
||||
if (distinct.Contains(id))
|
||||
throw new NotSupportedException($"{id} is not distinct!");
|
||||
distinct.Add(id);
|
||||
line = $"{id}(fa:{host.Type}{newLine}{host.Name}{newLine}{host.Colon}{newLine}{host.Hyphen}{newLine}{host.Device}{newLine}https://{host.Name}/)";
|
||||
results.Add(line);
|
||||
results.Add($" {id}(fa:{host.Type}{newLine}{host.Colon}{newLine}{host.Hyphen}{newLine}{host.Device}{newLine}https://{host.Name}/)");
|
||||
}
|
||||
results.Add(" end");
|
||||
results.Add($" subgraph {title}");
|
||||
foreach (Host host in hosts)
|
||||
foreach (Host host in from l in hosts orderby l.Location, l.Type, l.Line select l)
|
||||
{
|
||||
if (host.Id is null || host.Hyphen is null || host.Device is null || host.Name is null || host.Hyphen.Length != 17)
|
||||
continue;
|
||||
if (!int.TryParse(host.Id, out id))
|
||||
throw new NotSupportedException($"{host.Id} is not a number");
|
||||
check = host.Type == wired ? "-->" : "-.->";
|
||||
line = $"{id} {check} {argsIP}{host.Line}";
|
||||
results.Add(line);
|
||||
results.Add($" {id} {check} |{id}| {host.Location}{host.Type}{host.Line}");
|
||||
}
|
||||
results.Add(" end");
|
||||
results.Add($" subgraph {title}");
|
||||
foreach (Host host in from l in hosts orderby l.Line, l.Location, l.Type select l)
|
||||
{
|
||||
if (host.Id is null || host.Hyphen is null || host.Device is null || host.Name is null || host.Line is null || host.Hyphen.Length != 17)
|
||||
continue;
|
||||
if (!int.TryParse(host.Id, out id))
|
||||
throw new NotSupportedException($"{host.Id} is not a number");
|
||||
check = host.Type == wired ? "-->" : "-.->";
|
||||
results.Add($" {host.Location}{host.Type}{host.Line} {check} Line{host.Line}");
|
||||
}
|
||||
results.Add(" end");
|
||||
results.Add("```");
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
internal static void JsonToMarkdown(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
Host[] hosts;
|
||||
string title = args[4];
|
||||
string wired = args[5];
|
||||
string argsIP = args[3];
|
||||
string extension = args[6];
|
||||
string title = args[3];
|
||||
string wired = args[4];
|
||||
string extension = args[5];
|
||||
string searchPattern = args[2];
|
||||
ReadOnlyCollection<string> lines;
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
@ -93,7 +76,7 @@ internal static partial class Helper20240718
|
||||
foreach (string file in files)
|
||||
{
|
||||
hosts = GetHosts(logger, file);
|
||||
lines = GetLines(hosts, argsIP, title, wired);
|
||||
lines = GetLines(hosts, title, wired);
|
||||
File.WriteAllText($"{file}{extension}", string.Join(Environment.NewLine, lines));
|
||||
}
|
||||
}
|
||||
|
@ -369,7 +369,9 @@ internal static partial class HelperMarkdown
|
||||
private static ReadOnlyDictionary<string, object> GetFromMatterYaml(List<string> lines, LineNumber lineNumber)
|
||||
{
|
||||
Dictionary<string, object> results = [];
|
||||
#pragma warning disable IL3050
|
||||
IDeserializer deserializer = new DeserializerBuilder().Build();
|
||||
#pragma warning restore IL3050
|
||||
ReadOnlyCollection<string> frontMatterYamlLines = GetFromMatterYamlLines(lines, lineNumber);
|
||||
string frontMatterYaml = string.Join(Environment.NewLine, frontMatterYamlLines);
|
||||
Dictionary<string, object>? keyValuePairs = deserializer.Deserialize<Dictionary<string, object>>(frontMatterYaml);
|
||||
@ -693,7 +695,9 @@ internal static partial class HelperMarkdown
|
||||
string frontMatterYaml;
|
||||
MarkdownFile markdownFile;
|
||||
string[] frontMatterYamlLines;
|
||||
#pragma warning disable IL3050
|
||||
ISerializer serializer = new SerializerBuilder().WithIndentedSequences().Build();
|
||||
#pragma warning restore IL3050
|
||||
foreach (KeyValuePair<string, MarkdownFileAndLines> relativeTo in relativeToCollection)
|
||||
{
|
||||
results.Clear();
|
||||
|
20
Models/Host.cs
Normal file
20
Models/Host.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace File_Folder_Helper.Models;
|
||||
|
||||
public record Host([property: JsonPropertyName("a")] string? Id,
|
||||
[property: JsonPropertyName("b")] string? Colon,
|
||||
[property: JsonPropertyName("c")] string? Hyphen,
|
||||
[property: JsonPropertyName("d")] string? Line,
|
||||
[property: JsonPropertyName("e")] string? Count,
|
||||
[property: JsonPropertyName("f")] string? Segments,
|
||||
[property: JsonPropertyName("g")] string? Type,
|
||||
[property: JsonPropertyName("h")] string? Device,
|
||||
[property: JsonPropertyName("i")] string? Name,
|
||||
[property: JsonPropertyName("j")] string? Location);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, AllowTrailingCommas = true)]
|
||||
[JsonSerializable(typeof(Host[]))]
|
||||
public partial class HostSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
@ -12,7 +12,7 @@ internal class Program
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
#pragma warning disable IL3050
|
||||
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
|
||||
HostApplicationBuilder builder = Microsoft.Extensions.Hosting.Host.CreateApplicationBuilder(args);
|
||||
#pragma warning restore IL3050
|
||||
_ = builder.Configuration.AddEnvironmentVariables();
|
||||
_ = builder.Configuration.AddUserSecrets<Program>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user