MET08DDUPSP1TBI - v2.43.0 - FileInfo added GetMID

This commit is contained in:
Mike Phares 2022-06-29 13:03:23 -07:00
parent 44a2e5e67d
commit 48bba76f11
7 changed files with 174 additions and 196 deletions

View File

@ -25,10 +25,6 @@ public class FileRead : Shared.FileRead, IFileRead
throw new Exception(cellInstanceConnectionName); throw new Exception(cellInstanceConnectionName);
if (!_IsDuplicator) if (!_IsDuplicator)
throw new Exception(cellInstanceConnectionName); throw new Exception(cellInstanceConnectionName);
ModelObjectParameterDefinition[] pathParameters = GetProperties(cellInstanceConnectionName, modelObjectParameters, "Path.");
string oiContextDataPendingPath = GetPropertyValue(cellInstanceConnectionName, pathParameters, "Path.OIContextDataPending");
string oiContextDataResultsPath = GetPropertyValue(cellInstanceConnectionName, pathParameters, "Path.OIContextDataResults");
string oiContextDataSearchPath = GetPropertyValue(cellInstanceConnectionName, pathParameters, "Path.OIContextDataSearch");
string lsl2SQLConnectionString = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "ConnectionString.LSL2SQL"); string lsl2SQLConnectionString = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "ConnectionString.LSL2SQL");
ModelObjectParameterDefinition[] tibcoParameters = GetProperties(cellInstanceConnectionName, modelObjectParameters, "TIBCO."); ModelObjectParameterDefinition[] tibcoParameters = GetProperties(cellInstanceConnectionName, modelObjectParameters, "TIBCO.");
string tibcoParameterChannel = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_CHANNEL"); string tibcoParameterChannel = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_CHANNEL");
@ -38,7 +34,7 @@ public class FileRead : Shared.FileRead, IFileRead
string tibcoParameterConfigurationLocationCopy = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_CONFIGURATION_LOCATION_LOCAL_COPY"); string tibcoParameterConfigurationLocationCopy = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_CONFIGURATION_LOCATION_LOCAL_COPY");
if (_IsEAFHosted) if (_IsEAFHosted)
{ {
Transport.Main.Initialize(smtp, cellInstanceName, fileConnectorConfiguration, oiContextDataPendingPath, oiContextDataResultsPath, oiContextDataSearchPath, lsl2SQLConnectionString); Transport.Main.Initialize(smtp, cellInstanceName, fileConnectorConfiguration, lsl2SQLConnectionString);
if (!string.IsNullOrEmpty(fileConnectorConfiguration.SourceFileLocation)) if (!string.IsNullOrEmpty(fileConnectorConfiguration.SourceFileLocation))
_ = Transport.Main.Setup(useSleep: true, setIfxTransport: true, tibcoParameterChannel, tibcoParameterSubjectPrefix, tibcoParameterConfigurationLocation, tibcoParameterConfigurationLocationCopy, tibcoParameterSubject); _ = Transport.Main.Setup(useSleep: true, setIfxTransport: true, tibcoParameterChannel, tibcoParameterSubjectPrefix, tibcoParameterConfigurationLocation, tibcoParameterConfigurationLocationCopy, tibcoParameterSubject);
else else

View File

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
@ -30,10 +28,10 @@ public class Job
public DateTime DateTime { get; } public DateTime DateTime { get; }
public List<Item> Items { get; } public List<Item> Items { get; }
public Job(string oiContextDataPendingPath, string oiContextDataResultsPath, string oiContextDataSearchPath, string lsl2SQLConnectionString, Dictionary<int, List<(string MID, int Count)>> _RDS, string mid) public Job(string lsl2SQLConnectionString, Dictionary<int, List<(string MID, int Count)>> _RDS, string mid)
{ {
Items = new List<Item>(); Items = new List<Item>();
if (mid[0] != '{' || mid[mid.Length - 1] != '}' || !mid.Contains("\"Si\"")) if (string.IsNullOrEmpty(mid) || mid[0] != '{' || mid[mid.Length - 1] != '}' || !mid.Contains("\"Si\""))
IsAreaSi = false; IsAreaSi = false;
else else
{ {
@ -55,32 +53,43 @@ public class Job
psn = string.Empty; psn = string.Empty;
reactor = string.Empty; reactor = string.Empty;
} }
else if (rds > 0) else if (rds is < 100000 or > 100000000)
{ {
psn = string.Empty;
reactor = string.Empty;
}
else
{
psn = segments[2];
reactor = segments[0];
lock (_RDS) lock (_RDS)
{ {
if (!_RDS.ContainsKey(rds)) if (!_RDS.ContainsKey(rds))
_RDS.Add(rds, new()); _RDS.Add(rds, new());
List<(string MID, int Count)> collection = _RDS[rds]; bool rdsCollectionCountIsZero = _RDS[rds].Count == 0;
if (collection.Count == 0) if (rdsCollectionCountIsZero)
_RDS[rds].Add(new(input.MID, 1)); {
else if (!string.IsNullOrEmpty(reactor) && !string.IsNullOrEmpty(psn))
_RDS[rds].Add(new(input.MID, 1));
else
{
string lsl2SQLMID = GetMID(lsl2SQLConnectionString, rds);
if (string.IsNullOrEmpty(lsl2SQLMID))
_RDS[rds].Add(new(input.MID, 1));
else
_RDS[rds].Add(new(lsl2SQLMID, 1));
}
}
IEnumerable<IGrouping<string, (string MID, int Count)>> grouped = _RDS[rds].GroupBy(l => l.MID);
orderedMatches.AddRange(from l in grouped orderby l.Count() descending select l);
if (!rdsCollectionCountIsZero)
{ {
IEnumerable<IGrouping<string, (string MID, int Count)>> grouped = collection.GroupBy(l => l.MID);
orderedMatches.AddRange(from l in grouped orderby l.Count() descending select l);
int length = (from l in orderedMatches where l.Key == input.MID select true).Count(); int length = (from l in orderedMatches where l.Key == input.MID select true).Count();
_RDS[rds].Add(new(input.MID, length + 1)); _RDS[rds].Add(new(input.MID, length + 1));
} }
if (_RDS.Count > 1000) if (_RDS.Count > 1000)
_ = _RDS.Remove(_RDS.ElementAt(0).Key); _ = _RDS.Remove(_RDS.ElementAt(0).Key);
} }
psn = segments[2];
reactor = segments[0];
}
else
{
psn = string.Empty;
reactor = string.Empty;
} }
AutomationMode = string.Concat(DateTime.Ticks, ".", input.MesEntity); AutomationMode = string.Concat(DateTime.Ticks, ".", input.MesEntity);
Equipment = input.MesEntity; Equipment = input.MesEntity;
@ -92,7 +101,7 @@ public class Job
reactor = segments[0]; reactor = segments[0];
} }
const string hyphen = "-"; const string hyphen = "-";
if (rds < 1) if (rds is < 100000 or > 100000000)
{ {
BasicType = hyphen; BasicType = hyphen;
LotName = input.MID; LotName = input.MID;
@ -110,11 +119,10 @@ public class Job
RecipeName = input.Recipe; RecipeName = input.Recipe;
StateModel = input.EquipmentType; StateModel = input.EquipmentType;
Items.Add(new Item { Name = "0", Type = "NA", Number = (0 + 1).ToString(), Qty = "1", CarrierName = hyphen }); Items.Add(new Item { Name = "0", Type = "NA", Number = (0 + 1).ToString(), Qty = "1", CarrierName = hyphen });
MoveOldFiles(oiContextDataSearchPath, oiContextDataPendingPath, oiContextDataResultsPath);
} }
} }
public static string GetBasicType(string lsl2SQLConnectionString, string hyphen, int rds) private static string GetBasicType(string lsl2SQLConnectionString, string hyphen, int rds)
{ {
string result; string result;
// string json; // string json;
@ -181,8 +189,7 @@ public class Job
sqlConnection.Close(); sqlConnection.Close();
} }
catch (Exception) catch (Exception)
{ { }
}
if (scalar is null) if (scalar is null)
result = hyphen; result = hyphen;
else else
@ -190,41 +197,29 @@ public class Job
return result; return result;
} }
private static void MoveOldFiles(string oiContextDataPendingPath, string oiContextDataResultsPath, string oiContextDataSearchPath) private static string GetMID(string lsl2SQLConnectionString, int rds)
{ {
string yearWeek; string result;
string[] oldFiles; object scalar = null;
FileInfo fileInfo; StringBuilder sql = new();
string weekOfYear; _ = sql.Append(" SELECT CONCAT(REACTOR, '-', RDS_NO, '-', PS_NO) [MID] ").
string moveDirectory; Append(" FROM [LSL2SQL].[dbo].[REACT_RUN] ").
DateTime daysOld = DateTime.Now.AddDays(-2); Append($" WHERE RDS_NO = '{rds}' ");
CultureInfo cultureInfo = new("en-US"); try
Calendar calendar = cultureInfo.Calendar;
string[] directories = new string[] { oiContextDataSearchPath, oiContextDataPendingPath, oiContextDataResultsPath };
foreach (string directory in directories)
{ {
try using SqlConnection sqlConnection = new(lsl2SQLConnectionString);
{ sqlConnection.Open();
oldFiles = Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly); using (SqlCommand sqlCommand = new(sql.ToString(), sqlConnection))
foreach (string oldFile in oldFiles) scalar = sqlCommand.ExecuteScalar();
{ sqlConnection.Close();
fileInfo = new FileInfo(oldFile);
if (!fileInfo.Exists || fileInfo.LastWriteTime > daysOld)
continue;
weekOfYear = calendar.GetWeekOfYear(fileInfo.LastWriteTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
yearWeek = string.Concat(fileInfo.LastWriteTime.ToString("yyyy"), "___Week_", weekOfYear);
moveDirectory = Path.Combine(fileInfo.DirectoryName, yearWeek);
if (!Directory.Exists(moveDirectory))
_ = Directory.CreateDirectory(moveDirectory);
try
{ File.Move(oldFile, Path.Combine(moveDirectory, fileInfo.Name)); }
catch (Exception) { }
}
}
catch (Exception)
{
}
} }
catch (Exception)
{ }
if (scalar is null)
result = string.Empty;
else
result = scalar.ToString();
return result;
} }
} }

