// 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,333 +24,327 @@ 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 IFileRead _FileRead;
|
||||||
|
private EquipmentEvent _EquipmentEvent;
|
||||||
|
private readonly bool _UseCyclicalForDescription;
|
||||||
|
private FilePathGenerator _FilePathGeneratorForError;
|
||||||
|
private FilePathGenerator _FilePathGeneratorForTarget;
|
||||||
|
private readonly List<EquipmentParameter> _EquipmentParameters;
|
||||||
|
private static readonly Dictionary<string, List<long>> _DummyRuns;
|
||||||
|
|
||||||
|
static FileRead() => _DummyRuns = new Dictionary<string, List<long>>();
|
||||||
|
|
||||||
|
public FileRead()
|
||||||
{
|
{
|
||||||
|
if (FileParameter is null)
|
||||||
|
FileParameter = new Dictionary<string, string>();
|
||||||
|
_FileRead = null;
|
||||||
|
_UseCyclicalForDescription = false;
|
||||||
|
_Log = LogManager.GetLogger(typeof(FileRead));
|
||||||
|
_EquipmentParameters = new List<EquipmentParameter>();
|
||||||
|
}
|
||||||
|
|
||||||
private readonly ILog _Log;
|
public override void CreateSelfDescription()
|
||||||
private IFileRead _FileRead;
|
{
|
||||||
private EquipmentEvent _EquipmentEvent;
|
MethodBase methodBase = new StackFrame().GetMethod();
|
||||||
private readonly bool _UseCyclicalForDescription;
|
_Log.Debug(string.Concat(methodBase.Name, " - Entry"));
|
||||||
private FilePathGenerator _FilePathGeneratorForError;
|
try
|
||||||
private FilePathGenerator _FilePathGeneratorForTarget;
|
|
||||||
private readonly List<EquipmentParameter> _EquipmentParameters;
|
|
||||||
private static readonly Dictionary<string, List<long>> _DummyRuns;
|
|
||||||
|
|
||||||
static FileRead()
|
|
||||||
{
|
{
|
||||||
_DummyRuns = new Dictionary<string, List<long>>();
|
if (Equipment is null)
|
||||||
}
|
|
||||||
|
|
||||||
public FileRead()
|
|
||||||
{
|
|
||||||
if (FileParameter is null)
|
|
||||||
FileParameter = new Dictionary<string, string>();
|
|
||||||
_FileRead = null;
|
|
||||||
_UseCyclicalForDescription = false;
|
|
||||||
_Log = LogManager.GetLogger(typeof(FileRead));
|
|
||||||
_EquipmentParameters = new List<EquipmentParameter>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void CreateSelfDescription()
|
|
||||||
{
|
|
||||||
MethodBase methodBase = new StackFrame().GetMethod();
|
|
||||||
_Log.Debug(string.Concat(methodBase.Name, " - Entry"));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (Equipment is null)
|
|
||||||
throw new Exception();
|
|
||||||
CreateSelfDescription(methodBase);
|
|
||||||
_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 override bool Extract(string reportFullPath, string eventName)
|
|
||||||
{
|
|
||||||
MethodBase methodBase = new StackFrame().GetMethod();
|
|
||||||
_Log.Debug(string.Concat(methodBase.Name, " - Entry - {", reportFullPath, "}"));
|
|
||||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
extractResults = _FileRead.GetExtractResult(reportFullPath, eventName);
|
|
||||||
TriggerEvents(extractResults);
|
|
||||||
_FileRead.Move(extractResults);
|
|
||||||
FilePathGeneratorInfoMove(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(extractResults, exception: ex);
|
|
||||||
FilePathGeneratorInfoMove(extractResults, exception: ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Send(EmailMessage emailMessage)
|
|
||||||
{
|
|
||||||
ISmtp smtp = Backbone.Instance.GetBackboneComponentsOfType<ISmtp>().SingleOrDefault();
|
|
||||||
if (!(smtp is null))
|
|
||||||
smtp.Send(emailMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ISMTP.SendLowPriorityEmailMessage(string subject, string body)
|
|
||||||
{
|
|
||||||
EmailMessage emailMessage = new(subject, body, MailPriority.Low);
|
|
||||||
Send(emailMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ISMTP.SendHighPriorityEmailMessage(string subject, string body)
|
|
||||||
{
|
|
||||||
EmailMessage emailMessage = new(subject, body, MailPriority.High);
|
|
||||||
Send(emailMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ISMTP.SendNormalPriorityEmailMessage(string subject, string body)
|
|
||||||
{
|
|
||||||
EmailMessage emailMessage = new(subject, body, MailPriority.Normal);
|
|
||||||
Send(emailMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddParameterRangeAndEvent()
|
|
||||||
{
|
|
||||||
string description;
|
|
||||||
bool allowNull = false;
|
|
||||||
EquipmentParameter equipmentParameter;
|
|
||||||
JsonProperty[] jsonProperties = _FileRead.GetDefault();
|
|
||||||
Dictionary<string, string> keyValuePairs = _FileRead.GetDisplayNamesJsonElement();
|
|
||||||
Dictionary<JsonValueKind, ParameterTypeDefinition> parameterTypeDefinitions = new();
|
|
||||||
FileConnectorParameterTypeDefinitionProvider fileConnectorParameterTypeDefinitionProvider = new();
|
|
||||||
foreach (ParameterTypeDefinition parameterTypeDefinition in fileConnectorParameterTypeDefinitionProvider.GetAllParameterTypeDefinition())
|
|
||||||
{
|
|
||||||
switch (parameterTypeDefinition.Name)
|
|
||||||
{
|
|
||||||
case nameof(String):
|
|
||||||
parameterTypeDefinitions.Add(JsonValueKind.String, parameterTypeDefinition);
|
|
||||||
break;
|
|
||||||
case nameof(Double):
|
|
||||||
parameterTypeDefinitions.Add(JsonValueKind.Number, parameterTypeDefinition);
|
|
||||||
break;
|
|
||||||
case nameof(Boolean):
|
|
||||||
parameterTypeDefinitions.Add(JsonValueKind.True, parameterTypeDefinition);
|
|
||||||
parameterTypeDefinitions.Add(JsonValueKind.False, parameterTypeDefinition);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (JsonProperty jsonProperty in jsonProperties)
|
|
||||||
{
|
|
||||||
if (jsonProperty.Value.ValueKind == JsonValueKind.Object && !parameterTypeDefinitions.ContainsKey(JsonValueKind.Object))
|
|
||||||
{
|
|
||||||
StructuredType structuredType = new(nameof(StructuredType), string.Empty, new List<Field>());
|
|
||||||
parameterTypeDefinitions.Add(JsonValueKind.Object, structuredType);
|
|
||||||
Equipment.SelfDescriptionBuilder.AddParameterTypeDefinition(structuredType);
|
|
||||||
}
|
|
||||||
if (!parameterTypeDefinitions.ContainsKey(jsonProperty.Value.ValueKind))
|
|
||||||
throw new Exception(string.Concat('{', jsonProperty.Value.ValueKind, "} is not mapped!"));
|
|
||||||
}
|
|
||||||
foreach (JsonProperty jsonProperty in jsonProperties)
|
|
||||||
{
|
|
||||||
if (jsonProperty.Value.ValueKind == JsonValueKind.Null && !allowNull)
|
|
||||||
throw new Exception();
|
|
||||||
if (jsonProperty.Value.ValueKind != JsonValueKind.String || !keyValuePairs.ContainsKey(jsonProperty.Name))
|
|
||||||
description = string.Empty;
|
|
||||||
else
|
|
||||||
description = keyValuePairs[jsonProperty.Name].Split('|')[0];
|
|
||||||
equipmentParameter = new EquipmentParameter(jsonProperty.Name, parameterTypeDefinitions[jsonProperty.Value.ValueKind], description);
|
|
||||||
_EquipmentParameters.Add(equipmentParameter);
|
|
||||||
}
|
|
||||||
Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.AddParameterRange(_EquipmentParameters);
|
|
||||||
_EquipmentEvent = new EquipmentEvent(_FileRead.EventName, _FileRead.GetEventDescription(), _EquipmentParameters);
|
|
||||||
Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.AddEvent(_EquipmentEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateSelfDescription(MethodBase methodBase)
|
|
||||||
{
|
|
||||||
string cellInstanceName;
|
|
||||||
string equipmentTypeName = string.Empty;
|
|
||||||
string equipmentDictionaryName = string.Empty;
|
|
||||||
EquipmentElement equipmentElement = Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.Item;
|
|
||||||
if (Backbone.Instance?.CellName is null)
|
|
||||||
cellInstanceName = string.Empty;
|
|
||||||
else
|
|
||||||
cellInstanceName = Backbone.Instance.CellName;
|
|
||||||
string cellInstanceConnectionName = equipmentElement.Name;
|
|
||||||
FileConnectorConfiguration fileConnectorConfiguration = Mapper.Map(Configuration);
|
|
||||||
string parameterizedModelObjectDefinitionType = methodBase.DeclaringType.FullName;
|
|
||||||
IList<ModelObjectParameterDefinition> modelObjectParameters = Mapper.Map(ConfiguredParameters);
|
|
||||||
_FileRead = CellInstanceConnectionName.Get(this, FileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, _DummyRuns, _UseCyclicalForDescription, isEAFHosted: true);
|
|
||||||
if (_FileRead.IsEvent)
|
|
||||||
AddParameterRangeAndEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private 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 void FilePathGeneratorInfoMove(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception = null)
|
|
||||||
{
|
|
||||||
bool isErrorFile = !(exception is null);
|
|
||||||
object filePathGeneratorInfo = GetFilePathGeneratorInfo(_FileRead.ReportFullPath, isErrorFile);
|
|
||||||
if (!(filePathGeneratorInfo is null) && filePathGeneratorInfo is FilePathGeneratorInfo filePathGenerator)
|
|
||||||
{
|
|
||||||
string[] exceptionLines = _FileRead.Move(extractResults, filePathGenerator.To, filePathGenerator.From, filePathGenerator.ResolvedFileLocation, exception);
|
|
||||||
if (isErrorFile)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
StringBuilder stringBuilder = new();
|
|
||||||
foreach (string item in exceptionLines)
|
|
||||||
stringBuilder.Append("<").Append(item).AppendLine(">");
|
|
||||||
ISmtp smtp = Backbone.Instance.GetBackboneComponentsOfType<ISmtp>().SingleOrDefault();
|
|
||||||
EmailMessage emailMessage = new(_FileRead.ExceptionSubject, stringBuilder.ToString(), MailPriority.High);
|
|
||||||
smtp.Send(emailMessage);
|
|
||||||
}
|
|
||||||
catch (Exception) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ParameterValue> GetParameterValues(List<string> headerNames, JsonElement[] jsonElements, int i)
|
|
||||||
{
|
|
||||||
List<ParameterValue> results = new();
|
|
||||||
if (_UseCyclicalForDescription && i > 0)
|
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
object value;
|
CreateSelfDescription(methodBase);
|
||||||
List<object[]> list;
|
_Log.Debug(string.Concat(methodBase.Name, " - Try - Exit"));
|
||||||
JsonProperty[] jsonProperties = jsonElements[i].EnumerateObject().ToArray();
|
|
||||||
if (jsonProperties.Length != _EquipmentParameters.Count)
|
|
||||||
throw new Exception();
|
|
||||||
for (int p = 0; p < jsonProperties.Length; p++)
|
|
||||||
{
|
|
||||||
if (!_UseCyclicalForDescription || headerNames.Contains(jsonProperties[p].Name))
|
|
||||||
value = jsonProperties[p].Value.ToString();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
list = new List<object[]>();
|
|
||||||
for (int z = 0; z < jsonElements.Length; z++)
|
|
||||||
list.Add(new object[] { z, jsonElements[z].GetProperty(jsonProperties[p].Name).ToString() });
|
|
||||||
value = list;
|
|
||||||
}
|
|
||||||
results.Add(new ParameterValue(_EquipmentParameters[p], value, DateTime.Now));
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
private void TriggerEvents(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults)
|
|
||||||
{
|
{
|
||||||
List<string> headerNames;
|
_Log.Error(string.Concat(methodBase.Name, " - Catch - Entry {", ex.Message, "}", Environment.NewLine, Environment.NewLine, ex.StackTrace));
|
||||||
List<ParameterValue> parameters;
|
long breakAfter = DateTime.Now.AddSeconds(30).Ticks;
|
||||||
if (!_UseCyclicalForDescription)
|
for (short i = 0; i < short.MaxValue; i++)
|
||||||
headerNames = null;
|
|
||||||
else
|
|
||||||
headerNames = _FileRead.GetHeaderNames();
|
|
||||||
for (int i = 0; i < extractResults.Item3.Length; i++)
|
|
||||||
{
|
{
|
||||||
|
if (DateTime.Now.Ticks > breakAfter)
|
||||||
|
break;
|
||||||
|
Thread.Sleep(500);
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Extract(string reportFullPath, string eventName)
|
||||||
|
{
|
||||||
|
MethodBase methodBase = new StackFrame().GetMethod();
|
||||||
|
_Log.Debug(string.Concat(methodBase.Name, " - Entry - {", reportFullPath, "}"));
|
||||||
|
Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
extractResults = _FileRead.GetExtractResult(reportFullPath, eventName);
|
||||||
|
TriggerEvents(extractResults);
|
||||||
|
_FileRead.Move(extractResults);
|
||||||
|
FilePathGeneratorInfoMove(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(extractResults, exception: ex);
|
||||||
|
FilePathGeneratorInfoMove(extractResults, exception: ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Send(EmailMessage emailMessage)
|
||||||
|
{
|
||||||
|
ISmtp smtp = Backbone.Instance.GetBackboneComponentsOfType<ISmtp>().SingleOrDefault();
|
||||||
|
if (smtp is not null)
|
||||||
|
smtp.Send(emailMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ISMTP.SendLowPriorityEmailMessage(string subject, string body)
|
||||||
|
{
|
||||||
|
EmailMessage emailMessage = new(subject, body, MailPriority.Low);
|
||||||
|
Send(emailMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ISMTP.SendHighPriorityEmailMessage(string subject, string body)
|
||||||
|
{
|
||||||
|
EmailMessage emailMessage = new(subject, body, MailPriority.High);
|
||||||
|
Send(emailMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ISMTP.SendNormalPriorityEmailMessage(string subject, string body)
|
||||||
|
{
|
||||||
|
EmailMessage emailMessage = new(subject, body, MailPriority.Normal);
|
||||||
|
Send(emailMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddParameterRangeAndEvent()
|
||||||
|
{
|
||||||
|
string description;
|
||||||
|
bool allowNull = false;
|
||||||
|
EquipmentParameter equipmentParameter;
|
||||||
|
JsonProperty[] jsonProperties = _FileRead.GetDefault();
|
||||||
|
Dictionary<string, string> keyValuePairs = _FileRead.GetDisplayNamesJsonElement();
|
||||||
|
Dictionary<JsonValueKind, ParameterTypeDefinition> parameterTypeDefinitions = new();
|
||||||
|
FileConnectorParameterTypeDefinitionProvider fileConnectorParameterTypeDefinitionProvider = new();
|
||||||
|
foreach (ParameterTypeDefinition parameterTypeDefinition in fileConnectorParameterTypeDefinitionProvider.GetAllParameterTypeDefinition())
|
||||||
|
{
|
||||||
|
switch (parameterTypeDefinition.Name)
|
||||||
|
{
|
||||||
|
case nameof(String):
|
||||||
|
parameterTypeDefinitions.Add(JsonValueKind.String, parameterTypeDefinition);
|
||||||
|
break;
|
||||||
|
case nameof(Double):
|
||||||
|
parameterTypeDefinitions.Add(JsonValueKind.Number, parameterTypeDefinition);
|
||||||
|
break;
|
||||||
|
case nameof(Boolean):
|
||||||
|
parameterTypeDefinitions.Add(JsonValueKind.True, parameterTypeDefinition);
|
||||||
|
parameterTypeDefinitions.Add(JsonValueKind.False, parameterTypeDefinition);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (JsonProperty jsonProperty in jsonProperties)
|
||||||
|
{
|
||||||
|
if (jsonProperty.Value.ValueKind == JsonValueKind.Object && !parameterTypeDefinitions.ContainsKey(JsonValueKind.Object))
|
||||||
|
{
|
||||||
|
StructuredType structuredType = new(nameof(StructuredType), string.Empty, new List<Field>());
|
||||||
|
parameterTypeDefinitions.Add(JsonValueKind.Object, structuredType);
|
||||||
|
Equipment.SelfDescriptionBuilder.AddParameterTypeDefinition(structuredType);
|
||||||
|
}
|
||||||
|
if (!parameterTypeDefinitions.ContainsKey(jsonProperty.Value.ValueKind))
|
||||||
|
throw new Exception(string.Concat('{', jsonProperty.Value.ValueKind, "} is not mapped!"));
|
||||||
|
}
|
||||||
|
foreach (JsonProperty jsonProperty in jsonProperties)
|
||||||
|
{
|
||||||
|
if (jsonProperty.Value.ValueKind == JsonValueKind.Null && !allowNull)
|
||||||
|
throw new Exception();
|
||||||
|
if (jsonProperty.Value.ValueKind != JsonValueKind.String || !keyValuePairs.ContainsKey(jsonProperty.Name))
|
||||||
|
description = string.Empty;
|
||||||
|
else
|
||||||
|
description = keyValuePairs[jsonProperty.Name].Split('|')[0];
|
||||||
|
equipmentParameter = new EquipmentParameter(jsonProperty.Name, parameterTypeDefinitions[jsonProperty.Value.ValueKind], description);
|
||||||
|
_EquipmentParameters.Add(equipmentParameter);
|
||||||
|
}
|
||||||
|
_ = Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.AddParameterRange(_EquipmentParameters);
|
||||||
|
_EquipmentEvent = new EquipmentEvent(_FileRead.EventName, _FileRead.GetEventDescription(), _EquipmentParameters);
|
||||||
|
_ = Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.AddEvent(_EquipmentEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateSelfDescription(MethodBase methodBase)
|
||||||
|
{
|
||||||
|
string cellInstanceName;
|
||||||
|
string equipmentTypeName = string.Empty;
|
||||||
|
string equipmentDictionaryName = string.Empty;
|
||||||
|
EquipmentElement equipmentElement = Equipment.SelfDescriptionBuilder.RootEquipmentElementBuilder.Item;
|
||||||
|
if (Backbone.Instance?.CellName is null)
|
||||||
|
cellInstanceName = string.Empty;
|
||||||
|
else
|
||||||
|
cellInstanceName = Backbone.Instance.CellName;
|
||||||
|
string cellInstanceConnectionName = equipmentElement.Name;
|
||||||
|
FileConnectorConfiguration fileConnectorConfiguration = Mapper.Map(Configuration);
|
||||||
|
string parameterizedModelObjectDefinitionType = methodBase.DeclaringType.FullName;
|
||||||
|
IList<ModelObjectParameterDefinition> modelObjectParameters = Mapper.Map(ConfiguredParameters);
|
||||||
|
_FileRead = CellInstanceConnectionName.Get(this, FileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, _DummyRuns, _UseCyclicalForDescription, isEAFHosted: true);
|
||||||
|
if (_FileRead.IsEvent)
|
||||||
|
AddParameterRangeAndEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private 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 void FilePathGeneratorInfoMove(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception = null)
|
||||||
|
{
|
||||||
|
bool isErrorFile = exception is not null;
|
||||||
|
object filePathGeneratorInfo = GetFilePathGeneratorInfo(_FileRead.ReportFullPath, isErrorFile);
|
||||||
|
if (filePathGeneratorInfo is not null and FilePathGeneratorInfo filePathGenerator)
|
||||||
|
{
|
||||||
|
string[] exceptionLines = _FileRead.Move(extractResults, filePathGenerator.To, filePathGenerator.From, filePathGenerator.ResolvedFileLocation, exception);
|
||||||
|
if (isErrorFile)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StringBuilder stringBuilder = new();
|
||||||
|
foreach (string item in exceptionLines)
|
||||||
|
_ = stringBuilder.Append("<").Append(item).AppendLine(">");
|
||||||
|
ISmtp smtp = Backbone.Instance.GetBackboneComponentsOfType<ISmtp>().SingleOrDefault();
|
||||||
|
EmailMessage emailMessage = new(_FileRead.ExceptionSubject, stringBuilder.ToString(), MailPriority.High);
|
||||||
|
smtp.Send(emailMessage);
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ParameterValue> GetParameterValues(List<string> headerNames, JsonElement[] jsonElements, int i)
|
||||||
|
{
|
||||||
|
List<ParameterValue> results = new();
|
||||||
|
if (_UseCyclicalForDescription && i > 0)
|
||||||
|
throw new Exception();
|
||||||
|
object value;
|
||||||
|
List<object[]> list;
|
||||||
|
JsonProperty[] jsonProperties = jsonElements[i].EnumerateObject().ToArray();
|
||||||
|
if (jsonProperties.Length != _EquipmentParameters.Count)
|
||||||
|
throw new Exception();
|
||||||
|
for (int p = 0; p < jsonProperties.Length; p++)
|
||||||
|
{
|
||||||
|
if (!_UseCyclicalForDescription || headerNames.Contains(jsonProperties[p].Name))
|
||||||
|
value = jsonProperties[p].Value.ToString();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list = new List<object[]>();
|
||||||
|
for (int z = 0; z < jsonElements.Length; z++)
|
||||||
|
list.Add(new object[] { z, jsonElements[z].GetProperty(jsonProperties[p].Name).ToString() });
|
||||||
|
value = list;
|
||||||
|
}
|
||||||
|
results.Add(new ParameterValue(_EquipmentParameters[p], value, DateTime.Now));
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TriggerEvents(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults)
|
||||||
|
{
|
||||||
|
List<string> headerNames;
|
||||||
|
List<ParameterValue> parameters;
|
||||||
|
if (!_UseCyclicalForDescription)
|
||||||
|
headerNames = null;
|
||||||
|
else
|
||||||
|
headerNames = _FileRead.GetHeaderNames();
|
||||||
|
for (int i = 0; i < extractResults.Item3.Length; i++)
|
||||||
|
{
|
||||||
|
if (_EquipmentEvent is not null)
|
||||||
|
{
|
||||||
|
_Log.Debug(string.Concat("TriggerEvent - {", _FileRead.ReportFullPath, "} ", i, " of ", extractResults.Item3.Length));
|
||||||
|
parameters = GetParameterValues(headerNames, extractResults.Item3, i);
|
||||||
if (_EquipmentEvent is not null)
|
if (_EquipmentEvent is not null)
|
||||||
{
|
Equipment.DataCollection.TriggerEvent(_EquipmentEvent, parameters);
|
||||||
_Log.Debug(string.Concat("TriggerEvent - {", _FileRead.ReportFullPath, "} ", i, " of ", extractResults.Item3.Length));
|
if (_UseCyclicalForDescription)
|
||||||
parameters = GetParameterValues(headerNames, extractResults.Item3, i);
|
break;
|
||||||
if (!(_EquipmentEvent is null))
|
|
||||||
Equipment.DataCollection.TriggerEvent(_EquipmentEvent, parameters);
|
|
||||||
if (_UseCyclicalForDescription)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Tuple<string, Test[], JsonElement[], List<FileInfo>> ReExtract(string json)
|
public Tuple<string, Test[], JsonElement[], List<FileInfo>> ReExtract(string json)
|
||||||
|
{
|
||||||
|
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||||
|
string cellInstanceName;
|
||||||
|
if (!json.Contains(nameof(cellInstanceName)))
|
||||||
|
throw new Exception();
|
||||||
|
string equipmentTypeName;
|
||||||
|
if (!json.Contains(nameof(equipmentTypeName)))
|
||||||
|
throw new Exception();
|
||||||
|
string equipmentDictionaryName;
|
||||||
|
if (!json.Contains(nameof(equipmentDictionaryName)))
|
||||||
|
throw new Exception();
|
||||||
|
string cellInstanceConnectionName;
|
||||||
|
if (!json.Contains(nameof(cellInstanceConnectionName)))
|
||||||
|
throw new Exception();
|
||||||
|
if (!json.Contains(nameof(FileConnectorConfiguration)))
|
||||||
|
throw new Exception();
|
||||||
|
if (!json.Contains(nameof(IList<ModelObjectParameterDefinition>)))
|
||||||
|
throw new Exception();
|
||||||
|
string parameterizedModelObjectDefinitionType;
|
||||||
|
if (!json.Contains(nameof(parameterizedModelObjectDefinitionType)))
|
||||||
|
throw new Exception();
|
||||||
|
Dictionary<string, List<long>> dummyRuns = new();
|
||||||
|
Dictionary<string, string> fileParameter = new();
|
||||||
|
MethodBase methodBase = new StackFrame().GetMethod();
|
||||||
|
JsonElement jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
|
||||||
|
cellInstanceName = jsonElement.GetProperty(nameof(cellInstanceName)).ToString();
|
||||||
|
equipmentTypeName = jsonElement.GetProperty(nameof(equipmentTypeName)).ToString();
|
||||||
|
equipmentDictionaryName = jsonElement.GetProperty(nameof(equipmentDictionaryName)).ToString();
|
||||||
|
cellInstanceConnectionName = jsonElement.GetProperty(nameof(cellInstanceConnectionName)).ToString();
|
||||||
|
JsonElement fileConnectorConfigurationJsonElement = jsonElement.GetProperty(nameof(FileConnectorConfiguration));
|
||||||
|
parameterizedModelObjectDefinitionType = jsonElement.GetProperty(nameof(parameterizedModelObjectDefinitionType)).ToString();
|
||||||
|
if (fileConnectorConfigurationJsonElement.ValueKind != JsonValueKind.Object)
|
||||||
|
throw new Exception();
|
||||||
|
JsonSerializerOptions jsonSerializerOptions = new() { Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) } };
|
||||||
|
FileConnectorConfiguration fileConnectorConfiguration = JsonSerializer.Deserialize<FileConnectorConfiguration>(fileConnectorConfigurationJsonElement.ToString(), jsonSerializerOptions);
|
||||||
|
JsonElement modelObjectParameterDefinitionJsonElement = jsonElement.GetProperty(nameof(IList<ModelObjectParameterDefinition>));
|
||||||
|
if (modelObjectParameterDefinitionJsonElement.ValueKind != JsonValueKind.Array)
|
||||||
|
throw new Exception();
|
||||||
|
IList<ModelObjectParameterDefinition> modelObjectParameters = JsonSerializer.Deserialize<IList<ModelObjectParameterDefinition>>(modelObjectParameterDefinitionJsonElement.ToString(), jsonSerializerOptions);
|
||||||
|
_FileRead = CellInstanceConnectionName.Get(this, FileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, _DummyRuns, _UseCyclicalForDescription, isEAFHosted: false);
|
||||||
|
results = _FileRead.ReExtract();
|
||||||
|
if (results?.Item2 is null)
|
||||||
|
throw new Exception();
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
TriggerEvents(results);
|
||||||
string cellInstanceName;
|
_FileRead.Move(results);
|
||||||
if (!json.Contains(nameof(cellInstanceName)))
|
FilePathGeneratorInfoMove(results);
|
||||||
throw new Exception();
|
|
||||||
string equipmentTypeName;
|
|
||||||
if (!json.Contains(nameof(equipmentTypeName)))
|
|
||||||
throw new Exception();
|
|
||||||
string equipmentDictionaryName;
|
|
||||||
if (!json.Contains(nameof(equipmentDictionaryName)))
|
|
||||||
throw new Exception();
|
|
||||||
string cellInstanceConnectionName;
|
|
||||||
if (!json.Contains(nameof(cellInstanceConnectionName)))
|
|
||||||
throw new Exception();
|
|
||||||
if (!json.Contains(nameof(FileConnectorConfiguration)))
|
|
||||||
throw new Exception();
|
|
||||||
if (!json.Contains(nameof(IList<ModelObjectParameterDefinition>)))
|
|
||||||
throw new Exception();
|
|
||||||
string parameterizedModelObjectDefinitionType;
|
|
||||||
if (!json.Contains(nameof(parameterizedModelObjectDefinitionType)))
|
|
||||||
throw new Exception();
|
|
||||||
Dictionary<string, List<long>> dummyRuns = new();
|
|
||||||
Dictionary<string, string> fileParameter = new();
|
|
||||||
MethodBase methodBase = new StackFrame().GetMethod();
|
|
||||||
JsonElement jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
|
|
||||||
cellInstanceName = jsonElement.GetProperty(nameof(cellInstanceName)).ToString();
|
|
||||||
equipmentTypeName = jsonElement.GetProperty(nameof(equipmentTypeName)).ToString();
|
|
||||||
equipmentDictionaryName = jsonElement.GetProperty(nameof(equipmentDictionaryName)).ToString();
|
|
||||||
cellInstanceConnectionName = jsonElement.GetProperty(nameof(cellInstanceConnectionName)).ToString();
|
|
||||||
JsonElement fileConnectorConfigurationJsonElement = jsonElement.GetProperty(nameof(FileConnectorConfiguration));
|
|
||||||
parameterizedModelObjectDefinitionType = jsonElement.GetProperty(nameof(parameterizedModelObjectDefinitionType)).ToString();
|
|
||||||
if (fileConnectorConfigurationJsonElement.ValueKind != JsonValueKind.Object)
|
|
||||||
throw new Exception();
|
|
||||||
JsonSerializerOptions jsonSerializerOptions = new() { Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) } };
|
|
||||||
FileConnectorConfiguration fileConnectorConfiguration = JsonSerializer.Deserialize<FileConnectorConfiguration>(fileConnectorConfigurationJsonElement.ToString(), jsonSerializerOptions);
|
|
||||||
JsonElement modelObjectParameterDefinitionJsonElement = jsonElement.GetProperty(nameof(IList<ModelObjectParameterDefinition>));
|
|
||||||
if (modelObjectParameterDefinitionJsonElement.ValueKind != JsonValueKind.Array)
|
|
||||||
throw new Exception();
|
|
||||||
IList<ModelObjectParameterDefinition> modelObjectParameters = JsonSerializer.Deserialize<IList<ModelObjectParameterDefinition>>(modelObjectParameterDefinitionJsonElement.ToString(), jsonSerializerOptions);
|
|
||||||
_FileRead = CellInstanceConnectionName.Get(this, FileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, _DummyRuns, _UseCyclicalForDescription, isEAFHosted: false);
|
|
||||||
results = _FileRead.ReExtract();
|
|
||||||
if (results?.Item2 is null)
|
|
||||||
throw new Exception();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TriggerEvents(results);
|
|
||||||
_FileRead.Move(results);
|
|
||||||
FilePathGeneratorInfoMove(results);
|
|
||||||
}
|
|
||||||
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) => FileConnectorConfiguration = config;
|
||||||
|
|
||||||
public FilePathGenerator(FileConnectorConfiguration config, Dictionary<string, string> customPattern = null) : base(config, 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, File file, bool isErrorFile = false, Dictionary<string, string> customPattern = null) : base(config, file, 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 FilePathGenerator(FileConnectorConfiguration config, string sourceFilePath, bool isErrorFile = false, Dictionary<string, string> customPattern = null) : base(config, sourceFilePath, isErrorFile, customPattern)
|
public string GetSubFolderPath() => SubFolderPath;
|
||||||
{
|
|
||||||
FileConnectorConfiguration = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetSubFolderPath()
|
|
||||||
{
|
|
||||||
return SubFolderPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,66 +1,63 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Shared
|
namespace Shared;
|
||||||
|
|
||||||
|
public class FilePathGeneratorInfo
|
||||||
{
|
{
|
||||||
|
|
||||||
public class FilePathGeneratorInfo
|
public string To { get; protected set; }
|
||||||
|
public string From { get; protected set; }
|
||||||
|
public bool IsErrorFile { get; protected set; }
|
||||||
|
public string SubFolderPath { get; protected set; }
|
||||||
|
public string FirstDirectory { get; protected set; }
|
||||||
|
public string ReportFullPath { get; protected set; }
|
||||||
|
public string ResolvedFileLocation { get; protected set; }
|
||||||
|
|
||||||
|
public FilePathGeneratorInfo(object originalFilePathGenerator, string reportFullPath, bool isErrorFile, System.Collections.Generic.Dictionary<string, string> fileParameter)
|
||||||
{
|
{
|
||||||
|
ReportFullPath = reportFullPath;
|
||||||
public string To { get; protected set; }
|
IsErrorFile = isErrorFile;
|
||||||
public string From { get; protected set; }
|
if (originalFilePathGenerator is null || originalFilePathGenerator is not FilePathGenerator original)
|
||||||
public bool IsErrorFile { get; protected set; }
|
|
||||||
public string SubFolderPath { get; protected set; }
|
|
||||||
public string FirstDirectory { get; protected set; }
|
|
||||||
public string ReportFullPath { get; protected set; }
|
|
||||||
public string ResolvedFileLocation { get; protected set; }
|
|
||||||
|
|
||||||
public FilePathGeneratorInfo(object originalFilePathGenerator, string reportFullPath, bool isErrorFile, System.Collections.Generic.Dictionary<string, string> fileParameter)
|
|
||||||
{
|
{
|
||||||
ReportFullPath = reportFullPath;
|
FirstDirectory = string.Empty;
|
||||||
IsErrorFile = isErrorFile;
|
ResolvedFileLocation = string.Empty;
|
||||||
if (originalFilePathGenerator is null || originalFilePathGenerator is not FilePathGenerator original)
|
To = string.Empty;
|
||||||
{
|
From = string.Empty;
|
||||||
FirstDirectory = string.Empty;
|
}
|
||||||
ResolvedFileLocation = string.Empty;
|
else
|
||||||
To = string.Empty;
|
{
|
||||||
From = string.Empty;
|
string directorySeparatorChar = Path.DirectorySeparatorChar.ToString();
|
||||||
}
|
FilePathGenerator filePathGenerator = new(original.FileConnectorConfiguration, reportFullPath, isErrorFile);
|
||||||
else
|
SubFolderPath = filePathGenerator.GetSubFolderPath();
|
||||||
{
|
if (string.IsNullOrEmpty(SubFolderPath))
|
||||||
string directorySeparatorChar = Path.DirectorySeparatorChar.ToString();
|
FirstDirectory = SubFolderPath;
|
||||||
FilePathGenerator filePathGenerator = new(original.FileConnectorConfiguration, reportFullPath, isErrorFile);
|
else
|
||||||
SubFolderPath = filePathGenerator.GetSubFolderPath();
|
FirstDirectory = SubFolderPath.Split(Path.DirectorySeparatorChar)[0];
|
||||||
if (string.IsNullOrEmpty(SubFolderPath))
|
ResolvedFileLocation = filePathGenerator.GetTargetFolder();
|
||||||
FirstDirectory = SubFolderPath;
|
if (string.IsNullOrEmpty(ResolvedFileLocation) && string.IsNullOrEmpty(SubFolderPath))
|
||||||
else
|
To = string.Empty;
|
||||||
FirstDirectory = SubFolderPath.Split(Path.DirectorySeparatorChar)[0];
|
else if (string.IsNullOrEmpty(SubFolderPath))
|
||||||
ResolvedFileLocation = filePathGenerator.GetTargetFolder();
|
To = ResolvedFileLocation;
|
||||||
if (string.IsNullOrEmpty(ResolvedFileLocation) && string.IsNullOrEmpty(SubFolderPath))
|
else
|
||||||
To = string.Empty;
|
To = string.Concat(ResolvedFileLocation.Replace(SubFolderPath, string.Empty), Path.DirectorySeparatorChar, FirstDirectory);
|
||||||
else if (string.IsNullOrEmpty(SubFolderPath))
|
#if (true)
|
||||||
To = ResolvedFileLocation;
|
if (string.IsNullOrEmpty(original.FileConnectorConfiguration.DefaultPlaceHolderValue))
|
||||||
else
|
original.FileConnectorConfiguration.DefaultPlaceHolderValue = "NA";
|
||||||
To = string.Concat(ResolvedFileLocation.Replace(SubFolderPath, string.Empty), Path.DirectorySeparatorChar, FirstDirectory);
|
if (fileParameter is not null && fileParameter.Count == 1 && To.Contains(original.FileConnectorConfiguration.DefaultPlaceHolderValue))
|
||||||
#if (true)
|
{
|
||||||
if (string.IsNullOrEmpty(original.FileConnectorConfiguration.DefaultPlaceHolderValue))
|
foreach (System.Collections.Generic.KeyValuePair<string, string> keyValuePair in fileParameter)
|
||||||
original.FileConnectorConfiguration.DefaultPlaceHolderValue = "NA";
|
To = To.Replace(string.Concat(original.FileConnectorConfiguration.DefaultPlaceHolderValue), keyValuePair.Value);
|
||||||
if (!(fileParameter is null) && fileParameter.Count == 1 && To.Contains(original.FileConnectorConfiguration.DefaultPlaceHolderValue))
|
}
|
||||||
{
|
#endif
|
||||||
foreach (System.Collections.Generic.KeyValuePair<string, string> keyValuePair in fileParameter)
|
if (original.FileConnectorConfiguration.SourceFileLocation.EndsWith(directorySeparatorChar))
|
||||||
To = To.Replace(string.Concat(original.FileConnectorConfiguration.DefaultPlaceHolderValue), keyValuePair.Value);
|
From = string.Concat(original.FileConnectorConfiguration.SourceFileLocation, FirstDirectory);
|
||||||
}
|
else
|
||||||
#endif
|
From = string.Concat(original.FileConnectorConfiguration.SourceFileLocation, Path.DirectorySeparatorChar, FirstDirectory);
|
||||||
if (original.FileConnectorConfiguration.SourceFileLocation.EndsWith(directorySeparatorChar))
|
if (From.EndsWith(directorySeparatorChar) && !To.EndsWith(directorySeparatorChar))
|
||||||
From = string.Concat(original.FileConnectorConfiguration.SourceFileLocation, FirstDirectory);
|
To = string.Concat(To, Path.DirectorySeparatorChar);
|
||||||
else
|
else if (To.EndsWith(directorySeparatorChar) && !From.EndsWith(directorySeparatorChar))
|
||||||
From = string.Concat(original.FileConnectorConfiguration.SourceFileLocation, Path.DirectorySeparatorChar, FirstDirectory);
|
To = To.Remove(To.Length - 1, 1);
|
||||||
if (From.EndsWith(directorySeparatorChar) && !To.EndsWith(directorySeparatorChar))
|
|
||||||
To = string.Concat(To, Path.DirectorySeparatorChar);
|
|
||||||
else if (To.EndsWith(directorySeparatorChar) && !From.EndsWith(directorySeparatorChar))
|
|
||||||
To = To.Remove(To.Length - 1, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
123
Shared/Mapper.cs
123
Shared/Mapper.cs
@ -2,76 +2,73 @@ 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)
|
||||||
{
|
{
|
||||||
|
Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration result = new()
|
||||||
internal static Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration Map(FileConnectorConfiguration configuration)
|
|
||||||
{
|
{
|
||||||
Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration result = new()
|
AlternateTargetFolder = configuration.AlternateTargetFolder,
|
||||||
{
|
ConnectionRetryInterval = configuration.ConnectionRetryInterval,
|
||||||
AlternateTargetFolder = configuration.AlternateTargetFolder,
|
ConnectionSettings = new List<Adaptation.Ifx.Eaf.Common.Configuration.ConnectionSetting>(),
|
||||||
ConnectionRetryInterval = configuration.ConnectionRetryInterval,
|
CopySourceFolderStructure = configuration.CopySourceFolderStructure,
|
||||||
ConnectionSettings = new List<Adaptation.Ifx.Eaf.Common.Configuration.ConnectionSetting>(),
|
DefaultPlaceHolderValue = configuration.DefaultPlaceHolderValue,
|
||||||
CopySourceFolderStructure = configuration.CopySourceFolderStructure,
|
//DeleteAbandonedEmptySourceSubFolders = configuration.DeleteAbandonedEmptySourceSubFolders,
|
||||||
DefaultPlaceHolderValue = configuration.DefaultPlaceHolderValue,
|
DeleteEmptySourceSubFolders = configuration.DeleteEmptySourceSubFolders,
|
||||||
//DeleteAbandonedEmptySourceSubFolders = configuration.DeleteAbandonedEmptySourceSubFolders,
|
ErrorPostProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PostProcessingModeEnum)configuration.ErrorPostProcessingMode,
|
||||||
DeleteEmptySourceSubFolders = configuration.DeleteEmptySourceSubFolders,
|
ErrorTargetFileLocation = configuration.ErrorTargetFileLocation,
|
||||||
ErrorPostProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PostProcessingModeEnum)configuration.ErrorPostProcessingMode,
|
ErrorTargetFileName = configuration.ErrorTargetFileName,
|
||||||
ErrorTargetFileLocation = configuration.ErrorTargetFileLocation,
|
FileAgeFilterMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.FileAgeFilterEnum)configuration.FileAgeFilterMode,
|
||||||
ErrorTargetFileName = configuration.ErrorTargetFileName,
|
FileAgeThreshold = configuration.FileAgeThreshold,
|
||||||
FileAgeFilterMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.FileAgeFilterEnum)configuration.FileAgeFilterMode,
|
//FileHandlers = configuration.FileHandlers,
|
||||||
FileAgeThreshold = configuration.FileAgeThreshold,
|
FileHandleTimeout = (long)configuration.FileHandleTimeout,
|
||||||
//FileHandlers = configuration.FileHandlers,
|
FileHandleWaitTime = configuration.FileHandleWaitTime,
|
||||||
FileHandleTimeout = (long)configuration.FileHandleTimeout,
|
FileScanningIntervalInSeconds = configuration.FileScanningIntervalInSeconds,
|
||||||
FileHandleWaitTime = configuration.FileHandleWaitTime,
|
FileScanningOption = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.FileScanningOptionEnum)configuration.FileScanningOption,
|
||||||
FileScanningIntervalInSeconds = configuration.FileScanningIntervalInSeconds,
|
FolderAgeCheckIndividualSubFolders = configuration.FolderAgeCheckIndividualSubFolders,
|
||||||
FileScanningOption = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.FileScanningOptionEnum)configuration.FileScanningOption,
|
FolderAgeThreshold = configuration.FolderAgeThreshold,
|
||||||
FolderAgeCheckIndividualSubFolders = configuration.FolderAgeCheckIndividualSubFolders,
|
//FolderOperationsSubFolderLevel = configuration.FolderOperationsSubFolderLevel,
|
||||||
FolderAgeThreshold = configuration.FolderAgeThreshold,
|
IdleEventWaitTimeInSeconds = (long)configuration.IdleEventWaitTimeInSeconds,
|
||||||
//FolderOperationsSubFolderLevel = configuration.FolderOperationsSubFolderLevel,
|
IfFileExistAction = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.IfFileExistEnum)configuration.IfFileExistAction,
|
||||||
IdleEventWaitTimeInSeconds = (long)configuration.IdleEventWaitTimeInSeconds,
|
IfPostProcessingFailsAction = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.IfPostProcessingFailsEnum)configuration.IfPostProcessingFailsAction,
|
||||||
IfFileExistAction = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.IfFileExistEnum)configuration.IfFileExistAction,
|
IncludeSubDirectories = configuration.IncludeSubDirectories,
|
||||||
IfPostProcessingFailsAction = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.IfPostProcessingFailsEnum)configuration.IfPostProcessingFailsAction,
|
PostProcessingRetries = configuration.PostProcessingRetries,
|
||||||
IncludeSubDirectories = configuration.IncludeSubDirectories,
|
PreProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PreProcessingModeEnum)configuration.PreProcessingMode,
|
||||||
PostProcessingRetries = configuration.PostProcessingRetries,
|
PostProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PostProcessingModeEnum)configuration.PostProcessingMode,
|
||||||
PreProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PreProcessingModeEnum)configuration.PreProcessingMode,
|
SourceDirectoryCloaking = configuration.SourceDirectoryCloaking,
|
||||||
PostProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PostProcessingModeEnum)configuration.PostProcessingMode,
|
SourceFileFilter = configuration.SourceFileFilter,
|
||||||
SourceDirectoryCloaking = configuration.SourceDirectoryCloaking,
|
SourceFileFilters = configuration.SourceFileFilters,
|
||||||
SourceFileFilter = configuration.SourceFileFilter,
|
SourceFileLocation = configuration.SourceFileLocation,
|
||||||
SourceFileFilters = configuration.SourceFileFilters,
|
TargetFileLocation = configuration.TargetFileLocation,
|
||||||
SourceFileLocation = configuration.SourceFileLocation,
|
TargetFileName = configuration.TargetFileName,
|
||||||
TargetFileLocation = configuration.TargetFileLocation,
|
TriggerOnChanged = configuration.TriggerOnChanged,
|
||||||
TargetFileName = configuration.TargetFileName,
|
TriggerOnCreated = configuration.TriggerOnCreated,
|
||||||
TriggerOnChanged = configuration.TriggerOnChanged,
|
UseZip64Mode = configuration.UseZip64Mode,
|
||||||
TriggerOnCreated = configuration.TriggerOnCreated,
|
ZipErrorTargetFileName = configuration.ZipErrorTargetFileName,
|
||||||
UseZip64Mode = configuration.UseZip64Mode,
|
ZipFileAmount = configuration.ZipFileAmount,
|
||||||
ZipErrorTargetFileName = configuration.ZipErrorTargetFileName,
|
ZipFileSubFolderLevel = configuration.ZipFileSubFolderLevel,
|
||||||
ZipFileAmount = configuration.ZipFileAmount,
|
ZipFileTime = configuration.ZipFileTime,
|
||||||
ZipFileSubFolderLevel = configuration.ZipFileSubFolderLevel,
|
ZipMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.ZipModeEnum)configuration.ZipMode,
|
||||||
ZipFileTime = configuration.ZipFileTime,
|
ZipTargetFileName = configuration.ZipTargetFileName,
|
||||||
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));
|
||||||
foreach (Ifx.Eaf.Common.Configuration.ConnectionSetting connectionSetting in configuration.ConnectionSettings)
|
return result;
|
||||||
result.ConnectionSettings.Add(new Adaptation.Ifx.Eaf.Common.Configuration.ConnectionSetting(connectionSetting.Name, connectionSetting.Value));
|
}
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static IList<Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition> Map(IList<ModelObjectParameterDefinition> configuredParameters)
|
internal static IList<Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition> Map(IList<ModelObjectParameterDefinition> configuredParameters)
|
||||||
|
{
|
||||||
|
List<Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition> results = new();
|
||||||
|
Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterType modelObjectParameterType;
|
||||||
|
for (int i = 0; i < configuredParameters.Count; i++)
|
||||||
{
|
{
|
||||||
List<Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition> results = new();
|
modelObjectParameterType = (Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterType)configuredParameters[i].ValueType;
|
||||||
Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterType modelObjectParameterType;
|
results.Add(new Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition() { Id = i, Name = configuredParameters[i].Name, Value = configuredParameters[i].Value, ValueType = modelObjectParameterType, EnumType = modelObjectParameterType.ToString() });
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user