diff --git a/Adaptation/FileHandlers/Archive/FileRead.cs b/Adaptation/FileHandlers/Archive/FileRead.cs index 0e79541..6dfdff4 100644 --- a/Adaptation/FileHandlers/Archive/FileRead.cs +++ b/Adaptation/FileHandlers/Archive/FileRead.cs @@ -115,10 +115,10 @@ public class FileRead : Shared.FileRead, IFileRead } } -#pragma warning disable IDE0060 private void MoveArchive(string reportFullPath, DateTime dateTime) -#pragma warning restore IDE0060 { + if (dateTime == DateTime.MinValue) + throw new ArgumentNullException(nameof(dateTime)); string logisticsSequence = _Logistics.Sequence.ToString(); string weekOfYear = _Calendar.GetWeekOfYear(_Logistics.DateTimeFromSequence, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00"); string weekDirectory = $"{_Logistics.DateTimeFromSequence:yyyy}_Week_{weekOfYear}{@"\"}{_Logistics.DateTimeFromSequence:yyyy-MM-dd}"; diff --git a/Adaptation/FileHandlers/OpenInsightMetrologyViewerAttachments/FileRead.cs b/Adaptation/FileHandlers/OpenInsightMetrologyViewerAttachments/FileRead.cs index db31681..c44e174 100644 --- a/Adaptation/FileHandlers/OpenInsightMetrologyViewerAttachments/FileRead.cs +++ b/Adaptation/FileHandlers/OpenInsightMetrologyViewerAttachments/FileRead.cs @@ -163,10 +163,10 @@ public class FileRead : Shared.FileRead, IFileRead OpenInsightMetrologyViewer.WSRequest.PostOpenInsightMetrologyViewerAttachments(this, _Logistics, _OpenInsightMetrologyViewerAPI, descriptions, matchDirectories[0], subGroupId, headerId, headerIdDirectory); } -#pragma warning disable IDE0060 private Tuple> GetExtractResult(string reportFullPath, DateTime dateTime) -#pragma warning restore IDE0060 { + if (dateTime == DateTime.MinValue) + throw new ArgumentNullException(nameof(dateTime)); Tuple> results; Tuple pdsf = ProcessDataStandardFormat.GetLogisticsColumnsAndBody(reportFullPath); _Logistics = new Logistics(reportFullPath, pdsf.Item1); diff --git a/Adaptation/FileHandlers/Processed/FileRead.cs b/Adaptation/FileHandlers/Processed/FileRead.cs index 31718eb..58ce540 100644 --- a/Adaptation/FileHandlers/Processed/FileRead.cs +++ b/Adaptation/FileHandlers/Processed/FileRead.cs @@ -108,10 +108,10 @@ public class FileRead : Shared.FileRead, IFileRead return results; } -#pragma warning disable IDE0060 private void DirectoryMove(string reportFullPath, DateTime dateTime, List descriptions) -#pragma warning restore IDE0060 { + if (dateTime == DateTime.MinValue) + throw new ArgumentNullException(nameof(dateTime)); FileInfo fileInfo = new(reportFullPath); string logisticsSequence = _Logistics.Sequence.ToString(); string jobIdDirectory = Path.Combine(_JobIdParentDirectory, _Logistics.JobID); diff --git a/Adaptation/FileHandlers/QS408M/Complete.cs b/Adaptation/FileHandlers/QS408M/Complete.cs index e574a49..720dbc9 100644 --- a/Adaptation/FileHandlers/QS408M/Complete.cs +++ b/Adaptation/FileHandlers/QS408M/Complete.cs @@ -1,4 +1,8 @@ +using Adaptation.Shared; using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; using System.Text.Json.Serialization; namespace Adaptation.FileHandlers.QS408M; @@ -60,11 +64,12 @@ internal class Complete return result; } - internal static Complete? Get(Header lastHeader, string text) + internal static Complete? Get(Logistics logistics, List fileInfoCollection, Header[] lastHeader) { Complete? result; int[] i = new int[] { 0 }; - Header? header = Header.Get(lastHeader, text, i); + string text = File.ReadAllText(logistics.ReportFullPath); + Header? header = Header.Get(lastHeader[0], text, i); if (header is null) result = null; else @@ -78,7 +83,14 @@ internal class Complete if (footer is null) result = null; else + { result = new(header, body, footer); + 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; diff --git a/Adaptation/FileHandlers/QS408M/FileRead.cs b/Adaptation/FileHandlers/QS408M/FileRead.cs index 7f36eca..8e53f48 100644 --- a/Adaptation/FileHandlers/QS408M/FileRead.cs +++ b/Adaptation/FileHandlers/QS408M/FileRead.cs @@ -84,7 +84,7 @@ public class FileRead : Shared.FileRead, IFileRead DateTime dateTime = DateTime.Now; results = GetExtractResult(reportFullPath, dateTime); if (results.Item3 is null) - results = new Tuple>(results.Item1, Array.Empty(), JsonSerializer.Deserialize("[]") ?? throw new Exception(), results.Item4); + results = new Tuple>(results.Item1, Array.Empty(), Array.Empty(), results.Item4); if (results.Item3.Length > 0 && _IsEAFHosted) WritePDSF(this, results.Item3); UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks); @@ -100,19 +100,24 @@ public class FileRead : Shared.FileRead, IFileRead return results; } +#nullable enable + private Tuple> GetExtractResult(string reportFullPath, DateTime dateTime) { - Tuple> results = new(string.Empty, Array.Empty(), JsonSerializer.Deserialize("[]") ?? throw new Exception(), new List()); - _TickOffset ??= new FileInfo(reportFullPath).LastWriteTime.Ticks - dateTime.Ticks; + Tuple> results = new(string.Empty, Array.Empty(), Array.Empty(), new List()); + _TickOffset ??= 0; // new FileInfo(reportFullPath).LastWriteTime.Ticks - dateTime.Ticks; _Logistics = new Logistics(this, _TickOffset.Value, reportFullPath, useSplitForMID: true); SetFileParameterLotIDToLogisticsMID(); if (_Logistics.FileInfo.Length < _MinFileLength) results.Item4.Add(_Logistics.FileInfo); else { - IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, _OriginalDataBioRad, lastHeader: _LastHeader, tickOffset: _TickOffset.Value); - if (iProcessData is not ProcessData processData) + Complete? complete = Complete.Get(_Logistics, results.Item4, lastHeader: _LastHeader); + IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, _OriginalDataBioRad, _TickOffset.Value, complete); + if (complete is null) throw new Exception(string.Concat("A) No Data - ", dateTime.Ticks)); + if (iProcessData is not ProcessData processData) + throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks)); string mid; if (!string.IsNullOrEmpty(processData.Wafer) && string.IsNullOrEmpty(processData.Reactor) && string.IsNullOrEmpty(processData.RDS) && string.IsNullOrEmpty(processData.PSN)) mid = processData.Wafer; @@ -126,7 +131,7 @@ public class FileRead : Shared.FileRead, IFileRead SetFileParameterLotID(mid); _Logistics.Update(mid, processData.Reactor); if (iProcessData.Details.Count == 0) - throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks)); + throw new Exception(string.Concat("C) No Data - ", dateTime.Ticks)); results = iProcessData.GetResults(this, _Logistics, results.Item4); } return results; diff --git a/Adaptation/FileHandlers/QS408M/ProcessData.cs b/Adaptation/FileHandlers/QS408M/ProcessData.cs index 99461b6..b0fe179 100644 --- a/Adaptation/FileHandlers/QS408M/ProcessData.cs +++ b/Adaptation/FileHandlers/QS408M/ProcessData.cs @@ -1,6 +1,5 @@ using Adaptation.Shared; using Adaptation.Shared.Methods; -using log4net; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -52,27 +51,32 @@ public partial class ProcessData : IProcessData List Shared.Properties.IProcessData.Details => _Details; - private readonly ILog _Log; - public ProcessData() { } #nullable enable - public ProcessData(IFileRead fileRead, Logistics logistics, List fileInfoCollection, string originalDataBioRad, Header[] lastHeader, long tickOffset) + internal ProcessData(IFileRead fileRead, Logistics logistics, List fileInfoCollection, string originalDataBioRad, long tickOffset, Complete? complete) { + if (fileRead is null) + throw new ArgumentNullException(nameof(fileRead)); JobID = logistics.JobID; - fileInfoCollection.Clear(); _Details = new List(); + List moveFiles = new(); MesEntity = logistics.MesEntity; - _Log = LogManager.GetLogger(typeof(ProcessData)); - Complete? complete = Parse(fileRead, logistics, fileInfoCollection, originalDataBioRad, lastHeader); + string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(logistics.ReportFullPath); + string directoryName = Path.GetDirectoryName(logistics.ReportFullPath) ?? throw new Exception(); + moveFiles.AddRange(Directory.GetFiles(directoryName, string.Concat(originalDataBioRad, "*", logistics.Sequence, "*"), SearchOption.TopDirectoryOnly)); + moveFiles.AddRange(Directory.GetFiles(directoryName, string.Concat(originalDataBioRad, "*", fileNameWithoutExtension.Split('_').Last(), "*"), SearchOption.TopDirectoryOnly)); + foreach (string moveFile in moveFiles.Distinct()) + fileInfoCollection.Add(new FileInfo(moveFile)); + fileInfoCollection.Add(logistics.FileInfo); if (complete is not null) SetValues(logistics, tickOffset, complete); } - string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary reactors) => throw new Exception(string.Concat("See ", nameof(Parse))); + string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary reactors) => throw new Exception(string.Concat("See ", nameof(ProcessData))); Tuple> IProcessData.GetResults(IFileRead fileRead, Logistics logistics, List fileInfoCollection) { @@ -247,34 +251,6 @@ public partial class ProcessData : IProcessData return result; } - private Complete? Parse(IFileRead fileRead, Logistics logistics, List fileInfoCollection, string originalDataBioRad, Header[] lastHeader) - { - if (fileRead is null) - throw new ArgumentNullException(nameof(fileRead)); - Complete? result; - List moveFiles = new(); - string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(logistics.ReportFullPath); - string directoryName = Path.GetDirectoryName(logistics.ReportFullPath) ?? throw new Exception(); - moveFiles.AddRange(Directory.GetFiles(directoryName, string.Concat(originalDataBioRad, "*", logistics.Sequence, "*"), SearchOption.TopDirectoryOnly)); - moveFiles.AddRange(Directory.GetFiles(directoryName, string.Concat(originalDataBioRad, "*", fileNameWithoutExtension.Split('_').Last(), "*"), SearchOption.TopDirectoryOnly)); - foreach (string moveFile in moveFiles.Distinct()) - fileInfoCollection.Add(new FileInfo(moveFile)); - string receivedData = File.ReadAllText(logistics.ReportFullPath); - result = Complete.Get(lastHeader[0], receivedData); - if (result is null) - _Log.Warn($"Could not get Complete from {fileNameWithoutExtension}"); - else - { - FileInfo fileInfo = new($"{fileNameWithoutExtension}.json"); - string json = JsonSerializer.Serialize(result, CompleteSourceGenerationContext.Default.Complete); - File.WriteAllText(fileInfo.FullName, json); - fileInfoCollection.Add(fileInfo); - lastHeader[0] = result.Header; - } - fileInfoCollection.Add(logistics.FileInfo); - return result; - } - private void SetValues(Logistics logistics, long tickOffset, Complete complete) { int slot = 0;