DEP08SIASM - v2.43.0 - Running but

with nuget_System.Text.Json v5.0.1
This commit is contained in:
2022-06-28 11:57:49 -07:00
parent c7884587bb
commit 1a152fafe0
75 changed files with 3067 additions and 2859 deletions

View File

@ -7,7 +7,6 @@ using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Text.RegularExpressions;
@ -20,20 +19,21 @@ public class FileRead : Shared.FileRead, IFileRead
protected string _LastText;
protected readonly int _EndX;
protected readonly int _EndY;
protected readonly Size _Size;
protected readonly int _StartX;
protected readonly int _StartY;
protected string _TessDataDirectory;
protected List<int> _PreviousTotalDeltaCollection;
protected readonly Dictionary<string, string> _Reactors;
protected readonly List<(string, Color[])> _ColorCollections;
protected readonly List<Tuple<string, Color[]>> _ColorCollections;
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 = 36790;
_NullData = string.Empty;
_LastText = string.Empty;
_Logistics = new Logistics(this);
_Logistics = new(this);
if (_FileParameter is null)
throw new Exception(cellInstanceConnectionName);
if (_ModelObjectParameterDefinitions is null)
@ -42,33 +42,27 @@ public class FileRead : Shared.FileRead, IFileRead
throw new Exception(cellInstanceConnectionName);
_LastChange = DateTime.Now.AddDays(-1).Ticks;
_Reactors = new Dictionary<string, string>();
string reactor = string.Concat("Reactor.", cellInstanceName);
ModelObjectParameterDefinition[] reactors = GetProperties(cellInstanceConnectionName, modelObjectParameters, "Reactor.");
reactors = (from l in reactors where l.Name.EndsWith(".FilePrefix") select l).ToArray();
if (!reactors.Any())
throw new Exception(cellInstanceConnectionName);
foreach (ModelObjectParameterDefinition modelObjectParameterDefinition in reactors)
_Reactors.Add(modelObjectParameterDefinition.Name.Split('.')[1], modelObjectParameterDefinition.Value);
string entryAssemblyLocationDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string x86 = Path.Combine(entryAssemblyLocationDirectory, "x86");
string alias = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, string.Concat("CellInstance.", cellInstanceName, ".Alias"));
_Reactors.Add(alias, alias);
string x86 = Path.Combine(AppContext.BaseDirectory, "x86");
if (!Directory.Exists(x86))
_ = Directory.CreateDirectory(x86);
_TessDataDirectory = Path.Combine(entryAssemblyLocationDirectory, "tessdata");
_TessDataDirectory = Path.Combine(AppContext.BaseDirectory, "tessdata");
if (!Directory.Exists(_TessDataDirectory))
_ = Directory.CreateDirectory(_TessDataDirectory);
string pdfttfSource = Path.Combine(entryAssemblyLocationDirectory, "pdf.ttf");
string pdfttfSource = Path.Combine(AppContext.BaseDirectory, "pdf.ttf");
string pdfttfDestination = Path.Combine(_TessDataDirectory, Path.GetFileName(pdfttfSource));
if (File.Exists(pdfttfSource) && !File.Exists(pdfttfDestination))
File.Copy(pdfttfSource, pdfttfDestination);
string tesseract41dllSource = Path.Combine(entryAssemblyLocationDirectory, "tesseract41.dll");
string tesseract41dllSource = Path.Combine(AppContext.BaseDirectory, "tesseract41.dll");
string tesseract41dllDestination = Path.Combine(x86, Path.GetFileName(tesseract41dllSource));
if (File.Exists(tesseract41dllSource) && !File.Exists(tesseract41dllDestination))
File.Copy(tesseract41dllSource, tesseract41dllDestination);
string engtraineddataSource = Path.Combine(entryAssemblyLocationDirectory, "eng.traineddata");
string engtraineddataSource = Path.Combine(AppContext.BaseDirectory, "eng.traineddata");
string engtraineddataDestination = Path.Combine(_TessDataDirectory, Path.GetFileName(engtraineddataSource));
if (File.Exists(engtraineddataSource) && !File.Exists(engtraineddataDestination))
File.Copy(engtraineddataSource, engtraineddataDestination);
string leptonica1800dllSource = Path.Combine(entryAssemblyLocationDirectory, "leptonica-1.80.0.dll");
string leptonica1800dllSource = Path.Combine(AppContext.BaseDirectory, "leptonica-1.80.0.dll");
string leptonica1800dllDestination = Path.Combine(x86, Path.GetFileName(leptonica1800dllSource));
if (File.Exists(leptonica1800dllSource) && !File.Exists(leptonica1800dllDestination))
File.Copy(leptonica1800dllSource, leptonica1800dllDestination);
@ -81,12 +75,18 @@ public class FileRead : Shared.FileRead, IFileRead
_StartY = int.Parse(startY);
_EndX = int.Parse(endX);
_EndY = int.Parse(endY);
_ColorCollections = new();
_PreviousTotalDeltaCollection = new();
string masterImageDirectory = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "Path.Memory.Master.Images");
_ColorCollections = ProcessData.GetColorCollections(_StartX, _StartY, _EndX, _EndY, masterImageDirectory);
List<(string File, Size Size, Color[] Colors)> colorCollections = ProcessData.GetColorCollections(_StartX, _StartY, _EndX, _EndY, masterImageDirectory);
int[] distinctSizes = (from l in colorCollections select l.Size.Width * l.Size.Height).Distinct().ToArray();
if (distinctSizes.Length != 1)
throw new Exception($"All Master Images must be the same size{Environment.NewLine}{string.Join(Environment.NewLine, distinctSizes)}");
_Size = colorCollections[0].Size;
_ColorCollections.AddRange(from l in colorCollections select new Tuple<string, Color[]>(l.File, l.Colors));
}
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);
@ -151,25 +151,22 @@ 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>());
_Logistics = new Logistics(this, reportFullPath, useSplitForMID: true);
SetFileParameterLotIDToLogisticsMID();
if (reportFullPath.Length < _MinFileLength)
results.Item4.Add(new FileInfo(reportFullPath));
if (_Logistics.FileInfo.Length < _MinFileLength)
results.Item4.Add(_Logistics.FileInfo);
else
{
IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, _StartX, _StartY, _EndX, _EndY, _ColorCollections);
IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, _StartX, _StartY, _EndX, _EndY, _Size, _ColorCollections);
if (iProcessData is not ProcessData processData)
throw new Exception(string.Concat("A) No Data - ", dateTime.Ticks));
string mid = processData.Text;
mid = Regex.Replace(mid, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
_Logistics.MID = mid;
string mid = Regex.Replace(processData.Text, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
SetFileParameterLotID(mid);
_Logistics.ProcessJobID = iProcessData.GetCurrentReactor(this, _Logistics, _Reactors);
string processJobID = iProcessData.GetCurrentReactor(this, _Logistics, _Reactors);
_Logistics.Update(mid, processJobID);
if (!iProcessData.Details.Any())
throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks));
if (processData.Text == _LastText && _LastChange > DateTime.Now.AddMinutes(-30).Ticks)

