94 lines
4.9 KiB
C#

using Adaptation.Shared;
using Adaptation.Shared.Metrology;
using Adaptation.Shared.Properties;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
namespace Adaptation.FileHandlers.MET08THFTIRQS408M;
public class ProcessData
{
internal static List<Tuple<int, Enum, string>> HyphenTuples => new()
{
new Tuple<int, Enum, string>(0, Hyphen.IsNaEDA, @"\EC_EDA\Staging\Traces\~\Source"),
new Tuple<int, Enum, string>(15, Hyphen.IsXToOpenInsightMetrologyViewer, @"\EC_EAFLog\TracesMES\~\Source"),
new Tuple<int, Enum, string>(-36, Hyphen.IsXToIQSSi, @"\EC_SPC_Si\Traces\~\PollPath"),
new Tuple<int, Enum, string>(36, Hyphen.IsXToOpenInsight, @"\\messa01ec.ec.local\APPS\Metrology\~\Source"),
new Tuple<int, Enum, string>(36, Hyphen.IsXToOpenInsightMetrologyViewerAttachments, @"\EC_Characterization_Si\In Process\~\Source"),
new Tuple<int, Enum, string>(360, Hyphen.IsXToAPC, @"\EC_APC\Staging\Traces\~\PollPath"),
new Tuple<int, Enum, string>(-36, Hyphen.IsXToSPaCe, @"\EC_SPC_Si\Traces\~\Source"),
new Tuple<int, Enum, string>(180, Hyphen.IsXToArchive, @"\EC_EAFLog\TracesArchive\~\Source"),
new Tuple<int, Enum, string>(36, Hyphen.IsArchive, @"\EC_Characterization_Si\Processed")
//new Tuple<int, Enum, string>("IsDummy"
};
internal static string GetLines(IFileRead fileRead, Logistics logistics, List<Stratus.Description> descriptions)
{
StringBuilder results = new();
if (fileRead is null)
{ }
Stratus.Description x = descriptions[0];
_ = results.Append("Stratus_").Append(logistics.MID).Append('_').Append(logistics.DateTimeFromSequence.ToString("yyyyMMddhhmmssfff")).Append('\t').
Append(x.Date).Append('\t').
Append(logistics.JobID).Append('\t').
Append("FQA Thickness").Append('\t').
Append(x.Employee).Append('\t').
Append(x.Recipe).Append('\t').
Append(x.Reactor).Append('\t').
Append(x.RDS).Append('\t').
Append(x.PSN).Append('\t').
Append(x.Lot).Append('\t').
Append(x.Cassette).Append('\t').
Append(x.MeanThickness);
for (int i = 0; i < descriptions.Count; i++)
_ = results.Append('\t').Append(descriptions[i].Slot).Append('\t').Append(descriptions[i].Mean);
return results.ToString();
}
internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, string originalDataBioRad, DateTime dateTime, string logisticsSequenceMemoryDirectory, List<Stratus.Description> descriptions, string matchDirectory)
{
if (fileRead is null)
{ }
if (dateTime == DateTime.MinValue)
{ }
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<WS.Results>(json);
long wsResultsHeaderID = metrologyWSRequest.HeaderID;
string dataPDFFile = Path.Combine(matchDirectory, $"{wsResultsHeaderID}.pdf");
string[] txtFiles = Directory.GetFiles(matchDirectory, string.Concat(originalDataBioRad, "*.txt"), SearchOption.TopDirectoryOnly);
if (txtFiles.Length != 1)
throw new Exception("Invalid source file count!");
string[] lines = File.ReadAllLines(txtFiles[0]);
lines = (from l in lines where !string.IsNullOrEmpty(l) select l).ToArray();
if (lines.Length > 1)
{
org.apache.pdfbox.pdmodel.PDDocument pdDocument = new();
org.apache.pdfbox.pdmodel.PDPage pdPage = new();
pdDocument.addPage(pdPage);
org.apache.pdfbox.pdmodel.edit.PDPageContentStream pdPageContentStream = new(pdDocument, pdPage);
org.apache.pdfbox.pdmodel.font.PDFont pdFont = org.apache.pdfbox.pdmodel.font.PDType1Font.HELVETICA;
pdPageContentStream.setFont(pdFont, 16);
for (int i = 1; i < lines.Length; i++)
{
pdPageContentStream.beginText();
pdPageContentStream.moveTextPositionByAmount(16, 750 - (i * 16));
pdPageContentStream.drawString(lines[i]);
pdPageContentStream.endText();
}
pdPageContentStream.close();
pdDocument.save(dataPDFFile);
pdDocument.close();
List<WS.Attachment> headerAttachments = new() { new WS.Attachment(descriptions[0].HeaderUniqueId, "Data.pdf", dataPDFFile) };
WS.AttachFiles(openInsightMetrologyViewerAPI, wsResultsHeaderID, headerAttachments, dataAttachments: null);
}
}
}