2024-11-20 08:16:28 -07:00

57 lines
1.7 KiB
C#

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<FileInfo> fileInfoCollection, ReadOnlyDictionary<string, string> 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<Wafer> 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
{
}