View File

@ -8,6 +8,7 @@ using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Adaptation.FileHandlers.jpeg;
@ -29,7 +30,7 @@ public class ProcessData : IProcessData
List<object> Shared.Properties.IProcessData.Details => _Details;
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, List<(string, Color[])> colorCollections)
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, Size size, List<Tuple<string, Color[]>> colorCollections)
{
if (logistics is null)
{ }
@ -38,7 +39,7 @@ public class ProcessData : IProcessData
_Details = new List<object>();
MesEntity = logistics.MesEntity;
_Log = LogManager.GetLogger(typeof(ProcessData));
Parse(fileRead, fileInfoCollection, startX, startY, endX, endY, colorCollections);
Parse(fileRead, fileInfoCollection, startX, startY, endX, endY, size, colorCollections);
}
private static string Get(string value, bool useSplitForMID)
@ -104,7 +105,7 @@ public class ProcessData : IProcessData
#nullable enable
#pragma warning disable CA1416
private static Color[] Get(string reportFullPath, int startX, int startY, int endX, int endY)
private static (Size, Color[]) Get(string reportFullPath, int startX, int startY, int endX, int endY)
{
Color color;
List<Color> colors = new();
@ -119,7 +120,7 @@ public class ProcessData : IProcessData
colors.Add(color);
}
}
return colors.ToArray();
return new(bitmap.Size, colors.ToArray());
}
private static System.Drawing.Imaging.ImageFormat Get(string extension)
@ -137,7 +138,7 @@ public class ProcessData : IProcessData
return imageFormat;
}
private static (Color[], int, int) Get(IFileRead fileRead, List<FileInfo> fileInfoCollection, string extension, int startX, int startY, int endX, int endY)
private static (Color[], int, int) Get(IFileRead fileRead, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, string extension, Size size)
{
Color color;
List<Color> colors = new();
@ -148,6 +149,8 @@ public class ProcessData : IProcessData
string saveFileName = Path.ChangeExtension(fileRead.ReportFullPath, extension);
if (bitmap is null)
throw new Exception($"Couldn't load image from <{fileRead.ReportFullPath}>");
if (!size.Equals(bitmap.Size))
throw new Exception("Source size doesn't match master image size <http://10.95.154.28/set_output?input=0&output=0&venc_framerate=60&venc_gop=300&venc_width=640&venc_height=480&venc_bitrate=32000&http_ts_uri=/0.ts&http_flv_uri=/0.flv&rtsp_uri=/0&rtmp_enable=0&rtmp_uri=/0&rtmp_publish_uri=rtmp%3A%2F%2F192.168.1.169%2Flive%2F0&rtmp_publish_enable=0&http_ts_enable=1&http_flv_enable=1&rtsp_enable=1&venc_profile=0&http_hls_uri=/0.m3u8&http_hls_enable=0&venc_width_height_same_as_input=0&multicast_ip=238.0.0.1&multicast_port=1234&multicast_enable=0&venc_codec=265&srt_enable=0&srt_port=9000&srt_publish_enable=0&srt_publish_uri=srt%3A%2F%2F192.168.1.169%3A9000&srt_key=0123456789&srt_key_enable=0&max_qp=42&venc_rc_mode=0&ts_muxrate=0&_=1655307485097>");
for (int x = startX; x < endX; x++)
{
for (int y = startY; y < endY; y++)
@ -209,16 +212,20 @@ public class ProcessData : IProcessData
File.WriteAllLines(textFileName, lines);
}
internal static List<(string, Color[])> GetColorCollections(int startX, int startY, int endX, int endY, string masterImageDirectory)
internal static List<(string, Size, Color[])> GetColorCollections(int startX, int startY, int endX, int endY, string masterImageDirectory)
{
List<(string, Color[])> results = new();
List<(string, Size, Color[])> results = new();
(Size Size, Color[] Colors) result;
string[] files = Directory.GetFiles(masterImageDirectory, "*.jpeg", SearchOption.TopDirectoryOnly);
foreach (string file in files)
results.Add(new(file, Get(file, startX, startY, endX, endY)));
{
result = Get(file, startX, startY, endX, endY);
results.Add(new(file, result.Size, result.Colors));
}
return results;
}
private void Parse(IFileRead fileRead, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, List<(string, Color[])> colorCollections)
private void Parse(IFileRead fileRead, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, Size size, List<Tuple<string, Color[]>> colorCollections)
{
Red = 0;
Green = 0;
@ -228,7 +235,7 @@ public class ProcessData : IProcessData
const int thresHold = 70;
const string extension = ".tiff";
List<(string File, int TotalDelta)> totalDeltaCollection = new();
(Color[] sourceColors, int width, int height) = Get(fileRead, fileInfoCollection, extension, startX, startY, endX, endY);
(Color[] sourceColors, int width, int height) = Get(fileRead, fileInfoCollection, startX, startY, endX, endY, extension, size);
foreach ((string file, Color[] colors) in colorCollections)
{
totalDelta = 0;
@ -274,4 +281,23 @@ public class ProcessData : IProcessData
_Details.Add(Text);
}
#nullable enable
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);
if (description is null)
continue;
results.Add(description);
}
return results;
}
}