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))

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Threading;
namespace Adaptation.FileHandlers.TIBCO.Transport;
@ -19,12 +20,14 @@ internal partial class Main
private static string _BarcodeHostFileShare;
private static string _LSL2SQLConnectionString;
private static string _TibcoParameterSubjectPrefix;
private static HttpClient _HttpClient;
private static FileConnectorConfiguration _FileConnectorConfiguration;
internal static void Initialize(ISMTP smtp, string cellInstanceName, FileConnectorConfiguration fileConnectorConfiguration, string lsl2SQLConnectionString, string metrologyFileShare, string barcodeHostFileShare)
internal static void Initialize(ISMTP smtp, string cellInstanceName, FileConnectorConfiguration fileConnectorConfiguration, string lsl2SQLConnectionString, string metrologyFileShare, string barcodeHostFileShare, HttpClient httpClient)
{
_SMTP = smtp;
_IfxTransport = null;
_HttpClient = httpClient;
_CellInstanceName = cellInstanceName;
_MetrologyFileShare = metrologyFileShare;
_TibcoParameterSubjectPrefix = string.Empty;
@ -186,7 +189,7 @@ internal partial class Main
if (!subject.Contains(_TibcoParameterSubjectPrefix))
throw new Exception("Invalid Subject");
mid = GetJobsMID(envelopeDocument);
Job job = new(_LSL2SQLConnectionString, _MetrologyFileShare, _BarcodeHostFileShare, mid);
Job job = new(_LSL2SQLConnectionString, _MetrologyFileShare, _BarcodeHostFileShare, _HttpClient, mid);
if (job.IsAreaSi)
{
IfxDoc sendReply = GetJobsReply(job);

View File

@ -0,0 +1,18 @@
using System.Text.Json.Serialization;
namespace Adaptation.FileHandlers.TIBCO.Transport;
public class Reactor
{
[JsonConstructor]
public Reactor(int reactorNo, int[] loadedRDS)
{
ReactorNo = reactorNo;
LoadedRDS = loadedRDS;
}
[JsonPropertyName("reactorNo")] public int ReactorNo { get; } // { init; get; }
[JsonPropertyName("loadedRDS")] public int[] LoadedRDS { get; } // { init; get; }
}

View File

@ -0,0 +1,14 @@
using System.Text.Json.Serialization;
namespace Adaptation.FileHandlers.TIBCO.Transport;
public class ReactorRoot
{
[JsonConstructor]
public ReactorRoot(Reactor reactor) =>
Reactor = reactor;
[JsonPropertyName("reactor")] public Reactor Reactor { get; } // { init; get; }
}

View File

@ -0,0 +1,18 @@
using System.Text.Json.Serialization;
namespace Adaptation.FileHandlers.TIBCO.Transport;
public class RunDataSheet
{
[JsonConstructor]
public RunDataSheet(int psn, int reactor)
{
PSN = psn;
Reactor = reactor;
}
[JsonPropertyName("PSN")] public int PSN { get; } // { init; get; }
[JsonPropertyName("reactor")] public int Reactor { get; } // { init; get; }
}

View File

@ -0,0 +1,14 @@
using System.Text.Json.Serialization;
namespace Adaptation.FileHandlers.TIBCO.Transport;
public class RunDataSheetRoot
{
[JsonConstructor]
public RunDataSheetRoot(RunDataSheet runDataSheet) =>
RunDataSheet = runDataSheet;
[JsonPropertyName("rds")] public RunDataSheet RunDataSheet { get; } // { init; get; }
}