using File_Folder_Helper.Models; using Microsoft.Extensions.Logging; using System.Text.Json; namespace File_Folder_Helper.Day; internal static partial class Helper20240518 { internal static void PersonKeyToImmichImport(ILogger logger, List args) { string name; string birthDate; string ownerId = args[5]; List inserts = []; string tableName = args[3]; string birthDateFormat = args[6]; string[] columns = args[4].Split(','); string json = File.ReadAllText(args[2]); string root = Path.GetFullPath(args[0]); Dictionary people = JsonSerializer.Deserialize(json, PeopleSourceGenerationContext.Default.DictionaryInt64Person) ?? throw new NullReferenceException(); foreach (KeyValuePair keyValuePair in people) { if (keyValuePair.Value.Birth?.Note is null || keyValuePair.Value.Name?.ForwardSlashFull is null || keyValuePair.Value.Birth?.Date is null) continue; birthDate = keyValuePair.Value.Birth.Date.Value.ToString(birthDateFormat); name = keyValuePair.Value.Name.ForwardSlashFull.Replace("/", string.Empty); inserts.Add($"insert into \"{tableName}\" (\"{string.Join("\", \"", columns)}\") values ('{ownerId}', '{name}', '{birthDate}');"); } string file = Path.Combine(root, $"{DateTime.Now.Ticks}.sql"); logger.LogInformation("<{file}> saved", file); File.WriteAllLines(file, inserts); } }