diff --git a/Adaptation/.editorconfig b/Adaptation/.editorconfig
index 281d064..3607dc3 100644
--- a/Adaptation/.editorconfig
+++ b/Adaptation/.editorconfig
@@ -122,6 +122,7 @@ dotnet_diagnostic.IDE0290.severity = none # Use primary constructor [Distance]cs
dotnet_diagnostic.IDE0300.severity = none # IDE0300: Collection initialization can be simplified
dotnet_diagnostic.IDE0301.severity = none #IDE0301: Collection initialization can be simplified
dotnet_diagnostic.IDE0305.severity = none # IDE0305: Collection initialization can be simplified
+dotnet_diagnostic.MSTEST0037.severity = error # MSTEST0037: Use proper 'Assert' methods
dotnet_diagnostic.SYSLIB1045.severity = none # SYSLIB1045: diagnostics for regex source generation
dotnet_naming_rule.abstract_method_should_be_pascal_case.severity = warning
dotnet_naming_rule.abstract_method_should_be_pascal_case.style = pascal_case
diff --git a/Adaptation/.vscode/tasks.json b/Adaptation/.vscode/tasks.json
index 6304974..7a8f3c3 100644
--- a/Adaptation/.vscode/tasks.json
+++ b/Adaptation/.vscode/tasks.json
@@ -82,6 +82,26 @@
"command": "code ../DEP08SIHTRPLC.csproj",
"problemMatcher": []
},
+ {
+ "label": "Readme",
+ "type": "shell",
+ "command": "code ../README.md",
+ "problemMatcher": []
+ },
+ {
+ "label": "File-Folder-Helper AOT s X Day-Helper-2025-03-20",
+ "type": "shell",
+ "command": "L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe",
+ "args": [
+ "s",
+ "X",
+ "L:/DevOps/EAF-Mesa-Integration/DEP08SIHTRPLC",
+ "Day-Helper-2025-03-20",
+ "false",
+ "4"
+ ],
+ "problemMatcher": []
+ },
{
"label": "Git Config",
"type": "shell",
diff --git a/Adaptation/DEP08SIHTRPLC.Tests.csproj b/Adaptation/DEP08SIHTRPLC.Tests.csproj
index fbe5f66..f18cb19 100644
--- a/Adaptation/DEP08SIHTRPLC.Tests.csproj
+++ b/Adaptation/DEP08SIHTRPLC.Tests.csproj
@@ -69,7 +69,7 @@
- NU1701
+ NU1701
diff --git a/Adaptation/Shared/FileRead.cs b/Adaptation/Shared/FileRead.cs
index c8bed49..49a4526 100644
--- a/Adaptation/Shared/FileRead.cs
+++ b/Adaptation/Shared/FileRead.cs
@@ -44,9 +44,9 @@ public class FileRead : Properties.IFileRead
protected readonly string _CellInstanceConnectionNameBase;
protected readonly Dictionary> _DummyRuns;
protected readonly Dictionary _FileParameter;
- protected readonly Dictionary> _StaticRuns;
protected readonly string _ParameterizedModelObjectDefinitionType;
protected readonly FileConnectorConfiguration _FileConnectorConfiguration;
+ protected readonly Dictionary> _StaticRuns;
protected readonly IList _ModelObjectParameterDefinitions;
bool Properties.IFileRead.IsEvent => _IsEvent;
@@ -63,203 +63,6 @@ public class FileRead : Properties.IFileRead
string Properties.IFileRead.CellInstanceConnectionName => _CellInstanceConnectionName;
string Properties.IFileRead.ParameterizedModelObjectDefinitionType => _ParameterizedModelObjectDefinitionType;
- public FileRead(IDescription description, bool isEvent, ISMTP smtp, Dictionary fileParameter, string cellInstanceName, int? connectionCount, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList modelObjectParameters, string equipmentDictionaryName, Dictionary> dummyRuns, Dictionary> staticRuns, bool useCyclicalForDescription, bool isEAFHosted)
- {
- _SMTP = smtp;
- _IsEvent = isEvent;
- _DummyRuns = dummyRuns;
- _LastTicksDuration = 0;
- _StaticRuns = staticRuns;
- _IsEAFHosted = isEAFHosted;
- _Description = description;
- _FileParameter = fileParameter;
- _ReportFullPath = string.Empty;
- _CellInstanceName = cellInstanceName;
- _Calendar = new CultureInfo("en-US").Calendar;
- _Log = LogManager.GetLogger(typeof(FileRead));
- _UseCyclicalForDescription = useCyclicalForDescription;
- _CellInstanceConnectionName = cellInstanceConnectionName;
- _ModelObjectParameterDefinitions = modelObjectParameters;
- _FileConnectorConfiguration = fileConnectorConfiguration;
- _ParameterizedModelObjectDefinitionType = parameterizedModelObjectDefinitionType;
- _IsSourceTimer = fileConnectorConfiguration.SourceFileFilter.StartsWith("*Timer.txt");
- string cellInstanceConnectionNameBase = cellInstanceConnectionName.Replace("-", string.Empty);
- _Hyphens = cellInstanceConnectionName.Length - cellInstanceConnectionNameBase.Length;
- _TracePath = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "Path.Trace");
- _ExceptionSubject = string.Concat("Exception:", _CellInstanceConnectionName, _FileConnectorConfiguration?.SourceDirectoryCloaking);
- string suffix;
- string[] segments = _ParameterizedModelObjectDefinitionType.Split('.');
- string @namespace = segments[0];
- string eventNameFileRead = "FileRead";
- string eventName = segments[segments.Length - 1];
- bool isDuplicator = segments[0] == cellInstanceName;
- _IsDuplicator = isDuplicator;
- _CellInstanceConnectionNameBase = cellInstanceConnectionNameBase;
- if (eventName == eventNameFileRead)
- suffix = string.Empty;
- else
- suffix = string.Concat('_', eventName.Split(new string[] { eventNameFileRead }, StringSplitOptions.RemoveEmptyEntries)[1]);
- string parameterizedModelObjectDefinitionTypeAppended = string.Concat(@namespace, suffix);
- if (!isEAFHosted)
- {
- if (string.IsNullOrEmpty(equipmentTypeName) || equipmentTypeName != parameterizedModelObjectDefinitionTypeAppended)
- throw new Exception(cellInstanceConnectionName);
- if (string.IsNullOrEmpty(equipmentDictionaryName) && isEvent)
- throw new Exception(cellInstanceConnectionName);
- if (!string.IsNullOrEmpty(equipmentDictionaryName) && !isEvent && connectionCount > 1)
- throw new Exception(cellInstanceConnectionName);
- // if (string.IsNullOrEmpty(equipmentDictionaryName) && !isEvent)
- // throw new Exception(cellInstanceConnectionName);
- // if (!string.IsNullOrEmpty(equipmentDictionaryName) && isEvent)
- // throw new Exception(cellInstanceConnectionName);
- }
- if (isDuplicator)
- _MesEntity = string.Empty;
- else
- _MesEntity = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, string.Concat("CellInstance.", cellInstanceName, ".Alias"));
- _EventName = eventName;
- _EventNameFileRead = eventNameFileRead;
- _EquipmentType = parameterizedModelObjectDefinitionTypeAppended;
- long breakAfterSeconds;
- if (_FileConnectorConfiguration is null)
- breakAfterSeconds = 360;
- else
- {
- if (_FileConnectorConfiguration.FileScanningOption == FileConnectorConfiguration.FileScanningOptionEnum.TimeBased)
- breakAfterSeconds = Math.Abs(_FileConnectorConfiguration.FileHandleTimeout.Value);
- else if (_FileConnectorConfiguration.FileScanningOption == FileConnectorConfiguration.FileScanningOptionEnum.FileWatcher)
- breakAfterSeconds = Math.Abs(_FileConnectorConfiguration.FileScanningIntervalInSeconds.Value);
- else
- throw new Exception();
- }
- _BreakAfterSeconds = breakAfterSeconds;
- UpdateLastTicksDuration(breakAfterSeconds * 10000000);
- if (_IsDuplicator)
- {
- if (string.IsNullOrEmpty(_FileConnectorConfiguration.TargetFileLocation) || string.IsNullOrEmpty(_FileConnectorConfiguration.ErrorTargetFileLocation))
- throw new Exception("_Configuration is empty?");
- if (_FileConnectorConfiguration.TargetFileLocation.Contains('%') || _FileConnectorConfiguration.ErrorTargetFileLocation.Contains('%'))
- throw new Exception("_Configuration is incorrect for a duplicator!");
- // if (_FileConnectorConfiguration is not null)
- // {
- // if (string.IsNullOrEmpty(_FileConnectorConfiguration.SourceDirectoryCloaking))
- // throw new Exception("SourceDirectoryCloaking is empty?");
- // if (!_FileConnectorConfiguration.SourceDirectoryCloaking.StartsWith("~"))
- // throw new Exception("SourceDirectoryCloaking is incorrect for a duplicator!");
- // }
- }
- }
-
- protected static string GetPropertyValue(string cellInstanceConnectionName, IList modelObjectParameters, string propertyName)
- {
- string result;
- List results = (from l in modelObjectParameters where l.Name == propertyName select l.Value).ToList();
- if (results.Count != 1)
- throw new Exception(cellInstanceConnectionName);
- result = results[0];
- return result;
- }
-
- protected static ModelObjectParameterDefinition[] GetProperties(string cellInstanceConnectionName, IList modelObjectParameters, string propertyNamePrefix)
- {
- ModelObjectParameterDefinition[] results = (from l in modelObjectParameters where l.Name.StartsWith(propertyNamePrefix) select l).ToArray();
- if (results.Length == 0)
- throw new Exception(cellInstanceConnectionName);
- return results;
- }
-
- protected static ModelObjectParameterDefinition[] GetProperties(string cellInstanceConnectionName, IList modelObjectParameters, string propertyNamePrefix, string propertyNameSuffix)
- {
- ModelObjectParameterDefinition[] results = (from l in modelObjectParameters where l.Name.StartsWith(propertyNamePrefix) && l.Name.EndsWith(propertyNameSuffix) select l).ToArray();
- if (results.Length == 0)
- throw new Exception(cellInstanceConnectionName);
- return results;
- }
-
- protected void UpdateLastTicksDuration(long ticksDuration)
- {
- if (ticksDuration < 50000000)
- ticksDuration = 50000000;
- _LastTicksDuration = (long)Math.Ceiling(ticksDuration * .667);
- _Log.Info($"{new TimeSpan(ticksDuration).TotalMilliseconds} TotalMillisecond(s) to process {Environment.NewLine}{_CellInstanceConnectionName}{Environment.NewLine}<{_ReportFullPath}>");
- }
-
- protected void WaitForThread(Thread thread, List threadExceptions)
- {
- if (thread is not null)
- {
- ThreadState threadState;
- for (short i = 0; i < short.MaxValue; i++)
- {
- if (thread is null)
- break;
- else
- {
- threadState = thread.ThreadState;
- if (threadState is not ThreadState.Running and not ThreadState.WaitSleepJoin)
- break;
- }
- Thread.Sleep(500);
- }
- lock (threadExceptions)
- {
- if (threadExceptions.Count != 0)
- {
- foreach (Exception item in threadExceptions)
- _Log.Error(string.Concat(item.Message, Environment.NewLine, Environment.NewLine, item.StackTrace));
- Exception exception = threadExceptions[0];
- threadExceptions.Clear();
- throw exception;
- }
- }
- }
- }
-
- private void WriteAllLines(string to, string[] exceptionLines)
- {
- string fileName = string.Concat(to, @"\readme.txt");
- try
- {
- if (!Directory.Exists(to))
- _ = Directory.CreateDirectory(to);
- File.WriteAllLines(fileName, exceptionLines);
- }
- catch (Exception ex) { _Log.Error(ex.Message); }
- }
-
- protected string[] Move(Tuple> extractResults, string to, string from, string resolvedFileLocation, Exception exception)
- {
- string[] results;
- bool isErrorFile = exception is not null;
- if (!to.EndsWith(@"\"))
- _ = string.Concat(to, @"\");
- if (!isErrorFile)
- results = Array.Empty();
- else
- {
- results = new string[] { _Logistics.Sequence.ToString(), _Logistics.ReportFullPath, from, resolvedFileLocation, to, string.Empty, string.Empty, exception.Message, string.Empty, string.Empty, exception.StackTrace };
- if (!_IsDuplicator)
- WriteAllLines(to, results);
- }
- if (extractResults is not null && extractResults.Item4 is not null && extractResults.Item4.Count != 0)
- {
- string itemFile;
- List directories = new();
- foreach (FileInfo sourceFile in extractResults.Item4)
- {
- if (sourceFile.FullName != _Logistics.ReportFullPath)
- {
- itemFile = sourceFile.FullName.Replace(from, to);
- Shared1880(itemFile, directories, sourceFile, isErrorFile);
- }
- else if (!isErrorFile && _Logistics is not null)
- Shared1811(to, sourceFile);
- }
- Shared0231(directories);
- }
- return results;
- }
-
protected static string GetTupleFile(Logistics logistics, List descriptions, Properties.IScopeInfo scopeInfo, string duplicateDirectory, string duplicateFile) where T : Properties.IDescription
{
string result;
@@ -384,217 +187,131 @@ public class FileRead : Properties.IFileRead
}
}
- protected void SetFileParameter(string key, string value)
+ protected void WaitForFileConsumption(DateTime dateTime, List descriptions, bool isDummyRun, string successDirectory, string duplicateDirectory, List<(Properties.IScopeInfo, string)> collection, string duplicateFile) where T : Properties.IDescription
{
- if (_FileConnectorConfiguration is null || _FileConnectorConfiguration.TargetFileLocation.Contains(string.Concat("%", key, "%")) || _FileConnectorConfiguration.ErrorTargetFileLocation.Contains(string.Concat("%", key, "%")) || _FileConnectorConfiguration.TargetFileName.Contains(string.Concat("%", key, "%")) || _FileConnectorConfiguration.ErrorTargetFileName.Contains(string.Concat("%", key, "%")))
- {
- if (_FileParameter.ContainsKey(key))
- _FileParameter[key] = value;
- else
- _FileParameter.Add(key, value);
- }
- }
-
- protected void SetFileParameterLotIDToLogisticsMID(bool includeLogisticsSequence = true)
- {
- string key;
- if (!includeLogisticsSequence)
- key = "LotID";
- else
- key = "LotIDWithLogisticsSequence";
- string value = string.Concat(_Logistics.MID, "_", _Logistics.Sequence, "_", DateTime.Now.Ticks - _Logistics.Sequence);
- SetFileParameter(key, value);
- }
-
- protected void SetFileParameterLotID(string value, bool includeLogisticsSequence = true)
- {
- string key;
- if (!includeLogisticsSequence)
- key = "LotID";
+ if (!isDummyRun && _IsEAFHosted)
+ WaitForFileConsumption(_FileConnectorConfiguration.SourceDirectoryCloaking, _Logistics, dateTime, descriptions, successDirectory, duplicateDirectory, duplicateFile, collection);
else
{
- key = "LotIDWithLogisticsSequence";
- value = string.Concat(value, "_", _Logistics.Sequence, "_", DateTime.Now.Ticks - _Logistics.Sequence);
- }
- SetFileParameter(key, value);
- }
-
- protected void WritePDSF(IFileRead fileRead, JsonElement[] jsonElements)
- {
- string directory;
- string weekOfYear = _Calendar.GetWeekOfYear(_Logistics.DateTimeFromSequence, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
- string weekDirectory = $"{_Logistics.DateTimeFromSequence:yyyy}_Week_{weekOfYear}{@"\"}{_Logistics.DateTimeFromSequence:yyyy-MM-dd}";
- if (!_CellInstanceConnectionName.StartsWith(_CellInstanceName) && _CellInstanceConnectionNameBase == _EquipmentType)
- directory = Path.Combine(_TracePath, _EquipmentType, "Target", weekDirectory, _CellInstanceName, _CellInstanceConnectionName);
- else
- directory = Path.Combine(_TracePath, _EquipmentType, "Source", weekDirectory, _CellInstanceName, _CellInstanceConnectionName);
- if (!Directory.Exists(directory))
- _ = Directory.CreateDirectory(directory);
- string file = Path.Combine(directory, string.Concat(_Logistics.MesEntity, "_", _Logistics.Sequence, ".ipdsf"));
- string lines = ProcessDataStandardFormat.GetPDSFText(fileRead, _Logistics, jsonElements, logisticsText: string.Empty);
- File.WriteAllText(file, lines);
- if (_Logistics.TotalSecondsSinceLastWriteTimeFromSequence > 600)
- {
- try
- { File.SetLastWriteTime(file, _Logistics.DateTimeFromSequence); }
- catch (Exception) { }
- }
- }
-
- protected void Move(Tuple> extractResults)
- {
- if (!_IsEAFHosted)
- {
- string to;
- if (!_FileConnectorConfiguration.TargetFileLocation.EndsWith(Path.DirectorySeparatorChar.ToString()))
- to = _FileConnectorConfiguration.TargetFileLocation;
- else
- to = Path.GetDirectoryName(_FileConnectorConfiguration.TargetFileLocation);
- foreach (KeyValuePair keyValuePair in _FileParameter)
- to = to.Replace(string.Concat('%', keyValuePair.Key, '%'), keyValuePair.Value);
- if (to.Contains('%'))
- _Log.Debug("Can't debug without EAF Hosting");
- else
- _ = Move(extractResults, to, _FileConnectorConfiguration.SourceFileLocation, resolvedFileLocation: string.Empty, exception: null);
- }
- }
-
- protected void TriggerEvents(Tuple> extractResults, List headerNames, Dictionary keyValuePairs)
- {
- object value;
- string segments;
- string description;
- List