Refactor WSRequest to streamline attachment handling and improve error checking for PDF file counts
This commit is contained in:
@ -662,52 +662,34 @@ public class WSRequest
|
|||||||
internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, string ghostPCLFileName, List<txt.Description> descriptions, string matchDirectory, WS.Results results, string headerIdDirectory)
|
internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, string ghostPCLFileName, List<txt.Description> descriptions, string matchDirectory, WS.Results results, string headerIdDirectory)
|
||||||
#pragma warning restore IDE0060
|
#pragma warning restore IDE0060
|
||||||
{
|
{
|
||||||
string extension;
|
string pdfFile;
|
||||||
|
string extension = ".pdf";
|
||||||
List<string> attachmentFiles = new();
|
List<string> attachmentFiles = new();
|
||||||
string uniqueId = Logistics.GetUniqueId(logistics);
|
string uniqueId = Logistics.GetUniqueId(logistics);
|
||||||
string[] summaryFiles = Directory.GetFiles(matchDirectory, "*.txt", SearchOption.TopDirectoryOnly);
|
string[] summaryFiles = Directory.GetFiles(matchDirectory, "*.txt", SearchOption.TopDirectoryOnly);
|
||||||
if (summaryFiles.Length != 1)
|
if (summaryFiles.Length != 1)
|
||||||
throw new Exception($"Invalid source file count for <{results.HeaderId}>!");
|
throw new Exception($"Invalid source file count for <{results.HeaderId}>!");
|
||||||
string[] xpsFiles = Directory.GetFiles(matchDirectory, "*.xps", SearchOption.TopDirectoryOnly);
|
string[] prnFiles = Directory.GetFiles(matchDirectory, "WaferMap*.prn", SearchOption.TopDirectoryOnly);
|
||||||
if (xpsFiles.Length > 0)
|
foreach (string prnFile in prnFiles.OrderBy(l => l))
|
||||||
{
|
{
|
||||||
extension = ".xps";
|
pdfFile = ConvertSourceFileToPdf(ghostPCLFileName, prnFile);
|
||||||
foreach (string xpsFile in xpsFiles.OrderBy(l => l))
|
attachmentFiles.Add(pdfFile);
|
||||||
attachmentFiles.Add(xpsFile);
|
|
||||||
if (attachmentFiles.Count == 0 || attachmentFiles.Count != descriptions.Count)
|
|
||||||
throw new Exception("Invalid *.pdf file count!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string pdfFile;
|
|
||||||
extension = ".pdf";
|
|
||||||
string[] prnFiles = Directory.GetFiles(matchDirectory, "WaferMap*.prn", SearchOption.TopDirectoryOnly);
|
|
||||||
foreach (string prnFile in prnFiles.OrderBy(l => l))
|
|
||||||
{
|
|
||||||
pdfFile = ConvertSourceFileToPdf(ghostPCLFileName, prnFile);
|
|
||||||
attachmentFiles.Add(pdfFile);
|
|
||||||
}
|
|
||||||
if (attachmentFiles.Count == 0 || attachmentFiles.Count != descriptions.Count)
|
|
||||||
throw new Exception("Invalid *.pdf file count!");
|
|
||||||
}
|
}
|
||||||
|
if (attachmentFiles.Count == 0)
|
||||||
|
throw new Exception("Invalid *.pdf file count!");
|
||||||
List<WS.Attachment> dataAttachments = new();
|
List<WS.Attachment> dataAttachments = new();
|
||||||
List<WS.Attachment> headerAttachments = new()
|
List<WS.Attachment> headerAttachments = new()
|
||||||
{
|
{
|
||||||
new WS.Attachment(results, headerIdDirectory, uniqueId, "Data.txt", summaryFiles[0])
|
new WS.Attachment(results, headerIdDirectory, uniqueId, "Data.txt", summaryFiles[0])
|
||||||
};
|
};
|
||||||
int count;
|
for (int i = 0; i < attachmentFiles.Count; i++)
|
||||||
if (attachmentFiles.Count < descriptions.Count)
|
|
||||||
count = attachmentFiles.Count;
|
|
||||||
else
|
|
||||||
count = descriptions.Count;
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(attachmentFiles[i]))
|
if (!string.IsNullOrEmpty(attachmentFiles[i]))
|
||||||
dataAttachments.Add(new WS.Attachment(results, headerIdDirectory, $"{uniqueId}_Item-{i + 1}", $"Image{extension}", attachmentFiles[i]));
|
dataAttachments.Add(new WS.Attachment(results, headerIdDirectory, $"{uniqueId}_Item-{i + 1}", $"Image{extension}", attachmentFiles[i]));
|
||||||
}
|
}
|
||||||
if (dataAttachments.Count == 0 || dataAttachments.Count != descriptions.Count)
|
|
||||||
throw new Exception($"Invalid attachment count! {dataAttachments.Count} != {descriptions.Count}");
|
|
||||||
WS.AttachFiles(openInsightMetrologyViewerAPI, headerAttachments, dataAttachments);
|
WS.AttachFiles(openInsightMetrologyViewerAPI, headerAttachments, dataAttachments);
|
||||||
|
if (attachmentFiles.Count == 0 || attachmentFiles.Count != descriptions.Count)
|
||||||
|
throw new Exception("Invalid *.pdf file count!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user