diff --git a/Adaptation/FileHandlers/MoveAllFiles/ApiController/BarcodeController.cs b/Adaptation/FileHandlers/MoveAllFiles/ApiController/BarcodeController.cs new file mode 100644 index 0000000..efa2b0e --- /dev/null +++ b/Adaptation/FileHandlers/MoveAllFiles/ApiController/BarcodeController.cs @@ -0,0 +1,63 @@ +using System; +using System.Globalization; +using System.IO; +using System.Text.Json; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Adaptation.FileHandlers.MoveAllFiles.ApiController; + +[Route("api/[controller]")] +public class BarcodeController : System.Web.Http.ApiController +{ + +#nullable enable + +#pragma warning disable CA1822 + public string Get() +#pragma warning restore CA1822 + { + string results = "record"; + return results; + } + + private static string? GetJson(System.Net.Http.HttpContent? httpContent) + { + string? result; + if (httpContent is null) + result = null; + else + { + Task task = httpContent.ReadAsStringAsync(); + task.Wait(); + result = task.Result; + } + return result; + } + + private static void Write(string barcodeHostFileShare, string cellInstanceConnectionName, Notification notification) + { + DateTime dateTime = DateTime.Now; + Calendar calendar = new CultureInfo("en-US").Calendar; + 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); + } + + [Route("{id}")] +#pragma warning disable CA1822 + public void Post(string id) +#pragma warning restore CA1822 + { + string? json = GetJson(Request.Content); + if (json is not null) + { + Notification? notification = JsonSerializer.Deserialize(json); + if (notification is not null) + Write(FileRead.BarcodeHostFileShare, id, notification.Value); + } + } + +} \ No newline at end of file diff --git a/Adaptation/FileHandlers/TIBCO/SignalR/EventCode.cs b/Adaptation/FileHandlers/MoveAllFiles/ApiController/EventCode.cs similarity index 98% rename from Adaptation/FileHandlers/TIBCO/SignalR/EventCode.cs rename to Adaptation/FileHandlers/MoveAllFiles/ApiController/EventCode.cs index 411cbc0..01c679d 100644 --- a/Adaptation/FileHandlers/TIBCO/SignalR/EventCode.cs +++ b/Adaptation/FileHandlers/MoveAllFiles/ApiController/EventCode.cs @@ -1,4 +1,4 @@ -namespace Adaptation.FileHandlers.TIBCO.SignalR; +namespace Adaptation.FileHandlers.MoveAllFiles.ApiController; /// /// Mapping for this can be found here: https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h diff --git a/Adaptation/FileHandlers/TIBCO/SignalR/KeyPressEvent.cs b/Adaptation/FileHandlers/MoveAllFiles/ApiController/KeyPressEvent.cs similarity index 87% rename from Adaptation/FileHandlers/TIBCO/SignalR/KeyPressEvent.cs rename to Adaptation/FileHandlers/MoveAllFiles/ApiController/KeyPressEvent.cs index 9ec933f..aa7e1fe 100644 --- a/Adaptation/FileHandlers/TIBCO/SignalR/KeyPressEvent.cs +++ b/Adaptation/FileHandlers/MoveAllFiles/ApiController/KeyPressEvent.cs @@ -1,6 +1,6 @@ using System; -namespace Adaptation.FileHandlers.TIBCO.SignalR; +namespace Adaptation.FileHandlers.MoveAllFiles.ApiController; public readonly struct KeyPressEvent { diff --git a/Adaptation/FileHandlers/MoveAllFiles/ApiController/KeyState.cs b/Adaptation/FileHandlers/MoveAllFiles/ApiController/KeyState.cs new file mode 100644 index 0000000..5a52452 --- /dev/null +++ b/Adaptation/FileHandlers/MoveAllFiles/ApiController/KeyState.cs @@ -0,0 +1,8 @@ +namespace Adaptation.FileHandlers.MoveAllFiles.ApiController; + +public enum KeyState +{ + KeyUp, + KeyDown, + KeyHold +} \ No newline at end of file diff --git a/Adaptation/FileHandlers/TIBCO/SignalR/Notification.cs b/Adaptation/FileHandlers/MoveAllFiles/ApiController/Notification.cs similarity index 75% rename from Adaptation/FileHandlers/TIBCO/SignalR/Notification.cs rename to Adaptation/FileHandlers/MoveAllFiles/ApiController/Notification.cs index f8c3fe9..f82ea54 100644 --- a/Adaptation/FileHandlers/TIBCO/SignalR/Notification.cs +++ b/Adaptation/FileHandlers/MoveAllFiles/ApiController/Notification.cs @@ -1,10 +1,11 @@ -namespace Adaptation.FileHandlers.TIBCO.SignalR; +namespace Adaptation.FileHandlers.MoveAllFiles.ApiController; public readonly struct Notification { public KeyPressEvent KeyPressEvent { get; } public string LastScanServiceResultValue { get; } + [System.Text.Json.Serialization.JsonConstructor] public Notification(KeyPressEvent keyPressEvent, string lastScanServiceResultValue) { KeyPressEvent = keyPressEvent; diff --git a/Adaptation/FileHandlers/MoveAllFiles/FileRead.cs b/Adaptation/FileHandlers/MoveAllFiles/FileRead.cs index ecd9801..59ad144 100644 --- a/Adaptation/FileHandlers/MoveAllFiles/FileRead.cs +++ b/Adaptation/FileHandlers/MoveAllFiles/FileRead.cs @@ -7,13 +7,20 @@ using System; using System.Collections.Generic; using System.IO; using System.Text.Json; +using System.Web.Http; +using System.Web.Http.SelfHost; namespace Adaptation.FileHandlers.MoveAllFiles; public class FileRead : Shared.FileRead, IFileRead { +#nullable enable + private long? _TickOffset; + private readonly HttpSelfHostServer? _HttpSelfHostServer; + + public const string BarcodeHostFileShare = @"\\messv02ecc1.ec.local\EC_Metrology_Si\BarcodeHost\API"; // GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "BarcodeHost.FileShare"); 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,8 +34,22 @@ public class FileRead : Shared.FileRead, IFileRead throw new Exception(cellInstanceConnectionName); if (_IsDuplicator) throw new Exception(cellInstanceConnectionName); + if (!_IsEAFHosted) + _HttpSelfHostServer = null; + else + { + // string propertyName = string.Concat("CellInstance.", cellInstanceName, ".HttpSelfHostConfiguration.BaseAddress"); + // string httpSelfHostConfigurationBaseAddress = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, propertyName); + string httpSelfHostConfigurationBaseAddress = "http://localhost:8080/"; + HttpSelfHostConfiguration config = new(httpSelfHostConfigurationBaseAddress); + _ = config.Routes.MapHttpRoute("API Default", "api/{controller}/{id}", new { id = RouteParameter.Optional }); + _HttpSelfHostServer = new(config); + _HttpSelfHostServer.OpenAsync().Wait(); + } } +#nullable disable + void IFileRead.Move(Tuple> extractResults, Exception exception) => Move(extractResults); void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null); diff --git a/Adaptation/FileHandlers/OpenInsightMetrologyViewer/FileRead.cs b/Adaptation/FileHandlers/OpenInsightMetrologyViewer/FileRead.cs index 6332fcc..a14a964 100644 --- a/Adaptation/FileHandlers/OpenInsightMetrologyViewer/FileRead.cs +++ b/Adaptation/FileHandlers/OpenInsightMetrologyViewer/FileRead.cs @@ -6,6 +6,7 @@ using Adaptation.Shared.Methods; using Adaptation.Shared.Metrology; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Text.Json; @@ -16,6 +17,7 @@ public class FileRead : Shared.FileRead, IFileRead { private readonly string _OpenInsightMetrologyViewerAPI; + private readonly string _OpenInsightMetrologyViewerFileShare; 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) @@ -29,6 +31,7 @@ public class FileRead : Shared.FileRead, IFileRead throw new Exception(cellInstanceConnectionName); if (!_IsDuplicator) throw new Exception(cellInstanceConnectionName); + _OpenInsightMetrologyViewerFileShare = @"\\messv02ecc1.ec.local\EC_Metrology_Si\MetrologyAttachments\SP1RunHeader_"; _OpenInsightMetrologyViewerAPI = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "OpenInsight.MetrologyViewerAPI"); } @@ -107,11 +110,15 @@ public class FileRead : Shared.FileRead, IFileRead return results; } -#pragma warning disable IDE0060 - private void SendData(DateTime dateTime, List descriptions) -#pragma warning restore IDE0060 + private void SendData(string reportFullPath, DateTime dateTime, List descriptions) { - WSRequest wsRequest = new(this, _Logistics, descriptions); + int weekOfYear = _Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); + string directory = Path.Combine(_OpenInsightMetrologyViewerFileShare, dateTime.Year.ToString(), $"WW{weekOfYear:00}", _Logistics.Sequence.ToString()); + if (!Directory.Exists(directory)) + _ = Directory.CreateDirectory(directory); + string fullPath = Path.Combine(directory, Path.GetFileName(reportFullPath)); + File.Copy(reportFullPath, fullPath); + WSRequest wsRequest = new(this, _Logistics, descriptions, fullPath); (string json, WS.Results wsResults) = WS.SendData(_OpenInsightMetrologyViewerAPI, wsRequest); if (!wsResults.Success) throw new Exception(wsResults.ToString()); @@ -134,7 +141,7 @@ public class FileRead : Shared.FileRead, IFileRead List descriptions = txt.ProcessData.GetDescriptions(jsonElements); Test[] tests = (from l in descriptions select (Test)l.Test).ToArray(); if (_IsEAFHosted && _FileConnectorConfiguration.FileScanningIntervalInSeconds > 0) - SendData(dateTime, descriptions); + SendData(reportFullPath, dateTime, descriptions); results = new Tuple>(pdsf.Item1, tests, jsonElements, new List()); return results; } diff --git a/Adaptation/FileHandlers/OpenInsightMetrologyViewer/WSRequest.cs b/Adaptation/FileHandlers/OpenInsightMetrologyViewer/WSRequest.cs index 79e1d61..56152c9 100644 --- a/Adaptation/FileHandlers/OpenInsightMetrologyViewer/WSRequest.cs +++ b/Adaptation/FileHandlers/OpenInsightMetrologyViewer/WSRequest.cs @@ -267,13 +267,15 @@ public class WSRequest public string DwnSlipMin { get; set; } public string DwnSlipStDev { get; set; } public List Details { get; protected set; } + public string ProcessDataStandardFormat { get; set; } [Obsolete("For json")] public WSRequest() { } #pragma warning disable IDE0060 - internal WSRequest(IFileRead fileRead, Logistics logistics, List descriptions) + internal WSRequest(IFileRead fileRead, Logistics logistics, List descriptions, string processDataStandardFormat = null) #pragma warning restore IDE0060 { + ProcessDataStandardFormat = processDataStandardFormat; Details = new List(); CellName = logistics.MesEntity; txt.Description x = descriptions[0]; @@ -636,7 +638,7 @@ public class WSRequest { if (string.IsNullOrEmpty(json)) { - WSRequest wsRequest = new(fileRead, logistics, descriptions); + WSRequest wsRequest = new(fileRead, logistics, descriptions, string.Empty); (json, WS.Results wsResults) = WS.SendData(openInsightMetrologyViewerAPI, wsRequest); if (!wsResults.Success) throw new Exception(wsResults.ToString()); diff --git a/Adaptation/FileHandlers/TIBCO/FileRead.cs b/Adaptation/FileHandlers/TIBCO/FileRead.cs index c0281c4..25b2d92 100644 --- a/Adaptation/FileHandlers/TIBCO/FileRead.cs +++ b/Adaptation/FileHandlers/TIBCO/FileRead.cs @@ -1,31 +1,22 @@ 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, IAsyncDisposable +public class FileRead : Shared.FileRead, IFileRead { #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) @@ -39,7 +30,6 @@ public class FileRead : Shared.FileRead, IFileRead, IAsyncDisposable 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"); @@ -49,8 +39,6 @@ public class FileRead : Shared.FileRead, IFileRead, IAsyncDisposable 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)) @@ -62,25 +50,6 @@ public class FileRead : Shared.FileRead, IFileRead, IAsyncDisposable _ = 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); } } @@ -168,66 +137,4 @@ public class FileRead : Shared.FileRead, IFileRead, IAsyncDisposable 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/KeyState.cs b/Adaptation/FileHandlers/TIBCO/SignalR/KeyState.cs deleted file mode 100644 index ca64681..0000000 --- a/Adaptation/FileHandlers/TIBCO/SignalR/KeyState.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Adaptation.FileHandlers.TIBCO.SignalR; - -public enum KeyState -{ - KeyUp, - KeyDown, - KeyHold -} \ No newline at end of file diff --git a/Adaptation/MET08DDUPSP1TBI.Tests.csproj b/Adaptation/MET08DDUPSP1TBI.Tests.csproj index bb52386..9c9a2a3 100644 --- a/Adaptation/MET08DDUPSP1TBI.Tests.csproj +++ b/Adaptation/MET08DDUPSP1TBI.Tests.csproj @@ -43,7 +43,7 @@ NU1701 NU1701 - + diff --git a/MET08DDUPSP1TBI.csproj b/MET08DDUPSP1TBI.csproj index d4d9a93..cb9c55d 100644 --- a/MET08DDUPSP1TBI.csproj +++ b/MET08DDUPSP1TBI.csproj @@ -102,6 +102,11 @@ + + + + + @@ -112,10 +117,6 @@ - - - - @@ -178,8 +179,11 @@ 2.49.2 - - 7.0.5 + + 5.2.7 + + + 5.2.7 6.0.3