Synced with other adaptations
This commit is contained in:
@ -5,7 +5,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Adaptation.FileHandlers.OpenInsightMetrologyViewer;
|
||||
|
||||
@ -77,32 +76,33 @@ public class WSRequest
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
internal static long GetHeaderId(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, string openInsightMetrologyViewerFileShare, int weekOfYear, string json, List<json.Description> descriptions)
|
||||
internal static long GetHeaderId(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, string openInsightMetrologyViewerFileShare, int weekOfYear, WS.Results results, List<json.Description> descriptions)
|
||||
{
|
||||
long result;
|
||||
if (string.IsNullOrEmpty(json))
|
||||
if (results is not null && results.HeaderId is not null)
|
||||
result = results.HeaderId.Value;
|
||||
else
|
||||
{
|
||||
WSRequest wsRequest = new(fileRead, logistics, descriptions);
|
||||
string directory = Path.Combine(openInsightMetrologyViewerFileShare, logistics.DateTimeFromSequence.Year.ToString(), $"WW{weekOfYear:00}");
|
||||
(json, WS.Results wsResults) = WS.SendData(openInsightMetrologyViewerAPI, logistics.Sequence, directory, wsRequest);
|
||||
if (!wsResults.Success)
|
||||
(_, WS.Results wsResults) = WS.SendData(openInsightMetrologyViewerAPI, logistics.Sequence, directory, wsRequest);
|
||||
if (wsResults.Success is null || !wsResults.Success.Value)
|
||||
throw new Exception(wsResults.ToString());
|
||||
result = wsResults.HeaderId.Value;
|
||||
}
|
||||
WS.Results metrologyWSRequest = JsonSerializer.Deserialize<WS.Results>(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
result = metrologyWSRequest.HeaderID;
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma warning disable IDE0060
|
||||
internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, List<json.Description> descriptions, string matchDirectory, string subGroupId, long headerId, string headerIdDirectory)
|
||||
internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, List<json.Description> descriptions, string matchDirectory, WS.Results results, string headerIdDirectory)
|
||||
#pragma warning restore IDE0060
|
||||
{
|
||||
string[] jsonFiles = Directory.GetFiles(matchDirectory, "*.json", SearchOption.TopDirectoryOnly);
|
||||
if (jsonFiles.Length != 1)
|
||||
throw new Exception($"Invalid source file count for <{headerId}>!");
|
||||
throw new Exception($"Invalid source file count for <{results.HeaderId}>!");
|
||||
List<WS.Attachment> headerAttachments = new()
|
||||
{
|
||||
new WS.Attachment(subGroupId, headerId, headerIdDirectory, descriptions[0].HeaderUniqueId, "Data.json", jsonFiles.First())
|
||||
new WS.Attachment(results, headerIdDirectory, $"{logistics.JobID}_{logistics.MID}_{logistics.DateTimeFromSequence:yyyyMMddHHmmssffff}", "Data.json", jsonFiles.First())
|
||||
};
|
||||
WS.AttachFiles(openInsightMetrologyViewerAPI, headerAttachments, dataAttachments: null);
|
||||
}
|
||||
|
Reference in New Issue
Block a user