Require Complete

IDE0060
This commit is contained in:
2024-11-20 12:35:54 -07:00
parent a95f783733
commit 334929a025
10 changed files with 49 additions and 103 deletions

View File

@ -42,14 +42,16 @@ public partial class ProcessData : IProcessData
private string _Data;
private readonly ILog _Log;
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string originalDataBioRad, string dataText)
#nullable enable
internal ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string originalDataBioRad, Complete? complete, string dataText)
{
JobID = logistics.JobID;
fileInfoCollection.Clear();
_Details = new List<object>();
MesEntity = logistics.MesEntity;
_Log = LogManager.GetLogger(typeof(ProcessData));
Parse(fileRead, logistics, fileInfoCollection, originalDataBioRad, dataText);
Parse(fileRead, logistics, fileInfoCollection, originalDataBioRad, complete, dataText);
}
string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary<string, string> reactors) => throw new Exception(string.Concat("See ", nameof(Parse)));
@ -72,7 +74,7 @@ public partial class ProcessData : IProcessData
}
List<Description> fileReadDescriptions = (from l in descriptions select (Description)l).ToList();
string json = JsonSerializer.Serialize(fileReadDescriptions, fileReadDescriptions.GetType());
JsonElement[] jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json);
JsonElement[] jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json) ?? throw new Exception();
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(logistics.Logistics1[0], tests.ToArray(), jsonElements, fileInfoCollection);
return results;
}
@ -383,7 +385,7 @@ public partial class ProcessData : IProcessData
return result;
}
private void Set(Logistics logistics)
private void Set(Logistics logistics, Complete? complete)
{
string psn;
string rds;
@ -413,6 +415,8 @@ public partial class ProcessData : IProcessData
batch = GetToText(startedKey);
ScanPast(startedAtKey);
}
if (complete is not null)
{ }
ScanPast(cassetteKey);
if (!_Data.Substring(_I).Contains(startedKey))
text = string.Empty;
@ -445,48 +449,17 @@ public partial class ProcessData : IProcessData
UniqueId = string.Concat("StratusBioRad_", reactor, "_", rds, "_", psn, "_", logistics.DateTimeFromSequence.ToString("yyyyMMddHHmmssffff"));
}
#nullable enable
private static Complete? GetComplete(string text)
{
Complete? result;
Constant constant = new();
result = Complete.Get(text, constant);
return result;
}
#pragma warning disable IDE0060
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string originalDataBioRad, string receivedData)
#pragma warning restore IDE0060
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string originalDataBioRad, Complete? complete, string receivedData)
{
if (fileRead is null)
throw new ArgumentNullException(nameof(fileRead));
_I = 0;
_Data = string.Empty;
List<Detail> details = new();
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(logistics.ReportFullPath);
if (string.IsNullOrEmpty(receivedData))
{
receivedData = File.ReadAllText(logistics.ReportFullPath);
try
{
Complete? complete = GetComplete(receivedData);
if (complete is null)
_Log.Warn($"Could not get Complete from {fileNameWithoutExtension}");
else
{
FileInfo fileInfo = new($"{fileNameWithoutExtension}.json");
string json = JsonSerializer.Serialize(complete, CompleteSourceGenerationContext.Default.Complete);
File.WriteAllText(fileInfo.FullName, json);
fileInfoCollection.Add(fileInfo);
}
}
catch (Exception ex)
{
_Log.Error($"Error in {nameof(GetComplete)}", ex);
}
}
_Log.Debug($"****ParseData - Source file contents:");
_Log.Debug(receivedData);
List<string> moveFiles = new();
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(logistics.ReportFullPath);
string directoryName = Path.GetDirectoryName(logistics.ReportFullPath) ?? throw new Exception();
moveFiles.AddRange(Directory.GetFiles(directoryName, string.Concat(originalDataBioRad, "*", logistics.Sequence, "*"), SearchOption.TopDirectoryOnly));
moveFiles.AddRange(Directory.GetFiles(directoryName, string.Concat(originalDataBioRad, "*", fileNameWithoutExtension.Split('_').Last(), "*"), SearchOption.TopDirectoryOnly));
@ -504,7 +477,7 @@ public partial class ProcessData : IProcessData
string nextLine;
_I = 0;
_Data = receivedData;
Set(logistics);
Set(logistics, complete);
nextLine = PeekNextLine();
string cassette = "Cassette";
if (nextLine.Contains("Wafer"))