FlagDuplicates

CA1510
Complete
This commit is contained in:
2024-11-18 14:31:39 -07:00
parent 94c82f0894
commit ca0e7d2030
18 changed files with 429 additions and 361 deletions

View File

@ -58,16 +58,18 @@ public partial class ProcessData : IProcessData
{
}
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string originalDataBioRad, LastProcessData lastProcessData, long tickOffset)
#nullable enable
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string originalDataBioRad, Header[] lastHeader, long tickOffset)
{
JobID = logistics.JobID;
fileInfoCollection.Clear();
_Details = new List<object>();
MesEntity = logistics.MesEntity;
_Log = LogManager.GetLogger(typeof(ProcessData));
TXT txt = Parse(fileRead, logistics, fileInfoCollection, originalDataBioRad, lastProcessData);
if (txt is not null)
SetValues(logistics, tickOffset, txt);
Complete? complete = Parse(fileRead, logistics, fileInfoCollection, originalDataBioRad, lastHeader);
if (complete is not null)
SetValues(logistics, tickOffset, complete);
}
string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary<string, string> reactors) => throw new Exception(string.Concat("See ", nameof(Parse)));
@ -90,7 +92,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;
}
@ -245,49 +247,46 @@ public partial class ProcessData : IProcessData
return result;
}
#pragma warning disable IDE0060
private static TXT Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string originalDataBioRad, LastProcessData lastProcessData)
#pragma warning restore IDE0060
private Complete? Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string originalDataBioRad, Header[] lastHeader)
{
TXT result;
if (fileRead is null)
throw new ArgumentNullException(nameof(fileRead));
Complete? result;
List<string> moveFiles = new();
string directoryName = Path.GetDirectoryName(logistics.ReportFullPath);
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));
foreach (string moveFile in moveFiles.Distinct())
fileInfoCollection.Add(new FileInfo(moveFile));
string receivedData = File.ReadAllText(logistics.ReportFullPath);
// occasionally there are multiple blocks of details, get the last one as earlier ones may be aborted runs.
int index = receivedData.LastIndexOf("Bio-Rad");
if (index > -1)
receivedData = receivedData.Substring(index);
if (string.IsNullOrEmpty(receivedData))
result = null;
result = Complete.Get(lastHeader[0], receivedData);
if (result is null)
_Log.Warn($"Could not get Complete from {fileNameWithoutExtension}");
else
{
result = new TXT(lastProcessData, receivedData);
string fileName = Path.Combine(directoryName, $"{Path.GetFileNameWithoutExtension(logistics.ReportFullPath)}.json");
string json = JsonSerializer.Serialize(result, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(fileName, json);
fileInfoCollection.Add(new(fileName));
FileInfo fileInfo = new($"{fileNameWithoutExtension}.json");
string json = JsonSerializer.Serialize(result, CompleteSourceGenerationContext.Default.Complete);
File.WriteAllText(fileInfo.FullName, json);
fileInfoCollection.Add(fileInfo);
lastHeader[0] = result.Header;
}
fileInfoCollection.Add(logistics.FileInfo);
return result;
}
private void SetValues(Logistics logistics, long tickOffset, TXT txt)
private void SetValues(Logistics logistics, long tickOffset, Complete complete)
{
int slot = 0;
Detail detail;
int counter = 1;
List<Detail> details = new();
DateTime dateTime = GetDateTime(logistics, tickOffset, txt.Header.DateTime);
bool isWaferSlot = !string.IsNullOrEmpty(txt.Header.Wafer) && txt.Header.Wafer.Length is 1 or 2 && int.TryParse(txt.Header.Wafer, out slot) && slot < 27;
string batch = !isWaferSlot ? logistics.JobID : Regex.Replace(txt.Header.Batch, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
Descriptor descriptor = isWaferSlot ? GetDescriptor(txt.Header.Batch) : GetDescriptor(txt.Header.Wafer);
DateTime dateTime = GetDateTime(logistics, tickOffset, complete.Header.DateTime);
bool isWaferSlot = !string.IsNullOrEmpty(complete.Header.Wafer) && complete.Header.Wafer.Length is 1 or 2 && int.TryParse(complete.Header.Wafer, out slot) && slot < 27;
string batch = !isWaferSlot ? logistics.JobID : Regex.Replace(complete.Header.Batch, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
Descriptor descriptor = isWaferSlot ? GetDescriptor(complete.Header.Batch) : GetDescriptor(complete.Header.Wafer);
string wafer = isWaferSlot ? slot.ToString("00") : descriptor.Wafer;
string uniqueId = string.Concat(txt.Header.Title, '_', wafer, '_', logistics.DateTimeFromSequence.ToString("yyyyMMddHHmmssffff"), '_', logistics.TotalSecondsSinceLastWriteTimeFromSequence);
string uniqueId = string.Concat(complete.Header.Title, '_', wafer, '_', logistics.DateTimeFromSequence.ToString("yyyyMMddHHmmssffff"), '_', logistics.TotalSecondsSinceLastWriteTimeFromSequence);
Batch = batch;
Wafer = wafer;
Date = dateTime;
@ -297,17 +296,17 @@ public partial class ProcessData : IProcessData
Zone = descriptor.Zone;
JobID = logistics.JobID;
Layer = descriptor.Layer;
StdDev = txt.Body.StdDev;
Title = txt.Header.Title;
Recipe = txt.Header.Recipe;
PassFail = txt.Body.PassFail;
Reactor = descriptor.Reactor;
Cassette = txt.Header.Cassette;
RVThickness = txt.Footer.RadialVariationThickness;
Slot = string.IsNullOrEmpty(txt.Footer.Slot) ? slot.ToString("00") : txt.Footer.Slot;
Employee = string.IsNullOrEmpty(txt.Header.Operator) ? Employee : txt.Header.Operator;
MeanThickness = string.IsNullOrEmpty(txt.Body.WaferMeanThickness) && txt.Body.Sites.Count == 1 ? txt.Body.Sites.First().Thickness : txt.Body.WaferMeanThickness;
foreach (Site site in txt.Body.Sites)
StdDev = complete.Body.StdDev;
Title = complete.Header.Title;
Recipe = complete.Header.Recipe;
PassFail = complete.Body.PassFail;
Cassette = complete.Header.Cassette;
RVThickness = complete.Footer.RadialVariationThickness;
Slot = string.IsNullOrEmpty(complete.Footer.Slot) ? slot.ToString("00") : complete.Footer.Slot;
Employee = string.IsNullOrEmpty(complete.Header.Operator) ? Employee : complete.Header.Operator;
MeanThickness = string.IsNullOrEmpty(complete.Body.WaferMeanThickness) && complete.Body.Sites.Count == 1 ? complete.Body.Sites.First().Thickness : complete.Body.WaferMeanThickness;
foreach (Site site in complete.Body.Sites)
{
detail = new()
{