Handle two sequential runs by only parsing the last
Refactor FileRead and WSRequest classes to utilize unique sequence and unique ID generation; enhance JSON handling and improve code clarity.
This commit is contained in:
@ -97,9 +97,9 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
|
|
||||||
private void CallbackInProcessCleared(string sourceArchiveFile, string traceDummyFile, string targetFileLocation, string monARessource, string inProcessDirectory, long sequence, bool warning)
|
private void CallbackInProcessCleared(string sourceArchiveFile, string traceDummyFile, string targetFileLocation, string monARessource, string inProcessDirectory, long sequence, bool warning)
|
||||||
{
|
{
|
||||||
const string site = "sjc";
|
const string site = "els";
|
||||||
string stateName = string.Concat("Dummy_", _EventName);
|
string stateName = string.Concat("Dummy_", _EventName);
|
||||||
const string monInURL = "http://moninhttp.sjc.infineon.com/input/text";
|
const string monInURL = $"http://moninhttp.{site}.infineon.com/input/text";
|
||||||
MonIn monIn = MonIn.GetInstance(monInURL);
|
MonIn monIn = MonIn.GetInstance(monInURL);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@ -267,11 +267,12 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
List<Post> results = new();
|
List<Post> results = new();
|
||||||
Post post;
|
Post post;
|
||||||
long preWait;
|
long preWait;
|
||||||
|
long uniqueSequence = Logistics.GetUniqueSequence(_Logistics);
|
||||||
foreach (PreWith preWith in preWithCollection)
|
foreach (PreWith preWith in preWithCollection)
|
||||||
{
|
{
|
||||||
if (!_IsEAFHosted)
|
if (!_IsEAFHosted)
|
||||||
continue;
|
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;
|
wsResults = null;
|
||||||
if (processDataStandardFormat.InputPDSF is null)
|
if (processDataStandardFormat.InputPDSF is null)
|
||||||
File.Move(preWith.MatchingFile, preWith.CheckFile);
|
File.Move(preWith.MatchingFile, preWith.CheckFile);
|
||||||
|
|||||||
@ -141,13 +141,14 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
{
|
{
|
||||||
long? subgroupId;
|
long? subgroupId;
|
||||||
string fileName = Path.GetFileName(reportFullPath);
|
string fileName = Path.GetFileName(reportFullPath);
|
||||||
|
long uniqueSequence = Logistics.GetUniqueSequence(_Logistics);
|
||||||
long breakAfter = dateTime.AddSeconds(_BreakAfterSeconds).Ticks;
|
long breakAfter = dateTime.AddSeconds(_BreakAfterSeconds).Ticks;
|
||||||
long preWait = _FileConnectorConfiguration?.FileHandleWaitTime is null ? dateTime.AddMilliseconds(1234).Ticks : dateTime.AddMilliseconds(_FileConnectorConfiguration.FileHandleWaitTime.Value).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))
|
if (string.IsNullOrEmpty(descriptions[0].Reactor) || string.IsNullOrEmpty(descriptions[0].PSN))
|
||||||
subgroupId = null;
|
subgroupId = null;
|
||||||
else
|
else
|
||||||
(subgroupId, int? _, string _) = FromIQS.GetCommandText(_IqsConnectionString, _Logistics, descriptions[0], breakAfter, preWait);
|
(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)
|
if (wsResults is null || wsResults.Count != 1)
|
||||||
throw new NullReferenceException($"{nameof(wsResults)} {wsResults?.Count} != 1 {_Logistics.Sequence}!");
|
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)
|
private void SendData(string reportFullPath, DateTime dateTime, JsonElement[] jsonElements, List<pcl.Description> descriptions)
|
||||||
{
|
{
|
||||||
string checkDirectory;
|
string checkDirectory;
|
||||||
|
long uniqueSequence = Logistics.GetUniqueSequence(_Logistics);
|
||||||
WSRequest wsRequest = new(this, _Logistics, jsonElements, descriptions);
|
WSRequest wsRequest = new(this, _Logistics, jsonElements, descriptions);
|
||||||
int weekOfYear = _Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
|
int weekOfYear = _Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
|
||||||
string directory = Path.Combine(_OpenInsightMetrologyViewerFileShare, dateTime.Year.ToString(), $"WW{weekOfYear:00}");
|
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);
|
_Log.Debug(wsResults.HeaderId);
|
||||||
lock (_StaticRuns)
|
lock (_StaticRuns)
|
||||||
{
|
{
|
||||||
if (!_StaticRuns.ContainsKey(_Logistics.Sequence))
|
if (!_StaticRuns.ContainsKey(uniqueSequence))
|
||||||
_StaticRuns.Add(_Logistics.Sequence, new());
|
_StaticRuns.Add(uniqueSequence, new());
|
||||||
_StaticRuns[_Logistics.Sequence].Add(wsResults);
|
_StaticRuns[uniqueSequence].Add(wsResults);
|
||||||
}
|
}
|
||||||
checkDirectory = Path.Combine(directory, $"-{wsResults.HeaderId}");
|
checkDirectory = Path.Combine(directory, $"-{wsResults.HeaderId}");
|
||||||
if (!Directory.Exists(checkDirectory))
|
if (!Directory.Exists(checkDirectory))
|
||||||
|
|||||||
@ -158,11 +158,12 @@ public class WSRequest
|
|||||||
Details.Add(detail);
|
Details.Add(detail);
|
||||||
}
|
}
|
||||||
Date ??= logistics.DateTimeFromSequence.ToString();
|
Date ??= logistics.DateTimeFromSequence.ToString();
|
||||||
UniqueId = $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}";
|
string uniqueId = Logistics.GetUniqueId(logistics);
|
||||||
|
UniqueId = uniqueId;
|
||||||
for (int i = 0; i < Details.Count; i++)
|
for (int i = 0; i < Details.Count; i++)
|
||||||
{
|
{
|
||||||
Details[i].HeaderUniqueId = UniqueId;
|
Details[i].HeaderUniqueId = UniqueId;
|
||||||
Details[i].UniqueId = $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}_Item-{i + 1}";
|
Details[i].UniqueId = $"{uniqueId}_Item-{i + 1}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +209,7 @@ public class WSRequest
|
|||||||
internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, string lincPDFCFileName, List<pcl.Description> descriptions, string matchDirectory, WS.Results results, string headerIdDirectory)
|
internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, string lincPDFCFileName, List<pcl.Description> descriptions, string matchDirectory, WS.Results results, string headerIdDirectory)
|
||||||
#pragma warning restore IDE0060
|
#pragma warning restore IDE0060
|
||||||
{
|
{
|
||||||
|
string uniqueId = Logistics.GetUniqueId(logistics);
|
||||||
string[] pclFiles = Directory.GetFiles(matchDirectory, "*.pcl", SearchOption.TopDirectoryOnly);
|
string[] pclFiles = Directory.GetFiles(matchDirectory, "*.pcl", SearchOption.TopDirectoryOnly);
|
||||||
if (pclFiles.Length != 1)
|
if (pclFiles.Length != 1)
|
||||||
throw new Exception($"Invalid source file count for <{results.HeaderId}>!");
|
throw new Exception($"Invalid source file count for <{results.HeaderId}>!");
|
||||||
@ -226,7 +228,7 @@ public class WSRequest
|
|||||||
throw new Exception("Invalid *.pdf file count!");
|
throw new Exception("Invalid *.pdf file count!");
|
||||||
List<WS.Attachment> headerAttachments = new()
|
List<WS.Attachment> headerAttachments = new()
|
||||||
{
|
{
|
||||||
new WS.Attachment(results, headerIdDirectory, $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}", "Data.pdf", pdfFiles[0])
|
new WS.Attachment(results, headerIdDirectory, uniqueId, "Data.pdf", pdfFiles[0])
|
||||||
};
|
};
|
||||||
WS.AttachFiles(openInsightMetrologyViewerAPI, headerAttachments, dataAttachments: null);
|
WS.AttachFiles(openInsightMetrologyViewerAPI, headerAttachments, dataAttachments: null);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -145,8 +145,9 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
string jobIdDirectory = Path.Combine(Path.GetDirectoryName(_FileConnectorConfiguration.AlternateTargetFolder) ?? throw new Exception(), _Logistics.JobID);
|
string jobIdDirectory = Path.Combine(Path.GetDirectoryName(_FileConnectorConfiguration.AlternateTargetFolder) ?? throw new Exception(), _Logistics.JobID);
|
||||||
if (!Directory.Exists(jobIdDirectory))
|
if (!Directory.Exists(jobIdDirectory))
|
||||||
_ = Directory.CreateDirectory(jobIdDirectory);
|
_ = Directory.CreateDirectory(jobIdDirectory);
|
||||||
|
long uniqueSequence = Logistics.GetUniqueSequence(_Logistics);
|
||||||
string[] matchDirectories = GetInProcessDirectory(jobIdDirectory);
|
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;
|
results = null;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -114,6 +114,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
throw new ArgumentNullException(nameof(dateTime));
|
throw new ArgumentNullException(nameof(dateTime));
|
||||||
FileInfo fileInfo = new(reportFullPath);
|
FileInfo fileInfo = new(reportFullPath);
|
||||||
string logisticsSequence = _Logistics.Sequence.ToString();
|
string logisticsSequence = _Logistics.Sequence.ToString();
|
||||||
|
long uniqueSequence = Logistics.GetUniqueSequence(_Logistics);
|
||||||
string jobIdDirectory = Path.Combine(_JobIdParentDirectory, _Logistics.JobID);
|
string jobIdDirectory = Path.Combine(_JobIdParentDirectory, _Logistics.JobID);
|
||||||
if (!Directory.Exists(jobIdDirectory))
|
if (!Directory.Exists(jobIdDirectory))
|
||||||
_ = Directory.CreateDirectory(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.Copy(reportFullPath, Path.Combine(sequenceDirectory, Path.GetFileName(reportFullPath)), overwrite: true);
|
||||||
File.WriteAllText(jsonFileName, json);
|
File.WriteAllText(jsonFileName, json);
|
||||||
lock (_StaticRuns)
|
lock (_StaticRuns)
|
||||||
_ = _StaticRuns.Remove(_Logistics.Sequence);
|
_ = _StaticRuns.Remove(uniqueSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MoveMatchingFile(string jobIdDirectory, string matchDirectory)
|
private static void MoveMatchingFile(string jobIdDirectory, string matchDirectory)
|
||||||
|
|||||||
@ -5,6 +5,7 @@ internal class Constant
|
|||||||
|
|
||||||
public int Take { get; } = 11;
|
public int Take { get; } = 11;
|
||||||
public string Site { get; } = "Site: ";
|
public string Site { get; } = "Site: ";
|
||||||
|
public string Page1 { get; } = "Page 1";
|
||||||
public string Multiple { get; } = "MULTIPLE";
|
public string Multiple { get; } = "MULTIPLE";
|
||||||
public string SummaryLine { get; } = "SUMMARY A A";
|
public string SummaryLine { get; } = "SUMMARY A A";
|
||||||
public string LastUnits { get; } = "Flat Z: Grade : % Flat Z: Grade : % Flat Z: Grade : %";
|
public string LastUnits { get; } = "Flat Z: Grade : % Flat Z: Grade : % Flat Z: Grade : %";
|
||||||
|
|||||||
@ -25,11 +25,17 @@ internal class Run
|
|||||||
public Summary Summary { get; }
|
public Summary Summary { get; }
|
||||||
public ReadOnlyCollection<Point> Points { get; }
|
public ReadOnlyCollection<Point> Points { get; }
|
||||||
|
|
||||||
private static ReadOnlyCollection<string> FilterLines(ReadOnlyCollection<string> collection)
|
private static ReadOnlyCollection<string> FilterLines(ReadOnlyCollection<string> collection, Constant constant)
|
||||||
{
|
{
|
||||||
List<string> results = new();
|
List<string> results = new();
|
||||||
foreach (string line in collection)
|
foreach (string line in collection)
|
||||||
{
|
{
|
||||||
|
if (line.EndsWith(constant.Page1))
|
||||||
|
{
|
||||||
|
results.Clear();
|
||||||
|
results.Add(line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (string.IsNullOrEmpty(line) || line is "*" or "@")
|
if (string.IsNullOrEmpty(line) || line is "*" or "@")
|
||||||
continue;
|
continue;
|
||||||
if (line.Length < 3 || line[0] is not '*' and not '@' || line[1] != ' ')
|
if (line.Length < 3 || line[0] is not '*' and not '@' || line[1] != ' ')
|
||||||
@ -109,7 +115,7 @@ internal class Run
|
|||||||
{
|
{
|
||||||
Run? result;
|
Run? result;
|
||||||
Constant constant = new();
|
Constant constant = new();
|
||||||
ReadOnlyCollection<string> lines = FilterLines(collection);
|
ReadOnlyCollection<string> lines = FilterLines(collection, constant);
|
||||||
if (collection.Count <= constant.Take)
|
if (collection.Count <= constant.Take)
|
||||||
result = null;
|
result = null;
|
||||||
else
|
else
|
||||||
|
|||||||
@ -199,4 +199,31 @@ public class Logistics : ILogistics
|
|||||||
_ProcessJobID = processJobID;
|
_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;
|
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;
|
string result;
|
||||||
if (jsonElements.Length == 0)
|
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")));
|
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)
|
internal static string GetXml(ProcessDataStandardFormat processDataStandardFormat)
|
||||||
{
|
{
|
||||||
string result;
|
string result;
|
||||||
|
|||||||
Reference in New Issue
Block a user