From cc4473ffa8562ebaa6f6774349ab9bb2b72196a6 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Tue, 20 Jun 2023 12:08:50 -0700 Subject: [PATCH] IDescription.GetDescriptions with body SignalR --- Adaptation/FileHandlers/TIBCO/FileRead.cs | 107 ++++++- .../FileHandlers/TIBCO/SignalR/EventCode.cs | 277 ++++++++++++++++++ .../TIBCO/SignalR/KeyPressEvent.cs | 20 ++ .../FileHandlers/TIBCO/SignalR/KeyState.cs | 8 + .../TIBCO/SignalR/Notification.cs | 14 + .../FileHandlers/TIBCO/Transport/Job.cs | 41 ++- .../FileHandlers/TIBCO/Transport/Main.cs | 6 +- Adaptation/MET08DDUPSP1TBI.Tests.csproj | 13 +- Adaptation/Shared/Duplicator/Description.cs | 36 +++ .../Staging/v2.49.2/MET08DDUPSP1TBI.cs | 11 + .../Staging/v2.49.2/MET08DDUPSP1TBI.cs | 30 ++ Adaptation/_Tests/Static/Job.cs | 16 +- MET08DDUPSP1TBI.csproj | 7 + 13 files changed, 563 insertions(+), 23 deletions(-) create mode 100644 Adaptation/FileHandlers/TIBCO/SignalR/EventCode.cs create mode 100644 Adaptation/FileHandlers/TIBCO/SignalR/KeyPressEvent.cs create mode 100644 Adaptation/FileHandlers/TIBCO/SignalR/KeyState.cs create mode 100644 Adaptation/FileHandlers/TIBCO/SignalR/Notification.cs diff --git a/Adaptation/FileHandlers/TIBCO/FileRead.cs b/Adaptation/FileHandlers/TIBCO/FileRead.cs index d784d01..c0281c4 100644 --- a/Adaptation/FileHandlers/TIBCO/FileRead.cs +++ b/Adaptation/FileHandlers/TIBCO/FileRead.cs @@ -1,19 +1,31 @@ using Adaptation.Eaf.Management.ConfigurationData.CellAutomation; +using Adaptation.FileHandlers.TIBCO.SignalR; using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration; using Adaptation.Shared; using Adaptation.Shared.Duplicator; using Adaptation.Shared.Methods; +using Microsoft.AspNetCore.SignalR.Client; using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; using System.IO; using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; namespace Adaptation.FileHandlers.TIBCO; -public class FileRead : Shared.FileRead, IFileRead +public class FileRead : Shared.FileRead, IFileRead, IAsyncDisposable { +#nullable enable + private long? _TickOffset; + private readonly Timer _Timer; + private readonly string _BarcodeHostFileShare; + private readonly HubConnection? _HubConnectionBioRad2; + private readonly HubConnection? _HubConnectionBioRad3; public FileRead(ISMTP smtp, Dictionary fileParameter, string cellInstanceName, int? connectionCount, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList modelObjectParameters, string equipmentDictionaryName, Dictionary> dummyRuns, Dictionary> staticRuns, bool useCyclicalForDescription, bool isEAFHosted) : base(new Description(), false, smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null) @@ -27,7 +39,9 @@ public class FileRead : Shared.FileRead, IFileRead throw new Exception(cellInstanceConnectionName); if (!_IsDuplicator) throw new Exception(cellInstanceConnectionName); + _Timer = new Timer(Callback, null, Timeout.Infinite, Timeout.Infinite); string metrologyFileShare = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "Metrology.FileShare"); + _BarcodeHostFileShare = @"\\messv02ecc1.ec.local\EC_Metrology_Si\BarcodeHost\API"; // GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "BarcodeHost.FileShare"); string lsl2SQLConnectionString = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "ConnectionString.LSL2SQL"); ModelObjectParameterDefinition[] tibcoParameters = GetProperties(cellInstanceConnectionName, modelObjectParameters, "TIBCO."); string tibcoParameterChannel = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_CHANNEL"); @@ -35,15 +49,38 @@ public class FileRead : Shared.FileRead, IFileRead string tibcoParameterSubjectPrefix = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_SUBJECT_PREFIX"); string tibcoParameterConfigurationLocation = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_CONFIGURATION_LOCATION"); string tibcoParameterConfigurationLocationCopy = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_CONFIGURATION_LOCATION_LOCAL_COPY"); + string hostDomainBioRad2 = "unity4"; // GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "CellInstance.BIORAD2.StaticFileServer"); + string hostDomainBioRad3 = "unity5"; // GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "CellInstance.BIORAD3.StaticFileServer"); if (!Directory.Exists(metrologyFileShare)) throw new Exception($"Unable to access file-share <{metrologyFileShare}>"); + if (!Directory.Exists(_BarcodeHostFileShare)) + throw new Exception($"Unable to access file-share <{_BarcodeHostFileShare}>"); if (_IsEAFHosted) { - Transport.Main.Initialize(smtp, cellInstanceName, fileConnectorConfiguration, lsl2SQLConnectionString, metrologyFileShare); + Transport.Main.Initialize(smtp, cellInstanceName, fileConnectorConfiguration, lsl2SQLConnectionString, metrologyFileShare, _BarcodeHostFileShare); if (!string.IsNullOrEmpty(fileConnectorConfiguration.SourceFileLocation)) _ = Transport.Main.Setup(useSleep: true, setIfxTransport: true, tibcoParameterChannel, tibcoParameterSubjectPrefix, tibcoParameterConfigurationLocation, tibcoParameterConfigurationLocationCopy, tibcoParameterSubject); else _ = Transport.Main.Setup(useSleep: false, setIfxTransport: false, tibcoParameterChannel, tibcoParameterSubjectPrefix, tibcoParameterConfigurationLocation, tibcoParameterConfigurationLocationCopy, tibcoParameterSubject); + _HubConnectionBioRad2 = new HubConnectionBuilder() + .WithUrl(new Uri($"https://{hostDomainBioRad2}/NotificationHub")) + .WithAutomaticReconnect() + .Build(); + _HubConnectionBioRad2.Closed += Closed; + _ = _HubConnectionBioRad2.On("NotifyAll", OnNotifyAllBioRad2); + _HubConnectionBioRad3 = new HubConnectionBuilder() + .WithUrl(new Uri($"https://{hostDomainBioRad3}/NotificationHub")) + .WithAutomaticReconnect() + .Build(); + _HubConnectionBioRad3.Closed += Closed; + _ = _HubConnectionBioRad3.On("NotifyAll", OnNotifyAllBioRad3); + } + if (Debugger.IsAttached || fileConnectorConfiguration.PreProcessingMode == FileConnectorConfiguration.PreProcessingModeEnum.Process || _FileConnectorConfiguration.FileScanningIntervalInSeconds is null) + Callback(null); + else + { + TimeSpan timeSpan = new(DateTime.Now.AddSeconds(_FileConnectorConfiguration.FileScanningIntervalInSeconds.Value).Ticks - DateTime.Now.Ticks); + _ = _Timer.Change((long)timeSpan.TotalMilliseconds, Timeout.Infinite); } } @@ -106,7 +143,7 @@ public class FileRead : Shared.FileRead, IFileRead DateTime dateTime = DateTime.Now; results = GetExtractResult(reportFullPath, dateTime); if (results.Item3 is null) - results = new Tuple>(results.Item1, Array.Empty(), JsonSerializer.Deserialize("[]"), results.Item4); + results = new Tuple>(results.Item1, Array.Empty(), Array.Empty(), results.Item4); if (results.Item3.Length > 0 && _IsEAFHosted) WritePDSF(this, results.Item3); UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks); @@ -124,11 +161,73 @@ public class FileRead : Shared.FileRead, IFileRead private Tuple> GetExtractResult(string reportFullPath, DateTime dateTime) { - Tuple> results = new(string.Empty, null, null, new List()); + Tuple> results = new(string.Empty, Array.Empty(), Array.Empty(), new List()); _TickOffset ??= new FileInfo(reportFullPath).LastWriteTime.Ticks - dateTime.Ticks; _Logistics = new Logistics(this, _TickOffset.Value, reportFullPath, useSplitForMID: true); SetFileParameterLotIDToLogisticsMID(); return results; } + private Task Closed(Exception? exception) => + throw new NotImplementedException(); + + private void Write(string cellInstanceConnectionName, Notification notification) + { + DateTime dateTime = DateTime.Now; + string weekOfYear = $"{dateTime:yyyy}_Week_{_Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}"; + string directory = Path.Combine(_BarcodeHostFileShare, weekOfYear, dateTime.ToString("yyyy-MM-dd_HH")); + if (!Directory.Exists(directory)) + _ = Directory.CreateDirectory(directory); + File.WriteAllText(Path.Combine(directory, $"{cellInstanceConnectionName}.csv"), notification.LastScanServiceResultValue); + } + + private void OnNotifyAllBioRad2(Notification notification) => + Write("BIORAD2", notification); + + private void OnNotifyAllBioRad3(Notification notification) => + Write("BIORAD3", notification); + + public async ValueTask DisposeAsync() + { + if (_HubConnectionBioRad2 is not null) + await _HubConnectionBioRad2.DisposeAsync(); + if (_HubConnectionBioRad3 is not null) + await _HubConnectionBioRad3.DisposeAsync(); + } + + private void Callback(object? state) + { + try + { + int modulus = DateTime.Now.Second % 2; + if (modulus == 0 && _HubConnectionBioRad2?.State == HubConnectionState.Disconnected) + _HubConnectionBioRad2.StartAsync().Wait(); + if (modulus == 1 && _HubConnectionBioRad3?.State == HubConnectionState.Disconnected) + _HubConnectionBioRad3.StartAsync().Wait(); + } + catch (Exception exception) + { + string subject = string.Concat("Exception:", _CellInstanceConnectionName); + string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace); + try + { _SMTP.SendHighPriorityEmailMessage(subject, body); } + catch (Exception) { } + } + try + { + if (_FileConnectorConfiguration.FileScanningIntervalInSeconds is null) + throw new NullReferenceException(nameof(_FileConnectorConfiguration.FileScanningIntervalInSeconds)); + TimeSpan timeSpan = new(DateTime.Now.AddSeconds(_FileConnectorConfiguration.FileScanningIntervalInSeconds.Value).Ticks - DateTime.Now.Ticks); + _ = _Timer.Change((long)timeSpan.TotalMilliseconds, Timeout.Infinite); + } + catch (Exception exception) + { + string subject = string.Concat("Exception:", _CellInstanceConnectionName); + string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace); + try + { _SMTP.SendHighPriorityEmailMessage(subject, body); } + catch (Exception) { } + } + } + } \ No newline at end of file diff --git a/Adaptation/FileHandlers/TIBCO/SignalR/EventCode.cs b/Adaptation/FileHandlers/TIBCO/SignalR/EventCode.cs new file mode 100644 index 0000000..411cbc0 --- /dev/null +++ b/Adaptation/FileHandlers/TIBCO/SignalR/EventCode.cs @@ -0,0 +1,277 @@ +namespace Adaptation.FileHandlers.TIBCO.SignalR; + +/// +/// Mapping for this can be found here: https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h +/// +public enum EventCode +{ + Reserved = 0, + Esc = 1, + Num1 = 2, + Num2 = 3, + Num3 = 4, + Num4 = 5, + Num5 = 6, + Num6 = 7, + Num7 = 8, + Num8 = 9, + Num9 = 10, + Num0 = 11, + Minus = 12, + Equal = 13, + Backspace = 14, + Tab = 15, + Q = 16, + W = 17, + E = 18, + R = 19, + T = 20, + Y = 21, + U = 22, + I = 23, + O = 24, + P = 25, + LeftBrace = 26, + RightBrace = 27, + Enter = 28, + LeftCtrl = 29, + A = 30, + S = 31, + D = 32, + F = 33, + G = 34, + H = 35, + J = 36, + K = 37, + L = 38, + Semicolon = 39, + Apostrophe = 40, + Grave = 41, + LeftShift = 42, + Backslash = 43, + Z = 44, + X = 45, + C = 46, + V = 47, + B = 48, + N = 49, + M = 50, + Comma = 51, + Dot = 52, + Slash = 53, + RightShift = 54, + KpAsterisk = 55, + LeftAlt = 56, + Space = 57, + Capslock = 58, + F1 = 59, + Pf2 = 60, + F3 = 61, + F4 = 62, + F5 = 63, + F6 = 64, + F7 = 65, + F8 = 66, + Pf9 = 67, + F10 = 68, + Numlock = 69, + ScrollLock = 70, + Kp7 = 71, + Kp8 = 72, + Kp9 = 73, + PkpMinus = 74, + Kp4 = 75, + Kp5 = 76, + Kp6 = 77, + KpPlus = 78, + Kp1 = 79, + Kp2 = 80, + Kp3 = 81, + Kp0 = 82, + KpDot = 83, + + Zenkakuhankaku = 85, + //102ND = 86, + F11 = 87, + F12 = 88, + Ro = 89, + Katakana = 90, + Hiragana = 91, + Henkan = 92, + Katakanahiragana = 93, + Muhenkan = 94, + KpJpComma = 95, + KpEnter = 96, + RightCtrl = 97, + KpSlash = 98, + SysRq = 99, + RightAlt = 100, + LineFeed = 101, + Home = 102, + Up = 103, + Pageup = 104, + Left = 105, + Right = 106, + End = 107, + Down = 108, + Pagedown = 109, + Insert = 110, + Delete = 111, + Macro = 112, + Mute = 113, + VolumeDown = 114, + VolumeUp = 115, + Power = 116, // SC System Power Down + KpEqual = 117, + KpPlusMinus = 118, + Pause = 119, + Scale = 120, // AL Compiz Scale (Expose) + + KpComma = 121, + Hangeul = 122, + Hanja = 123, + Yen = 124, + LeftMeta = 125, + RightMeta = 126, + Compose = 127, + + Stop = 128, // AC Stop + Again = 129, + Props = 130, // AC Properties + Undo = 131, // AC Undo + Front = 132, + Copy = 133, // AC Copy + Open = 134, // AC Open + Paste = 135, // AC Paste + Find = 136, // AC Search + Cut = 137, // AC Cut + Help = 138, // AL Integrated Help Center + Menu = 139, // Menu (show menu) + Calc = 140, // AL Calculator + Setup = 141, + Sleep = 142, // SC System Sleep + Wakeup = 143, // System Wake Up + File = 144, // AL Local Machine Browser + Sendfile = 145, + DeleteFile = 146, + Xfer = 147, + Prog1 = 148, + Prog2 = 149, + Www = 150, // AL Internet Browser + MsDos = 151, + Coffee = 152, // AL Terminal Lock/Screensaver + RotateDisplay = 153, // Display orientation for e.g. tablets + CycleWindows = 154, + Mail = 155, + Bookmarks = 156, // AC Bookmarks + Computer = 157, + Back = 158, // AC Back + Forward = 159, // AC Forward + CloseCd = 160, + EjectCd = 161, + EjectCloseCd = 162, + NextSong = 163, + PlayPause = 164, + PreviousSong = 165, + StopCd = 166, + Record = 167, + Rewind = 168, + Phone = 169, // Media Select Telephone + Iso = 170, + Config = 171, // AL Consumer Control Configuration + Homepage = 172, // AC Home + Refresh = 173, // AC Refresh + Exit = 174, // AC Exit + Move = 175, + Edit = 176, + ScrollUp = 177, + ScrollDown = 178, + KpLeftParen = 179, + KpRightParen = 180, + New = 181, // AC New + Redo = 182, // AC Redo/Repeat + + F13 = 183, + F14 = 184, + F15 = 185, + F16 = 186, + F17 = 187, + F18 = 188, + F19 = 189, + F20 = 190, + F21 = 191, + F22 = 192, + F23 = 193, + F24 = 194, + + PlayCd = 200, + PauseCd = 201, + Prog3 = 202, + Prog4 = 203, + Dashboard = 204, // AL Dashboard + Suspend = 205, + Close = 206, // AC Close + Play = 207, + FastForward = 208, + BassBoost = 209, + Print = 210, // AC Print + Hp = 211, + Camera = 212, + Sound = 213, + Question = 214, + Email = 215, + Chat = 216, + Search = 217, + Connect = 218, + Finance = 219, // AL Checkbook/Finance + Sport = 220, + Shop = 221, + AltErase = 222, + Cancel = 223, // AC Cancel + BrightnessDown = 224, + BrightnessUp = 225, + Media = 226, + + SwitchVideoMode = 227, // Cycle between available video outputs (Monitor/LCD/TV-out/etc) + KbdIllumToggle = 228, + KbdIllumDown = 229, + KbdIllumUp = 230, + + Send = 231, // AC Send + Reply = 232, // AC Reply + ForwardMail = 233, // AC Forward Msg + Save = 234, // AC Save + Documents = 235, + + Battery = 236, + + Bluetooth = 237, + Wlan = 238, + Uwb = 239, + + Unknown = 240, + + VideoNext = 241, // drive next video source + VideoPrev = 242, // drive previous video source + BrightnessCycle = 243, // brightness up, after max is min + BrightnessAuto = 244, // Set Auto Brightness: manual brightness control is off, rely on ambient + DisplayOff = 245, // display device to off state + + Wwan = 246, // Wireless WAN (LTE, UMTS, GSM, etc.) + RfKill = 247, // Key that controls all radios + + MicMute = 248, // Mute / unmute the microphone + LeftMouse = 272, + RightMouse = 273, + MiddleMouse = 274, + MouseBack = 275, + MouseForward = 276, + + ToolFinger = 325, + ToolQuintTap = 328, + Touch = 330, + ToolDoubleTap = 333, + ToolTripleTap = 334, + ToolQuadTap = 335, + Mic = 582 +} \ No newline at end of file diff --git a/Adaptation/FileHandlers/TIBCO/SignalR/KeyPressEvent.cs b/Adaptation/FileHandlers/TIBCO/SignalR/KeyPressEvent.cs new file mode 100644 index 0000000..9ec933f --- /dev/null +++ b/Adaptation/FileHandlers/TIBCO/SignalR/KeyPressEvent.cs @@ -0,0 +1,20 @@ +using System; + +namespace Adaptation.FileHandlers.TIBCO.SignalR; + +public readonly struct KeyPressEvent +{ + public DateTime DateTime { get; } + public EventCode EventCode { get; } + public KeyState KeyState { get; } + public TimeSpan TimeSpan { get; } + + public KeyPressEvent(DateTime dateTime, EventCode eventCode, KeyState keyState, TimeSpan timeSpan) + { + DateTime = dateTime; + EventCode = eventCode; + KeyState = keyState; + TimeSpan = timeSpan; + } + +} \ No newline at end of file diff --git a/Adaptation/FileHandlers/TIBCO/SignalR/KeyState.cs b/Adaptation/FileHandlers/TIBCO/SignalR/KeyState.cs new file mode 100644 index 0000000..ca64681 --- /dev/null +++ b/Adaptation/FileHandlers/TIBCO/SignalR/KeyState.cs @@ -0,0 +1,8 @@ +namespace Adaptation.FileHandlers.TIBCO.SignalR; + +public enum KeyState +{ + KeyUp, + KeyDown, + KeyHold +} \ No newline at end of file diff --git a/Adaptation/FileHandlers/TIBCO/SignalR/Notification.cs b/Adaptation/FileHandlers/TIBCO/SignalR/Notification.cs new file mode 100644 index 0000000..f8c3fe9 --- /dev/null +++ b/Adaptation/FileHandlers/TIBCO/SignalR/Notification.cs @@ -0,0 +1,14 @@ +namespace Adaptation.FileHandlers.TIBCO.SignalR; + +public readonly struct Notification +{ + public KeyPressEvent KeyPressEvent { get; } + public string LastScanServiceResultValue { get; } + + public Notification(KeyPressEvent keyPressEvent, string lastScanServiceResultValue) + { + KeyPressEvent = keyPressEvent; + LastScanServiceResultValue = lastScanServiceResultValue; + } + +} \ No newline at end of file diff --git a/Adaptation/FileHandlers/TIBCO/Transport/Job.cs b/Adaptation/FileHandlers/TIBCO/Transport/Job.cs index 70fe548..67e7298 100644 --- a/Adaptation/FileHandlers/TIBCO/Transport/Job.cs +++ b/Adaptation/FileHandlers/TIBCO/Transport/Job.cs @@ -39,7 +39,7 @@ public class Job public DateTime DateTime { get; } public List Items { get; } - public Job(string lsl2SQLConnectionString, string metrologyFileShare, string mid) + public Job(string lsl2SQLConnectionString, string metrologyFileShare, string barcodeHostFileShare, string mid) { const int zero = 0; Items = new List(); @@ -64,6 +64,8 @@ public class Job (layer, psn, rdsNumber, zone) = (string.Empty, string.Empty, null, string.Empty); else if (!string.IsNullOrEmpty(input.MID) && input.MID.Length is 2 or 3 && Regex.IsMatch(input.MID, "^[a-zA-z]{2,3}")) (layer, psn, rdsNumber, reactorNumber, zone) = Get(metrologyFileShare, input); + else if (!string.IsNullOrEmpty(input.MID) && !string.IsNullOrEmpty(input.MesEntity) && input.MesEntity is "BIORAD2" or "BIORAD3" && Regex.IsMatch(input.MID, @"^[0-9]{2}[.][0-9]{1}[.]?[0-9]{0,1}")) + (layer, psn, rdsNumber, reactorNumber, zone) = Get(input, barcodeHostFileShare); else (layer, psn, rdsNumber, reactorNumber, zone) = Get(input); if (IsValid(rdsNumber)) @@ -246,7 +248,7 @@ public class Job return new(layer, psn, rdsNumber, reactorNumber, zone); } - private static string[] GetDirectories(string metrologyFileShare) + private static string[] GetDirectories(string fileShare) { DateTime dateTime = DateTime.Now; DateTime before = dateTime.AddHours(-1); @@ -255,8 +257,8 @@ public class Job string weekOfYearForBefore = $"{before:yyyy}_Week_{calendar.GetWeekOfYear(before, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}"; return new string[] { - Path.Combine(metrologyFileShare, weekOfYear, dateTime.ToString("yyyy-MM-dd_HH")), - Path.Combine(metrologyFileShare, weekOfYearForBefore, before.ToString("yyyy-MM-dd_HH")) + Path.Combine(fileShare, weekOfYear, dateTime.ToString("yyyy-MM-dd_HH")), + Path.Combine(fileShare, weekOfYearForBefore, before.ToString("yyyy-MM-dd_HH")) }; } @@ -306,6 +308,37 @@ public class Job return new(layer, psn, rdsNumber, reactor, zone); } + private static (string, string, int?, int?, string) Get(Input input, string barcodeHostFileShare) + { + string text; + int? rds = null; + string psn = string.Empty; + List files = new(); + string[] segments = input.MID.Split('.'); + string layer = segments[1]; + string zone = segments.Length <= 2 ? string.Empty : segments[2]; + int? reactor = !int.TryParse(segments[0], out int reactorNumber) ? null : reactorNumber; + if (string.IsNullOrEmpty(barcodeHostFileShare) || !Directory.Exists(barcodeHostFileShare)) + throw new Exception($"Unable to access file-share <{barcodeHostFileShare}>"); + if (!string.IsNullOrEmpty(input.MID)) + { + string[] checkDirectories = GetDirectories(barcodeHostFileShare); + foreach (string checkDirectory in checkDirectories) + { + if (!Directory.Exists(checkDirectory)) + _ = Directory.CreateDirectory(checkDirectory); + files.AddRange(Directory.GetFiles(checkDirectory, $"{input.MesEntity}.csv", SearchOption.TopDirectoryOnly)); + } + } + foreach (string file in files.OrderByDescending(l => new FileInfo(l).LastWriteTime)) + { + text = File.ReadAllText(file); + rds = !int.TryParse(segments[0], out int rdsNumber) ? null : rdsNumber; + break; + } + return new(layer, psn, rds, reactor, zone); + } + #nullable disable private static string GetRunJson(string lsl2SQLConnectionString, int? rds, int? workOrderNumber, int? workOrderCassette, int? slot, int? reactor) diff --git a/Adaptation/FileHandlers/TIBCO/Transport/Main.cs b/Adaptation/FileHandlers/TIBCO/Transport/Main.cs index c71f031..6bd77d5 100644 --- a/Adaptation/FileHandlers/TIBCO/Transport/Main.cs +++ b/Adaptation/FileHandlers/TIBCO/Transport/Main.cs @@ -16,17 +16,19 @@ internal partial class Main private static object _IfxTransport; private static string _CellInstanceName; private static string _MetrologyFileShare; + private static string _BarcodeHostFileShare; private static string _LSL2SQLConnectionString; private static string _TibcoParameterSubjectPrefix; private static FileConnectorConfiguration _FileConnectorConfiguration; - internal static void Initialize(ISMTP smtp, string cellInstanceName, FileConnectorConfiguration fileConnectorConfiguration, string lsl2SQLConnectionString, string metrologyFileShare) + internal static void Initialize(ISMTP smtp, string cellInstanceName, FileConnectorConfiguration fileConnectorConfiguration, string lsl2SQLConnectionString, string metrologyFileShare, string barcodeHostFileShare) { _SMTP = smtp; _IfxTransport = null; _CellInstanceName = cellInstanceName; _MetrologyFileShare = metrologyFileShare; _TibcoParameterSubjectPrefix = string.Empty; + _BarcodeHostFileShare = barcodeHostFileShare; _LSL2SQLConnectionString = lsl2SQLConnectionString; _FileConnectorConfiguration = fileConnectorConfiguration; } @@ -184,7 +186,7 @@ internal partial class Main if (!subject.Contains(_TibcoParameterSubjectPrefix)) throw new Exception("Invalid Subject"); mid = GetJobsMID(envelopeDocument); - Job job = new(_LSL2SQLConnectionString, _MetrologyFileShare, mid); + Job job = new(_LSL2SQLConnectionString, _MetrologyFileShare, _BarcodeHostFileShare, mid); if (job.IsAreaSi) { IfxDoc sendReply = GetJobsReply(job); diff --git a/Adaptation/MET08DDUPSP1TBI.Tests.csproj b/Adaptation/MET08DDUPSP1TBI.Tests.csproj index 3a29f43..bb52386 100644 --- a/Adaptation/MET08DDUPSP1TBI.Tests.csproj +++ b/Adaptation/MET08DDUPSP1TBI.Tests.csproj @@ -33,7 +33,7 @@ Linux - + NU1701 NU1701 @@ -43,6 +43,7 @@ NU1701 NU1701 + @@ -53,10 +54,10 @@ - + - - + + NU1701 @@ -67,8 +68,8 @@ - - + + NU1701 diff --git a/Adaptation/Shared/Duplicator/Description.cs b/Adaptation/Shared/Duplicator/Description.cs index ee456bf..ee6eb49 100644 --- a/Adaptation/Shared/Duplicator/Description.cs +++ b/Adaptation/Shared/Duplicator/Description.cs @@ -110,6 +110,42 @@ public class Description : IDescription, Properties.IDescription List IDescription.GetDescriptions(IFileRead fileRead, Logistics logistics, List tests, IProcessData iProcessData) { List results = new(); + if (iProcessData is null || !iProcessData.Details.Any()) + results.Add(GetDefault(fileRead, logistics)); + else + { + string nullData; + Description description; + object configDataNullData = fileRead.NullData; + if (configDataNullData is null) + nullData = string.Empty; + else + nullData = configDataNullData.ToString(); + for (int i = 0; i < iProcessData.Details.Count; i++) + { + if (iProcessData.Details[i] is null) + continue; + description = new Description + { + Test = (int)tests[i], + Count = tests.Count, + Index = i, + // + EventName = fileRead.EventName, + NullData = nullData, + JobID = fileRead.CellInstanceName, + Sequence = logistics.Sequence.ToString(), + MesEntity = logistics.MesEntity, + ReportFullPath = logistics.ReportFullPath, + ProcessJobID = logistics.ProcessJobID, + MID = logistics.MID, + // + Date = DateTime.Now.ToString(GetDateFormat()), + RDS = string.Empty, + }; + results.Add(description); + } + } return results; } diff --git a/Adaptation/_Tests/CreateSelfDescription/Staging/v2.49.2/MET08DDUPSP1TBI.cs b/Adaptation/_Tests/CreateSelfDescription/Staging/v2.49.2/MET08DDUPSP1TBI.cs index 5caee04..35519a8 100644 --- a/Adaptation/_Tests/CreateSelfDescription/Staging/v2.49.2/MET08DDUPSP1TBI.cs +++ b/Adaptation/_Tests/CreateSelfDescription/Staging/v2.49.2/MET08DDUPSP1TBI.cs @@ -177,4 +177,15 @@ public class MET08DDUPSP1TBI : EAFLoggingUnitTesting EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, " - Exit")); } + [Ignore] + [TestMethod] + public void Staging__v2_49_2__MET08DDUPSP1TBI__TIBCO() + { + string check = "*.idc"; + MethodBase methodBase = new StackFrame().GetMethod(); + EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, " - Getting configuration")); + _ = AdaptationTesting.GetWriteConfigurationGetFileRead(methodBase, check, EAFLoggingUnitTesting.AdaptationTesting); + EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, " - Exit")); + } + } \ No newline at end of file diff --git a/Adaptation/_Tests/Extract/Staging/v2.49.2/MET08DDUPSP1TBI.cs b/Adaptation/_Tests/Extract/Staging/v2.49.2/MET08DDUPSP1TBI.cs index 63cf44a..e1ca79f 100644 --- a/Adaptation/_Tests/Extract/Staging/v2.49.2/MET08DDUPSP1TBI.cs +++ b/Adaptation/_Tests/Extract/Staging/v2.49.2/MET08DDUPSP1TBI.cs @@ -1,6 +1,7 @@ using Adaptation.Shared; using Adaptation.Shared.Methods; using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; using System.Diagnostics; using System.Reflection; @@ -22,6 +23,13 @@ public class MET08DDUPSP1TBI _MET08DDUPSP1TBI = CreateSelfDescription.Staging.v2_49_2.MET08DDUPSP1TBI.EAFLoggingUnitTesting; } + private static void NonThrowTryCatch() + { + try + { throw new Exception(); } + catch (Exception) { } + } + #if DEBUG [Ignore] #endif @@ -113,4 +121,26 @@ public class MET08DDUPSP1TBI [TestMethod] public void Staging__v2_49_2__MET08DDUPSP1TBI__Dummy() => _MET08DDUPSP1TBI.Staging__v2_49_2__MET08DDUPSP1TBI__Dummy(); +#if true + [Ignore] +#endif + [TestMethod] + public void Staging__v2_49_2__MET08DDUPSP1TBI__TIBCO() => _MET08DDUPSP1TBI.Staging__v2_49_2__MET08DDUPSP1TBI__TIBCO(); + +#if true + [Ignore] +#endif + [TestMethod] + public void Staging__v2_49_2__MET08DDUPSP1TBI__TIBCO638217888620242702__Normal() + { + string check = "*.idc"; + MethodBase methodBase = new StackFrame().GetMethod(); + _MET08DDUPSP1TBI.Staging__v2_49_2__MET08DDUPSP1TBI__TIBCO(); + string[] variables = _MET08DDUPSP1TBI.AdaptationTesting.GetVariables(methodBase, check, validatePDSF: false); + _ = _MET08DDUPSP1TBI.AdaptationTesting.Get(methodBase, sourceFileLocation: variables[2], sourceFileFilter: variables[3], useCyclicalForDescription: false); + for (int i = 0; i < int.MaxValue; i++) + System.Threading.Thread.Sleep(500); + NonThrowTryCatch(); + } + } \ No newline at end of file diff --git a/Adaptation/_Tests/Static/Job.cs b/Adaptation/_Tests/Static/Job.cs index e03ea03..1d64b0f 100644 --- a/Adaptation/_Tests/Static/Job.cs +++ b/Adaptation/_Tests/Static/Job.cs @@ -49,31 +49,32 @@ public class Job : LoggingUnitTesting, IDisposable { FileHandlers.TIBCO.Transport.Job job; MethodBase methodBase = new StackFrame().GetMethod(); + string barcodeHostFileShare = @"\\messv02ecc1.ec.local\EC_Metrology_Si\BarcodeHost\API"; string metrologyFileShare = @"\\messv02ecc1.ec.local\EC_Metrology_Si\WorkMaterialOut\API"; LoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, " - Getting configuration")); string lsl2SQLConnectionString = "Data Source=10.95.128.28\\PROD1,53959;Initial Catalog=LSL2SQL;Persist Security Info=True;User ID=srpadmin;Password=0okm9ijn;"; - job = new(lsl2SQLConnectionString, metrologyFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"12-123456-1234\", \"Recipe\": \"Recipe\"}"); + job = new(lsl2SQLConnectionString, metrologyFileShare, barcodeHostFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"12-123456-1234\", \"Recipe\": \"Recipe\"}"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProcessType)); // == "21"); Assert.IsTrue(job.LotName == "123456"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProductName)); // == "4609"); - job = new(lsl2SQLConnectionString, metrologyFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"-544481-\", \"Recipe\": \"Recipe\"}"); + job = new(lsl2SQLConnectionString, metrologyFileShare, barcodeHostFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"-544481-\", \"Recipe\": \"Recipe\"}"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProcessType)); // == "51"); Assert.IsTrue(job.LotName == "544481"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProductName)); // == "5158"); - job = new(lsl2SQLConnectionString, metrologyFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"00-544481-0000\", \"Recipe\": \"Recipe\"}"); + job = new(lsl2SQLConnectionString, metrologyFileShare, barcodeHostFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"00-544481-0000\", \"Recipe\": \"Recipe\"}"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProcessType)); // == "51"); Assert.IsTrue(job.LotName == "544481"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProductName)); // == "5158"); - job = new(lsl2SQLConnectionString, metrologyFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"37\", \"Recipe\": \"Recipe\"}"); + job = new(lsl2SQLConnectionString, metrologyFileShare, barcodeHostFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"37\", \"Recipe\": \"Recipe\"}"); Assert.IsTrue(job.ProcessType == "37"); Assert.IsTrue(!string.IsNullOrEmpty(job.LotName)); // == "549918"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProductName)); // == "5101"); - job = new(lsl2SQLConnectionString, metrologyFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"00-o171308.1.51-0000\", \"Recipe\": \"Recipe\", \"Slot\": \"11\"}"); + job = new(lsl2SQLConnectionString, metrologyFileShare, barcodeHostFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"00-o171308.1.51-0000\", \"Recipe\": \"Recipe\", \"Slot\": \"11\"}"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProcessType)); // == "54"); Assert.IsTrue(!string.IsNullOrEmpty(job.LotName)); // == "547000"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProductName)); // == "4445"); LoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, " - Exit")); - job = new(lsl2SQLConnectionString, metrologyFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE5\", \"Sequence\": \"638163023363575829\", \"MID\": \"B48\", \"Recipe\": \"lsl_6in \"}"); + job = new(lsl2SQLConnectionString, metrologyFileShare, barcodeHostFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE5\", \"Sequence\": \"638163023363575829\", \"MID\": \"B48\", \"Recipe\": \"lsl_6in \"}"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProcessType)); // == "54"); Assert.IsTrue(!string.IsNullOrEmpty(job.LotName)); // == "547000"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProductName)); // == "4445"); @@ -87,10 +88,11 @@ public class Job : LoggingUnitTesting, IDisposable { MethodBase methodBase = new StackFrame().GetMethod(); FileHandlers.TIBCO.Transport.Job job; + string barcodeHostFileShare = @"\\messv02ecc1.ec.local\EC_Metrology_Si\BarcodeHost\API"; string metrologyFileShare = @"\\messv02ecc1.ec.local\EC_Metrology_Si\WorkMaterialOut\API"; LoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, " - Getting configuration")); string lsl2SQLConnectionString = "Data Source=10.95.128.28\\PROD1,53959;Initial Catalog=LSL2SQL;Persist Security Info=True;User ID=srpadmin;Password=0okm9ijn;"; - job = new(lsl2SQLConnectionString, metrologyFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"P1234\", \"Recipe\": \"Recipe\"}"); + job = new(lsl2SQLConnectionString, metrologyFileShare, barcodeHostFileShare, "{\"Area\": \"Si\", \"EquipmentType\": \"MET08RESIMAPCDE\", \"MesEntity\": \"CDE4\", \"Sequence\": \"123456789\", \"MID\": \"P1234\", \"Recipe\": \"Recipe\"}"); Assert.IsTrue(!string.IsNullOrEmpty(job.ProcessType)); Assert.IsTrue(!string.IsNullOrEmpty(job.LotName)); Assert.IsTrue(!string.IsNullOrEmpty(job.ProductName)); diff --git a/MET08DDUPSP1TBI.csproj b/MET08DDUPSP1TBI.csproj index 0cce3a4..d4d9a93 100644 --- a/MET08DDUPSP1TBI.csproj +++ b/MET08DDUPSP1TBI.csproj @@ -112,6 +112,10 @@ + + + + @@ -174,6 +178,9 @@ 2.49.2 + + 7.0.5 + 6.0.3