diff --git a/Day/Q32024/Helper-2024-08-28.cs b/Day/Q32024/Helper-2024-08-28.cs index 3d0d3f1..30e91c9 100644 --- a/Day/Q32024/Helper-2024-08-28.cs +++ b/Day/Q32024/Helper-2024-08-28.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; using System.Collections.ObjectModel; using System.Globalization; using System.Text.Json; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; namespace File_Folder_Helper.Day.Q32024; @@ -20,6 +21,12 @@ internal static partial class Helper20240828 string? Recipe, string? Zone); + [JsonSourceGenerationOptions(WriteIndented = true)] + [JsonSerializable(typeof(HeaderCommon))] + internal partial class HeaderCommonSourceGenerationContext : JsonSerializerContext + { + } + public record Record(string? CassetteId, ReadOnlyCollection? CassetteSegments, DateTime? Date, @@ -167,7 +174,6 @@ internal static partial class Helper20240828 string logDirectory = Path.GetFullPath(args[0]); string sourceDirectory = Path.GetFullPath(args[4]); string archiveDirectory = Path.GetFullPath(args[6]); - JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true }; FileInfo[] collection = Directory.GetFiles(sourceDirectory, wcSearchPattern, SearchOption.AllDirectories).Select(l => new FileInfo(l)).ToArray(); logger.LogInformation("Found {collection}(s)", collection.Length); foreach (FileInfo fileInfo in collection) @@ -192,7 +198,7 @@ internal static partial class Helper20240828 if (File.Exists(checkFile)) continue; headerCommon = new(fileInfo.LastWriteTime, null, null, null, null, quantity, runDataSheet, null, recipe, null); - json = JsonSerializer.Serialize(headerCommon, jsonSerializerOptions); + json = JsonSerializer.Serialize(headerCommon, HeaderCommonSourceGenerationContext.Default.HeaderCommon); File.Move(fileInfo.FullName, checkFile); File.Delete(keyFile); checkFile = Path.Combine(checkDirectory, $"{fileInfo.Name}.json"); diff --git a/Day/Q32024/Helper-2024-09-11.cs b/Day/Q32024/Helper-2024-09-11.cs index d139ef9..1b2fd6a 100644 --- a/Day/Q32024/Helper-2024-09-11.cs +++ b/Day/Q32024/Helper-2024-09-11.cs @@ -16,6 +16,12 @@ internal static partial class Helper20240911 public record Record(WorkItem WorkItem, ReadOnlyDictionary Children); + [JsonSourceGenerationOptions(WriteIndented = true)] + [JsonSerializable(typeof(Record))] + internal partial class RecordCommonSourceGenerationContext : JsonSerializerContext + { + } + public record WorkItem(string AreaPath, string? AssignedTo, int? BusinessValue, @@ -222,7 +228,7 @@ internal static partial class Helper20240911 logger.LogInformation("With search pattern '{SearchPattern}' found {files} workItemAndChildren", searchPattern, workItemAndChildren.Count); if (workItemAndChildren.Count == -1) { - string json = JsonSerializer.Serialize(workItemAndChildren, new JsonSerializerOptions() { WriteIndented = true }); + string json = JsonSerializer.Serialize(workItemAndChildren, RecordCommonSourceGenerationContext.Default.ReadOnlyDictionaryInt32Record); File.WriteAllText(".json", json); } foreach (string workItemType in workItemTypes)