Ready to test

This commit is contained in:
2024-09-13 17:53:26 -07:00
parent adc995c67d
commit e45c71f358
9 changed files with 184 additions and 13 deletions

View File

@ -5,9 +5,11 @@ using System.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Adaptation.FileHandlers.TIBCO.Transport;
@ -37,7 +39,7 @@ public partial class Job
public DateTime DateTime { get; }
public List<Item> Items { get; }
public Job(string lsl2SQLConnectionString, string metrologyFileShare, string barcodeHostFileShare, string mid)
public Job(string lsl2SQLConnectionString, string metrologyFileShare, string barcodeHostFileShare, HttpClient httpClient, string mid)
{
const int zero = 0;
Items = new List<Item>();
@ -59,7 +61,10 @@ public partial class Job
DateTime = DateTime.Now;
else
DateTime = new DateTime(sequence);
if (!string.IsNullOrEmpty(input.MID) && !string.IsNullOrEmpty(input.MesEntity) && Regex.IsMatch(input.MID, reactorNumberPattern) && input.MesEntity is bioRad2 or bioRad3)
const string dep08CEPIEPSILON = "DEP08CEPIEPSILON";
if (input.EquipmentType == dep08CEPIEPSILON)
(common, workOrder) = Get(input, httpClient);
else if (!string.IsNullOrEmpty(input.MID) && !string.IsNullOrEmpty(input.MesEntity) && Regex.IsMatch(input.MID, reactorNumberPattern) && input.MesEntity is bioRad2 or bioRad3)
(common, workOrder) = Get(input, barcodeHostFileShare);
else
{
@ -348,6 +353,63 @@ public partial class Job
return result;
}
private static (Common common, WorkOrder workOrder) Get(Input input, HttpClient httpClient)
{
int? rds;
string psn;
Common common;
WorkOrder workOrder;
Task<Stream> streamTask;
string zone = string.Empty;
string layer = string.Empty;
Task<HttpResponseMessage> httpResponseMessageTask;
JsonSerializerOptions jsonSerializerOptions = new() { PropertyNameCaseInsensitive = true };
int? reactor = !int.TryParse(input.MID.Substring(0, 2), out int reactorNumber) ? null : reactorNumber;
httpResponseMessageTask = httpClient.GetAsync($"{httpClient.BaseAddress}/reactors/{reactor}");
httpResponseMessageTask.Wait();
if (httpResponseMessageTask.Result.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception($"Unable to OI <{httpResponseMessageTask.Result.StatusCode}>");
streamTask = httpResponseMessageTask.Result.Content.ReadAsStreamAsync();
streamTask.Wait();
if (!streamTask.Result.CanRead)
throw new NullReferenceException(nameof(streamTask));
ReactorRoot? reactorRoot = JsonSerializer.Deserialize<ReactorRoot>(streamTask.Result, jsonSerializerOptions);
streamTask.Result.Dispose();
if (reactorRoot is null || reactor != reactorRoot.Reactor.ReactorNo || reactorRoot.Reactor.LoadedRDS is null || reactorRoot.Reactor.LoadedRDS.Length < 1)
{
rds = null;
psn = string.Empty;
workOrder = new(null, null, null, null, false);
common = new(layer, psn, rds, reactor, zone);
}
else
{
rds = reactorRoot.Reactor.LoadedRDS[0];
workOrder = new(null, null, null, null, false);
httpResponseMessageTask = httpClient.GetAsync($"{httpClient.BaseAddress}/materials/rds/{rds}");
httpResponseMessageTask.Wait();
if (httpResponseMessageTask.Result.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception($"Unable to OI <{httpResponseMessageTask.Result.StatusCode}>");
streamTask = httpResponseMessageTask.Result.Content.ReadAsStreamAsync();
streamTask.Wait();
if (!streamTask.Result.CanRead)
throw new NullReferenceException(nameof(streamTask));
RunDataSheetRoot? runDataSheetRoot = JsonSerializer.Deserialize<RunDataSheetRoot>(streamTask.Result, jsonSerializerOptions);
streamTask.Result.Dispose();
if (runDataSheetRoot is null || reactor != runDataSheetRoot.RunDataSheet.Reactor)
{
psn = string.Empty;
common = new(layer, psn, rds, reactor, zone);
}
else
{
psn = runDataSheetRoot.RunDataSheet.PSN.ToString();
common = new(layer, psn, rds, reactor, zone);
}
}
return new(common, workOrder);
}
private static (Common common, WorkOrder workOrder) Get(Input input, string barcodeHostFileShare)
{
if (string.IsNullOrEmpty(barcodeHostFileShare) || !Directory.Exists(barcodeHostFileShare))