View File

@ -16,22 +16,16 @@ internal partial class Main
private static object _IfxTransport; private static object _IfxTransport;
private static string _CellInstanceName; private static string _CellInstanceName;
private static string _LSL2SQLConnectionString; private static string _LSL2SQLConnectionString;
private static string _OIContextDataSearchPath;
private static string _OIContextDataPendingPath;
private static string _OIContextDataResultsPath;
private static Dictionary<int, List<(string MID, int Count)>> _RDS; private static Dictionary<int, List<(string MID, int Count)>> _RDS;
private static FileConnectorConfiguration _FileConnectorConfiguration; private static FileConnectorConfiguration _FileConnectorConfiguration;
internal static void Initialize(ISMTP smtp, string cellInstanceName, FileConnectorConfiguration fileConnectorConfiguration, string oiContextDataPendingPath, string oiContextDataResultsPath, string oiContextDataSearchPath, string lsl2SQLConnectionString) internal static void Initialize(ISMTP smtp, string cellInstanceName, FileConnectorConfiguration fileConnectorConfiguration, string lsl2SQLConnectionString)
{ {
_RDS = new(); _RDS = new();
_SMTP = smtp; _SMTP = smtp;
_IfxTransport = null; _IfxTransport = null;
_CellInstanceName = cellInstanceName; _CellInstanceName = cellInstanceName;
_LSL2SQLConnectionString = lsl2SQLConnectionString; _LSL2SQLConnectionString = lsl2SQLConnectionString;
_OIContextDataSearchPath = oiContextDataSearchPath;
_OIContextDataPendingPath = oiContextDataPendingPath;
_OIContextDataResultsPath = oiContextDataResultsPath;
_FileConnectorConfiguration = fileConnectorConfiguration; _FileConnectorConfiguration = fileConnectorConfiguration;
} }
@ -120,36 +114,36 @@ internal partial class Main
IfxDoc lotDoc = new(); IfxDoc lotDoc = new();
IfxDoc recipeDoc = new(); IfxDoc recipeDoc = new();
List<IfxDoc> itemDocs = new(); List<IfxDoc> itemDocs = new();
jobDoc.Add("AutomationMode", job.AutomationMode); jobDoc.Add(nameof(Job.AutomationMode), job.AutomationMode);
jobDoc.Add("CreationTimestamp", job.DateTime); jobDoc.Add("CreationTimestamp", job.DateTime);
jobDoc.Add("CreationUser", "-"); jobDoc.Add("CreationUser", "-");
jobDoc.Add("CurrentState", true); jobDoc.Add("CurrentState", true);
jobDoc.Add("Equipment", job.Equipment); jobDoc.Add(nameof(Job.Equipment), job.Equipment);
jobDoc.Add("JobName", job.JobName); jobDoc.Add(nameof(Job.JobName), job.JobName);
jobDoc.Add("LastUpdateTimestamp", job.DateTime); jobDoc.Add("LastUpdateTimestamp", job.DateTime);
jobDoc.Add("LastUpdateUser", "-"); jobDoc.Add("LastUpdateUser", "-");
jobDoc.Add("ProcessType", job.ProcessType); jobDoc.Add(nameof(Job.ProcessType), job.ProcessType); //Key.ProccessJobId
jobDoc.Add("StateModel", job.StateModel); jobDoc.Add(nameof(Job.StateModel), job.StateModel);
jobDoc.Add("Status", "-"); jobDoc.Add("Status", "-");
lotDoc.Add("BasicType", job.BasicType); lotDoc.Add(nameof(Job.BasicType), job.BasicType); //Key.BasicType
lotDoc.Add("IsActive", true); lotDoc.Add("IsActive", true);
lotDoc.Add("LotName", job.LotName); lotDoc.Add(nameof(Job.LotName), job.LotName); //Key.MID
lotDoc.Add("LotState", "-"); lotDoc.Add("LotState", "-");
lotDoc.Add("PackageName", job.PackageName); lotDoc.Add(nameof(Job.PackageName), job.PackageName); //Key.WaferId
lotDoc.Add("ProcessSpecName", job.ProcessSpecName); lotDoc.Add(nameof(Job.ProcessSpecName), job.ProcessSpecName); //Key.Chamber
lotDoc.Add("ProductName", job.ProductName); lotDoc.Add(nameof(Job.ProductName), job.ProductName); //Key.Product
lotDoc.Add("Qty", job.Qty); lotDoc.Add(nameof(Job.Qty), job.Qty);
lotDoc.Add("Qty2", "-"); lotDoc.Add("Qty2", "-"); //Key.Sequence
recipeDoc.Add("RecipeName", job.RecipeName); recipeDoc.Add(nameof(Job.RecipeName), job.RecipeName); //Key.PPID
lotDoc.Add("SpecName", "-"); lotDoc.Add("SpecName", "-"); //Key.Info
foreach (Item item in job.Items) foreach (Item item in job.Items)
{ {
itemDoc = new IfxDoc(); itemDoc = new IfxDoc();
itemDoc.Add("Name", item.Name); itemDoc.Add(nameof(Item.Name), item.Name);
itemDoc.Add("Type", item.Type); itemDoc.Add(nameof(Item.Type), item.Type);
itemDoc.Add("Number", item.Number); itemDoc.Add(nameof(Item.Number), item.Number);
itemDoc.Add("Qty", item.Qty); itemDoc.Add(nameof(Item.Qty), item.Qty);
itemDoc.Add("CarrierName", item.CarrierName); itemDoc.Add(nameof(Item.CarrierName), item.CarrierName);
itemDocs.Add(itemDoc); itemDocs.Add(itemDoc);
} }
jobDoc.Add("Recipe", recipeDoc); jobDoc.Add("Recipe", recipeDoc);
@ -187,7 +181,7 @@ internal partial class Main
if (!subject.EndsWith("GETJOBS")) if (!subject.EndsWith("GETJOBS"))
throw new Exception(); throw new Exception();
mid = GetJobsMID(envelopeDocument); mid = GetJobsMID(envelopeDocument);
Job job = new(_OIContextDataPendingPath, _OIContextDataResultsPath, _OIContextDataSearchPath, _LSL2SQLConnectionString, _RDS, mid); Job job = new(_LSL2SQLConnectionString, _RDS, mid);
if (job.IsAreaSi) if (job.IsAreaSi)
{ {
IfxDoc sendReply = GetJobsReply(job); IfxDoc sendReply = GetJobsReply(job);

View File

@ -98,8 +98,8 @@ public class FileRead : Shared.FileRead, IFileRead
Tuple<string, Test[], JsonElement[], List<FileInfo>> results = new(string.Empty, null, null, new List<FileInfo>()); Tuple<string, Test[], JsonElement[], List<FileInfo>> results = new(string.Empty, null, null, new List<FileInfo>());
_Logistics = new Logistics(this, reportFullPath, useSplitForMID: true); _Logistics = new Logistics(this, reportFullPath, useSplitForMID: true);
SetFileParameterLotIDToLogisticsMID(); SetFileParameterLotIDToLogisticsMID();
if (reportFullPath.Length < _MinFileLength) if (_Logistics.FileInfo.Length < _MinFileLength)
results.Item4.Add(new FileInfo(reportFullPath)); results.Item4.Add(_Logistics.FileInfo);
else else
{ {
IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4); IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4);
@ -107,9 +107,8 @@ public class FileRead : Shared.FileRead, IFileRead
throw new Exception(string.Concat("A) No Data - ", dateTime.Ticks)); throw new Exception(string.Concat("A) No Data - ", dateTime.Ticks));
string mid = string.Concat(processData.Reactor, "-", processData.RDS, "-", processData.PSN); string mid = string.Concat(processData.Reactor, "-", processData.RDS, "-", processData.PSN);
mid = Regex.Replace(mid, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0]; mid = Regex.Replace(mid, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
_Logistics.MID = mid;
SetFileParameterLotID(mid); SetFileParameterLotID(mid);
_Logistics.ProcessJobID = processData.Reactor; _Logistics.Update(mid, processData.Reactor);
if (!iProcessData.Details.Any()) if (!iProcessData.Details.Any())
throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks)); throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks));
results = iProcessData.GetResults(this, _Logistics, results.Item4); results = iProcessData.GetResults(this, _Logistics, results.Item4);

