Ready to test v2.43.0
This commit is contained in:
@ -6,7 +6,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@ -16,25 +15,29 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
|
||||
private readonly string _GhostPCLFileName;
|
||||
private readonly string _PDFTextStripperFileName;
|
||||
|
||||
public FileRead(ISMTP smtp, Dictionary<string, string> fileParameter, string cellInstanceName, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList<ModelObjectParameterDefinition> modelObjectParameters, string equipmentDictionaryName, Dictionary<string, List<long>> dummyRuns, bool useCyclicalForDescription, bool isEAFHosted) :
|
||||
base(new Description(), true, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted)
|
||||
public FileRead(ISMTP smtp, Dictionary<string, string> fileParameter, string cellInstanceName, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList<ModelObjectParameterDefinition> modelObjectParameters, string equipmentDictionaryName, Dictionary<string, List<long>> dummyRuns, Dictionary<long, List<string>> staticRuns, bool useCyclicalForDescription, bool isEAFHosted) :
|
||||
base(new Description(), true, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted)
|
||||
{
|
||||
_MinFileLength = 15;
|
||||
_NullData = string.Empty;
|
||||
_Logistics = new Logistics(this);
|
||||
_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);
|
||||
_GhostPCLFileName = string.Concat(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"\gpcl6win64.exe");
|
||||
_GhostPCLFileName = Path.Combine(AppContext.BaseDirectory, "gpcl6win64.exe");
|
||||
if (!File.Exists(_GhostPCLFileName))
|
||||
throw new Exception("Ghost PCL FileName doesn't Exist!");
|
||||
_PDFTextStripperFileName = Path.Combine(AppContext.BaseDirectory, "PDF-Text-Stripper.exe");
|
||||
if (!File.Exists(_PDFTextStripperFileName))
|
||||
throw new Exception("PDF-Text-Stripper FileName doesn't Exist!");
|
||||
}
|
||||
|
||||
void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) => Move(extractResults, exception);
|
||||
void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) => Move(extractResults);
|
||||
|
||||
void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null);
|
||||
|
||||
@ -99,8 +102,6 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
return results;
|
||||
}
|
||||
|
||||
void IFileRead.CheckTests(Test[] tests, bool extra) => throw new Exception(string.Concat("Not ", nameof(_IsDuplicator)));
|
||||
|
||||
private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime)
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results = new(string.Empty, null, null, new List<FileInfo>());
|
||||
@ -110,17 +111,16 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
results.Item4.Add(new FileInfo(reportFullPath));
|
||||
else
|
||||
{
|
||||
IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, _GhostPCLFileName);
|
||||
if (iProcessData is ProcessData processData)
|
||||
{
|
||||
string mid = string.Concat(processData.Reactor, "-", processData.RDS, "-", processData.PSN);
|
||||
mid = Regex.Replace(mid, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
|
||||
_Logistics.MID = mid;
|
||||
SetFileParameterLotID(mid);
|
||||
_Logistics.ProcessJobID = processData.Reactor;
|
||||
}
|
||||
IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, _GhostPCLFileName, _PDFTextStripperFileName);
|
||||
if (iProcessData is not ProcessData processData)
|
||||
throw new Exception(string.Concat("A) No Data - ", dateTime.Ticks));
|
||||
string mid = string.Concat(processData.Reactor, "-", processData.RDS, "-", processData.PSN);
|
||||
mid = Regex.Replace(mid, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
|
||||
_Logistics.MID = mid;
|
||||
SetFileParameterLotID(mid);
|
||||
_Logistics.ProcessJobID = processData.Reactor;
|
||||
if (!iProcessData.Details.Any())
|
||||
throw new Exception(string.Concat("No Data - ", dateTime.Ticks));
|
||||
throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks));
|
||||
results = iProcessData.GetResults(this, _Logistics, results.Item4);
|
||||
}
|
||||
return results;
|
||||
|
@ -5,11 +5,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Adaptation.FileHandlers.pcl;
|
||||
@ -79,7 +78,7 @@ public class ProcessData : IProcessData
|
||||
|
||||
List<object> Shared.Properties.IProcessData.Details => _Details;
|
||||
|
||||
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string ghostPCLFileName)
|
||||
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string ghostPCLFileName, string pdfTextStripperFileName)
|
||||
{
|
||||
fileInfoCollection.Clear();
|
||||
_Details = new List<object>();
|
||||
@ -89,7 +88,7 @@ public class ProcessData : IProcessData
|
||||
MesEntity = logistics.MesEntity;
|
||||
_Log = LogManager.GetLogger(typeof(ProcessData));
|
||||
Date = DateTime.Now.ToString();
|
||||
Parse(fileRead, logistics, fileInfoCollection, ghostPCLFileName);
|
||||
Parse(fileRead, logistics, fileInfoCollection, ghostPCLFileName, pdfTextStripperFileName);
|
||||
}
|
||||
|
||||
string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary<string, string> reactors) => throw new Exception(string.Concat("See ", nameof(Parse)));
|
||||
@ -99,7 +98,7 @@ public class ProcessData : IProcessData
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
List<Test> tests = new();
|
||||
foreach (object item in _Details)
|
||||
tests.Add(Test.HGCV);
|
||||
tests.Add(Test.HgCV);
|
||||
List<IDescription> descriptions = fileRead.GetDescriptions(fileRead, tests, this);
|
||||
if (tests.Count != descriptions.Count)
|
||||
throw new Exception();
|
||||
@ -201,7 +200,25 @@ public class ProcessData : IProcessData
|
||||
return text.Trim();
|
||||
}
|
||||
|
||||
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string ghostPCLFileName)
|
||||
private static string GetTextFromPDF(string pdfTextStripperFileName, string sourceFileNamePdf, string altHeaderFileName)
|
||||
{
|
||||
string result;
|
||||
ProcessStartInfo processStartInfo = new(pdfTextStripperFileName, $"s \"{sourceFileNamePdf}\"")
|
||||
{
|
||||
UseShellExecute = false,
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true,
|
||||
};
|
||||
Process process = Process.Start(processStartInfo);
|
||||
_ = process.WaitForExit(30000);
|
||||
if (!File.Exists(altHeaderFileName))
|
||||
result = string.Empty;
|
||||
else
|
||||
result = File.ReadAllText(altHeaderFileName);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string ghostPCLFileName, string pdfTextStripperFileName)
|
||||
{
|
||||
if (fileRead is null)
|
||||
{ }
|
||||
@ -216,13 +233,25 @@ public class ProcessData : IProcessData
|
||||
}
|
||||
else
|
||||
{
|
||||
//Pdfbox, IKVM.AWT.WinForms
|
||||
org.apache.pdfbox.pdmodel.PDDocument pdfDocument = org.apache.pdfbox.pdmodel.PDDocument.load(sourceFileNamePdf);
|
||||
org.apache.pdfbox.util.PDFTextStripper stripper = new();
|
||||
headerText = stripper.getText(pdfDocument);
|
||||
pdfDocument.close();
|
||||
File.AppendAllText(altHeaderFileName, headerText);
|
||||
fileInfoCollection.Add(new FileInfo(altHeaderFileName));
|
||||
try
|
||||
{
|
||||
//Pdfbox, IKVM.AWT.WinForms
|
||||
org.apache.pdfbox.pdmodel.PDDocument pdfDocument = org.apache.pdfbox.pdmodel.PDDocument.load(sourceFileNamePdf);
|
||||
org.apache.pdfbox.util.PDFTextStripper stripper = new();
|
||||
headerText = stripper.getText(pdfDocument);
|
||||
pdfDocument.close();
|
||||
File.AppendAllText(altHeaderFileName, headerText);
|
||||
fileInfoCollection.Add(new FileInfo(altHeaderFileName));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (!File.Exists(pdfTextStripperFileName))
|
||||
throw;
|
||||
headerText = GetTextFromPDF(pdfTextStripperFileName, sourceFileNamePdf, altHeaderFileName);
|
||||
if (string.IsNullOrEmpty(headerText))
|
||||
throw;
|
||||
fileInfoCollection.Add(new FileInfo(altHeaderFileName));
|
||||
}
|
||||
}
|
||||
if (headerText.Contains("G A T E V O L T A G E"))
|
||||
throw new Exception("Ignore: GATEVOLTAGE runs are not parsed.");
|
||||
@ -374,6 +403,7 @@ public class ProcessData : IProcessData
|
||||
hgProbeDetail.Phase = GetToken();
|
||||
_ = GetToEOL();
|
||||
hgProbeDetail.Grade = GetToken();
|
||||
;
|
||||
hgProbeDetail.UniqueId = string.Concat("_Point-", _Details.Count + 1);
|
||||
_Details.Add(hgProbeDetail);
|
||||
_ = GetToken();
|
||||
@ -392,8 +422,9 @@ public class ProcessData : IProcessData
|
||||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
UniqueId = string.Format("{0}_{1}_{2}", logistics.JobID, Lot, Path.GetFileNameWithoutExtension(logistics.ReportFullPath));
|
||||
foreach (Detail detail in _Details)
|
||||
foreach (Detail detail in _Details.Cast<Detail>())
|
||||
{
|
||||
detail.HeaderUniqueId = UniqueId;
|
||||
detail.UniqueId = string.Concat(detail, detail.UniqueId);
|
||||
@ -401,4 +432,19 @@ public class ProcessData : IProcessData
|
||||
fileInfoCollection.Add(new FileInfo(logistics.ReportFullPath));
|
||||
}
|
||||
|
||||
internal static List<Description> GetDescriptions(JsonElement[] jsonElements)
|
||||
{
|
||||
List<Description> results = new();
|
||||
Description description;
|
||||
JsonSerializerOptions jsonSerializerOptions = new() { NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString };
|
||||
foreach (JsonElement jsonElement in jsonElements)
|
||||
{
|
||||
if (jsonElement.ValueKind != JsonValueKind.Object)
|
||||
throw new Exception();
|
||||
description = JsonSerializer.Deserialize<Description>(jsonElement.ToString(), jsonSerializerOptions);
|
||||
results.Add(description);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
0
Adaptation/FileHandlers/pcl/teest.cs
Normal file
0
Adaptation/FileHandlers/pcl/teest.cs
Normal file
Reference in New Issue
Block a user