Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
c3c4564548 | |||
67bde58b17 | |||
23d2250c5f | |||
468890e5f4 | |||
b1696afd26 | |||
b0b5033314 | |||
21aaf804ee |
64
Adaptation/.vscode/launch.json
vendored
64
Adaptation/.vscode/launch.json
vendored
@ -1,43 +1,43 @@
|
|||||||
{
|
{
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"mode": "debug",
|
|
||||||
"name": "Go launch file",
|
"name": "Go launch file",
|
||||||
"program": "${file}",
|
"type": "go",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "go"
|
"mode": "debug",
|
||||||
},
|
"program": "${file}"
|
||||||
{
|
|
||||||
"name": "node Launch Current Opened File",
|
|
||||||
"program": "${file}",
|
|
||||||
"request": "launch",
|
|
||||||
"type": "node"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cwd": "${workspaceFolder}",
|
|
||||||
"internalConsoleOptions": "neverOpen",
|
|
||||||
"name": "Debug File",
|
|
||||||
"program": "${file}",
|
|
||||||
"request": "launch",
|
|
||||||
"stopOnEntry": false,
|
|
||||||
"type": "bun",
|
|
||||||
"watchMode": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cwd": "${workspaceFolder}",
|
|
||||||
"internalConsoleOptions": "neverOpen",
|
|
||||||
"name": "Run File",
|
|
||||||
"noDebug": true,
|
|
||||||
"program": "${file}",
|
|
||||||
"request": "launch",
|
|
||||||
"type": "bun",
|
|
||||||
"watchMode": false
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": ".NET Core Attach",
|
"name": ".NET Core Attach",
|
||||||
"processId": 32760,
|
"type": "coreclr",
|
||||||
"request": "attach",
|
"request": "attach",
|
||||||
"type": "coreclr"
|
"processId": 32760
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "node Launch Current Opened File",
|
||||||
|
"program": "${file}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bun",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug File",
|
||||||
|
"program": "${file}",
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"stopOnEntry": false,
|
||||||
|
"watchMode": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bun",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Run File",
|
||||||
|
"program": "${file}",
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"noDebug": true,
|
||||||
|
"watchMode": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyAndWriteFile(string reportFullPath, ProcessDataStandardFormat processDataStandardFormat, JsonElement[] jsonElements)
|
private void CopyAndMoveFile(JsonElement[] jsonElements)
|
||||||
{
|
{
|
||||||
string day = $"{_Logistics.DateTimeFromSequence:yyyy-MM-dd}";
|
string day = $"{_Logistics.DateTimeFromSequence:yyyy-MM-dd}";
|
||||||
string segment = _Logistics.FileInfo.Name.Split('-')[0].Split('_')[0];
|
string segment = _Logistics.FileInfo.Name.Split('-')[0].Split('_')[0];
|
||||||
@ -127,15 +127,15 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Six six = JsonSerializer.Deserialize(jsonElements[0].GetRawText(), SixSourceGenerationContext.Default.Six) ?? throw new Exception($"{nameof(Six)} deserialization failed");
|
Six six = JsonSerializer.Deserialize(jsonElements[0].GetRawText(), SixSourceGenerationContext.Default.Six) ?? throw new Exception($"{nameof(Six)} deserialization failed");
|
||||||
File.Delete(_Logistics.FileInfo.FullName);
|
if (six.VP12Count < _IQSVP12Count)
|
||||||
if (six.VP12Count > _IQSVP12Count)
|
File.Delete(_Logistics.FileInfo.FullName);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
string duplicateDirectory = Path.Combine(_FileConnectorConfiguration.SourceFileLocation, _CellInstanceName);
|
string duplicateDirectory = Path.Combine(_FileConnectorConfiguration.SourceFileLocation, _CellInstanceName);
|
||||||
if (!Directory.Exists(duplicateDirectory))
|
if (!Directory.Exists(duplicateDirectory))
|
||||||
_ = Directory.CreateDirectory(duplicateDirectory);
|
_ = Directory.CreateDirectory(duplicateDirectory);
|
||||||
string duplicateFile = Path.Combine(duplicateDirectory, $"{Path.GetFileName(reportFullPath)}.xml");
|
string duplicateFile = Path.Combine(duplicateDirectory, _Logistics.FileInfo.Name);
|
||||||
string xml = ProcessDataStandardFormat.GetXml(processDataStandardFormat);
|
File.Move(_Logistics.FileInfo.FullName, duplicateFile);
|
||||||
File.WriteAllText(duplicateFile, xml);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception) { File.Delete(_Logistics.FileInfo.FullName); }
|
catch (Exception) { File.Delete(_Logistics.FileInfo.FullName); }
|
||||||
@ -152,7 +152,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
List<Shared.Properties.IDescription> descriptions = GetDuplicatorDescriptions(jsonElements);
|
List<Shared.Properties.IDescription> descriptions = GetDuplicatorDescriptions(jsonElements);
|
||||||
Test[] tests = (from l in descriptions select (Test)l.Test).ToArray();
|
Test[] tests = (from l in descriptions select (Test)l.Test).ToArray();
|
||||||
if (_IsEAFHosted && _FileConnectorConfiguration.FileScanningIntervalInSeconds > 0)
|
if (_IsEAFHosted && _FileConnectorConfiguration.FileScanningIntervalInSeconds > 0)
|
||||||
CopyAndWriteFile(reportFullPath, processDataStandardFormat, jsonElements);
|
CopyAndMoveFile(jsonElements);
|
||||||
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(string.Join(Environment.NewLine, processDataStandardFormat.Logistics), tests, jsonElements, new List<FileInfo>());
|
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(string.Join(Environment.NewLine, processDataStandardFormat.Logistics), tests, jsonElements, new List<FileInfo>());
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@ -383,24 +383,17 @@ public class FileRead : Properties.IFileRead
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
string[] files;
|
string[] files;
|
||||||
string[] directories;
|
string logisticsSequence = _Logistics.Sequence.ToString();
|
||||||
string logisticsSequence;
|
string[] directories = Directory.GetDirectories(jobIdDirectory, $"*{logisticsSequence}*", SearchOption.TopDirectoryOnly);
|
||||||
for (int i = 0; i < 10; i++)
|
foreach (string directory in directories)
|
||||||
{
|
{
|
||||||
logisticsSequence = (_Logistics.Sequence + -i).ToString();
|
files = Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly);
|
||||||
directories = Directory.GetDirectories(jobIdDirectory, $"*{logisticsSequence}*", SearchOption.TopDirectoryOnly);
|
if (files.Length == 0)
|
||||||
foreach (string directory in directories)
|
continue;
|
||||||
{
|
results.Add(directory);
|
||||||
files = Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly);
|
|
||||||
if (files.Length == 0)
|
|
||||||
continue;
|
|
||||||
results.Add(directory);
|
|
||||||
}
|
|
||||||
if (results.Count == 1)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (results.Count != 1)
|
if ((results is null) || results.Count != 1)
|
||||||
throw new Exception("Didn't find directory by logistics sequence");
|
throw new Exception("Didn't find directory by logistics sequence");
|
||||||
return results.ToArray();
|
return results.ToArray();
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,12 @@ using Adaptation.Shared.Methods;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace Adaptation.Shared;
|
namespace Adaptation.Shared;
|
||||||
|
|
||||||
@ -229,19 +227,19 @@ internal class ProcessDataStandardFormat
|
|||||||
return results.AsReadOnly();
|
return results.AsReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static ProcessDataStandardFormat GetProcessDataStandardFormat(string reportFullPath, ProcessDataStandardFormatMapping processDataStandardFormatMapping)
|
internal static ProcessDataStandardFormat GetProcessDataStandardFormat(string reportFullPath, ProcessDataStandardFormatMapping pdsfMapping)
|
||||||
{
|
{
|
||||||
ProcessDataStandardFormat result;
|
ProcessDataStandardFormat result;
|
||||||
const int columnsLine = 6;
|
const int columnsLine = 6;
|
||||||
FileInfo fileInfo = new(reportFullPath);
|
FileInfo fileInfo = new(reportFullPath);
|
||||||
ProcessDataStandardFormat processDataStandardFormat = GetProcessDataStandardFormat(fileInfo.LastWriteTime, columnsLine, fileInfo.FullName, lines: null);
|
ProcessDataStandardFormat processDataStandardFormat = GetProcessDataStandardFormat(fileInfo.LastWriteTime, columnsLine, fileInfo.FullName, lines: null);
|
||||||
JsonElement[]? jsonElements = processDataStandardFormatMapping.OldColumnNames.Count != processDataStandardFormatMapping.ColumnIndices.Count ? null : GetFullArray(processDataStandardFormat);
|
JsonElement[]? jsonElements = pdsfMapping.OldColumnNames.Count != pdsfMapping.ColumnIndices.Count ? null : GetFullArray(processDataStandardFormat);
|
||||||
JsonProperty[]? jsonProperties = jsonElements is null || jsonElements.Length == 0 ? null : jsonElements[0].EnumerateObject().ToArray();
|
JsonProperty[]? jsonProperties = jsonElements is null || jsonElements.Length == 0 ? null : jsonElements[0].EnumerateObject().ToArray();
|
||||||
if (jsonElements is null || jsonProperties is null || jsonProperties.Length != processDataStandardFormatMapping.NewColumnNames.Count)
|
if (jsonElements is null || jsonProperties is null || jsonProperties.Length != pdsfMapping.NewColumnNames.Count)
|
||||||
result = processDataStandardFormat;
|
result = processDataStandardFormat;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = GetProcessDataStandardFormat(processDataStandardFormatMapping, jsonElements, processDataStandardFormat);
|
result = GetProcessDataStandardFormat(pdsfMapping, jsonElements, processDataStandardFormat);
|
||||||
if (result.Sequence is null || result.Columns.Count == 0 || result.Body.Count == 0 || result.Logistics.Count == 0)
|
if (result.Sequence is null || result.Columns.Count == 0 || result.Body.Count == 0 || result.Logistics.Count == 0)
|
||||||
result = processDataStandardFormat;
|
result = processDataStandardFormat;
|
||||||
}
|
}
|
||||||
@ -337,14 +335,12 @@ internal class ProcessDataStandardFormat
|
|||||||
int column;
|
int column;
|
||||||
string value;
|
string value;
|
||||||
JsonProperty jsonProperty;
|
JsonProperty jsonProperty;
|
||||||
List<string> debug = new();
|
|
||||||
List<string> values = new();
|
List<string> values = new();
|
||||||
List<string> results = new();
|
List<string> results = new();
|
||||||
JsonProperty[] jsonProperties;
|
JsonProperty[] jsonProperties;
|
||||||
List<string> unknownColumns = new();
|
List<string> unknownColumns = new();
|
||||||
for (int i = 0; i < jsonElements.Length; i++)
|
for (int i = 0; i < jsonElements.Length; i++)
|
||||||
{
|
{
|
||||||
debug.Clear();
|
|
||||||
values.Clear();
|
values.Clear();
|
||||||
if (jsonElements[i].ValueKind != JsonValueKind.Object)
|
if (jsonElements[i].ValueKind != JsonValueKind.Object)
|
||||||
{
|
{
|
||||||
@ -358,22 +354,16 @@ internal class ProcessDataStandardFormat
|
|||||||
{
|
{
|
||||||
column = processDataStandardFormatMapping.ColumnIndices[c];
|
column = processDataStandardFormatMapping.ColumnIndices[c];
|
||||||
if (column == -1)
|
if (column == -1)
|
||||||
{
|
|
||||||
value = processDataStandardFormatMapping.OldColumnNames[c];
|
value = processDataStandardFormatMapping.OldColumnNames[c];
|
||||||
debug.Add($"<Item C=-01 Name=\"{value}\" DataType=\"8\" XmlType=\"1\" XPath=\"//records/record/{value}\" />");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jsonProperty = jsonProperties[column];
|
jsonProperty = jsonProperties[column];
|
||||||
value = jsonProperty.Value.ToString();
|
value = jsonProperty.Value.ToString();
|
||||||
debug.Add($"<Item C={column + 2:000} Name=\"{processDataStandardFormatMapping.OldColumnNames[c]}\" DataType=\"8\" XmlType=\"1\" XPath=\"//records/record/{jsonProperty.Name}\" />");
|
|
||||||
}
|
}
|
||||||
values.Add(value);
|
values.Add(value);
|
||||||
}
|
}
|
||||||
results.Add(string.Join("\t", values));
|
results.Add(string.Join("\t", values));
|
||||||
}
|
}
|
||||||
if (Debugger.IsAttached)
|
|
||||||
File.WriteAllText("../../.txt", string.Join(Environment.NewLine, debug.OrderBy(l => l)));
|
|
||||||
result = new(body: new(results),
|
result = new(body: new(results),
|
||||||
columns: processDataStandardFormatMapping.OldColumnNames,
|
columns: processDataStandardFormatMapping.OldColumnNames,
|
||||||
footer: processDataStandardFormat.Footer,
|
footer: processDataStandardFormat.Footer,
|
||||||
@ -388,6 +378,7 @@ internal class ProcessDataStandardFormat
|
|||||||
{
|
{
|
||||||
if (processDataStandardFormat.InputPDSF is null)
|
if (processDataStandardFormat.InputPDSF is null)
|
||||||
throw new NullReferenceException(nameof(processDataStandardFormat.InputPDSF));
|
throw new NullReferenceException(nameof(processDataStandardFormat.InputPDSF));
|
||||||
|
#pragma warning disable CA1845, IDE0057
|
||||||
string result;
|
string result;
|
||||||
string line;
|
string line;
|
||||||
string value;
|
string value;
|
||||||
@ -863,40 +854,6 @@ internal class ProcessDataStandardFormat
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string GetXml(ProcessDataStandardFormat processDataStandardFormat)
|
|
||||||
{
|
|
||||||
string result;
|
|
||||||
string tag;
|
|
||||||
string value;
|
|
||||||
string[] segments;
|
|
||||||
ReadOnlyCollection<string> body = processDataStandardFormat.InputPDSF is null ?
|
|
||||||
processDataStandardFormat.Body : processDataStandardFormat.InputPDSF.Body;
|
|
||||||
ReadOnlyCollection<string> columns = processDataStandardFormat.InputPDSF is null ?
|
|
||||||
processDataStandardFormat.Columns : processDataStandardFormat.InputPDSF.Columns;
|
|
||||||
List<string> lines = new() { "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<records>" };
|
|
||||||
for (int i = 0; i < body.Count; i++)
|
|
||||||
{
|
|
||||||
lines.Add(" <record>");
|
|
||||||
segments = body[i].Trim().Split('\t');
|
|
||||||
if (segments.Length != columns.Count)
|
|
||||||
break;
|
|
||||||
for (int c = 0; c < segments.Length; c++)
|
|
||||||
{
|
|
||||||
value = segments[c].Replace("&", "&")
|
|
||||||
.Replace("<", "<")
|
|
||||||
.Replace(">", ">")
|
|
||||||
.Replace("\"", """)
|
|
||||||
.Replace("'", "'");
|
|
||||||
tag = Regex.Replace(columns[c].Trim('"'), @"[^a-zA-Z0-9]", "_").Split('\r')[0].Split('\n')[0];
|
|
||||||
lines.Add(string.Concat(" <", tag, '>', value, "</", tag, '>'));
|
|
||||||
}
|
|
||||||
lines.Add(" </record>");
|
|
||||||
}
|
|
||||||
lines.Add("</records>");
|
|
||||||
result = string.Join(Environment.NewLine, lines);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
Reference in New Issue
Block a user