diff --git a/Adaptation/FileHandlers/RsM/Run.cs b/Adaptation/FileHandlers/RsM/Run.cs index ecac015..fb88102 100644 --- a/Adaptation/FileHandlers/RsM/Run.cs +++ b/Adaptation/FileHandlers/RsM/Run.cs @@ -69,17 +69,22 @@ internal class Run fileInfoCollection.Add(fileInfo); } - private static ReadOnlyCollection GetLines(JsonElement[]? jsonElements) + private static ReadOnlyCollection GetLines(Logistics logistics, JsonElement[]? jsonElements) { List results = new(); int columns = 0; StringBuilder stringBuilder = new(); + results.Add($"\"Count\",{jsonElements?.Length}"); + results.Add($"\"{nameof(logistics.Sequence)}\",{logistics.Sequence}"); + results.Add($"\"{nameof(logistics.MesEntity)}\",\"{logistics.MesEntity}\""); + string dateTimeFromSequence = logistics.DateTimeFromSequence.ToString("MM/dd/yyyy hh:mm:ss tt"); for (int i = 0; i < jsonElements?.Length;) { + _ = stringBuilder.Append('"').Append(nameof(logistics.DateTimeFromSequence)).Append('"').Append(','); foreach (JsonProperty jsonProperty in jsonElements[0].EnumerateObject()) { columns += 1; - _ = stringBuilder.Append('"').Append(jsonProperty.Name).Append('"').Append('\t'); + _ = stringBuilder.Append('"').Append(jsonProperty.Name).Append('"').Append(','); } break; } @@ -89,14 +94,15 @@ internal class Run for (int i = 0; i < jsonElements?.Length; i++) { _ = stringBuilder.Clear(); + _ = stringBuilder.Append('"').Append(dateTimeFromSequence).Append('"').Append(','); foreach (JsonProperty jsonProperty in jsonElements[i].EnumerateObject()) { if (jsonProperty.Value.ValueKind == JsonValueKind.Object) - _ = stringBuilder.Append('\t'); + _ = stringBuilder.Append(','); else if (jsonProperty.Value.ValueKind != JsonValueKind.String) - _ = stringBuilder.Append(jsonProperty.Value).Append('\t'); + _ = stringBuilder.Append(jsonProperty.Value).Append(','); else - _ = stringBuilder.Append('"').Append(jsonProperty.Value).Append('"').Append('\t'); + _ = stringBuilder.Append('"').Append(jsonProperty.Value).Append('"').Append(','); } _ = stringBuilder.Remove(stringBuilder.Length - 1, 1); results.Add(stringBuilder.ToString()); @@ -104,14 +110,10 @@ internal class Run return results.AsReadOnly(); } - private static ReadOnlyCollection GetLines(JsonElement jsonElement) => - GetLines(new JsonElement[] { jsonElement }); - - private static void WriteTabSeparatedValues(Logistics logistics, List fileInfoCollection, Run run) + private static void WriteCommaSeparatedValues(Logistics logistics, Run run) { List results = new(); Row row; - FileInfo fileInfo = new($"{logistics.ReportFullPath}.tsv"); for (int i = 0; i < run.Points.Count; i++) { row = new(run, i); @@ -119,16 +121,8 @@ internal class Run } string json = JsonSerializer.Serialize(results); JsonElement[]? jsonElements = JsonSerializer.Deserialize(json); - ReadOnlyCollection lines = GetLines(jsonElements); - File.WriteAllText(fileInfo.FullName, string.Join(Environment.NewLine, lines)); - File.SetLastWriteTime(fileInfo.FullName, logistics.DateTimeFromSequence); - fileInfoCollection.Add(fileInfo); - } - - private static void WriteException(Logistics logistics, Exception ex) - { - FileInfo fileInfo = new($"{logistics.ReportFullPath}.{nameof(Exception)}.txt"); - File.WriteAllText(fileInfo.FullName, $"{ex.Message}{Environment.NewLine}{ex.StackTrace}"); + ReadOnlyCollection lines = GetLines(logistics, jsonElements); + File.WriteAllText($"{logistics.ReportFullPath}.csv", string.Join(Environment.NewLine, lines)); } internal static Run? Get(Logistics logistics, List fileInfoCollection) @@ -182,14 +176,7 @@ internal class Run { result = new(line1, line2, line3, line4, line4B, line5, line6, line7, line8, line9, line10, line11, line12, line13, points); WriteJson(logistics, fileInfoCollection, result); - try - { - WriteTabSeparatedValues(logistics, fileInfoCollection, result); - } - catch (Exception ex) - { - WriteException(logistics, ex); - } + WriteCommaSeparatedValues(logistics, result); } } } diff --git a/FileHandlers/FileRead.cs b/FileHandlers/FileRead.cs index 5447b9e..da28de6 100644 --- a/FileHandlers/FileRead.cs +++ b/FileHandlers/FileRead.cs @@ -88,7 +88,7 @@ public partial class FileRead : FileReaderHandler, ISMTP try { extractResults = _FileRead.GetExtractResult(reportFullPath, eventName); - if (extractResults.Item3.Length == 0 && !string.IsNullOrEmpty(extractResults.Item1) && !extractResults.Item1.Contains(Environment.NewLine)) + if (extractResults.Item3.Length == 0 && !string.IsNullOrEmpty(extractResults.Item1) && !extractResults.Item1.Contains("LOGISTICS_1")) throw new Exception(extractResults.Item1); TriggerEvents(extractResults); _FileRead.Move(extractResults);