442 lines
18 KiB
C#
442 lines
18 KiB
C#
//using Adaptation.Shared;
|
|
//using Adaptation.Shared.Metrology;
|
|
//using log4net;
|
|
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.IO;
|
|
//using System.Linq;
|
|
//using System.Text;
|
|
//using System.Text.Json;
|
|
//using System.Text.RegularExpressions;
|
|
|
|
//namespace Adaptation.Helpers
|
|
//{
|
|
|
|
// public partial class ProcessData : IProcessData
|
|
// {
|
|
|
|
// public BioRadFile Header { get; private set; }
|
|
// public List<BioRadDetail> Details { get; private set; }
|
|
|
|
// private int _I;
|
|
// private readonly ILog _Log;
|
|
// private string _Data;
|
|
|
|
// public ProcessData(ILogic logic, ConfigData configData, List<FileInfo> fileInfoCollection, BioRadFile lastBioRadFile)
|
|
// {
|
|
// Header = null;
|
|
// fileInfoCollection.Clear();
|
|
// _I = 0; _Data = string.Empty;
|
|
// Details = new List<BioRadDetail>();
|
|
// _Log = LogManager.GetLogger(typeof(ProcessData));
|
|
// Tuple<BioRadFile, List<BioRadDetail>> tuple = Parse(logic, configData, fileInfoCollection, lastBioRadFile);
|
|
// Details.AddRange(tuple.Item2);
|
|
// Header = tuple.Item1;
|
|
// }
|
|
|
|
// public Tuple<string, JsonElement?, List<FileInfo>> GetResults(ILogic logic, ConfigDataBase configDataBase, List<FileInfo> fileInfoCollection)
|
|
// {
|
|
// Tuple<string, JsonElement?, List<FileInfo>> results;
|
|
// if (!(configDataBase is ConfigData configData))
|
|
// throw new Exception();
|
|
// List<Test> tests = new List<Test>();
|
|
// List<IProcessDataDescription> descriptions;
|
|
// EventName eventName = configData.GetEventNameValue();
|
|
// if (eventName == EventName.FileRead && Details.Any())
|
|
// {
|
|
// foreach (var item in Details)
|
|
// tests.Add(Test.BioRadQS408M);
|
|
// descriptions = configData.GetDescription(logic, tests, this);
|
|
// }
|
|
// else
|
|
// throw new Exception();
|
|
// if (!configData.EafHosted)
|
|
// {
|
|
// new FileRead.Description().GetDescription(logic, configData, tests, this);
|
|
// }
|
|
// if (tests.Count != descriptions.Count)
|
|
// throw new Exception();
|
|
// for (int i = 0; i < tests.Count; i++)
|
|
// {
|
|
// if (descriptions[i].Test != (int)tests[i])
|
|
// throw new Exception();
|
|
// }
|
|
// string json;
|
|
// if (descriptions[0] is Duplicator.Description)
|
|
// {
|
|
// List<Duplicator.Description> duplicatorDescriptions = (from l in descriptions select (Duplicator.Description)l).ToList();
|
|
// json = JsonSerializer.Serialize(duplicatorDescriptions, duplicatorDescriptions.GetType());
|
|
// }
|
|
// else if (descriptions[0] is FileRead.Description)
|
|
// {
|
|
// List<FileRead.Description> fileReadDescriptions = (from l in descriptions select (FileRead.Description)l).ToList();
|
|
// json = JsonSerializer.Serialize(fileReadDescriptions, fileReadDescriptions.GetType());
|
|
// }
|
|
// else
|
|
// throw new Exception();
|
|
// object @object = JsonSerializer.Deserialize<object>(json);
|
|
// if (!(@object is JsonElement jsonElement))
|
|
// throw new Exception();
|
|
// results = new Tuple<string, JsonElement?, List<FileInfo>>(logic.Logistics.Logistics1[0], jsonElement, fileInfoCollection);
|
|
// return results;
|
|
// }
|
|
|
|
// public static Dictionary<Test, List<Duplicator.Description>> GetKeyValuePairs(ConfigData configData, JsonElement jsonElement, List<Duplicator.Description> processDataDescriptions, bool extra = false)
|
|
// {
|
|
// Dictionary<Test, List<Duplicator.Description>> results = configData.GetKeyValuePairs(processDataDescriptions);
|
|
// configData.CheckProcessDataDescription(results, extra);
|
|
// return results;
|
|
// }
|
|
|
|
// public static List<FileRead.Description> GetProcessDataFileReadDescriptions(ConfigData configData, JsonElement jsonElement)
|
|
// {
|
|
// List<FileRead.Description> results = new List<FileRead.Description>();
|
|
// List<IProcessDataDescription> processDataDescriptions = configData.GetIProcessDataDescriptions(jsonElement);
|
|
// foreach (IProcessDataDescription processDataDescription in processDataDescriptions)
|
|
// {
|
|
// if (!(processDataDescription is FileRead.Description description))
|
|
// continue;
|
|
// results.Add(description);
|
|
// }
|
|
// return results;
|
|
// }
|
|
|
|
// public static string GetLines(ILogic logic, List<FileRead.Description> descriptions)
|
|
// {
|
|
// char del = '\t';
|
|
// StringBuilder results = new StringBuilder();
|
|
// FileRead.Description x = descriptions[0];
|
|
// results.Append(x.UniqueId).Append(del).
|
|
// Append(x.Date).Append(del).
|
|
// Append(x.Employee).Append(del).
|
|
// Append(x.Recipe).Append(del).
|
|
// Append(x.Reactor).Append(del).
|
|
// Append(x.RDS).Append(del).
|
|
// Append(x.PSN).Append(del).
|
|
// Append(x.Layer).Append(del).
|
|
// Append(x.Zone).Append(del).
|
|
// Append(x.Cassette).Append(del).
|
|
// Append(x.Wafer).Append(del).
|
|
// Append(x.RVThickness);
|
|
// return results.ToString();
|
|
// }
|
|
|
|
// internal static void PostOpenInsightMetrologyViewerAttachments(ILog log, ConfigData configData, Logistics logistics, DateTime dateTime, string logisticsSequenceMemoryDirectory, List<FileRead.Description> descriptions, string matchDirectory)
|
|
// {
|
|
// }
|
|
|
|
// private string GetBefore(string text)
|
|
// {
|
|
// string str;
|
|
// string str1;
|
|
// int num = _Data.IndexOf(text, _I);
|
|
// if (num <= -1)
|
|
// {
|
|
// str = _Data.Substring(_I);
|
|
// _I = _Data.Length;
|
|
// str1 = str.Trim();
|
|
// }
|
|
// else
|
|
// {
|
|
// str = _Data.Substring(_I, num - _I);
|
|
// _I = num + text.Length;
|
|
// str1 = str.Trim();
|
|
// }
|
|
// return str1;
|
|
// }
|
|
|
|
// private string GetBefore(string text, bool trim)
|
|
// {
|
|
// string str;
|
|
// string before;
|
|
// if (!trim)
|
|
// {
|
|
// int num = _Data.IndexOf(text, _I);
|
|
// if (num <= -1)
|
|
// {
|
|
// str = _Data.Substring(_I);
|
|
// _I = _Data.Length;
|
|
// before = str;
|
|
// }
|
|
// else
|
|
// {
|
|
// str = _Data.Substring(_I, num - _I);
|
|
// _I = num + text.Length;
|
|
// before = str;
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// before = GetBefore(text);
|
|
// }
|
|
// return before;
|
|
// }
|
|
|
|
// private string GetToEOL()
|
|
// {
|
|
// return GetBefore("\n");
|
|
// }
|
|
|
|
// private string GetToEOL(bool trim)
|
|
// {
|
|
// string str;
|
|
// str = (!trim ? GetBefore("\n", false) : GetToEOL());
|
|
// return str;
|
|
// }
|
|
|
|
// private string GetToken()
|
|
// {
|
|
// while (true)
|
|
// {
|
|
// if ((_I >= _Data.Length ? true : !IsNullOrWhiteSpace(_Data.Substring(_I, 1))))
|
|
// {
|
|
// break;
|
|
// }
|
|
// _I++;
|
|
// }
|
|
// int num = _I;
|
|
// while (true)
|
|
// {
|
|
// if ((num >= _Data.Length ? true : IsNullOrWhiteSpace(_Data.Substring(num, 1))))
|
|
// {
|
|
// break;
|
|
// }
|
|
// num++;
|
|
// }
|
|
// string str = _Data.Substring(_I, num - _I);
|
|
// _I = num;
|
|
// return str.Trim();
|
|
// }
|
|
|
|
// private string GetToText(string text)
|
|
// {
|
|
// string str = _Data.Substring(_I, _Data.IndexOf(text, _I) - _I).Trim();
|
|
// return str;
|
|
// }
|
|
|
|
// private bool IsBlankLine()
|
|
// {
|
|
// int num = _Data.IndexOf("\n", _I);
|
|
// return IsNullOrWhiteSpace((num > -1 ? _Data.Substring(_I, num - _I) : _Data.Substring(_I)));
|
|
// }
|
|
|
|
// private 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;
|
|
// }
|
|
|
|
// private string PeekNextLine()
|
|
// {
|
|
// int num = _I;
|
|
// string toEOL = GetToEOL();
|
|
// _I = num;
|
|
// return toEOL;
|
|
// }
|
|
|
|
// private void ScanPast(string text)
|
|
// {
|
|
// int num = _Data.IndexOf(text, _I);
|
|
// if (num <= -1)
|
|
// {
|
|
// _I = _Data.Length;
|
|
// }
|
|
// else
|
|
// {
|
|
// _I = num + text.Length;
|
|
// }
|
|
// }
|
|
|
|
// private Tuple<BioRadFile, List<BioRadDetail>> Parse(ILogic logic, ConfigData configData, List<FileInfo> fileInfoCollection, BioRadFile lastBioRadFile)
|
|
// {
|
|
// Tuple<BioRadFile, List<BioRadDetail>> result;
|
|
// BioRadFile bioRadFile = new BioRadFile { JobID = logic.Logistics.JobID, MesEntity = logic.Logistics.MesEntity };
|
|
// _I = 0; _Data = string.Empty;
|
|
// string h = string.Empty;
|
|
// List<BioRadDetail> bioRadDetails = new List<BioRadDetail>();
|
|
// string receivedData = File.ReadAllText(logic.Logistics.ReportFullPath);
|
|
// _Log.Debug($"****ParseData - Source file contents:");
|
|
// _Log.Debug(receivedData);
|
|
// string[] files = Directory.GetFiles(Path.GetDirectoryName(logic.Logistics.ReportFullPath), string.Concat(configData.OriginalDataBioRad, logic.Logistics.Sequence, "*"), SearchOption.TopDirectoryOnly);
|
|
// foreach (string file in files)
|
|
// fileInfoCollection.Add(new FileInfo(file));
|
|
// // occasionally there are multiple blocks of results, get the last one as earlier ones may be aborted runs.
|
|
// int index = receivedData.LastIndexOf("Bio-Rad");
|
|
// if (index > -1)
|
|
// receivedData = receivedData.Substring(index);
|
|
// _Log.Debug($"****ParseData - Source file contents to be parsed:");
|
|
// _Log.Debug(receivedData);
|
|
// if (!string.IsNullOrEmpty(receivedData))
|
|
// {
|
|
// _I = 0; _Data = receivedData;
|
|
// bioRadFile.Title = GetBefore("Recipe:");
|
|
// bioRadFile.Recipe = GetToken();
|
|
// bioRadFile.Date = GetToEOL();
|
|
// ScanPast("operator:");
|
|
// bioRadFile.Employee = GetBefore("batch:");
|
|
// bioRadFile.Batch = GetToEOL();
|
|
// // Remove illegal characters \/:*?"<>| found in the Batch
|
|
// bioRadFile.Batch = Regex.Replace(bioRadFile.Batch, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
|
|
// ScanPast("cassette:");
|
|
// bioRadFile.Cassette = GetBefore("wafer:");
|
|
// if (string.IsNullOrEmpty(bioRadFile.Batch))
|
|
// {
|
|
// _I = 0; _Data = receivedData;
|
|
// ScanPast("wafer:");
|
|
// }
|
|
// bioRadFile.Wafer = GetToEOL();
|
|
// GetToEOL();
|
|
// GetToEOL();
|
|
// string token = GetToken();
|
|
// int counter = 1;
|
|
// while (true)
|
|
// {
|
|
// if ((string.IsNullOrEmpty(token) ? true : !char.IsDigit(token[0])))
|
|
// break;
|
|
// BioRadDetail bioRadDetail = new BioRadDetail()
|
|
// {
|
|
// Position = token,
|
|
// Thickness = GetToken(),
|
|
// UniqueId = string.Concat("_Point-", counter)
|
|
// };
|
|
// bioRadDetails.Add(bioRadDetail);
|
|
// token = GetToken();
|
|
// counter++;
|
|
// }
|
|
// ScanPast("mean thickness =");
|
|
// bioRadFile.MeanThickness = GetBefore(", std. dev =");
|
|
// bioRadFile.StdDev = GetToken();
|
|
// bioRadFile.PassFail = GetToEOL();
|
|
// ScanPast("thickness");
|
|
// bioRadFile.RVThickness = GetToEOL();
|
|
// }
|
|
|
|
// if (string.IsNullOrEmpty(bioRadFile.Wafer))
|
|
// throw new Exception("Wafer field is missing.");
|
|
|
|
// //parse out batch and validate
|
|
// string[] parsedBatch = bioRadFile.Wafer.Split('-');
|
|
// if (parsedBatch.Length >= 1)
|
|
// bioRadFile.Reactor = parsedBatch[0];
|
|
// if (parsedBatch.Length >= 2)
|
|
// bioRadFile.RDS = parsedBatch[1];
|
|
// if (parsedBatch.Length >= 3)
|
|
// {
|
|
// string[] parsedPSN = parsedBatch[2].Split('.');
|
|
// if (parsedPSN.Length >= 1)
|
|
// bioRadFile.PSN = parsedPSN[0];
|
|
// if (parsedPSN.Length >= 2)
|
|
// bioRadFile.Layer = parsedPSN[1];
|
|
// }
|
|
// if (parsedBatch.Length >= 4)
|
|
// bioRadFile.Zone = parsedBatch[3];
|
|
|
|
// bioRadFile.JobID = logic.Logistics.JobID;
|
|
|
|
// if (logic.Logistics.DateTimeFromSequence > DateTime.Now.AddHours(-24))
|
|
// {
|
|
// if (string.IsNullOrEmpty(lastBioRadFile.Wafer))
|
|
// {
|
|
// lastBioRadFile.Batch = bioRadFile.JobID;
|
|
// lastBioRadFile.Cassette = bioRadFile.JobID;
|
|
// lastBioRadFile.Employee = bioRadFile.JobID;
|
|
// lastBioRadFile.Recipe = bioRadFile.JobID;
|
|
// lastBioRadFile.Title = bioRadFile.JobID;
|
|
// }
|
|
// lastBioRadFile.Wafer = bioRadFile.Wafer;
|
|
// lastBioRadFile.Reactor = bioRadFile.Reactor;
|
|
// lastBioRadFile.RDS = bioRadFile.RDS;
|
|
|
|
// string check = "--------";
|
|
// if (string.IsNullOrEmpty(bioRadFile.Batch) || bioRadFile.Batch.Contains(check))
|
|
// bioRadFile.Batch = lastBioRadFile.Batch;
|
|
// else
|
|
// lastBioRadFile.Batch = bioRadFile.Batch;
|
|
// if (string.IsNullOrEmpty(bioRadFile.Cassette) || bioRadFile.Cassette.Contains(check))
|
|
// bioRadFile.Cassette = lastBioRadFile.Cassette;
|
|
// else
|
|
// lastBioRadFile.Cassette = bioRadFile.Cassette;
|
|
// if (string.IsNullOrEmpty(bioRadFile.Employee) || bioRadFile.Employee.Contains(check))
|
|
// bioRadFile.Employee = lastBioRadFile.Employee;
|
|
// else
|
|
// lastBioRadFile.Employee = bioRadFile.Employee;
|
|
// if (string.IsNullOrEmpty(bioRadFile.Recipe) || bioRadFile.Recipe.Contains(check))
|
|
// bioRadFile.Recipe = lastBioRadFile.Recipe;
|
|
// else
|
|
// lastBioRadFile.Recipe = bioRadFile.Recipe;
|
|
// if (string.IsNullOrEmpty(bioRadFile.Title) || bioRadFile.Title.Contains(check))
|
|
// bioRadFile.Title = lastBioRadFile.Title;
|
|
// else
|
|
// lastBioRadFile.Title = bioRadFile.Title;
|
|
// }
|
|
|
|
// //fix title
|
|
// StringBuilder titleFixed = new StringBuilder();
|
|
// foreach (char c in bioRadFile.Title)
|
|
// {
|
|
// if (char.IsLetterOrDigit(c) || c == '-' || c == '.')
|
|
// titleFixed.Append(c);
|
|
// }
|
|
// bioRadFile.Title = titleFixed.ToString();
|
|
|
|
// //fix wafer
|
|
// StringBuilder waferFixed = new StringBuilder();
|
|
// foreach (char c in bioRadFile.Wafer)
|
|
// {
|
|
// if (char.IsLetterOrDigit(c) || c == '-' || c == '.')
|
|
// waferFixed.Append(c);
|
|
// }
|
|
// bioRadFile.Wafer = waferFixed.ToString();
|
|
|
|
// //overwrite incorrect datetime from tool
|
|
// bioRadFile.Date = DateTime.Now.ToString(); // defaults to format "G"
|
|
|
|
// //create filename / unique id
|
|
// bioRadFile.UniqueId = string.Concat(bioRadFile.Title, "_", bioRadFile.Wafer, "_", DateTime.Now.ToString("yyyyMMddHHmmssffff"));
|
|
// foreach (BioRadDetail detail in bioRadDetails)
|
|
// {
|
|
// detail.HeaderUniqueId = bioRadFile.UniqueId;
|
|
// detail.UniqueId = string.Concat(bioRadFile.UniqueId, detail.UniqueId);
|
|
// }
|
|
|
|
// //trace datatype
|
|
// _Log.Debug("BioRad parsed infomation:");
|
|
// _Log.Debug(string.Format("Batch: {0}", bioRadFile.Batch));
|
|
// _Log.Debug(string.Format("Cassette: {0}", bioRadFile.Cassette));
|
|
// _Log.Debug(string.Format("Date: {0}", bioRadFile.Date));
|
|
// foreach (BioRadDetail bioRadDetail in bioRadDetails)
|
|
// _Log.Debug(string.Format("Details: {0} - {1}", bioRadDetail.Position, bioRadDetail.Thickness));
|
|
// _Log.Debug(string.Format("Mean Thickness: {0}", bioRadFile.MeanThickness));
|
|
// _Log.Debug(string.Format("Operator: {0}", bioRadFile.Employee));
|
|
// _Log.Debug(string.Format("Pass/Fail: {0}", bioRadFile.PassFail));
|
|
// _Log.Debug(string.Format("Recipe: {0}", bioRadFile.Recipe));
|
|
// _Log.Debug(string.Format("RV Thickness: {0}", bioRadFile.RVThickness));
|
|
// _Log.Debug(string.Format("Std Dev: {0}", bioRadFile.StdDev));
|
|
// _Log.Debug(string.Format("Title: {0}", bioRadFile.Title));
|
|
// _Log.Debug(string.Format("Wafer: {0}", bioRadFile.Wafer));
|
|
// fileInfoCollection.Add(new FileInfo(logic.Logistics.ReportFullPath));
|
|
// result = new Tuple<BioRadFile, List<BioRadDetail>>(bioRadFile, bioRadDetails);
|
|
// return result;
|
|
// }
|
|
|
|
// }
|
|
|
|
//} |