Ready to test
This commit is contained in:
141
Adaptation/FileHandlers/Archive/FileRead.cs
Normal file
141
Adaptation/FileHandlers/Archive/FileRead.cs
Normal file
@ -0,0 +1,141 @@
|
||||
using Adaptation.Eaf.Management.ConfigurationData.CellAutomation;
|
||||
using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration;
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Duplicator;
|
||||
using Adaptation.Shared.Methods;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Adaptation.FileHandlers.Archive;
|
||||
|
||||
public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
|
||||
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(), false, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted)
|
||||
{
|
||||
_MinFileLength = 10;
|
||||
_NullData = string.Empty;
|
||||
_Logistics = new Logistics(this);
|
||||
if (_FileParameter is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (_ModelObjectParameterDefinitions is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (!_IsDuplicator)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
}
|
||||
|
||||
void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) => Move(extractResults, exception);
|
||||
|
||||
void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null);
|
||||
|
||||
string IFileRead.GetEventDescription()
|
||||
{
|
||||
string result = _Description.GetEventDescription();
|
||||
return result;
|
||||
}
|
||||
|
||||
List<string> IFileRead.GetHeaderNames()
|
||||
{
|
||||
List<string> results = _Description.GetHeaderNames();
|
||||
return results;
|
||||
}
|
||||
|
||||
string[] IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, string to, string from, string resolvedFileLocation, Exception exception)
|
||||
{
|
||||
string[] results = Move(extractResults, to, from, resolvedFileLocation, exception);
|
||||
return results;
|
||||
}
|
||||
|
||||
JsonProperty[] IFileRead.GetDefault()
|
||||
{
|
||||
JsonProperty[] results = _Description.GetDefault(this, _Logistics);
|
||||
return results;
|
||||
}
|
||||
|
||||
Dictionary<string, string> IFileRead.GetDisplayNamesJsonElement()
|
||||
{
|
||||
Dictionary<string, string> results = _Description.GetDisplayNamesJsonElement(this);
|
||||
return results;
|
||||
}
|
||||
|
||||
List<IDescription> IFileRead.GetDescriptions(IFileRead fileRead, List<Test> tests, IProcessData processData)
|
||||
{
|
||||
List<IDescription> results = _Description.GetDescriptions(fileRead, _Logistics, tests, processData);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.GetExtractResult(string reportFullPath, string eventName)
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
if (string.IsNullOrEmpty(eventName))
|
||||
throw new Exception();
|
||||
_ReportFullPath = reportFullPath;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
results = GetExtractResult(reportFullPath, dateTime);
|
||||
if (results.Item3 is null)
|
||||
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(results.Item1, Array.Empty<Test>(), JsonSerializer.Deserialize<JsonElement[]>("[]"), results.Item4);
|
||||
if (results.Item3.Length > 0 && _IsEAFHosted)
|
||||
WritePDSF(this, results.Item3);
|
||||
UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.ReExtract()
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
List<string> headerNames = _Description.GetHeaderNames();
|
||||
Dictionary<string, string> keyValuePairs = _Description.GetDisplayNamesJsonElement(this);
|
||||
results = ReExtract(this, headerNames, keyValuePairs);
|
||||
return results;
|
||||
}
|
||||
|
||||
void IFileRead.CheckTests(Test[] tests, bool extra)
|
||||
{
|
||||
if (_Description is not Description)
|
||||
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)
|
||||
{ }
|
||||
string logisticsSequence = _Logistics.Sequence.ToString();
|
||||
string weekOfYear = _Calendar.GetWeekOfYear(_Logistics.DateTimeFromSequence, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
string weekDirectory = string.Concat(_Logistics.DateTimeFromSequence.ToString("yyyy"), "_Week_", weekOfYear, @"\", _Logistics.DateTimeFromSequence.ToString("yyyy-MM-dd"));
|
||||
string jobIdDirectory = string.Concat(_FileConnectorConfiguration.TargetFileLocation, @"\", _Logistics.JobID);
|
||||
if (!Directory.Exists(jobIdDirectory))
|
||||
_ = Directory.CreateDirectory(jobIdDirectory);
|
||||
//string destinationArchiveDirectory = string.Concat(jobIdDirectory, @"\!Archive\", weekDirectory);
|
||||
string destinationArchiveDirectory = string.Concat(Path.GetDirectoryName(_FileConnectorConfiguration.TargetFileLocation), @"\Archive\", _Logistics.JobID, @"\", weekDirectory);
|
||||
if (!Directory.Exists(destinationArchiveDirectory))
|
||||
_ = Directory.CreateDirectory(destinationArchiveDirectory);
|
||||
string[] matchDirectories = new string[] { GetDirectoriesRecursively(jobIdDirectory, logisticsSequence).FirstOrDefault() };
|
||||
if ((matchDirectories is null) || matchDirectories.Length != 1)
|
||||
throw new Exception("Didn't find directory by logistics sequence");
|
||||
string sourceDirectory = Path.GetDirectoryName(matchDirectories[0]);
|
||||
destinationArchiveDirectory = string.Concat(destinationArchiveDirectory, @"\", Path.GetFileName(sourceDirectory));
|
||||
Directory.Move(sourceDirectory, destinationArchiveDirectory);
|
||||
}
|
||||
|
||||
private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime)
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
Tuple<string, string[], string[]> pdsf = ProcessDataStandardFormat.GetLogisticsColumnsAndBody(reportFullPath);
|
||||
_Logistics = new Logistics(reportFullPath, pdsf.Item1);
|
||||
SetFileParameterLotIDToLogisticsMID();
|
||||
JsonElement[] jsonElements = ProcessDataStandardFormat.GetArray(pdsf);
|
||||
List<Shared.Properties.IDescription> descriptions = GetDuplicatorDescriptions(jsonElements);
|
||||
Tuple<Test[], Dictionary<Test, List<Shared.Properties.IDescription>>> tuple = GetTuple(this, descriptions, extra: false);
|
||||
MoveArchive(dateTime);
|
||||
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(pdsf.Item1, tuple.Item1, jsonElements, new List<FileInfo>());
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
39
Adaptation/FileHandlers/CellInstanceConnectionName.cs
Normal file
39
Adaptation/FileHandlers/CellInstanceConnectionName.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using Adaptation.Eaf.Management.ConfigurationData.CellAutomation;
|
||||
using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration;
|
||||
using Adaptation.Shared.Methods;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Adaptation.FileHandlers;
|
||||
|
||||
public class CellInstanceConnectionName
|
||||
{
|
||||
|
||||
internal static IFileRead Get(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)
|
||||
{
|
||||
IFileRead result;
|
||||
bool isDuplicator = cellInstanceConnectionName.StartsWith(cellInstanceName);
|
||||
if (isDuplicator)
|
||||
{
|
||||
string cellInstanceConnectionNameBase = cellInstanceConnectionName.Replace("-", string.Empty);
|
||||
int hyphens = cellInstanceConnectionName.Length - cellInstanceConnectionNameBase.Length;
|
||||
result = hyphens switch
|
||||
{
|
||||
(int)MET08DDUPSFS6420.Hyphen.IsArchive => new Archive.FileRead(smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted),
|
||||
(int)MET08DDUPSFS6420.Hyphen.IsDummy => new Dummy.FileRead(smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted),
|
||||
(int)MET08DDUPSFS6420.Hyphen.IsXToArchive => new ToArchive.FileRead(smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted),
|
||||
_ => new MET08DDUPSFS6420.FileRead(smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted)
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
result = cellInstanceConnectionName switch
|
||||
{
|
||||
nameof(pcl) => new pcl.FileRead(smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted),
|
||||
_ => throw new Exception(),
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
308
Adaptation/FileHandlers/Dummy/FileRead.cs
Normal file
308
Adaptation/FileHandlers/Dummy/FileRead.cs
Normal file
@ -0,0 +1,308 @@
|
||||
using Adaptation.Eaf.Management.ConfigurationData.CellAutomation;
|
||||
using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration;
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Duplicator;
|
||||
using Adaptation.Shared.Methods;
|
||||
using Infineon.Monitoring.MonA;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
|
||||
namespace Adaptation.FileHandlers.Dummy;
|
||||
|
||||
public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
|
||||
private readonly Timer _Timer;
|
||||
private int _LastDummyRunIndex;
|
||||
private readonly string[] _CellNames;
|
||||
|
||||
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(), false, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted)
|
||||
{
|
||||
_MinFileLength = 10;
|
||||
_NullData = string.Empty;
|
||||
_Logistics = new Logistics(this);
|
||||
if (_FileParameter is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (_ModelObjectParameterDefinitions is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (!_IsDuplicator)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
_LastDummyRunIndex = -1;
|
||||
List<string> cellNames = new();
|
||||
_Timer = new Timer(Callback, null, Timeout.Infinite, Timeout.Infinite);
|
||||
ModelObjectParameterDefinition[] cellInstanceCollection = GetProperties(cellInstanceConnectionName, modelObjectParameters, "CellInstance.", ".Alias");
|
||||
foreach (ModelObjectParameterDefinition modelObjectParameterDefinition in cellInstanceCollection)
|
||||
cellNames.Add(modelObjectParameterDefinition.Name.Split('.')[1]);
|
||||
_CellNames = cellNames.ToArray();
|
||||
if (Debugger.IsAttached || fileConnectorConfiguration.PreProcessingMode == FileConnectorConfiguration.PreProcessingModeEnum.Process)
|
||||
Callback(null);
|
||||
else
|
||||
{
|
||||
TimeSpan timeSpan = new(DateTime.Now.AddSeconds(_FileConnectorConfiguration.FileScanningIntervalInSeconds.Value).Ticks - DateTime.Now.Ticks);
|
||||
_ = _Timer.Change((long)timeSpan.TotalMilliseconds, Timeout.Infinite);
|
||||
}
|
||||
}
|
||||
|
||||
void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) => Move(extractResults, exception);
|
||||
|
||||
void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null);
|
||||
|
||||
string IFileRead.GetEventDescription()
|
||||
{
|
||||
string result = _Description.GetEventDescription();
|
||||
return result;
|
||||
}
|
||||
|
||||
List<string> IFileRead.GetHeaderNames()
|
||||
{
|
||||
List<string> results = _Description.GetHeaderNames();
|
||||
return results;
|
||||
}
|
||||
|
||||
string[] IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, string to, string from, string resolvedFileLocation, Exception exception)
|
||||
{
|
||||
string[] results = Move(extractResults, to, from, resolvedFileLocation, exception);
|
||||
return results;
|
||||
}
|
||||
|
||||
JsonProperty[] IFileRead.GetDefault()
|
||||
{
|
||||
JsonProperty[] results = _Description.GetDefault(this, _Logistics);
|
||||
return results;
|
||||
}
|
||||
|
||||
Dictionary<string, string> IFileRead.GetDisplayNamesJsonElement()
|
||||
{
|
||||
Dictionary<string, string> results = _Description.GetDisplayNamesJsonElement(this);
|
||||
return results;
|
||||
}
|
||||
|
||||
List<IDescription> IFileRead.GetDescriptions(IFileRead fileRead, List<Test> tests, IProcessData processData)
|
||||
{
|
||||
List<IDescription> results = _Description.GetDescriptions(fileRead, _Logistics, tests, processData);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.GetExtractResult(string reportFullPath, string eventName) => throw new Exception(string.Concat("See ", nameof(CallbackFileExists)));
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.ReExtract() => throw new Exception(string.Concat("See ", nameof(CallbackFileExists)));
|
||||
|
||||
void IFileRead.CheckTests(Test[] tests, bool extra)
|
||||
{
|
||||
if (_Description is not Description)
|
||||
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";
|
||||
string stateName = string.Concat("Dummy_", _EventName);
|
||||
const string monInURL = "http://moninhttp.sjc.infineon.com/input/text";
|
||||
MonIn monIn = MonIn.GetInstance(monInURL);
|
||||
try
|
||||
{
|
||||
if (warning)
|
||||
{
|
||||
File.AppendAllLines(traceDummyFile, new string[] { site, monARessource, stateName, State.Warning.ToString() });
|
||||
_ = monIn.SendStatus(site, monARessource, stateName, State.Warning);
|
||||
for (int i = 1; i < 12; i++)
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
ZipFile.ExtractToDirectory(sourceArchiveFile, inProcessDirectory);
|
||||
string[] files = Directory.GetFiles(inProcessDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (files.Length > 250)
|
||||
throw new Exception("Safety net!");
|
||||
foreach (string file in files)
|
||||
File.SetLastWriteTime(file, new DateTime(sequence));
|
||||
if (!_FileConnectorConfiguration.IncludeSubDirectories.Value)
|
||||
{
|
||||
foreach (string file in files)
|
||||
File.Move(file, Path.Combine(targetFileLocation, Path.GetFileName(file)));
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] directories = Directory.GetDirectories(inProcessDirectory, "*", SearchOption.AllDirectories);
|
||||
foreach (string directory in directories)
|
||||
_ = Directory.CreateDirectory(string.Concat(targetFileLocation, directory.Substring(inProcessDirectory.Length)));
|
||||
foreach (string file in files)
|
||||
File.Move(file, string.Concat(targetFileLocation, file.Substring(inProcessDirectory.Length)));
|
||||
}
|
||||
File.AppendAllLines(traceDummyFile, new string[] { site, monARessource, stateName, State.Ok.ToString() });
|
||||
_ = monIn.SendStatus(site, monARessource, stateName, State.Ok);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
string subject = string.Concat("Exception:", _CellInstanceConnectionName);
|
||||
string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace);
|
||||
try
|
||||
{ _SMTP.SendHighPriorityEmailMessage(subject, body); }
|
||||
catch (Exception) { }
|
||||
File.AppendAllLines(traceDummyFile, new string[] { site, monARessource, stateName, State.Critical.ToString(), exception.Message, exception.StackTrace });
|
||||
_ = monIn.SendStatus(site, monARessource, stateName, State.Critical);
|
||||
}
|
||||
}
|
||||
|
||||
private void CallbackFileExists(string sourceArchiveFile, string traceDummyFile, string targetFileLocation, string monARessource, long sequence)
|
||||
{
|
||||
string[] files;
|
||||
bool warning = false;
|
||||
if (!_DummyRuns.ContainsKey(monARessource))
|
||||
_DummyRuns.Add(monARessource, new List<long>());
|
||||
if (!_DummyRuns[monARessource].Contains(sequence))
|
||||
_DummyRuns[monARessource].Add(sequence);
|
||||
File.AppendAllLines(traceDummyFile, new string[] { sourceArchiveFile });
|
||||
string inProcessDirectory = Path.Combine(_ProgressPath, "Dummy In-Process", sequence.ToString());
|
||||
if (!Directory.Exists(inProcessDirectory))
|
||||
_ = Directory.CreateDirectory(inProcessDirectory);
|
||||
files = Directory.GetFiles(inProcessDirectory, "*", SearchOption.AllDirectories);
|
||||
if (files.Any())
|
||||
{
|
||||
if (files.Length > 250)
|
||||
throw new Exception("Safety net!");
|
||||
try
|
||||
{
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
if (_FileConnectorConfiguration.IncludeSubDirectories.Value)
|
||||
files = Directory.GetFiles(targetFileLocation, "*", SearchOption.AllDirectories);
|
||||
else
|
||||
files = Directory.GetFiles(targetFileLocation, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (new FileInfo(file).LastWriteTime.Ticks == sequence)
|
||||
{
|
||||
warning = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
CallbackInProcessCleared(sourceArchiveFile, traceDummyFile, targetFileLocation, monARessource, inProcessDirectory, sequence, warning);
|
||||
}
|
||||
|
||||
private string GetCellName(string pathSegment)
|
||||
{
|
||||
string result = string.Empty;
|
||||
foreach (string cellName in _CellNames)
|
||||
{
|
||||
if (pathSegment.ToLower().Contains(cellName.ToLower()))
|
||||
{
|
||||
result = cellName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
int count;
|
||||
List<(string CellName, int Count)> cellNames = new();
|
||||
foreach (string cellName in _CellNames)
|
||||
{
|
||||
count = 0;
|
||||
foreach (char @char in cellName.ToLower())
|
||||
count += pathSegment.Length - pathSegment.ToLower().Replace(@char.ToString(), string.Empty).Length;
|
||||
cellNames.Add(new(cellName, count));
|
||||
}
|
||||
result = (from l in cellNames orderby l.CellName.Length, l.Count descending select l.CellName).First();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Callback(object state)
|
||||
{
|
||||
try
|
||||
{
|
||||
string pathSegment;
|
||||
string monARessource;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
if (!_FileConnectorConfiguration.TargetFileLocation.Contains(_FileConnectorConfiguration.SourceFileLocation))
|
||||
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)
|
||||
{
|
||||
string checkSegment;
|
||||
string checkDirectory;
|
||||
string sourceFileFilter;
|
||||
string sourceArchiveFile;
|
||||
string sourceFileLocation;
|
||||
string weekOfYear = _Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
string traceDummyDirectory = Path.Combine(Path.GetPathRoot(_TracePath), "TracesDummy", _CellInstanceName, "Source", $"{dateTime:yyyy}___Week_{weekOfYear}");
|
||||
if (!Directory.Exists(traceDummyDirectory))
|
||||
_ = Directory.CreateDirectory(traceDummyDirectory);
|
||||
string traceDummyFile = Path.Combine(traceDummyDirectory, $"{dateTime.Ticks} - {_CellInstanceName}.txt");
|
||||
File.AppendAllText(traceDummyFile, string.Empty);
|
||||
if (_FileConnectorConfiguration.SourceFileLocation.EndsWith("\\"))
|
||||
sourceFileLocation = _FileConnectorConfiguration.SourceFileLocation;
|
||||
else
|
||||
sourceFileLocation = string.Concat(_FileConnectorConfiguration.SourceFileLocation, '\\');
|
||||
for (int i = 0; i < _FileConnectorConfiguration.SourceFileFilters.Count; i++)
|
||||
{
|
||||
_LastDummyRunIndex += 1;
|
||||
if (_LastDummyRunIndex >= _FileConnectorConfiguration.SourceFileFilters.Count)
|
||||
_LastDummyRunIndex = 0;
|
||||
sourceFileFilter = _FileConnectorConfiguration.SourceFileFilters[_LastDummyRunIndex];
|
||||
sourceArchiveFile = Path.GetFullPath(string.Concat(sourceFileLocation, sourceFileFilter));
|
||||
if (File.Exists(sourceArchiveFile))
|
||||
{
|
||||
checkSegment = _FileConnectorConfiguration.TargetFileLocation.Substring(sourceFileLocation.Length);
|
||||
checkDirectory = Path.GetDirectoryName(sourceArchiveFile);
|
||||
for (int z = 0; z < int.MaxValue; z++)
|
||||
{
|
||||
if (checkDirectory.Length < sourceFileLocation.Length || !checkDirectory.StartsWith(sourceFileLocation))
|
||||
break;
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (Directory.Exists(Path.Combine(checkDirectory, checkSegment)))
|
||||
{
|
||||
checkDirectory = Path.Combine(checkDirectory, checkSegment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!checkDirectory.EndsWith(checkSegment))
|
||||
throw new Exception("Could not determine dummy target directory for extract!");
|
||||
if (!long.TryParse(Path.GetFileNameWithoutExtension(sourceArchiveFile).Replace("x", string.Empty), out long sequence))
|
||||
throw new Exception("Invalid file name for source archive file!");
|
||||
pathSegment = checkDirectory.Substring(sourceFileLocation.Length);
|
||||
monARessource = GetCellName(pathSegment);
|
||||
if (string.IsNullOrEmpty(monARessource))
|
||||
throw new Exception("Could not determine which cell archive file is associated with!");
|
||||
if (_IsEAFHosted)
|
||||
CallbackFileExists(sourceArchiveFile, traceDummyFile, checkDirectory, monARessource, sequence);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
string subject = string.Concat("Exception:", _CellInstanceConnectionName);
|
||||
string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace);
|
||||
try
|
||||
{ _SMTP.SendHighPriorityEmailMessage(subject, body); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
try
|
||||
{
|
||||
TimeSpan timeSpan = new(DateTime.Now.AddSeconds(_FileConnectorConfiguration.FileScanningIntervalInSeconds.Value).Ticks - DateTime.Now.Ticks);
|
||||
_ = _Timer.Change((long)timeSpan.TotalMilliseconds, Timeout.Infinite);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
string subject = string.Concat("Exception:", _CellInstanceConnectionName);
|
||||
string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace);
|
||||
try
|
||||
{ _SMTP.SendHighPriorityEmailMessage(subject, body); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,300 +0,0 @@
|
||||
using Adaptation.Helpers;
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Metrology;
|
||||
using log4net;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Adaptation.FileHandlers
|
||||
{
|
||||
|
||||
public partial class FileRead : ILogic
|
||||
{
|
||||
|
||||
private ConfigData _ConfigData;
|
||||
|
||||
public FileRead()
|
||||
{
|
||||
Logistics = new Logistics();
|
||||
_Log = LogManager.GetLogger(typeof(FileRead));
|
||||
}
|
||||
|
||||
public ILogic ShallowCopy()
|
||||
{
|
||||
return (ILogic)MemberwiseClone();
|
||||
}
|
||||
|
||||
public void WaitForThread()
|
||||
{
|
||||
WaitForThread(thread: null, threadExceptions: null);
|
||||
}
|
||||
|
||||
public Tuple<string, ConfigDataBase> GetOpenInsightTuple()
|
||||
{
|
||||
Tuple<string, ConfigDataBase> restuls = new Tuple<string, ConfigDataBase>(_ConfigData.OpenInsightSiViewer, _ConfigData);
|
||||
return restuls;
|
||||
}
|
||||
|
||||
public Tuple<string, JsonElement?, List<FileInfo>> GetExtractResult(string reportFullPath, string eventName)
|
||||
{
|
||||
Tuple<string, JsonElement?, List<FileInfo>> results;
|
||||
_FileParameter.Clear();
|
||||
DateTime dateTime = DateTime.Now;
|
||||
if (_ConfigData.IsEvent && _ConfigData.Duplicator is null)
|
||||
results = GetExtractResult(reportFullPath);
|
||||
else if (_ConfigData.Duplicator.HasValue && _ConfigData.Duplicator.Value != ConfigData.Level.IsManualOIEntry)
|
||||
results = GetDuplicatorExtractResult(reportFullPath, dateTime);
|
||||
else if (_ConfigData.Duplicator.HasValue && _ConfigData.Duplicator.Value == ConfigData.Level.IsManualOIEntry)
|
||||
results = _ConfigData.IsManualOIEntry(reportFullPath);
|
||||
else
|
||||
throw new Exception();
|
||||
if (results.Item2 is null)
|
||||
results = new Tuple<string, JsonElement?, List<FileInfo>>(results.Item1, JsonSerializer.Deserialize<JsonElement>("[]"), results.Item3);
|
||||
int count = results.Item2.Value.GetArrayLength();
|
||||
if (count > 0 && _ConfigData.EafHosted)
|
||||
WritePDSF(results.Item2.Value);
|
||||
UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks);
|
||||
return results;
|
||||
}
|
||||
|
||||
private Tuple<string, JsonElement?, List<FileInfo>> GetExtractResult(string reportFullPath)
|
||||
{
|
||||
Tuple<string, JsonElement?, List<FileInfo>> results = new Tuple<string, JsonElement?, List<FileInfo>>(string.Empty, null, new List<FileInfo>());
|
||||
FileInfo fileInfo = new FileInfo(reportFullPath);
|
||||
Logistics = new Logistics(ConfigData.NullData, _ConfigData.CellNames, _ConfigData.MesEntities, fileInfo, useSplitForMID: false, fileInfoLength: 50000);
|
||||
SetFileParameterLotID(Logistics.MID);
|
||||
if (new FileInfo(reportFullPath).Length < ConfigData.MinFileLength)
|
||||
results.Item3.Add(fileInfo);
|
||||
else
|
||||
{
|
||||
ProcessData processData = new ProcessData(this, _ConfigData, results.Item3);
|
||||
if (!(processData.Header is null))
|
||||
{
|
||||
string mid = string.Concat(processData.Header.Reactor, "-", processData.Header.RDS, "-", processData.Header.PSN);
|
||||
mid = Regex.Replace(mid, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
|
||||
Logistics.MID = mid;
|
||||
SetFileParameterLotID(mid);
|
||||
Logistics.ProcessJobID = processData.Header.Reactor;
|
||||
}
|
||||
if (processData.Header is null || !processData.Details.Any())
|
||||
throw new Exception();
|
||||
results = processData.GetResults(this, _ConfigData, results.Item3);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private Tuple<string, JsonElement?, List<FileInfo>> GetDuplicatorExtractResult(string reportFullPath, DateTime dateTime)
|
||||
{
|
||||
Tuple<string, JsonElement?, List<FileInfo>> results;
|
||||
Tuple<string, string[], string[]> pdsf = ProcessDataStandardFormat.GetLogisticsColumnsAndBody(reportFullPath);
|
||||
Logistics = new Logistics(reportFullPath, pdsf.Item1);
|
||||
SetFileParameterLotIDToLogisticsMID();
|
||||
JsonElement pdsdBodyValues = ProcessDataStandardFormat.GetArray(pdsf);
|
||||
results = new Tuple<string, JsonElement?, List<FileInfo>>(pdsf.Item1, pdsdBodyValues, new List<FileInfo>());
|
||||
List<Duplicator.Description> processDataDescriptions = _ConfigData.GetProcessDataDescriptions(pdsdBodyValues);
|
||||
Dictionary<Test, List<Duplicator.Description>> keyValuePairs = ProcessData.GetKeyValuePairs(_ConfigData, pdsdBodyValues, processDataDescriptions, extra: false);
|
||||
bool isNotUsedInsightMetrologyViewerAttachments = (!(_Configuration.FileScanningIntervalInSeconds > 0) && _ConfigData.Duplicator.Value == ConfigData.Level.IsXToOpenInsightMetrologyViewerAttachments);
|
||||
bool isDummyRun = (ConfigData.DummyRuns.Any() && ConfigData.DummyRuns.ContainsKey(Logistics.JobID) && ConfigData.DummyRuns[Logistics.JobID].Any() && (from l in ConfigData.DummyRuns[Logistics.JobID] where l == Logistics.Sequence select 1).Any());
|
||||
if (isDummyRun)
|
||||
{
|
||||
try
|
||||
{ File.SetLastWriteTime(reportFullPath, dateTime); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
string duplicateDirectory;
|
||||
string[] segments = Path.GetFileNameWithoutExtension(reportFullPath).Split('_');
|
||||
if (_ConfigData.Duplicator.Value == ConfigData.Level.IsXToIQSSi)
|
||||
duplicateDirectory = string.Concat(_Configuration.TargetFileLocation, @"\ALL");
|
||||
else if (_ConfigData.Duplicator.Value != ConfigData.Level.IsXToOpenInsight)
|
||||
duplicateDirectory = string.Concat(_Configuration.TargetFileLocation, @"\", segments[0]);
|
||||
else
|
||||
duplicateDirectory = string.Concat(Path.GetDirectoryName(Path.GetDirectoryName(_Configuration.TargetFileLocation)), @"\Data");
|
||||
if (segments.Length > 2)
|
||||
duplicateDirectory = string.Concat(duplicateDirectory, @"-", segments[2]);
|
||||
if (!Directory.Exists(duplicateDirectory))
|
||||
Directory.CreateDirectory(duplicateDirectory);
|
||||
if ((isDummyRun || isNotUsedInsightMetrologyViewerAttachments || _Configuration.FileScanningIntervalInSeconds > 0) && _ConfigData.Duplicator.Value != ConfigData.Level.IsXToArchive && _ConfigData.Duplicator.Value != ConfigData.Level.IsArchive)
|
||||
{
|
||||
bool ganPPTST = false;
|
||||
string successDirectory;
|
||||
if (_ConfigData.Duplicator.Value != ConfigData.Level.IsXToAPC)
|
||||
successDirectory = string.Empty;
|
||||
else
|
||||
{
|
||||
successDirectory = string.Concat(Path.GetDirectoryName(_Configuration.TargetFileLocation), @"\ViewerPath");
|
||||
if (!Directory.Exists(successDirectory))
|
||||
Directory.CreateDirectory(successDirectory);
|
||||
}
|
||||
CultureInfo cultureInfo = new CultureInfo("en-US");
|
||||
Calendar calendar = cultureInfo.Calendar;
|
||||
List<Tuple<IScopeInfo, string>> tuples = new List<Tuple<IScopeInfo, string>>();
|
||||
string duplicateFile = string.Concat(duplicateDirectory, @"\", Path.GetFileName(reportFullPath));
|
||||
string weekOfYear = calendar.GetWeekOfYear(Logistics.DateTimeFromSequence, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
string weekDirectory = string.Concat(Logistics.DateTimeFromSequence.ToString("yyyy"), "_Week_", weekOfYear, @"\", Logistics.DateTimeFromSequence.ToString("yyyy-MM-dd"));
|
||||
string logisticsSequenceMemoryDirectory = string.Concat(_ConfigData.MemoryPath, @"\", _ConfigData.GetEquipmentType(), @"\Source\", weekDirectory, @"\", Logistics.Sequence);
|
||||
if (!Directory.Exists(logisticsSequenceMemoryDirectory))
|
||||
Directory.CreateDirectory(logisticsSequenceMemoryDirectory);
|
||||
if (_ConfigData.Duplicator.Value == ConfigData.Level.IsXToAPC)
|
||||
{
|
||||
if (!isDummyRun && _ConfigData.EafHosted)
|
||||
File.Copy(reportFullPath, duplicateFile, overwrite: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_ConfigData.Duplicator.Value == ConfigData.Level.IsXToOpenInsightMetrologyViewer)
|
||||
{
|
||||
List<ProcessData.FileRead.Description> fileReadDescriptions = ProcessData.GetProcessDataFileReadDescriptions(_ConfigData, pdsdBodyValues);
|
||||
ProcessData.WSRequest wsRequest = new ProcessData.WSRequest(this, fileReadDescriptions);
|
||||
if (!isDummyRun && _ConfigData.EafHosted)
|
||||
{
|
||||
Tuple<string, WS.Results> wsResults = WS.SendData(_ConfigData.OpenInsightMetrogyViewerAPI, wsRequest);
|
||||
if (!wsResults.Item2.Success)
|
||||
throw new Exception(wsResults.ToString());
|
||||
_Log.Debug(wsResults.Item2.HeaderID);
|
||||
File.WriteAllText(string.Concat(logisticsSequenceMemoryDirectory, @"\", nameof(WS.Results), ".json"), wsResults.Item1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Test test;
|
||||
string lines;
|
||||
IScopeInfo scopeInfo;
|
||||
foreach (KeyValuePair<Test, List<Duplicator.Description>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
test = keyValuePair.Key;
|
||||
//scopeInfo = new ScopeInfo(this, _ConfigData, test);
|
||||
if (_ConfigData.Duplicator.Value != ConfigData.Level.IsXToOpenInsight)
|
||||
scopeInfo = new ScopeInfo(this, _ConfigData, test, _ConfigData.IqsFile, _ConfigData.IqsQueryFilter);
|
||||
else
|
||||
scopeInfo = new ScopeInfo(this, _ConfigData, test, _ConfigData.OpenInsightFilePattern, _ConfigData.IqsQueryFilter);
|
||||
//lines = ProcessDataStandardFormat.GetLines(Logistics, scopeInfo, names, values, dateFormat: "M/d/yyyy hh:mm:ss tt", timeFormat: string.Empty, pairedColumns: ExtractResultPairedColumns);
|
||||
List<ProcessData.FileRead.Description> fileReadDescriptions = ProcessData.GetProcessDataFileReadDescriptions(_ConfigData, pdsdBodyValues);
|
||||
ganPPTST = fileReadDescriptions[0].Recipe.Contains("GAN_PPTST");
|
||||
lines = ProcessData.GetLines(this, fileReadDescriptions, ganPPTST);
|
||||
tuples.Add(new Tuple<IScopeInfo, string>(scopeInfo, lines));
|
||||
}
|
||||
}
|
||||
if (_ConfigData.Duplicator.Value == ConfigData.Level.IsXToOpenInsightMetrologyViewerAttachments)
|
||||
{
|
||||
string[] matchDirectories = Shared1567(reportFullPath, tuples);
|
||||
if (!isDummyRun && _ConfigData.EafHosted && !isNotUsedInsightMetrologyViewerAttachments)
|
||||
{
|
||||
List<ProcessData.FileRead.Description> fileReadDescriptions = ProcessData.GetProcessDataFileReadDescriptions(_ConfigData, pdsdBodyValues);
|
||||
ProcessData.PostOpenInsightMetrologyViewerAttachments(_Log, _ConfigData, Logistics, dateTime, logisticsSequenceMemoryDirectory, fileReadDescriptions, matchDirectories[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_ConfigData.Duplicator.Value != ConfigData.Level.IsXToOpenInsightMetrologyViewer && _ConfigData.Duplicator.Value != ConfigData.Level.IsXToOpenInsightMetrologyViewerAttachments)
|
||||
{
|
||||
bool check = false;
|
||||
if (_ConfigData.Duplicator.Value != ConfigData.Level.IsXToIQSSi && _ConfigData.Duplicator.Value != ConfigData.Level.IsXToIQSGaN)
|
||||
check = true;
|
||||
else if (_ConfigData.Duplicator.Value == ConfigData.Level.IsXToIQSSi && !ganPPTST)
|
||||
check = true;
|
||||
else if (_ConfigData.Duplicator.Value == ConfigData.Level.IsXToIQSGaN && ganPPTST)
|
||||
check = true;
|
||||
//else
|
||||
// Don't write file(s) //throw new Exception();
|
||||
if (check)
|
||||
Shared0413(dateTime, isDummyRun, successDirectory, duplicateDirectory, tuples, duplicateFile);
|
||||
}
|
||||
}
|
||||
if (_ConfigData.Duplicator.Value == ConfigData.Level.IsXToOpenInsightMetrologyViewerAttachments)
|
||||
{
|
||||
string destinationDirectory;
|
||||
//string destinationDirectory = WriteScopeInfo(_ConfigData.ProgressPath, Logistics, dateTime, duplicateDirectory, tuples);
|
||||
FileInfo fileInfo = new FileInfo(reportFullPath);
|
||||
string logisticsSequence = Logistics.Sequence.ToString();
|
||||
if (fileInfo.Exists && fileInfo.LastWriteTime < fileInfo.CreationTime)
|
||||
File.SetLastWriteTime(reportFullPath, fileInfo.CreationTime);
|
||||
string jobIdDirectory = string.Concat(Path.GetDirectoryName(Path.GetDirectoryName(_Configuration.TargetFileLocation)), @"\", Logistics.JobID);
|
||||
if (!Directory.Exists(jobIdDirectory))
|
||||
Directory.CreateDirectory(jobIdDirectory);
|
||||
string[] matchDirectories;
|
||||
if (!_ConfigData.EafHosted)
|
||||
matchDirectories = new string[] { Path.GetDirectoryName(Path.GetDirectoryName(reportFullPath)) };
|
||||
else
|
||||
matchDirectories = Directory.GetDirectories(jobIdDirectory, string.Concat(Logistics.MID, '*', logisticsSequence, '*'), SearchOption.TopDirectoryOnly);
|
||||
if ((matchDirectories is null) || matchDirectories.Length != 1)
|
||||
throw new Exception("Didn't find directory by logistics sequence");
|
||||
destinationDirectory = matchDirectories[0];
|
||||
if (isDummyRun)
|
||||
Shared0607(reportFullPath, duplicateDirectory, logisticsSequence, destinationDirectory);
|
||||
else
|
||||
{
|
||||
List<ProcessData.FileRead.Description> fileReadDescriptions = ProcessData.GetProcessDataFileReadDescriptions(_ConfigData, pdsdBodyValues);
|
||||
ProcessData.WSRequest wsRequest = new ProcessData.WSRequest(this, fileReadDescriptions);
|
||||
JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
string json = JsonSerializer.Serialize(wsRequest, wsRequest.GetType(), jsonSerializerOptions);
|
||||
if (_ConfigData.EafHosted)
|
||||
Shared1277(reportFullPath, destinationDirectory, logisticsSequence, jobIdDirectory, json);
|
||||
else
|
||||
{
|
||||
string jsonFileName = Path.ChangeExtension(reportFullPath, ".json");
|
||||
string historicalText = File.ReadAllText(jsonFileName);
|
||||
if (json != historicalText)
|
||||
throw new Exception("File doesn't match historical!");
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private void MoveArchive()
|
||||
{
|
||||
CultureInfo cultureInfo = new CultureInfo("en-US");
|
||||
Calendar calendar = cultureInfo.Calendar;
|
||||
string logisticsSequence = Logistics.Sequence.ToString();
|
||||
string weekOfYear = calendar.GetWeekOfYear(Logistics.DateTimeFromSequence, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
string weekDirectory = string.Concat(Logistics.DateTimeFromSequence.ToString("yyyy"), "_Week_", weekOfYear, @"\", Logistics.DateTimeFromSequence.ToString("yyyy-MM-dd"));
|
||||
string jobIdDirectory = string.Concat(_Configuration.TargetFileLocation, @"\", Logistics.JobID);
|
||||
if (!Directory.Exists(jobIdDirectory))
|
||||
Directory.CreateDirectory(jobIdDirectory);
|
||||
//string destinationArchiveDirectory = string.Concat(jobIdDirectory, @"\!Archive\", weekDirectory);
|
||||
string destinationArchiveDirectory = string.Concat(Path.GetDirectoryName(_Configuration.TargetFileLocation), @"\Archive\", Logistics.JobID, @"\", weekDirectory);
|
||||
if (!Directory.Exists(destinationArchiveDirectory))
|
||||
Directory.CreateDirectory(destinationArchiveDirectory);
|
||||
string[] matchDirectories = new string[] { GetDirectoriesRecursively(jobIdDirectory, logisticsSequence).FirstOrDefault() };
|
||||
if ((matchDirectories is null) || matchDirectories.Length != 1)
|
||||
throw new Exception("Didn't find directory by logistics sequence");
|
||||
string sourceDirectory = Path.GetDirectoryName(matchDirectories[0]);
|
||||
destinationArchiveDirectory = string.Concat(destinationArchiveDirectory, @"\", Path.GetFileName(sourceDirectory));
|
||||
Directory.Move(sourceDirectory, destinationArchiveDirectory);
|
||||
}
|
||||
|
||||
public void Move(string reportFullPath, Tuple<string, JsonElement?, List<FileInfo>> extractResults, Exception exception = null)
|
||||
{
|
||||
Shared1872(reportFullPath, exception);
|
||||
bool isErrorFile = !(exception is null);
|
||||
if (!isErrorFile && _ConfigData.Duplicator.HasValue)
|
||||
{
|
||||
if (_ConfigData.Duplicator.Value == ConfigData.Level.IsXToArchive)
|
||||
Shared0192(reportFullPath);
|
||||
else if (_ConfigData.EafHosted && _ConfigData.Duplicator.Value == ConfigData.Level.IsArchive)
|
||||
MoveArchive();
|
||||
if (_ConfigData.EafHosted && !string.IsNullOrEmpty(_ConfigData.ProgressPath))
|
||||
CreateProgressDirectory(_ConfigData.ProgressPath, Logistics, (int?)_ConfigData.Duplicator, exceptionLines: null);
|
||||
}
|
||||
if (!isErrorFile && _ConfigData.Duplicator is null)
|
||||
WriteIO(reportFullPath);
|
||||
if (!_ConfigData.EafHosted)
|
||||
{
|
||||
object @object = GetFilePathGeneratorInfo(reportFullPath, isErrorFile: false);
|
||||
if (!(@object is null) && @object is string to)
|
||||
{
|
||||
if (to.Contains("%"))
|
||||
_Log.Debug("Can't debug without EAF Hosting");
|
||||
else
|
||||
Shared1124(reportFullPath, extractResults, to, _Configuration.SourceFileLocation, resolvedFileLocation: string.Empty, exception: null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
519
Adaptation/FileHandlers/MET08DDUPSFS6420/FileRead.cs
Normal file
519
Adaptation/FileHandlers/MET08DDUPSFS6420/FileRead.cs
Normal file
@ -0,0 +1,519 @@
|
||||
using Adaptation.Eaf.Management.ConfigurationData.CellAutomation;
|
||||
using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration;
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Duplicator;
|
||||
using Adaptation.Shared.Methods;
|
||||
using Adaptation.Shared.Metrology;
|
||||
using Infineon.Monitoring.MonA;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
|
||||
namespace Adaptation.FileHandlers.MET08DDUPSFS6420;
|
||||
|
||||
public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
|
||||
private readonly Timer _Timer;
|
||||
private int _LastDummyRunIndex;
|
||||
private readonly bool _IsDummy;
|
||||
private readonly bool _IsNaEDA;
|
||||
private readonly bool _IsXToAPC;
|
||||
private readonly string _IqsFile;
|
||||
private readonly bool _IsXToIQSSi;
|
||||
private readonly bool _IsXToSPaCe;
|
||||
private readonly bool _IsXToIQSGaN;
|
||||
private readonly string _MemoryPath;
|
||||
private readonly bool _IsXToOpenInsight;
|
||||
private readonly string _OpenInsightFilePattern;
|
||||
private readonly bool _IsXToOpenInsightMetrologyViewer;
|
||||
private readonly Dictionary<string, string> _CellNames;
|
||||
private readonly string _OpenInsightMetrologyViewerAPI;
|
||||
private readonly bool _IsXToOpenInsightMetrologyViewerAttachments;
|
||||
|
||||
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(), false, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted)
|
||||
{
|
||||
_MinFileLength = 10;
|
||||
_NullData = string.Empty;
|
||||
_Logistics = new Logistics(this);
|
||||
if (_FileParameter is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (_ModelObjectParameterDefinitions is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (!_IsDuplicator)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
_LastDummyRunIndex = -1;
|
||||
_IsDummy = _Hyphens == (int)Hyphen.IsDummy;
|
||||
_IsNaEDA = _Hyphens == (int)Hyphen.IsNaEDA;
|
||||
_IsXToAPC = _Hyphens == (int)Hyphen.IsXToAPC;
|
||||
_CellNames = new Dictionary<string, string>();
|
||||
_IsXToIQSSi = _Hyphens == (int)Hyphen.IsXToIQSSi;
|
||||
_IsXToSPaCe = _Hyphens == (int)Hyphen.IsXToSPaCe;
|
||||
_IsXToIQSGaN = _Hyphens == (int)Hyphen.IsXToIQSGaN;
|
||||
_IsXToOpenInsight = _Hyphens == (int)Hyphen.IsXToOpenInsight;
|
||||
_IsXToOpenInsightMetrologyViewer = _Hyphens == (int)Hyphen.IsXToOpenInsightMetrologyViewer;
|
||||
_IqsFile = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "IQS.File");
|
||||
_MemoryPath = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "Path.Memory");
|
||||
_IsXToOpenInsightMetrologyViewerAttachments = _Hyphens == (int)Hyphen.IsXToOpenInsightMetrologyViewerAttachments;
|
||||
_OpenInsightFilePattern = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "OpenInsight.FilePattern");
|
||||
_OpenInsightMetrologyViewerAPI = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "OpenInsight.MetrologyViewerAPI");
|
||||
ModelObjectParameterDefinition[] cellInstanceCollection = GetProperties(cellInstanceConnectionName, modelObjectParameters, "CellInstance.", ".Path");
|
||||
foreach (ModelObjectParameterDefinition modelObjectParameterDefinition in cellInstanceCollection)
|
||||
_CellNames.Add(modelObjectParameterDefinition.Name.Split('.')[1], modelObjectParameterDefinition.Value);
|
||||
if (_IsDummy)
|
||||
{
|
||||
if (Debugger.IsAttached || fileConnectorConfiguration.PreProcessingMode == FileConnectorConfiguration.PreProcessingModeEnum.Process)
|
||||
{
|
||||
_Timer = new Timer(Callback, null, Timeout.Infinite, Timeout.Infinite);
|
||||
Callback(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
int milliSeconds;
|
||||
milliSeconds = (int)(fileConnectorConfiguration.FileScanningIntervalInSeconds * 1000 / 2);
|
||||
_Timer = new Timer(Callback, null, milliSeconds, Timeout.Infinite);
|
||||
milliSeconds += 2000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) => Move(extractResults, exception);
|
||||
|
||||
void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null);
|
||||
|
||||
string IFileRead.GetEventDescription()
|
||||
{
|
||||
string result = _Description.GetEventDescription();
|
||||
return result;
|
||||
}
|
||||
|
||||
List<string> IFileRead.GetHeaderNames()
|
||||
{
|
||||
List<string> results = _Description.GetHeaderNames();
|
||||
return results;
|
||||
}
|
||||
|
||||
string[] IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, string to, string from, string resolvedFileLocation, Exception exception)
|
||||
{
|
||||
string[] results = Move(extractResults, to, from, resolvedFileLocation, exception);
|
||||
return results;
|
||||
}
|
||||
|
||||
JsonProperty[] IFileRead.GetDefault()
|
||||
{
|
||||
JsonProperty[] results = _Description.GetDefault(this, _Logistics);
|
||||
return results;
|
||||
}
|
||||
|
||||
Dictionary<string, string> IFileRead.GetDisplayNamesJsonElement()
|
||||
{
|
||||
Dictionary<string, string> results = _Description.GetDisplayNamesJsonElement(this);
|
||||
return results;
|
||||
}
|
||||
|
||||
List<IDescription> IFileRead.GetDescriptions(IFileRead fileRead, List<Test> tests, IProcessData processData)
|
||||
{
|
||||
List<IDescription> results = _Description.GetDescriptions(fileRead, _Logistics, tests, processData);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.GetExtractResult(string reportFullPath, string eventName)
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
if (string.IsNullOrEmpty(eventName))
|
||||
throw new Exception();
|
||||
_ReportFullPath = reportFullPath;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
results = GetExtractResult(reportFullPath, dateTime);
|
||||
if (results.Item3 is null)
|
||||
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(results.Item1, Array.Empty<Test>(), JsonSerializer.Deserialize<JsonElement[]>("[]"), results.Item4);
|
||||
if (results.Item3.Length > 0 && _IsEAFHosted)
|
||||
WritePDSF(this, results.Item3);
|
||||
UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.ReExtract()
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
List<string> headerNames = _Description.GetHeaderNames();
|
||||
Dictionary<string, string> keyValuePairs = _Description.GetDisplayNamesJsonElement(this);
|
||||
results = ReExtract(this, headerNames, keyValuePairs);
|
||||
return results;
|
||||
}
|
||||
|
||||
void IFileRead.CheckTests(Test[] tests, bool extra)
|
||||
{
|
||||
if (_Description is not Description)
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
void IFileRead.Callback(object state) => Callback(state);
|
||||
|
||||
protected static List<pcl.Description> GetDescriptions(JsonElement[] jsonElements)
|
||||
{
|
||||
List<pcl.Description> results = new();
|
||||
pcl.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<pcl.Description>(jsonElement.ToString(), jsonSerializerOptions);
|
||||
results.Add(description);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime)
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
string duplicateDirectory;
|
||||
Tuple<string, string[], string[]> pdsf = ProcessDataStandardFormat.GetLogisticsColumnsAndBody(reportFullPath);
|
||||
_Logistics = new Logistics(reportFullPath, pdsf.Item1);
|
||||
SetFileParameterLotIDToLogisticsMID();
|
||||
JsonElement[] jsonElements = ProcessDataStandardFormat.GetArray(pdsf);
|
||||
List<pcl.Description> descriptions = GetDescriptions(jsonElements);
|
||||
Tuple<Test[], Dictionary<Test, List<Shared.Properties.IDescription>>> tuple = GetTuple(this, from l in descriptions select (Shared.Properties.IDescription)l, extra: false);
|
||||
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(pdsf.Item1, tuple.Item1, jsonElements, new List<FileInfo>());
|
||||
bool isNotUsedInsightMetrologyViewerAttachments = !(_FileConnectorConfiguration.FileScanningIntervalInSeconds > 0) && _IsXToOpenInsightMetrologyViewerAttachments;
|
||||
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();
|
||||
if (isDummyRun)
|
||||
{
|
||||
try
|
||||
{ File.SetLastWriteTime(reportFullPath, dateTime); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
string[] segments = Path.GetFileNameWithoutExtension(reportFullPath).Split('_');
|
||||
if (_IsXToIQSSi)
|
||||
duplicateDirectory = string.Concat(_FileConnectorConfiguration.TargetFileLocation, @"\All");
|
||||
else if (!_IsXToOpenInsight)
|
||||
duplicateDirectory = string.Concat(_FileConnectorConfiguration.TargetFileLocation, @"\", segments[0]);
|
||||
else
|
||||
duplicateDirectory = string.Concat(Path.GetDirectoryName(Path.GetDirectoryName(_FileConnectorConfiguration.TargetFileLocation)), @"\Data");
|
||||
if (segments.Length > 2)
|
||||
duplicateDirectory = string.Concat(duplicateDirectory, @"-", segments[2]);
|
||||
if (!Directory.Exists(duplicateDirectory))
|
||||
_ = Directory.CreateDirectory(duplicateDirectory);
|
||||
if (isDummyRun || isNotUsedInsightMetrologyViewerAttachments || _FileConnectorConfiguration.FileScanningIntervalInSeconds > 0)
|
||||
{
|
||||
bool ganPPTST = false;
|
||||
if (!Directory.Exists(duplicateDirectory))
|
||||
_ = Directory.CreateDirectory(duplicateDirectory);
|
||||
string successDirectory;
|
||||
if (!_IsXToAPC)
|
||||
successDirectory = string.Empty;
|
||||
else
|
||||
{
|
||||
successDirectory = string.Concat(Path.GetDirectoryName(_FileConnectorConfiguration.TargetFileLocation), @"\ViewerPath");
|
||||
if (!Directory.Exists(successDirectory))
|
||||
_ = Directory.CreateDirectory(successDirectory);
|
||||
}
|
||||
List<Tuple<Shared.Properties.IScopeInfo, string>> tuples = new();
|
||||
string duplicateFile = string.Concat(duplicateDirectory, @"\", Path.GetFileName(reportFullPath));
|
||||
string weekOfYear = _Calendar.GetWeekOfYear(_Logistics.DateTimeFromSequence, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
string weekDirectory = string.Concat(_Logistics.DateTimeFromSequence.ToString("yyyy"), "_Week_", weekOfYear, @"\", _Logistics.DateTimeFromSequence.ToString("yyyy-MM-dd"));
|
||||
string logisticsSequenceMemoryDirectory = string.Concat(_MemoryPath, @"\", _EquipmentType, @"\Source\", weekDirectory, @"\", _Logistics.Sequence);
|
||||
if (!Directory.Exists(logisticsSequenceMemoryDirectory))
|
||||
_ = Directory.CreateDirectory(logisticsSequenceMemoryDirectory);
|
||||
if (_IsXToAPC)
|
||||
{
|
||||
if (!isDummyRun && _IsEAFHosted)
|
||||
File.Copy(reportFullPath, duplicateFile, overwrite: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_IsXToOpenInsightMetrologyViewer)
|
||||
{
|
||||
WSRequest wsRequest = new(this, _Logistics, descriptions);
|
||||
if (!isDummyRun && _IsEAFHosted)
|
||||
{
|
||||
Tuple<string, WS.Results> wsResults = WS.SendData(_OpenInsightMetrologyViewerAPI, wsRequest);
|
||||
if (!wsResults.Item2.Success)
|
||||
throw new Exception(wsResults.ToString());
|
||||
_Log.Debug(wsResults.Item2.HeaderID);
|
||||
File.WriteAllText(string.Concat(logisticsSequenceMemoryDirectory, @"\", nameof(WS.Results), ".json"), wsResults.Item1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Test test;
|
||||
string lines;
|
||||
Shared.Properties.IScopeInfo scopeInfo;
|
||||
foreach (KeyValuePair<Test, List<Shared.Properties.IDescription>> keyValuePair in tuple.Item2)
|
||||
{
|
||||
test = keyValuePair.Key;
|
||||
//scopeInfo = new ScopeInfo(test);
|
||||
if (!_IsXToOpenInsight)
|
||||
scopeInfo = new ScopeInfo(test, _IqsFile);
|
||||
else
|
||||
scopeInfo = new ScopeInfo(test, _OpenInsightFilePattern);
|
||||
//lines = ProcessDataStandardFormat.GetLines(this, scopeInfo, names, values, dateFormat: "M/d/yyyy hh:mm:ss tt", timeFormat: string.Empty, pairedColumns: ExtractResultPairedColumns);
|
||||
ganPPTST = descriptions[0].Recipe.Contains("GAN_PPTST");
|
||||
lines = ProcessData.GetLines(this, _Logistics, descriptions, ganPPTST);
|
||||
tuples.Add(new Tuple<Shared.Properties.IScopeInfo, string>(scopeInfo, lines));
|
||||
}
|
||||
}
|
||||
if (_IsXToOpenInsightMetrologyViewerAttachments)
|
||||
{
|
||||
string[] matchDirectories = Shared1567(reportFullPath, tuples);
|
||||
if (!isDummyRun && _IsEAFHosted && !isNotUsedInsightMetrologyViewerAttachments)
|
||||
ProcessData.PostOpenInsightMetrologyViewerAttachments(this, _Logistics, _OpenInsightMetrologyViewerAPI, dateTime, logisticsSequenceMemoryDirectory, descriptions, matchDirectories[0]);
|
||||
}
|
||||
}
|
||||
if (!_IsXToOpenInsightMetrologyViewer && !_IsXToOpenInsightMetrologyViewerAttachments)
|
||||
{
|
||||
bool check = false;
|
||||
if (!_IsXToIQSSi && !_IsXToIQSGaN)
|
||||
check = true;
|
||||
else if (_IsXToIQSSi && !ganPPTST)
|
||||
check = true;
|
||||
else if (_IsXToIQSGaN && ganPPTST)
|
||||
check = true;
|
||||
//else
|
||||
// Don't write file(s) //throw new Exception();
|
||||
if (check)
|
||||
Shared0413(dateTime, isDummyRun, successDirectory, duplicateDirectory, tuples, duplicateFile);
|
||||
}
|
||||
}
|
||||
if (_IsXToOpenInsightMetrologyViewerAttachments)
|
||||
{
|
||||
string destinationDirectory;
|
||||
//string destinationDirectory = WriteScopeInfo(_ProgressPath, _Logistics, dateTime, duplicateDirectory, tuples);
|
||||
FileInfo fileInfo = new(reportFullPath);
|
||||
string logisticsSequence = _Logistics.Sequence.ToString();
|
||||
if (fileInfo.Exists && fileInfo.LastWriteTime < fileInfo.CreationTime)
|
||||
File.SetLastWriteTime(reportFullPath, fileInfo.CreationTime);
|
||||
string jobIdDirectory = string.Concat(Path.GetDirectoryName(Path.GetDirectoryName(_FileConnectorConfiguration.TargetFileLocation)), @"\", _Logistics.JobID);
|
||||
if (!Directory.Exists(jobIdDirectory))
|
||||
_ = Directory.CreateDirectory(jobIdDirectory);
|
||||
string[] matchDirectories;
|
||||
if (!_IsEAFHosted)
|
||||
matchDirectories = new string[] { Path.GetDirectoryName(Path.GetDirectoryName(reportFullPath)) };
|
||||
else
|
||||
matchDirectories = Directory.GetDirectories(jobIdDirectory, string.Concat(_Logistics.MID, '*', logisticsSequence, '*'), SearchOption.TopDirectoryOnly);
|
||||
if ((matchDirectories is null) || matchDirectories.Length != 1)
|
||||
throw new Exception("Didn't find directory by logistics sequence");
|
||||
destinationDirectory = matchDirectories[0];
|
||||
if (isDummyRun)
|
||||
Shared0607(reportFullPath, duplicateDirectory, logisticsSequence, destinationDirectory);
|
||||
else
|
||||
{
|
||||
WSRequest wsRequest = new(this, _Logistics, descriptions);
|
||||
JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true };
|
||||
string json = JsonSerializer.Serialize(wsRequest, wsRequest.GetType(), jsonSerializerOptions);
|
||||
if (_IsEAFHosted)
|
||||
Shared1277(reportFullPath, destinationDirectory, logisticsSequence, jobIdDirectory, json);
|
||||
else
|
||||
{
|
||||
string jsonFileName = Path.ChangeExtension(reportFullPath, ".json");
|
||||
string historicalText = File.ReadAllText(jsonFileName);
|
||||
if (json != historicalText)
|
||||
throw new Exception("File doesn't match historical!");
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private void CallbackIsDummy(string traceDummyFile, List<Tuple<string, string, string, string, int>> tuples, bool fileConnectorConfigurationIncludeSubDirectories, bool includeSubDirectoriesExtra)
|
||||
{
|
||||
int fileCount;
|
||||
string[] files;
|
||||
string monARessource;
|
||||
string checkDirectory;
|
||||
string sourceArchiveFile;
|
||||
string inProcessDirectory;
|
||||
const string site = "sjc";
|
||||
string stateName = string.Concat("Dummy_", _EventName);
|
||||
const string monInURL = "http://moninhttp.sjc.infineon.com/input/text";
|
||||
MonIn monIn = MonIn.GetInstance(monInURL);
|
||||
foreach (Tuple<string, string, string, string, int> item in tuples)
|
||||
{
|
||||
monARessource = item.Item1;
|
||||
sourceArchiveFile = item.Item2;
|
||||
inProcessDirectory = item.Item3;
|
||||
checkDirectory = item.Item4;
|
||||
fileCount = item.Item5;
|
||||
try
|
||||
{
|
||||
if (fileCount > 0 || string.IsNullOrEmpty(checkDirectory))
|
||||
{
|
||||
File.AppendAllLines(traceDummyFile, new string[] { site, monARessource, stateName, State.Warning.ToString() });
|
||||
_ = monIn.SendStatus(site, monARessource, stateName, State.Warning);
|
||||
for (int i = 1; i < 12; i++)
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
else if (inProcessDirectory == checkDirectory)
|
||||
continue;
|
||||
if (!_IsEAFHosted)
|
||||
continue;
|
||||
if (!File.Exists(sourceArchiveFile))
|
||||
continue;
|
||||
if (!long.TryParse(Path.GetFileNameWithoutExtension(sourceArchiveFile).Replace("x", string.Empty), out long sequence))
|
||||
continue;
|
||||
ZipFile.ExtractToDirectory(sourceArchiveFile, inProcessDirectory);
|
||||
if (fileConnectorConfigurationIncludeSubDirectories && includeSubDirectoriesExtra)
|
||||
checkDirectory = string.Concat(checkDirectory, @"\", sequence);
|
||||
if (fileConnectorConfigurationIncludeSubDirectories)
|
||||
files = Directory.GetFiles(inProcessDirectory, "*", SearchOption.AllDirectories);
|
||||
else
|
||||
files = Directory.GetFiles(inProcessDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (files.Length > 250)
|
||||
throw new Exception("Safety net!");
|
||||
foreach (string file in files)
|
||||
File.SetLastWriteTime(file, new DateTime(sequence));
|
||||
if (!fileConnectorConfigurationIncludeSubDirectories)
|
||||
{
|
||||
foreach (string file in files)
|
||||
File.Move(file, string.Concat(checkDirectory, @"\", Path.GetFileName(file)));
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] directories = Directory.GetDirectories(inProcessDirectory, "*", SearchOption.AllDirectories);
|
||||
foreach (string directory in directories)
|
||||
_ = Directory.CreateDirectory(string.Concat(checkDirectory, directory.Substring(inProcessDirectory.Length)));
|
||||
foreach (string file in files)
|
||||
File.Move(file, string.Concat(checkDirectory, file.Substring(inProcessDirectory.Length)));
|
||||
}
|
||||
File.AppendAllLines(traceDummyFile, new string[] { site, monARessource, stateName, State.Ok.ToString() });
|
||||
_ = monIn.SendStatus(site, monARessource, stateName, State.Ok);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
string subject = string.Concat("Exception:", _CellInstanceConnectionName);
|
||||
string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace);
|
||||
try
|
||||
{ _SMTP.SendHighPriorityEmailMessage(subject, body); }
|
||||
catch (Exception) { }
|
||||
File.AppendAllLines(traceDummyFile, new string[] { site, monARessource, stateName, State.Critical.ToString(), exception.Message, exception.StackTrace });
|
||||
_ = monIn.SendStatus(site, monARessource, stateName, State.Critical);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Callback(object state)
|
||||
{
|
||||
if (!_IsDummy)
|
||||
throw new Exception();
|
||||
try
|
||||
{
|
||||
DateTime dateTime = DateTime.Now;
|
||||
bool check = dateTime.Hour > 7 && dateTime.Hour < 18 && dateTime.DayOfWeek != DayOfWeek.Sunday && dateTime.DayOfWeek != DayOfWeek.Saturday;
|
||||
if (check)
|
||||
{
|
||||
int fileCount;
|
||||
string[] files;
|
||||
string monARessource;
|
||||
string checkDirectory;
|
||||
string sourceArchiveFile;
|
||||
string sourceFileLocation;
|
||||
string inProcessDirectory;
|
||||
string weekOfYear = _Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
string traceDummyDirectory = string.Concat(Path.GetPathRoot(_TracePath), @"\TracesDummy\", _CellInstanceName, @"\Source\", dateTime.ToString("yyyy"), "___Week_", weekOfYear);
|
||||
if (!Directory.Exists(traceDummyDirectory))
|
||||
_ = Directory.CreateDirectory(traceDummyDirectory);
|
||||
string traceDummyFile = string.Concat(traceDummyDirectory, @"\", dateTime.Ticks, " - ", _CellInstanceName, ".txt");
|
||||
File.AppendAllText(traceDummyFile, string.Empty);
|
||||
List<Tuple<string, string, string, string, int>> tuples = new();
|
||||
string progressDirectory = Path.GetFullPath(string.Concat(_FileConnectorConfiguration.SourceFileLocation, @"\_ Progress"));
|
||||
if (progressDirectory != _ProgressPath || !Directory.Exists(progressDirectory))
|
||||
throw new Exception("Invalid progress path");
|
||||
foreach (KeyValuePair<string, string> keyValuePair in _CellNames)
|
||||
{
|
||||
monARessource = keyValuePair.Key;
|
||||
if (!keyValuePair.Value.Contains('\\'))
|
||||
continue;
|
||||
foreach (string sourceFileFilter in _FileConnectorConfiguration.SourceFileFilter.Split('|'))
|
||||
{
|
||||
if (sourceFileFilter.ToLower().StartsWith(keyValuePair.Value.Replace(@"\", string.Empty)))
|
||||
sourceFileLocation = Path.GetFullPath(_FileConnectorConfiguration.SourceFileLocation);
|
||||
else if (_FileConnectorConfiguration.SourceFileLocation.ToLower().EndsWith(keyValuePair.Value))
|
||||
sourceFileLocation = Path.GetFullPath(_FileConnectorConfiguration.SourceFileLocation);
|
||||
else
|
||||
sourceFileLocation = Path.GetFullPath(string.Concat(_FileConnectorConfiguration.SourceFileLocation, @"\", keyValuePair.Value));
|
||||
sourceArchiveFile = Path.GetFullPath(string.Concat(sourceFileLocation, @"\", sourceFileFilter));
|
||||
if (!File.Exists(sourceArchiveFile))
|
||||
continue;
|
||||
if (!_DummyRuns.ContainsKey(monARessource))
|
||||
_DummyRuns.Add(monARessource, new List<long>());
|
||||
tuples.Add(new Tuple<string, string, string, string, int>(monARessource, sourceFileFilter, sourceFileLocation, sourceArchiveFile, 0));
|
||||
}
|
||||
}
|
||||
File.AppendAllLines(traceDummyFile, from l in tuples select l.Item4);
|
||||
if (tuples.Any())
|
||||
{
|
||||
_LastDummyRunIndex += 1;
|
||||
if (_LastDummyRunIndex >= tuples.Count)
|
||||
_LastDummyRunIndex = 0;
|
||||
monARessource = tuples[_LastDummyRunIndex].Item1;
|
||||
string sourceFileFilter = tuples[_LastDummyRunIndex].Item2;
|
||||
sourceFileLocation = tuples[_LastDummyRunIndex].Item3;
|
||||
sourceArchiveFile = tuples[_LastDummyRunIndex].Item4;
|
||||
//fileCount = tuples[_LastDummyRunIndex].Item5;
|
||||
tuples.Clear();
|
||||
if (long.TryParse(Path.GetFileNameWithoutExtension(sourceArchiveFile).Replace("x", string.Empty), out long sequence))
|
||||
{
|
||||
if (!_DummyRuns[monARessource].Contains(sequence))
|
||||
_DummyRuns[monARessource].Add(sequence);
|
||||
inProcessDirectory = string.Concat(progressDirectory, @"\Dummy_in process\", sequence);
|
||||
checkDirectory = inProcessDirectory;
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
files = Directory.GetFiles(checkDirectory, "*", SearchOption.AllDirectories);
|
||||
fileCount = files.Length;
|
||||
if (files.Any())
|
||||
{
|
||||
if (files.Length > 250)
|
||||
throw new Exception("Safety net!");
|
||||
try
|
||||
{
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
tuples.Add(new Tuple<string, string, string, string, int>(monARessource, sourceArchiveFile, inProcessDirectory, checkDirectory, fileCount));
|
||||
checkDirectory = sourceFileLocation;
|
||||
files = Directory.GetFiles(checkDirectory, string.Concat("*", sequence, "*"), SearchOption.TopDirectoryOnly);
|
||||
fileCount = files.Length;
|
||||
tuples.Add(new Tuple<string, string, string, string, int>(monARessource, sourceArchiveFile, inProcessDirectory, checkDirectory, fileCount));
|
||||
}
|
||||
}
|
||||
if (tuples.Any())
|
||||
//CallbackIsDummy(traceDummyFile, tuples, FileConnectorConfiguration.IncludeSubDirectories.Value, includeSubDirectoriesExtra: false);
|
||||
CallbackIsDummy(traceDummyFile, tuples, fileConnectorConfigurationIncludeSubDirectories: true, includeSubDirectoriesExtra: true);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
string subject = string.Concat("Exception:", _CellInstanceConnectionName);
|
||||
string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace);
|
||||
try
|
||||
{ _SMTP.SendHighPriorityEmailMessage(subject, body); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
try
|
||||
{
|
||||
TimeSpan timeSpan = new(DateTime.Now.AddSeconds(_FileConnectorConfiguration.FileScanningIntervalInSeconds.Value).Ticks - DateTime.Now.Ticks);
|
||||
_ = _Timer.Change((long)timeSpan.TotalMilliseconds, Timeout.Infinite);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
string subject = string.Concat("Exception:", _CellInstanceConnectionName);
|
||||
string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace);
|
||||
try
|
||||
{ _SMTP.SendHighPriorityEmailMessage(subject, body); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
17
Adaptation/FileHandlers/MET08DDUPSFS6420/Hyphen.cs
Normal file
17
Adaptation/FileHandlers/MET08DDUPSFS6420/Hyphen.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace Adaptation.FileHandlers.MET08DDUPSFS6420;
|
||||
|
||||
public enum Hyphen
|
||||
{
|
||||
IsXToOpenInsightMetrologyViewer, //MetrologyWS.SendData(logic, string.Concat("http://", serverName, "/api/inbound/Tencor"), headerAttachments, detailAttachments);
|
||||
IsXToIQSSi, //bool WriteFileSPC(Dictionary
|
||||
IsXToIQSGaN, //GAN_PPTST
|
||||
IsXToOpenInsight, //bool WriteFileOpenInsight(Dictionary
|
||||
IsXToOpenInsightMetrologyViewerAttachments, //Site-Two
|
||||
IsXToAPC,
|
||||
IsXToSPaCe,
|
||||
IsXToArchive,
|
||||
IsArchive,
|
||||
IsDummy,
|
||||
IsManualOIEntry,
|
||||
IsNaEDA
|
||||
}
|
278
Adaptation/FileHandlers/MET08DDUPSFS6420/ProcessData.cs
Normal file
278
Adaptation/FileHandlers/MET08DDUPSFS6420/ProcessData.cs
Normal file
@ -0,0 +1,278 @@
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Metrology;
|
||||
using Adaptation.Shared.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Adaptation.FileHandlers.MET08DDUPSFS6420;
|
||||
|
||||
public class ProcessData
|
||||
{
|
||||
|
||||
internal static List<Tuple<int, Enum, string>> HyphenTuples => new()
|
||||
{
|
||||
new Tuple<int, Enum, string>(0, Hyphen.IsNaEDA, @"\EC_EDA\Staging\Traces\~\Source"),
|
||||
new Tuple<int, Enum, string>(15, Hyphen.IsXToOpenInsightMetrologyViewer, @"\EC_EAFLog\TracesMES\~\Source"),
|
||||
new Tuple<int, Enum, string>(36, Hyphen.IsXToIQSSi, @"\EC_SPC_Si\Traces\~\PollPath"),
|
||||
new Tuple<int, Enum, string>(36, Hyphen.IsXToIQSGaN, @"\EC_SPC_GaN\Traces\~\PollPath"),
|
||||
new Tuple<int, Enum, string>(36, Hyphen.IsXToOpenInsight, @"\\messa01ec.ec.local\APPS\Metrology\~\Source"),
|
||||
new Tuple<int, Enum, string>(36, Hyphen.IsXToOpenInsightMetrologyViewerAttachments, @"\EC_Characterization_Si\In Process\~\Source"),
|
||||
new Tuple<int, Enum, string>(360, Hyphen.IsXToAPC, @"\EC_APC\Staging\Traces\~\PollPath"),
|
||||
new Tuple<int, Enum, string>(-36, Hyphen.IsXToSPaCe, @"\EC_SPC_Si\Traces\~\Source"),
|
||||
new Tuple<int, Enum, string>(180, Hyphen.IsXToArchive, @"\EC_EAFLog\TracesArchive\~\Source"),
|
||||
new Tuple<int, Enum, string>(36, Hyphen.IsArchive, @"\EC_Characterization_Si\Processed")
|
||||
//new Tuple<int, Enum, string>("IsDummy"
|
||||
};
|
||||
|
||||
internal static string GetLines(IFileRead fileRead, Logistics logistics, List<pcl.Description> descriptions, bool ganPPTST)
|
||||
{
|
||||
if (fileRead is null)
|
||||
{ }
|
||||
StringBuilder result = new();
|
||||
pcl.Description x = descriptions[0];
|
||||
if (ganPPTST)
|
||||
{
|
||||
string slot;
|
||||
string reactor;
|
||||
const int eight = 8;
|
||||
DateTime dateTime = DateTime.Parse(x.Date);
|
||||
string lot = x.Lot.ToLower().Replace("69-", string.Empty).Replace("71-", string.Empty).Replace("-", string.Empty);
|
||||
if (string.IsNullOrEmpty(x.Lot) || x.Lot.Length < 2)
|
||||
reactor = "R";
|
||||
else
|
||||
reactor = string.Concat("R", x.Lot.Substring(0, 2));
|
||||
_ = result.Append(nameof(x.Date)).Append(';').
|
||||
Append("Part").Append(';').
|
||||
Append(nameof(x.Reactor)).Append(';').
|
||||
Append("Lot").Append(';').
|
||||
Append(nameof(pcl.Detail.Slot)).Append(';').
|
||||
Append(nameof(pcl.Detail.Bin1)).Append(';').
|
||||
Append(nameof(pcl.Detail.Bin2)).Append(';').
|
||||
Append(nameof(pcl.Detail.Bin3)).Append(';').
|
||||
Append(nameof(pcl.Detail.Bin4)).Append(';').
|
||||
Append(nameof(pcl.Detail.Bin5)).Append(';').
|
||||
Append(nameof(pcl.Detail.Bin6)).Append(';').
|
||||
Append("Bin9").
|
||||
AppendLine();
|
||||
foreach (pcl.Description description in descriptions)
|
||||
{
|
||||
slot = description.Slot.Replace("*", string.Empty);
|
||||
_ = result.Append('!').Append(dateTime.ToString("MM/dd/yyyy HH:mm:ss")).Append(';').
|
||||
Append("Particle Adder;").
|
||||
Append(reactor).Append(';').
|
||||
Append(lot).Append(';').
|
||||
Append(slot).Append(';').
|
||||
Append(description.Bin1).Append(';').
|
||||
Append(description.Bin2).Append(';').
|
||||
Append(description.Bin3).Append(';').
|
||||
Append(description.Bin4).Append(';').
|
||||
Append(description.Bin5).Append(';').
|
||||
Append(description.Bin6).Append(';').
|
||||
Append(description.AreaCount).
|
||||
AppendLine();
|
||||
}
|
||||
if (descriptions.Count != eight)
|
||||
{
|
||||
string negativeTenThousand = "-10000";
|
||||
for (int i = descriptions.Count; i < eight; i++)
|
||||
{
|
||||
_ = result.Append('!').Append(dateTime.ToString("MM/dd/yyyy HH:mm:ss")).Append(';').
|
||||
Append("Particle Adder;").
|
||||
Append(reactor).Append(';').
|
||||
Append(lot).Append(';').
|
||||
Append(negativeTenThousand).Append(';').
|
||||
Append(negativeTenThousand).Append(';').
|
||||
Append(negativeTenThousand).Append(';').
|
||||
Append(negativeTenThousand).Append(';').
|
||||
Append(negativeTenThousand).Append(';').
|
||||
Append(negativeTenThousand).Append(';').
|
||||
Append(negativeTenThousand).Append(';').
|
||||
Append(negativeTenThousand).
|
||||
AppendLine();
|
||||
}
|
||||
}
|
||||
if (result.ToString().Split('\n').Length != (eight + 2))
|
||||
throw new Exception(string.Concat("Must have ", eight, " samples"));
|
||||
}
|
||||
else
|
||||
{
|
||||
char del = '\t';
|
||||
_ = result.Append(x.AreaCountAvg).Append(del). // 001 - AreaCountAvg
|
||||
Append(x.AreaCountMax).Append(del). // 002 - AreaCountMax
|
||||
Append(x.AreaCountMin).Append(del). // 003 - AreaCountMin
|
||||
Append(x.AreaCountStdDev).Append(del). // 004 - AreaCountStdDev
|
||||
Append(x.AreaTotalAvg).Append(del). // 005 - AreaTotalAvg
|
||||
Append(x.AreaTotalMax).Append(del). // 006 - AreaTotalMax
|
||||
Append(x.AreaTotalMin).Append(del). // 007 - AreaTotalMin
|
||||
Append(x.AreaTotalStdDev).Append(del). // 008 - AreaTotalStdDev
|
||||
Append(x.Date).Append(del). // 009 -
|
||||
Append(x.HazeAverageAvg).Append(del). // 010 - Haze Average
|
||||
Append(x.HazeAverageMax).Append(del). // 011 -
|
||||
Append(x.HazeAverageMin).Append(del). // 012 -
|
||||
Append(x.HazeAverageStdDev).Append(del). // 013 -
|
||||
Append(x.HazeRegionAvg).Append(del). // 014 -
|
||||
Append(x.HazeRegionMax).Append(del). // 015 -
|
||||
Append(x.HazeRegionMin).Append(del). // 016 -
|
||||
Append(x.HazeRegionStdDev).Append(del). // 017 -
|
||||
Append(x.Lot).Append(del). // 018 -
|
||||
Append(x.LPDCM2Avg).Append(del). // 019 -
|
||||
Append(x.LPDCM2Max).Append(del). // 020 -
|
||||
Append(x.LPDCM2Min).Append(del). // 021 -
|
||||
Append(x.LPDCM2StdDev).Append(del). // 022 -
|
||||
Append(x.LPDCountAvg).Append(del). // 023 -
|
||||
Append(x.LPDCountMax).Append(del). // 024 -
|
||||
Append(x.LPDCM2Min).Append(del). // 025 -
|
||||
Append(x.LPDCountStdDev).Append(del). // 026 -
|
||||
Append(x.Employee).Append(del). // 027 -
|
||||
Append(x.RDS).Append(del). // 028 - Lot
|
||||
Append(x.Reactor).Append(del). // 029 - Process
|
||||
Append(x.Recipe.Replace(";", string.Empty)).Append(del). // 030 - Part
|
||||
Append(x.ScratchCountAvg).Append(del). // 031 - Scratch Count
|
||||
Append(x.ScratchCountMax).Append(del). // 032 -
|
||||
Append(x.ScratchCountMin).Append(del). // 033 -
|
||||
Append(x.ScratchTotalStdDev).Append(del). // 034 -
|
||||
Append(x.ScratchTotalAvg).Append(del). // 035 - Scratch Length
|
||||
Append(x.ScratchTotalMax).Append(del). // 036 -
|
||||
Append(x.ScratchTotalMin).Append(del). // 037 -
|
||||
Append(x.ScratchTotalStdDev).Append(del). // 038 -
|
||||
Append(x.SumOfDefectsAvg).Append(del). // 039 - Average Sum of Defects
|
||||
Append(x.SumOfDefectsMax).Append(del). // 040 - Max Sum of Defects
|
||||
Append(x.SumOfDefectsMin).Append(del). // 041 - Min Sum of Defects
|
||||
Append(x.SumOfDefectsStdDev).Append(del). // 042 - SumOfDefectsStdDev
|
||||
Append(logistics.MesEntity).Append(del). // 043 -
|
||||
AppendLine();
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
private static void UpdateDataPDF(List<pcl.Description> descriptions, string checkFileName)
|
||||
{
|
||||
string value;
|
||||
object possiblePage;
|
||||
object possibleString;
|
||||
object possibleCOSArray;
|
||||
java.util.List tokenList;
|
||||
java.util.List arrayList;
|
||||
java.io.OutputStream outputStream;
|
||||
List<string> updateValues = new();
|
||||
StringBuilder stringBuilder = new();
|
||||
java.util.ListIterator tokenIterator;
|
||||
java.util.ListIterator arrayIterator;
|
||||
java.io.File file = new(checkFileName);
|
||||
string reactorLoadLock = descriptions[0].Comments;
|
||||
org.apache.pdfbox.pdmodel.common.PDStream pdStream;
|
||||
org.apache.pdfbox.pdmodel.common.PDStream updatedStream;
|
||||
org.apache.pdfbox.pdfparser.PDFStreamParser pdfStreamParser;
|
||||
org.apache.pdfbox.pdfwriter.ContentStreamWriter contentStreamWriter;
|
||||
org.apache.pdfbox.pdmodel.PDDocument pdDocument = org.apache.pdfbox.pdmodel.PDDocument.load(file);
|
||||
org.apache.pdfbox.pdmodel.PDDocumentCatalog pdDocumentCatalog = pdDocument.getDocumentCatalog();
|
||||
java.util.List pagesList = pdDocumentCatalog.getAllPages();
|
||||
java.util.ListIterator pageIterator = pagesList.listIterator();
|
||||
for (short i = 1; i < short.MaxValue; i++)
|
||||
{
|
||||
if (!pageIterator.hasNext())
|
||||
break;
|
||||
possiblePage = pageIterator.next();
|
||||
if (possiblePage is not org.apache.pdfbox.pdmodel.PDPage page)
|
||||
continue;
|
||||
pdStream = page.getContents();
|
||||
pdfStreamParser = new org.apache.pdfbox.pdfparser.PDFStreamParser(pdStream);
|
||||
pdfStreamParser.parse();
|
||||
tokenList = pdfStreamParser.getTokens();
|
||||
tokenIterator = tokenList.listIterator();
|
||||
for (short t = 1; i < short.MaxValue; t++)
|
||||
{
|
||||
if (!tokenIterator.hasNext())
|
||||
break;
|
||||
possibleCOSArray = tokenIterator.next();
|
||||
if (possibleCOSArray is not org.apache.pdfbox.cos.COSArray cossArray)
|
||||
continue;
|
||||
_ = stringBuilder.Clear();
|
||||
arrayList = cossArray.toList();
|
||||
arrayIterator = arrayList.listIterator();
|
||||
for (short a = 1; i < short.MaxValue; a++)
|
||||
{
|
||||
if (!arrayIterator.hasNext())
|
||||
break;
|
||||
possibleString = arrayIterator.next();
|
||||
if (possibleString is not org.apache.pdfbox.cos.COSString cossString)
|
||||
continue;
|
||||
value = cossString.getString();
|
||||
_ = stringBuilder.Append(value);
|
||||
if (value != "]")
|
||||
continue;
|
||||
updateValues.Add(value);
|
||||
value = stringBuilder.ToString();
|
||||
if (value.Contains("[]"))
|
||||
cossArray.setString(a - 1, string.Concat("*", reactorLoadLock, "]"));
|
||||
else
|
||||
cossArray.setString(a - 1, string.Concat(" {*", reactorLoadLock, "}]"));
|
||||
}
|
||||
}
|
||||
if (updateValues.Any())
|
||||
{
|
||||
updatedStream = new org.apache.pdfbox.pdmodel.common.PDStream(pdDocument);
|
||||
outputStream = updatedStream.createOutputStream();
|
||||
contentStreamWriter = new org.apache.pdfbox.pdfwriter.ContentStreamWriter(outputStream);
|
||||
contentStreamWriter.writeTokens(tokenList);
|
||||
outputStream.close();
|
||||
page.setContents(updatedStream);
|
||||
}
|
||||
}
|
||||
if (updateValues.Any())
|
||||
pdDocument.save(checkFileName);
|
||||
pdDocument.close();
|
||||
}
|
||||
|
||||
internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, DateTime dateTime, string logisticsSequenceMemoryDirectory, List<pcl.Description> descriptions, string matchDirectory)
|
||||
{
|
||||
if (fileRead is null)
|
||||
{ }
|
||||
if (dateTime == DateTime.MinValue)
|
||||
{ }
|
||||
if (logisticsSequenceMemoryDirectory is null)
|
||||
{ }
|
||||
if (descriptions is null)
|
||||
{ }
|
||||
if (matchDirectory is null)
|
||||
{ }
|
||||
string checkFileName;
|
||||
string[] pclFiles = Directory.GetFiles(matchDirectory, "*.pcl", SearchOption.TopDirectoryOnly);
|
||||
if (pclFiles.Length != 1)
|
||||
throw new Exception("Invalid source file count!");
|
||||
string sourceFileNameNoExt = Path.GetFileNameWithoutExtension(pclFiles[0]);
|
||||
string wsResultsMemoryFile = string.Concat(logisticsSequenceMemoryDirectory, @"\", nameof(WS.Results), ".json");
|
||||
if (!File.Exists(wsResultsMemoryFile))
|
||||
throw new Exception(string.Concat("Memory file <", wsResultsMemoryFile, "> doesn't exist!"));
|
||||
string json = File.ReadAllText(wsResultsMemoryFile);
|
||||
WS.Results metrologyWSRequest = JsonSerializer.Deserialize<WS.Results>(json);
|
||||
long wsResultsHeaderID = metrologyWSRequest.HeaderID;
|
||||
List<WS.Attachment> dataAttachments = new();
|
||||
List<WS.Attachment> headerAttachments = new();
|
||||
checkFileName = string.Concat(matchDirectory, @"\", sourceFileNameNoExt, "_data.pdf");
|
||||
if (!File.Exists(checkFileName))
|
||||
throw new Exception("Header file doesn't exist!");
|
||||
else
|
||||
{
|
||||
UpdateDataPDF(descriptions, checkFileName);
|
||||
headerAttachments.Add(new WS.Attachment(descriptions[0].HeaderUniqueId, "Data.pdf", checkFileName));
|
||||
}
|
||||
foreach (pcl.Description description in descriptions)
|
||||
{
|
||||
checkFileName = string.Concat(matchDirectory, @"\", sourceFileNameNoExt, "_", description.Slot.Replace('*', 's'), "_image.pdf");
|
||||
if (File.Exists(checkFileName))
|
||||
dataAttachments.Add(new WS.Attachment(description.UniqueId, "Image.pdf", checkFileName));
|
||||
checkFileName = string.Concat(matchDirectory, @"\", sourceFileNameNoExt, "_", description.Slot.Replace('*', 's'), "_data.pdf");
|
||||
if (File.Exists(checkFileName))
|
||||
dataAttachments.Add(new WS.Attachment(description.UniqueId, "Data.pdf", checkFileName));
|
||||
}
|
||||
if (dataAttachments.Count == 0 || dataAttachments.Count != descriptions.Count)
|
||||
throw new Exception("Invalid attachment count!");
|
||||
WS.AttachFiles(openInsightMetrologyViewerAPI, wsResultsHeaderID, headerAttachments, dataAttachments);
|
||||
}
|
||||
|
||||
}
|
199
Adaptation/FileHandlers/MET08DDUPSFS6420/WSRequest.cs
Normal file
199
Adaptation/FileHandlers/MET08DDUPSFS6420/WSRequest.cs
Normal file
@ -0,0 +1,199 @@
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Adaptation.FileHandlers.MET08DDUPSFS6420;
|
||||
|
||||
public class WSRequest
|
||||
{
|
||||
|
||||
public long Id { get; set; }
|
||||
public string AreaCountAvg { get; set; }
|
||||
public string AreaCountMax { get; set; }
|
||||
public string AreaCountMin { get; set; }
|
||||
public string AreaCountStdDev { get; set; }
|
||||
public string AreaTotalAvg { get; set; }
|
||||
public string AreaTotalMax { get; set; }
|
||||
public string AreaTotalMin { get; set; }
|
||||
public string AreaTotalStdDev { get; set; }
|
||||
public string Date { get; set; }
|
||||
public string HazeAverageAvg { get; set; }
|
||||
public string HazeAverageMax { get; set; }
|
||||
public string HazeAverageMin { get; set; }
|
||||
public string HazeAverageStdDev { get; set; }
|
||||
public string HazeRegionAvg { get; set; }
|
||||
public string HazeRegionMax { get; set; }
|
||||
public string HazeRegionMin { get; set; }
|
||||
public string HazeRegionStdDev { get; set; }
|
||||
public string Layer { get; set; }
|
||||
public string LotID { get; set; }
|
||||
public string LPDCM2Avg { get; set; }
|
||||
public string LPDCM2Max { get; set; }
|
||||
public string LPDCM2Min { get; set; }
|
||||
public string LPDCM2StdDev { get; set; }
|
||||
public string LPDCountAvg { get; set; }
|
||||
public string LPDCountMax { get; set; }
|
||||
public string LPDCountMin { get; set; }
|
||||
public string LPDCountStdDev { get; set; }
|
||||
public string Operator { get; set; }
|
||||
public string ParseErrorText { get; set; }
|
||||
public string PSN { get; set; }
|
||||
public string RDS { get; set; }
|
||||
public string Reactor { get; set; }
|
||||
public string Recipe { get; set; }
|
||||
public string ScratchCountAvg { get; set; }
|
||||
public string ScratchCountMax { get; set; }
|
||||
public string ScratchCountMin { get; set; }
|
||||
public string ScratchCountStdDev { get; set; }
|
||||
public string ScratchTotalAvg { get; set; }
|
||||
public string ScratchTotalMax { get; set; }
|
||||
public string ScratchTotalMin { get; set; }
|
||||
public string ScratchTotalStdDev { get; set; }
|
||||
public string SumOfDefectsAvg { get; set; }
|
||||
public string SumOfDefectsMax { get; set; }
|
||||
public string SumOfDefectsMin { get; set; }
|
||||
public string SumOfDefectsStdDev { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string UniqueId { get; set; }
|
||||
public string Zone { get; set; }
|
||||
|
||||
public string CellName { get; set; }
|
||||
public string Data { get; set; }
|
||||
public int i { get; set; }
|
||||
public List<pcl.Detail> Details { get; protected set; }
|
||||
|
||||
[Obsolete("For json")] public WSRequest() { }
|
||||
|
||||
internal WSRequest(IFileRead fileRead, Logistics logistics, List<pcl.Description> descriptions)
|
||||
{
|
||||
if (fileRead is null)
|
||||
{ }
|
||||
i = -1;
|
||||
Id = 0;
|
||||
Zone = null;
|
||||
Layer = null;
|
||||
Title = null;
|
||||
Data = "*Data*";
|
||||
Details = new List<pcl.Detail>();
|
||||
CellName = logistics.MesEntity;
|
||||
pcl.Description x = descriptions[0];
|
||||
//Header
|
||||
{
|
||||
AreaCountAvg = x.AreaCountAvg;
|
||||
AreaCountMax = x.AreaCountMax;
|
||||
AreaCountMin = x.AreaCountMin;
|
||||
AreaCountStdDev = x.AreaCountStdDev;
|
||||
AreaTotalAvg = x.AreaTotalAvg;
|
||||
AreaTotalMax = x.AreaTotalMax;
|
||||
AreaTotalMin = x.AreaTotalMin;
|
||||
AreaTotalStdDev = x.AreaTotalStdDev;
|
||||
Date = x.Date;
|
||||
HazeAverageAvg = x.HazeAverageAvg;
|
||||
HazeAverageMax = x.HazeAverageMax;
|
||||
HazeAverageMin = x.HazeAverageMin;
|
||||
HazeAverageStdDev = x.HazeAverageStdDev;
|
||||
HazeRegionAvg = x.HazeRegionAvg;
|
||||
HazeRegionMax = x.HazeRegionMax;
|
||||
HazeRegionMin = x.HazeRegionMin;
|
||||
HazeRegionStdDev = x.HazeRegionStdDev;
|
||||
LotID = x.Lot;
|
||||
LPDCM2Avg = x.LPDCM2Avg;
|
||||
LPDCM2Max = x.LPDCM2Max;
|
||||
LPDCM2Min = x.LPDCM2Min;
|
||||
LPDCM2StdDev = x.LPDCM2StdDev;
|
||||
LPDCountAvg = x.LPDCountAvg;
|
||||
LPDCountMax = x.LPDCountMax;
|
||||
LPDCountMin = x.LPDCountMin;
|
||||
LPDCountStdDev = x.LPDCountStdDev;
|
||||
ParseErrorText = x.ParseErrorText;
|
||||
PSN = x.PSN;
|
||||
RDS = x.RDS;
|
||||
Reactor = x.Reactor;
|
||||
Recipe = x.Recipe;
|
||||
ScratchCountAvg = x.ScratchCountAvg;
|
||||
ScratchCountMax = x.ScratchCountMax;
|
||||
ScratchCountMin = x.ScratchCountMin;
|
||||
ScratchCountStdDev = x.ScratchCountStdDev;
|
||||
ScratchTotalAvg = x.ScratchTotalAvg;
|
||||
ScratchTotalMax = x.ScratchTotalMax;
|
||||
ScratchTotalMin = x.ScratchTotalMin;
|
||||
ScratchTotalStdDev = x.ScratchTotalStdDev;
|
||||
SumOfDefectsAvg = x.SumOfDefectsAvg;
|
||||
SumOfDefectsMax = x.SumOfDefectsMax;
|
||||
SumOfDefectsMin = x.SumOfDefectsMin;
|
||||
SumOfDefectsStdDev = x.SumOfDefectsStdDev;
|
||||
UniqueId = x.UniqueId;
|
||||
}
|
||||
pcl.Detail detail;
|
||||
foreach (pcl.Description description in descriptions)
|
||||
{
|
||||
detail = new pcl.Detail
|
||||
{
|
||||
Data = "*Data*",
|
||||
i = -1,
|
||||
Id = 0, //item.Id,
|
||||
AreaCount = description.AreaCount,
|
||||
AreaTotal = description.AreaTotal,
|
||||
Bin1 = description.Bin1,
|
||||
Bin2 = description.Bin2,
|
||||
Bin3 = description.Bin3,
|
||||
Bin4 = description.Bin4,
|
||||
Bin5 = description.Bin5,
|
||||
Bin6 = description.Bin6,
|
||||
Bin7 = description.Bin7,
|
||||
Bin8 = description.Bin8,
|
||||
Comments = description.Comments,
|
||||
Date = description.Date,
|
||||
Diameter = description.Diameter,
|
||||
Exclusion = description.Exclusion,
|
||||
Gain = description.Gain,
|
||||
HazeAverage = description.HazeAverage,
|
||||
HazePeak = description.HazePeak,
|
||||
HazeRegion = description.HazeRegion,
|
||||
HazeRng = description.HazeRng,
|
||||
HeaderUniqueId = description.HeaderUniqueId,
|
||||
LPDCM2 = description.LPDCM2,
|
||||
LPDCount = description.LPDCount,
|
||||
Laser = description.Laser,
|
||||
Mean = description.Mean,
|
||||
Recipe = description.Recipe,
|
||||
ScratchCount = description.ScratchCount,
|
||||
ScratchTotal = description.ScratchTotal,
|
||||
Slot = description.Slot,
|
||||
Sort = description.Sort,
|
||||
StdDev = description.StdDev,
|
||||
SumOfDefects = description.SumOfDefects,
|
||||
Thresh = description.Thresh,
|
||||
Thruput = description.Thruput,
|
||||
Title = null,
|
||||
UniqueId = description.UniqueId
|
||||
};
|
||||
Details.Add(detail);
|
||||
}
|
||||
Date = logistics.DateTimeFromSequence.ToString();
|
||||
if (UniqueId is null && Details.Any())
|
||||
UniqueId = Details[0].HeaderUniqueId;
|
||||
for (int i = 0; i < Details.Count; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Details[i].Bin1))
|
||||
Details[i].Bin1 = null;
|
||||
if (string.IsNullOrEmpty(Details[i].Bin2))
|
||||
Details[i].Bin2 = null;
|
||||
if (string.IsNullOrEmpty(Details[i].Bin3))
|
||||
Details[i].Bin3 = null;
|
||||
if (string.IsNullOrEmpty(Details[i].Bin4))
|
||||
Details[i].Bin4 = null;
|
||||
if (string.IsNullOrEmpty(Details[i].Bin5))
|
||||
Details[i].Bin5 = null;
|
||||
if (string.IsNullOrEmpty(Details[i].Bin6))
|
||||
Details[i].Bin6 = null;
|
||||
if (string.IsNullOrEmpty(Details[i].Bin7))
|
||||
Details[i].Bin7 = null;
|
||||
if (string.IsNullOrEmpty(Details[i].Bin8))
|
||||
Details[i].Bin8 = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
145
Adaptation/FileHandlers/ManualOIEntry/FileRead.cs
Normal file
145
Adaptation/FileHandlers/ManualOIEntry/FileRead.cs
Normal file
@ -0,0 +1,145 @@
|
||||
using Adaptation.Eaf.Management.ConfigurationData.CellAutomation;
|
||||
using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration;
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Duplicator;
|
||||
using Adaptation.Shared.Methods;
|
||||
using Infineon.Monitoring.MonA;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Adaptation.FileHandlers.IsManualOIEntry;
|
||||
|
||||
public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
|
||||
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(), false, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted)
|
||||
{
|
||||
_MinFileLength = 10;
|
||||
_NullData = string.Empty;
|
||||
_Logistics = new Logistics(this);
|
||||
if (_FileParameter is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (_ModelObjectParameterDefinitions is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (!_IsDuplicator)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
}
|
||||
|
||||
void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception)
|
||||
{
|
||||
bool isErrorFile = exception is not null;
|
||||
if (!isErrorFile && !string.IsNullOrEmpty(_Logistics.ReportFullPath))
|
||||
{
|
||||
FileInfo fileInfo = new(_Logistics.ReportFullPath);
|
||||
if (fileInfo.Exists && fileInfo.LastWriteTime < fileInfo.CreationTime)
|
||||
File.SetLastWriteTime(_Logistics.ReportFullPath, fileInfo.CreationTime);
|
||||
}
|
||||
Move(extractResults, exception);
|
||||
}
|
||||
|
||||
void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null);
|
||||
|
||||
string IFileRead.GetEventDescription()
|
||||
{
|
||||
string result = _Description.GetEventDescription();
|
||||
return result;
|
||||
}
|
||||
|
||||
List<string> IFileRead.GetHeaderNames()
|
||||
{
|
||||
List<string> results = _Description.GetHeaderNames();
|
||||
return results;
|
||||
}
|
||||
|
||||
string[] IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, string to, string from, string resolvedFileLocation, Exception exception)
|
||||
{
|
||||
string[] results = Move(extractResults, to, from, resolvedFileLocation, exception);
|
||||
return results;
|
||||
}
|
||||
|
||||
JsonProperty[] IFileRead.GetDefault()
|
||||
{
|
||||
JsonProperty[] results = _Description.GetDefault(this, _Logistics);
|
||||
return results;
|
||||
}
|
||||
|
||||
Dictionary<string, string> IFileRead.GetDisplayNamesJsonElement()
|
||||
{
|
||||
Dictionary<string, string> results = _Description.GetDisplayNamesJsonElement(this);
|
||||
return results;
|
||||
}
|
||||
|
||||
List<IDescription> IFileRead.GetDescriptions(IFileRead fileRead, List<Test> tests, IProcessData processData)
|
||||
{
|
||||
List<IDescription> results = _Description.GetDescriptions(fileRead, _Logistics, tests, processData);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.GetExtractResult(string reportFullPath, string eventName)
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
if (string.IsNullOrEmpty(eventName))
|
||||
throw new Exception();
|
||||
_ReportFullPath = reportFullPath;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
results = GetExtractResult(reportFullPath, dateTime);
|
||||
if (results.Item3 is null)
|
||||
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(results.Item1, Array.Empty<Test>(), JsonSerializer.Deserialize<JsonElement[]>("[]"), results.Item4);
|
||||
if (results.Item3.Length > 0 && _IsEAFHosted)
|
||||
WritePDSF(this, results.Item3);
|
||||
UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.ReExtract()
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
List<string> headerNames = _Description.GetHeaderNames();
|
||||
Dictionary<string, string> keyValuePairs = _Description.GetDisplayNamesJsonElement(this);
|
||||
results = ReExtract(this, headerNames, keyValuePairs);
|
||||
return results;
|
||||
}
|
||||
|
||||
void IFileRead.CheckTests(Test[] tests, bool extra)
|
||||
{
|
||||
if (_Description is not Description)
|
||||
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>());
|
||||
string monARessource;
|
||||
const string site = "sjc";
|
||||
string equipment = string.Empty;
|
||||
string description = string.Empty;
|
||||
string stateName = "MANUAL_OI_ENTRY";
|
||||
string json = File.ReadAllText(reportFullPath);
|
||||
JsonElement jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
|
||||
foreach (JsonProperty jsonProperty in jsonElement.EnumerateObject())
|
||||
{
|
||||
if (jsonProperty.Name == "Equipment")
|
||||
equipment = jsonProperty.Value.ToString();
|
||||
else if (jsonProperty.Name == "Description")
|
||||
description = jsonProperty.Value.ToString();
|
||||
}
|
||||
if (string.IsNullOrEmpty(equipment))
|
||||
monARessource = _CellInstanceName;
|
||||
else
|
||||
monARessource = equipment;
|
||||
const string monInURL = "http://moninhttp.sjc.infineon.com/input/text";
|
||||
MonIn monIn = MonIn.GetInstance(monInURL);
|
||||
if (_IsEAFHosted)
|
||||
_ = monIn.SendStatus(site, monARessource, stateName, State.Warning, description);
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
140
Adaptation/FileHandlers/ToArchive/FileRead.cs
Normal file
140
Adaptation/FileHandlers/ToArchive/FileRead.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using Adaptation.Eaf.Management.ConfigurationData.CellAutomation;
|
||||
using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration;
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Duplicator;
|
||||
using Adaptation.Shared.Methods;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Adaptation.FileHandlers.ToArchive;
|
||||
|
||||
public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
|
||||
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(), false, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted)
|
||||
{
|
||||
_MinFileLength = 10;
|
||||
_NullData = string.Empty;
|
||||
_Logistics = new Logistics(this);
|
||||
if (_FileParameter is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (_ModelObjectParameterDefinitions is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (!_IsDuplicator)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
}
|
||||
|
||||
void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception)
|
||||
{
|
||||
bool isErrorFile = exception is not null;
|
||||
if (!isErrorFile && !string.IsNullOrEmpty(_Logistics.ReportFullPath))
|
||||
{
|
||||
FileInfo fileInfo = new(_Logistics.ReportFullPath);
|
||||
if (fileInfo.Exists && fileInfo.LastWriteTime < fileInfo.CreationTime)
|
||||
File.SetLastWriteTime(_Logistics.ReportFullPath, fileInfo.CreationTime);
|
||||
}
|
||||
Move(extractResults, exception);
|
||||
}
|
||||
|
||||
void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null);
|
||||
|
||||
string IFileRead.GetEventDescription()
|
||||
{
|
||||
string result = _Description.GetEventDescription();
|
||||
return result;
|
||||
}
|
||||
|
||||
List<string> IFileRead.GetHeaderNames()
|
||||
{
|
||||
List<string> results = _Description.GetHeaderNames();
|
||||
return results;
|
||||
}
|
||||
|
||||
string[] IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, string to, string from, string resolvedFileLocation, Exception exception)
|
||||
{
|
||||
string[] results = Move(extractResults, to, from, resolvedFileLocation, exception);
|
||||
return results;
|
||||
}
|
||||
|
||||
JsonProperty[] IFileRead.GetDefault()
|
||||
{
|
||||
JsonProperty[] results = _Description.GetDefault(this, _Logistics);
|
||||
return results;
|
||||
}
|
||||
|
||||
Dictionary<string, string> IFileRead.GetDisplayNamesJsonElement()
|
||||
{
|
||||
Dictionary<string, string> results = _Description.GetDisplayNamesJsonElement(this);
|
||||
return results;
|
||||
}
|
||||
|
||||
List<IDescription> IFileRead.GetDescriptions(IFileRead fileRead, List<Test> tests, IProcessData processData)
|
||||
{
|
||||
List<IDescription> results = _Description.GetDescriptions(fileRead, _Logistics, tests, processData);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.GetExtractResult(string reportFullPath, string eventName)
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
if (string.IsNullOrEmpty(eventName))
|
||||
throw new Exception();
|
||||
_ReportFullPath = reportFullPath;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
results = GetExtractResult(reportFullPath, dateTime);
|
||||
if (results.Item3 is null)
|
||||
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(results.Item1, Array.Empty<Test>(), JsonSerializer.Deserialize<JsonElement[]>("[]"), results.Item4);
|
||||
if (results.Item3.Length > 0 && _IsEAFHosted)
|
||||
WritePDSF(this, results.Item3);
|
||||
UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.ReExtract()
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
List<string> headerNames = _Description.GetHeaderNames();
|
||||
Dictionary<string, string> keyValuePairs = _Description.GetDisplayNamesJsonElement(this);
|
||||
results = ReExtract(this, headerNames, keyValuePairs);
|
||||
return results;
|
||||
}
|
||||
|
||||
void IFileRead.CheckTests(Test[] tests, bool extra)
|
||||
{
|
||||
if (_Description is not Description)
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
499
Adaptation/FileHandlers/pcl/Description.cs
Normal file
499
Adaptation/FileHandlers/pcl/Description.cs
Normal file
@ -0,0 +1,499 @@
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Methods;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Adaptation.FileHandlers.pcl;
|
||||
|
||||
public class Description : IDescription, Shared.Properties.IDescription
|
||||
{
|
||||
|
||||
public int Test { get; set; }
|
||||
public int Count { get; set; }
|
||||
public int Index { get; set; }
|
||||
//
|
||||
public string EventName { get; set; }
|
||||
public string NullData { get; set; }
|
||||
public string JobID { get; set; }
|
||||
public string Sequence { get; set; }
|
||||
public string MesEntity { get; set; }
|
||||
public string ReportFullPath { get; set; }
|
||||
public string ProcessJobID { get; set; }
|
||||
public string MID { get; set; }
|
||||
//
|
||||
public string Date { get; set; }
|
||||
public string Employee { get; set; }
|
||||
public string Lot { get; set; }
|
||||
public string PSN { get; set; }
|
||||
public string Reactor { get; set; }
|
||||
public string Recipe { get; set; }
|
||||
//
|
||||
public string Comments { get; set; }
|
||||
public string Diameter { get; set; }
|
||||
public string Exclusion { get; set; }
|
||||
public string Gain { get; set; }
|
||||
public string HeaderUniqueId { get; set; }
|
||||
public string Laser { get; set; }
|
||||
public string ParseErrorText { get; set; }
|
||||
public string RDS { get; set; }
|
||||
public string Slot { get; set; }
|
||||
public string UniqueId { get; set; }
|
||||
//
|
||||
public string AreaCount { get; set; }
|
||||
public string AreaCountAvg { get; set; }
|
||||
public string AreaCountMax { get; set; }
|
||||
public string AreaCountMin { get; set; }
|
||||
public string AreaCountStdDev { get; set; }
|
||||
public string AreaTotal { get; set; }
|
||||
public string AreaTotalAvg { get; set; }
|
||||
public string AreaTotalMax { get; set; }
|
||||
public string AreaTotalMin { get; set; }
|
||||
public string AreaTotalStdDev { get; set; }
|
||||
public string Bin1 { get; set; }
|
||||
public string Bin2 { get; set; }
|
||||
public string Bin3 { get; set; }
|
||||
public string Bin4 { get; set; }
|
||||
public string Bin5 { get; set; }
|
||||
public string Bin6 { get; set; }
|
||||
public string Bin7 { get; set; }
|
||||
public string Bin8 { get; set; }
|
||||
public string HazeAverage { get; set; }
|
||||
public string HazeAverageAvg { get; set; }
|
||||
public string HazeAverageMax { get; set; }
|
||||
public string HazeAverageMin { get; set; }
|
||||
public string HazeAverageStdDev { get; set; }
|
||||
public string HazePeak { get; set; }
|
||||
public string HazeRegion { get; set; }
|
||||
public string HazeRegionAvg { get; set; }
|
||||
public string HazeRegionMax { get; set; }
|
||||
public string HazeRegionMin { get; set; }
|
||||
public string HazeRegionStdDev { get; set; }
|
||||
public string HazeRng { get; set; }
|
||||
public string LPDCM2 { get; set; }
|
||||
public string LPDCM2Avg { get; set; }
|
||||
public string LPDCM2Max { get; set; }
|
||||
public string LPDCM2Min { get; set; }
|
||||
public string LPDCM2StdDev { get; set; }
|
||||
public string LPDCount { get; set; }
|
||||
public string LPDCountAvg { get; set; }
|
||||
public string LPDCountMax { get; set; }
|
||||
public string LPDCountMin { get; set; }
|
||||
public string LPDCountStdDev { get; set; }
|
||||
public string Mean { get; set; }
|
||||
public string ScratchCount { get; set; }
|
||||
public string ScratchCountAvg { get; set; }
|
||||
public string ScratchCountMax { get; set; }
|
||||
public string ScratchCountMin { get; set; }
|
||||
public string ScratchCountStdDev { get; set; }
|
||||
public string ScratchTotal { get; set; }
|
||||
public string ScratchTotalAvg { get; set; }
|
||||
public string ScratchTotalMax { get; set; }
|
||||
public string ScratchTotalMin { get; set; }
|
||||
public string ScratchTotalStdDev { get; set; }
|
||||
public string Sort { get; set; }
|
||||
public string StdDev { get; set; }
|
||||
public string SumOfDefects { get; set; }
|
||||
public string SumOfDefectsAvg { get; set; }
|
||||
public string SumOfDefectsMax { get; set; }
|
||||
public string SumOfDefectsMin { get; set; }
|
||||
public string SumOfDefectsStdDev { get; set; }
|
||||
public string Thresh { get; set; }
|
||||
public string Thruput { get; set; }
|
||||
//
|
||||
public object Data { get; set; }
|
||||
public object Parameters { get; set; }
|
||||
|
||||
string IDescription.GetEventDescription() => "File Has been read and parsed";
|
||||
|
||||
List<string> IDescription.GetNames(IFileRead fileRead, Logistics logistics)
|
||||
{
|
||||
List<string> results = new();
|
||||
IDescription description = GetDefault(fileRead, logistics);
|
||||
string json = JsonSerializer.Serialize(description, description.GetType());
|
||||
object @object = JsonSerializer.Deserialize<object>(json);
|
||||
if (@object is not JsonElement jsonElement)
|
||||
throw new Exception();
|
||||
foreach (JsonProperty jsonProperty in jsonElement.EnumerateObject())
|
||||
results.Add(jsonProperty.Name);
|
||||
return results;
|
||||
}
|
||||
|
||||
List<string> IDescription.GetDetailNames()
|
||||
{
|
||||
List<string> results = new()
|
||||
{
|
||||
nameof(Comments),
|
||||
nameof(Diameter),
|
||||
nameof(Exclusion),
|
||||
nameof(Gain),
|
||||
nameof(HeaderUniqueId),
|
||||
nameof(Laser),
|
||||
nameof(ParseErrorText),
|
||||
nameof(RDS),
|
||||
nameof(Slot),
|
||||
nameof(UniqueId)
|
||||
};
|
||||
return results;
|
||||
}
|
||||
|
||||
List<string> IDescription.GetHeaderNames()
|
||||
{
|
||||
List<string> results = new()
|
||||
{
|
||||
nameof(Date),
|
||||
nameof(Employee),
|
||||
nameof(Lot),
|
||||
nameof(PSN),
|
||||
nameof(Reactor),
|
||||
nameof(Recipe)
|
||||
};
|
||||
return results;
|
||||
}
|
||||
|
||||
IDescription IDescription.GetDisplayNames()
|
||||
{
|
||||
Description result = GetDisplayNames();
|
||||
return result;
|
||||
}
|
||||
|
||||
List<string> IDescription.GetParameterNames()
|
||||
{
|
||||
List<string> results = new()
|
||||
{
|
||||
nameof(AreaCount),
|
||||
nameof(AreaCountAvg),
|
||||
nameof(AreaCountMax),
|
||||
nameof(AreaCountMin),
|
||||
nameof(AreaCountStdDev),
|
||||
nameof(AreaTotal),
|
||||
nameof(AreaTotalAvg),
|
||||
nameof(AreaTotalMax),
|
||||
nameof(AreaTotalMin),
|
||||
nameof(AreaTotalStdDev),
|
||||
nameof(Bin1),
|
||||
nameof(Bin2),
|
||||
nameof(Bin3),
|
||||
nameof(Bin4),
|
||||
nameof(Bin5),
|
||||
nameof(Bin6),
|
||||
nameof(Bin7),
|
||||
nameof(Bin8),
|
||||
nameof(HazeAverage),
|
||||
nameof(HazeAverageAvg),
|
||||
nameof(HazeAverageMax),
|
||||
nameof(HazeAverageMin),
|
||||
nameof(HazeAverageStdDev),
|
||||
nameof(HazePeak),
|
||||
nameof(HazeRegion),
|
||||
nameof(HazeRegionAvg),
|
||||
nameof(HazeRegionMax),
|
||||
nameof(HazeRegionMin),
|
||||
nameof(HazeRegionStdDev),
|
||||
nameof(HazeRng),
|
||||
nameof(LPDCM2),
|
||||
nameof(LPDCM2Avg),
|
||||
nameof(LPDCM2Max),
|
||||
nameof(LPDCM2Min),
|
||||
nameof(LPDCM2StdDev),
|
||||
nameof(LPDCount),
|
||||
nameof(LPDCountAvg),
|
||||
nameof(LPDCountMax),
|
||||
nameof(LPDCountMin),
|
||||
nameof(LPDCountStdDev),
|
||||
nameof(Mean),
|
||||
nameof(ScratchCount),
|
||||
nameof(ScratchCountAvg),
|
||||
nameof(ScratchCountMax),
|
||||
nameof(ScratchCountMin),
|
||||
nameof(ScratchCountStdDev),
|
||||
nameof(ScratchTotal),
|
||||
nameof(ScratchTotalAvg),
|
||||
nameof(ScratchTotalMax),
|
||||
nameof(ScratchTotalMin),
|
||||
nameof(ScratchTotalStdDev),
|
||||
nameof(Sort),
|
||||
nameof(StdDev),
|
||||
nameof(SumOfDefects),
|
||||
nameof(SumOfDefectsAvg),
|
||||
nameof(SumOfDefectsMax),
|
||||
nameof(SumOfDefectsMin),
|
||||
nameof(SumOfDefectsStdDev),
|
||||
nameof(Thresh),
|
||||
nameof(Thruput)
|
||||
};
|
||||
return results;
|
||||
}
|
||||
|
||||
JsonProperty[] IDescription.GetDefault(IFileRead fileRead, Logistics logistics)
|
||||
{
|
||||
JsonProperty[] results;
|
||||
IDescription description = GetDefault(fileRead, logistics);
|
||||
string json = JsonSerializer.Serialize(description, description.GetType());
|
||||
object @object = JsonSerializer.Deserialize<object>(json);
|
||||
results = ((JsonElement)@object).EnumerateObject().ToArray();
|
||||
return results;
|
||||
}
|
||||
|
||||
List<string> IDescription.GetPairedParameterNames()
|
||||
{
|
||||
List<string> results = new();
|
||||
return results;
|
||||
}
|
||||
|
||||
List<string> IDescription.GetIgnoreParameterNames(Test test)
|
||||
{
|
||||
List<string> results = new();
|
||||
return results;
|
||||
}
|
||||
|
||||
IDescription IDescription.GetDefaultDescription(IFileRead fileRead, Logistics logistics)
|
||||
{
|
||||
Description result = GetDefault(fileRead, logistics);
|
||||
return result;
|
||||
}
|
||||
|
||||
Dictionary<string, string> IDescription.GetDisplayNamesJsonElement(IFileRead fileRead)
|
||||
{
|
||||
Dictionary<string, string> results = new();
|
||||
IDescription description = GetDisplayNames();
|
||||
string json = JsonSerializer.Serialize(description, description.GetType());
|
||||
JsonElement jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
|
||||
foreach (JsonProperty jsonProperty in jsonElement.EnumerateObject())
|
||||
{
|
||||
if (!results.ContainsKey(jsonProperty.Name))
|
||||
results.Add(jsonProperty.Name, string.Empty);
|
||||
if (jsonProperty.Value is JsonElement jsonPropertyValue)
|
||||
results[jsonProperty.Name] = jsonPropertyValue.ToString();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
List<IDescription> IDescription.GetDescriptions(IFileRead fileRead, Logistics logistics, List<Test> tests, IProcessData iProcessData)
|
||||
{
|
||||
List<IDescription> results = new();
|
||||
if (iProcessData is null || !iProcessData.Details.Any() || iProcessData is not ProcessData processData)
|
||||
results.Add(GetDefault(fileRead, logistics));
|
||||
else
|
||||
{
|
||||
string nullData;
|
||||
Description description;
|
||||
object configDataNullData = fileRead.NullData;
|
||||
if (configDataNullData is null)
|
||||
nullData = string.Empty;
|
||||
else
|
||||
nullData = configDataNullData.ToString();
|
||||
for (int i = 0; i < iProcessData.Details.Count; i++)
|
||||
{
|
||||
if (iProcessData.Details[i] is not Detail detail)
|
||||
continue;
|
||||
description = new Description
|
||||
{
|
||||
Test = (int)tests[i],
|
||||
Count = tests.Count,
|
||||
Index = i,
|
||||
//
|
||||
EventName = fileRead.EventName,
|
||||
NullData = nullData,
|
||||
JobID = fileRead.CellInstanceName,
|
||||
Sequence = logistics.Sequence.ToString(),
|
||||
MesEntity = logistics.MesEntity,
|
||||
ReportFullPath = logistics.ReportFullPath,
|
||||
ProcessJobID = logistics.ProcessJobID,
|
||||
MID = logistics.MID,
|
||||
//
|
||||
Date = processData.Date,
|
||||
Employee = processData.PSN,
|
||||
Lot = processData.Lot,
|
||||
PSN = processData.PSN,
|
||||
Reactor = processData.Reactor,
|
||||
Recipe = processData.Recipe,
|
||||
//
|
||||
Comments = detail.Comments,
|
||||
Diameter = detail.Diameter,
|
||||
Exclusion = detail.Exclusion,
|
||||
Gain = detail.Gain,
|
||||
HeaderUniqueId = detail.UniqueId,
|
||||
Laser = detail.Laser,
|
||||
ParseErrorText = processData.ParseErrorText,
|
||||
RDS = processData.RDS,
|
||||
Slot = detail.Slot,
|
||||
UniqueId = detail.UniqueId,
|
||||
//
|
||||
AreaCount = detail.AreaCount,
|
||||
AreaCountAvg = processData.AreaCountAvg,
|
||||
AreaCountMax = processData.AreaCountMax,
|
||||
AreaCountMin = processData.AreaCountMin,
|
||||
AreaCountStdDev = processData.AreaCountStdDev,
|
||||
AreaTotal = detail.AreaTotal,
|
||||
AreaTotalAvg = processData.AreaTotalAvg,
|
||||
AreaTotalMax = processData.AreaTotalMax,
|
||||
AreaTotalMin = processData.AreaTotalMin,
|
||||
AreaTotalStdDev = processData.AreaTotalStdDev,
|
||||
Bin1 = detail.Bin1,
|
||||
Bin2 = detail.Bin2,
|
||||
Bin3 = detail.Bin3,
|
||||
Bin4 = detail.Bin4,
|
||||
Bin5 = detail.Bin5,
|
||||
Bin6 = detail.Bin6,
|
||||
Bin7 = detail.Bin7,
|
||||
Bin8 = detail.Bin8,
|
||||
HazeAverage = detail.HazeAverage,
|
||||
HazeAverageAvg = processData.HazeAverageAvg,
|
||||
HazeAverageMax = processData.HazeAverageMax,
|
||||
HazeAverageMin = processData.HazeAverageMin,
|
||||
HazeAverageStdDev = processData.HazeAverageStdDev,
|
||||
HazePeak = detail.HazePeak,
|
||||
HazeRegion = detail.HazeRegion,
|
||||
HazeRegionAvg = processData.HazeRegionAvg,
|
||||
HazeRegionMax = processData.HazeRegionMax,
|
||||
HazeRegionMin = processData.HazeRegionMin,
|
||||
HazeRegionStdDev = processData.HazeRegionStdDev,
|
||||
HazeRng = detail.HazeRng,
|
||||
LPDCM2 = detail.LPDCM2,
|
||||
LPDCM2Avg = processData.LPDCM2Avg,
|
||||
LPDCM2Max = processData.LPDCM2Max,
|
||||
LPDCM2Min = processData.LPDCM2Min,
|
||||
LPDCM2StdDev = processData.LPDCM2StdDev,
|
||||
LPDCount = detail.LPDCount,
|
||||
LPDCountAvg = processData.LPDCountAvg,
|
||||
LPDCountMax = processData.LPDCountMax,
|
||||
LPDCountMin = processData.LPDCountMin,
|
||||
LPDCountStdDev = processData.LPDCountStdDev,
|
||||
Mean = detail.Mean,
|
||||
ScratchCount = detail.ScratchCount,
|
||||
ScratchCountAvg = processData.ScratchCountAvg,
|
||||
ScratchCountMax = processData.ScratchCountMax,
|
||||
ScratchCountMin = processData.ScratchCountMin,
|
||||
ScratchCountStdDev = processData.ScratchCountStdDev,
|
||||
ScratchTotal = detail.ScratchTotal,
|
||||
ScratchTotalAvg = processData.ScratchTotalAvg,
|
||||
ScratchTotalMax = processData.ScratchTotalMax,
|
||||
ScratchTotalMin = processData.ScratchTotalMin,
|
||||
ScratchTotalStdDev = processData.ScratchTotalStdDev,
|
||||
Sort = detail.Sort,
|
||||
StdDev = detail.StdDev,
|
||||
SumOfDefects = detail.SumOfDefects,
|
||||
SumOfDefectsAvg = processData.SumOfDefectsAvg,
|
||||
SumOfDefectsMax = processData.SumOfDefectsMax,
|
||||
SumOfDefectsMin = processData.SumOfDefectsMin,
|
||||
SumOfDefectsStdDev = processData.SumOfDefectsStdDev,
|
||||
Thresh = detail.Thresh,
|
||||
Thruput = detail.Thruput
|
||||
};
|
||||
results.Add(description);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static Description GetDisplayNames()
|
||||
{
|
||||
Description result = new();
|
||||
return result;
|
||||
}
|
||||
|
||||
private Description GetDefault(IFileRead fileRead, Logistics logistics)
|
||||
{
|
||||
Description result = new()
|
||||
{
|
||||
Test = -1,
|
||||
Count = 0,
|
||||
Index = -1,
|
||||
//
|
||||
EventName = fileRead.EventName,
|
||||
NullData = fileRead.NullData,
|
||||
JobID = fileRead.CellInstanceName,
|
||||
Sequence = logistics.Sequence.ToString(),
|
||||
MesEntity = fileRead.MesEntity,
|
||||
ReportFullPath = logistics.ReportFullPath,
|
||||
ProcessJobID = logistics.ProcessJobID,
|
||||
MID = logistics.MID,
|
||||
//
|
||||
Date = nameof(Date),
|
||||
Employee = nameof(Employee),
|
||||
Lot = nameof(Lot),
|
||||
PSN = nameof(PSN),
|
||||
Reactor = nameof(Reactor),
|
||||
Recipe = nameof(Recipe),
|
||||
//
|
||||
Comments = nameof(Comments),
|
||||
Diameter = nameof(Diameter),
|
||||
Exclusion = nameof(Exclusion),
|
||||
Gain = nameof(Gain),
|
||||
HeaderUniqueId = nameof(HeaderUniqueId),
|
||||
Laser = nameof(Laser),
|
||||
ParseErrorText = nameof(ParseErrorText),
|
||||
RDS = nameof(RDS),
|
||||
Slot = nameof(Slot),
|
||||
UniqueId = nameof(UniqueId),
|
||||
//
|
||||
AreaCount = nameof(AreaCount),
|
||||
AreaCountAvg = nameof(AreaCountAvg),
|
||||
AreaCountMax = nameof(AreaCountMax),
|
||||
AreaCountMin = nameof(AreaCountMin),
|
||||
AreaCountStdDev = nameof(AreaCountStdDev),
|
||||
AreaTotal = nameof(AreaTotal),
|
||||
AreaTotalAvg = nameof(AreaTotalAvg),
|
||||
AreaTotalMax = nameof(AreaTotalMax),
|
||||
AreaTotalMin = nameof(AreaTotalMin),
|
||||
AreaTotalStdDev = nameof(AreaTotalStdDev),
|
||||
Bin1 = nameof(Bin1),
|
||||
Bin2 = nameof(Bin2),
|
||||
Bin3 = nameof(Bin3),
|
||||
Bin4 = nameof(Bin4),
|
||||
Bin5 = nameof(Bin5),
|
||||
Bin6 = nameof(Bin6),
|
||||
Bin7 = nameof(Bin7),
|
||||
Bin8 = nameof(Bin8),
|
||||
HazeAverage = nameof(HazeAverage),
|
||||
HazeAverageAvg = nameof(HazeAverageAvg),
|
||||
HazeAverageMax = nameof(HazeAverageMax),
|
||||
HazeAverageMin = nameof(HazeAverageMin),
|
||||
HazeAverageStdDev = nameof(HazeAverageStdDev),
|
||||
HazePeak = nameof(HazePeak),
|
||||
HazeRegion = nameof(HazeRegion),
|
||||
HazeRegionAvg = nameof(HazeRegionAvg),
|
||||
HazeRegionMax = nameof(HazeRegionMax),
|
||||
HazeRegionMin = nameof(HazeRegionMin),
|
||||
HazeRegionStdDev = nameof(HazeRegionStdDev),
|
||||
HazeRng = nameof(HazeRng),
|
||||
LPDCM2 = nameof(LPDCM2),
|
||||
LPDCM2Avg = nameof(LPDCM2Avg),
|
||||
LPDCM2Max = nameof(LPDCM2Max),
|
||||
LPDCM2Min = nameof(LPDCM2Min),
|
||||
LPDCM2StdDev = nameof(LPDCM2StdDev),
|
||||
LPDCount = nameof(LPDCount),
|
||||
LPDCountAvg = nameof(LPDCountAvg),
|
||||
LPDCountMax = nameof(LPDCountMax),
|
||||
LPDCountMin = nameof(LPDCountMin),
|
||||
LPDCountStdDev = nameof(LPDCountStdDev),
|
||||
Mean = nameof(Mean),
|
||||
ScratchCount = nameof(ScratchCount),
|
||||
ScratchCountAvg = nameof(ScratchCountAvg),
|
||||
ScratchCountMax = nameof(ScratchCountMax),
|
||||
ScratchCountMin = nameof(ScratchCountMin),
|
||||
ScratchCountStdDev = nameof(ScratchCountStdDev),
|
||||
ScratchTotal = nameof(ScratchTotal),
|
||||
ScratchTotalAvg = nameof(ScratchTotalAvg),
|
||||
ScratchTotalMax = nameof(ScratchTotalMax),
|
||||
ScratchTotalMin = nameof(ScratchTotalMin),
|
||||
ScratchTotalStdDev = nameof(ScratchTotalStdDev),
|
||||
Sort = nameof(Sort),
|
||||
StdDev = nameof(StdDev),
|
||||
SumOfDefects = nameof(SumOfDefects),
|
||||
SumOfDefectsAvg = nameof(SumOfDefectsAvg),
|
||||
SumOfDefectsMax = nameof(SumOfDefectsMax),
|
||||
SumOfDefectsMin = nameof(SumOfDefectsMin),
|
||||
SumOfDefectsStdDev = nameof(SumOfDefectsStdDev),
|
||||
Thresh = nameof(Thresh),
|
||||
Thruput = nameof(Thruput),
|
||||
//
|
||||
Data = nameof(Data),
|
||||
Parameters = nameof(Parameters)
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
45
Adaptation/FileHandlers/pcl/Detail.cs
Normal file
45
Adaptation/FileHandlers/pcl/Detail.cs
Normal file
@ -0,0 +1,45 @@
|
||||
namespace Adaptation.FileHandlers.pcl;
|
||||
|
||||
public class Detail
|
||||
{
|
||||
|
||||
public long Id { get; set; }
|
||||
public string AreaCount { get; set; }
|
||||
public string AreaTotal { get; set; }
|
||||
public string Bin1 { get; set; }
|
||||
public string Bin2 { get; set; }
|
||||
public string Bin3 { get; set; }
|
||||
public string Bin4 { get; set; }
|
||||
public string Bin5 { get; set; }
|
||||
public string Bin6 { get; set; }
|
||||
public string Bin7 { get; set; }
|
||||
public string Bin8 { get; set; }
|
||||
public string Comments { get; set; }
|
||||
public string Date { get; set; }
|
||||
public string Diameter { get; set; }
|
||||
public string Exclusion { get; set; }
|
||||
public string Gain { get; set; }
|
||||
public string HazeAverage { get; set; }
|
||||
public string HazePeak { get; set; }
|
||||
public string HazeRegion { get; set; }
|
||||
public string HazeRng { get; set; }
|
||||
public string HeaderUniqueId { get; set; }
|
||||
public string LPDCM2 { get; set; }
|
||||
public string LPDCount { get; set; }
|
||||
public string Laser { get; set; }
|
||||
public string Mean { get; set; }
|
||||
public string Recipe { get; set; }
|
||||
public string ScratchCount { get; set; }
|
||||
public string ScratchTotal { get; set; }
|
||||
public string Slot { get; set; }
|
||||
public string Sort { get; set; }
|
||||
public string StdDev { get; set; }
|
||||
public string SumOfDefects { get; set; }
|
||||
public string Thresh { get; set; }
|
||||
public string Thruput { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string UniqueId { get; set; }
|
||||
public string Data { get; set; }
|
||||
public int i { get; set; }
|
||||
|
||||
}
|
131
Adaptation/FileHandlers/pcl/FileRead.cs
Normal file
131
Adaptation/FileHandlers/pcl/FileRead.cs
Normal file
@ -0,0 +1,131 @@
|
||||
using Adaptation.Eaf.Management.ConfigurationData.CellAutomation;
|
||||
using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration;
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Methods;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Adaptation.FileHandlers.pcl;
|
||||
|
||||
public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
|
||||
private readonly string _GhostPCLFileName;
|
||||
|
||||
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)
|
||||
{
|
||||
_MinFileLength = 10;
|
||||
_NullData = string.Empty;
|
||||
_Logistics = new Logistics(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");
|
||||
if (_IsEAFHosted && !File.Exists(_GhostPCLFileName))
|
||||
throw new Exception("Ghost PCL FileName doesn't Exist!");
|
||||
}
|
||||
|
||||
void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) => Move(extractResults, exception);
|
||||
|
||||
void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null);
|
||||
|
||||
string IFileRead.GetEventDescription()
|
||||
{
|
||||
string result = _Description.GetEventDescription();
|
||||
return result;
|
||||
}
|
||||
|
||||
List<string> IFileRead.GetHeaderNames()
|
||||
{
|
||||
List<string> results = _Description.GetHeaderNames();
|
||||
return results;
|
||||
}
|
||||
|
||||
string[] IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, string to, string from, string resolvedFileLocation, Exception exception)
|
||||
{
|
||||
string[] results = Move(extractResults, to, from, resolvedFileLocation, exception);
|
||||
return results;
|
||||
}
|
||||
|
||||
JsonProperty[] IFileRead.GetDefault()
|
||||
{
|
||||
JsonProperty[] results = _Description.GetDefault(this, _Logistics);
|
||||
return results;
|
||||
}
|
||||
|
||||
Dictionary<string, string> IFileRead.GetDisplayNamesJsonElement()
|
||||
{
|
||||
Dictionary<string, string> results = _Description.GetDisplayNamesJsonElement(this);
|
||||
return results;
|
||||
}
|
||||
|
||||
List<IDescription> IFileRead.GetDescriptions(IFileRead fileRead, List<Test> tests, IProcessData processData)
|
||||
{
|
||||
List<IDescription> results = _Description.GetDescriptions(fileRead, _Logistics, tests, processData);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.GetExtractResult(string reportFullPath, string eventName)
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
if (string.IsNullOrEmpty(eventName))
|
||||
throw new Exception();
|
||||
_ReportFullPath = reportFullPath;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
results = GetExtractResult(reportFullPath, dateTime);
|
||||
if (results.Item3 is null)
|
||||
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(results.Item1, Array.Empty<Test>(), JsonSerializer.Deserialize<JsonElement[]>("[]"), results.Item4);
|
||||
if (results.Item3.Length > 0 && _IsEAFHosted)
|
||||
WritePDSF(this, results.Item3);
|
||||
UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.ReExtract()
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
List<string> headerNames = _Description.GetHeaderNames();
|
||||
Dictionary<string, string> keyValuePairs = _Description.GetDisplayNamesJsonElement(this);
|
||||
results = ReExtract(this, headerNames, keyValuePairs);
|
||||
return results;
|
||||
}
|
||||
|
||||
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>());
|
||||
_Logistics = new Logistics(this, reportFullPath, useSplitForMID: true);
|
||||
SetFileParameterLotIDToLogisticsMID();
|
||||
if (reportFullPath.Length < _MinFileLength)
|
||||
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;
|
||||
}
|
||||
if (!iProcessData.Details.Any())
|
||||
throw new Exception(string.Concat("No Data - ", dateTime.Ticks));
|
||||
results = iProcessData.GetResults(this, _Logistics, results.Item4);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
672
Adaptation/FileHandlers/pcl/ProcessData.cs
Normal file
672
Adaptation/FileHandlers/pcl/ProcessData.cs
Normal file
@ -0,0 +1,672 @@
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Methods;
|
||||
using log4net;
|
||||
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.RegularExpressions;
|
||||
|
||||
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; }
|
||||
public string AreaCountMax { get; set; }
|
||||
public string AreaCountMin { get; set; }
|
||||
public string AreaCountStdDev { get; set; }
|
||||
public string AreaTotalAvg { get; set; }
|
||||
public string AreaTotalMax { get; set; }
|
||||
public string AreaTotalMin { get; set; }
|
||||
public string AreaTotalStdDev { get; set; }
|
||||
public string Date { get; set; }
|
||||
public string HazeAverageAvg { get; set; }
|
||||
public string HazeAverageMax { get; set; }
|
||||
public string HazeAverageMin { get; set; }
|
||||
public string HazeAverageStdDev { get; set; }
|
||||
public string HazeRegionAvg { get; set; }
|
||||
public string HazeRegionMax { get; set; }
|
||||
public string HazeRegionMin { get; set; }
|
||||
public string HazeRegionStdDev { get; set; }
|
||||
public string LPDCM2Avg { get; set; }
|
||||
public string LPDCM2Max { get; set; }
|
||||
public string LPDCM2Min { get; set; }
|
||||
public string LPDCM2StdDev { get; set; }
|
||||
public string LPDCountAvg { get; set; }
|
||||
public string LPDCountMax { get; set; }
|
||||
public string LPDCountMin { get; set; }
|
||||
public string LPDCountStdDev { get; set; }
|
||||
public string Lot { get; set; }
|
||||
public string ParseErrorText { get; set; }
|
||||
public string PSN { get; set; }
|
||||
public string RDS { get; set; }
|
||||
public string Reactor { get; set; }
|
||||
public string Recipe { get; set; }
|
||||
public string ScratchCountAvg { get; set; }
|
||||
public string ScratchCountMax { get; set; }
|
||||
public string ScratchCountMin { get; set; }
|
||||
public string ScratchCountStdDev { get; set; }
|
||||
public string ScratchTotalAvg { get; set; }
|
||||
public string ScratchTotalMax { get; set; }
|
||||
public string ScratchTotalMin { get; set; }
|
||||
public string ScratchTotalStdDev { get; set; }
|
||||
public string SumOfDefectsAvg { get; set; }
|
||||
public string SumOfDefectsMax { get; set; }
|
||||
public string SumOfDefectsMin { get; set; }
|
||||
public string SumOfDefectsStdDev { get; set; }
|
||||
public string UniqueId { get; set; }
|
||||
|
||||
List<object> Shared.Properties.IProcessData.Details => _Details;
|
||||
|
||||
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string ghostPCLFileName)
|
||||
{
|
||||
fileInfoCollection.Clear();
|
||||
_Details = new List<object>();
|
||||
_I = 0;
|
||||
_Data = string.Empty;
|
||||
JobID = logistics.JobID;
|
||||
MesEntity = logistics.MesEntity;
|
||||
_Log = LogManager.GetLogger(typeof(ProcessData));
|
||||
Parse(fileRead, logistics, fileInfoCollection, ghostPCLFileName);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
List<Description> fileReadDescriptions = (from l in descriptions select (Description)l).ToList();
|
||||
string json = JsonSerializer.Serialize(fileReadDescriptions, fileReadDescriptions.GetType());
|
||||
JsonElement[] jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json);
|
||||
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 toEol = GetToEOL();
|
||||
_I = j;
|
||||
return toEol;
|
||||
}
|
||||
|
||||
private void ParseLotSummary(IFileRead fileRead, ILogistics logistics, string headerFileName, Dictionary<string, string> pages, Dictionary<string, List<Detail>> slots)
|
||||
{
|
||||
if (fileRead is null)
|
||||
{ }
|
||||
_I = 0;
|
||||
//string headerText;
|
||||
//string altHeaderFileName = Path.ChangeExtension(headerFileName, ".txt");
|
||||
//if (File.Exists(altHeaderFileName))
|
||||
// headerText = File.ReadAllText(altHeaderFileName);
|
||||
//else
|
||||
//{
|
||||
// //Pdfbox, IKVM.AWT.WinForms
|
||||
// org.apache.pdfbox.pdmodel.PDDocument pdfDocument = org.apache.pdfbox.pdmodel.PDDocument.load(headerFileName);
|
||||
// org.apache.pdfbox.util.PDFTextStripper stripper = new org.apache.pdfbox.util.PDFTextStripper();
|
||||
// headerText = stripper.getText(pdfDocument);
|
||||
// pdfDocument.close();
|
||||
// File.AppendAllText(altHeaderFileName, headerText);
|
||||
//}
|
||||
//result.Id = h;
|
||||
//result.Title = h;
|
||||
//result.Zone = h;
|
||||
//result.PSN = h;
|
||||
//result.Layer = h;
|
||||
ParseErrorText = string.Empty;
|
||||
if (!pages.ContainsKey(headerFileName))
|
||||
throw new Exception();
|
||||
_I = 0;
|
||||
_Data = pages[headerFileName];
|
||||
ScanPast("Date:");
|
||||
Date = GetToEOL();
|
||||
ScanPast("Recipe ID:");
|
||||
Recipe = GetBefore("LotID:");
|
||||
Recipe = Recipe.Replace(";", "");
|
||||
if (_Data.Contains("[]"))
|
||||
Lot = GetBefore("[]");
|
||||
else if (_Data.Contains("[7]"))
|
||||
Lot = GetBefore("[7]");
|
||||
else
|
||||
Lot = GetBefore("[");
|
||||
|
||||
// Remove illegal characters \/:*?"<>| found in the Lot.
|
||||
Lot = Regex.Replace(Lot, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
|
||||
|
||||
// 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();
|
||||
|
||||
string[] segments = Lot.Split('-');
|
||||
if (segments.Length > 0)
|
||||
Reactor = segments[0];
|
||||
if (segments.Length > 1)
|
||||
RDS = segments[1];
|
||||
if (segments.Length > 2)
|
||||
PSN = segments[2];
|
||||
// Example of header.UniqueId is TENCOR1_33-289217-4693_201901300556533336
|
||||
UniqueId = string.Format("{0}_{1}_{2}", logistics.JobID, Lot, Path.GetFileNameWithoutExtension(logistics.ReportFullPath));
|
||||
}
|
||||
|
||||
private Detail ParseWaferSummary(string waferFileName, Dictionary<string, string> pages)
|
||||
{
|
||||
Detail result = new() { Data = "*Data*", i = -1, };
|
||||
_I = 0;
|
||||
//string waferText;
|
||||
//string altWaferFileName = Path.ChangeExtension(waferFileName, ".txt");
|
||||
//if (File.Exists(altWaferFileName))
|
||||
// waferText = File.ReadAllText(altWaferFileName);
|
||||
//else
|
||||
//{
|
||||
// //Pdfbox, IKVM.AWT.WinForms
|
||||
// org.apache.pdfbox.pdmodel.PDDocument pdfDocument = org.apache.pdfbox.pdmodel.PDDocument.load(waferFileName);
|
||||
// org.apache.pdfbox.util.PDFTextStripper dataStripper = new org.apache.pdfbox.util.PDFTextStripper();
|
||||
// waferText = dataStripper.getText(pdfDocument);
|
||||
// pdfDocument.close();
|
||||
// File.AppendAllText(altWaferFileName, waferText);
|
||||
//}
|
||||
List<string> stringList = new();
|
||||
result.HeaderUniqueId = UniqueId;
|
||||
result.Id = 0;
|
||||
result.Title = null;
|
||||
if (!pages.ContainsKey(waferFileName))
|
||||
throw new Exception();
|
||||
_I = 0;
|
||||
_Data = pages[waferFileName];
|
||||
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;
|
||||
}
|
||||
|
||||
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string ghostPCLFileName)
|
||||
{
|
||||
object item;
|
||||
string pageText;
|
||||
string pagePDFFile;
|
||||
string pageTextFile;
|
||||
List<string> sourceFiles = new();
|
||||
List<string> missingSlots = new();
|
||||
List<Detail> dataFiles = new();
|
||||
Dictionary<string, string> pages = new();
|
||||
string sourcePath = Path.GetDirectoryName(logistics.ReportFullPath);
|
||||
Dictionary<string, List<Detail>> slots = new();
|
||||
string sourceFileNamePdf = ConvertSourceFileToPdf(ghostPCLFileName, logistics);
|
||||
sourceFiles.Add(sourceFileNamePdf);
|
||||
string sourceFileNameNoExt = Path.GetFileNameWithoutExtension(logistics.ReportFullPath);
|
||||
////PdfSharp open pdf
|
||||
//using (PdfSharp.Pdf.PdfDocument sourceDocument = PdfSharp.Pdf.IO.PdfReader.Open(sourceFileNamePdf, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import))
|
||||
//{
|
||||
// for (int idxPage = 0; idxPage < sourceDocument.PageCount; idxPage++)
|
||||
// {
|
||||
// // split the pdf into separate pages. Odd pages are wafer image, even are wafer summary. Last page is Lot Summary.
|
||||
// _Log.Debug($"****ParseData - Splitting page: {idxPage}, sourceDocument: {sourceDocument.FullPath}, sourcePathFileNoExt: {sourcePathFileNoExt}");
|
||||
// //SplitPage(sourceDocument, sourcePathFileNoExt, idxPage);
|
||||
// pageNum = idxPage + 1;
|
||||
// pageFile = string.Format("{0}_{1}.pdf", sourcePathFileNoExt, pageNum);
|
||||
// _Log.Debug($"****SplitPage - Page {pageNum} Source file: {sourceDocument.FullPath}");
|
||||
// _Log.Debug($"****SplitPage - Page {pageNum} Output file: {pageFile}");
|
||||
// //PdfSharp Create new document
|
||||
// PdfSharp.Pdf.PdfDocument outputDocument = new PdfSharp.Pdf.PdfDocument { Version = sourceDocument.Version };
|
||||
// outputDocument.Info.Title = string.Format("Page {0} of {1}", pageNum, sourceDocument.Info.Title);
|
||||
// outputDocument.Info.Creator = sourceDocument.Info.Creator;
|
||||
// outputDocument.AddPage(sourceDocument.Pages[idxPage]);
|
||||
// outputDocument.Pages[0].CropBox = new PdfSharp.Pdf.PdfRectangle(new PdfSharp.Drawing.XRect(0, 100, 700, 700));
|
||||
// outputDocument.Save(pageFile);
|
||||
// }
|
||||
// sourceDocumentPageCount = sourceDocument.PageCount;
|
||||
// sourceDocument.Close();
|
||||
//}
|
||||
java.io.File file = new(sourceFileNamePdf);
|
||||
org.apache.pdfbox.util.Splitter splitter = new();
|
||||
org.apache.pdfbox.pdmodel.PDDocument pdDocument = org.apache.pdfbox.pdmodel.PDDocument.load(file);
|
||||
java.util.List list = splitter.split(pdDocument);
|
||||
java.util.ListIterator iterator = list.listIterator();
|
||||
org.apache.pdfbox.util.PDFTextStripper dataStripper = new();
|
||||
for (short i = 1; i < short.MaxValue; i++)
|
||||
{
|
||||
if (!iterator.hasNext())
|
||||
break;
|
||||
item = iterator.next();
|
||||
pagePDFFile = string.Concat(sourcePath, @"\", sourceFileNameNoExt, "_", i, ".pdf");
|
||||
pageTextFile = Path.ChangeExtension(pagePDFFile, ".txt");
|
||||
if (File.Exists(pageTextFile))
|
||||
{
|
||||
pageText = File.ReadAllText(pageTextFile);
|
||||
sourceFiles.Add(pageTextFile);
|
||||
if (item is not org.apache.pdfbox.pdmodel.PDDocument pd)
|
||||
continue;
|
||||
pd.close();
|
||||
}
|
||||
else if (File.Exists(pagePDFFile))
|
||||
{
|
||||
org.apache.pdfbox.pdmodel.PDDocument document = org.apache.pdfbox.pdmodel.PDDocument.load(pagePDFFile);
|
||||
pageText = dataStripper.getText(document);
|
||||
document.close();
|
||||
sourceFiles.Add(pagePDFFile);
|
||||
if (item is not org.apache.pdfbox.pdmodel.PDDocument pd)
|
||||
continue;
|
||||
pd.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item is not org.apache.pdfbox.pdmodel.PDDocument pd)
|
||||
continue;
|
||||
pageText = dataStripper.getText(pd);
|
||||
pd.save(pagePDFFile);
|
||||
sourceFiles.Add(pagePDFFile);
|
||||
pd.close();
|
||||
File.WriteAllText(pageTextFile, pageText);
|
||||
sourceFiles.Add(pageTextFile);
|
||||
}
|
||||
pages.Add(pagePDFFile, pageText);
|
||||
}
|
||||
pdDocument.close();
|
||||
// parse lot summary
|
||||
_Log.Debug($"****ParseData - Parsing lot summary");
|
||||
List<Tuple<string, string>> pageMapping = new();
|
||||
string headerFileName = string.Concat(sourcePath, @"\", sourceFileNameNoExt, "_", pages.Count, ".pdf");
|
||||
ParseLotSummary(fileRead, logistics, headerFileName, pages, slots);
|
||||
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, @"\", sourceFileNameNoExt, "_", dataFile.Slot.Replace('*', 's'), "_data.pdf")));
|
||||
slots[dataFile.Slot].Add(dataFile);
|
||||
}
|
||||
string checkFileName = string.Concat(sourcePath, @"\", sourceFileNameNoExt, "_data.pdf");
|
||||
if (!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 (!File.Exists(checkFileName))
|
||||
{
|
||||
File.Move(pageMapping[i].Item1, checkFileName);
|
||||
_ = sourceFiles.Remove(pageMapping[i].Item1);
|
||||
sourceFiles.Add(checkFileName);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(checkFileName))
|
||||
{
|
||||
//if (i == 0 || !string.IsNullOrEmpty(pageMapping[i - 1].Item2))
|
||||
//{
|
||||
checkFileName = checkFileName.Replace("_data.pdf", "_image.pdf");
|
||||
if (!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.Any() || keyValuePair.Value[0] is null)
|
||||
missingSlots.Add(string.Concat("Slot ", keyValuePair.Key, ") is missing."));
|
||||
else
|
||||
{
|
||||
foreach (Detail data in keyValuePair.Value)
|
||||
dataFiles.Add(data);
|
||||
}
|
||||
}
|
||||
if (missingSlots.Any())
|
||||
{
|
||||
string missingSlotsFile = string.Concat(sourcePath, @"\", sourceFileNameNoExt, "_MissingSlots.txt");
|
||||
File.WriteAllLines(missingSlotsFile, missingSlots);
|
||||
sourceFiles.Add(missingSlotsFile);
|
||||
}
|
||||
Date = DateTime.Parse(Date).ToString();
|
||||
//Equipment data is wrong!!!
|
||||
Date = DateTime.Now.ToString();
|
||||
//Equipment data is wrong!!!
|
||||
//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(new FileInfo(logistics.ReportFullPath));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user