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) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user