diff --git a/Adaptation/FileHandlers/MoveMatchingFiles/FileRead.cs b/Adaptation/FileHandlers/MoveMatchingFiles/FileRead.cs index 9ffd8a7..e81631a 100644 --- a/Adaptation/FileHandlers/MoveMatchingFiles/FileRead.cs +++ b/Adaptation/FileHandlers/MoveMatchingFiles/FileRead.cs @@ -27,21 +27,18 @@ public class FileRead : Shared.FileRead, IFileRead internal string MatchingFile { get; private set; } internal string CheckDirectory { get; private set; } internal string NoWaitDirectory { get; private set; } - internal bool MesEntityMatchesProcess { get; private set; } internal PreWith(string checkDirectory, string checkFile, string errFile, string matchingFile, - string noWaitDirectory, - bool mesEntityMatchesProcess) + string noWaitDirectory) { ErrFile = errFile; CheckFile = checkFile; MatchingFile = matchingFile; CheckDirectory = checkDirectory; NoWaitDirectory = noWaitDirectory; - MesEntityMatchesProcess = mesEntityMatchesProcess; } } @@ -212,7 +209,7 @@ public class FileRead : Shared.FileRead, IFileRead return result; } - private static ReadOnlyCollection GetPreWithCollection(ReadOnlyCollection
 preCollection, bool mesEntityMatchesProcess)
+    private static ReadOnlyCollection GetPreWithCollection(ReadOnlyCollection
 preCollection)
     {
         List results = new();
         string errFile;
@@ -232,8 +229,7 @@ public class FileRead : Shared.FileRead, IFileRead
                           checkFile: pre.CheckFile,
                           errFile: errFile,
                           matchingFile: pre.MatchingFile,
-                          noWaitDirectory: noWaitDirectory,
-                          mesEntityMatchesProcess: mesEntityMatchesProcess);
+                          noWaitDirectory: noWaitDirectory);
             results.Add(preWith);
         }
         return results.AsReadOnly();
@@ -272,7 +268,7 @@ public class FileRead : Shared.FileRead, IFileRead
         }
     }
 
-    private static ReadOnlyCollection
 GetPreCollection(int numberLength, string parentDirectory, ReadOnlyCollection matchingFiles)
+    private static ReadOnlyCollection
 GetPreCollection(int numberLength, string parentDirectory, ReadOnlyCollection matchingFiles, bool _)
     {
         List
 results = new();
         Pre pre;
@@ -287,7 +283,7 @@ public class FileRead : Shared.FileRead, IFileRead
         return results.AsReadOnly();
     }
 
-    private void MoveCollection(DateTime dateTime, ProcessDataStandardFormat? processDataStandardFormat, ReadOnlyCollection preWithCollection)
+    private void MoveCollection(DateTime dateTime, ProcessDataStandardFormat processDataStandardFormat, ReadOnlyCollection preWithCollection)
     {
         ReadOnlyCollection postCollection = GetPostCollection(dateTime, processDataStandardFormat, preWithCollection);
         if (postCollection.Count != 0)
@@ -306,7 +302,7 @@ public class FileRead : Shared.FileRead, IFileRead
         }
     }
 
