diff --git a/Server/Models/AppSettings.cs b/Server/Models/AppSettings.cs index 233b0e9..ce16ae6 100644 --- a/Server/Models/AppSettings.cs +++ b/Server/Models/AppSettings.cs @@ -2,8 +2,7 @@ using System.Text.Json; namespace OI.Metrology.Server.Models; -public record AppSettings(string ApiExportPath, - string ApiFileShare, +public record AppSettings(string ApiFileShare, string ApiLoggingContentTypes, string ApiLoggingPathPrefixes, string ApiLogPath, @@ -17,7 +16,7 @@ public record AppSettings(string ApiExportPath, string GitCommitSeven, string InboundApiAllowedIPList, string IqsColumns, - string IqsFile, + string[] IqsFileSegments, string IqsKey, string IqsRed, string IqsYellow, @@ -30,6 +29,7 @@ public record AppSettings(string ApiExportPath, Dictionary TableToPath, string URLs, string WaferCounterDestinationDirectory, + int WaferCounterTwoFileSecondsWait, string WorkingDirectoryName) { diff --git a/Server/Models/Binder/AppSettings.cs b/Server/Models/Binder/AppSettings.cs index 5245c12..7054000 100644 --- a/Server/Models/Binder/AppSettings.cs +++ b/Server/Models/Binder/AppSettings.cs @@ -6,7 +6,6 @@ namespace OI.Metrology.Server.Models.Binder; public class AppSettings { - public string? ApiExportPath { get; set; } public string? ApiFileShare { get; set; } public string? ApiLoggingContentTypes { get; set; } public string? ApiLoggingPathPrefixes { get; set; } @@ -21,7 +20,7 @@ public class AppSettings public string? GitCommitSeven { get; set; } public string? InboundApiAllowedIPList { get; set; } public string? IqsColumns { get; set; } - public string? IqsFile { get; set; } + public string[]? IqsFileSegments { get; set; } public string? IqsKey { get; set; } public string? IqsRed { get; set; } public string? IqsYellow { get; set; } @@ -34,6 +33,7 @@ public class AppSettings public Dictionary? TableToPath { get; set; } public string? URLs { get; set; } public string? WaferCounterDestinationDirectory { get; set; } + public int? WaferCounterTwoFileSecondsWait { get; set; } public string? WorkingDirectoryName { get; set; } public override string ToString() @@ -44,7 +44,7 @@ public class AppSettings private static void PreVerify(IConfigurationRoot configurationRoot, AppSettings? appSettings) { - if (appSettings?.ApiExportPath is null) + if (appSettings?.ApiFileShare is null) { List paths = new(); foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers) @@ -63,7 +63,6 @@ public class AppSettings { Models.AppSettings result; if (appSettings is null) throw new NullReferenceException(nameof(appSettings)); - if (appSettings.ApiExportPath is null) throw new NullReferenceException(nameof(ApiExportPath)); if (appSettings.ApiFileShare is null) throw new NullReferenceException(nameof(ApiFileShare)); if (appSettings.ApiLoggingContentTypes is null) throw new NullReferenceException(nameof(ApiLoggingContentTypes)); if (appSettings.ApiLoggingPathPrefixes is null) throw new NullReferenceException(nameof(ApiLoggingPathPrefixes)); @@ -78,7 +77,7 @@ public class AppSettings if (appSettings.GitCommitSeven is null) throw new NullReferenceException(nameof(GitCommitSeven)); if (appSettings.InboundApiAllowedIPList is null) throw new NullReferenceException(nameof(InboundApiAllowedIPList)); if (appSettings.IqsColumns is null) throw new NullReferenceException(nameof(IqsColumns)); - if (appSettings.IqsFile is null) throw new NullReferenceException(nameof(IqsFile)); + if (appSettings.IqsFileSegments is null) throw new NullReferenceException(nameof(IqsFileSegments)); if (appSettings.IqsKey is null) throw new NullReferenceException(nameof(IqsKey)); if (appSettings.IqsRed is null) throw new NullReferenceException(nameof(IqsRed)); if (appSettings.IqsYellow is null) throw new NullReferenceException(nameof(IqsYellow)); @@ -91,9 +90,9 @@ public class AppSettings if (appSettings.URLs is null) throw new NullReferenceException(nameof(URLs)); if (appSettings.TableToPath is null) throw new NullReferenceException(nameof(TableToPath)); if (appSettings.WaferCounterDestinationDirectory is null) throw new NullReferenceException(nameof(WaferCounterDestinationDirectory)); + if (appSettings.WaferCounterTwoFileSecondsWait is null) throw new NullReferenceException(nameof(WaferCounterTwoFileSecondsWait)); if (appSettings.WorkingDirectoryName is null) throw new NullReferenceException(nameof(WorkingDirectoryName)); result = new( - appSettings.ApiExportPath, appSettings.ApiFileShare, appSettings.ApiLoggingContentTypes, appSettings.ApiLoggingPathPrefixes, @@ -108,7 +107,7 @@ public class AppSettings appSettings.GitCommitSeven, appSettings.InboundApiAllowedIPList, appSettings.IqsColumns, - appSettings.IqsFile, + appSettings.IqsFileSegments, appSettings.IqsKey, appSettings.IqsRed, appSettings.IqsYellow, @@ -121,6 +120,7 @@ public class AppSettings appSettings.TableToPath, appSettings.URLs, appSettings.WaferCounterDestinationDirectory, + appSettings.WaferCounterTwoFileSecondsWait.Value, appSettings.WorkingDirectoryName); return result; } diff --git a/Server/Repositories/InfinityQSV4Repository.cs b/Server/Repositories/InfinityQSV4Repository.cs index 18e2d97..0447d27 100644 --- a/Server/Repositories/InfinityQSV4Repository.cs +++ b/Server/Repositories/InfinityQSV4Repository.cs @@ -677,12 +677,11 @@ public class InfinityQSV4Repository : IInfinityQSV4Repository return result; } - private static ReadOnlyCollection GetRecords(AppSettings appSettings, string file) + private static ReadOnlyCollection GetRecords(AppSettings appSettings, string[] lines) { Record? record; List results = new(); List checkColumns = new(); - string[] lines = File.ReadAllLines(file); foreach (string line in lines) { if (line.StartsWith("> IInfinityQSV4Repository.GetEngineeringSpcReview() @@ -765,19 +777,27 @@ public class InfinityQSV4Repository : IInfinityQSV4Repository } else { - FileInfo iqsFileInfo = new(_AppSettings.IqsFile); - Assembly assembly = Assembly.GetExecutingAssembly(); - string? assemblyName = assembly.GetName()?.Name; - if (string.IsNullOrEmpty(assemblyName)) - throw new Exception(); - FileInfo localFileInfo = new(Path.Combine(AppContext.BaseDirectory, "wwwroot", iqsFileInfo.Name)); - if (!localFileInfo.Exists && (!iqsFileInfo.Exists || iqsFileInfo.Length == 0)) + string wwwRootDirectory = GetWwwRootDirectory(); + HttpClient httpClient = _HttpClientFactory.CreateClient(); + FileInfo localFileInfo = new(Path.Combine(wwwRootDirectory, _AppSettings.IqsFileSegments.Last())); + Uri uri = _FileShareRepository.Append(new Uri(_AppSettings.EcMesaFileShareCharacterizationSi), _AppSettings.IqsFileSegments[0..^1]); + List nginxFileSystemSortableCollection = _FileShareRepository.GetNginxFileSystemSortableCollection(httpClient, uri, ".html"); + if (!localFileInfo.Exists && nginxFileSystemSortableCollection.Count == 0) results = new(); else { - if (!localFileInfo.Exists || localFileInfo.LastWriteTime != iqsFileInfo.LastWriteTime) - FileFindReplaceAndSave(iqsFileInfo.FullName, localFileInfo); - ReadOnlyCollection records = !iqsFileInfo.Exists || iqsFileInfo.Length == 0 ? GetRecords(_AppSettings, localFileInfo.FullName) : GetRecords(_AppSettings, iqsFileInfo.FullName); + string[] lines; + HttpResponseMessage httpResponseMessage = _FileShareRepository.ReadFile(httpClient, nginxFileSystemSortableCollection[0].Uri); + Task value = httpResponseMessage.Content.ReadAsStringAsync(); + value.Wait(); + if (localFileInfo.Exists && localFileInfo.LastWriteTime == nginxFileSystemSortableCollection[0].DateTime) + lines = File.ReadAllLines(localFileInfo.FullName); + else + { + FileFindReplaceAndSave(localFileInfo, value.Result); + lines = value.Result.Split("\r\n"); + } + ReadOnlyCollection records = GetRecords(_AppSettings, lines); List> collection = GetCollection(_AppSettings.IqsColumns, records); results = GetResults(_AppSettings, collection); } diff --git a/Server/Repositories/WaferCounterRepository.cs b/Server/Repositories/WaferCounterRepository.cs index 7eae63a..ae5b172 100644 --- a/Server/Repositories/WaferCounterRepository.cs +++ b/Server/Repositories/WaferCounterRepository.cs @@ -4,7 +4,6 @@ using OI.Metrology.Shared.Models; using OI.Metrology.Shared.Models.Stateless; using OI.Metrology.Shared.Repositories; using System.Globalization; -using System.Text.Json; namespace OI.Metrology.Server.Repository; @@ -137,94 +136,75 @@ public class WaferCounterRepository : IWaferCounterRepository private List GetNginxFileSystemSortableCollection(HttpClient httpClient, Uri waferSizeUri, string waferSizeDirectory) { - List results = _FileShareRepository.GetNginxFileSystemSortableCollection(httpClient, waferSizeUri, ".wc"); + List results = new(); + DateTime dateTime = DateTime.Now; + long ticks = dateTime.AddSeconds(_AppSettings.WaferCounterTwoFileSecondsWait).Ticks; + for (int i = 0; i < int.MaxValue; i++) + { + results = _FileShareRepository.GetNginxFileSystemSortableCollection(httpClient, waferSizeUri, ".wc"); + if (results.Count > 1 || DateTime.Now.Ticks > ticks) + break; + Thread.Sleep(250); + } for (int i = 1; i < results.Count; i++) MoveFile(waferSizeDirectory, results[i]); return results; } - private static WaferCounter? GetLastQuantityAndSlotMapWithText(string waferSize, string text, HttpClient httpClient, NginxFileSystemSortable nginxFileSystemSortable) + private static WaferCounter GetLastQuantityAndSlotMapWithText(string waferSize, string text, HttpClient httpClient, NginxFileSystemSortable nginxFileSystemSortable) { - WaferCounter? result; + WaferCounter result; Task value = httpClient.GetStringAsync(nginxFileSystemSortable.Uri); value.Wait(); - string[] lines = value.Result.Split(Environment.NewLine); - if (lines.Length < 2) - result = null; - else - { - string[] segments = nginxFileSystemSortable.Name.Split('-'); - Record record = GetRecord(lines[0], lines[1]); - string equipmentId = segments.Length < 2 ? nginxFileSystemSortable.Name : segments[1].Split('.')[0]; - if (string.IsNullOrEmpty(record.SlotMap) || record.SlotMap.Length != 25) - result = null; // Wrong length! - else if (record.Total != record.Check) - result = null; // Invalid! - else - result = new(nginxFileSystemSortable.DateTime, nginxFileSystemSortable.DateTime.ToString("yyyy-MM-dd hh:mm tt"), $"WC{waferSize}{equipmentId}", text, record.Total, record.SlotMap); - } + string[] lines = value.Result.Split("\r\n"); + if (lines.Length <= 1) + throw new Exception("Incomplete file length!"); + string[] segments = nginxFileSystemSortable.Name.Split('-'); + Record record = GetRecord(lines[0], lines[1]); + string equipmentId = segments.Length <= 1 ? nginxFileSystemSortable.Name : segments[1].Split('.')[0]; + if (string.IsNullOrEmpty(record.SlotMap) || record.SlotMap.Length != 25) + throw new Exception("Wrong length!"); + if (record.Total != record.Check) + throw new Exception("Invalid!"); + result = new(nginxFileSystemSortable.DateTime, nginxFileSystemSortable.DateTime.ToString("yyyy-MM-dd hh:mm tt"), $"WC{waferSize}{equipmentId}", text, record.Total, record.SlotMap); return result; } - WaferCounter? IWaferCounterRepository.GetLastQuantityAndSlotMap(string area, string waferSize) + WaferCounter IWaferCounterRepository.GetLastQuantityAndSlotMap(string area, string waferSize) { - WaferCounter? result; - if (!string.IsNullOrEmpty(_MockRoot)) - { - string json = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), $"{_RepositoryName}-{nameof(IWaferCounterRepository.GetLastQuantityAndSlotMap)}.json")); - result = JsonSerializer.Deserialize(json); - if (result is null) - throw new NullReferenceException(nameof(result)); - } - else - { - Uri waferSizeUri = GetWaferSizeUri(area, waferSize); - HttpClient httpClient = _HttpClientFactory.CreateClient(); - string waferSizeDirectory = GetWaferSizeDirectory(area, waferSize, destination: false); - List nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(httpClient, waferSizeUri, waferSizeDirectory); - if (nginxFileSystemSortableCollection.Count == 0) - result = null; - else - { - string text = string.Empty; - result = GetLastQuantityAndSlotMapWithText(waferSize, text, httpClient, nginxFileSystemSortableCollection[0]); - } - } + WaferCounter result; + Uri waferSizeUri = GetWaferSizeUri(area, waferSize); + HttpClient httpClient = _HttpClientFactory.CreateClient(); + string waferSizeDirectory = GetWaferSizeDirectory(area, waferSize, destination: false); + List nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(httpClient, waferSizeUri, waferSizeDirectory); + if (nginxFileSystemSortableCollection.Count < 1) + throw new Exception("No files!"); + string text = string.Empty; + result = GetLastQuantityAndSlotMapWithText(waferSize, text, httpClient, nginxFileSystemSortableCollection[0]); return result; } private void Save(string waferSizeDestinationDirectory, string area, string waferSize, string text, NginxFileSystemSortable nginxFileSystemSortable, WaferCounter result) => _FileShareRepository.FileWrite(Path.Combine(waferSizeDestinationDirectory, $"{nginxFileSystemSortable.Name}.csv"), $"100,{waferSize},{area},{nginxFileSystemSortable.DateTime},{text},{result.Total:00},{result.SlotMap} "); - WaferCounter? IWaferCounterRepository.GetLastQuantityAndSlotMapWithText(string area, string waferSize, string text) + WaferCounter IWaferCounterRepository.GetLastQuantityAndSlotMapWithText(string area, string waferSize, string text) { - WaferCounter? result; - if (!string.IsNullOrEmpty(_MockRoot)) + WaferCounter result; + Uri waferSizeUri = GetWaferSizeUri(area, waferSize); + HttpClient httpClient = _HttpClientFactory.CreateClient(); + string waferSizeDirectory = GetWaferSizeDirectory(area, waferSize, destination: false); + List nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(httpClient, waferSizeUri, waferSizeDirectory); + if (nginxFileSystemSortableCollection.Count < 1) + throw new Exception("No files!"); + result = GetLastQuantityAndSlotMapWithText(waferSize, text, httpClient, nginxFileSystemSortableCollection[0]); + if (result is not null) { - string json = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), $"{_RepositoryName}-{nameof(IWaferCounterRepository.GetLastQuantityAndSlotMapWithText)}.json")); - result = JsonSerializer.Deserialize(json); - if (result is null) - throw new NullReferenceException(nameof(result)); - } - else - { - Uri waferSizeUri = GetWaferSizeUri(area, waferSize); - HttpClient httpClient = _HttpClientFactory.CreateClient(); - string waferSizeDirectory = GetWaferSizeDirectory(area, waferSize, destination: false); - List nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(httpClient, waferSizeUri, waferSizeDirectory); - if (nginxFileSystemSortableCollection.Count == 0) - result = null; - else - { - result = GetLastQuantityAndSlotMapWithText(waferSize, text, httpClient, nginxFileSystemSortableCollection[0]); - if (result is not null) - { - string waferSizeDestinationDirectory = _AppSettings.WaferCounterDestinationDirectory; - // string waferSizeDestinationDirectory = GetWaferSizeUri(area, waferSize, destination: true); - Save(waferSizeDestinationDirectory, area, waferSize, text, nginxFileSystemSortableCollection[0], result); - } - } + string waferSizeDestinationDirectory = _AppSettings.WaferCounterDestinationDirectory; + // string waferSizeDestinationDirectory = GetWaferSizeUri(area, waferSize, destination: true); + Save(waferSizeDestinationDirectory, area, waferSize, text, nginxFileSystemSortableCollection[0], result); } + if (result is null) + throw new NullReferenceException(nameof(result)); return result; } diff --git a/Shared/Models/Stateless/IWaferCounterRepository.cs b/Shared/Models/Stateless/IWaferCounterRepository.cs index 28c8d31..3a0d024 100644 --- a/Shared/Models/Stateless/IWaferCounterRepository.cs +++ b/Shared/Models/Stateless/IWaferCounterRepository.cs @@ -4,7 +4,7 @@ public interface IWaferCounterRepository { string? GetSlotMap(string line1, string line2); - DataModels.WaferCounter? GetLastQuantityAndSlotMap(string area, string waferSize); + DataModels.WaferCounter GetLastQuantityAndSlotMap(string area, string waferSize); DataModels.WaferCounter? GetLastQuantityAndSlotMapWithText(string area, string waferSize, string text); } \ No newline at end of file diff --git a/Tests/UnitTestWaferCounterController.cs b/Tests/UnitTestWaferCounterController.cs index 77ae2be..1252d55 100644 --- a/Tests/UnitTestWaferCounterController.cs +++ b/Tests/UnitTestWaferCounterController.cs @@ -64,22 +64,45 @@ public class UnitTestWaferCounterController Assert.AreEqual("0111011111111111111111000", result); result = waferCounterRepository?.GetSlotMap("T20", "P07FFFF8"); Assert.AreEqual("0011111111111111111111000", result); + result = waferCounterRepository?.GetSlotMap("T20", "P17FFFF0"); + Assert.AreEqual("1011111111111111111110000", result); + result = waferCounterRepository?.GetSlotMap("T03", "P1002002"); + Assert.AreEqual("1000000000010000000000010", result); + result = waferCounterRepository?.GetSlotMap("T02", "P1000002"); + Assert.AreEqual("1000000000000000000000010", result); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } + [Ignore] [TestMethod] public void GetLastQuantityAndSlotMap() { + WaferCounter? result; _Logger?.LogInformation("Starting Web Application"); IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IWaferCounterRepository? waferCounterRepository = serviceProvider?.GetRequiredService(); - WaferCounter? result = waferCounterRepository?.GetLastQuantityAndSlotMap("EPP-East", "8INCH"); + result = waferCounterRepository?.GetLastQuantityAndSlotMap("EPP-East", "6INCH"); + Assert.IsNotNull(result); + result = waferCounterRepository?.GetLastQuantityAndSlotMap("EPP-East", "8INCH"); + Assert.IsNotNull(result); + result = waferCounterRepository?.GetLastQuantityAndSlotMap("EPP-West", "6INCH"); + Assert.IsNotNull(result); + result = waferCounterRepository?.GetLastQuantityAndSlotMap("EPP-West", "8INCH"); + Assert.IsNotNull(result); + result = waferCounterRepository?.GetLastQuantityAndSlotMap("FQA", "6INCH"); + Assert.IsNotNull(result); + result = waferCounterRepository?.GetLastQuantityAndSlotMap("FQA", "8INCH"); + Assert.IsNotNull(result); + result = waferCounterRepository?.GetLastQuantityAndSlotMap("MU", "6INCH"); + Assert.IsNotNull(result); + result = waferCounterRepository?.GetLastQuantityAndSlotMap("MU", "8INCH"); Assert.IsNotNull(result); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } + [Ignore] [TestMethod] public async Task GetLastQuantityAndSlotMapApi() { @@ -93,6 +116,7 @@ public class UnitTestWaferCounterController NonThrowTryCatch(); } + [Ignore] [TestMethod] public void GetLastQuantityAndSlotMapWithText() { @@ -105,6 +129,7 @@ public class UnitTestWaferCounterController NonThrowTryCatch(); } + [Ignore] [TestMethod] public async Task GetLastQuantityAndSlotMapWithTextApi() {