// 2022-02-15 -> FileRead
This commit is contained in:
parent
8ef7fca67a
commit
7fab3b7c1f
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
@ -9,8 +10,6 @@ namespace Adaptation.Shared.Metrology;
|
|||||||
public partial class WS
|
public partial class WS
|
||||||
{
|
{
|
||||||
|
|
||||||
#pragma warning disable CA1847
|
|
||||||
|
|
||||||
public static Tuple<string, Results> SendData(string url, object payload, int timeoutSeconds = 120)
|
public static Tuple<string, Results> SendData(string url, object payload, int timeoutSeconds = 120)
|
||||||
{
|
{
|
||||||
Results results = new();
|
Results results = new();
|
||||||
@ -18,7 +17,7 @@ public partial class WS
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string json = JsonSerializer.Serialize(payload, payload.GetType());
|
string json = JsonSerializer.Serialize(payload, payload.GetType());
|
||||||
if (string.IsNullOrEmpty(url) || !url.Contains(":") || !url.Contains("."))
|
if (string.IsNullOrEmpty(url) || !url.Contains(':') || !url.Contains('.'))
|
||||||
throw new Exception("Invalid URL");
|
throw new Exception("Invalid URL");
|
||||||
using (HttpClient httpClient = new())
|
using (HttpClient httpClient = new())
|
||||||
{
|
{
|
||||||
|
@ -24,11 +24,10 @@ using System.Text.Json;
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace MET08RESIMAPCDE.FileHandlers
|
namespace MET08RESIMAPCDE.FileHandlers;
|
||||||
{
|
|
||||||
|
|
||||||
public partial class FileRead : FileReaderHandler, ISMTP
|
public partial class FileRead : FileReaderHandler, ISMTP
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ILog _Log;
|
private readonly ILog _Log;
|
||||||
private IFileRead _FileRead;
|
private IFileRead _FileRead;
|
||||||
@ -39,10 +38,7 @@ namespace MET08RESIMAPCDE.FileHandlers
|
|||||||
private readonly List<EquipmentParameter> _EquipmentParameters;
|
private readonly List<EquipmentParameter> _EquipmentParameters;
|
||||||
private static readonly Dictionary<string, List<long>> _DummyRuns;
|
private static readonly Dictionary<string, List<long>> _DummyRuns;
|
||||||
|
|
||||||
static FileRead()
|
static FileRead() => _DummyRuns = new Dictionary<string, List<long>>();
|
||||||
{
|
|
||||||
_DummyRuns = new Dictionary<string, List<long>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileRead()
|
public FileRead()
|
||||||
{
|
{
|
||||||
@ -106,7 +102,7 @@ namespace MET08RESIMAPCDE.FileHandlers
|
|||||||
private void Send(EmailMessage emailMessage)
|
private void Send(EmailMessage emailMessage)
|
||||||
{
|
{
|
||||||
ISmtp smtp = Backbone.Instance.GetBackboneComponentsOfType<ISmtp>().SingleOrDefault();
|
ISmtp smtp = Backbone.Instance.GetBackboneComponentsOfType<ISmtp>().SingleOrDefault();
|
||||||
if (!(smtp is null))
|
if (smtp is not null)
|
||||||
smtp.Send(emailMessage);
|
smtp.Send(emailMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,9 +173,9 @@ namespace MET08RESIMAPCDE.FileHandlers
|
|||||||
equipmentParameter = new EquipmentParameter(jsonProperty.Name, parameterTypeDefinitions[jsonProperty.Value.ValueKind], description);
|
equipmentParameter = new EquipmentParameter(jsonProperty.Name, parameterTypeDefinitions[jsonProperty.Value.ValueKind], description);
|
||||||
_EquipmentParameters.Add(equipmentParameter);
|
_EquipmentParameters.Add(equipmentParameter);
|
||||||
}
|
}
|
||||||
Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.AddParameterRange(_EquipmentParameters);
|
_ = Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.AddParameterRange(_EquipmentParameters);
|
||||||
_EquipmentEvent = new EquipmentEvent(_FileRead.EventName, _FileRead.GetEventDescription(), _EquipmentParameters);
|
_EquipmentEvent = new EquipmentEvent(_FileRead.EventName, _FileRead.GetEventDescription(), _EquipmentParameters);
|
||||||
Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.AddEvent(_EquipmentEvent);
|
_ = Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.AddEvent(_EquipmentEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateSelfDescription(MethodBase methodBase)
|
private void CreateSelfDescription(MethodBase methodBase)
|
||||||
@ -228,9 +224,9 @@ namespace MET08RESIMAPCDE.FileHandlers
|
|||||||
|
|
||||||
private void FilePathGeneratorInfoMove(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception = null)
|
private void FilePathGeneratorInfoMove(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception = null)
|
||||||
{
|
{
|
||||||
bool isErrorFile = !(exception is null);
|
bool isErrorFile = exception is not null;
|
||||||
object filePathGeneratorInfo = GetFilePathGeneratorInfo(_FileRead.ReportFullPath, isErrorFile);
|
object filePathGeneratorInfo = GetFilePathGeneratorInfo(_FileRead.ReportFullPath, isErrorFile);
|
||||||
if (!(filePathGeneratorInfo is null) && filePathGeneratorInfo is FilePathGeneratorInfo filePathGenerator)
|
if (filePathGeneratorInfo is not null and FilePathGeneratorInfo filePathGenerator)
|
||||||
{
|
{
|
||||||
string[] exceptionLines = _FileRead.Move(extractResults, filePathGenerator.To, filePathGenerator.From, filePathGenerator.ResolvedFileLocation, exception);
|
string[] exceptionLines = _FileRead.Move(extractResults, filePathGenerator.To, filePathGenerator.From, filePathGenerator.ResolvedFileLocation, exception);
|
||||||
if (isErrorFile)
|
if (isErrorFile)
|
||||||
@ -239,7 +235,7 @@ namespace MET08RESIMAPCDE.FileHandlers
|
|||||||
{
|
{
|
||||||
StringBuilder stringBuilder = new();
|
StringBuilder stringBuilder = new();
|
||||||
foreach (string item in exceptionLines)
|
foreach (string item in exceptionLines)
|
||||||
stringBuilder.Append("<").Append(item).AppendLine(">");
|
_ = stringBuilder.Append("<").Append(item).AppendLine(">");
|
||||||
ISmtp smtp = Backbone.Instance.GetBackboneComponentsOfType<ISmtp>().SingleOrDefault();
|
ISmtp smtp = Backbone.Instance.GetBackboneComponentsOfType<ISmtp>().SingleOrDefault();
|
||||||
EmailMessage emailMessage = new(_FileRead.ExceptionSubject, stringBuilder.ToString(), MailPriority.High);
|
EmailMessage emailMessage = new(_FileRead.ExceptionSubject, stringBuilder.ToString(), MailPriority.High);
|
||||||
smtp.Send(emailMessage);
|
smtp.Send(emailMessage);
|
||||||
@ -289,7 +285,7 @@ namespace MET08RESIMAPCDE.FileHandlers
|
|||||||
{
|
{
|
||||||
_Log.Debug(string.Concat("TriggerEvent - {", _FileRead.ReportFullPath, "} ", i, " of ", extractResults.Item3.Length));
|
_Log.Debug(string.Concat("TriggerEvent - {", _FileRead.ReportFullPath, "} ", i, " of ", extractResults.Item3.Length));
|
||||||
parameters = GetParameterValues(headerNames, extractResults.Item3, i);
|
parameters = GetParameterValues(headerNames, extractResults.Item3, i);
|
||||||
if (!(_EquipmentEvent is null))
|
if (_EquipmentEvent is not null)
|
||||||
Equipment.DataCollection.TriggerEvent(_EquipmentEvent, parameters);
|
Equipment.DataCollection.TriggerEvent(_EquipmentEvent, parameters);
|
||||||
if (_UseCyclicalForDescription)
|
if (_UseCyclicalForDescription)
|
||||||
break;
|
break;
|
||||||
@ -350,7 +346,5 @@ namespace MET08RESIMAPCDE.FileHandlers
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// 2021-12-16 -> FileRead
|
// 2022-02-15 -> FileRead
|
@ -2,34 +2,19 @@ using System.Collections.Generic;
|
|||||||
using Ifx.Eaf.EquipmentConnector.File.Component;
|
using Ifx.Eaf.EquipmentConnector.File.Component;
|
||||||
using Ifx.Eaf.EquipmentConnector.File.Configuration;
|
using Ifx.Eaf.EquipmentConnector.File.Configuration;
|
||||||
|
|
||||||
namespace Shared
|
namespace Shared;
|
||||||
{
|
|
||||||
|
|
||||||
public class FilePathGenerator : Ifx.Eaf.EquipmentConnector.File.Component.FilePathGenerator
|
public class FilePathGenerator : Ifx.Eaf.EquipmentConnector.File.Component.FilePathGenerator
|
||||||
{
|
{
|
||||||
|
|
||||||
public FileConnectorConfiguration FileConnectorConfiguration { get; private set; }
|
public FileConnectorConfiguration FileConnectorConfiguration { get; private set; }
|
||||||
|
|
||||||
public FilePathGenerator(FileConnectorConfiguration config, Dictionary<string, string> customPattern = null) : base(config, customPattern)
|
public FilePathGenerator(FileConnectorConfiguration config, Dictionary<string, string> customPattern = null) : base(config, customPattern) => FileConnectorConfiguration = config;
|
||||||
{
|
|
||||||
FileConnectorConfiguration = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FilePathGenerator(FileConnectorConfiguration config, File file, bool isErrorFile = false, Dictionary<string, string> customPattern = null) : base(config, file, isErrorFile, customPattern)
|
public FilePathGenerator(FileConnectorConfiguration config, File file, bool isErrorFile = false, Dictionary<string, string> customPattern = null) : base(config, file, isErrorFile, customPattern) => FileConnectorConfiguration = config;
|
||||||
{
|
|
||||||
FileConnectorConfiguration = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FilePathGenerator(FileConnectorConfiguration config, string sourceFilePath, bool isErrorFile = false, Dictionary<string, string> customPattern = null) : base(config, sourceFilePath, isErrorFile, customPattern)
|
public FilePathGenerator(FileConnectorConfiguration config, string sourceFilePath, bool isErrorFile = false, Dictionary<string, string> customPattern = null) : base(config, sourceFilePath, isErrorFile, customPattern) => FileConnectorConfiguration = config;
|
||||||
{
|
|
||||||
FileConnectorConfiguration = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetSubFolderPath()
|
public string GetSubFolderPath() => SubFolderPath;
|
||||||
{
|
|
||||||
return SubFolderPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Shared
|
namespace Shared;
|
||||||
{
|
|
||||||
|
|
||||||
public class FilePathGeneratorInfo
|
public class FilePathGeneratorInfo
|
||||||
{
|
{
|
||||||
|
|
||||||
public string To { get; protected set; }
|
public string To { get; protected set; }
|
||||||
public string From { get; protected set; }
|
public string From { get; protected set; }
|
||||||
@ -44,7 +43,7 @@ namespace Shared
|
|||||||
#if (true)
|
#if (true)
|
||||||
if (string.IsNullOrEmpty(original.FileConnectorConfiguration.DefaultPlaceHolderValue))
|
if (string.IsNullOrEmpty(original.FileConnectorConfiguration.DefaultPlaceHolderValue))
|
||||||
original.FileConnectorConfiguration.DefaultPlaceHolderValue = "NA";
|
original.FileConnectorConfiguration.DefaultPlaceHolderValue = "NA";
|
||||||
if (!(fileParameter is null) && fileParameter.Count == 1 && To.Contains(original.FileConnectorConfiguration.DefaultPlaceHolderValue))
|
if (fileParameter is not null && fileParameter.Count == 1 && To.Contains(original.FileConnectorConfiguration.DefaultPlaceHolderValue))
|
||||||
{
|
{
|
||||||
foreach (System.Collections.Generic.KeyValuePair<string, string> keyValuePair in fileParameter)
|
foreach (System.Collections.Generic.KeyValuePair<string, string> keyValuePair in fileParameter)
|
||||||
To = To.Replace(string.Concat(original.FileConnectorConfiguration.DefaultPlaceHolderValue), keyValuePair.Value);
|
To = To.Replace(string.Concat(original.FileConnectorConfiguration.DefaultPlaceHolderValue), keyValuePair.Value);
|
||||||
@ -61,6 +60,4 @@ namespace Shared
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,10 @@ using System.Collections.Generic;
|
|||||||
using Eaf.Management.ConfigurationData.CellAutomation;
|
using Eaf.Management.ConfigurationData.CellAutomation;
|
||||||
using Ifx.Eaf.EquipmentConnector.File.Configuration;
|
using Ifx.Eaf.EquipmentConnector.File.Configuration;
|
||||||
|
|
||||||
namespace Shared
|
namespace Shared;
|
||||||
{
|
|
||||||
|
|
||||||
public static class Mapper
|
public static class Mapper
|
||||||
{
|
{
|
||||||
|
|
||||||
internal static Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration Map(FileConnectorConfiguration configuration)
|
internal static Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration Map(FileConnectorConfiguration configuration)
|
||||||
{
|
{
|
||||||
@ -72,6 +71,4 @@ namespace Shared
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user