Removed IFileRead.Callback
This commit is contained in:
parent
9ceed5b5a4
commit
18033a355a
2
Adaptation/.vscode/launch.json
vendored
2
Adaptation/.vscode/launch.json
vendored
@ -4,7 +4,7 @@
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": 16816
|
||||
"processId": 13700
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -100,8 +100,6 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
void IFileRead.Callback(object state) => throw new Exception(string.Concat("Not ", nameof(_IsDuplicator)));
|
||||
|
||||
private void MoveArchive(DateTime dateTime)
|
||||
{
|
||||
if (dateTime == DateTime.MinValue)
|
||||
|
@ -101,8 +101,6 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
void IFileRead.Callback(object state) => Callback(state);
|
||||
|
||||
private void CallbackInProcessCleared(string sourceArchiveFile, string traceDummyFile, string targetFileLocation, string monARessource, string inProcessDirectory, long sequence, bool warning)
|
||||
{
|
||||
const string site = "sjc";
|
||||
@ -226,7 +224,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
string monARessource;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
if (!_FileConnectorConfiguration.TargetFileLocation.Contains(_FileConnectorConfiguration.SourceFileLocation))
|
||||
throw new Exception("Target must start with source");
|
||||
throw new Exception("Target must start with source!");
|
||||
bool check = dateTime.Hour > 7 && dateTime.Hour < 18 && dateTime.DayOfWeek != DayOfWeek.Sunday && dateTime.DayOfWeek != DayOfWeek.Saturday;
|
||||
if (!_IsEAFHosted || check)
|
||||
{
|
||||
|
@ -109,31 +109,14 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
void IFileRead.Callback(object state) => throw new Exception(string.Concat("Not ", nameof(_IsDuplicator)));
|
||||
|
||||
private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime)
|
||||
{
|
||||
if (dateTime == DateTime.MinValue)
|
||||
{ }
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results = new(string.Empty, null, null, new List<FileInfo>());
|
||||
_Logistics = new Logistics(this, reportFullPath, useSplitForMID: true);
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results = new(string.Empty, null, null, new List<FileInfo>());
|
||||
Tuple<string, string[], string[]> pdsf = ProcessDataStandardFormat.GetLogisticsColumnsAndBody(reportFullPath);
|
||||
_Logistics = new Logistics(reportFullPath, pdsf.Item1);
|
||||
SetFileParameterLotIDToLogisticsMID();
|
||||
|
||||
string[] segments = Path.GetFileNameWithoutExtension(reportFullPath).Split('_');
|
||||
string duplicateDirectory = string.Concat(_FileConnectorConfiguration.TargetFileLocation, @"\", segments[0]);
|
||||
if (segments.Length > 2)
|
||||
duplicateDirectory = string.Concat(duplicateDirectory, @"-", segments[2]);
|
||||
if (!Directory.Exists(duplicateDirectory))
|
||||
_ = Directory.CreateDirectory(duplicateDirectory);
|
||||
|
||||
string logisticsSequence = _Logistics.Sequence.ToString();
|
||||
bool isDummyRun = _DummyRuns.Any() && _DummyRuns.ContainsKey(_Logistics.JobID) && _DummyRuns[_Logistics.JobID].Any() && (from l in _DummyRuns[_Logistics.JobID] where l == _Logistics.Sequence select 1).Any();
|
||||
|
||||
List<Tuple<Shared.Properties.IScopeInfo, string>> tuples = new();
|
||||
|
||||
string destinationDirectory = WriteScopeInfo(_ProgressPath, _Logistics, dateTime, duplicateDirectory, tuples);
|
||||
if (isDummyRun)
|
||||
Shared0607(reportFullPath, duplicateDirectory, logisticsSequence, destinationDirectory);
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,8 @@ namespace Adaptation.FileHandlers.jpeg;
|
||||
public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
|
||||
protected string _LastText;
|
||||
protected long _LastChange;
|
||||
protected readonly Dictionary<string, string> _Reactors;
|
||||
|
||||
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) :
|
||||
@ -20,6 +22,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
_MinFileLength = 10;
|
||||
_NullData = string.Empty;
|
||||
_LastText = string.Empty;
|
||||
_Logistics = new Logistics(this);
|
||||
if (_FileParameter is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
@ -27,6 +30,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (_IsDuplicator)
|
||||
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.");
|
||||
@ -104,8 +108,6 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
|
||||
void IFileRead.CheckTests(Test[] tests, bool extra) => throw new Exception(string.Concat("Not ", nameof(_IsDuplicator)));
|
||||
|
||||
void IFileRead.Callback(object state) => 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>());
|
||||
@ -120,16 +122,20 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
if (!iProcessData.Details.Any())
|
||||
throw new Exception(string.Concat("A) No Data - ", dateTime.Ticks));
|
||||
if (iProcessData.Details[0] is not string detail)
|
||||
if (iProcessData.Details[0] is not string mid || string.IsNullOrEmpty(mid))
|
||||
throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks));
|
||||
string mid = detail;
|
||||
_Logistics.MID = mid;
|
||||
SetFileParameterLotID(mid);
|
||||
_Logistics.ProcessJobID = iProcessData.GetCurrentReactor(this, _Logistics, _Reactors);
|
||||
}
|
||||
if (!iProcessData.Details.Any())
|
||||
throw new Exception(string.Concat("C) No Data - ", dateTime.Ticks));
|
||||
results = iProcessData.GetResults(this, _Logistics, results.Item4);
|
||||
if (_LastText != _Logistics.MID || _LastChange < DateTime.Now.AddMinutes(-30).Ticks)
|
||||
{
|
||||
_LastText = _Logistics.MesEntity;
|
||||
_LastChange = DateTime.Now.Ticks;
|
||||
results = iProcessData.GetResults(this, _Logistics, results.Item4);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class ProcessData : IProcessData
|
||||
_Details = new List<object>();
|
||||
MesEntity = logistics.MesEntity;
|
||||
_Log = LogManager.GetLogger(typeof(ProcessData));
|
||||
Parse(fileRead);
|
||||
Parse(fileRead, fileInfoCollection);
|
||||
}
|
||||
|
||||
private static string Get(string value, bool useSplitForMID)
|
||||
@ -105,9 +105,10 @@ public class ProcessData : IProcessData
|
||||
|
||||
#pragma warning disable CA1416
|
||||
|
||||
private static byte[] GetBytes(IFileRead fileRead, int endY, int endX, int startY, int startX, int outputQuality)
|
||||
private static (byte[], Color[]) Get(IFileRead fileRead, int endY, int endX, int startY, int startX, int outputQuality, string saveFileName)
|
||||
{
|
||||
byte[] results;
|
||||
byte[] bytes;
|
||||
List<Color> colors = new();
|
||||
Point startPoint = new(startX, startY);
|
||||
using MemoryStream memoryStream = new();
|
||||
EncoderParameters encoderParameters = new(1);
|
||||
@ -117,27 +118,53 @@ public class ProcessData : IProcessData
|
||||
Rectangle rectangle = new(startPoint, new Size(endX - startX, endY - startY));
|
||||
using Bitmap bitmap = Image.FromFile(fileRead.ReportFullPath) as Bitmap;
|
||||
using Bitmap clonedBitmap = bitmap.Clone(rectangle, bitmap.PixelFormat);
|
||||
//clonedBitmap.Save(Path.ChangeExtension(fileRead.ReportFullPath, ".png"), System.Drawing.Imaging.ImageFormat.Png);
|
||||
if (!string.IsNullOrEmpty(saveFileName))
|
||||
{
|
||||
if (!saveFileName.EndsWith(".png"))
|
||||
throw new NotImplementedException("Configured to save as *.png");
|
||||
clonedBitmap.Save(saveFileName, System.Drawing.Imaging.ImageFormat.Png);
|
||||
for (int i = 0; i < rectangle.Width; i++)
|
||||
colors.Add(clonedBitmap.GetPixel(i, (int)(rectangle.Height * .5)));
|
||||
}
|
||||
clonedBitmap.Save(memoryStream, imageCodecInfo, encoderParameters);
|
||||
results = memoryStream.GetBuffer();
|
||||
return results;
|
||||
bytes = memoryStream.GetBuffer();
|
||||
return new(bytes, colors.ToArray());
|
||||
}
|
||||
|
||||
#pragma warning restore CA1416
|
||||
|
||||
private static byte[] GetBytes(IFileRead fileRead) => GetBytes(fileRead, 68, 1687, 32, 1094, 95);
|
||||
private static (byte[], Color[]) Get(IFileRead fileRead, string saveFileName) => Get(fileRead, 68, 1559, 32, 1094, 95, saveFileName);
|
||||
|
||||
private void Parse(IFileRead fileRead)
|
||||
private void Parse(IFileRead fileRead, List<FileInfo> fileInfoCollection)
|
||||
{
|
||||
string text;
|
||||
using TesseractEngine engine = new(string.Empty, "eng", EngineMode.Default);
|
||||
//using Pix img = Pix.LoadFromFile(fileRead.ReportFullPath);
|
||||
byte[] bytes = GetBytes(fileRead);
|
||||
(byte[] bytes, Color[] colors) = Get(fileRead, saveFileName: string.Empty);
|
||||
using Pix img = Pix.LoadFromMemory(bytes);
|
||||
using Page page = engine.Process(img);
|
||||
text = page.GetText();
|
||||
if (string.IsNullOrEmpty(text))
|
||||
throw new Exception("OCR Failure!");
|
||||
string text = page.GetText().Trim();
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
_Log.Debug(text);
|
||||
else
|
||||
{
|
||||
int red = 0;
|
||||
int green = 0;
|
||||
_Log.Debug("Looking by color");
|
||||
string saveFileName = Path.ChangeExtension(fileRead.ReportFullPath, ".png");
|
||||
(bytes, colors) = Get(fileRead, saveFileName);
|
||||
foreach (Color color in colors)
|
||||
{
|
||||
if (color.R > 127)
|
||||
red += 1;
|
||||
if (color.G > 127)
|
||||
green += 1;
|
||||
}
|
||||
if (red > green)
|
||||
text = "Red*";
|
||||
else
|
||||
text = "Green*";
|
||||
fileInfoCollection.Add(new FileInfo(saveFileName));
|
||||
}
|
||||
_Details.Add(text);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@ public interface IFileRead : Properties.IFileRead
|
||||
|
||||
void WaitForThread();
|
||||
JsonProperty[] GetDefault();
|
||||
void Callback(object state);
|
||||
string GetEventDescription();
|
||||
List<string> GetHeaderNames();
|
||||
void CheckTests(Test[] tests, bool extra);
|
||||
|
Loading…
x
Reference in New Issue
Block a user