using Adaptation.FileHandlers.txt;

Sequence as a string
Job Update using null
This commit is contained in:
2025-02-17 12:45:31 -07:00
parent ba22cebdf2
commit 0788998e09
7 changed files with 153 additions and 107 deletions

View File

@ -1,21 +1,30 @@
namespace Adaptation.FileHandlers.TIBCO.Transport;
#nullable enable
public class Common
{
public string Layer { get; }
public string PSN { get; }
public string? Layer { get; }
public string? PSN { get; }
public int? RDSNumber { get; }
public int? ReactorNumber { get; }
public string Zone { get; }
public string? Zone { get; }
public string? Employee { get; }
public Common(string layer, string psn, int? rdsNumber, int? reactor, string zone)
public Common(string? layer,
string? psn,
int? rdsNumber,
int? reactor,
string? zone,
string? employee)
{
Layer = layer;
PSN = psn;
RDSNumber = rdsNumber;
ReactorNumber = reactor;
Zone = zone;
Employee = employee;
}
}

View File

@ -13,27 +13,29 @@ using System.Threading.Tasks;
namespace Adaptation.FileHandlers.TIBCO.Transport;
#nullable enable
public partial class Job
{
public string AutomationMode { get; }
public string BasicType { get; }
public string CreationUser { get; }
public string Equipment { get; }
public string JobName { get; }
public string LastUpdateUser { get; }
public string LotName { get; }
public string LotState { get; }
public string PackageName { get; }
public string ProcessSpecName { get; }
public string ProcessType { get; }
public string ProductName { get; }
public string Qty { get; }
public string Qty2 { get; }
public string RecipeName { get; }
public string SpecName { get; }
public string StateModel { get; }
public string Status { get; }
public string? AutomationMode { get; }
public string? BasicType { get; }
public string? CreationUser { get; }
public string? Equipment { get; }
public string? JobName { get; }
public string? LastUpdateUser { get; }
public string? LotName { get; }
public string? LotState { get; }
public string? PackageName { get; }
public string? ProcessSpecName { get; }
public string? ProcessType { get; }
public string? ProductName { get; }
public string? Qty { get; }
public string? Qty2 { get; }
public string? RecipeName { get; }
public string? SpecName { get; }
public string? StateModel { get; }
public string? Status { get; }
//
public bool IsAreaSi { get; }
public DateTime DateTime { get; }
@ -56,7 +58,7 @@ public partial class Job
const string bioRad3 = "BIORAD3";
const string twoAlphaPattern = "^[a-zA-z]{2,3}";
const string reactorNumberPattern = @"^[0-9]{2}--";
Input input = JsonSerializer.Deserialize<Input>(mid);
Input input = JsonSerializer.Deserialize<Input>(mid) ?? throw new Exception();
if (!long.TryParse(input.Sequence, out long sequence))
DateTime = DateTime.Now;
else
@ -71,9 +73,14 @@ public partial class Job
workOrder = GetWorkOrder(input);
reactorNumber = GetReactorNumber(input);
if (workOrder.IsWorkOrder || reactorNumber.HasValue)
common = new(string.Empty, string.Empty, null, null, string.Empty);
common = new(layer: null,
psn: null,
rdsNumber: null,
reactor: null,
zone: null,
employee: null);
else if (!string.IsNullOrEmpty(input.MID) && input.MID.Length is 2 or 3 && Regex.IsMatch(input.MID, twoAlphaPattern))
common = Get(metrologyFileShare, input);
common = GetTwoAlphaPattern(metrologyFileShare, input);
else
common = Get(input);
}
@ -121,6 +128,7 @@ public partial class Job
private static WorkOrder GetWorkOrder(Input input)
{
WorkOrder result;
int? slotNumber;
int? workOrderStep = null;
int? workOrderNumber = null;
@ -154,48 +162,53 @@ public partial class Job
slotNumber = null;
else
slotNumber = slot;
return new(workOrderNumber, workOrderStep, workOrderCassette, slotNumber, workOrderStep is not null || workOrderNumber is not null || workOrderCassette is not null);
result = new(workOrderNumber: workOrderNumber,
workOrderStep: workOrderStep,
workOrderCassette: workOrderCassette,
slotNumber: slotNumber,
isWorkOrder: workOrderStep is not null || workOrderNumber is not null || workOrderCassette is not null);
return result;
}
private static bool IsValid(int? rdsNumber) => !IsInvalid(rdsNumber);
private static bool IsInvalid(int? rdsNumber) => rdsNumber is null or < 100000 or > 100000000;
private static (string, string) GetReactorAndRDS(string defaultReactor, string defaultRDS, string text, string formattedText, string[] segments)
private static (string?, string?) GetReactorAndRDS(string text, string formattedText, string[] segments)
{
string rds;
string reactor;
if (string.IsNullOrEmpty(text) || segments.Length == 0 || string.IsNullOrEmpty(formattedText))
reactor = defaultReactor;
string? rds;
string? reactor;
if (string.IsNullOrEmpty(text) || segments.Length < 1 || string.IsNullOrEmpty(formattedText))
reactor = null;
else
reactor = segments[0];
if (segments.Length <= 1 || !int.TryParse(segments[1], out int rdsValue) || rdsValue < 99)
rds = defaultRDS;
if (segments.Length < 2 || !int.TryParse(segments[1], out int rdsValue) || rdsValue < 99)
rds = null;
else
rds = segments[1];
if (reactor.Length > 3)
if (!string.IsNullOrEmpty(reactor) && reactor.Length > 3)
{
rds = reactor;
reactor = defaultReactor;
reactor = null;
}
return new(reactor, rds);
}
private static (string, string) GetLayerAndPSN(string defaultLayer, string defaultPSN, string[] segments)
private static (string?, string?) GetLayerAndPSN(string[] segments)
{
string psn;
string layer;
string? psn;
string? layer;
if (segments.Length <= 2)
{
psn = defaultPSN;
layer = defaultLayer;
psn = null;
layer = null;
}
else
{
string[] segmentsB = segments[2].Split('.');
psn = segmentsB[0];
if (segmentsB.Length <= 1)
layer = defaultLayer;
layer = null;
else
{
layer = segmentsB[1];
@ -206,11 +219,11 @@ public partial class Job
return (layer, psn);
}
private static string GetZone(string[] segments)
private static string? GetZone(string[] segments)
{
string result;
string? result;
if (segments.Length <= 3)
result = string.Empty;
result = null;
else
{
result = segments[3];
@ -222,39 +235,43 @@ public partial class Job
private static Common Get(Input input)
{
string psn;
string rds;
string zone;
string layer;
string? psn;
string? rds;
string? zone;
int rdsNumber;
string reactor;
string? layer;
string? reactor;
string? employee;
int? reactorNumber;
string defaultPSN = string.Empty;
string defaultRDS = string.Empty;
string defaultLayer = string.Empty;
string defaultReactor = string.Empty;
string[] segments = input.MID.Split(new char[] { '-' });
// bool hasRDS = Regex.IsMatch(input.MID, "[-]?([QP][0-9]{4,}|[0-9]{5,})[-]?");
string formattedText = Regex.Replace(input.MID, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
(reactor, rds) = GetReactorAndRDS(defaultReactor, defaultRDS, input.MID, formattedText, segments);
if (string.IsNullOrEmpty(rds) || segments.Length < 2)
(reactor, rds) = GetReactorAndRDS(input.MID, formattedText, segments);
if (string.IsNullOrEmpty(rds))
rdsNumber = 0;
else
_ = int.TryParse(segments[1], out rdsNumber);
_ = int.TryParse(rds, out rdsNumber);
if (IsInvalid(rdsNumber) || !int.TryParse(reactor, out int reactorCheck))
{
psn = string.Empty;
zone = string.Empty;
layer = string.Empty;
psn = null;
zone = null;
layer = null;
employee = null;
reactorNumber = null;
}
else
{
reactorNumber = reactorCheck;
(layer, psn) = GetLayerAndPSN(defaultLayer, defaultPSN, segments);
zone = GetZone(segments);
reactorNumber = reactorCheck;
(layer, psn) = GetLayerAndPSN(segments);
employee = segments.Length <= 4 ? null : segments[4];
}
return new(layer, psn, rdsNumber, reactorNumber, zone);
return new(layer: layer,
psn: psn,
rdsNumber: rdsNumber,
reactor: reactorNumber,
zone: zone,
employee: employee);
}
private static string[] GetDirectories(string fileShare)
@ -271,18 +288,16 @@ public partial class Job
};
}
#nullable enable
private static Common Get(string metrologyFileShare, Input input)
private static Common GetTwoAlphaPattern(string metrologyFileShare, Input input)
{
string lines;
const int zero = 0;
string? psn = null;
int? reactor = null;
string? zone = null;
string? layer = null;
int? rdsNumber = null;
string psn = string.Empty;
List<string> files = new();
string zone = string.Empty;
string layer = string.Empty;
WorkMaterialOut? workMaterialOut;
if (string.IsNullOrEmpty(metrologyFileShare) || !Directory.Exists(metrologyFileShare))
throw new Exception($"Unable to access file-share <{metrologyFileShare}>");
@ -314,7 +329,12 @@ public partial class Job
zone = workMaterialOut.Zone;
break;
}
return new(layer, psn, rdsNumber, reactor, zone);
return new(layer: layer,
psn: psn,
rdsNumber: rdsNumber,
reactor: reactor,
zone: zone,
employee: null);
}
private static List<string> GetFiles(Input input, string barcodeHostFileShare)
@ -360,8 +380,6 @@ public partial class Job
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;
@ -380,7 +398,12 @@ public partial class Job
rds = null;
psn = string.Empty;
workOrder = new(null, null, null, null, false);
common = new(layer, psn, rds, reactor, zone);
common = new(layer: null,
psn: psn,
rdsNumber: rds,
reactor: reactor,
zone: null,
employee: null);
}
else
{
@ -399,12 +422,22 @@ public partial class Job
if (runDataSheetRoot is null || reactor != runDataSheetRoot.RunDataSheet.Reactor)
{
psn = string.Empty;
common = new(layer, psn, rds, reactor, zone);
common = new(layer: null,
psn: psn,
rdsNumber: rds,
reactor: reactor,
zone: null,
employee: null);
}
else
{
psn = runDataSheetRoot.RunDataSheet.PSN.ToString();
common = new(layer, psn, rds, reactor, zone);
common = new(layer: null,
psn: psn,
rdsNumber: rds,
reactor: reactor,
zone: null,
employee: null);
}
}
return new(common, workOrder);
@ -417,9 +450,6 @@ public partial class Job
int? rds;
long sequence = 0;
WorkOrder workOrder;
string psn = string.Empty;
string zone = string.Empty;
string layer = string.Empty;
int? reactor = !int.TryParse(input.MID.Substring(0, 2), out int reactorNumber) ? null : reactorNumber;
bool parsed = !string.IsNullOrEmpty(input.Sequence) && long.TryParse(input.Sequence, out sequence);
List<string> files;
@ -443,7 +473,12 @@ public partial class Job
rds = null;
workOrder = GetWorkOrder(new(input, text.Substring(2)));
}
Common common = new(layer, psn, rds, reactor, zone);
Common common = new(layer: null,
psn: null,
rdsNumber: rds,
reactor: reactor,
zone: null,
employee: null);
return new(common, workOrder);
}

View File

@ -9,7 +9,11 @@ public class WorkOrder
public int? SlotNumber { get; }
public bool IsWorkOrder { get; }
public WorkOrder(int? workOrderNumber, int? workOrderStep, int? workOrderCassette, int? slotNumber, bool isWorkOrder)
public WorkOrder(int? workOrderNumber,
int? workOrderStep,
int? workOrderCassette,
int? slotNumber,
bool isWorkOrder)
{
WorkOrderNumber = workOrderNumber;
WorkOrderStep = workOrderStep;