Moved to ADO2024 PI#
Ran SortCodeMethods
This commit is contained in:
39
ADO2024/PI2/Helper-2024-05-13.cs
Normal file
39
ADO2024/PI2/Helper-2024-05-13.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using File_Folder_Helper.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace File_Folder_Helper.ADO2024.PI2;
|
||||
|
||||
internal static partial class Helper20240513
|
||||
{
|
||||
|
||||
internal static void PersonKeyToName(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
Person? person;
|
||||
string directoryName;
|
||||
string checkDirectory;
|
||||
string root = Path.GetFullPath(args[0]);
|
||||
string json = File.ReadAllText(args[2]);
|
||||
Dictionary<string, Person> keyValuePairs = [];
|
||||
string[] directories = Directory.GetDirectories(root, "*", SearchOption.TopDirectoryOnly);
|
||||
Dictionary<long, Person> people = JsonSerializer.Deserialize(json, PeopleSourceGenerationContext.Default.DictionaryInt64Person) ?? throw new NullReferenceException();
|
||||
foreach (KeyValuePair<long, Person> keyValuePair in people)
|
||||
{
|
||||
if (keyValuePair.Value.Birth?.Note is null)
|
||||
continue;
|
||||
keyValuePairs.Add(keyValuePair.Value.Birth.Note, keyValuePair.Value);
|
||||
}
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
directoryName = Path.GetFileName(directory);
|
||||
if (!keyValuePairs.TryGetValue(directoryName, out person) || person.Name?.ForwardSlashFull is null)
|
||||
continue;
|
||||
checkDirectory = Path.Combine(root, $"{person.Name.ForwardSlashFull.Replace('/', '-')}{directoryName}-{person.Id}");
|
||||
if (Directory.Exists(checkDirectory))
|
||||
continue;
|
||||
Directory.Move(directory, checkDirectory);
|
||||
logger.LogInformation("<{directory}> was moved", directory);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user