From 127a24b77ee78e28b6550aa45fccc4880b5e72e1 Mon Sep 17 00:00:00 2001 From: "phares@iscn5cg20977xq" Date: Mon, 24 Nov 2025 11:10:18 -0700 Subject: [PATCH] Refactor file handling classes: rename MoveAllFiles to MoveMapFiles, add MoveTextFiles, and update logistics sequence handling across various FileRead implementations. Bug fix for recipe to session Add one to run count --- .../CellInstanceConnectionName.cs | 3 +- Adaptation/FileHandlers/IQSSi/FileRead.cs | 88 +++++++------- .../FileRead.cs | 2 +- .../MoveMatchingFiles/FileRead.cs | 3 +- .../FileHandlers/MoveTextFiles/FileRead.cs | 112 ++++++++++++++++++ .../FileHandlers/OpenInsight/FileRead.cs | 3 +- .../OpenInsightMetrologyViewer/FileRead.cs | 7 +- .../OpenInsightMetrologyViewer/WSRequest.cs | 48 +++++--- .../FileRead.cs | 3 +- Adaptation/FileHandlers/Processed/FileRead.cs | 3 +- .../FileHandlers/TIBCO/Transport/Job.cs | 2 +- Adaptation/FileHandlers/txt/Run.cs | 6 +- Adaptation/Shared/Logistics.cs | 27 +++++ MET08DDUPSP1TBI.csproj | 3 +- 14 files changed, 240 insertions(+), 70 deletions(-) rename Adaptation/FileHandlers/{MoveAllFiles => MoveMapFiles}/FileRead.cs (99%) create mode 100644 Adaptation/FileHandlers/MoveTextFiles/FileRead.cs diff --git a/Adaptation/FileHandlers/CellInstanceConnectionName.cs b/Adaptation/FileHandlers/CellInstanceConnectionName.cs index 8c89694..4d932bc 100644 --- a/Adaptation/FileHandlers/CellInstanceConnectionName.cs +++ b/Adaptation/FileHandlers/CellInstanceConnectionName.cs @@ -17,8 +17,9 @@ public class CellInstanceConnectionName nameof(Archive) => new Archive.FileRead(smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null), nameof(Dummy) => new Dummy.FileRead(smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null), nameof(IQSSi) => new IQSSi.FileRead(smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null), - nameof(MoveAllFiles) => new MoveAllFiles.FileRead(smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null), + nameof(MoveMapFiles) => new MoveMapFiles.FileRead(smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null), nameof(MoveMatchingFiles) => new MoveMatchingFiles.FileRead(smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null), + nameof(MoveTextFiles) => new MoveTextFiles.FileRead(smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null), nameof(OpenInsight) => new OpenInsight.FileRead(smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null), nameof(OpenInsightMetrologyViewer) => new OpenInsightMetrologyViewer.FileRead(smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null), nameof(OpenInsightMetrologyViewerAttachments) => new OpenInsightMetrologyViewerAttachments.FileRead(smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null), diff --git a/Adaptation/FileHandlers/IQSSi/FileRead.cs b/Adaptation/FileHandlers/IQSSi/FileRead.cs index c189c1e..2c3169d 100644 --- a/Adaptation/FileHandlers/IQSSi/FileRead.cs +++ b/Adaptation/FileHandlers/IQSSi/FileRead.cs @@ -115,50 +115,50 @@ public class FileRead : Shared.FileRead, IFileRead StringBuilder result = new(); char del = '\t'; txt.Description x = descriptions[0]; - _ = result.Append(x.DcnLpdMin).Append(del). // 001 - - Append(x.DcnLpdMax).Append(del). // 002 - - Append(x.DcnLpdMean).Append(del). // 003 - DCN LPD - Append(x.DcnAreaCountMin).Append(del). // 004 - - Append(x.DcnAreaCountMax).Append(del). // 005 - - Append(x.DcnAreaCountMean).Append(del).// 006 - DCN Area - Append(x.DcnAreaMin).Append(del). // 007 - - Append(x.DcnAreaMax).Append(del). // 008 - - Append(x.Date).Append(del). // 009 - - Append(x.DcnHazeAvgMean).Append(del). // 010 - Haze Average - Append(string.Empty).Append(del). // 011 - - Append(string.Empty).Append(del). // 012 - - Append(string.Empty).Append(del). // 013 - - Append(string.Empty).Append(del). // 014 - - Append(string.Empty).Append(del). // 015 - - Append(string.Empty).Append(del). // 016 - - Append(string.Empty).Append(del). // 017 - - Append(string.Empty).Append(del). // 018 - - Append(string.Empty).Append(del). // 019 - - Append(string.Empty).Append(del). // 020 - - Append(string.Empty).Append(del). // 021 - - Append(string.Empty).Append(del). // 022 - - Append(string.Empty).Append(del). // 023 - - Append(string.Empty).Append(del). // 024 - - Append(string.Empty).Append(del). // 025 - - Append(string.Empty).Append(del). // 026 - - Append(string.Empty).Append(del). // 027 - - Append(x.RDS).Append(del). // 028 - Lot - Append(x.Reactor).Append(del). // 029 - Process - Append(x.Recipe).Append(del). // 030 - Part - Append(x.DcnScrMean).Append(del). // 031 - Scratch Count - Append(string.Empty).Append(del). // 032 - - Append(string.Empty).Append(del). // 033 - - Append(string.Empty).Append(del). // 034 - - Append(x.DcnMicroScrMean).Append(del). // 035 - Scratch Length - Append(string.Empty).Append(del). // 036 - - Append(string.Empty).Append(del). // 037 - - Append(string.Empty).Append(del). // 038 - - Append(x.DcnAllMean).Append(del). // 039 - Average Sum of Defects - Append(x.DcnAllMax).Append(del). // 040 - Max Sum of defects - Append(x.DcnAllMin).Append(del). // 041 - Min Sum of Defects - Append(string.Empty).Append(del). // 042 - - Append(logistics.MesEntity).Append(del). // 043 - - Append(x.DcnAreaMean).Append(del). // 044 - DCN MM2 + _ = result.Append(x.DcnLpdMin).Append(del). // 001 - + Append(x.DcnLpdMax).Append(del). // 002 - + Append(x.DcnLpdMean).Append(del). // 003 - DCN LPD + Append(x.DcnAreaCountMin).Append(del). // 004 - + Append(x.DcnAreaCountMax).Append(del). // 005 - + Append(x.DcnAreaCountMean).Append(del). // 006 - DCN Area + Append(x.DcnAreaMin).Append(del). // 007 - + Append(x.DcnAreaMax).Append(del). // 008 - + Append(x.Date).Append(del). // 009 - + Append(x.DcnHazeAvgMean).Append(del). // 010 - Haze Average + Append(string.Empty).Append(del). // 011 - + Append(string.Empty).Append(del). // 012 - + Append(string.Empty).Append(del). // 013 - + Append(string.Empty).Append(del). // 014 - + Append(string.Empty).Append(del). // 015 - + Append(string.Empty).Append(del). // 016 - + Append(string.Empty).Append(del). // 017 - + Append(string.Empty).Append(del). // 018 - + Append(string.Empty).Append(del). // 019 - + Append(string.Empty).Append(del). // 020 - + Append(string.Empty).Append(del). // 021 - + Append(string.Empty).Append(del). // 022 - + Append(string.Empty).Append(del). // 023 - + Append(string.Empty).Append(del). // 024 - + Append(string.Empty).Append(del). // 025 - + Append(string.Empty).Append(del). // 026 - + Append(string.Empty).Append(del). // 027 - + Append(x.RDS).Append(del). // 028 - Lot + Append(x.Reactor).Append(del). // 029 - Process + Append(x.Session).Append(del). // 030 - Part + Append(x.DcnScrMean).Append(del). // 031 - Scratch Count + Append(string.Empty).Append(del). // 032 - + Append(string.Empty).Append(del). // 033 - + Append(string.Empty).Append(del). // 034 - + Append(x.DcnMicroScrMean).Append(del). // 035 - Scratch Length + Append(string.Empty).Append(del). // 036 - + Append(string.Empty).Append(del). // 037 - + Append(string.Empty).Append(del). // 038 - + Append(x.DcnAllMean).Append(del). // 039 - Average Sum of Defects + Append(x.DcnAllMax).Append(del). // 040 - Max Sum of defects + Append(x.DcnAllMin).Append(del). // 041 - Min Sum of Defects + Append(string.Empty).Append(del). // 042 - + Append(logistics.MesEntity).Append(del). // 043 - + Append(x.DcnAreaMean).Append(del). // 044 - DCN MM2 AppendLine(); return new Tuple(result.ToString(), x.Date); } diff --git a/Adaptation/FileHandlers/MoveAllFiles/FileRead.cs b/Adaptation/FileHandlers/MoveMapFiles/FileRead.cs similarity index 99% rename from Adaptation/FileHandlers/MoveAllFiles/FileRead.cs rename to Adaptation/FileHandlers/MoveMapFiles/FileRead.cs index 322e7b5..cd1982c 100644 --- a/Adaptation/FileHandlers/MoveAllFiles/FileRead.cs +++ b/Adaptation/FileHandlers/MoveMapFiles/FileRead.cs @@ -8,7 +8,7 @@ using System.Collections.Generic; using System.IO; using System.Text.Json; -namespace Adaptation.FileHandlers.MoveAllFiles; +namespace Adaptation.FileHandlers.MoveMapFiles; public class FileRead : Shared.FileRead, IFileRead { diff --git a/Adaptation/FileHandlers/MoveMatchingFiles/FileRead.cs b/Adaptation/FileHandlers/MoveMatchingFiles/FileRead.cs index 73c6d12..5e73ef1 100644 --- a/Adaptation/FileHandlers/MoveMatchingFiles/FileRead.cs +++ b/Adaptation/FileHandlers/MoveMatchingFiles/FileRead.cs @@ -267,11 +267,12 @@ public class FileRead : Shared.FileRead, IFileRead List results = new(); Post post; long preWait; + long uniqueSequence = Logistics.GetUniqueSequence(_Logistics); foreach (PreWith preWith in preWithCollection) { if (!_IsEAFHosted) continue; - if (!_StaticRuns.TryGetValue(_Logistics.Sequence, out List? wsResults)) + if (!_StaticRuns.TryGetValue(uniqueSequence, out List? wsResults)) wsResults = null; if (processDataStandardFormat.InputPDSF is null) File.Move(preWith.MatchingFile, preWith.CheckFile); diff --git a/Adaptation/FileHandlers/MoveTextFiles/FileRead.cs b/Adaptation/FileHandlers/MoveTextFiles/FileRead.cs new file mode 100644 index 0000000..5968eef --- /dev/null +++ b/Adaptation/FileHandlers/MoveTextFiles/FileRead.cs @@ -0,0 +1,112 @@ +using Adaptation.Eaf.Management.ConfigurationData.CellAutomation; +using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration; +using Adaptation.Shared; +using Adaptation.Shared.Duplicator; +using Adaptation.Shared.Methods; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; + +namespace Adaptation.FileHandlers.MoveTextFiles; + +public class FileRead : Shared.FileRead, IFileRead +{ + +#nullable enable + + private long? _TickOffset; + + public FileRead(ISMTP smtp, Dictionary fileParameter, string cellInstanceName, int? connectionCount, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList modelObjectParameters, string equipmentDictionaryName, Dictionary> dummyRuns, Dictionary> staticRuns, bool useCyclicalForDescription, bool isEAFHosted) : + base(new Description(), false, smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null) + { + _MinFileLength = 10; + _NullData = string.Empty; + _Logistics = new(this); + if (_FileParameter is null) + throw new Exception(cellInstanceConnectionName); + if (_ModelObjectParameterDefinitions is null) + throw new Exception(cellInstanceConnectionName); + if (_IsDuplicator) + throw new Exception(cellInstanceConnectionName); + } + +#nullable disable + + void IFileRead.Move(Tuple> extractResults, Exception exception) => Move(extractResults); + + void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null); + + string IFileRead.GetEventDescription() + { + string result = _Description.GetEventDescription(); + return result; + } + + List IFileRead.GetHeaderNames() + { + List results = _Description.GetHeaderNames(); + return results; + } + + string[] IFileRead.Move(Tuple> extractResults, string to, string from, string resolvedFileLocation, Exception exception) + { + string[] results = Move(extractResults, to, from, resolvedFileLocation, exception); + return results; + } + + JsonProperty[] IFileRead.GetDefault() + { + JsonProperty[] results = _Description.GetDefault(this, _Logistics); + return results; + } + + Dictionary IFileRead.GetDisplayNamesJsonElement() + { + Dictionary results = _Description.GetDisplayNamesJsonElement(this); + return results; + } + + List IFileRead.GetDescriptions(IFileRead fileRead, List tests, IProcessData processData) + { + List results = _Description.GetDescriptions(fileRead, _Logistics, tests, processData); + return results; + } + + Tuple> IFileRead.GetExtractResult(string reportFullPath, string eventName) + { + Tuple> results; + if (string.IsNullOrEmpty(eventName)) + throw new Exception(); + _ReportFullPath = reportFullPath; + DateTime dateTime = DateTime.Now; + results = GetExtractResult(reportFullPath, dateTime); + if (results.Item3 is null) + results = new Tuple>(results.Item1, Array.Empty(), JsonSerializer.Deserialize("[]"), results.Item4); + if (results.Item3.Length > 0 && _IsEAFHosted) + WritePDSF(this, results.Item3); + UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks); + return results; + } + + Tuple> IFileRead.ReExtract() + { + Tuple> results; + List headerNames = _Description.GetHeaderNames(); + Dictionary keyValuePairs = _Description.GetDisplayNamesJsonElement(this); + results = ReExtract(this, headerNames, keyValuePairs); + return results; + } + + 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 ??= 0; // new FileInfo(reportFullPath).LastWriteTime.Ticks - dateTime.Ticks; + _Logistics = new Logistics(this, _TickOffset.Value, reportFullPath, useSplitForMID: true); + SetFileParameterLotIDToLogisticsMID(); + return results; + } + +} \ No newline at end of file diff --git a/Adaptation/FileHandlers/OpenInsight/FileRead.cs b/Adaptation/FileHandlers/OpenInsight/FileRead.cs index 37eac98..3977693 100644 --- a/Adaptation/FileHandlers/OpenInsight/FileRead.cs +++ b/Adaptation/FileHandlers/OpenInsight/FileRead.cs @@ -125,13 +125,14 @@ public class FileRead : Shared.FileRead, IFileRead { long? subgroupId; string fileName = Path.GetFileName(reportFullPath); + long uniqueSequence = Logistics.GetUniqueSequence(_Logistics); long breakAfter = dateTime.AddSeconds(_BreakAfterSeconds).Ticks; long preWait = _FileConnectorConfiguration?.FileHandleWaitTime is null ? dateTime.AddMilliseconds(1234).Ticks : dateTime.AddMilliseconds(_FileConnectorConfiguration.FileHandleWaitTime.Value).Ticks; if (string.IsNullOrEmpty(descriptions[0].Reactor) || string.IsNullOrEmpty(descriptions[0].PSN)) subgroupId = null; else (subgroupId, int? _, string _) = FromIQS.GetCommandText(_IqsConnectionString, _Logistics, descriptions[0], breakAfter, preWait); - if (_StaticRuns.TryGetValue(_Logistics.Sequence, out List wsResults)) + if (_StaticRuns.TryGetValue(uniqueSequence, out List wsResults)) { if (wsResults is null || wsResults.Count != 1) throw new NullReferenceException($"{nameof(wsResults)} {wsResults?.Count} != 1 {_Logistics.Sequence}!"); diff --git a/Adaptation/FileHandlers/OpenInsightMetrologyViewer/FileRead.cs b/Adaptation/FileHandlers/OpenInsightMetrologyViewer/FileRead.cs index 4905d1c..9966d37 100644 --- a/Adaptation/FileHandlers/OpenInsightMetrologyViewer/FileRead.cs +++ b/Adaptation/FileHandlers/OpenInsightMetrologyViewer/FileRead.cs @@ -113,6 +113,7 @@ public class FileRead : Shared.FileRead, IFileRead private void SendData(string reportFullPath, DateTime dateTime, JsonElement[] jsonElements, List descriptions) { string checkDirectory; + long uniqueSequence = Logistics.GetUniqueSequence(_Logistics); WSRequest wsRequest = new(this, _Logistics, jsonElements, descriptions); int weekOfYear = _Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); string directory = Path.Combine(_OpenInsightMetrologyViewerFileShare, dateTime.Year.ToString(), $"WW{weekOfYear:00}"); @@ -126,9 +127,9 @@ public class FileRead : Shared.FileRead, IFileRead _Log.Debug(wsResults.HeaderId); lock (_StaticRuns) { - if (!_StaticRuns.ContainsKey(_Logistics.Sequence)) - _StaticRuns.Add(_Logistics.Sequence, new()); - _StaticRuns[_Logistics.Sequence].Add(wsResults); + if (!_StaticRuns.ContainsKey(uniqueSequence)) + _StaticRuns.Add(uniqueSequence, new()); + _StaticRuns[uniqueSequence].Add(wsResults); } checkDirectory = Path.Combine(directory, $"-{wsResults.HeaderId}"); if (!Directory.Exists(checkDirectory)) diff --git a/Adaptation/FileHandlers/OpenInsightMetrologyViewer/WSRequest.cs b/Adaptation/FileHandlers/OpenInsightMetrologyViewer/WSRequest.cs index 718d0c1..d7efcb8 100644 --- a/Adaptation/FileHandlers/OpenInsightMetrologyViewer/WSRequest.cs +++ b/Adaptation/FileHandlers/OpenInsightMetrologyViewer/WSRequest.cs @@ -611,11 +611,12 @@ public class WSRequest Details.Add(detail); } Date = logistics.DateTimeFromSequence.ToString(); - UniqueID = $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}"; + string uniqueId = Logistics.GetUniqueId(logistics); + UniqueID = uniqueId; for (int i = 0; i < Details.Count; i++) { Details[i].HeaderUniqueID = UniqueID; - Details[i].UniqueID = $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}_Item-{i + 1}"; + Details[i].UniqueID = $"{uniqueId}_Item-{i + 1}"; } } @@ -624,7 +625,7 @@ public class WSRequest /// /// source file to be converted to PDF /// - private static string ConvertSourceFileToPdf(string ghostPCLFileName, string sourceFile) + public static string ConvertSourceFileToPdf(string ghostPCLFileName, string sourceFile) { string result = Path.ChangeExtension(sourceFile, ".pdf"); if (!File.Exists(result)) @@ -661,29 +662,48 @@ public class WSRequest internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, string ghostPCLFileName, List descriptions, string matchDirectory, WS.Results results, string headerIdDirectory) #pragma warning restore IDE0060 { + string extension; + List attachmentFiles = new(); + string uniqueId = Logistics.GetUniqueId(logistics); string[] summaryFiles = Directory.GetFiles(matchDirectory, "*.txt", SearchOption.TopDirectoryOnly); if (summaryFiles.Length != 1) throw new Exception($"Invalid source file count for <{results.HeaderId}>!"); - string[] prnFiles = Directory.GetFiles(matchDirectory, "WaferMap*.prn", SearchOption.TopDirectoryOnly); - List pdfFiles = new(); - foreach (string prnFile in prnFiles.OrderBy(l => l)) - pdfFiles.Add(ConvertSourceFileToPdf(ghostPCLFileName, prnFile)); - if (pdfFiles.Count == 0 || pdfFiles.Count != descriptions.Count) - throw new Exception("Invalid *.pdf file count!"); + string[] xpsFiles = Directory.GetFiles(matchDirectory, "*.xps", SearchOption.TopDirectoryOnly); + if (xpsFiles.Length > 0) + { + extension = ".xps"; + foreach (string xpsFile in xpsFiles.OrderBy(l => l)) + attachmentFiles.Add(xpsFile); + if (attachmentFiles.Count == 0 || attachmentFiles.Count != descriptions.Count) + throw new Exception("Invalid *.pdf file count!"); + } + else + { + string pdfFile; + extension = ".pdf"; + string[] prnFiles = Directory.GetFiles(matchDirectory, "WaferMap*.prn", SearchOption.TopDirectoryOnly); + foreach (string prnFile in prnFiles.OrderBy(l => l)) + { + pdfFile = ConvertSourceFileToPdf(ghostPCLFileName, prnFile); + attachmentFiles.Add(pdfFile); + } + if (attachmentFiles.Count == 0 || attachmentFiles.Count != descriptions.Count) + throw new Exception("Invalid *.pdf file count!"); + } List dataAttachments = new(); List headerAttachments = new() { - new WS.Attachment(results, headerIdDirectory, $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}", "Data.txt", summaryFiles[0]) + new WS.Attachment(results, headerIdDirectory, uniqueId, "Data.txt", summaryFiles[0]) }; int count; - if (pdfFiles.Count < descriptions.Count) - count = pdfFiles.Count; + if (attachmentFiles.Count < descriptions.Count) + count = attachmentFiles.Count; else count = descriptions.Count; for (int i = 0; i < count; i++) { - if (!string.IsNullOrEmpty(pdfFiles[i])) - dataAttachments.Add(new WS.Attachment(results, headerIdDirectory, $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}_Item-{i + 1}", "Image.pdf", pdfFiles[i])); + if (!string.IsNullOrEmpty(attachmentFiles[i])) + dataAttachments.Add(new WS.Attachment(results, headerIdDirectory, $"{uniqueId}_Item-{i + 1}", $"Image{extension}", attachmentFiles[i])); } if (dataAttachments.Count == 0 || dataAttachments.Count != descriptions.Count) throw new Exception($"Invalid attachment count! {dataAttachments.Count} != {descriptions.Count}"); diff --git a/Adaptation/FileHandlers/OpenInsightMetrologyViewerAttachments/FileRead.cs b/Adaptation/FileHandlers/OpenInsightMetrologyViewerAttachments/FileRead.cs index d2aae7b..cb83d5b 100644 --- a/Adaptation/FileHandlers/OpenInsightMetrologyViewerAttachments/FileRead.cs +++ b/Adaptation/FileHandlers/OpenInsightMetrologyViewerAttachments/FileRead.cs @@ -145,8 +145,9 @@ public class FileRead : Shared.FileRead, IFileRead string jobIdDirectory = Path.Combine(Path.GetDirectoryName(_FileConnectorConfiguration.AlternateTargetFolder) ?? throw new Exception(), _Logistics.JobID); if (!Directory.Exists(jobIdDirectory)) _ = Directory.CreateDirectory(jobIdDirectory); + long uniqueSequence = Logistics.GetUniqueSequence(_Logistics); string[] matchDirectories = GetInProcessDirectory(jobIdDirectory); - if (!_StaticRuns.TryGetValue(_Logistics.Sequence, out List? wsResults)) + if (!_StaticRuns.TryGetValue(uniqueSequence, out List? wsResults)) results = null; else { diff --git a/Adaptation/FileHandlers/Processed/FileRead.cs b/Adaptation/FileHandlers/Processed/FileRead.cs index 6f0dc2d..c3fd58c 100644 --- a/Adaptation/FileHandlers/Processed/FileRead.cs +++ b/Adaptation/FileHandlers/Processed/FileRead.cs @@ -114,6 +114,7 @@ public class FileRead : Shared.FileRead, IFileRead throw new ArgumentNullException(nameof(dateTime)); FileInfo fileInfo = new(reportFullPath); string logisticsSequence = _Logistics.Sequence.ToString(); + long uniqueSequence = Logistics.GetUniqueSequence(_Logistics); string jobIdDirectory = Path.Combine(_JobIdParentDirectory, _Logistics.JobID); if (!Directory.Exists(jobIdDirectory)) _ = Directory.CreateDirectory(jobIdDirectory); @@ -136,7 +137,7 @@ public class FileRead : Shared.FileRead, IFileRead File.Copy(reportFullPath, Path.Combine(sequenceDirectory, Path.GetFileName(reportFullPath)), overwrite: true); File.WriteAllText(jsonFileName, json); lock (_StaticRuns) - _ = _StaticRuns.Remove(_Logistics.Sequence); + _ = _StaticRuns.Remove(uniqueSequence); } private static void MoveMatchingFile(string jobIdDirectory, string matchDirectory) diff --git a/Adaptation/FileHandlers/TIBCO/Transport/Job.cs b/Adaptation/FileHandlers/TIBCO/Transport/Job.cs index 99acc33..8d73907 100644 --- a/Adaptation/FileHandlers/TIBCO/Transport/Job.cs +++ b/Adaptation/FileHandlers/TIBCO/Transport/Job.cs @@ -116,7 +116,7 @@ public partial class Job { runCount = GetScalar(iqsSQLConnectionString, commandText); } catch (Exception) { runCount = null; } - basicType = runCount is null ? hyphen : runCount.ToString(); + basicType = runCount is null ? hyphen : (runCount + 1).ToString(); } Qty = "1"; Status = hyphen; // INFO diff --git a/Adaptation/FileHandlers/txt/Run.cs b/Adaptation/FileHandlers/txt/Run.cs index 280c707..62fa3b9 100644 --- a/Adaptation/FileHandlers/txt/Run.cs +++ b/Adaptation/FileHandlers/txt/Run.cs @@ -93,7 +93,11 @@ internal class Run private static void AddPrintFiles(Logistics logistics, List fileInfoCollection) { string sourceDirectory = Path.GetDirectoryName(logistics.ReportFullPath) ?? throw new Exception(); - string[] files = Directory.GetFiles(sourceDirectory, "WaferMap*.prn", SearchOption.TopDirectoryOnly); + string[] files; + files = Directory.GetFiles(sourceDirectory, "*.xps", SearchOption.TopDirectoryOnly); + foreach (string file in files) + fileInfoCollection.Add(new FileInfo(file)); + files = Directory.GetFiles(sourceDirectory, "WaferMap*.prn", SearchOption.TopDirectoryOnly); foreach (string file in files) fileInfoCollection.Add(new FileInfo(file)); } diff --git a/Adaptation/Shared/Logistics.cs b/Adaptation/Shared/Logistics.cs index 4f187f8..0575bf6 100644 --- a/Adaptation/Shared/Logistics.cs +++ b/Adaptation/Shared/Logistics.cs @@ -199,4 +199,31 @@ public class Logistics : ILogistics _ProcessJobID = processJobID; } + private static int GetCountFromFileName(Logistics logistics) + { + int result; + string[] segments = logistics.FileInfo.Name.Split('.'); + string[] segmentsB = segments[0].Split('_'); + string countFromFileName = segmentsB.Length < 3 ? "0" : segmentsB[2]; + if (!int.TryParse(countFromFileName, out result)) + result = 0; + return result; + } + + internal static long GetUniqueSequence(Logistics logistics) + { + long result; + int countFromFileName = GetCountFromFileName(logistics); + result = (logistics.Sequence * 10) + countFromFileName; + return result; + } + + internal static string GetUniqueId(Logistics logistics) + { + string result; + int countFromFileName = GetCountFromFileName(logistics); + result = $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}_{countFromFileName}"; + return result; + } + } \ No newline at end of file diff --git a/MET08DDUPSP1TBI.csproj b/MET08DDUPSP1TBI.csproj index 666ff48..1804dbc 100644 --- a/MET08DDUPSP1TBI.csproj +++ b/MET08DDUPSP1TBI.csproj @@ -108,8 +108,9 @@ - + +