Refactor QS408M and PDSF File Handlers
- Updated Detail class to include JsonSourceGenerationOptions and JsonSerializable attributes for source generation. - Modified ProcessData class to utilize source generation context for Description deserialization. - Renamed RowSourceGenerationContext to QS408MRowSourceGenerationContext for clarity. - Updated Run class to use QS408MRunSourceGenerationContext for serialization. - Enhanced Description class with source generation attributes. - Refactored FileRead class to use source generation context for Description deserialization. - Added new methods in ProcessDataStandardFormat for JSON element array extraction. - Introduced new PDSF file handler classes: Body, Constant, FileRead, Footer, Header, Row, Run, and Site. - Implemented logic for parsing and handling PDSF data structures. - Added unit tests for PDSF processing to ensure functionality.
This commit is contained in:
80
Adaptation/FileHandlers/pdsf/Body.cs
Normal file
80
Adaptation/FileHandlers/pdsf/Body.cs
Normal file
@ -0,0 +1,80 @@
|
||||
namespace Adaptation.FileHandlers.pdsf;
|
||||
|
||||
#nullable enable
|
||||
|
||||
public class Body
|
||||
{
|
||||
|
||||
public Body(string waferMeanThickness, string stdDev, string passFail)
|
||||
{
|
||||
WaferMeanThickness = waferMeanThickness;
|
||||
StdDev = stdDev;
|
||||
PassFail = passFail;
|
||||
}
|
||||
|
||||
public string WaferMeanThickness { get; }
|
||||
public string StdDev { get; }
|
||||
public string PassFail { get; }
|
||||
|
||||
private static bool IsNullOrWhiteSpace(string text)
|
||||
{
|
||||
bool flag;
|
||||
int num = 0;
|
||||
while (true)
|
||||
{
|
||||
if (num >= text.Length)
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
else if (char.IsWhiteSpace(text[num]))
|
||||
{
|
||||
num++;
|
||||
}
|
||||
else
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
internal static string GetToken(string text, int[] i)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (i[0] >= text.Length || !IsNullOrWhiteSpace(text.Substring(i[0], 1)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
i[0]++;
|
||||
}
|
||||
int num = i[0];
|
||||
while (true)
|
||||
{
|
||||
if (num >= text.Length || IsNullOrWhiteSpace(text.Substring(num, 1)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
string str = text.Substring(i[0], num - i[0]);
|
||||
i[0] = num;
|
||||
return str.Trim();
|
||||
}
|
||||
|
||||
internal static Body? Get(Constant constant, string text, int[] i)
|
||||
{
|
||||
Body? result;
|
||||
i[0] = Run.ScanPast(text, i, constant.MeanThickness);
|
||||
string meanThickness = Run.GetBefore(text, i, constant.StandardDeviation);
|
||||
string stdDev = GetToken(text, i);
|
||||
string passFail = Run.GetToEOL(text, i);
|
||||
result = new(meanThickness,
|
||||
stdDev,
|
||||
passFail);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
21
Adaptation/FileHandlers/pdsf/Constant.cs
Normal file
21
Adaptation/FileHandlers/pdsf/Constant.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace Adaptation.FileHandlers.pdsf;
|
||||
|
||||
internal class Constant
|
||||
{
|
||||
|
||||
public string Period { get; } = ".";
|
||||
public string Slot { get; } = "Slot:";
|
||||
public string Semicolon { get; } = ";";
|
||||
public string Batch { get; } = "batch:";
|
||||
public string TwoSpaces { get; } = " ";
|
||||
public string Wafer { get; } = "wafer:";
|
||||
public string BioRad { get; } = "Bio-Rad";
|
||||
public string Recipe { get; } = "Recipe:";
|
||||
public string Cassette { get; } = "cassette:";
|
||||
public string Operator { get; } = "operator:";
|
||||
public string Thickness { get; } = "thickness";
|
||||
public string MeanThickness { get; } = "mean thickness =";
|
||||
public string StandardDeviation { get; } = ", std. dev =";
|
||||
public string WaferFieldIsMissing { get; } = "Wafer field is missing.";
|
||||
|
||||
}
|
130
Adaptation/FileHandlers/pdsf/FileRead.cs
Normal file
130
Adaptation/FileHandlers/pdsf/FileRead.cs
Normal file
@ -0,0 +1,130 @@
|
||||
using Adaptation.Eaf.Management.ConfigurationData.CellAutomation;
|
||||
using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration;
|
||||
using Adaptation.Shared;
|
||||
using Adaptation.Shared.Duplicator;
|
||||
using Adaptation.Shared.Methods;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Adaptation.FileHandlers.pdsf;
|
||||
|
||||
public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
|
||||
private readonly Header[] _LastHeader;
|
||||
|
||||
public FileRead(ISMTP smtp, Dictionary<string, string> fileParameter, string cellInstanceName, int? connectionCount, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList<ModelObjectParameterDefinition> modelObjectParameters, string equipmentDictionaryName, Dictionary<string, List<long>> dummyRuns, Dictionary<long, List<Shared.Metrology.WS.Results>> staticRuns, bool useCyclicalForDescription, bool isEAFHosted) :
|
||||
base(new Description(), false, smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null)
|
||||
{
|
||||
_MinFileLength = 10;
|
||||
_NullData = string.Empty;
|
||||
_Logistics = new(this);
|
||||
if (_FileParameter is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (_ModelObjectParameterDefinitions is null)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
if (_IsDuplicator)
|
||||
throw new Exception(cellInstanceConnectionName);
|
||||
_LastHeader = new Header[] { Header.Get() };
|
||||
if (_IsEAFHosted)
|
||||
NestExistingFiles(_FileConnectorConfiguration);
|
||||
}
|
||||
|
||||
void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) => Move(extractResults);
|
||||
|
||||
void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null);
|
||||
|
||||
string IFileRead.GetEventDescription()
|
||||
{
|
||||
string result = _Description.GetEventDescription();
|
||||
return result;
|
||||
}
|
||||
|
||||
List<string> IFileRead.GetHeaderNames()
|
||||
{
|
||||
List<string> results = _Description.GetHeaderNames();
|
||||
return results;
|
||||
}
|
||||
|
||||
string[] IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, string to, string from, string resolvedFileLocation, Exception exception)
|
||||
{
|
||||
string[] results = Move(extractResults, to, from, resolvedFileLocation, exception);
|
||||
return results;
|
||||
}
|
||||
|
||||
JsonProperty[] IFileRead.GetDefault()
|
||||
{
|
||||
JsonProperty[] results = _Description.GetDefault(this, _Logistics);
|
||||
return results;
|
||||
}
|
||||
|
||||
Dictionary<string, string> IFileRead.GetDisplayNamesJsonElement()
|
||||
{
|
||||
Dictionary<string, string> results = _Description.GetDisplayNamesJsonElement(this);
|
||||
return results;
|
||||
}
|
||||
|
||||
List<IDescription> IFileRead.GetDescriptions(IFileRead fileRead, List<Test> tests, IProcessData processData)
|
||||
{
|
||||
List<IDescription> results = _Description.GetDescriptions(fileRead, _Logistics, tests, processData);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.GetExtractResult(string reportFullPath, string eventName)
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
if (string.IsNullOrEmpty(eventName))
|
||||
throw new Exception();
|
||||
_ReportFullPath = reportFullPath;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
results = GetExtractResult(reportFullPath, dateTime);
|
||||
if (results.Item3 is null)
|
||||
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(results.Item1, Array.Empty<Test>(), Array.Empty<JsonElement>(), results.Item4);
|
||||
if (results.Item3.Length > 0 && _IsEAFHosted)
|
||||
WritePDSF(this, results.Item3);
|
||||
UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks);
|
||||
return results;
|
||||
}
|
||||
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.ReExtract()
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
List<string> headerNames = _Description.GetHeaderNames();
|
||||
Dictionary<string, string> keyValuePairs = _Description.GetDisplayNamesJsonElement(this);
|
||||
results = ReExtract(this, headerNames, keyValuePairs);
|
||||
return results;
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
|
||||
private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime)
|
||||
{
|
||||
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
|
||||
string result;
|
||||
JsonElement[] jsonElements;
|
||||
Test[] tests = Array.Empty<Test>();
|
||||
List<FileInfo> fileInfoCollection = new();
|
||||
ProcessDataStandardFormat processDataStandardFormat = ProcessDataStandardFormat.GetProcessDataStandardFormat(reportFullPath);
|
||||
_Logistics = new Logistics(reportFullPath, processDataStandardFormat);
|
||||
SetFileParameterLotIDToLogisticsMID();
|
||||
Run? run = Run.Get(_Logistics, processDataStandardFormat, fileInfoCollection, lastHeader: _LastHeader[0]);
|
||||
if (run is null)
|
||||
{
|
||||
_LastHeader[0] = Header.Get();
|
||||
jsonElements = Array.Empty<JsonElement>();
|
||||
result = string.Concat("A) No Data - ", dateTime.Ticks);
|
||||
results = new(result, tests, jsonElements, fileInfoCollection);
|
||||
}
|
||||
else
|
||||
{
|
||||
_LastHeader[0] = run.Header;
|
||||
result = string.Join(Environment.NewLine, _Logistics.Logistics1);
|
||||
jsonElements = _IsEAFHosted ? Array.Empty<JsonElement>() : ProcessDataStandardFormat.GetArray(processDataStandardFormat);
|
||||
results = new(result, tests, jsonElements, fileInfoCollection);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
36
Adaptation/FileHandlers/pdsf/Footer.cs
Normal file
36
Adaptation/FileHandlers/pdsf/Footer.cs
Normal file
@ -0,0 +1,36 @@
|
||||
namespace Adaptation.FileHandlers.pdsf;
|
||||
|
||||
#nullable enable
|
||||
|
||||
public class Footer
|
||||
{
|
||||
|
||||
public Footer(string line, string radialVariationThickness, string slot)
|
||||
{
|
||||
Line = line;
|
||||
RadialVariationThickness = radialVariationThickness;
|
||||
Slot = slot;
|
||||
}
|
||||
|
||||
public string Line { get; }
|
||||
public string RadialVariationThickness { get; }
|
||||
public string Slot { get; }
|
||||
|
||||
internal static Footer? Get(Constant constant, string text, int[] i)
|
||||
{
|
||||
Footer? result;
|
||||
_ = Run.GetToEOL(text, i);
|
||||
_ = Run.GetToEOL(text, i);
|
||||
string line = Run.GetToEOL(text, i);
|
||||
i[0] = Run.ScanPast(text, i, constant.Thickness);
|
||||
string radialVariationThickness = Run.GetToEOL(text, i);
|
||||
_ = Run.GetToEOL(text, i);
|
||||
i[0] = Run.ScanPast(text, i, constant.Slot);
|
||||
string slot = Run.GetBefore(text, i, constant.Semicolon);
|
||||
result = new(line,
|
||||
radialVariationThickness,
|
||||
slot);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
106
Adaptation/FileHandlers/pdsf/Header.cs
Normal file
106
Adaptation/FileHandlers/pdsf/Header.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Adaptation.FileHandlers.pdsf;
|
||||
|
||||
#nullable enable
|
||||
|
||||
public class Header
|
||||
{
|
||||
|
||||
public Header(string title, string recipe, string dateTime, string @operator, string batch, string cassette, bool usedLast, string wafer)
|
||||
{
|
||||
Title = title;
|
||||
Recipe = recipe;
|
||||
DateTime = dateTime;
|
||||
Operator = @operator;
|
||||
Batch = batch;
|
||||
Cassette = cassette;
|
||||
UsedLast = usedLast;
|
||||
Wafer = wafer;
|
||||
}
|
||||
|
||||
public string Title { get; }
|
||||
public string Recipe { get; }
|
||||
public string DateTime { get; }
|
||||
public string Operator { get; }
|
||||
public string Batch { get; }
|
||||
public string Cassette { get; }
|
||||
public bool UsedLast { get; }
|
||||
public string Wafer { get; }
|
||||
|
||||
internal static Header Get() =>
|
||||
new(string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
false,
|
||||
string.Empty);
|
||||
|
||||
internal static Header? Get(Constant constant, Header lastHeader, string text, int[] i)
|
||||
{
|
||||
Header? result;
|
||||
// occasionally there are multiple blocks of details, get the last one as earlier ones may be aborted runs.
|
||||
int index = text.LastIndexOf(constant.BioRad);
|
||||
if (index > -1)
|
||||
text = text.Substring(index);
|
||||
if (string.IsNullOrEmpty(text))
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
bool usedLast;
|
||||
string recipe;
|
||||
string title = Run.GetBefore(text, i, constant.Recipe);
|
||||
string recipeAndDateTime = Run.GetToEOL(text, i);
|
||||
if (recipeAndDateTime.Length < constant.TwoSpaces.Length)
|
||||
recipe = recipeAndDateTime.Trim();
|
||||
else if (!recipeAndDateTime.Contains(constant.TwoSpaces))
|
||||
recipe = recipeAndDateTime.Substring(0, 25).Trim();
|
||||
else
|
||||
recipe = recipeAndDateTime.Split(new string[] { constant.TwoSpaces }, StringSplitOptions.None)[0].Trim();
|
||||
string dateTime = recipeAndDateTime.Substring(recipe.Length).Trim();
|
||||
if (dateTime.EndsWith(constant.Period))
|
||||
dateTime = dateTime.Remove(dateTime.Length - 1, 1);
|
||||
i[0] = Run.ScanPast(text, i, constant.Operator);
|
||||
string @operator = Run.GetBefore(text, i, constant.Batch);
|
||||
string batch = Run.GetToEOL(text, i);
|
||||
i[0] = Run.ScanPast(text, i, constant.Cassette);
|
||||
if (!text.Contains(constant.Cassette))
|
||||
title = string.Empty;
|
||||
string cassette = Run.GetBefore(text, i, constant.Wafer);
|
||||
if (string.IsNullOrEmpty(batch))
|
||||
{
|
||||
i[0] = 0;
|
||||
i[0] = Run.ScanPast(text, i, constant.Wafer);
|
||||
}
|
||||
string wafer = Run.GetToEOL(text, i);
|
||||
_ = Run.GetToEOL(text, i);
|
||||
_ = Run.GetToEOL(text, i);
|
||||
if (string.IsNullOrEmpty(wafer))
|
||||
throw new Exception(constant.WaferFieldIsMissing);
|
||||
if (!string.IsNullOrEmpty(title))
|
||||
usedLast = false;
|
||||
else
|
||||
{
|
||||
title = lastHeader.Title;
|
||||
recipe = lastHeader.Recipe;
|
||||
@operator = lastHeader.Operator;
|
||||
batch = lastHeader.Batch;
|
||||
cassette = lastHeader.Cassette;
|
||||
usedLast = true;
|
||||
}
|
||||
result = new(title: title,
|
||||
recipe: recipe,
|
||||
dateTime: dateTime,
|
||||
@operator: @operator,
|
||||
batch: batch,
|
||||
cassette: cassette,
|
||||
usedLast: usedLast,
|
||||
wafer: wafer);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
63
Adaptation/FileHandlers/pdsf/Row.cs
Normal file
63
Adaptation/FileHandlers/pdsf/Row.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Adaptation.FileHandlers.pdsf;
|
||||
|
||||
#nullable enable
|
||||
|
||||
internal class Row
|
||||
{
|
||||
|
||||
public Row(Run run, int i)
|
||||
{
|
||||
Index = i;
|
||||
//
|
||||
Title = run.Header.Title;
|
||||
Recipe = run.Header.Recipe;
|
||||
DateTime = run.Header.DateTime;
|
||||
Operator = run.Header.Operator;
|
||||
Batch = run.Header.Batch;
|
||||
Cassette = run.Header.Cassette;
|
||||
UsedLast = run.Header.UsedLast;
|
||||
Wafer = run.Header.Wafer;
|
||||
//
|
||||
Position = run.Sites[i].Position;
|
||||
Thickness = run.Sites[i].Thickness;
|
||||
//
|
||||
WaferMeanThickness = run.Body.WaferMeanThickness;
|
||||
StdDev = run.Body.StdDev;
|
||||
PassFail = run.Body.PassFail;
|
||||
//
|
||||
Line = run.Footer.Line;
|
||||
RadialVariationThickness = run.Footer.RadialVariationThickness;
|
||||
Slot = run.Footer.Slot;
|
||||
}
|
||||
|
||||
public int Index { get; }
|
||||
//
|
||||
public string Title { get; }
|
||||
public string Recipe { get; }
|
||||
public string DateTime { get; }
|
||||
public string Operator { get; }
|
||||
public string Batch { get; }
|
||||
public string Cassette { get; }
|
||||
public bool UsedLast { get; }
|
||||
public string Wafer { get; }
|
||||
//
|
||||
public string Position { get; }
|
||||
public string Thickness { get; }
|
||||
//
|
||||
public string WaferMeanThickness { get; }
|
||||
public string StdDev { get; }
|
||||
public string PassFail { get; }
|
||||
//
|
||||
public string Line { get; }
|
||||
public string RadialVariationThickness { get; }
|
||||
public string Slot { get; }
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Row))]
|
||||
internal partial class RowSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
190
Adaptation/FileHandlers/pdsf/Run.cs
Normal file
190
Adaptation/FileHandlers/pdsf/Run.cs
Normal file
@ -0,0 +1,190 @@
|
||||
using Adaptation.Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Adaptation.FileHandlers.pdsf;
|
||||
|
||||
#nullable enable
|
||||
|
||||
internal class Run
|
||||
{
|
||||
|
||||
public Header Header { get; }
|
||||
public ReadOnlyCollection<Site> Sites { get; }
|
||||
public Body Body { get; }
|
||||
public Footer Footer { get; }
|
||||
|
||||
public Run(Header header, ReadOnlyCollection<Site> sites, Body body, Footer footer)
|
||||
{
|
||||
Header = header;
|
||||
Sites = sites;
|
||||
Body = body;
|
||||
Footer = footer;
|
||||
}
|
||||
|
||||
internal static string GetBefore(string text, int[] i, string search)
|
||||
{
|
||||
string str;
|
||||
string str1;
|
||||
int num = text.IndexOf(search, i[0]);
|
||||
if (num <= -1)
|
||||
{
|
||||
str = text.Substring(i[0]);
|
||||
i[0] = text.Length;
|
||||
str1 = str.Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
str = text.Substring(i[0], num - i[0]);
|
||||
i[0] = num + search.Length;
|
||||
str1 = str.Trim();
|
||||
}
|
||||
return str1;
|
||||
}
|
||||
|
||||
internal static string GetToEOL(string text, int[] i)
|
||||
{
|
||||
string result;
|
||||
if (text.IndexOf("\n", i[0]) > -1)
|
||||
result = GetBefore(text, i, "\n");
|
||||
else
|
||||
result = GetBefore(text, i, Environment.NewLine);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static int ScanPast(string text, int[] i, string search)
|
||||
{
|
||||
int result;
|
||||
int num = text.IndexOf(search, i[0]);
|
||||
if (num <= -1)
|
||||
result = text.Length;
|
||||
else
|
||||
result = num + search.Length;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void WriteJson(Logistics logistics, List<FileInfo> fileInfoCollection, Run result)
|
||||
{
|
||||
FileInfo fileInfo = new($"{logistics.ReportFullPath}.run.json");
|
||||
string json = JsonSerializer.Serialize(result, RunSourceGenerationContext.Default.Run);
|
||||
File.WriteAllText(fileInfo.FullName, json);
|
||||
File.SetLastWriteTime(fileInfo.FullName, logistics.DateTimeFromSequence);
|
||||
fileInfoCollection.Add(fileInfo);
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetLines(Logistics logistics, JsonElement[]? jsonElements)
|
||||
{
|
||||
List<string> 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(',');
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (jsonElements?.Length != 0)
|
||||
_ = stringBuilder.Remove(stringBuilder.Length - 1, 1);
|
||||
results.Add(stringBuilder.ToString());
|
||||
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(',');
|
||||
else if (jsonProperty.Value.ValueKind != JsonValueKind.String)
|
||||
_ = stringBuilder.Append(jsonProperty.Value).Append(',');
|
||||
else
|
||||
_ = stringBuilder.Append('"').Append(jsonProperty.Value).Append('"').Append(',');
|
||||
}
|
||||
_ = stringBuilder.Remove(stringBuilder.Length - 1, 1);
|
||||
results.Add(stringBuilder.ToString());
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static void WriteCommaSeparatedValues(Logistics logistics, Run run)
|
||||
{
|
||||
List<Row> results = new();
|
||||
Row row;
|
||||
for (int i = 0; i < run.Sites.Count; i++)
|
||||
{
|
||||
row = new(run, i);
|
||||
results.Add(row);
|
||||
}
|
||||
string json = JsonSerializer.Serialize(results);
|
||||
JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json);
|
||||
ReadOnlyCollection<string> lines = GetLines(logistics, jsonElements);
|
||||
File.WriteAllText($"{logistics.ReportFullPath}.csv", string.Join(Environment.NewLine, lines));
|
||||
}
|
||||
|
||||
private static string GetText(ProcessDataStandardFormat processDataStandardFormat)
|
||||
{
|
||||
string result;
|
||||
List<string> results = new();
|
||||
int skipColumns = processDataStandardFormat.Columns.Count - 1;
|
||||
foreach (string line in processDataStandardFormat.Body)
|
||||
results.Add(string.Join("\t", line.Split('\t').Skip(skipColumns)));
|
||||
result = string.Join(Environment.NewLine, results);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static Run? Get(Logistics logistics, ProcessDataStandardFormat processDataStandardFormat, List<FileInfo> fileInfoCollection, Header lastHeader)
|
||||
{
|
||||
Run? result;
|
||||
Constant constant = new();
|
||||
int[] i = new int[] { 0 };
|
||||
string text = GetText(processDataStandardFormat);
|
||||
Header? header = Header.Get(constant, lastHeader, text, i);
|
||||
if (header is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
ReadOnlyCollection<Site> sites = Site.Get(text, i);
|
||||
if (sites.Count == 0)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
Body? body = Body.Get(constant, text, i);
|
||||
if (body is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
Footer? footer = Footer.Get(constant, text, i);
|
||||
if (footer is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
result = new(header, sites, body, footer);
|
||||
WriteJson(logistics, fileInfoCollection, result);
|
||||
WriteCommaSeparatedValues(logistics, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Run))]
|
||||
internal partial class RunSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
36
Adaptation/FileHandlers/pdsf/Site.cs
Normal file
36
Adaptation/FileHandlers/pdsf/Site.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Adaptation.FileHandlers.pdsf;
|
||||
|
||||
public class Site
|
||||
{
|
||||
|
||||
public Site(string position, string thickness)
|
||||
{
|
||||
Position = position;
|
||||
Thickness = thickness;
|
||||
}
|
||||
|
||||
public string Position { get; }
|
||||
public string Thickness { get; }
|
||||
|
||||
internal static ReadOnlyCollection<Site> Get(string text, int[] i)
|
||||
{
|
||||
List<Site> results = new();
|
||||
Site site;
|
||||
string thickness;
|
||||
string position = Body.GetToken(text, i);
|
||||
while (true)
|
||||
{
|
||||
if (string.IsNullOrEmpty(position) || !char.IsDigit(position[0]))
|
||||
break;
|
||||
thickness = Body.GetToken(text, i);
|
||||
site = new(position, thickness);
|
||||
results.Add(site);
|
||||
position = Body.GetToken(text, i);
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user