Refactor FileRead and WSRequest classes to use unique sequence and ID generation; enhance logistics handling across multiple file handlers
This commit is contained in:
@ -113,7 +113,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
StringBuilder result = new();
|
||||
pcl.Description x = descriptions[0];
|
||||
char del = '\t';
|
||||
_ = result.Append(x.AreaCountAvg).Append(del). // 001 - AreaCountAvg
|
||||
_ = result.Append(x.AreaCountAvg).Append(del). // 001 - AreaCountAvg
|
||||
Append(x.AreaCountMax).Append(del). // 002 - AreaCountMax
|
||||
Append(x.AreaCountMin).Append(del). // 003 - AreaCountMin
|
||||
Append(x.AreaCountStdDev).Append(del). // 004 - AreaCountStdDev
|
||||
@ -121,41 +121,41 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
Append(x.AreaTotalMax).Append(del). // 006 - AreaTotalMax
|
||||
Append(x.AreaTotalMin).Append(del). // 007 - AreaTotalMin
|
||||
Append(x.AreaTotalStdDev).Append(del). // 008 - AreaTotalStdDev
|
||||
Append(x.Date).Append(del). // 009 -
|
||||
Append(x.Date).Append(del). // 009 -
|
||||
Append(x.HazeAverageAvg).Append(del). // 010 - Haze Average
|
||||
Append(x.HazeAverageMax).Append(del). // 011 -
|
||||
Append(x.HazeAverageMin).Append(del). // 012 -
|
||||
Append(x.HazeAverageStdDev).Append(del). // 013 -
|
||||
Append(x.HazeRegionAvg).Append(del). // 014 -
|
||||
Append(x.HazeRegionMax).Append(del). // 015 -
|
||||
Append(x.HazeRegionMin).Append(del). // 016 -
|
||||
Append(x.HazeRegionStdDev).Append(del). // 017 -
|
||||
Append(x.Lot).Append(del). // 018 -
|
||||
Append(x.LPDCM2Avg).Append(del). // 019 -
|
||||
Append(x.LPDCM2Max).Append(del). // 020 -
|
||||
Append(x.LPDCM2Min).Append(del). // 021 -
|
||||
Append(x.LPDCM2StdDev).Append(del). // 022 -
|
||||
Append(x.LPDCountAvg).Append(del). // 023 -
|
||||
Append(x.LPDCountMax).Append(del). // 024 -
|
||||
Append(x.LPDCM2Min).Append(del). // 025 -
|
||||
Append(x.LPDCountStdDev).Append(del). // 026 -
|
||||
Append(x.Employee).Append(del). // 027 -
|
||||
Append(x.HazeAverageMax).Append(del). // 011 -
|
||||
Append(x.HazeAverageMin).Append(del). // 012 -
|
||||
Append(x.HazeAverageStdDev).Append(del). // 013 -
|
||||
Append(x.HazeRegionAvg).Append(del). // 014 -
|
||||
Append(x.HazeRegionMax).Append(del). // 015 -
|
||||
Append(x.HazeRegionMin).Append(del). // 016 -
|
||||
Append(x.HazeRegionStdDev).Append(del). // 017 -
|
||||
Append(x.Lot).Append(del). // 018 -
|
||||
Append(x.LPDCM2Avg).Append(del). // 019 -
|
||||
Append(x.LPDCM2Max).Append(del). // 020 -
|
||||
Append(x.LPDCM2Min).Append(del). // 021 -
|
||||
Append(x.LPDCM2StdDev).Append(del). // 022 -
|
||||
Append(x.LPDCountAvg).Append(del). // 023 -
|
||||
Append(x.LPDCountMax).Append(del). // 024 -
|
||||
Append(x.LPDCM2Min).Append(del). // 025 -
|
||||
Append(x.LPDCountStdDev).Append(del). // 026 -
|
||||
Append(x.Employee).Append(del). // 027 -
|
||||
Append(x.RDS).Append(del). // 028 - Lot
|
||||
Append(x.Reactor).Append(del). // 029 - Process
|
||||
Append(x.Recipe.Replace(";", string.Empty)).Append(del). // 030 - Part
|
||||
Append(x.ScratchCountAvg).Append(del). // 031 - Scratch Count
|
||||
Append(x.ScratchCountMax).Append(del). // 032 -
|
||||
Append(x.ScratchCountMin).Append(del). // 033 -
|
||||
Append(x.ScratchTotalStdDev).Append(del). // 034 -
|
||||
Append(x.ScratchCountMax).Append(del). // 032 -
|
||||
Append(x.ScratchCountMin).Append(del). // 033 -
|
||||
Append(x.ScratchTotalStdDev).Append(del). // 034 -
|
||||
Append(x.ScratchTotalAvg).Append(del). // 035 - Scratch Length
|
||||
Append(x.ScratchTotalMax).Append(del). // 036 -
|
||||
Append(x.ScratchTotalMin).Append(del). // 037 -
|
||||
Append(x.ScratchTotalStdDev).Append(del). // 038 -
|
||||
Append(x.ScratchTotalMax).Append(del). // 036 -
|
||||
Append(x.ScratchTotalMin).Append(del). // 037 -
|
||||
Append(x.ScratchTotalStdDev).Append(del). // 038 -
|
||||
Append(x.SumOfDefectsAvg).Append(del). // 039 - Average Sum of Defects
|
||||
Append(x.SumOfDefectsMax).Append(del). // 040 - Max Sum of Defects
|
||||
Append(x.SumOfDefectsMin).Append(del). // 041 - Min Sum of Defects
|
||||
Append(x.SumOfDefectsStdDev).Append(del). // 042 - SumOfDefectsStdDev
|
||||
Append(logistics.MesEntity).Append(del). // 043 -
|
||||
Append(logistics.MesEntity).Append(del). // 043 -
|
||||
AppendLine();
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
@ -267,11 +267,12 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
List<Post> results = new();
|
||||
Post post;
|
||||
long preWait;
|
||||
long uniqueSequence = Logistics.GetUniqueSequence(_Logistics);
|
||||
foreach (PreWith preWith in preWithCollection)
|
||||
{
|
||||
if (!_IsEAFHosted)
|
||||
continue;
|
||||
if (!_StaticRuns.TryGetValue(_Logistics.Sequence, out List<Shared.Metrology.WS.Results>? wsResults))
|
||||
if (!_StaticRuns.TryGetValue(uniqueSequence, out List<Shared.Metrology.WS.Results>? wsResults))
|
||||
wsResults = null;
|
||||
if (processDataStandardFormat.InputPDSF is null)
|
||||
File.Move(preWith.MatchingFile, preWith.CheckFile);
|
||||
|
||||
@ -125,13 +125,14 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
long? subgroupId;
|
||||
string fileName = Path.GetFileName(reportFullPath);
|
||||
long uniqueSequence = Logistics.GetUniqueSequence(_Logistics);
|
||||
long breakAfter = dateTime.AddSeconds(_BreakAfterSeconds).Ticks;
|
||||
long preWait = _FileConnectorConfiguration?.FileHandleWaitTime is null ? dateTime.AddMilliseconds(1234).Ticks : dateTime.AddMilliseconds(_FileConnectorConfiguration.FileHandleWaitTime.Value).Ticks;
|
||||
if (string.IsNullOrEmpty(descriptions[0].Reactor) || string.IsNullOrEmpty(descriptions[0].PSN))
|
||||
subgroupId = null;
|
||||
else
|
||||
(subgroupId, int? _, string _) = FromIQS.GetCommandText(_IqsConnectionString, _Logistics, descriptions[0], breakAfter, preWait);
|
||||
if (_StaticRuns.TryGetValue(_Logistics.Sequence, out List<WS.Results> wsResults))
|
||||
if (_StaticRuns.TryGetValue(uniqueSequence, out List<WS.Results> wsResults))
|
||||
{
|
||||
if (wsResults is null || wsResults.Count != 1)
|
||||
throw new NullReferenceException($"{nameof(wsResults)} {wsResults?.Count} != 1 {_Logistics.Sequence}!");
|
||||
|
||||
@ -113,6 +113,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
private void SendData(string reportFullPath, DateTime dateTime, JsonElement[] jsonElements, List<pcl.Description> descriptions)
|
||||
{
|
||||
string checkDirectory;
|
||||
long uniqueSequence = Logistics.GetUniqueSequence(_Logistics);
|
||||
WSRequest wsRequest = new(this, _Logistics, jsonElements, descriptions);
|
||||
int weekOfYear = _Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
|
||||
string directory = Path.Combine(_OpenInsightMetrologyViewerFileShare, dateTime.Year.ToString(), $"WW{weekOfYear:00}");
|
||||
@ -126,9 +127,9 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
_Log.Debug(wsResults.HeaderId);
|
||||
lock (_StaticRuns)
|
||||
{
|
||||
if (!_StaticRuns.ContainsKey(_Logistics.Sequence))
|
||||
_StaticRuns.Add(_Logistics.Sequence, new());
|
||||
_StaticRuns[_Logistics.Sequence].Add(wsResults);
|
||||
if (!_StaticRuns.ContainsKey(uniqueSequence))
|
||||
_StaticRuns.Add(uniqueSequence, new());
|
||||
_StaticRuns[uniqueSequence].Add(wsResults);
|
||||
}
|
||||
checkDirectory = Path.Combine(directory, $"-{wsResults.HeaderId}");
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
|
||||
@ -182,6 +182,7 @@ public class WSRequest
|
||||
Details.Add(detail);
|
||||
}
|
||||
Date = logistics.DateTimeFromSequence.ToString();
|
||||
string uniqueId = Logistics.GetUniqueId(logistics);
|
||||
if (UniqueId is null && Details.Count != 0)
|
||||
UniqueId = Details[0].HeaderUniqueId;
|
||||
for (int i = 0; i < Details.Count; i++)
|
||||
@ -203,11 +204,11 @@ public class WSRequest
|
||||
if (string.IsNullOrEmpty(Details[i].Bin8))
|
||||
Details[i].Bin8 = null;
|
||||
}
|
||||
UniqueId = $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}";
|
||||
UniqueId = uniqueId;
|
||||
for (int i = 0; i < Details.Count; i++)
|
||||
{
|
||||
Details[i].HeaderUniqueId = UniqueId;
|
||||
Details[i].UniqueId = $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}_Item-{i + 1}";
|
||||
Details[i].UniqueId = $"{uniqueId}_Item-{i + 1}";
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,6 +319,7 @@ public class WSRequest
|
||||
{
|
||||
string checkFileName;
|
||||
pcl.Description description;
|
||||
string uniqueId = Logistics.GetUniqueId(logistics);
|
||||
string[] pclFiles = Directory.GetFiles(matchDirectory, "*.pcl", SearchOption.TopDirectoryOnly);
|
||||
if (pclFiles.Length != 1)
|
||||
throw new Exception($"Invalid source file count for <{results.HeaderId}>!");
|
||||
@ -330,19 +332,19 @@ public class WSRequest
|
||||
else
|
||||
{
|
||||
UpdateDataPDF(descriptions, checkFileName);
|
||||
headerAttachments.Add(new WS.Attachment(results, headerIdDirectory, $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}", "Data.pdf", checkFileName));
|
||||
headerAttachments.Add(new WS.Attachment(results, headerIdDirectory, uniqueId, "Data.pdf", checkFileName));
|
||||
}
|
||||
for (int i = 0; i < descriptions.Count; i++)
|
||||
{
|
||||
description = descriptions[i];
|
||||
checkFileName = Path.Combine(matchDirectory, $"{sourceFileNameNoExt}_s{description.Slot}_image.pdf");
|
||||
if (File.Exists(checkFileName))
|
||||
dataAttachments.Add(new WS.Attachment(results, headerIdDirectory, $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}_Item-{i + 1}", "Image.pdf", checkFileName));
|
||||
dataAttachments.Add(new WS.Attachment(results, headerIdDirectory, $"{uniqueId}_Item-{i + 1}", "Image.pdf", checkFileName));
|
||||
else
|
||||
{
|
||||
checkFileName = Path.Combine(matchDirectory, $"{sourceFileNameNoExt}_s{description.Slot}_data.pdf");
|
||||
if (File.Exists(checkFileName))
|
||||
dataAttachments.Add(new WS.Attachment(results, headerIdDirectory, $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}_Item-{i + 1}", "Image.pdf", checkFileName));
|
||||
dataAttachments.Add(new WS.Attachment(results, headerIdDirectory, $"{uniqueId}_Item-{i + 1}", "Image.pdf", checkFileName));
|
||||
}
|
||||
}
|
||||
if (dataAttachments.Count == 0 || dataAttachments.Count != descriptions.Count)
|
||||
|
||||
@ -141,8 +141,9 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
string jobIdDirectory = Path.Combine(Path.GetDirectoryName(_FileConnectorConfiguration.AlternateTargetFolder) ?? throw new Exception(), _Logistics.JobID);
|
||||
if (!Directory.Exists(jobIdDirectory))
|
||||
_ = Directory.CreateDirectory(jobIdDirectory);
|
||||
long uniqueSequence = Logistics.GetUniqueSequence(_Logistics);
|
||||
string[] matchDirectories = GetInProcessDirectory(jobIdDirectory);
|
||||
if (!_StaticRuns.TryGetValue(_Logistics.Sequence, out List<Shared.Metrology.WS.Results>? wsResults))
|
||||
if (!_StaticRuns.TryGetValue(uniqueSequence, out List<Shared.Metrology.WS.Results>? wsResults))
|
||||
results = null;
|
||||
else
|
||||
{
|
||||
|
||||
@ -114,6 +114,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
FileInfo fileInfo = new(reportFullPath);
|
||||
string logisticsSequence = _Logistics.Sequence.ToString();
|
||||
long uniqueSequence = Logistics.GetUniqueSequence(_Logistics);
|
||||
string jobIdDirectory = Path.Combine(_JobIdParentDirectory, _Logistics.JobID);
|
||||
if (!Directory.Exists(jobIdDirectory))
|
||||
_ = Directory.CreateDirectory(jobIdDirectory);
|
||||
@ -136,7 +137,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
File.Copy(reportFullPath, Path.Combine(sequenceDirectory, Path.GetFileName(reportFullPath)), overwrite: true);
|
||||
File.WriteAllText(jsonFileName, json);
|
||||
lock (_StaticRuns)
|
||||
_ = _StaticRuns.Remove(_Logistics.Sequence);
|
||||
_ = _StaticRuns.Remove(uniqueSequence);
|
||||
}
|
||||
|
||||
private static void MoveMatchingFile(string jobIdDirectory, string matchDirectory)
|
||||
|
||||
@ -199,4 +199,31 @@ public class Logistics : ILogistics
|
||||
_ProcessJobID = processJobID;
|
||||
}
|
||||
|
||||
private static int GetCountFromFileName(Logistics logistics)
|
||||
{
|
||||
int result;
|
||||
string[] segments = logistics.FileInfo.Name.Split('.');
|
||||
string[] segmentsB = segments[0].Split('_');
|
||||
string countFromFileName = segmentsB.Length < 3 ? "0" : segmentsB[2];
|
||||
if (!int.TryParse(countFromFileName, out result))
|
||||
result = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static long GetUniqueSequence(Logistics logistics)
|
||||
{
|
||||
long result;
|
||||
int countFromFileName = GetCountFromFileName(logistics);
|
||||
result = (logistics.Sequence * 10) + countFromFileName;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetUniqueId(Logistics logistics)
|
||||
{
|
||||
string result;
|
||||
int countFromFileName = GetCountFromFileName(logistics);
|
||||
result = $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}_{countFromFileName}";
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -665,7 +665,7 @@ internal class ProcessDataStandardFormat
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static string GetPDSFText(IFileRead fileRead, Logistics logistics, JsonElement[] jsonElements, string logisticsText)
|
||||
internal static string GetPDSFText(IFileRead fileRead, Logistics logistics, JsonElement[] jsonElements, string? logisticsText)
|
||||
{
|
||||
string result;
|
||||
if (jsonElements.Length == 0)
|
||||
@ -850,33 +850,6 @@ internal class ProcessDataStandardFormat
|
||||
return string.Concat(((int)searchFor).ToString().PadLeft(2, '0'), separator, searchFor.ToString().Replace("In", string.Concat(separator, "In")).Replace("Ex", string.Concat(separator, "Ex")));
|
||||
}
|
||||
|
||||
private static int? TryGetPropertyIndex(JsonProperty[] jsonProperties, string propertyName)
|
||||
{
|
||||
int? result = null;
|
||||
for (int i = 0; i < jsonProperties.Length; i++)
|
||||
{
|
||||
if (jsonProperties[i].Name != propertyName)
|
||||
continue;
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
if (result is null)
|
||||
{
|
||||
for (int i = 0; i < jsonProperties.Length; i++)
|
||||
{
|
||||
if (jsonProperties[i].Name[0] != propertyName[0])
|
||||
continue;
|
||||
if (jsonProperties[i].Name.Length != propertyName.Length)
|
||||
continue;
|
||||
if (jsonProperties[i].Name != propertyName)
|
||||
continue;
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetXml(ProcessDataStandardFormat processDataStandardFormat)
|
||||
{
|
||||
string result;
|
||||
|
||||
@ -199,4 +199,31 @@ public class Logistics : ILogistics
|
||||
_ProcessJobID = processJobID;
|
||||
}
|
||||
|
||||
private static int GetCountFromFileName(Logistics logistics)
|
||||
{
|
||||
int result;
|
||||
string[] segments = logistics.FileInfo.Name.Split('.');
|
||||
string[] segmentsB = segments[0].Split('_');
|
||||
string countFromFileName = segmentsB.Length < 3 ? "0" : segmentsB[2];
|
||||
if (!int.TryParse(countFromFileName, out result))
|
||||
result = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static long GetUniqueSequence(Logistics logistics)
|
||||
{
|
||||
long result;
|
||||
int countFromFileName = GetCountFromFileName(logistics);
|
||||
result = (logistics.Sequence * 10) + countFromFileName;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetUniqueId(Logistics logistics)
|
||||
{
|
||||
string result;
|
||||
int countFromFileName = GetCountFromFileName(logistics);
|
||||
result = $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}_{countFromFileName}";
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user