249 lines
15 KiB
C#
249 lines
15 KiB
C#
using Adaptation.Shared.Metrology;
|
|
using Eaf.Core;
|
|
using Eaf.EquipmentCore.DataCollection.Reporting;
|
|
using Eaf.EquipmentCore.SelfDescription.ElementDescription;
|
|
using Eaf.EquipmentCore.SelfDescription.EquipmentStructure;
|
|
using Eaf.Management.ConfigurationData.CellAutomation;
|
|
using Ifx.Eaf.EquipmentConnector.File.Configuration;
|
|
using log4net;
|
|
using Shared;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text.Json;
|
|
using System.Threading;
|
|
|
|
namespace MET08ANLYSDIFAAST230.FileHandlers
|
|
{
|
|
|
|
public partial class FileRead
|
|
{
|
|
|
|
#pragma warning disable CS0169
|
|
private readonly ILog _Log;
|
|
private Description _Description;
|
|
private ConfigDataBase _ConfigDataBase;
|
|
private EquipmentEvent _EquipmentEvent;
|
|
private FilePathGenerator _FilePathGeneratorForError;
|
|
private FilePathGenerator _FilePathGeneratorForTarget;
|
|
#pragma warning restore CS0169
|
|
|
|
public override void CreateSelfDescription()
|
|
{
|
|
MethodBase methodBase = new StackFrame().GetMethod();
|
|
_Log.Debug(string.Concat(methodBase.Name, " - Entry"));
|
|
try
|
|
{
|
|
if (Equipment is null)
|
|
throw new Exception();
|
|
string cellInstanceName;
|
|
if (Backbone.Instance?.CellName is null)
|
|
cellInstanceName = string.Empty;
|
|
else
|
|
cellInstanceName = Backbone.Instance.CellName;
|
|
if (cellInstanceName.Contains("-IO"))
|
|
cellInstanceName = cellInstanceName.Replace("-IO", string.Empty);
|
|
EquipmentElement equipmentElement = Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.Item;
|
|
Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration fileConnectorConfiguration = Map(Configuration);
|
|
IList<Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition> modelObjectParameterDefinitions = Map(ConfiguredParameters);
|
|
_ConfigDataBase = _FileRead.GetConfigDataBase(methodBase, cellInstanceName, equipmentElement.Name, fileConnectorConfiguration, modelObjectParameterDefinitions, eafHosted: !(Equipment is null));
|
|
if (Configuration.SourceFileLocation != _ConfigDataBase.FileConnectorConfiguration.SourceFileLocation)
|
|
Configuration.SourceFileLocation = _ConfigDataBase.FileConnectorConfiguration.SourceFileLocation;
|
|
_Description = new Description(_FileRead, _ConfigDataBase, Equipment);
|
|
_FileRead.Shared0749();
|
|
if (FileParameter is null)
|
|
FileParameter = new Dictionary<string, string>();
|
|
_FileRead.Shared1301(FileParameter, fileConnectorConfiguration);
|
|
if (!(Equipment is null) && _ConfigDataBase.IsEvent)
|
|
{
|
|
if (_Description.ParameterTypeDefinitions.Any())
|
|
{
|
|
foreach (Eaf.EquipmentCore.SelfDescription.ParameterTypes.ParameterTypeDefinition item in _Description.ParameterTypeDefinitions)
|
|
{
|
|
Equipment.SelfDescriptionBuilder.AddParameterTypeDefinition(item);
|
|
}
|
|
}
|
|
Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.AddParameterRange(_Description.EquipmentParameters);
|
|
_EquipmentEvent = new EquipmentEvent(_ConfigDataBase.GetEventName(), _ConfigDataBase.GetEventDescription(), _Description.EquipmentParameters);
|
|
Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.AddEvent(_EquipmentEvent);
|
|
}
|
|
_Log.Debug(string.Concat(methodBase.Name, " - Try - Exit"));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_Log.Error(string.Concat(methodBase.Name, " - Catch - Entry {", ex.Message, "}", Environment.NewLine, Environment.NewLine, ex.StackTrace));
|
|
long breakAfter = DateTime.Now.AddSeconds(30).Ticks;
|
|
for (short i = 0; i < short.MaxValue; i++)
|
|
{
|
|
if (DateTime.Now.Ticks > breakAfter)
|
|
break;
|
|
Thread.Sleep(500);
|
|
}
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public object GetFilePathGeneratorInfo(string reportFullPath, bool isErrorFile)
|
|
{
|
|
FilePathGeneratorInfo result;
|
|
FilePathGenerator filePathGeneratorOriginal;
|
|
if (Configuration is null)
|
|
result = null;
|
|
else
|
|
{
|
|
if (isErrorFile)
|
|
{
|
|
if (_FilePathGeneratorForError is null)
|
|
_FilePathGeneratorForError = new FilePathGenerator(Configuration, reportFullPath, isErrorFile: true);
|
|
filePathGeneratorOriginal = _FilePathGeneratorForError;
|
|
}
|
|
else
|
|
{
|
|
if (_FilePathGeneratorForTarget is null)
|
|
_FilePathGeneratorForTarget = new FilePathGenerator(Configuration, reportFullPath, isErrorFile: false);
|
|
filePathGeneratorOriginal = _FilePathGeneratorForTarget;
|
|
}
|
|
result = new FilePathGeneratorInfo(filePathGeneratorOriginal, reportFullPath, isErrorFile, FileParameter);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration Map(FileConnectorConfiguration configuration)
|
|
{
|
|
Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration result = new Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration
|
|
{
|
|
AlternateTargetFolder = configuration.AlternateTargetFolder,
|
|
ConnectionRetryInterval = configuration.ConnectionRetryInterval,
|
|
ConnectionSettings = new List<Adaptation.Ifx.Eaf.Common.Configuration.ConnectionSetting>(),
|
|
CopySourceFolderStructure = configuration.CopySourceFolderStructure,
|
|
DefaultPlaceHolderValue = configuration.DefaultPlaceHolderValue,
|
|
//DeleteAbandonedEmptySourceSubFolders = configuration.DeleteAbandonedEmptySourceSubFolders,
|
|
DeleteEmptySourceSubFolders = configuration.DeleteEmptySourceSubFolders,
|
|
ErrorPostProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PostProcessingModeEnum)configuration.ErrorPostProcessingMode,
|
|
ErrorTargetFileLocation = configuration.ErrorTargetFileLocation,
|
|
ErrorTargetFileName = configuration.ErrorTargetFileName,
|
|
FileAgeFilterMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.FileAgeFilterEnum)configuration.FileAgeFilterMode,
|
|
FileAgeThreshold = configuration.FileAgeThreshold,
|
|
//FileHandlers = configuration.FileHandlers,
|
|
FileHandleTimeout = (long)configuration.FileHandleTimeout,
|
|
FileHandleWaitTime = configuration.FileHandleWaitTime,
|
|
FileScanningIntervalInSeconds = configuration.FileScanningIntervalInSeconds,
|
|
FileScanningOption = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.FileScanningOptionEnum)configuration.FileScanningOption,
|
|
FolderAgeCheckIndividualSubFolders = configuration.FolderAgeCheckIndividualSubFolders,
|
|
FolderAgeThreshold = configuration.FolderAgeThreshold,
|
|
//FolderOperationsSubFolderLevel = configuration.FolderOperationsSubFolderLevel,
|
|
IdleEventWaitTimeInSeconds = (long)configuration.IdleEventWaitTimeInSeconds,
|
|
IfFileExistAction = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.IfFileExistEnum)configuration.IfFileExistAction,
|
|
IfPostProcessingFailsAction = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.IfPostProcessingFailsEnum)configuration.IfPostProcessingFailsAction,
|
|
IncludeSubDirectories = configuration.IncludeSubDirectories,
|
|
PostProcessingRetries = configuration.PostProcessingRetries,
|
|
PreProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PreProcessingModeEnum)configuration.PreProcessingMode,
|
|
PostProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PostProcessingModeEnum)configuration.PostProcessingMode,
|
|
SourceDirectoryCloaking = configuration.SourceDirectoryCloaking,
|
|
SourceFileFilter = configuration.SourceFileFilter,
|
|
SourceFileFilters = configuration.SourceFileFilters,
|
|
SourceFileLocation = configuration.SourceFileLocation,
|
|
TargetFileLocation = configuration.TargetFileLocation,
|
|
TargetFileName = configuration.TargetFileName,
|
|
TriggerOnChanged = configuration.TriggerOnChanged,
|
|
TriggerOnCreated = configuration.TriggerOnCreated,
|
|
UseZip64Mode = configuration.UseZip64Mode,
|
|
ZipErrorTargetFileName = configuration.ZipErrorTargetFileName,
|
|
ZipFileAmount = configuration.ZipFileAmount,
|
|
ZipFileSubFolderLevel = configuration.ZipFileSubFolderLevel,
|
|
ZipFileTime = configuration.ZipFileTime,
|
|
ZipMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.ZipModeEnum)configuration.ZipMode,
|
|
ZipTargetFileName = configuration.ZipTargetFileName,
|
|
};
|
|
foreach (Ifx.Eaf.Common.Configuration.ConnectionSetting connectionSetting in configuration.ConnectionSettings)
|
|
result.ConnectionSettings.Add(new Adaptation.Ifx.Eaf.Common.Configuration.ConnectionSetting(connectionSetting.Name, connectionSetting.Value));
|
|
return result;
|
|
}
|
|
|
|
private IList<Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition> Map(IList<ModelObjectParameterDefinition> configuredParameters)
|
|
{
|
|
List<Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition> results = new List<Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition>();
|
|
Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterType modelObjectParameterType;
|
|
for (int i = 0; i < configuredParameters.Count; i++)
|
|
{
|
|
modelObjectParameterType = (Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterType)configuredParameters[i].ValueType;
|
|
results.Add(new Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition() { Id = i, Name = configuredParameters[i].Name, Value = configuredParameters[i].Value, ValueType = modelObjectParameterType, EnumType = modelObjectParameterType.ToString() });
|
|
}
|
|
return results;
|
|
}
|
|
|
|
public ConfigDataBase ReflectionCreateSelfDescriptionV2(string json)
|
|
{
|
|
ConfigDataBase result = _FileRead.ReflectionCreateSelfDescriptionV2(json);
|
|
_ConfigDataBase = result;
|
|
_Description = new Description(_FileRead, result, Equipment);
|
|
return result;
|
|
}
|
|
|
|
private void TriggerEvents(string reportFullPath, Tuple<string, JsonElement?, List<FileInfo>> extractResults)
|
|
{
|
|
List<ParameterValue> parameters;
|
|
int count = extractResults.Item2.Value.GetArrayLength();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
_Log.Debug(string.Concat("TriggerEvent - {", reportFullPath, "} ", i, " of ", count));
|
|
parameters = _Description.GetParameterValues(_FileRead, Equipment, extractResults.Item2.Value, i);
|
|
if (!(_EquipmentEvent is null))
|
|
Equipment.DataCollection.TriggerEvent(_EquipmentEvent, parameters);
|
|
if (_ConfigDataBase.UseCyclicalForDescription)
|
|
break;
|
|
}
|
|
if (_ConfigDataBase.IsDatabaseExportToIPDSF && count > 0)
|
|
{
|
|
_Log.Debug(string.Concat("TriggerEvent - {", reportFullPath, "} ", null, " of ", count));
|
|
parameters = _Description.GetParameterValues(_FileRead, Equipment, extractResults.Item2.Value, null);
|
|
if (!(_EquipmentEvent is null))
|
|
Equipment.DataCollection.TriggerEvent(_EquipmentEvent, parameters);
|
|
}
|
|
}
|
|
|
|
private void TriggerEvents(string reportFullPath, Tuple<string, JsonElement?, List<FileInfo>> extractResults, Dictionary<string, object> eventDataList, int count)
|
|
{
|
|
const string DATA_LIST_KEY = "DataList";
|
|
const int RESULT_CODE_SUCCESS = 0;
|
|
const string RESULT_CODE_KEY = "ReturnCode";
|
|
const string RESULT_EMAIL_FAILURE_TYPE = "ReturnEmailFailureType";
|
|
const string RESULT_EMAIL_FAILURE_NONE = "EmailFailureNone";
|
|
const string RESULT_TEXT_KEY = "ReturnText";
|
|
List<ParameterValue> parameters;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
_Log.Debug(string.Concat("TriggerEvent - {", reportFullPath, "} ", i, " of ", count));
|
|
//parameters = _Description.GetParameterValues(this, Equipment, extractResults.Item2, count, i);
|
|
// add the final results fields to the data dictionary
|
|
Dictionary<string, object> finalDictionary = new Dictionary<string, object>
|
|
{
|
|
[RESULT_CODE_KEY] = RESULT_CODE_SUCCESS,
|
|
[RESULT_TEXT_KEY] = "success",
|
|
[RESULT_EMAIL_FAILURE_TYPE] = RESULT_EMAIL_FAILURE_NONE,
|
|
[DATA_LIST_KEY] = eventDataList
|
|
};
|
|
// trigger File Read event
|
|
//Equipment.DataCollection.TriggerEvent(mFileReadEvent, new List<ParameterValue>() { new ParameterValue(mMyParameter, finalDictionary) });
|
|
//
|
|
parameters = _Description.GetParameterValues(_FileRead, Equipment, extractResults.Item2.Value, i, keyValuePairs: finalDictionary);
|
|
if (!(_EquipmentEvent is null))
|
|
Equipment.DataCollection.TriggerEvent(_EquipmentEvent, parameters);
|
|
if (_ConfigDataBase.UseCyclicalForDescription)
|
|
break;
|
|
}
|
|
if (_ConfigDataBase.IsDatabaseExportToIPDSF && count > 0)
|
|
{
|
|
_Log.Debug(string.Concat("TriggerEvent - {", reportFullPath, "} ", null, " of ", count));
|
|
parameters = _Description.GetParameterValues(_FileRead, Equipment, extractResults.Item2.Value, null);
|
|
if (!(_EquipmentEvent is null))
|
|
Equipment.DataCollection.TriggerEvent(_EquipmentEvent, parameters);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} |