-    private ReadOnlyCollection GetPostCollection(DateTime dateTime, ProcessDataStandardFormat? processDataStandardFormat, ReadOnlyCollection preWithCollection)
+    private ReadOnlyCollection GetPostCollection(DateTime dateTime, ProcessDataStandardFormat processDataStandardFormat, ReadOnlyCollection preWithCollection)
     {
         List results = new();
         Post post;
@@ -315,15 +311,10 @@ public class FileRead : Shared.FileRead, IFileRead
         {
             if (!_IsEAFHosted)
                 continue;
-            if (processDataStandardFormat is null)
-                File.Move(preWith.MatchingFile, preWith.CheckFile);
-            else
-            {
-                if (!_StaticRuns.TryGetValue(_Logistics.Sequence, out List? wsResults))
-                    wsResults = null;
-                ProcessDataStandardFormat.Write(preWith.CheckFile, processDataStandardFormat, wsResults);
-                File.Delete(preWith.MatchingFile);
-            }
+            if (!_StaticRuns.TryGetValue(_Logistics.Sequence, out List? wsResults))
+                wsResults = null;
+            ProcessDataStandardFormat.Write(preWith.CheckFile, processDataStandardFormat, wsResults);
+            File.Delete(preWith.MatchingFile);
             if (Directory.Exists(preWith.NoWaitDirectory))
             {
                 post = new(preWith.CheckFile, preWith.ErrFile);
@@ -360,7 +351,7 @@ public class FileRead : Shared.FileRead, IFileRead
         ProcessDataStandardFormat processDataStandardFormat = ProcessDataStandardFormat.GetProcessDataStandardFormat(reportFullPath, _ProcessDataStandardFormatMapping);
         _Logistics = new Logistics(reportFullPath, processDataStandardFormat);
         if (!_IsEAFHosted)
-            ProcessDataStandardFormat.Write(".pdsf", processDataStandardFormat, wsResults: null);
+            ProcessDataStandardFormat.Write("../../.pdsf", processDataStandardFormat, wsResults: null);
         SetFileParameterLotIDToLogisticsMID();
         int numberLength = 2;
         long ticks = dateTime.Ticks;
@@ -378,8 +369,8 @@ public class FileRead : Shared.FileRead, IFileRead
         JsonElement[] jsonElements = ProcessDataStandardFormat.GetArray(processDataStandardFormat);
         List descriptions = pcl.ProcessData.GetDescriptions(jsonElements);
         bool mesEntityMatchesProcess = descriptions.Count > 0 && descriptions[0].MesEntity == descriptions[0].Reactor;
-        ReadOnlyCollection
 preCollection = GetPreCollection(numberLength, parentParentDirectory, matchingFiles);
-        ReadOnlyCollection preWithCollection = GetPreWithCollection(preCollection, mesEntityMatchesProcess);
+        ReadOnlyCollection
 preCollection = GetPreCollection(numberLength, parentParentDirectory, matchingFiles, mesEntityMatchesProcess);
+        ReadOnlyCollection preWithCollection = GetPreWithCollection(preCollection);
         MoveCollection(dateTime, processDataStandardFormat, preWithCollection);
         return results;
     }
diff --git a/Adaptation/Shared/ProcessDataStandardFormat.cs b/Adaptation/Shared/ProcessDataStandardFormat.cs
index e39d4e8..113ba5f 100644
--- a/Adaptation/Shared/ProcessDataStandardFormat.cs
+++ b/Adaptation/Shared/ProcessDataStandardFormat.cs
@@ -360,6 +360,63 @@ internal class ProcessDataStandardFormat
         return result;
     }
 
+    private static string GetJson(ProcessDataStandardFormat processDataStandardFormat)
+    {
+        if (processDataStandardFormat.InputPDSF is null)
+            throw new NullReferenceException(nameof(processDataStandardFormat.InputPDSF));
+#pragma warning disable CA1845, IDE0057
+        string result;
+        string line;
+        string value;
+        string[] segments;
+        List lines = new();
+        for (int i = 0; i < processDataStandardFormat.InputPDSF.Body.Count; i++)
+        {
+            line = "{";
+            segments = processDataStandardFormat.InputPDSF.Body[i].Trim().Split('\t');
+            if (segments.Length != processDataStandardFormat.InputPDSF.Columns.Count)
+                break;
+            for (int c = 0; c < segments.Length; c++)
+            {
+                value = segments[c].Replace("\"", "\\\"").Replace("\\", "\\\\");
+                line += string.Concat('"', processDataStandardFormat.InputPDSF.Columns[c].Trim('"'), '"', ':', '"', value, '"', ',');
+            }
+            line = string.Concat(line.Substring(0, line.Length - 1), '}');
+            lines.Add(line);
+        }
+        result = string.Concat(
+            '{',
+            Environment.NewLine,
+            '"',
+            "Count",
+            '"',
+            ": ",            
+            processDataStandardFormat.Body.Count,
+            ',',
+            Environment.NewLine,
+            '"',
+            "Records",
+            '"',
+            ": ",
+            Environment.NewLine,
+            '[',
+            Environment.NewLine,
+            string.Join($",{Environment.NewLine}", lines),
+            Environment.NewLine,
+            ']',
+            ',',
+            Environment.NewLine,
+            '"',
+            "Sequence",
+            '"',
+            ": ",            
+            processDataStandardFormat.Sequence,
+            Environment.NewLine,
+            '}');
+        return result;
+#pragma warning restore CA1845, IDE0057
+    }
+
     internal static void Write(string path, ProcessDataStandardFormat processDataStandardFormat, List? wsResults)
     {
         List results = new();
@@ -399,12 +456,12 @@ internal class ProcessDataStandardFormat
                     results.Add($"{segments[0]}\t{segments[1][0]}_HeaderId={wsResults[0].HeaderId};{segments[1][0]}_SubgroupId={wsResults[0].SubgroupId};{segments[1]}");
             }
         }
-        results.Add("EOF");
+        results.Add("END_HEADER");
         if (processDataStandardFormat.InputPDSF is not null)
         {
+            results.Add(string.Empty);
             List hyphens = new();
             results.AddRange(processDataStandardFormat.InputPDSF.Header.Select(l => l.Replace('\t', '|')));
-            results.Add(string.Empty);
             results.Add($"|{string.Join("|", processDataStandardFormat.InputPDSF.Columns)}|");
             for (int i = 0; i < processDataStandardFormat.InputPDSF.Columns.Count; i++)
                 hyphens.Add('-');
@@ -412,6 +469,11 @@ internal class ProcessDataStandardFormat
             results.AddRange(processDataStandardFormat.InputPDSF.Body.Select(l => l.Replace('\t', '|')));
             results.Add(string.Empty);
             results.AddRange(processDataStandardFormat.InputPDSF.Footer.Select(l => l.Replace('\t', '|')));
+            results.Add(string.Empty);
+            results.Add("EOF");
+            results.Add(string.Empty);
+            string json = GetJson(processDataStandardFormat);
+            results.Add(json);
         }
         File.WriteAllText(path, string.Join(Environment.NewLine, results));
     }