278 lines
15 KiB
C#
278 lines
15 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.MET08DDUPSFS6420;
|
|
|
|
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.IsXToIQSGaN, @"\EC_SPC_GaN\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<pcl.Description> descriptions, bool ganPPTST)
|
|
{
|
|
if (fileRead is null)
|
|
{ }
|
|
StringBuilder result = new();
|
|
pcl.Description x = descriptions[0];
|
|
if (ganPPTST)
|
|
{
|
|
string slot;
|
|
string reactor;
|
|
const int eight = 8;
|
|
DateTime dateTime = DateTime.Parse(x.Date);
|
|
string lot = x.Lot.ToLower().Replace("69-", string.Empty).Replace("71-", string.Empty).Replace("-", string.Empty);
|
|
if (string.IsNullOrEmpty(x.Lot) || x.Lot.Length < 2)
|
|
reactor = "R";
|
|
else
|
|
reactor = string.Concat("R", x.Lot.Substring(0, 2));
|
|
_ = result.Append(nameof(x.Date)).Append(';').
|
|
Append("Part").Append(';').
|
|
Append(nameof(x.Reactor)).Append(';').
|
|
Append("Lot").Append(';').
|
|
Append(nameof(pcl.Detail.Slot)).Append(';').
|
|
Append(nameof(pcl.Detail.Bin1)).Append(';').
|
|
Append(nameof(pcl.Detail.Bin2)).Append(';').
|
|
Append(nameof(pcl.Detail.Bin3)).Append(';').
|
|
Append(nameof(pcl.Detail.Bin4)).Append(';').
|
|
Append(nameof(pcl.Detail.Bin5)).Append(';').
|
|
Append(nameof(pcl.Detail.Bin6)).Append(';').
|
|
Append("Bin9").
|
|
AppendLine();
|
|
foreach (pcl.Description description in descriptions)
|
|
{
|
|
slot = description.Slot.Replace("*", string.Empty);
|
|
_ = result.Append('!').Append(dateTime.ToString("MM/dd/yyyy HH:mm:ss")).Append(';').
|
|
Append("Particle Adder;").
|
|
Append(reactor).Append(';').
|
|
Append(lot).Append(';').
|
|
Append(slot).Append(';').
|
|
Append(description.Bin1).Append(';').
|
|
Append(description.Bin2).Append(';').
|
|
Append(description.Bin3).Append(';').
|
|
Append(description.Bin4).Append(';').
|
|
Append(description.Bin5).Append(';').
|
|
Append(description.Bin6).Append(';').
|
|
Append(description.AreaCount).
|
|
AppendLine();
|
|
}
|
|
if (descriptions.Count != eight)
|
|
{
|
|
string negativeTenThousand = "-10000";
|
|
for (int i = descriptions.Count; i < eight; i++)
|
|
{
|
|
_ = result.Append('!').Append(dateTime.ToString("MM/dd/yyyy HH:mm:ss")).Append(';').
|
|
Append("Particle Adder;").
|
|
Append(reactor).Append(';').
|
|
Append(lot).Append(';').
|
|
Append(negativeTenThousand).Append(';').
|
|
Append(negativeTenThousand).Append(';').
|
|
Append(negativeTenThousand).Append(';').
|
|
Append(negativeTenThousand).Append(';').
|
|
Append(negativeTenThousand).Append(';').
|
|
Append(negativeTenThousand).Append(';').
|
|
Append(negativeTenThousand).Append(';').
|
|
Append(negativeTenThousand).
|
|
AppendLine();
|
|
}
|
|
}
|
|
if (result.ToString().Split('\n').Length != (eight + 2))
|
|
throw new Exception(string.Concat("Must have ", eight, " samples"));
|
|
}
|
|
else
|
|
{
|
|
char del = '\t';
|
|
_ = result.Append(x.AreaCountAvg).Append(del). // 001 - AreaCountAvg
|
|
Append(x.AreaCountMax).Append(del). // 002 - AreaCountMax
|
|
Append(x.AreaCountMin).Append(del). // 003 - AreaCountMin
|
|
Append(x.AreaCountStdDev).Append(del). // 004 - AreaCountStdDev
|
|
Append(x.AreaTotalAvg).Append(del). // 005 - AreaTotalAvg
|
|
Append(x.AreaTotalMax).Append(del). // 006 - AreaTotalMax
|
|
Append(x.AreaTotalMin).Append(del). // 007 - AreaTotalMin
|
|
Append(x.AreaTotalStdDev).Append(del). // 008 - AreaTotalStdDev
|
|
Append(x.Date).Append(del). // 009 -
|
|
Append(x.HazeAverageAvg).Append(del). // 010 - Haze Average
|
|
Append(x.HazeAverageMax).Append(del). // 011 -
|
|
Append(x.HazeAverageMin).Append(del). // 012 -
|
|
Append(x.HazeAverageStdDev).Append(del). // 013 -
|
|
Append(x.HazeRegionAvg).Append(del). // 014 -
|
|
Append(x.HazeRegionMax).Append(del). // 015 -
|
|
Append(x.HazeRegionMin).Append(del). // 016 -
|
|
Append(x.HazeRegionStdDev).Append(del). // 017 -
|
|
Append(x.Lot).Append(del). // 018 -
|
|
Append(x.LPDCM2Avg).Append(del). // 019 -
|
|
Append(x.LPDCM2Max).Append(del). // 020 -
|
|
Append(x.LPDCM2Min).Append(del). // 021 -
|
|
Append(x.LPDCM2StdDev).Append(del). // 022 -
|
|
Append(x.LPDCountAvg).Append(del). // 023 -
|
|
Append(x.LPDCountMax).Append(del). // 024 -
|
|
Append(x.LPDCM2Min).Append(del). // 025 -
|
|
Append(x.LPDCountStdDev).Append(del). // 026 -
|
|
Append(x.Employee).Append(del). // 027 -
|
|
Append(x.RDS).Append(del). // 028 - Lot
|
|
Append(x.Reactor).Append(del). // 029 - Process
|
|
Append(x.Recipe.Replace(";", string.Empty)).Append(del). // 030 - Part
|
|
Append(x.ScratchCountAvg).Append(del). // 031 - Scratch Count
|
|
Append(x.ScratchCountMax).Append(del). // 032 -
|
|
Append(x.ScratchCountMin).Append(del). // 033 -
|
|
Append(x.ScratchTotalStdDev).Append(del). // 034 -
|
|
Append(x.ScratchTotalAvg).Append(del). // 035 - Scratch Length
|
|
Append(x.ScratchTotalMax).Append(del). // 036 -
|
|
Append(x.ScratchTotalMin).Append(del). // 037 -
|
|
Append(x.ScratchTotalStdDev).Append(del). // 038 -
|
|
Append(x.SumOfDefectsAvg).Append(del). // 039 - Average Sum of Defects
|
|
Append(x.SumOfDefectsMax).Append(del). // 040 - Max Sum of Defects
|
|
Append(x.SumOfDefectsMin).Append(del). // 041 - Min Sum of Defects
|
|
Append(x.SumOfDefectsStdDev).Append(del). // 042 - SumOfDefectsStdDev
|
|
Append(logistics.MesEntity).Append(del). // 043 -
|
|
AppendLine();
|
|
}
|
|
return result.ToString();
|
|
}
|
|
|
|
private static void UpdateDataPDF(List<pcl.Description> descriptions, string checkFileName)
|
|
{
|
|
string value;
|
|
object possiblePage;
|
|
object possibleString;
|
|
object possibleCOSArray;
|
|
java.util.List tokenList;
|
|
java.util.List arrayList;
|
|
java.io.OutputStream outputStream;
|
|
List<string> updateValues = new();
|
|
StringBuilder stringBuilder = new();
|
|
java.util.ListIterator tokenIterator;
|
|
java.util.ListIterator arrayIterator;
|
|
java.io.File file = new(checkFileName);
|
|
string reactorLoadLock = descriptions[0].Comments;
|
|
org.apache.pdfbox.pdmodel.common.PDStream pdStream;
|
|
org.apache.pdfbox.pdmodel.common.PDStream updatedStream;
|
|
org.apache.pdfbox.pdfparser.PDFStreamParser pdfStreamParser;
|
|
org.apache.pdfbox.pdfwriter.ContentStreamWriter contentStreamWriter;
|
|
org.apache.pdfbox.pdmodel.PDDocument pdDocument = org.apache.pdfbox.pdmodel.PDDocument.load(file);
|
|
org.apache.pdfbox.pdmodel.PDDocumentCatalog pdDocumentCatalog = pdDocument.getDocumentCatalog();
|
|
java.util.List pagesList = pdDocumentCatalog.getAllPages();
|
|
java.util.ListIterator pageIterator = pagesList.listIterator();
|
|
for (short i = 1; i < short.MaxValue; i++)
|
|
{
|
|
if (!pageIterator.hasNext())
|
|
break;
|
|
possiblePage = pageIterator.next();
|
|
if (possiblePage is not org.apache.pdfbox.pdmodel.PDPage page)
|
|
continue;
|
|
pdStream = page.getContents();
|
|
pdfStreamParser = new org.apache.pdfbox.pdfparser.PDFStreamParser(pdStream);
|
|
pdfStreamParser.parse();
|
|
tokenList = pdfStreamParser.getTokens();
|
|
tokenIterator = tokenList.listIterator();
|
|
for (short t = 1; i < short.MaxValue; t++)
|
|
{
|
|
if (!tokenIterator.hasNext())
|
|
break;
|
|
possibleCOSArray = tokenIterator.next();
|
|
if (possibleCOSArray is not org.apache.pdfbox.cos.COSArray cossArray)
|
|
continue;
|
|
_ = stringBuilder.Clear();
|
|
arrayList = cossArray.toList();
|
|
arrayIterator = arrayList.listIterator();
|
|
for (short a = 1; i < short.MaxValue; a++)
|
|
{
|
|
if (!arrayIterator.hasNext())
|
|
break;
|
|
possibleString = arrayIterator.next();
|
|
if (possibleString is not org.apache.pdfbox.cos.COSString cossString)
|
|
continue;
|
|
value = cossString.getString();
|
|
_ = stringBuilder.Append(value);
|
|
if (value != "]")
|
|
continue;
|
|
updateValues.Add(value);
|
|
value = stringBuilder.ToString();
|
|
if (value.Contains("[]"))
|
|
cossArray.setString(a - 1, string.Concat("*", reactorLoadLock, "]"));
|
|
else
|
|
cossArray.setString(a - 1, string.Concat(" {*", reactorLoadLock, "}]"));
|
|
}
|
|
}
|
|
if (updateValues.Any())
|
|
{
|
|
updatedStream = new org.apache.pdfbox.pdmodel.common.PDStream(pdDocument);
|
|
outputStream = updatedStream.createOutputStream();
|
|
contentStreamWriter = new org.apache.pdfbox.pdfwriter.ContentStreamWriter(outputStream);
|
|
contentStreamWriter.writeTokens(tokenList);
|
|
outputStream.close();
|
|
page.setContents(updatedStream);
|
|
}
|
|
}
|
|
if (updateValues.Any())
|
|
pdDocument.save(checkFileName);
|
|
pdDocument.close();
|
|
}
|
|
|
|
internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, DateTime dateTime, string logisticsSequenceMemoryDirectory, List<pcl.Description> descriptions, string matchDirectory)
|
|
{
|
|
if (fileRead is null)
|
|
{ }
|
|
if (dateTime == DateTime.MinValue)
|
|
{ }
|
|
if (logisticsSequenceMemoryDirectory is null)
|
|
{ }
|
|
if (descriptions is null)
|
|
{ }
|
|
if (matchDirectory is null)
|
|
{ }
|
|
string checkFileName;
|
|
string[] pclFiles = Directory.GetFiles(matchDirectory, "*.pcl", SearchOption.TopDirectoryOnly);
|
|
if (pclFiles.Length != 1)
|
|
throw new Exception("Invalid source file count!");
|
|
string sourceFileNameNoExt = Path.GetFileNameWithoutExtension(pclFiles[0]);
|
|
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;
|
|
List<WS.Attachment> dataAttachments = new();
|
|
List<WS.Attachment> headerAttachments = new();
|
|
checkFileName = string.Concat(matchDirectory, @"\", sourceFileNameNoExt, "_data.pdf");
|
|
if (!File.Exists(checkFileName))
|
|
throw new Exception("Header file doesn't exist!");
|
|
else
|
|
{
|
|
UpdateDataPDF(descriptions, checkFileName);
|
|
headerAttachments.Add(new WS.Attachment(descriptions[0].HeaderUniqueId, "Data.pdf", checkFileName));
|
|
}
|
|
foreach (pcl.Description description in descriptions)
|
|
{
|
|
checkFileName = string.Concat(matchDirectory, @"\", sourceFileNameNoExt, "_", description.Slot.Replace('*', 's'), "_image.pdf");
|
|
if (File.Exists(checkFileName))
|
|
dataAttachments.Add(new WS.Attachment(description.UniqueId, "Image.pdf", checkFileName));
|
|
checkFileName = string.Concat(matchDirectory, @"\", sourceFileNameNoExt, "_", description.Slot.Replace('*', 's'), "_data.pdf");
|
|
if (File.Exists(checkFileName))
|
|
dataAttachments.Add(new WS.Attachment(description.UniqueId, "Data.pdf", checkFileName));
|
|
}
|
|
if (dataAttachments.Count == 0 || dataAttachments.Count != descriptions.Count)
|
|
throw new Exception("Invalid attachment count!");
|
|
WS.AttachFiles(openInsightMetrologyViewerAPI, wsResultsHeaderID, headerAttachments, dataAttachments);
|
|
}
|
|
|
|
} |