Refactor: Update site configuration and enhance file extraction logic in FileRead and ProcessData classes

This commit is contained in:
2025-12-10 11:21:19 -07:00
parent c20799ba72
commit d4e21c2c9a
7 changed files with 157 additions and 537 deletions

View File

@ -97,9 +97,9 @@ public class FileRead : Shared.FileRead, IFileRead
private void CallbackInProcessCleared(string sourceArchiveFile, string traceDummyFile, string targetFileLocation, string monARessource, string inProcessDirectory, long sequence, bool warning)
{
const string site = "sjc";
const string site = "els";
string stateName = string.Concat("Dummy_", _EventName);
const string monInURL = "http://moninhttp.sjc.infineon.com/input/text";
const string monInURL = $"http://moninhttp.{site}.infineon.com/input/text";
MonIn monIn = MonIn.GetInstance(monInURL);
try
{

View File

@ -396,7 +396,7 @@ public class Description : IDescription, Shared.Properties.IDescription
return result;
}
private Description GetDefault(IFileRead fileRead, Logistics logistics)
private static Description GetDefault(IFileRead fileRead, Logistics logistics)
{
Description result = new()
{
@ -497,6 +497,15 @@ public class Description : IDescription, Shared.Properties.IDescription
return result;
}
internal static JsonElement GetDefaultJsonElement(IFileRead fileRead, Logistics logistics)
{
JsonElement result;
Description description = GetDefault(fileRead, logistics);
string json = JsonSerializer.Serialize(description, DescriptionSourceGenerationContext.Default.Description);
result = JsonSerializer.Deserialize<JsonElement>(json);
return result;
}
internal static string GetDateFormat() => "MM/dd/yyyy hh:mm:ss tt";
}

View File

@ -109,39 +109,38 @@ public class FileRead : Shared.FileRead, IFileRead
private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime)
{
Tuple<string, Test[], JsonElement[], List<FileInfo>> results = new(string.Empty, Array.Empty<Test>(), Array.Empty<JsonElement>(), new List<FileInfo>());
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
Test[] tests = Array.Empty<Test>();
List<JsonElement> jsonElements = new();
List<FileInfo> fileInfoCollection = new();
_TickOffset ??= 0; // new FileInfo(reportFullPath).LastWriteTime.Ticks - dateTime.Ticks;
_Logistics = new Logistics(this, _TickOffset.Value, reportFullPath, useSplitForMID: true);
fileInfoCollection.Add(_Logistics.FileInfo);
SetFileParameterLotIDToLogisticsMID();
if (_Logistics.FileInfo.Length < _MinFileLength)
results.Item4.Add(_Logistics.FileInfo);
results = new(string.Empty, tests, jsonElements.ToArray(), fileInfoCollection);
else
{
ReadOnlyDictionary<string, string> pages = Convert.PDF(_Logistics, _GhostPCLFileName, _PDFTextStripperFileName, results.Item4);
Run? run = Run.Get(_Logistics, results.Item4, pages);
ReadOnlyDictionary<string, string> pages = Convert.PDF(_Logistics, _GhostPCLFileName, _PDFTextStripperFileName, fileInfoCollection);
Run? run = Run.Get(this, _Logistics, fileInfoCollection, pages);
if (run is null)
throw new Exception(string.Concat("A) No Data - ", dateTime.Ticks));
IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, pages, run);
if (iProcessData is not ProcessData processData)
results = new(string.Concat("B) No Data - ", dateTime.Ticks), Array.Empty<Test>(), Array.Empty<JsonElement>(), results.Item4);
results = new(string.Concat("A) No Data - ", dateTime.Ticks), tests, jsonElements.ToArray(), fileInfoCollection);
else
{
string mid;
if (!string.IsNullOrEmpty(processData.Lot) && string.IsNullOrEmpty(processData.Reactor) && string.IsNullOrEmpty(processData.RDS) && string.IsNullOrEmpty(processData.PSN))
mid = processData.Lot;
else if (!string.IsNullOrEmpty(processData.Employee) && string.IsNullOrEmpty(processData.Reactor) && string.IsNullOrEmpty(processData.RDS) && string.IsNullOrEmpty(processData.PSN))
mid = processData.Employee;
Descriptor descriptor = ProcessData.GetDescriptor(run.Header.Id);
if (!string.IsNullOrEmpty(descriptor.Lot) && string.IsNullOrEmpty(descriptor.Reactor) && string.IsNullOrEmpty(descriptor.RDS) && string.IsNullOrEmpty(descriptor.PSN))
mid = descriptor.Lot;
else if (!string.IsNullOrEmpty(descriptor.Employee) && string.IsNullOrEmpty(descriptor.Reactor) && string.IsNullOrEmpty(descriptor.RDS) && string.IsNullOrEmpty(descriptor.PSN))
mid = descriptor.Employee;
else
{
mid = string.Concat(processData.Reactor, "-", processData.RDS, "-", processData.PSN);
mid = Regex.Replace(mid, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
}
mid = string.Concat(descriptor.Reactor, "-", descriptor.RDS, "-", descriptor.PSN);
mid = Regex.Replace(mid, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
SetFileParameterLotID(mid);
_Logistics.Update(mid, processData.Reactor);
if (iProcessData.Details.Count > 0)
results = iProcessData.GetResults(this, _Logistics, results.Item4);
else
results = new(string.Concat("LOGISTICS_1 - C) No Data - ", dateTime.Ticks), Array.Empty<Test>(), Array.Empty<JsonElement>(), results.Item4);
_Logistics.Update(mid, descriptor.Reactor);
JsonElement jsonElement = Description.GetDefaultJsonElement(this, _Logistics);
jsonElements.Add(jsonElement);
results = new(_Logistics.Logistics1[0], tests, jsonElements.ToArray(), fileInfoCollection);
}
}
return results;

View File

@ -11,7 +11,8 @@ namespace Adaptation.FileHandlers.pcl;
public class Header
{
public Header(string date,
public Header(string fileName,
string date,
string recipe,
string id,
ReadOnlyCollection<WaferSummary> waferSummary,
@ -52,6 +53,7 @@ public class Header
string hazeRegionStdDev,
string hazeAverageStdDev)
{
FileName = fileName;
Date = date;
Recipe = recipe;
Id = id;
@ -94,6 +96,7 @@ public class Header
HazeAverageStdDev = hazeAverageStdDev;
}
public string FileName { get; }
public string Date { get; }
public string Recipe { get; }
public string Id { get; }
@ -216,8 +219,9 @@ public class Header
return GetBefore(text, i, "\n", false);
}
private static string? GetText(ReadOnlyDictionary<string, string> pages, Constant constant)
private static KeyValuePair<string?, string?> GetHeader(ReadOnlyDictionary<string, string> pages, Constant constant)
{
KeyValuePair<string?, string?> result;
string? text;
string? headerFileName = null;
foreach (KeyValuePair<string, string> keyValuePair in pages)
@ -231,7 +235,8 @@ public class Header
headerFileName ??= pages.Count == 0 ? string.Empty : pages.ElementAt(pages.Count - 1).Key;
if (pages.Count == 0 || !pages.TryGetValue(headerFileName, out text))
text = null;
return text;
result = new(headerFileName, text);
return result;
}
internal static Header Get(ReadOnlyDictionary<string, string> pages, Constant constant)
@ -243,8 +248,10 @@ public class Header
int[] i = new int[] { 0 };
WaferSummary waferSummary;
List<WaferSummary> collection = new();
string? text = GetText(pages, constant);
if (string.IsNullOrEmpty(text))
KeyValuePair<string?, string?> keyValuePair = GetHeader(pages, constant);
string? fileName = keyValuePair.Key;
string? text = keyValuePair.Value;
if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(text))
throw new Exception();
ScanPast(text, i, constant.Date);
string date = GetToEOL(text, i);
@ -289,7 +296,8 @@ public class Header
ScanPast(text, i, constant.StdDev);
string[] preToEol4 = GetToEOL(text, i, false).Trim().Split(' ');
ReadOnlyCollection<string> toEol4 = FixToEolArray(preToEol4);
result = new(date: date,
result = new(fileName: fileName,
date: date,
recipe: recipe,
id: id,
waferSummary: collection.AsReadOnly(),

View File

@ -1,6 +1,5 @@
using Adaptation.Shared;
using Adaptation.Shared.Methods;
using log4net;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -9,7 +8,6 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
namespace Adaptation.FileHandlers.pcl;
@ -17,12 +15,6 @@ namespace Adaptation.FileHandlers.pcl;
public class ProcessData : IProcessData
{
private int _I;
private string _Data;
private readonly ILog _Log;
private readonly List<object> _Details;
public string JobID { get; set; }
public string MesEntity { get; set; }
public string AreaCountAvg { get; set; }
@ -71,194 +63,19 @@ public class ProcessData : IProcessData
public string SumOfDefectsStdDev { get; set; }
public string UniqueId { get; set; }
List<object> Shared.Properties.IProcessData.Details => _Details;
List<object> Shared.Properties.IProcessData.Details { get; }
internal ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, ReadOnlyDictionary<string, string> pages, Run run)
{
_Details = new List<object>();
_I = 0;
_Data = string.Empty;
JobID = logistics.JobID;
Date = GetDateTime(logistics);
MesEntity = logistics.MesEntity;
_Log = LogManager.GetLogger(typeof(ProcessData));
Parse(fileRead, logistics, fileInfoCollection, pages, run);
}
#nullable enable
string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary<string, string> reactors) =>
throw new Exception(string.Concat("See ", nameof(ProcessData)));
Tuple<string, Test[], JsonElement[], List<FileInfo>> IProcessData.GetResults(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection) =>
throw new NotImplementedException();
private static DateTime GetDateTime(Logistics logistics) =>
logistics.DateTimeFromSequence;
string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary<string, string> reactors) => throw new Exception(string.Concat("See ", nameof(Parse)));
Tuple<string, Test[], JsonElement[], List<FileInfo>> IProcessData.GetResults(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection)
{
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
List<Test> tests = new();
foreach (object item in _Details)
tests.Add(Test.Tencor);
List<IDescription> descriptions = fileRead.GetDescriptions(fileRead, tests, this);
if (tests.Count != descriptions.Count)
throw new Exception();
for (int i = 0; i < tests.Count; i++)
{
if (descriptions[i] is not Description description)
throw new Exception();
if (description.Test != (int)tests[i])
throw new Exception();
}
FileInfo fileInfo = new($"{logistics.ReportFullPath}.descriptions.json");
List<Description> fileReadDescriptions = (from l in descriptions select (Description)l).ToList();
string json = JsonSerializer.Serialize(fileReadDescriptions, fileReadDescriptions.GetType());
File.WriteAllText(fileInfo.FullName, json);
File.SetLastWriteTime(fileInfo.FullName, logistics.DateTimeFromSequence);
fileInfoCollection.Add(fileInfo);
JsonElement[] jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json) ?? throw new Exception();
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(logistics.Logistics1[0], tests.ToArray(), jsonElements, fileInfoCollection);
return results;
}
/// <summary>
/// Test and fix a data line from the Lot Summary page if there are two values that are merged.
/// </summary>
/// <param name="toEol">data line from Lot Summary</param>
private void FixToEolArray(ref string[] toEol)
{
const int MAX_COLUMNS = 9;
int[] mColumnWidths = new int[MAX_COLUMNS] { 8, 6, 6, 6, 6, 7, 7, 5, 7 };
// is it short at least one data point
if (toEol.Length < MAX_COLUMNS)
{
_Log.Debug($"****FixToEolArray - Starting array:");
_Log.Debug(toEol);
_Log.Debug($"****FixToEolArray - Column widths:");
_Log.Debug(mColumnWidths);
string leftVal, rightVal;
// size up and assign a working list
List<string> toEolList = new(toEol);
if (string.IsNullOrEmpty(toEolList[toEolList.Count - 1]))
toEolList.RemoveAt(toEolList.Count - 1); // removes a null element at end
_Log.Debug($"****FixToEolArray - New toEolList:");
_Log.Debug(toEolList);
for (int i = toEolList.Count; i < MAX_COLUMNS; i++)
toEolList.Insert(0, ""); // insert to top of list
_Log.Debug(toEolList);
// start at the end
for (int i = MAX_COLUMNS - 1; i >= 0; i--)
{
// test for a bad value - does it have too many characters
_Log.Debug($"****FixToEolArray - toEolList[i].Length: {toEolList[i].Length}, mColumnWidths[i]: {mColumnWidths[i]}");
if (toEolList[i].Length > mColumnWidths[i])
{
// split it up into its two parts
leftVal = toEolList[i].Substring(0, toEolList[i].Length - mColumnWidths[i]);
rightVal = toEolList[i].Substring(leftVal.Length);
_Log.Debug($"****FixToEolArray - Split leftVal: {leftVal}");
_Log.Debug($"****FixToEolArray - Split rightVal: {rightVal}");
// insert new value
toEolList[i] = rightVal;
toEolList.Insert(i, leftVal);
if (string.IsNullOrEmpty(toEolList[0]))
toEolList.RemoveAt(0); // removes a null element at end
_Log.Debug($"****FixToEolArray - Fixed toEolList:");
_Log.Debug(toEolList);
}
}
toEol = toEolList.ToArray();
_Log.Debug($"****FixToEolArray - Ending array:");
_Log.Debug(toEol);
}
}
private void ScanPast(string text)
{
int num = _Data.IndexOf(text, _I);
if (num > -1)
_I = num + text.Length;
else
_I = _Data.Length;
}
private string GetBefore(string text)
{
int num = _Data.IndexOf(text, _I);
if (num > -1)
{
string str = _Data.Substring(_I, num - _I);
_I = num + text.Length;
return str.Trim();
}
string str1 = _Data.Substring(_I);
_I = _Data.Length;
return str1.Trim();
}
private string GetBefore(string text, bool trim)
{
if (trim)
return GetBefore(text);
int num = _Data.IndexOf(text, _I);
if (num > -1)
{
string str = _Data.Substring(_I, num - _I);
_I = num + text.Length;
return str;
}
string str1 = _Data.Substring(_I);
_I = _Data.Length;
return str1;
}
private static bool IsNullOrWhiteSpace(string text)
{
for (int index = 0; index < text.Length; ++index)
{
if (!char.IsWhiteSpace(text[index]))
return false;
}
return true;
}
private bool IsBlankLine()
{
int num = _Data.IndexOf("\n", _I);
return IsNullOrWhiteSpace(num > -1 ? _Data.Substring(_I, num - _I) : _Data.Substring(_I));
}
private string GetToEOL() => GetBefore("\n");
private string GetToEOL(bool trim)
{
if (trim)
return GetToEOL();
return GetBefore("\n", false);
}
private string GetToText(string text) =>
_Data.Substring(_I, _Data.IndexOf(text, _I) - _I).Trim();
private string GetToken()
{
while (_I < _Data.Length && IsNullOrWhiteSpace(_Data.Substring(_I, 1)))
++_I;
int j = _I;
while (j < _Data.Length && !IsNullOrWhiteSpace(_Data.Substring(j, 1)))
++j;
string str = _Data.Substring(_I, j - _I);
_I = j;
return str.Trim();
}
private string PeekNextLine()
{
int j = _I;
string result = GetToEOL();
_I = j;
return result;
}
private static (string, string) GetReactorAndRDS(string defaultReactor, string defaultRDS, string text, string formattedText, string[] segments)
{
string rds;
@ -385,320 +202,8 @@ public class ProcessData : IProcessData
return result;
}
private void Set(ILogistics logistics, Run run)
{
string lot;
string rds;
string psn;
string recipe;
string reactor;
string employee;
ScanPast("Recipe ID:");
_ = GetBefore("LotID:");
lot = run.Header.Id;
recipe = run.Header.Recipe;
Descriptor descriptor = GetDescriptor(lot);
lot = descriptor.Lot;
psn = descriptor.PSN;
rds = descriptor.RDS;
reactor = descriptor.Reactor;
employee = descriptor.Employee;
Lot = lot;
PSN = psn;
RDS = rds;
Recipe = recipe;
Reactor = reactor;
Employee = employee;
UniqueId = string.Format("{0}_{1}_{2}", logistics.JobID, lot, Path.GetFileNameWithoutExtension(logistics.ReportFullPath));
}
private void ParseLotSummary(ILogistics logistics, ReadOnlyDictionary<string, string> pages, Run run, string headerFileName, Dictionary<string, List<Detail>> slots)
{
_I = 0;
ParseErrorText = string.Empty;
if (!pages.TryGetValue(headerFileName, out string value))
throw new Exception();
_I = 0;
_Data = value;
ScanPast("Date:");
_ = GetToEOL();
Set(logistics, run);
// determine number of wafers and their slot numbers
_Log.Debug(_Data.Substring(_I));
string slot;
string toEOL;
int slotCount = _Data.Substring(_I).Split('*').Length - 1;
_Log.Debug($"****HeaderFile - Slot Count: {slotCount}.");
for (int i = 0; i < slotCount; i++)
{
ScanPast("*");
toEOL = GetToEOL(false);
slot = string.Concat("*", toEOL.Substring(0, 2));
if (!slots.ContainsKey(slot))
slots.Add(slot, new List<Detail>());
}
_Log.Debug($"****HeaderFile - Slots:");
_Log.Debug(slots);
ScanPast("Min:");
string[] toEol1 = GetToEOL(false).Trim().Split(' ');
_Log.Debug($"****HeaderFile - toEol1 Count: {toEol1.Length}.");
FixToEolArray(ref toEol1);
LPDCountMin = toEol1[0].Trim();
LPDCM2Min = toEol1[1].Trim();
AreaCountMin = toEol1[2].Trim();
AreaTotalMin = toEol1[3].Trim();
ScratchCountMin = toEol1[4].Trim();
ScratchTotalMin = toEol1[5].Trim();
SumOfDefectsMin = toEol1[6].Trim();
HazeRegionMin = toEol1[7].Trim();
HazeAverageMin = toEol1[8].Trim();
ScanPast("Max:");
string[] toEol2 = GetToEOL(false).Trim().Split(' ');
_Log.Debug($"****HeaderFile - toEol2 Count: {toEol2.Length}.");
FixToEolArray(ref toEol2);
LPDCountMax = toEol2[0].Trim();
LPDCM2Max = toEol2[1].Trim();
AreaCountMax = toEol2[2].Trim();
AreaTotalMax = toEol2[3].Trim();
ScratchCountMax = toEol2[4].Trim();
ScratchTotalMax = toEol2[5].Trim();
SumOfDefectsMax = toEol2[6].Trim();
HazeRegionMax = toEol2[7].Trim();
HazeAverageMax = toEol2[8].Trim();
ScanPast("Average:");
string[] toEol3 = GetToEOL(false).Trim().Split(' ');
_Log.Debug($"****HeaderFile - toEol3 Count: {toEol3.Length}.");
FixToEolArray(ref toEol3);
LPDCountAvg = toEol3[0].Trim();
LPDCM2Avg = toEol3[1].Trim();
AreaCountAvg = toEol3[2].Trim();
AreaTotalAvg = toEol3[3].Trim();
ScratchCountAvg = toEol3[4].Trim();
ScratchTotalAvg = toEol3[5].Trim();
SumOfDefectsAvg = toEol3[6].Trim();
HazeRegionAvg = toEol3[7].Trim();
HazeAverageAvg = toEol3[8].Trim();
ScanPast("Std Dev:");
string[] toEol4 = GetToEOL(false).Trim().Split(' ');
_Log.Debug($"****HeaderFile - toEol4 Count: {toEol4.Length}.");
FixToEolArray(ref toEol4);
LPDCountStdDev = toEol4[0].Trim();
LPDCM2StdDev = toEol4[1].Trim();
AreaCountStdDev = toEol4[2].Trim();
AreaTotalStdDev = toEol4[3].Trim();
ScratchCountStdDev = toEol4[4].Trim();
ScratchTotalStdDev = toEol4[5].Trim();
SumOfDefectsStdDev = toEol4[6].Trim();
HazeRegionStdDev = toEol4[7].Trim();
HazeAverageStdDev = toEol4[8].Trim();
}
private Detail ParseWaferSummary(string waferFileName, ReadOnlyDictionary<string, string> pages)
{
Detail result = new() { Data = "*Data*", i = -1, };
_I = 0;
List<string> stringList = new();
result.HeaderUniqueId = UniqueId;
result.Id = 0;
result.Title = null;
if (!pages.TryGetValue(waferFileName, out string value))
throw new Exception();
_I = 0;
_Data = value;
ScanPast("Date:");
result.Date = GetToEOL();
ScanPast("ID#");
result.Slot = GetToEOL();
if (result.Slot.Length > 5)
result.Slot = string.Concat(result.Slot.Substring(0, 5), "... - ***");
//result.Slot = result.Slot.Replace("*", "");
ScanPast("Comments:");
result.Comments = GetToEOL();
ScanPast("Sort:");
result.Sort = GetToEOL();
ScanPast("LPD Count:");
result.LPDCount = GetToEOL();
ScanPast("LPD / cm2:");
result.LPDCM2 = GetToEOL();
while (GetBefore(":").Contains("Bin"))
stringList.Add(GetToEOL());
if (stringList.Count >= 1)
result.Bin1 = stringList[0];
if (stringList.Count >= 2)
result.Bin2 = stringList[1];
if (stringList.Count >= 3)
result.Bin3 = stringList[2];
if (stringList.Count >= 4)
result.Bin4 = stringList[3];
if (stringList.Count >= 5)
result.Bin5 = stringList[4];
if (stringList.Count >= 6)
result.Bin6 = stringList[5];
if (stringList.Count >= 7)
result.Bin7 = stringList[6];
if (stringList.Count >= 8)
result.Bin8 = stringList[7];
result.Mean = GetToEOL();
ScanPast("Std Dev:");
result.StdDev = GetToEOL();
ScanPast("Area Count:");
result.AreaCount = GetToEOL();
ScanPast("Area Total:");
result.AreaTotal = GetToEOL();
ScanPast("Scratch Count:");
result.ScratchCount = GetToEOL();
ScanPast("Scratch Total:");
result.ScratchTotal = GetToEOL();
ScanPast("Sum of All Defects:");
result.SumOfDefects = GetToEOL();
ScanPast("Haze Region:");
result.HazeRegion = GetToEOL();
ScanPast("Haze Average:");
result.HazeAverage = GetToEOL();
ScanPast("Haze Peak:");
result.HazePeak = GetToEOL();
ScanPast("Laser:");
result.Laser = GetBefore("Gain:");
result.Gain = GetBefore("Diameter:");
result.Diameter = GetToEOL();
ScanPast("Thresh:");
result.Thresh = GetBefore("Exclusion:");
result.Exclusion = GetToEOL();
ScanPast("Haze Rng:");
result.HazeRng = GetBefore("Thruput:");
result.Thruput = GetToEOL();
ScanPast("Recipe ID:");
result.Recipe = GetToEOL();
result.UniqueId = string.Format("{0}_{1}", UniqueId, result.Slot.Replace("*", string.Empty).TrimStart('0'));
return result;
}
/// <summary>
/// Convert the raw data file to parsable file format - in this case from PCL to PDF
/// </summary>
/// <param name="sourceFile">source file to be converted to PDF</param>
/// <returns></returns>
private static string ConvertSourceFileToPdf(string ghostPCLFileName, Logistics logistics)
{
string result = Path.ChangeExtension(logistics.ReportFullPath, ".pdf");
if (!File.Exists(result))
{
//string arguments = string.Concat("-i \"", sourceFile, "\" -o \"", result, "\"");
string arguments = string.Concat("-dSAFER -dBATCH -dNOPAUSE -sOutputFile=\"", result, "\" -sDEVICE=pdfwrite \"", logistics.ReportFullPath, "\"");
//Process process = Process.Start(configData.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;
}
#nullable enable
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, ReadOnlyDictionary<string, string> pages, Run run)
{
if (fileRead is null)
throw new ArgumentNullException(nameof(fileRead));
List<string> sourceFiles = new();
List<string> missingSlots = new();
Dictionary<string, List<Detail>> slots = new();
List<Tuple<string, string>> pageMapping = new();
_Log.Debug($"****ParseData - Parsing lot summary");
string headerFileName = pages.ElementAt(pages.Count - 1).Key;
ParseLotSummary(logistics, pages, run, headerFileName, slots);
string sourcePath = Path.GetDirectoryName(logistics.ReportFullPath) ?? throw new Exception();
string sourceFileNameWithoutExtension = Path.GetFileNameWithoutExtension(logistics.ReportFullPath);
foreach (FileInfo fileInfo in fileInfoCollection)
sourceFiles.Add(fileInfo.FullName);
fileInfoCollection.Clear();
foreach (KeyValuePair<string, string> keyValuePair in pages)
{
if (keyValuePair.Key == headerFileName)
continue;
if (string.IsNullOrEmpty(keyValuePair.Value.Trim()))
{
pageMapping.Add(new Tuple<string, string>(keyValuePair.Key, string.Empty));
continue;
}
if (!pages.ContainsKey(keyValuePair.Key))
throw new Exception();
Detail dataFile = ParseWaferSummary(keyValuePair.Key, pages);
if (string.IsNullOrEmpty(dataFile.Recipe) || dataFile.Recipe != Recipe)
{
missingSlots.Add(keyValuePair.Key);
pageMapping.Add(new Tuple<string, string>(keyValuePair.Key, string.Empty));
continue;
}
if (!slots.ContainsKey(dataFile.Slot))
{
missingSlots.Add(keyValuePair.Key);
pageMapping.Add(new Tuple<string, string>(keyValuePair.Key, string.Empty));
continue;
}
pageMapping.Add(new Tuple<string, string>(keyValuePair.Key, string.Concat(sourcePath, @"\", sourceFileNameWithoutExtension, "_", dataFile.Slot.Replace('*', 's'), "_data.pdf")));
slots[dataFile.Slot].Add(dataFile);
}
string checkFileName = string.Concat(sourcePath, @"\", sourceFileNameWithoutExtension, "_data.pdf");
if (fileRead.IsEAFHosted && !File.Exists(checkFileName))
{
File.Move(headerFileName, checkFileName);
_ = sourceFiles.Remove(headerFileName);
sourceFiles.Add(checkFileName);
}
checkFileName = string.Empty;
for (int i = pageMapping.Count - 1; i > -1; i--)
{
if (!string.IsNullOrEmpty(pageMapping[i].Item2))
{
checkFileName = pageMapping[i].Item2;
if (fileRead.IsEAFHosted && !File.Exists(checkFileName))
{
File.Move(pageMapping[i].Item1, checkFileName);
_ = sourceFiles.Remove(pageMapping[i].Item1);
sourceFiles.Add(checkFileName);
}
}
else if (!string.IsNullOrEmpty(checkFileName))
{
checkFileName = checkFileName.Replace("_data.pdf", "_image.pdf");
if (fileRead.IsEAFHosted && !File.Exists(checkFileName))
{
File.Move(pageMapping[i].Item1, checkFileName);
_ = sourceFiles.Remove(pageMapping[i].Item1);
sourceFiles.Add(checkFileName);
}
checkFileName = string.Empty;
}
}
foreach (KeyValuePair<string, List<Detail>> keyValuePair in slots)
{
if (keyValuePair.Value.Count == 0 || keyValuePair.Value[0] is null)
missingSlots.Add(string.Concat("Slot ", keyValuePair.Key, ") is missing."));
else
{
foreach (Detail data in keyValuePair.Value)
_Details.Add(data);
}
}
if (missingSlots.Count != 0)
{
string missingSlotsFile = string.Concat(sourcePath, @"\", sourceFileNameWithoutExtension, "_MissingSlots.txt");
File.WriteAllLines(missingSlotsFile, missingSlots);
sourceFiles.Add(missingSlotsFile);
}
//for (int i = 0; i < dataFiles.Count; i++)
// dataFiles[i].Date = DateTime.Parse(dataFiles[i].Date).ToString();
foreach (string sourceFile in sourceFiles)
fileInfoCollection.Add(new FileInfo(sourceFile));
fileInfoCollection.Add(logistics.FileInfo);
}
internal static List<Description> GetDescriptions(JsonElement[] jsonElements)
{
List<Description> results = new();

View File

@ -1,4 +1,5 @@
using Adaptation.Shared;
using Adaptation.Shared.Methods;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -111,6 +112,99 @@ internal class Run
File.WriteAllText($"{logistics.ReportFullPath}.csv", string.Join(Environment.NewLine, lines));
}
private static void Rename(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, ReadOnlyDictionary<string, string> pages, Run run)
{
string slotName;
string fileName;
string? pageText;
string checkFileName;
List<string> sourceFiles = new();
List<string> missingSlots = new();
Dictionary<string, List<Wafer>> slots = new();
List<Tuple<string, string>> pageMapping = new();
string sourcePath = Path.GetDirectoryName(logistics.ReportFullPath) ?? throw new Exception();
string sourceFileNameWithoutExtension = Path.GetFileNameWithoutExtension(logistics.ReportFullPath);
foreach (FileInfo fileInfo in fileInfoCollection)
sourceFiles.Add(fileInfo.FullName);
fileInfoCollection.Clear();
fileInfoCollection.Add(logistics.FileInfo);
checkFileName = string.Concat(sourcePath, @"\", sourceFileNameWithoutExtension, "_data.pdf");
if (fileRead.IsEAFHosted && !File.Exists(checkFileName))
{
File.Move(run.Header.FileName, checkFileName);
_ = sourceFiles.Remove(run.Header.FileName);
sourceFiles.Add(checkFileName);
}
foreach (Wafer wafer in run.Wafers)
{
if (!pages.TryGetValue(wafer.FileName, out pageText))
continue;
if (string.IsNullOrEmpty(pageText.Trim()))
{
pageMapping.Add(new Tuple<string, string>(wafer.FileName, string.Empty));
continue;
}
if (run.Header.AreaCountAvg is null)
{
if (string.IsNullOrEmpty(wafer.Recipe) || wafer.Recipe != run.Header.Recipe)
{
missingSlots.Add(string.Concat("Slot ", wafer.Id, ") is missing."));
pageMapping.Add(new Tuple<string, string>(wafer.FileName, string.Empty));
continue;
}
if (!slots.ContainsKey(wafer.Id))
{
missingSlots.Add(wafer.FileName);
pageMapping.Add(new Tuple<string, string>(wafer.FileName, string.Empty));
continue;
}
slotName = wafer.Id.Contains('*') ? wafer.Id.Replace('*', 's') : $"s{wafer.Id}";
fileName = string.Concat(sourcePath, @"\", sourceFileNameWithoutExtension, "_", slotName, "_data.pdf");
pageMapping.Add(new Tuple<string, string>(wafer.FileName, fileName));
slots[wafer.Id].Add(wafer);
}
}
checkFileName = string.Empty;
for (int i = pageMapping.Count - 1; i > -1; i--)
{
if (!string.IsNullOrEmpty(pageMapping[i].Item2))
{
checkFileName = pageMapping[i].Item2;
if (fileRead.IsEAFHosted && !File.Exists(checkFileName))
{
File.Move(pageMapping[i].Item1, checkFileName);
_ = sourceFiles.Remove(pageMapping[i].Item1);
sourceFiles.Add(checkFileName);
}
}
else if (!string.IsNullOrEmpty(checkFileName))
{
checkFileName = checkFileName.Replace("_data.pdf", "_image.pdf");
if (fileRead.IsEAFHosted && !File.Exists(checkFileName))
{
File.Move(pageMapping[i].Item1, checkFileName);
_ = sourceFiles.Remove(pageMapping[i].Item1);
sourceFiles.Add(checkFileName);
}
checkFileName = string.Empty;
}
}
foreach (KeyValuePair<string, List<Wafer>> keyValuePair in slots)
{
if (keyValuePair.Value.Count == 0 || keyValuePair.Value[0] is null)
missingSlots.Add(string.Concat("Slot ", keyValuePair.Key, ") is missing."));
}
if (missingSlots.Count != 0)
{
string missingSlotsFile = string.Concat(sourcePath, @"\", sourceFileNameWithoutExtension, "_MissingSlots.txt");
File.WriteAllLines(missingSlotsFile, missingSlots);
sourceFiles.Add(missingSlotsFile);
}
foreach (string sourceFile in sourceFiles)
fileInfoCollection.Add(new FileInfo(sourceFile));
fileInfoCollection.Add(logistics.FileInfo);
}
private static ReadOnlyCollection<string> GetWaferIds(Header header)
{
List<string> results = new();
@ -119,7 +213,7 @@ internal class Run
return results.AsReadOnly();
}
internal static Run? Get(Logistics logistics, List<FileInfo> fileInfoCollection, ReadOnlyDictionary<string, string> pages)
internal static Run? Get(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, ReadOnlyDictionary<string, string> pages)
{
Run? result;
Constant constant = new();
@ -130,6 +224,7 @@ internal class Run
{
ReadOnlyCollection<Wafer> wafers = GetLastWaferForEachSlot(pages, constant, header);
result = new(header, wafers);
Rename(fileRead, logistics, fileInfoCollection, pages, result);
WriteJson(logistics, fileInfoCollection, result);
WriteCommaSeparatedValues(logistics, result);
}

View File

@ -11,8 +11,9 @@ namespace Adaptation.FileHandlers.pcl;
public class Wafer
{
public Wafer(string date, string id, string comments, string sort, string lPDCount, string lPDCM2, string bin1, string bin2, string bin3, string bin4, string bin5, string bin6, string bin7, string bin8, string mean, string stdDev, string areaCount, string areaTotal, string scratchCount, string scratchTotal, string sumOfDefects, string hazeRegion, string hazeAverage, string hazePeak, string laser, string gain, string diameter, string thresh, string exclusion, string hazeRng, string thruput, string recipe)
public Wafer(string fileName, string date, string id, string comments, string sort, string lPDCount, string lPDCM2, string bin1, string bin2, string bin3, string bin4, string bin5, string bin6, string bin7, string bin8, string mean, string stdDev, string areaCount, string areaTotal, string scratchCount, string scratchTotal, string sumOfDefects, string hazeRegion, string hazeAverage, string hazePeak, string laser, string gain, string diameter, string thresh, string exclusion, string hazeRng, string thruput, string recipe)
{
FileName = fileName;
Date = date;
Id = id;
Comments = comments;
@ -48,7 +49,8 @@ public class Wafer
}
internal static Wafer Get(string id) =>
new(date: string.Empty,
new(fileName: string.Empty,
date: string.Empty,
id: id,
comments: string.Empty,
sort: string.Empty,
@ -81,6 +83,7 @@ public class Wafer
thruput: string.Empty,
recipe: string.Empty);
public string FileName { get; }
public string Date { get; }
public string Id { get; }
public string Comments { get; }
@ -186,7 +189,8 @@ public class Wafer
string thruput = Header.GetToEOL(text, i);
Header.ScanPast(text, i, "Recipe ID:");
string recipe = Header.GetToEOL(text, i);
wafer = new(date: date,
wafer = new(fileName: keyValuePair.Key,
date: date,
id: id,
comments: comments,
sort: sort,