using Adaptation.Shared; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; namespace Adaptation.FileHandlers.pcl; #nullable enable internal class Complete { public Complete(Header header, Wafer[] wafers) { Header = header; Wafers = wafers; } public Header Header { get; } public Wafer[] Wafers { get; } internal static Complete? Get(Logistics logistics, List fileInfoCollection, ReadOnlyDictionary pages) { Complete? result; Constant constant = new(); string headerFileName = pages.ElementAt(pages.Count - 1).Key; Header? header = Header.Get(pages, constant, headerFileName); if (header is null) result = null; else { ReadOnlyCollection wafers = Wafer.Get(pages, constant, headerFileName); if (wafers.Count == 0) result = null; else { result = new(header, wafers.ToArray()); FileInfo fileInfo = new($"{logistics.ReportFullPath}.json"); string json = JsonSerializer.Serialize(result, CompleteSourceGenerationContext.Default.Complete); File.WriteAllText(fileInfo.FullName, json); File.SetLastWriteTime(fileInfo.FullName, logistics.DateTimeFromSequence); fileInfoCollection.Add(fileInfo); } } return result; } } [JsonSourceGenerationOptions(WriteIndented = true)] [JsonSerializable(typeof(Complete))] internal partial class CompleteSourceGenerationContext : JsonSerializerContext { }