Ready to test v2.43.0
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user