using Adaptation.Shared; using Adaptation.Shared.Metrology; using Adaptation.Shared.Properties; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Text.Json; namespace Adaptation.FileHandlers.MET08RESIHGCV; public class ProcessData { internal static List> HyphenTuples => new() { new Tuple(0, Hyphen.IsNaEDA, @"\EC_EDA\Staging\Traces\~\Source"), new Tuple(15, Hyphen.IsXToOpenInsightMetrologyViewer, @"\EC_EAFLog\TracesMES\~\Source"), new Tuple(-36, Hyphen.IsXToIQSSi, @"\EC_SPC_Si\Traces\~\PollPath"), new Tuple(-36, Hyphen.IsXToOpenInsight, @"\\messa01ec.ec.local\APPS\Metrology\~\Source"), new Tuple(36, Hyphen.IsXToOpenInsightMetrologyViewerAttachments, @"\EC_Characterization_Si\In Process\~\Source"), new Tuple(360, Hyphen.IsXToAPC, @"\EC_APC\Staging\Traces\~\PollPath"), new Tuple(-36, Hyphen.IsXToSPaCe, @"\EC_SPC_Si\Traces\~\Source"), new Tuple(180, Hyphen.IsXToArchive, @"\EC_EAFLog\TracesArchive\~\Source"), new Tuple(36, Hyphen.IsArchive, @"\EC_Characterization_Si\Processed") //new Tuple("IsDummy" }; internal static string GetLines(IFileRead fileRead, Logistics logistics, List descriptions) { StringBuilder result = new(); if (fileRead is null) { } if (logistics is null) { } if (descriptions is null) { } return result.ToString(); } /// /// Convert the raw data file to parsable file format - in this case from PCL to PDF /// /// source file to be converted to PDF /// private static string ConvertSourceFileToPdfWithChartData(string lincPDFCFileName, string sourceFile) { string result = Path.ChangeExtension(sourceFile, ".pdf"); if (!File.Exists(result)) { string arguments = string.Concat("-i \"", sourceFile, "\" -o \"", result, "\""); //string arguments = string.Concat("-dSAFER -dBATCH -dNOPAUSE -dFIXEDMEDIA -dFitPage -dAutoRotatePages=/All -dDEVICEWIDTHPOINTS=792 -dDEVICEHEIGHTPOINTS=612 -sOutputFile=\"", result, "\" -sDEVICE=pdfwrite \"", sourceFile, "\""); Process process = Process.Start(lincPDFCFileName, arguments); //Process process = Process.Start(ghostPCLFileName, arguments); _ = process.WaitForExit(30000); if (!File.Exists(result)) throw new Exception("PDF file wasn't created"); } return result; } internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, string lincPDFCFileName, DateTime dateTime, string logisticsSequenceMemoryDirectory, List descriptions, string matchDirectory) { if (fileRead is null) { } if (dateTime == DateTime.MinValue) { } if (logisticsSequenceMemoryDirectory is null) { } if (descriptions is null) { } if (matchDirectory is null) { } string[] pclFiles = Directory.GetFiles(matchDirectory, "*.pcl", SearchOption.TopDirectoryOnly); if (pclFiles.Length != 1) throw new Exception("Invalid source file count!"); string wsResultsMemoryFile = string.Concat(logisticsSequenceMemoryDirectory, @"\", nameof(WS.Results), ".json"); if (!File.Exists(wsResultsMemoryFile)) throw new Exception(string.Concat("Memory file <", wsResultsMemoryFile, "> doesn't exist!")); string json = File.ReadAllText(wsResultsMemoryFile); WS.Results metrologyWSRequest = JsonSerializer.Deserialize(json); long wsResultsHeaderID = metrologyWSRequest.HeaderID; List pdfFiles = new(); pdfFiles.AddRange(Directory.GetFiles(matchDirectory, "*.pdf_old", SearchOption.TopDirectoryOnly)); foreach (string pdfFile in pdfFiles) File.Delete(pdfFile); pdfFiles.Clear(); pdfFiles.AddRange(Directory.GetFiles(matchDirectory, "*.pdf", SearchOption.TopDirectoryOnly)); foreach (string pdfFile in pdfFiles) File.Move(pdfFile, Path.ChangeExtension(pdfFile, ".pdf_old")); pdfFiles.Clear(); foreach (string pclFile in pclFiles.OrderBy(l => l)) pdfFiles.Add(ConvertSourceFileToPdfWithChartData(lincPDFCFileName, pclFile)); if (pdfFiles.Count == 0) throw new Exception("Invalid *.pdf file count!"); List headerAttachments = new() { new WS.Attachment(descriptions[0].HeaderUniqueId, "Data.pdf", pdfFiles[0]) }; WS.AttachFiles(openInsightMetrologyViewerAPI, wsResultsHeaderID, headerAttachments, dataAttachments: null); } }