Removed updated and created front data
Helper-2023-12-21 -> Helper-2024-01-05
This commit is contained in:
parent
90380fdd43
commit
ccea8de8cf
@ -1,34 +0,0 @@
|
||||
---
|
||||
startedColumns:
|
||||
- 'In Progress'
|
||||
completedColumns:
|
||||
- Done
|
||||
dateFormat: mm/dd
|
||||
taskTemplate: '^+^_${overdue ? ''^R'' : ''''}${name}^: ${relations ? (''\n^-^/^g'' + relations.reduce((accumulator, currentValue) => accumulator.task + currentValue.task + '' '', '''')) : ''''}'
|
||||
created: "2023-10-01T18:07:00.085Z"
|
||||
updated: "2023-10-01T18:07:00.085Z"
|
||||
type: "Kanban"
|
||||
---
|
||||
|
||||
# File File Helper
|
||||
|
||||
## Backlog
|
||||
|
||||
- [markdown-links-to-json](tasks/markdown-links-to-json.md)
|
||||
- [markdown-to-json](tasks/markdown-to-json.md)
|
||||
|
||||
## Todo
|
||||
|
||||
- [find-orphan-links](tasks/find-orphan-links.md)
|
||||
|
||||
## In Progress
|
||||
|
||||
## Done
|
||||
|
||||
- [break-circular-references](tasks/break-circular-references.md)
|
||||
- [populate-a-collection-of-file-info-front-matter-and-first-indent-of-1](tasks/populate-a-collection-of-file-info-front-matter-and-first-indent-of-1.md)
|
||||
- [use-humanizer-on-title-of-links](tasks/use-humanizer-on-title-of-links.md)
|
||||
- [convert-files-to-slug-name](tasks/convert-files-to-slug-name.md)
|
||||
- [convert-wiki-links-to-markdown-links](tasks/convert-wiki-links-to-markdown-links.md)
|
||||
- [add-update-date-in-front-matter](tasks/add-update-date-in-front-matter.md)
|
||||
- [relative-path-to-relative-to-content](tasks/relative-path-to-relative-to-content.md)
|
14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
@ -25,17 +25,3 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
// dotnet build
|
||||
// dotnet run "s" "\\messv02ecc1.ec.local\EC_EDA\Staging\Traces\HTR-PLC\R45-PLC\PollPath"
|
||||
// dotnet run "s" "\\messv02ecc1.ec.local\EC_EDA\Staging\Traces\HTR-PLC\R47-PLC\PollPath"
|
||||
// dotnet run "s" "\\messv02ecc1.ec.local\EC_EDA\Staging\Traces\HTR-PLC\R49-PLC\PollPath"
|
||||
// dotnet run "s" "\\messv02ecc1.ec.local\EC_EDA\Staging\Traces\HTR-PLC\R51-PLC\PollPath"
|
||||
// dotnet run "s" "\\messv02ecc1.ec.local\EC_EDA\Staging\Traces\HTR-PLC\R70-PLC\PollPath"
|
||||
// dotnet run "s" "\\messv02ecc1.ec.local\EC_EDA\Staging\Traces\HTR-PLC\R72-PLC\PollPath"
|
||||
// dotnet run "s" "\\messv02ecc1.ec.local\EC_EDA\Staging\Traces\HTR-PLC\R73-PLC\PollPath"
|
||||
// dotnet run "s" "\\messv02ecc1.ec.local\EC_EDA\Staging\Traces\HTR-PLC\R74-PLC\PollPath"
|
||||
// dotnet run "s" "C:/Users/phares/.nuget/packages"
|
||||
// dotnet run "s" "D:/ProgramData/EC_EAFRepository/nupkg"
|
||||
// dotnet run "s" "D:/Baget/packages"
|
||||
// dotnet run "s" "\\messdv002.na.infineon.com\Candela\BaGet\packages"
|
||||
// dotnet run "s" "T:/MESAFIBACKLOG/06_SourceCode/MESAFIBACKLOG/Adaptation/.kanbn"
|
@ -1,295 +0,0 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace File_Folder_Helper.Day;
|
||||
|
||||
internal static partial class Helper20231221
|
||||
{
|
||||
|
||||
// Folders with these names will be put in the root instead.
|
||||
private static readonly string[] _BlacklistedFolders =
|
||||
[
|
||||
"KeePassHttp Passwords",
|
||||
"KeePassXC-Browser Passwords"
|
||||
];
|
||||
|
||||
private static readonly string[] _BlacklistedFields = [
|
||||
"KeePassXC-Browser Settings",
|
||||
"KeePassHttp Settings"
|
||||
];
|
||||
|
||||
private static Func<XElement, bool> OtherFields()
|
||||
{
|
||||
return x =>
|
||||
{
|
||||
string? key = x.Element("Key")?.Value;
|
||||
return key != "Title" && key != "Notes" && key != "UserName" && key != "Password" &&
|
||||
key != "URL" && !_BlacklistedFields.Contains(key);
|
||||
};
|
||||
}
|
||||
|
||||
private record Field(
|
||||
[property: JsonPropertyName("name")] string? Name,
|
||||
[property: JsonPropertyName("value")] string? Value,
|
||||
[property: JsonPropertyName("type")] int? Type
|
||||
);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Field))]
|
||||
private partial class FieldSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
private record Folder(
|
||||
[property: JsonPropertyName("id")] string? Id,
|
||||
[property: JsonPropertyName("name")] string? Name
|
||||
);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Folder))]
|
||||
private partial class FolderSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
private record Item(
|
||||
[property: JsonPropertyName("revisionDate")] string? RevisionDate,
|
||||
[property: JsonPropertyName("creationDate")] string? CreationDate,
|
||||
[property: JsonPropertyName("folderId")] string? FolderId,
|
||||
[property: JsonPropertyName("type")] int Type,
|
||||
[property: JsonPropertyName("name")] string? Name,
|
||||
[property: JsonPropertyName("notes")] string? Notes,
|
||||
[property: JsonPropertyName("fields")] IReadOnlyList<Field>? Fields,
|
||||
[property: JsonPropertyName("login")] Login Login
|
||||
);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Item))]
|
||||
private partial class ItemSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
private record Login(
|
||||
[property: JsonPropertyName("uris")] IReadOnlyList<Uri> Uris,
|
||||
[property: JsonPropertyName("username")] string? Username,
|
||||
[property: JsonPropertyName("password")] string? Password
|
||||
);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Login))]
|
||||
private partial class LoginSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
private record Root(
|
||||
[property: JsonPropertyName("folders")] IReadOnlyList<Folder> Folders,
|
||||
[property: JsonPropertyName("items")] IReadOnlyList<Item> Items
|
||||
);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Root))]
|
||||
private partial class RootSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
private record Uri(
|
||||
[property: JsonPropertyName("uri")] string? Value,
|
||||
[property: JsonPropertyName("host")] string? Host
|
||||
);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Uri))]
|
||||
private partial class UriSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
private static Item? GetEntry(string folderId, XElement entry)
|
||||
{
|
||||
Item? result;
|
||||
XElement[] stringFields = entry.Elements("String").ToArray();
|
||||
string? name = stringFields.Where(x => x.Element("Key")?.Value == "Title").Select(x => x.Element("Value")?.Value).FirstOrDefault();
|
||||
if (_BlacklistedFields.Contains(name))
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
XElement[] timesFields = entry.Elements("Times").ToArray();
|
||||
string? creationTime = timesFields.Elements("CreationTime").FirstOrDefault()?.Value;
|
||||
string? revisionDate = timesFields.Elements("LastModificationTime").FirstOrDefault()?.Value;
|
||||
string? uri = stringFields.Where(x => x.Element("Key")?.Value == "URL").Select(x => x.Element("Value")?.Value).FirstOrDefault();
|
||||
string? notes = stringFields.Where(x => x.Element("Key")?.Value == "Notes").Select(x => x.Element("Value")?.Value).FirstOrDefault();
|
||||
string? username = stringFields.Where(x => x.Element("Key")?.Value == "UserName").Select(x => x.Element("Value")?.Value).FirstOrDefault();
|
||||
string? password = stringFields.Where(x => x.Element("Key")?.Value == "Password").Select(x => x.Element("Value")?.Value).FirstOrDefault();
|
||||
string? host = string.IsNullOrEmpty(uri) || !uri.Contains(':') ? null : new System.Uri(uri).Host;
|
||||
Login login = new(new Uri[] { new(uri, host) }, username, password);
|
||||
List<Field> itemFields = stringFields.Where(OtherFields()).Select(x => new Field(x.Element("Key")?.Value, x.Element("Value")?.Value, 0)).ToList();
|
||||
result = new(revisionDate,
|
||||
creationTime,
|
||||
folderId,
|
||||
1,
|
||||
name,
|
||||
string.IsNullOrEmpty(notes) ? null : notes,
|
||||
itemFields.Count > 0 ? itemFields : null,
|
||||
login);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Item> Filter(List<Item> items)
|
||||
{
|
||||
List<Item> results = [];
|
||||
string key;
|
||||
Item result;
|
||||
Login login;
|
||||
string? uri;
|
||||
string? host;
|
||||
string? name;
|
||||
string? folderId;
|
||||
string? username;
|
||||
List<Item>? check;
|
||||
string? creationTime;
|
||||
string? revisionDate;
|
||||
List<string> notes = [];
|
||||
string? password = null;
|
||||
string?[] checkPasswords;
|
||||
Dictionary<string, List<Item>> keyValuePairs = [];
|
||||
foreach (Item item in items)
|
||||
{
|
||||
key = string.Concat(item.Login.Username, '-', string.Join('-', item.Login.Uris.Select(l => l.Host)));
|
||||
if (!keyValuePairs.TryGetValue(key, out check))
|
||||
{
|
||||
keyValuePairs.Add(key, []);
|
||||
if (!keyValuePairs.TryGetValue(key, out check))
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
check.Add(item);
|
||||
}
|
||||
foreach (KeyValuePair<string, List<Item>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
if (keyValuePair.Value.Count == 1)
|
||||
results.AddRange(keyValuePair.Value);
|
||||
else
|
||||
{
|
||||
checkPasswords = keyValuePair.Value.Select(l => l.Login.Password).Distinct().ToArray();
|
||||
if (checkPasswords.Length == 1)
|
||||
results.Add(keyValuePair.Value[0]);
|
||||
else
|
||||
{
|
||||
uri = null;
|
||||
host = null;
|
||||
name = null;
|
||||
notes.Clear();
|
||||
folderId = null;
|
||||
username = null;
|
||||
creationTime = null;
|
||||
revisionDate = null;
|
||||
notes.Add("Unset Password");
|
||||
foreach (Item item in from l in keyValuePair.Value orderby l.RevisionDate, l.Login.Password?.Length descending select l)
|
||||
{
|
||||
if (item.Login.Uris.Count == 1)
|
||||
{
|
||||
uri = item.Login.Uris[0].Value;
|
||||
host = item.Login.Uris[0].Host;
|
||||
}
|
||||
name = item.Name;
|
||||
folderId = item.FolderId;
|
||||
username = item.Login.Username;
|
||||
creationTime = item.CreationDate;
|
||||
revisionDate = item.RevisionDate;
|
||||
notes.Add($"{item.Login.Password} on {item.RevisionDate}");
|
||||
}
|
||||
login = new(new Uri[] { new(uri, host) }, username, password);
|
||||
result = new(revisionDate,
|
||||
creationTime,
|
||||
folderId,
|
||||
1,
|
||||
name,
|
||||
string.Join(Environment.NewLine, notes),
|
||||
null,
|
||||
login);
|
||||
results.Add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
results = (from l in results orderby l.Login.Uris[0].Host, l.Login.Username select l).ToList();
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void SaveTabSeparatedValueFiles(List<Item> items, string xmlFile)
|
||||
{
|
||||
List<string> lines = [];
|
||||
foreach (Item item in items)
|
||||
lines.Add($"{item.Login.Uris[0].Host}\t{item.Login.Username}\t{item.Login.Password}");
|
||||
File.WriteAllLines(Path.ChangeExtension(xmlFile, ".tvs"), lines);
|
||||
}
|
||||
|
||||
internal static void ConvertKeePassExport(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
Root root;
|
||||
Item? item;
|
||||
string json;
|
||||
string folderId;
|
||||
string groupKey;
|
||||
List<Item> items;
|
||||
XElement element;
|
||||
string newGroupKey;
|
||||
XDocument xDocument;
|
||||
List<Folder> folders;
|
||||
string childGroupName;
|
||||
string outputPath = args[0];
|
||||
string newExtension = args[3];
|
||||
IEnumerable<XElement> childEntries;
|
||||
IEnumerable<XElement> childElements;
|
||||
Dictionary<string, string> namesToIds;
|
||||
Queue<KeyValuePair<string, XElement>> groupsToProcess;
|
||||
string[] xmlFiles = Directory.GetFiles(args[0], args[2]);
|
||||
foreach (string xmlFile in xmlFiles)
|
||||
{
|
||||
xDocument = XDocument.Load(xmlFile);
|
||||
if (xDocument.Root is null)
|
||||
throw new Exception("Root element missing");
|
||||
items = [];
|
||||
folders = [];
|
||||
namesToIds = [];
|
||||
groupsToProcess = [];
|
||||
logger.LogInformation($"Loaded XML {xmlFile}.", xmlFile);
|
||||
groupsToProcess.Enqueue(new KeyValuePair<string, XElement>("", xDocument.Root.Descendants("Group").First()));
|
||||
while (groupsToProcess.TryDequeue(out KeyValuePair<string, XElement> valuePair))
|
||||
{
|
||||
groupKey = valuePair.Key;
|
||||
element = valuePair.Value;
|
||||
folderId = Guid.NewGuid().ToString();
|
||||
childElements = element.Elements("Group");
|
||||
folders.Add(new Folder(folderId, groupKey));
|
||||
foreach (XElement childElement in childElements)
|
||||
{
|
||||
childGroupName = (childElement.Element("Name")?.Value) ?? throw new Exception("Found group with no name, malformed file");
|
||||
if (_BlacklistedFolders.Contains(childGroupName))
|
||||
childGroupName = "";
|
||||
newGroupKey = $"{groupKey}/{childGroupName}";
|
||||
if (groupKey == "")
|
||||
newGroupKey = childGroupName;
|
||||
logger.LogInformation($"Found group '{newGroupKey}'");
|
||||
groupsToProcess.Enqueue(new KeyValuePair<string, XElement>(newGroupKey, childElement));
|
||||
}
|
||||
childEntries = element.Elements("Entry");
|
||||
foreach (XElement entry in childEntries)
|
||||
{
|
||||
item = GetEntry(folderId, entry);
|
||||
if (item is null)
|
||||
continue;
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
items = Filter(items);
|
||||
root = new(folders, items);
|
||||
logger.LogInformation("Serializing output file...");
|
||||
json = JsonSerializer.Serialize(root, RootSourceGenerationContext.Default.Root);
|
||||
logger.LogInformation("Writing output file...");
|
||||
File.WriteAllText(Path.ChangeExtension(xmlFile, newExtension), json);
|
||||
SaveTabSeparatedValueFiles(items, xmlFile);
|
||||
}
|
||||
logger.LogInformation("Done!");
|
||||
}
|
||||
|
||||
}
|
1347
Day/Helper-2024-01-05.cs
Normal file
1347
Day/Helper-2024-01-05.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -30,10 +30,10 @@ internal static class HelperDay
|
||||
Day.Helper20231205.SplitMarkdownFile(logger, args);
|
||||
else if (args[1] == "Day-Helper-2023-12-12")
|
||||
Day.Helper20231212.SplitJsonFile(logger, args);
|
||||
else if (args[1] == "Day-Helper-2023-12-21")
|
||||
Day.Helper20231221.ConvertKeePassExport(logger, args);
|
||||
else if (args[1] == "Day-Helper-2023-12-22")
|
||||
Day.Helper20231222.ConvertId(logger, args);
|
||||
else if (args[1] == "Day-Helper-2024-01-05")
|
||||
Day.Helper20240105.ConvertKeePassExport(logger, args);
|
||||
else
|
||||
throw new Exception(appSettings.Company);
|
||||
}
|
||||
|
@ -1282,12 +1282,7 @@ internal static partial class HelperMarkdown
|
||||
string h1Line;
|
||||
string[] lines;
|
||||
string typeLine;
|
||||
string createdLine;
|
||||
string updatedLine;
|
||||
DateTime creationDateTime;
|
||||
MarkdownFile markdownFile;
|
||||
string createdLineCompare;
|
||||
string updatedLineCompare;
|
||||
foreach (KeyValuePair<string, MarkdownFileAndLines> relativeTo in relativeToCollection)
|
||||
{
|
||||
if (relativeTo.Value.Lines.Length == 0)
|
||||
@ -1296,13 +1291,8 @@ internal static partial class HelperMarkdown
|
||||
lines = relativeTo.Value.Lines;
|
||||
markdownFile = relativeTo.Value.MarkdownFile;
|
||||
results.AddRange(lines);
|
||||
creationDateTime = markdownFile.CreationDateTime > markdownFile.LastWriteDateTime ? markdownFile.LastWriteDateTime : markdownFile.CreationDateTime;
|
||||
typeLine = $"type: \"{appSettings.DefaultNoteType}\"";
|
||||
h1Line = $"# {markdownFile.FileNameWithoutExtension}";
|
||||
createdLineCompare = $"created: \"{creationDateTime.ToUniversalTime():yyyy-MM-dd}T";
|
||||
createdLine = $"created: \"{creationDateTime.ToUniversalTime():yyyy-MM-ddTHH:mm:ss.fffZ}\"";
|
||||
updatedLineCompare = $"updated: \"{markdownFile.LastWriteDateTime.ToUniversalTime():yyyy-MM-dd}T";
|
||||
updatedLine = $"updated: \"{markdownFile.LastWriteDateTime.ToUniversalTime():yyyy-MM-ddTHH:mm:ss.fffZ}\"";
|
||||
if (markdownFile.LineNumber.FrontMatterYamlEnd is null)
|
||||
{
|
||||
if (markdownFile.LineNumber.H1 is null)
|
||||
@ -1312,8 +1302,6 @@ internal static partial class HelperMarkdown
|
||||
results.Insert(0, string.Empty);
|
||||
}
|
||||
results.Insert(0, "---");
|
||||
results.Insert(0, updatedLine);
|
||||
results.Insert(0, createdLine);
|
||||
results.Insert(0, typeLine);
|
||||
results.Insert(0, "---");
|
||||
}
|
||||
@ -1327,20 +1315,8 @@ internal static partial class HelperMarkdown
|
||||
}
|
||||
if (markdownFile.LineNumber.Type is null)
|
||||
results.Insert(markdownFile.LineNumber.FrontMatterYamlEnd.Value, typeLine);
|
||||
if (markdownFile.LineNumber.Updated is null)
|
||||
results.Insert(markdownFile.LineNumber.FrontMatterYamlEnd.Value, updatedLine);
|
||||
else
|
||||
{
|
||||
if (results[markdownFile.LineNumber.Updated.Value].Contains('$'))
|
||||
if (markdownFile.LineNumber.H1 is not null && markdownFile.LineNumber.Type is not null)
|
||||
continue;
|
||||
if (results[markdownFile.LineNumber.Updated.Value][..updatedLineCompare.Length] == updatedLineCompare)
|
||||
continue;
|
||||
results[markdownFile.LineNumber.Updated.Value] = updatedLine;
|
||||
}
|
||||
if (markdownFile.LineNumber.Created is null)
|
||||
results.Insert(markdownFile.LineNumber.FrontMatterYamlEnd.Value, createdLine);
|
||||
else if (results[markdownFile.LineNumber.Created.Value][..createdLineCompare.Length] != createdLineCompare)
|
||||
results[markdownFile.LineNumber.Created.Value] = createdLine;
|
||||
}
|
||||
File.WriteAllLines(markdownFile.File, results);
|
||||
File.SetLastWriteTime(markdownFile.File, markdownFile.LastWriteDateTime);
|
||||
|
Loading…
x
Reference in New Issue
Block a user