View File

@ -899,7 +899,7 @@ public class ProcessData : IProcessData
dataFile = ParseWaferSummary(i, dcnTotals, dwnTotals, dnnTotals); dataFile = ParseWaferSummary(i, dcnTotals, dwnTotals, dnnTotals);
_Details.Add(dataFile); _Details.Add(dataFile);
} }
fileInfoCollection.Add(new FileInfo(logistics.ReportFullPath)); fileInfoCollection.Add(logistics.FileInfo);
} }
#nullable enable #nullable enable

View File

@ -9,34 +9,46 @@ namespace Adaptation.Shared;
public class Logistics : ILogistics public class Logistics : ILogistics
{ {
public object NullData { get; private set; } protected readonly DateTime _DateTimeFromSequence;
public string JobID { get; private set; } //CellName protected readonly FileInfo _FileInfo;
public long Sequence { get; private set; } //Ticks protected readonly string _JobID;
public DateTime DateTimeFromSequence { get; private set; } protected readonly List<string> _Logistics1;
public double TotalSecondsSinceLastWriteTimeFromSequence { get; private set; } protected readonly List<Logistics2> _Logistics2;
public string MesEntity { get; private set; } //SPC protected string _MID;
public string ReportFullPath { get; private set; } //Extract file protected readonly string _MesEntity;
public string ProcessJobID { get; set; } //Reactor (duplicate but I want it in the logistics) protected readonly object _NullData;
public string MID { get; set; } //Lot & Pocket || Lot protected string _ProcessJobID;
public List<string> Tags { get; set; } protected readonly string _ReportFullPath;
public List<string> Logistics1 { get; set; } protected readonly long _Sequence;
public List<Logistics2> Logistics2 { get; set; } protected readonly double _TotalSecondsSinceLastWriteTimeFromSequence;
public DateTime DateTimeFromSequence => _DateTimeFromSequence;
public FileInfo FileInfo => _FileInfo;
public string JobID => _JobID;
public List<string> Logistics1 => _Logistics1;
public List<Logistics2> Logistics2 => _Logistics2;
public string MID => _MID;
public string MesEntity => _MesEntity;
public object NullData => _NullData;
public string ProcessJobID => _ProcessJobID;
public string ReportFullPath => _ReportFullPath;
public long Sequence => _Sequence;
public double TotalSecondsSinceLastWriteTimeFromSequence => _TotalSecondsSinceLastWriteTimeFromSequence;
public Logistics(IFileRead fileRead) public Logistics(IFileRead fileRead)
{ {
DateTime dateTime = DateTime.Now; DateTime dateTime = DateTime.Now;
NullData = null; _NullData = null;
Sequence = dateTime.Ticks; _Sequence = dateTime.Ticks;
DateTimeFromSequence = dateTime; _DateTimeFromSequence = dateTime;
JobID = fileRead.CellInstanceName; _JobID = fileRead.CellInstanceName;
TotalSecondsSinceLastWriteTimeFromSequence = (DateTime.Now - dateTime).TotalSeconds; _TotalSecondsSinceLastWriteTimeFromSequence = (DateTime.Now - dateTime).TotalSeconds;
MesEntity = DefaultMesEntity(dateTime); _MesEntity = DefaultMesEntity(dateTime);
ReportFullPath = string.Empty; _ReportFullPath = string.Empty;
ProcessJobID = nameof(ProcessJobID); _ProcessJobID = nameof(ProcessJobID);
MID = nameof(MID); _MID = nameof(MID);
Tags = new List<string>(); _Logistics1 = new string[] { string.Concat("LOGISTICS_1", '\t', "A_JOBID=", JobID, ";A_MES_ENTITY=", MesEntity, ";") }.ToList();
Logistics1 = new string[] { string.Concat("LOGISTICS_1", '\t', "A_JOBID=", JobID, ";A_MES_ENTITY=", MesEntity, ";") }.ToList(); _Logistics2 = new List<Logistics2>();
Logistics2 = new List<Logistics2>();
} }
public Logistics(IFileRead fileRead, string reportFullPath, bool useSplitForMID, int? fileInfoLength = null) public Logistics(IFileRead fileRead, string reportFullPath, bool useSplitForMID, int? fileInfoLength = null)
@ -45,19 +57,19 @@ public class Logistics : ILogistics
throw new Exception(); throw new Exception();
if (string.IsNullOrEmpty(fileRead.MesEntity)) if (string.IsNullOrEmpty(fileRead.MesEntity))
throw new Exception(); throw new Exception();
NullData = fileRead.NullData; _NullData = fileRead.NullData;
FileInfo fileInfo = new(reportFullPath); _FileInfo = new(reportFullPath);
DateTime dateTime = fileInfo.LastWriteTime; DateTime dateTime = _FileInfo.LastWriteTime;
if (fileInfoLength.HasValue && fileInfo.Length < fileInfoLength.Value) if (fileInfoLength.HasValue && _FileInfo.Length < fileInfoLength.Value)
dateTime = dateTime.AddTicks(-1); dateTime = dateTime.AddTicks(-1);
JobID = fileRead.CellInstanceName; _JobID = fileRead.CellInstanceName;
Sequence = dateTime.Ticks; _Sequence = dateTime.Ticks;
DateTimeFromSequence = dateTime; _DateTimeFromSequence = dateTime;
TotalSecondsSinceLastWriteTimeFromSequence = (DateTime.Now - dateTime).TotalSeconds; _TotalSecondsSinceLastWriteTimeFromSequence = (DateTime.Now - dateTime).TotalSeconds;
MesEntity = fileRead.MesEntity; _MesEntity = fileRead.MesEntity;
ReportFullPath = fileInfo.FullName; _ReportFullPath = _FileInfo.FullName;
ProcessJobID = nameof(ProcessJobID); _ProcessJobID = nameof(ProcessJobID);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(_FileInfo.FullName);
if (useSplitForMID) if (useSplitForMID)
{ {
if (fileNameWithoutExtension.IndexOf(".") > -1) if (fileNameWithoutExtension.IndexOf(".") > -1)
@ -67,10 +79,9 @@ public class Logistics : ILogistics
if (fileNameWithoutExtension.IndexOf("-") > -1) if (fileNameWithoutExtension.IndexOf("-") > -1)
fileNameWithoutExtension = fileNameWithoutExtension.Split('-')[0].Trim(); fileNameWithoutExtension = fileNameWithoutExtension.Split('-')[0].Trim();
} }
MID = string.Concat(fileNameWithoutExtension.Substring(0, 1).ToUpper(), fileNameWithoutExtension.Substring(1).ToLower()); _MID = string.Concat(fileNameWithoutExtension.Substring(0, 1).ToUpper(), fileNameWithoutExtension.Substring(1).ToLower());
Tags = new List<string>(); _Logistics1 = new string[] { string.Concat("LOGISTICS_1", '\t', "A_JOBID=", JobID, ";A_MES_ENTITY=", MesEntity, ";") }.ToList();
Logistics1 = new string[] { string.Concat("LOGISTICS_1", '\t', "A_JOBID=", JobID, ";A_MES_ENTITY=", MesEntity, ";") }.ToList(); _Logistics2 = new List<Logistics2>();
Logistics2 = new List<Logistics2>();
} }
public Logistics(string reportFullPath, string logistics) public Logistics(string reportFullPath, string logistics)
@ -78,57 +89,57 @@ public class Logistics : ILogistics
string key; string key;
DateTime dateTime; DateTime dateTime;
string[] segments; string[] segments;
Logistics1 = logistics.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(); _FileInfo = new(reportFullPath);
_Logistics1 = logistics.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList();
if (!Logistics1.Any() || !Logistics1[0].StartsWith("LOGISTICS_1")) if (!Logistics1.Any() || !Logistics1[0].StartsWith("LOGISTICS_1"))
{ {
NullData = null; _NullData = null;
JobID = "null"; _JobID = "null";
dateTime = new FileInfo(reportFullPath).LastWriteTime; dateTime = _FileInfo.LastWriteTime;
Sequence = dateTime.Ticks; _Sequence = dateTime.Ticks;
DateTimeFromSequence = dateTime; _DateTimeFromSequence = dateTime;
TotalSecondsSinceLastWriteTimeFromSequence = (DateTime.Now - dateTime).TotalSeconds; _TotalSecondsSinceLastWriteTimeFromSequence = (DateTime.Now - dateTime).TotalSeconds;
MesEntity = DefaultMesEntity(dateTime); _MesEntity = DefaultMesEntity(dateTime);
ReportFullPath = reportFullPath; _ReportFullPath = reportFullPath;
ProcessJobID = "R##"; _ProcessJobID = "R##";
MID = "null"; _MID = "null";
Tags = new List<string>(); _Logistics1 = new string[] { string.Concat("LOGISTICS_1", '\t', "A_JOBID=", JobID, ";A_MES_ENTITY=", MesEntity, ";") }.ToList();
Logistics1 = new string[] { string.Concat("LOGISTICS_1", '\t', "A_JOBID=", JobID, ";A_MES_ENTITY=", MesEntity, ";") }.ToList(); _Logistics2 = new List<Logistics2>();
Logistics2 = new List<Logistics2>();
} }
else else
{ {
string logistics1Line1 = Logistics1[0]; string logistics1Line1 = Logistics1[0];
key = "NULL_DATA="; key = "NULL_DATA=";
if (!logistics1Line1.Contains(key)) if (!logistics1Line1.Contains(key))
NullData = null; _NullData = null;
else else
{ {
segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries); segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries);
NullData = segments[1].Split(';')[0]; _NullData = segments[1].Split(';')[0];
} }
key = "JOBID="; key = "JOBID=";
if (!logistics1Line1.Contains(key)) if (!logistics1Line1.Contains(key))
JobID = "null"; _JobID = "null";
else else
{ {
segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries); segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries);
JobID = segments[1].Split(';')[0]; _JobID = segments[1].Split(';')[0];
} }
key = "SEQUENCE="; key = "SEQUENCE=";
if (!logistics1Line1.Contains(key)) if (!logistics1Line1.Contains(key))
dateTime = new FileInfo(reportFullPath).LastWriteTime; dateTime = _FileInfo.LastWriteTime;
else else
{ {
segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries); segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries);
if (!long.TryParse(segments[1].Split(';')[0].Split('.')[0], out long sequence) || sequence < new DateTime(1999, 1, 1).Ticks) if (!long.TryParse(segments[1].Split(';')[0].Split('.')[0], out long sequence) || sequence < new DateTime(1999, 1, 1).Ticks)
dateTime = new FileInfo(reportFullPath).LastWriteTime; dateTime = _FileInfo.LastWriteTime;
else else
dateTime = new DateTime(sequence); dateTime = new DateTime(sequence);
} }
Sequence = dateTime.Ticks; _Sequence = dateTime.Ticks;
DateTimeFromSequence = dateTime; _DateTimeFromSequence = dateTime;
TotalSecondsSinceLastWriteTimeFromSequence = (DateTime.Now - dateTime).TotalSeconds; _TotalSecondsSinceLastWriteTimeFromSequence = (DateTime.Now - dateTime).TotalSeconds;
DateTime lastWriteTime = new FileInfo(reportFullPath).LastWriteTime; DateTime lastWriteTime = _FileInfo.LastWriteTime;
if (TotalSecondsSinceLastWriteTimeFromSequence > 600) if (TotalSecondsSinceLastWriteTimeFromSequence > 600)
{ {
if (lastWriteTime != dateTime) if (lastWriteTime != dateTime)
@ -138,33 +149,32 @@ public class Logistics : ILogistics
} }
key = "MES_ENTITY="; key = "MES_ENTITY=";
if (!logistics1Line1.Contains(key)) if (!logistics1Line1.Contains(key))
MesEntity = DefaultMesEntity(dateTime); _MesEntity = DefaultMesEntity(dateTime);
else else
{ {
segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries); segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries);
MesEntity = segments[1].Split(';')[0]; _MesEntity = segments[1].Split(';')[0];
} }
ReportFullPath = reportFullPath; _ReportFullPath = reportFullPath;
key = "PROCESS_JOBID="; key = "PROCESS_JOBID=";
if (!logistics1Line1.Contains(key)) if (!logistics1Line1.Contains(key))
ProcessJobID = "R##"; _ProcessJobID = "R##";
else else
{ {
segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries); segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries);
ProcessJobID = segments[1].Split(';')[0]; _ProcessJobID = segments[1].Split(';')[0];
} }
key = "MID="; key = "MID=";
if (!logistics1Line1.Contains(key)) if (!logistics1Line1.Contains(key))
MID = "null"; _MID = "null";
else else
{ {
segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries); segments = logistics1Line1.Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries);
MID = segments[1].Split(';')[0]; _MID = segments[1].Split(';')[0];
} }
} }
Logistics2 logistics2; Logistics2 logistics2;
Tags = new List<string>(); _Logistics2 = new List<Logistics2>();
Logistics2 = new List<Logistics2>();
for (int i = 1; i < Logistics1.Count; i++) for (int i = 1; i < Logistics1.Count; i++)
{ {
if (Logistics1[i].StartsWith("LOGISTICS_2")) if (Logistics1[i].StartsWith("LOGISTICS_2"))
@ -180,29 +190,12 @@ public class Logistics : ILogistics
} }
} }
public Logistics ShallowCopy() => (Logistics)MemberwiseClone();
private static string DefaultMesEntity(DateTime dateTime) => string.Concat(dateTime.Ticks, "_MES_ENTITY"); private static string DefaultMesEntity(DateTime dateTime) => string.Concat(dateTime.Ticks, "_MES_ENTITY");
internal string GetLotViaMostCommonMethod() => MID.Substring(0, MID.Length - 2); internal void Update(string mid, string processJobID)
internal string GetPocketNumberViaMostCommonMethod() => MID.Substring(MID.Length - 2);
internal void Update(string dateTime, string processJobID, string mid)
{ {
if (!DateTime.TryParse(dateTime, out DateTime dateTimeCasted)) _MID = mid;
dateTimeCasted = DateTime.Now; _ProcessJobID = processJobID;
NullData = null;
//JobID = Description.GetCellName();
Sequence = dateTimeCasted.Ticks;
DateTimeFromSequence = dateTimeCasted;
TotalSecondsSinceLastWriteTimeFromSequence = (DateTime.Now - dateTimeCasted).TotalSeconds;
//MesEntity = DefaultMesEntity(dateTime);
//ReportFullPath = string.Empty;
ProcessJobID = processJobID;
MID = mid;
Tags = new List<string>();
Logistics1 = new string[] { string.Concat("LOGISTICS_1", '\t', "A_JOBID=", JobID, ";A_MES_ENTITY=", MesEntity, ";") }.ToList();
Logistics2 = new List<Logistics2>();
} }
} }

View File

@ -1,22 +1,23 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
namespace Adaptation.Shared.Properties; namespace Adaptation.Shared.Properties;
public interface ILogistics public interface ILogistics
{ {
public object NullData { get; }
public string JobID { get; } //CellName
public long Sequence { get; } //Ticks
public DateTime DateTimeFromSequence { get; } public DateTime DateTimeFromSequence { get; }
public FileInfo FileInfo { get; }
public string JobID { get; }
public List<string> Logistics1 { get; }
public List<Logistics2> Logistics2 { get; }
public string MID { get; }
public string MesEntity { get; }
public object NullData { get; }
public string ProcessJobID { get; }
public string ReportFullPath { get; }
public long Sequence { get; }
public double TotalSecondsSinceLastWriteTimeFromSequence { get; } public double TotalSecondsSinceLastWriteTimeFromSequence { get; }
public string MesEntity { get; } //SPC
public string ReportFullPath { get; } //Extract file
public string ProcessJobID { get; set; } //Reactor (duplicate but I want it in the logistics)
public string MID { get; set; } //Lot & Pocket || Lot
public List<string> Tags { get; set; }
public List<string> Logistics1 { get; set; }
public List<Logistics2> Logistics2 { get; set; }
} }