Match TFS Changeset 303336
This commit is contained in:
95
FileHandlers/FileRead.cs
Normal file
95
FileHandlers/FileRead.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using Eaf.Core.Smtp;
|
||||
using Adaptation.Shared.Metrology;
|
||||
using Eaf.Core;
|
||||
using Ifx.Eaf.EquipmentConnector.File.Component.Reader;
|
||||
using log4net;
|
||||
using Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Linq;
|
||||
|
||||
namespace MET08DDUPSP1TBI.FileHandlers
|
||||
{
|
||||
|
||||
public partial class FileRead : FileReaderHandler
|
||||
{
|
||||
|
||||
private Adaptation.FileHandlers.FileRead _FileRead;
|
||||
|
||||
public FileRead()
|
||||
{
|
||||
_Log = LogManager.GetLogger(typeof(FileRead));
|
||||
_FileRead = new Adaptation.FileHandlers.FileRead();
|
||||
}
|
||||
|
||||
public override bool Extract(string reportFullPath, string eventName)
|
||||
{
|
||||
MethodBase methodBase = new StackFrame().GetMethod();
|
||||
_Log.Debug(string.Concat(methodBase.Name, " - Entry - {", reportFullPath, "}"));
|
||||
Tuple<string, JsonElement?, List<FileInfo>> extractResults = null;
|
||||
try
|
||||
{
|
||||
extractResults = _FileRead.GetExtractResult(reportFullPath, eventName);
|
||||
TriggerEvents(reportFullPath, extractResults);
|
||||
_FileRead.Move(reportFullPath, extractResults);
|
||||
FilePathGeneratorInfoMove(reportFullPath, extractResults);
|
||||
_FileRead.WaitForThread();
|
||||
_Log.Debug(string.Concat(methodBase.Name, " - Try - Exit"));
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Log.Error(string.Concat(methodBase.Name, " - Catch - Entry {", ex.Message, "}", Environment.NewLine, Environment.NewLine, ex.StackTrace));
|
||||
_FileRead.Move(reportFullPath, extractResults, exception: ex);
|
||||
FilePathGeneratorInfoMove(reportFullPath, extractResults, exception: ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Tuple<string, JsonElement?, List<FileInfo>> ReExtract(string searchDirectory, string sourceFileFilter)
|
||||
{
|
||||
Tuple<string, JsonElement?, List<FileInfo>> results = _FileRead.ReExtract(searchDirectory, sourceFileFilter);
|
||||
if (!(results?.Item2 is null))
|
||||
{
|
||||
TriggerEvents(_FileRead.Logistics.ReportFullPath, results);
|
||||
_FileRead.Move(_FileRead.Logistics.ReportFullPath, results);
|
||||
FilePathGeneratorInfoMove(_FileRead.Logistics.ReportFullPath, results);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private void FilePathGeneratorInfoMove(string reportFullPath, Tuple<string, JsonElement?, List<FileInfo>> extractResults, Exception exception = null)
|
||||
{
|
||||
bool isErrorFile = !(exception is null);
|
||||
object filePathGeneratorInfo = GetFilePathGeneratorInfo(reportFullPath, isErrorFile);
|
||||
Tuple<string, ConfigDataBase> tuple = _FileRead.GetOpenInsightTuple();
|
||||
if (filePathGeneratorInfo is null || !(filePathGeneratorInfo is FilePathGeneratorInfo filePathGenerator))
|
||||
OISiViewer.WebClientDownloadString(tuple.Item1, tuple.Item2, reportFullPath, isErrorFile, string.Empty);
|
||||
else
|
||||
{
|
||||
OISiViewer.WebClientDownloadString(tuple.Item1, tuple.Item2, reportFullPath, isErrorFile, filePathGenerator.To);
|
||||
string[] exceptionLines = _FileRead.Shared1124(reportFullPath, extractResults, filePathGenerator.To, filePathGenerator.From, filePathGenerator.ResolvedFileLocation, exception);
|
||||
if (isErrorFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach (string item in exceptionLines)
|
||||
stringBuilder.Append("<").Append(item).AppendLine(">");
|
||||
ISmtp smtp = Backbone.Instance.GetBackboneComponentsOfType<ISmtp>().SingleOrDefault();
|
||||
EmailMessage emailMessage = new EmailMessage(string.Concat("Exception:", _ConfigDataBase.EquipmentElementName, _ConfigDataBase.FileConnectorConfiguration?.SourceDirectoryCloaking), stringBuilder.ToString(), MailPriority.High);
|
||||
smtp.Send(emailMessage);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
249
FileHandlers/FileReadShared.cs
Normal file
249
FileHandlers/FileReadShared.cs
Normal file
@ -0,0 +1,249 @@
|
||||
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 MET08DDUPSP1TBI.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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user