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 6f3df00..095e0ca 100644 --- a/Adaptation/FileHandlers/OpenInsightMetrologyViewerAttachments/FileRead.cs +++ b/Adaptation/FileHandlers/OpenInsightMetrologyViewerAttachments/FileRead.cs @@ -165,10 +165,10 @@ public class FileRead : Shared.FileRead, IFileRead OpenInsightMetrologyViewer.WSRequest.PostOpenInsightMetrologyViewerAttachments(this, _Logistics, _OpenInsightMetrologyViewerAPI, _OriginalDataBioRad, 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 3a2a000..247289b 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/Stratus/Complete.cs b/Adaptation/FileHandlers/Stratus/Complete.cs index 6a5496a..92bbd2c 100644 --- a/Adaptation/FileHandlers/Stratus/Complete.cs +++ b/Adaptation/FileHandlers/Stratus/Complete.cs @@ -1,5 +1,9 @@ +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.Stratus; @@ -20,10 +24,12 @@ internal class Complete public Wafer[] Wafers { get; } public Footer Footer { get; } - internal static Complete? Get(string text, Constant constant) + internal static Complete? Get(Logistics logistics, List fileInfoCollection) { Complete? result; + Constant constant = new(); int[] i = new int[] { 0 }; + string text = File.ReadAllText(logistics.ReportFullPath); Header? header = Header.Get(text, constant, i); if (header is null) result = null; @@ -43,7 +49,14 @@ internal class Complete if (footer is null) result = null; else + { result = new(header, wafers.ToArray(), 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); + } } } } diff --git a/Adaptation/FileHandlers/Stratus/FileRead.cs b/Adaptation/FileHandlers/Stratus/FileRead.cs index 94b1df2..0581b86 100644 --- a/Adaptation/FileHandlers/Stratus/FileRead.cs +++ b/Adaptation/FileHandlers/Stratus/FileRead.cs @@ -98,9 +98,11 @@ public class FileRead : Shared.FileRead, IFileRead return results; } +#nullable enable + private Tuple> GetExtractResult(string reportFullPath, DateTime dateTime) { - Tuple> results = new(string.Empty, null, null, new List()); + 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(); @@ -108,9 +110,12 @@ public class FileRead : Shared.FileRead, IFileRead results.Item4.Add(_Logistics.FileInfo); else { - IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, _OriginalDataBioRad, dataText: string.Empty); - if (iProcessData is not ProcessData processData) + Complete? complete = Complete.Get(_Logistics, results.Item4); + if (complete is null) throw new Exception(string.Concat("A) No Data - ", dateTime.Ticks)); + IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, _OriginalDataBioRad, complete, dataText: string.Empty); + if (iProcessData is not ProcessData processData) + throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks)); string mid; if (!string.IsNullOrEmpty(processData.Cassette) && string.IsNullOrEmpty(processData.Reactor) && string.IsNullOrEmpty(processData.RDS) && string.IsNullOrEmpty(processData.PSN)) mid = processData.Cassette; @@ -124,7 +129,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)); if (iProcessData.Details[0] is Detail detail && string.IsNullOrEmpty(detail.PassFail)) results.Item4.Add(_Logistics.FileInfo); else diff --git a/Adaptation/FileHandlers/Stratus/Footer.cs b/Adaptation/FileHandlers/Stratus/Footer.cs index b148b89..1a17c85 100644 --- a/Adaptation/FileHandlers/Stratus/Footer.cs +++ b/Adaptation/FileHandlers/Stratus/Footer.cs @@ -1,5 +1,3 @@ -using log4net; -using System; using System.Collections.ObjectModel; namespace Adaptation.FileHandlers.Stratus; @@ -18,47 +16,6 @@ public class Footer public string MeanThickness { get; } public string StdDev { get; } - private static string GetBefore(string text, int[] i, string search, bool trim) - { - string str; - string before; - if (trim) - before = Header.GetBefore(text, i, search); - else - { - int num = text.IndexOf(search, i[0]); - if (num <= -1) - { - str = text.Substring(i[0]); - i[0] = text.Length; - before = str; - } - else - { - str = text.Substring(i[0], num - i[0]); - i[0] = num + search.Length; - before = str; - } - } - return before; - } - - private static string GetToEOL(string text, int[] i, bool trim) - { - string str; - if (text.IndexOf("\n", i[0]) > -1) - str = !trim ? GetBefore(text, i, "\n", false) : Header.GetToEOL(text, i); - else - str = !trim ? GetBefore(text, i, Environment.NewLine, false) : Header.GetToEOL(text, i); - return str; - } - - private static bool IsBlankLine(string text, int[] i) - { - int num = text.IndexOf("\n", i[0]); - return Wafer.IsNullOrWhiteSpace(num > -1 ? text.Substring(i[0], num - i[0]) : text.Substring(i[0])); - } - internal static Footer? Get(Constant constant, ReadOnlyCollection groups) { Footer? result; @@ -80,12 +37,6 @@ public class Footer if (stdDev.EndsWith(",")) stdDev = stdDev.Remove(stdDev.Length - 1, 1); } - // if (PeekNextLine(groupText, j).Contains(constant.Cassette)) - // _ = Header.GetToEOL(groupText, j); - // if (PeekNextLine(groupText, j).Contains(constant.Cassette)) - // _ = Header.GetToEOL(groupText, j); - // if (PeekNextLine(groupText, j).Contains("Process failed")) - // _ = Header.GetToEOL(groupText, j); result = new(meanThickness: meanThickness, stdDev: stdDev); return result; diff --git a/Adaptation/FileHandlers/Stratus/ProcessData.cs b/Adaptation/FileHandlers/Stratus/ProcessData.cs index 989dde7..980a322 100644 --- a/Adaptation/FileHandlers/Stratus/ProcessData.cs +++ b/Adaptation/FileHandlers/Stratus/ProcessData.cs @@ -42,14 +42,16 @@ public partial class ProcessData : IProcessData private string _Data; private readonly ILog _Log; - public ProcessData(IFileRead fileRead, Logistics logistics, List fileInfoCollection, string originalDataBioRad, string dataText) +#nullable enable + + internal ProcessData(IFileRead fileRead, Logistics logistics, List fileInfoCollection, string originalDataBioRad, Complete? complete, string dataText) { JobID = logistics.JobID; fileInfoCollection.Clear(); _Details = new List(); MesEntity = logistics.MesEntity; _Log = LogManager.GetLogger(typeof(ProcessData)); - Parse(fileRead, logistics, fileInfoCollection, originalDataBioRad, dataText); + Parse(fileRead, logistics, fileInfoCollection, originalDataBioRad, complete, dataText); } string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary reactors) => throw new Exception(string.Concat("See ", nameof(Parse))); @@ -72,7 +74,7 @@ public partial class ProcessData : IProcessData } List fileReadDescriptions = (from l in descriptions select (Description)l).ToList(); string json = JsonSerializer.Serialize(fileReadDescriptions, fileReadDescriptions.GetType()); - JsonElement[] jsonElements = JsonSerializer.Deserialize(json); + JsonElement[] jsonElements = JsonSerializer.Deserialize(json) ?? throw new Exception(); results = new Tuple>(logistics.Logistics1[0], tests.ToArray(), jsonElements, fileInfoCollection); return results; } @@ -383,7 +385,7 @@ public partial class ProcessData : IProcessData return result; } - private void Set(Logistics logistics) + private void Set(Logistics logistics, Complete? complete) { string psn; string rds; @@ -413,6 +415,8 @@ public partial class ProcessData : IProcessData batch = GetToText(startedKey); ScanPast(startedAtKey); } + if (complete is not null) + { } ScanPast(cassetteKey); if (!_Data.Substring(_I).Contains(startedKey)) text = string.Empty; @@ -445,48 +449,17 @@ public partial class ProcessData : IProcessData UniqueId = string.Concat("StratusBioRad_", reactor, "_", rds, "_", psn, "_", logistics.DateTimeFromSequence.ToString("yyyyMMddHHmmssffff")); } -#nullable enable - - private static Complete? GetComplete(string text) - { - Complete? result; - Constant constant = new(); - result = Complete.Get(text, constant); - return result; - } - -#pragma warning disable IDE0060 - private void Parse(IFileRead fileRead, Logistics logistics, List fileInfoCollection, string originalDataBioRad, string receivedData) -#pragma warning restore IDE0060 + private void Parse(IFileRead fileRead, Logistics logistics, List fileInfoCollection, string originalDataBioRad, Complete? complete, string receivedData) { + if (fileRead is null) + throw new ArgumentNullException(nameof(fileRead)); _I = 0; _Data = string.Empty; List details = new(); - string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(logistics.ReportFullPath); - if (string.IsNullOrEmpty(receivedData)) - { - receivedData = File.ReadAllText(logistics.ReportFullPath); - try - { - Complete? complete = GetComplete(receivedData); - if (complete is null) - _Log.Warn($"Could not get Complete from {fileNameWithoutExtension}"); - else - { - FileInfo fileInfo = new($"{fileNameWithoutExtension}.json"); - string json = JsonSerializer.Serialize(complete, CompleteSourceGenerationContext.Default.Complete); - File.WriteAllText(fileInfo.FullName, json); - fileInfoCollection.Add(fileInfo); - } - } - catch (Exception ex) - { - _Log.Error($"Error in {nameof(GetComplete)}", ex); - } - } _Log.Debug($"****ParseData - Source file contents:"); _Log.Debug(receivedData); 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)); @@ -504,7 +477,7 @@ public partial class ProcessData : IProcessData string nextLine; _I = 0; _Data = receivedData; - Set(logistics); + Set(logistics, complete); nextLine = PeekNextLine(); string cassette = "Cassette"; if (nextLine.Contains("Wafer")) diff --git a/Adaptation/FileHandlers/Stratus/Wafer.cs b/Adaptation/FileHandlers/Stratus/Wafer.cs index 25fa017..e0f6c98 100644 --- a/Adaptation/FileHandlers/Stratus/Wafer.cs +++ b/Adaptation/FileHandlers/Stratus/Wafer.cs @@ -1,4 +1,3 @@ -using log4net; using System; using System.Collections.Generic; using System.Collections.ObjectModel; diff --git a/Adaptation/FileHandlers/txt/FileRead.cs b/Adaptation/FileHandlers/txt/FileRead.cs index 2bd1f6b..d412574 100644 --- a/Adaptation/FileHandlers/txt/FileRead.cs +++ b/Adaptation/FileHandlers/txt/FileRead.cs @@ -100,8 +100,10 @@ public class FileRead : Shared.FileRead, IFileRead private Tuple> GetExtractResult(string reportFullPath, DateTime dateTime) { + if (dateTime == DateTime.MinValue) + throw new ArgumentNullException(nameof(dateTime)); Tuple> results = new(string.Empty, null, null, new List()); - _TickOffset ??= new FileInfo(reportFullPath).LastWriteTime.Ticks - dateTime.Ticks; + _TickOffset ??= 0; // new FileInfo(reportFullPath).LastWriteTime.Ticks - dateTime.Ticks; _Logistics = new Logistics(this, _TickOffset.Value, reportFullPath, useSplitForMID: true); SetFileParameterLotID(_Logistics.MID); FileInfo fileInfo = new(reportFullPath); diff --git a/Adaptation/FileHandlers/txt/ProcessData.cs b/Adaptation/FileHandlers/txt/ProcessData.cs index 2f83c54..3b5febc 100644 --- a/Adaptation/FileHandlers/txt/ProcessData.cs +++ b/Adaptation/FileHandlers/txt/ProcessData.cs @@ -59,6 +59,8 @@ public partial class ProcessData : IProcessData return results; } +#nullable enable + private List> Parse(IFileRead fileRead, Logistics logistics, long tickOffset, List fileInfoCollection, string originalDataBioRad) { List> results = new(); @@ -224,7 +226,8 @@ public partial class ProcessData : IProcessData } else { - processData = new Stratus.ProcessData(fileRead, logistics, fileInfoCollection, originalDataBioRad, dataText: dataText); + Stratus.Complete? complete = null; + processData = new Stratus.ProcessData(fileRead, logistics, fileInfoCollection, originalDataBioRad, complete, dataText: dataText); iProcessData = processData; if (iProcessData.Details.Count == 0) _Log.Warn("No Details!");