diff --git a/.editorconfig b/.editorconfig index c8ce805..9198eff 100644 --- a/.editorconfig +++ b/.editorconfig @@ -101,6 +101,7 @@ dotnet_diagnostic.CA1860.severity = error # CA1860: Prefer comparing 'Count' to dotnet_diagnostic.CA1862.severity = warning # CA1862: Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' dotnet_diagnostic.CA1869.severity = none # CA1869: Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead. dotnet_diagnostic.CA2254.severity = none # CA2254: The logging message template should not vary between calls to 'LoggerExtensions.LogInformation(ILogger, string?, params object?[])' +dotnet_diagnostic.CS8936.severity = error # Feature 'collection expressions' is not available in C# 10.0. Please use language version 12.0 or greater. dotnet_diagnostic.IDE0001.severity = warning # IDE0001: Simplify name dotnet_diagnostic.IDE0002.severity = warning # Simplify (member access) - System.Version.Equals("1", "2"); Version.Equals("1", "2"); dotnet_diagnostic.IDE0004.severity = warning # IDE0004: Cast is redundant. diff --git a/Archive/Models/Binder/AppSettings.cs b/Archive/Models/Binder/AppSettings.cs index d56de6f..c0c6965 100644 --- a/Archive/Models/Binder/AppSettings.cs +++ b/Archive/Models/Binder/AppSettings.cs @@ -29,6 +29,23 @@ public class AppSettings return result; } + private static void PreVerify(IConfigurationRoot configurationRoot, AppSettings? appSettings) + { + if (appSettings?.ApiLoggingContentTypes is null) + { + List paths = []; + foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers) + { + if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider) + continue; + if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider) + continue; + paths.Add(physicalFileProvider.Root); + } + throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}"); + } + } + private static Models.AppSettings Get(AppSettings? appSettings) { Models.AppSettings result; @@ -73,20 +90,7 @@ public class AppSettings #pragma warning disable IL3050, IL2026 AppSettings? appSettings = configurationRoot.Get(); #pragma warning restore IL3050, IL2026 - if (appSettings?.ApiLoggingContentTypes is null) - { - foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers) - { - if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider) - continue; - if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider) - continue; - if (!physicalFileProvider.Root.Contains("UserSecrets")) - continue; - throw new NotSupportedException(physicalFileProvider.Root); - } - throw new NotSupportedException("Not found!"); - } + PreVerify(configurationRoot, appSettings); result = Get(appSettings); return result; } diff --git a/Server/ApiControllers/FileShareController.cs b/Server/ApiControllers/FileShareController.cs new file mode 100644 index 0000000..9e535c3 --- /dev/null +++ b/Server/ApiControllers/FileShareController.cs @@ -0,0 +1,36 @@ +using Microsoft.AspNetCore.Mvc; +using OI.Metrology.Shared.Models.Stateless; + +namespace OI.Metrology.Server.ApiControllers; + +[Route("api/v1/file-share")] +public class FileShareController : Controller, IFileShareController +{ + + private readonly IFileShareRepository _FileShareRepository; + + public FileShareController(IFileShareRepository fileShareRepository) => + _FileShareRepository = fileShareRepository; + + [HttpGet("copy-file")] + public IResult CopyFile(string from, string to) + { + _FileShareRepository.CopyFile(from, to); + return Results.Ok(); + } + + [HttpGet("move-file")] + public IResult MoveFile(string from, string to) + { + _FileShareRepository.CopyFile(from, to); + return Results.Ok(); + } + + [HttpGet("file-write")] + public IResult FileWrite(string path, string contents) + { + _FileShareRepository.FileWrite(path, contents); + return Results.Ok(); + } + +} \ No newline at end of file diff --git a/Server/ApiControllers/ReactorsController.cs b/Server/ApiControllers/ReactorsController.cs deleted file mode 100644 index 2fd00e1..0000000 --- a/Server/ApiControllers/ReactorsController.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using OI.Metrology.Shared.Models.Stateless; -using System.Text.Json; - -namespace OI.Metrology.Server.ApiControllers; - -[Route("api/[controller]")] -public class ReactorsController : Controller, IReactorsController -{ - - private readonly IReactorsRepository _ReactorsRepository; - - public ReactorsController(IReactorsRepository reactorsRepository) => - _ReactorsRepository = reactorsRepository; - - [HttpGet("{even}")] - public IActionResult Get(bool even) => - Json(even ? _ReactorsRepository.EvenReactors() : _ReactorsRepository.OddReactors(), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true }); - - [HttpPost()] - public IActionResult Post(Shared.DataModels.WorkMaterialOut workMaterialOut) => - Ok(_ReactorsRepository.GetKey(workMaterialOut, save: true)); - -} \ No newline at end of file diff --git a/Server/ApiControllers/ToolTypesController.cs b/Server/ApiControllers/ToolTypesController.cs index 118145e..a477214 100644 --- a/Server/ApiControllers/ToolTypesController.cs +++ b/Server/ApiControllers/ToolTypesController.cs @@ -100,7 +100,7 @@ public class ToolTypesController : Controller, IToolTypesController string.IsNullOrEmpty(_AppSettings.ApiUrl) ? Url.Content("~/") : _AppSettings.ApiUrl[0] == '~' ? Url.Content(_AppSettings.ApiUrl) : _AppSettings.ApiUrl; - - [HttpGet] - [Route("/Step1")] - [Route("/Metrology/Step1")] - public IActionResult Step1(string mod = "", string equipment = "", string layer = "", string zone = "", string rds = "", string initials = "") - { - string directory = "D:/Tmp/Metrology"; - if (!Directory.Exists(directory)) - _ = Directory.CreateDirectory(directory); - string[] model = new string[] { mod, equipment, layer, zone, rds, initials }; - if (!string.IsNullOrEmpty(initials)) - System.IO.File.WriteAllLines(Path.Combine(directory, $"{DateTime.Now.Ticks}-{initials}.rsv"), model); - return View(model); - } - - [HttpGet] - [Route("/Step2")] - [Route("/Metrology/Step2")] - public IActionResult Step2(string mod) => - View(new string[] { mod }); - - [HttpGet] - [Route("/Step3")] - [Route("/Metrology/Step3")] - public IActionResult Step3(string mod, string equipment) => - View(new string[] { mod, equipment }); - - [HttpGet] - [Route("/Step4")] - [Route("/Metrology/Step4")] - public IActionResult Step4(string mod, string equipment, string layer) => - View(new string[] { mod, equipment, layer }); - - [HttpGet] - [Route("/Step5")] - [Route("/Metrology/Step5")] - public IActionResult Step5(string mod, string equipment, string layer, string zone) => - View(new string[] { mod, equipment, layer, zone }); - - [HttpGet] - [Route("/Step6")] - [Route("/Metrology/Step6")] - public IActionResult Step6(string mod, string equipment, string layer, string zone, string rds) => - View(new string[] { mod, equipment, layer, zone, rds }); - - [HttpGet] - [Route("/Reactor")] - [Route("/Metrology/Reactor")] - public IActionResult Reactor() => View(new RunInfo()); - - [HttpGet] - [Route("/WorkMaterial")] - [Route("/Metrology/WorkMaterial")] - public IActionResult WorkMaterial() => View(); - -} \ No newline at end of file diff --git a/Server/Models/AppSettings.cs b/Server/Models/AppSettings.cs index 877e72d..233b0e9 100644 --- a/Server/Models/AppSettings.cs +++ b/Server/Models/AppSettings.cs @@ -3,14 +3,17 @@ using System.Text.Json; namespace OI.Metrology.Server.Models; public record AppSettings(string ApiExportPath, + string ApiFileShare, string ApiLoggingContentTypes, string ApiLoggingPathPrefixes, string ApiLogPath, string ApiUrl, - string AttachmentPath, string BuildNumber, string Company, string ConnectionString, + string EcCharacterizationSi, + string EcMesaFileShareCharacterizationSi, + string EcMesaFileShareMetrologySi, string GitCommitSeven, string InboundApiAllowedIPList, string IqsColumns, @@ -27,7 +30,6 @@ public record AppSettings(string ApiExportPath, Dictionary TableToPath, string URLs, string WaferCounterDestinationDirectory, - string WaferCounterRootDirectory, string WorkingDirectoryName) { diff --git a/Server/Models/Binder/AppSettings.cs b/Server/Models/Binder/AppSettings.cs index 929e9fd..5245c12 100644 --- a/Server/Models/Binder/AppSettings.cs +++ b/Server/Models/Binder/AppSettings.cs @@ -7,14 +7,17 @@ public class AppSettings { public string? ApiExportPath { get; set; } + public string? ApiFileShare { get; set; } public string? ApiLoggingContentTypes { get; set; } public string? ApiLoggingPathPrefixes { get; set; } public string? ApiLogPath { get; set; } public string? ApiUrl { get; set; } - public string? AttachmentPath { get; set; } public string? BuildNumber { get; set; } public string? Company { get; set; } public string? ConnectionString { get; set; } + public string? EcCharacterizationSi { get; set; } + public string? EcMesaFileShareCharacterizationSi { get; set; } + public string? EcMesaFileShareMetrologySi { get; set; } public string? GitCommitSeven { get; set; } public string? InboundApiAllowedIPList { get; set; } public string? IqsColumns { get; set; } @@ -31,7 +34,6 @@ public class AppSettings public Dictionary? TableToPath { get; set; } public string? URLs { get; set; } public string? WaferCounterDestinationDirectory { get; set; } - public string? WaferCounterRootDirectory { get; set; } public string? WorkingDirectoryName { get; set; } public override string ToString() @@ -40,19 +42,39 @@ public class AppSettings return result; } + private static void PreVerify(IConfigurationRoot configurationRoot, AppSettings? appSettings) + { + if (appSettings?.ApiExportPath is null) + { + List paths = new(); + foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers) + { + if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider) + continue; + if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider) + continue; + paths.Add(physicalFileProvider.Root); + } + throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}"); + } + } + private static Models.AppSettings Get(AppSettings? 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)); if (appSettings.ApiLogPath is null) throw new NullReferenceException(nameof(ApiLogPath)); if (appSettings.ApiUrl is null) throw new NullReferenceException(nameof(ApiUrl)); - if (appSettings.AttachmentPath is null) throw new NullReferenceException(nameof(AttachmentPath)); if (appSettings.BuildNumber is null) throw new NullReferenceException(nameof(BuildNumber)); if (appSettings.Company is null) throw new NullReferenceException(nameof(Company)); if (appSettings.ConnectionString is null) throw new NullReferenceException(nameof(ConnectionString)); + if (appSettings.EcCharacterizationSi is null) throw new NullReferenceException(nameof(EcCharacterizationSi)); + if (appSettings.EcMesaFileShareCharacterizationSi is null) throw new NullReferenceException(nameof(EcMesaFileShareCharacterizationSi)); + if (appSettings.EcMesaFileShareMetrologySi is null) throw new NullReferenceException(nameof(EcMesaFileShareMetrologySi)); 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)); @@ -69,18 +91,20 @@ 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.WaferCounterRootDirectory is null) throw new NullReferenceException(nameof(WaferCounterRootDirectory)); if (appSettings.WorkingDirectoryName is null) throw new NullReferenceException(nameof(WorkingDirectoryName)); result = new( appSettings.ApiExportPath, + appSettings.ApiFileShare, appSettings.ApiLoggingContentTypes, appSettings.ApiLoggingPathPrefixes, appSettings.ApiLogPath, appSettings.ApiUrl, - appSettings.AttachmentPath, appSettings.BuildNumber, appSettings.Company, appSettings.ConnectionString, + appSettings.EcCharacterizationSi, + appSettings.EcMesaFileShareCharacterizationSi, + appSettings.EcMesaFileShareMetrologySi, appSettings.GitCommitSeven, appSettings.InboundApiAllowedIPList, appSettings.IqsColumns, @@ -97,7 +121,6 @@ public class AppSettings appSettings.TableToPath, appSettings.URLs, appSettings.WaferCounterDestinationDirectory, - appSettings.WaferCounterRootDirectory, appSettings.WorkingDirectoryName); return result; } @@ -108,22 +131,7 @@ public class AppSettings #pragma warning disable IL3050, IL2026 AppSettings? appSettings = configurationRoot.Get(); #pragma warning restore IL3050, IL2026 - if (appSettings?.ApiExportPath is null) - { - List paths = new(); - foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers) - { - if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider) - continue; - if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider) - continue; - paths.Add(physicalFileProvider.Root); - if (!physicalFileProvider.Root.Contains("UserSecrets")) - continue; - throw new NotSupportedException(physicalFileProvider.Root); - } - throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths)}"); - } + PreVerify(configurationRoot, appSettings); result = Get(appSettings); return result; } diff --git a/Server/Program.cs b/Server/Program.cs index 201db17..613fa81 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -4,7 +4,6 @@ using OI.Metrology.Server.Models; using OI.Metrology.Server.Repositories; using OI.Metrology.Server.Repository; using OI.Metrology.Server.Services; -using OI.Metrology.Shared.Models; using OI.Metrology.Shared.Models.Stateless; using OI.Metrology.Shared.Repositories; using OI.Metrology.Shared.Services; @@ -49,8 +48,6 @@ public class Program throw new Exception("Company name must have a value!"); if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) throw new Exception("Working directory name must have a value!"); - string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assemblyName, appSettings.WorkingDirectoryName); - Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory); try { _ = webApplicationBuilder.Services.AddMemoryCache(); @@ -70,7 +67,7 @@ public class Program _ = webApplicationBuilder.Services.AddScoped(); _ = webApplicationBuilder.Services.AddSingleton(); _ = webApplicationBuilder.Services.AddScoped(); - _ = webApplicationBuilder.Services.AddSingleton(); + _ = webApplicationBuilder.Services.AddSingleton(); _ = webApplicationBuilder.Services.AddSingleton(); _ = webApplicationBuilder.Services.AddSingleton(); _ = webApplicationBuilder.Services.AddScoped(); diff --git a/Server/Repositories/ExportRepository.cs b/Server/Repositories/ExportRepository.cs index 7348da5..4b5c444 100644 --- a/Server/Repositories/ExportRepository.cs +++ b/Server/Repositories/ExportRepository.cs @@ -1,5 +1,6 @@ using OI.Metrology.Server.Models; using OI.Metrology.Shared.DataModels; +using OI.Metrology.Shared.Models; using OI.Metrology.Shared.Models.Stateless; using System.Globalization; using System.Text.Json; @@ -12,13 +13,17 @@ public class ExportRepository : IExportRepository private readonly string _RepositoryName; private readonly AppSettings _AppSettings; private readonly ILogger _Logger; + private readonly IHttpClientFactory _HttpClientFactory; + private readonly IFileShareRepository _FileShareRepository; private readonly Dictionary> _RdsToHeaderCommonCollection; - public ExportRepository(ILogger logger, AppSettings appSettings) + public ExportRepository(ILogger logger, AppSettings appSettings, IHttpClientFactory httpClientFactory, IFileShareRepository fileShareRepository) { _Logger = logger; _AppSettings = appSettings; _RdsToHeaderCommonCollection = new(); + _HttpClientFactory = httpClientFactory; + _FileShareRepository = fileShareRepository; _RepositoryName = nameof(ExportRepository)[..^10]; } @@ -32,32 +37,47 @@ public class ExportRepository : IExportRepository return new string[] { weekOfYear, lastWeekOfYear }; } - private List GetFiles(HeaderCommon headerCommon, string searchPattern) + private NginxFileSystemSortable[] GetNginxFileSystemSortableCollection(HeaderCommon headerCommon, HttpClient httpClient, string endsWith) { - List results = new(); - string directory; + List results = new(); + Uri uri; string[] weeks = Get(); + List nginxFileSystemSortableCollection; foreach (string weekYear in weeks) { if (headerCommon.ID < 1) - directory = Path.Combine(_AppSettings.ApiExportPath, "Archive", "API", weekYear, $"-{headerCommon.PSN}", $"-{headerCommon.Reactor}", $"-{headerCommon.RDS}"); + uri = _FileShareRepository.Append(new Uri(_AppSettings.EcMesaFileShareMetrologySi), "Archive", "API", weekYear, $"-{headerCommon.PSN}", $"-{headerCommon.Reactor}", $"-{headerCommon.RDS}"); else - directory = Path.Combine(_AppSettings.ApiExportPath, "Archive", "API", weekYear, $"-{headerCommon.PSN}", $"-{headerCommon.Reactor}", $"-{headerCommon.RDS}", $"-{headerCommon.ID}"); - if (!Directory.Exists(directory)) - continue; - results.AddRange(Directory.GetFiles(directory, searchPattern, SearchOption.AllDirectories)); + uri = _FileShareRepository.Append(new Uri(_AppSettings.EcMesaFileShareMetrologySi), "Archive", "API", weekYear, $"-{headerCommon.PSN}", $"-{headerCommon.Reactor}", $"-{headerCommon.RDS}", $"-{headerCommon.ID}"); + nginxFileSystemSortableCollection = _FileShareRepository.GetNginxFileSystemSortableCollection(httpClient, uri, endsWith); + results.AddRange(nginxFileSystemSortableCollection); } - return results; + return results.OrderByDescending(l => l.DateTime).ToArray(); + } + + private string GetLines(HttpClient httpClient, NginxFileSystemSortable[] nginxFileSystemSortableCollection) + { + string result; + if (nginxFileSystemSortableCollection.Length != 1) + result = string.Empty; + else + { + HttpResponseMessage httpResponseMessage = _FileShareRepository.ReadFile(httpClient, nginxFileSystemSortableCollection.First().Uri); + if (httpResponseMessage.StatusCode != System.Net.HttpStatusCode.OK) + throw new Exception("File not found!"); + Task lines = httpResponseMessage.Content.ReadAsStringAsync(); + lines.Wait(); + result = lines.Result; + } + return result; } string IExportRepository.GetExport(HeaderCommon headerCommon) { string result; - List files = GetFiles(headerCommon, "*.txt"); - if (files.Count != 1) - result = string.Empty; - else - result = File.ReadAllText(files.First()); + HttpClient httpClient = _HttpClientFactory.CreateClient(); + NginxFileSystemSortable[] nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(headerCommon, httpClient, ".txt"); + result = GetLines(httpClient, nginxFileSystemSortableCollection); return result; } @@ -72,16 +92,17 @@ public class ExportRepository : IExportRepository JsonElement? jsonElement; const string ticks = "Ticks"; JsonProperty[] jsonProperties; - List files = GetFiles(headerCommon, "*.json"); - foreach (string file in files) + HttpClient httpClient = _HttpClientFactory.CreateClient(); + NginxFileSystemSortable[] nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(headerCommon, httpClient, ".json"); + foreach (NginxFileSystemSortable nginxFileSystemSortable in nginxFileSystemSortableCollection) { - json = File.ReadAllText(file); + json = GetLines(httpClient, nginxFileSystemSortableCollection); hc = JsonSerializer.Deserialize(json); if (hc is null) continue; if (hc.ID < 1) { - directory = Path.GetDirectoryName(file); + directory = Path.GetDirectoryName(nginxFileSystemSortable.Uri.OriginalString); if (directory is null) continue; directoryName = Path.GetFileName(directory); @@ -112,10 +133,11 @@ public class ExportRepository : IExportRepository List results = new(); string json; HeaderCommon? hc; - List files = GetFiles(headerCommon, "*.json"); - foreach (string file in files) + HttpClient httpClient = _HttpClientFactory.CreateClient(); + NginxFileSystemSortable[] nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(headerCommon, httpClient, ".json"); + foreach (NginxFileSystemSortable nginxFileSystemSortable in nginxFileSystemSortableCollection) { - json = File.ReadAllText(file); + json = GetLines(httpClient, nginxFileSystemSortableCollection); hc = JsonSerializer.Deserialize(json); if (hc is null) continue; @@ -132,11 +154,9 @@ public class ExportRepository : IExportRepository string IExportRepository.GetProcessDataStandardFormat(HeaderCommon headerCommon) { string result; - List files = GetFiles(headerCommon, "*.pdsf"); - if (files.Count != 1) - result = string.Empty; - else - result = File.ReadAllText(files.First()); + HttpClient httpClient = _HttpClientFactory.CreateClient(); + NginxFileSystemSortable[] nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(headerCommon, httpClient, ".pdsf"); + result = GetLines(httpClient, nginxFileSystemSortableCollection); return result; } diff --git a/Server/Repositories/FileShareRepository.cs b/Server/Repositories/FileShareRepository.cs new file mode 100644 index 0000000..29022e3 --- /dev/null +++ b/Server/Repositories/FileShareRepository.cs @@ -0,0 +1,105 @@ +using OI.Metrology.Shared.Models; +using OI.Metrology.Shared.Models.Stateless; +using System.Text.Json; + +namespace OI.Metrology.Server.Repository; + +public class FileShareRepository : IFileShareRepository +{ + + Uri IFileShareRepository.Append(Uri uri, params string[] paths) => + new(paths.Aggregate(uri.AbsoluteUri, (current, path) => string.Format("{0}/{1}", current.TrimEnd('/'), path.TrimStart('/')))); + + private Uri GetEndPoint(HttpClient httpClient, string method) + { + Uri result; + if (httpClient.BaseAddress is null) + throw new NullReferenceException(nameof(httpClient.BaseAddress)); + IFileShareRepository fileShareRepository = this; + result = fileShareRepository.Append(httpClient.BaseAddress, "api", "v1", "file-share", method); + return result; + } + + void IFileShareRepository.CopyFile(string from, string to) + { + string directory = Path.GetDirectoryName(to) ?? throw new NullReferenceException(); + if (!Directory.Exists(directory)) + _ = Directory.CreateDirectory(directory); + File.Copy(from, to); + } + + void IFileShareRepository.MoveFile(string from, string to) + { + string directory = Path.GetDirectoryName(to) ?? throw new NullReferenceException(); + if (!Directory.Exists(directory)) + _ = Directory.CreateDirectory(directory); + File.Move(from, to); + } + + void IFileShareRepository.FileWrite(string path, string contents) + { + string directory = Path.GetDirectoryName(path) ?? throw new NullReferenceException(); + if (!Directory.Exists(directory)) + _ = Directory.CreateDirectory(directory); + File.WriteAllText(path, contents); + } + + void IFileShareRepository.CopyFile(HttpClient httpClient, string from, string to) + { + Uri uri = GetEndPoint(httpClient, "copy-file"); + Task httpResponseMessage = httpClient.GetAsync(uri); + httpResponseMessage.Wait(); + if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK) + throw new Exception(httpResponseMessage.Result.StatusCode.ToString()); + } + + void IFileShareRepository.MoveFile(HttpClient httpClient, string from, string to) + { + Uri uri = GetEndPoint(httpClient, "move-file"); + Task httpResponseMessage = httpClient.GetAsync(uri); + httpResponseMessage.Wait(); + if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK) + throw new Exception(httpResponseMessage.Result.StatusCode.ToString()); + } + + void IFileShareRepository.FileWrite(HttpClient httpClient, string path, string contents) + { + Uri uri = GetEndPoint(httpClient, "file-write"); + Task httpResponseMessage = httpClient.GetAsync(uri); + httpResponseMessage.Wait(); + if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK) + throw new Exception(httpResponseMessage.Result.StatusCode.ToString()); + } + + HttpResponseMessage IFileShareRepository.ReadFile(HttpClient httpClient, Uri uri) + { + HttpResponseMessage result; + Task httpResponseMessage = httpClient.GetAsync(uri); + httpResponseMessage.Wait(); + result = httpResponseMessage.Result; + return result; + } + + List IFileShareRepository.GetNginxFileSystemSortableCollection(HttpClient httpClient, Uri uri, string? endsWith) + { + List results = new(); + Task httpResponseMessage = httpClient.GetAsync(uri); + httpResponseMessage.Wait(); + if (httpResponseMessage.Result.StatusCode == System.Net.HttpStatusCode.OK) + { + FileShareRepository fileShareRepository = this; + Task json = httpResponseMessage.Result.Content.ReadAsStringAsync(); + json.Wait(); + NginxFileSystem[]? nginxFileSystemCollection = JsonSerializer.Deserialize(json.Result, NginxFileSystemCollectionSourceGenerationContext.Default.NginxFileSystemArray); + List nginxFileSystemSortableCollection = NginxFileSystemSortable.Convert(fileShareRepository, uri, nginxFileSystemCollection); + foreach (NginxFileSystemSortable nginxFileSystemSortable in nginxFileSystemSortableCollection.OrderByDescending(l => l.DateTime)) + { + if (!string.IsNullOrEmpty(endsWith) && !nginxFileSystemSortable.Name.EndsWith(endsWith)) + continue; + results.Add(nginxFileSystemSortable); + } + } + return results; + } + +} \ No newline at end of file diff --git a/Server/Repositories/InfinityQSV4Repository.cs b/Server/Repositories/InfinityQSV4Repository.cs index e60b2eb..18e2d97 100644 --- a/Server/Repositories/InfinityQSV4Repository.cs +++ b/Server/Repositories/InfinityQSV4Repository.cs @@ -22,14 +22,16 @@ public class InfinityQSV4Repository : IInfinityQSV4Repository private readonly AppSettings _AppSettings; private readonly IHttpClientFactory _HttpClientFactory; private readonly IDbConnectionFactory _DBConnectionFactory; + private readonly IFileShareRepository _FileShareRepository; private readonly string _OpenInsightApplicationProgrammingInterface; - public InfinityQSV4Repository(AppSettings appSettings, IDbConnectionFactory dbConnectionFactory, IHttpClientFactory httpClientFactory) + public InfinityQSV4Repository(AppSettings appSettings, IDbConnectionFactory dbConnectionFactory, IHttpClientFactory httpClientFactory, IFileShareRepository fileShareRepository) { _AppSettings = appSettings; _MockRoot = appSettings.MockRoot; _HttpClientFactory = httpClientFactory; _DBConnectionFactory = dbConnectionFactory; + _FileShareRepository = fileShareRepository; _RepositoryName = nameof(InfinityQSV4Repository)[..^10]; _OpenInsightApplicationProgrammingInterface = appSettings.OpenInsightApplicationProgrammingInterface; } @@ -591,7 +593,10 @@ public class InfinityQSV4Repository : IInfinityQSV4Repository { List lines = new(); foreach (char ch in runDataSheetRoot.RunDataSheet.PSN) - { } + { + if (ch is '1') + continue; + } result = string.Join(Environment.NewLine, lines); } } @@ -742,10 +747,10 @@ public class InfinityQSV4Repository : IInfinityQSV4Repository return results; } - private static void FileFindReplaceAndSave(AppSettings appSettings, string iqsFile, FileInfo fileInfo) + private void FileFindReplaceAndSave(string iqsFile, FileInfo fileInfo) { - string lines = File.ReadAllText(iqsFile).Replace(appSettings.IqsRed, "red").Replace(appSettings.IqsYellow, "Yellow"); - File.WriteAllText(fileInfo.FullName, lines); + string lines = File.ReadAllText(iqsFile).Replace(_AppSettings.IqsRed, "red").Replace(_AppSettings.IqsYellow, "Yellow"); + _FileShareRepository.FileWrite(fileInfo.FullName, lines); } Dictionary> IInfinityQSV4Repository.GetEngineeringSpcReview() @@ -771,7 +776,7 @@ public class InfinityQSV4Repository : IInfinityQSV4Repository else { if (!localFileInfo.Exists || localFileInfo.LastWriteTime != iqsFileInfo.LastWriteTime) - FileFindReplaceAndSave(_AppSettings, iqsFileInfo.FullName, localFileInfo); + FileFindReplaceAndSave(iqsFileInfo.FullName, localFileInfo); ReadOnlyCollection records = !iqsFileInfo.Exists || iqsFileInfo.Length == 0 ? GetRecords(_AppSettings, localFileInfo.FullName) : GetRecords(_AppSettings, iqsFileInfo.FullName); List> collection = GetCollection(_AppSettings.IqsColumns, records); results = GetResults(_AppSettings, collection); diff --git a/Server/Repositories/ReactorsRepository.cs b/Server/Repositories/ReactorsRepository.cs deleted file mode 100644 index 3e927e9..0000000 --- a/Server/Repositories/ReactorsRepository.cs +++ /dev/null @@ -1,146 +0,0 @@ -using OI.Metrology.Server.Models; -using OI.Metrology.Shared.DataModels; -using OI.Metrology.Shared.Models.Stateless; -using System.Globalization; -using System.Text.Json; - -namespace OI.Metrology.Server.Repository; - -public class ReactorsRepository : IReactorsRepository -{ - - private readonly AppSettings _AppSettings; - private readonly Dictionary _SecondsToAlpha; - - public ReactorsRepository(AppSettings appSettings) - { - _AppSettings = appSettings; - _SecondsToAlpha = new(); - for (int i = 65; i < 91; i++) - { - if (i is 73 or 79) - continue; - _SecondsToAlpha.Add(i - 65, (char)i); - } - - } - - Result IReactorsRepository.EvenReactors() - { - Result results; - int[] collection = new int[] { - 20, - 22, - 24, - 26, - 28, - 30, - 32, - 34, - 36, - 38, - 40, - 42, - 44, - 46, - 48, - 50, - 52, - 54, - 56, - 58, - 60, - 62, - 64, - 66, - 68, - 70, - 72, - 74 - }; - results = new() - { - Results = collection, - TotalRows = collection.Length, - }; - return results; - } - - Result IReactorsRepository.OddReactors() - { - Result results; - int[] collection = new int[] { - 21, - 23, - 25, - 27, - 29, - 31, - 33, - 35, - 37, - 39, - 41, - 43, - 45, - 47, - 49, - 51, - 53, - 55, - 57, - 59, - 61, - 63, - 65, - 73, - 75, - 77, - 79 - }; - results = new() - { - Results = collection, - TotalRows = collection.Length, - }; - return results; - } - - string? IReactorsRepository.GetKey(WorkMaterialOut workMaterialOut, bool save) - { - if (workMaterialOut is null) - throw new Exception(); - if (workMaterialOut.Username is null || workMaterialOut.Username.Length < 2) - throw new ArgumentException(nameof(workMaterialOut.Username)); - if (workMaterialOut.RunDataSheet is null || workMaterialOut.RunDataSheet.Length < 2) - throw new ArgumentException(nameof(workMaterialOut.RunDataSheet)); - string? result = null; - char c; - string? fileName = null; - DateTime dateTime = DateTime.Now; - Calendar calendar = new CultureInfo("en-US").Calendar; - string json = JsonSerializer.Serialize(workMaterialOut, new JsonSerializerOptions { WriteIndented = true }); - string weekOfYear = $"{dateTime:yyyy}_Week_{calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}"; - string directory = Path.Combine(_AppSettings.ApiExportPath, "WorkMaterialOut", "API", weekOfYear, dateTime.ToString("yyyy-MM-dd_HH")); - if (!Directory.Exists(directory)) - _ = Directory.CreateDirectory(directory); - for (int i = 0; i < int.MaxValue; i++) - { - dateTime = dateTime.AddSeconds(i); - if (!_SecondsToAlpha.TryGetValue(dateTime.Second, out c)) - continue; - fileName = Path.Combine(directory, $"WMO-{dateTime:mm}{c}.json"); - if (!File.Exists(fileName)) - { - result = $"{c}{dateTime:mm}"; - break; - } - } - if (fileName is null) - throw new Exception(); - if (save) - File.WriteAllText(fileName, json); - return result; - } - -} \ No newline at end of file diff --git a/Server/Repositories/ToolTypesRepository.cs b/Server/Repositories/ToolTypesRepository.cs index 346fca3..0ded8db 100644 --- a/Server/Repositories/ToolTypesRepository.cs +++ b/Server/Repositories/ToolTypesRepository.cs @@ -13,10 +13,16 @@ public class ToolTypesRepository : IToolTypesRepository private readonly string _MockRoot; private readonly string _RepositoryName; + private readonly AppSettings _AppSettings; + private readonly IHttpClientFactory _HttpClientFactory; + private readonly IFileShareRepository _FileShareRepository; - public ToolTypesRepository(AppSettings appSettings) + public ToolTypesRepository(AppSettings appSettings, IHttpClientFactory httpClientFactory, IFileShareRepository fileShareRepository) { + _AppSettings = appSettings; _MockRoot = appSettings.MockRoot; + _HttpClientFactory = httpClientFactory; + _FileShareRepository = fileShareRepository; _RepositoryName = nameof(ToolTypesRepository)[..^10]; } @@ -203,7 +209,7 @@ public class ToolTypesRepository : IToolTypesRepository return new(message, contentType, stream); } - string? IToolTypesRepository.OIExport(IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService, string attachmentPath, Dictionary tableToPath, int toolTypeId, long headerid) + string? IToolTypesRepository.OIExport(IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService, int toolTypeId, long headerid) { string? result; ToolType toolType = metrologyRepository.GetToolTypeByID(toolTypeId); @@ -211,16 +217,18 @@ public class ToolTypesRepository : IToolTypesRepository result = $"Invalid tool id [{toolTypeId}] [{headerid}]!"; else { - string? processDataStandardFormat = attachmentsService.GetProcessDataStandardFormat(metrologyRepository, attachmentPath, toolTypeId, headerid); + string? processDataStandardFormat = attachmentsService.GetProcessDataStandardFormat(metrologyRepository, toolTypeId, headerid); if (processDataStandardFormat is null) - result = $"Export file doesn't exist for [{toolTypeId}] [{headerid}] at <{attachmentPath}>!"; - else if (!tableToPath.TryGetValue(toolType.HeaderTableName, out string? directly)) - result = $"Export file doesn't exist for [{toolTypeId}] [{headerid}] at <{attachmentPath}>!"; + result = $"Export file doesn't exist for [{toolTypeId}] [{headerid}] at <{_AppSettings.EcMesaFileShareMetrologySi}>!"; + else if (!_AppSettings.TableToPath.TryGetValue(toolType.HeaderTableName, out string? directly)) + result = $"Export file doesn't exist for [{toolTypeId}] [{headerid}] at <{_AppSettings.EcMesaFileShareMetrologySi}>!"; else { try { - File.Copy(processDataStandardFormat, Path.Combine(directly, $"Viewer_{Path.GetFileName(processDataStandardFormat)}")); + HttpClient httpClient = _HttpClientFactory.CreateClient(); + httpClient.BaseAddress = new(_AppSettings.ApiFileShare); + _FileShareRepository.CopyFile(httpClient, processDataStandardFormat, Path.Combine(directly, $"Viewer_{Path.GetFileName(processDataStandardFormat)}")); result = null; } catch (Exception ex) { result = ex.Message; } diff --git a/Server/Repositories/WaferCounterRepository.cs b/Server/Repositories/WaferCounterRepository.cs index 32ac0c7..7eae63a 100644 --- a/Server/Repositories/WaferCounterRepository.cs +++ b/Server/Repositories/WaferCounterRepository.cs @@ -1,5 +1,6 @@ using OI.Metrology.Server.Models; using OI.Metrology.Shared.DataModels; +using OI.Metrology.Shared.Models; using OI.Metrology.Shared.Models.Stateless; using OI.Metrology.Shared.Repositories; using System.Globalization; @@ -19,28 +20,27 @@ public class WaferCounterRepository : IWaferCounterRepository private readonly AppSettings _AppSettings; private readonly IHttpClientFactory _HttpClientFactory; private readonly IDbConnectionFactory _DBConnectionFactory; + private readonly IFileShareRepository _FileShareRepository; private readonly string _OpenInsightApplicationProgrammingInterface; - public WaferCounterRepository(AppSettings appSettings, IDbConnectionFactory dbConnectionFactory, IHttpClientFactory httpClientFactory) + public WaferCounterRepository(AppSettings appSettings, IDbConnectionFactory dbConnectionFactory, IHttpClientFactory httpClientFactory, IFileShareRepository fileShareRepository) { _AppSettings = appSettings; _MockRoot = appSettings.MockRoot; _HttpClientFactory = httpClientFactory; _DBConnectionFactory = dbConnectionFactory; + _FileShareRepository = fileShareRepository; _RepositoryName = nameof(WaferCounterRepository)[..^10]; _OpenInsightApplicationProgrammingInterface = appSettings.OpenInsightApplicationProgrammingInterface; } - private static void MoveFile(string waferSizeDirectory, FileInfo fileInfo) + private void MoveFile(string waferSizeDirectory, NginxFileSystemSortable nginxFileSystemSortable) { Calendar calendar = new CultureInfo("en-US").Calendar; - string weekOfYear = $"{fileInfo.LastWriteTime:yyyy}_Week_{calendar.GetWeekOfYear(fileInfo.LastWriteTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}"; - string checkDirectory = Path.Combine(waferSizeDirectory, "Archive", weekOfYear); - if (!Directory.Exists(checkDirectory)) - _ = Directory.CreateDirectory(checkDirectory); - string checkFile = Path.Combine(checkDirectory, fileInfo.Name); - if (!File.Exists(checkFile)) - File.Move(fileInfo.FullName, checkFile); + string from = Path.Combine(waferSizeDirectory, nginxFileSystemSortable.Name); + string weekOfYear = $"{nginxFileSystemSortable.DateTime:yyyy}_Week_{calendar.GetWeekOfYear(nginxFileSystemSortable.DateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}"; + string to = Path.Combine(waferSizeDirectory, "Archive", weekOfYear, nginxFileSystemSortable.Name); + _FileShareRepository.MoveFile(from, to); } private static Record GetRecord(string line1, string line2) @@ -126,43 +126,42 @@ public class WaferCounterRepository : IWaferCounterRepository return result; } + private Uri GetWaferSizeUri(string area, string waferSize) => + _FileShareRepository.Append(new Uri(_AppSettings.EcMesaFileShareCharacterizationSi), "WaferCounter", area, waferSize); + private string GetWaferSizeDirectory(string area, string waferSize, bool destination) => - destination ? Path.Combine(_AppSettings.WaferCounterDestinationDirectory, area, waferSize) : Path.Combine(_AppSettings.WaferCounterRootDirectory, area, waferSize); + destination ? Path.Combine(_AppSettings.WaferCounterDestinationDirectory, area, waferSize) : Path.Combine(_AppSettings.EcCharacterizationSi, "WaferCounter", area, waferSize); string? IWaferCounterRepository.GetSlotMap(string line1, string line2) => GetRecord(line1, line2).SlotMap; - private static FileInfo[] GetFileInfoCollection(string waferSizeDirectory) + private List GetNginxFileSystemSortableCollection(HttpClient httpClient, Uri waferSizeUri, string waferSizeDirectory) { - List results = new(); - FileInfo[] fileInfoCollection; - string[] files = !Directory.Exists(waferSizeDirectory) ? Array.Empty() : Directory.GetFiles(waferSizeDirectory, "*.wc", SearchOption.TopDirectoryOnly); - fileInfoCollection = (from l in files select new FileInfo(l)).OrderByDescending(l => l.LastWriteTime).ToArray(); - if (fileInfoCollection.Length > 0) - results.Add(fileInfoCollection[0]); - - for (int i = 1; i < fileInfoCollection.Length; i++) - MoveFile(waferSizeDirectory, fileInfoCollection[i]); - return fileInfoCollection; + List results = _FileShareRepository.GetNginxFileSystemSortableCollection(httpClient, waferSizeUri, ".wc"); + for (int i = 1; i < results.Count; i++) + MoveFile(waferSizeDirectory, results[i]); + return results; } - private static WaferCounter? GetLastQuantityAndSlotMapWithText(string waferSize, string text, FileInfo fileInfo) + private static WaferCounter? GetLastQuantityAndSlotMapWithText(string waferSize, string text, HttpClient httpClient, NginxFileSystemSortable nginxFileSystemSortable) { WaferCounter? result; - string[] lines = File.ReadAllLines(fileInfo.FullName); + Task value = httpClient.GetStringAsync(nginxFileSystemSortable.Uri); + value.Wait(); + string[] lines = value.Result.Split(Environment.NewLine); if (lines.Length < 2) result = null; else { - string[] segments = fileInfo.Name.Split('-'); + string[] segments = nginxFileSystemSortable.Name.Split('-'); Record record = GetRecord(lines[0], lines[1]); - string equipmentId = segments.Length < 2 ? fileInfo.Name : segments[1].Split('.')[0]; + 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(fileInfo.LastWriteTime, fileInfo.LastWriteTime.ToString("yyyy-MM-dd hh:mm tt"), $"WC{waferSize}{equipmentId}", text, record.Total, record.SlotMap); + result = new(nginxFileSystemSortable.DateTime, nginxFileSystemSortable.DateTime.ToString("yyyy-MM-dd hh:mm tt"), $"WC{waferSize}{equipmentId}", text, record.Total, record.SlotMap); } return result; } @@ -179,21 +178,23 @@ public class WaferCounterRepository : IWaferCounterRepository } else { + Uri waferSizeUri = GetWaferSizeUri(area, waferSize); + HttpClient httpClient = _HttpClientFactory.CreateClient(); string waferSizeDirectory = GetWaferSizeDirectory(area, waferSize, destination: false); - FileInfo[] fileInfoCollection = GetFileInfoCollection(waferSizeDirectory); - if (fileInfoCollection.Length == 0) + List nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(httpClient, waferSizeUri, waferSizeDirectory); + if (nginxFileSystemSortableCollection.Count == 0) result = null; else { string text = string.Empty; - result = GetLastQuantityAndSlotMapWithText(waferSize, text, fileInfoCollection[0]); + result = GetLastQuantityAndSlotMapWithText(waferSize, text, httpClient, nginxFileSystemSortableCollection[0]); } } return result; } - private static void Save(string waferSizeDestinationDirectory, string area, string waferSize, string text, FileInfo fileInfo, WaferCounter result) => - File.WriteAllText(Path.Combine(waferSizeDestinationDirectory, $"{fileInfo.Name}.csv"), $"100,{waferSize},{area},{fileInfo.LastWriteTime},{text},{result.Total:00},{result.SlotMap} "); + 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) { @@ -207,18 +208,20 @@ public class WaferCounterRepository : IWaferCounterRepository } else { + Uri waferSizeUri = GetWaferSizeUri(area, waferSize); + HttpClient httpClient = _HttpClientFactory.CreateClient(); string waferSizeDirectory = GetWaferSizeDirectory(area, waferSize, destination: false); - FileInfo[] fileInfoCollection = GetFileInfoCollection(waferSizeDirectory); - if (fileInfoCollection.Length == 0) + List nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(httpClient, waferSizeUri, waferSizeDirectory); + if (nginxFileSystemSortableCollection.Count == 0) result = null; else { - result = GetLastQuantityAndSlotMapWithText(waferSize, text, fileInfoCollection[0]); + result = GetLastQuantityAndSlotMapWithText(waferSize, text, httpClient, nginxFileSystemSortableCollection[0]); if (result is not null) { string waferSizeDestinationDirectory = _AppSettings.WaferCounterDestinationDirectory; - // string waferSizeDestinationDirectory = GetWaferSizeDirectory(area, waferSize, destination: true); - Save(waferSizeDestinationDirectory, area, waferSize, text, fileInfoCollection[0], result); + // string waferSizeDestinationDirectory = GetWaferSizeUri(area, waferSize, destination: true); + Save(waferSizeDestinationDirectory, area, waferSize, text, nginxFileSystemSortableCollection[0], result); } } } diff --git a/Server/Services/AttachmentsService.cs b/Server/Services/AttachmentsService.cs index f71fb9e..9e34a64 100644 --- a/Server/Services/AttachmentsService.cs +++ b/Server/Services/AttachmentsService.cs @@ -4,17 +4,24 @@ namespace OI.Metrology.Server.Services; using OI.Metrology.Server.Models; using OI.Metrology.Shared.DataModels; +using OI.Metrology.Shared.Models; using OI.Metrology.Shared.Models.Stateless; using OI.Metrology.Shared.Services; +using System.Text.Json; public class AttachmentsService : IAttachmentsService { + private readonly AppSettings _AppSettings; + private readonly IHttpClientFactory _HttpClientFactory; + private readonly IFileShareRepository _FileShareRepository; private readonly IMetrologyRepository _MetrologyRepository; - public AttachmentsService(AppSettings appSettings, IMetrologyRepository metrologyRepository) + public AttachmentsService(AppSettings appSettings, IHttpClientFactory httpClientFactory, IFileShareRepository fileShareRepository, IMetrologyRepository metrologyRepository) { _AppSettings = appSettings; + _HttpClientFactory = httpClientFactory; + _FileShareRepository = fileShareRepository; _MetrologyRepository = metrologyRepository; } @@ -27,23 +34,16 @@ public class AttachmentsService : IAttachmentsService throw new NullReferenceException(nameof(tableName)); DateTime insertDate = Convert.ToDateTime(_MetrologyRepository.GetAttachmentInsertDateByGUID(tableName, attachmentId)); + string year = insertDate.Year.ToString(); + HttpClient httpClient = _HttpClientFactory.CreateClient(); + Uri mesaFileShareMetrologySi = new(_AppSettings.EcMesaFileShareMetrologySi); int weekNum = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(insertDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); - string directory = Path.Combine(_AppSettings.AttachmentPath, tableName + "_", year, $"WW{weekNum:00}", attachmentId.ToString()); - if (!Directory.Exists(directory)) - _ = Directory.CreateDirectory(directory); - string fullPath = Path.Combine(directory, filename); - - // Check to see if file exists in the "New" directory structure, if not change the path back to the old. and check there - if (!File.Exists(fullPath)) - { - fullPath = Path.Combine(_AppSettings.AttachmentPath, tableName, attachmentId.ToString(), filename); - } - - if (!File.Exists(fullPath)) - throw new Exception("File not found"); - - return new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + Uri uri = _FileShareRepository.Append(mesaFileShareMetrologySi, $"{tableName}_", year, $"WW{weekNum:00}", attachmentId.ToString(), filename); + HttpResponseMessage httpResponseMessage = _FileShareRepository.ReadFile(httpClient, uri); + if (httpResponseMessage.StatusCode != System.Net.HttpStatusCode.OK) + throw new Exception("File not found!"); + return httpResponseMessage.Content.ReadAsStream(); } Stream IAttachmentsService.GetAttachmentStreamByTitle(ToolType toolType, bool header, string title, string filename) @@ -86,7 +86,6 @@ public class AttachmentsService : IAttachmentsService Guid attachmentId = Guid.Empty; DateTime insertDate = new(); string? tableName = ""; - if (string.IsNullOrWhiteSpace(dataUniqueId)) { attachmentId = _MetrologyRepository.GetHeaderAttachmentID(toolType.ID, headerId); @@ -101,18 +100,22 @@ public class AttachmentsService : IAttachmentsService tableName = toolType.DataTableName; } if (Equals(attachmentId, Guid.Empty)) - throw new Exception("Invalid attachment ID"); - + { + trans.Dispose(); + throw new Exception("Invalid attachment ID!"); + } string year = insertDate.Year.ToString(); + HttpClient httpClient = _HttpClientFactory.CreateClient(); + Uri mesaFileShareMetrologySi = new(_AppSettings.EcMesaFileShareMetrologySi); int weekNum = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(insertDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); - string directory = Path.Combine(_AppSettings.AttachmentPath, $"{tableName}_", year, $"WW{weekNum:00}", attachmentId.ToString()); - if (!Directory.Exists(directory)) - _ = Directory.CreateDirectory(directory); - - string fullPath = Path.Combine(directory, filename); - - using (FileStream fileStream = new(fullPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) - uploadedFile.CopyTo(fileStream); + Uri uri = _FileShareRepository.Append(mesaFileShareMetrologySi, $"{tableName}_", year, $"WW{weekNum:00}", attachmentId.ToString(), filename); + HttpResponseMessage httpResponseMessage = _FileShareRepository.ReadFile(httpClient, uri); + if (httpResponseMessage.StatusCode != System.Net.HttpStatusCode.OK) + { + trans.Dispose(); + throw new Exception("Invalid attachment path!"); + } + uploadedFile.CopyTo(httpResponseMessage.Content.ReadAsStream()); trans.Complete(); } @@ -122,27 +125,38 @@ public class AttachmentsService : IAttachmentsService SaveAttachment(toolType, headerId, dataUniqueId, filename, formFile); } - string? IAttachmentsService.GetProcessDataStandardFormat(IMetrologyRepository metrologyRepository, string attachmentPath, int toolTypeId, long headerId) + string? IAttachmentsService.GetProcessDataStandardFormat(IMetrologyRepository metrologyRepository, int toolTypeId, long headerId) { string? result; - string year; int weekNum; - string directory; - string checkDirectory; + string year; + Task json; + Uri weekDirectory; + Uri checkDirectory; List files = new(); + NginxFileSystem[]? nginxFileSystemCollection; + Task httpResponseMessage; + HttpClient httpClient = _HttpClientFactory.CreateClient(); + Uri mesaFileShareMetrologySi = new(_AppSettings.EcMesaFileShareMetrologySi); DateTime[] dateTimes = new DateTime[] { DateTime.Now, DateTime.Now.AddDays(-6.66) }; ToolType toolType = metrologyRepository.GetToolTypeByID(toolTypeId) ?? throw new Exception("Invalid tool type ID"); foreach (DateTime dateTime in dateTimes) { year = dateTime.Year.ToString(); weekNum = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); - directory = Path.Combine(_AppSettings.AttachmentPath, $"{toolType.HeaderTableName}_", year, $"WW{weekNum:00}"); - if (!Directory.Exists(directory)) - _ = Directory.CreateDirectory(directory); - checkDirectory = Path.Combine(directory, headerId.ToString()); - if (!Directory.Exists(checkDirectory)) + weekDirectory = _FileShareRepository.Append(mesaFileShareMetrologySi, $"{toolType.HeaderTableName}_", year, $"WW{weekNum:00}"); + checkDirectory = _FileShareRepository.Append(weekDirectory, headerId.ToString()); + httpResponseMessage = httpClient.GetAsync(checkDirectory); + httpResponseMessage.Wait(); + if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK) continue; - files.AddRange(Directory.GetFiles(checkDirectory)); + json = httpResponseMessage.Result.Content.ReadAsStringAsync(); + json.Wait(); + nginxFileSystemCollection = JsonSerializer.Deserialize(json.Result, NginxFileSystemCollectionSourceGenerationContext.Default.NginxFileSystemArray); + if (nginxFileSystemCollection is null) + continue; + foreach (NginxFileSystem nginxFileSystem in nginxFileSystemCollection) + files.Add(_FileShareRepository.Append(checkDirectory, nginxFileSystem.Name).AbsoluteUri); if (files.Count != 0) break; } diff --git a/Server/wwwroot/js/wafer-counter.js b/Server/wwwroot/js/wafer-counter.js index 579e79c..b71ea62 100644 --- a/Server/wwwroot/js/wafer-counter.js +++ b/Server/wwwroot/js/wafer-counter.js @@ -17,8 +17,8 @@ function getUrlParameter(param) { return false; } -function setWafers(waferMap) { - var slots = waferMap.split(""); +function setSlots(slotMap) { + var slots = slotMap.split(""); if (slots.length !== 25) throw Error; $('.slot').each(function (index) { @@ -36,7 +36,7 @@ function setValues(data) { clearMap(); else { $('#waferCount').val(data.total); - setWafers(data.waferMap); + setSlots(data.slotMap); $('#lastDateTime').text(new Date().toLocaleString()); } } @@ -48,7 +48,7 @@ function clearText() { } function clearMap() { - setWafers('0000000000000000000000000'); + setSlots('0000000000000000000000000'); } function poll() { @@ -59,7 +59,7 @@ function poll() { } else if (_count > -1) { _count++; - $.get(_apiUrl + $("#toolId").val() + '/last-quantity-and-wafer-map/?area=' + $("#operation").val(), function (data) { + $.get(_apiUrl + $("#toolId").val() + '/last-quantity-and-slot-map/?area=' + $("#operation").val(), function (data) { setValues(data); }).fail(function () { ShowErrorMessage("Error"); @@ -68,7 +68,7 @@ function poll() { } function save() { - $.get(_apiUrl + $("#toolId").val() + '/last-quantity-and-wafer-map-with-text/?area=' + $("#operation").val() + '&text=' + $("#lot").val(), function (data) { + $.get(_apiUrl + $("#toolId").val() + '/last-quantity-and-slot-map-with-text/?area=' + $("#operation").val() + '&text=' + $("#lot").val(), function (data) { setValues(data); }).fail(function () { ShowErrorMessage("Error"); diff --git a/Server/wwwroot/wafer-counter.html b/Server/wwwroot/wafer-counter.html index 8210fa2..6f0ab53 100644 --- a/Server/wwwroot/wafer-counter.html +++ b/Server/wwwroot/wafer-counter.html @@ -6,9 +6,9 @@ Wafer Counter - - - + + + diff --git a/Shared/Models/IWorkingDirectory.cs b/Shared/Models/IWorkingDirectory.cs deleted file mode 100644 index fa914c0..0000000 --- a/Shared/Models/IWorkingDirectory.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace OI.Metrology.Shared.Models; - -public interface IWorkingDirectory -{ - - static string GetWorkingDirectory(string? executingAssemblyName, string subDirectoryName) => - WorkingDirectory.GetWorkingDirectory(executingAssemblyName, subDirectoryName); - -} \ No newline at end of file diff --git a/Shared/Models/NginxFileSystem.cs b/Shared/Models/NginxFileSystem.cs new file mode 100644 index 0000000..870a479 --- /dev/null +++ b/Shared/Models/NginxFileSystem.cs @@ -0,0 +1,21 @@ +using System.Text.Json.Serialization; + +namespace OI.Metrology.Shared.Models; + +public record NginxFileSystem( + [property: JsonPropertyName("name")] string Name, + [property: JsonPropertyName("type")] string Type, + [property: JsonPropertyName("mtime")] string MTime, + [property: JsonPropertyName("size")] float Size); + +[JsonSourceGenerationOptions(WriteIndented = true)] +[JsonSerializable(typeof(NginxFileSystem))] +public partial class NginxFileSystemSourceGenerationContext : JsonSerializerContext +{ +} + +[JsonSourceGenerationOptions(WriteIndented = true)] +[JsonSerializable(typeof(NginxFileSystem[]))] +public partial class NginxFileSystemCollectionSourceGenerationContext : JsonSerializerContext +{ +} \ No newline at end of file diff --git a/Shared/Models/NginxFileSystemSortable.cs b/Shared/Models/NginxFileSystemSortable.cs new file mode 100644 index 0000000..8d9173c --- /dev/null +++ b/Shared/Models/NginxFileSystemSortable.cs @@ -0,0 +1,29 @@ +using OI.Metrology.Shared.Models.Stateless; +using System.Globalization; + +namespace OI.Metrology.Shared.Models; + +public record NginxFileSystemSortable(DateTime DateTime, + Uri Uri, + string Name, + float Size, + string Type) +{ + + public static List Convert(IFileShareRepository fileShareRepository, Uri waferSizeUri, NginxFileSystem[]? collection) + { + List results = new(); + NginxFileSystemSortable nginxFileSystemSortable; + string nginxFormat = "ddd, dd MMM yyyy HH:mm:ss zzz"; + foreach (NginxFileSystem nginxFileSystem in collection ?? Array.Empty()) + { + if (DateTime.TryParseExact(nginxFileSystem.MTime.Replace("GMT", "+00:00"), nginxFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime)) + nginxFileSystemSortable = new(dateTime, fileShareRepository.Append(waferSizeUri, nginxFileSystem.Name), nginxFileSystem.Name, nginxFileSystem.Size, nginxFileSystem.Type); + else + nginxFileSystemSortable = new(DateTime.MinValue, fileShareRepository.Append(waferSizeUri, nginxFileSystem.Name), nginxFileSystem.Name, nginxFileSystem.Size, nginxFileSystem.Type); + results.Add(nginxFileSystemSortable); + } + return results; + } + +} \ No newline at end of file diff --git a/Shared/Models/Stateless/IFileShareController.cs b/Shared/Models/Stateless/IFileShareController.cs new file mode 100644 index 0000000..1b35053 --- /dev/null +++ b/Shared/Models/Stateless/IFileShareController.cs @@ -0,0 +1,18 @@ +namespace OI.Metrology.Shared.Models.Stateless; + +public interface IFileShareController +{ + + enum Action : int + { + Index = 0, + MarkAsPinned = 1 + } + + static string GetRouteName() => nameof(IFileShareController)[1..^10]; + + T CopyFile(string from, string to); + T MoveFile(string from, string to); + T FileWrite(string path, string contents); + +} \ No newline at end of file diff --git a/Shared/Models/Stateless/IFileShareRepository.cs b/Shared/Models/Stateless/IFileShareRepository.cs new file mode 100644 index 0000000..ef07d96 --- /dev/null +++ b/Shared/Models/Stateless/IFileShareRepository.cs @@ -0,0 +1,16 @@ +namespace OI.Metrology.Shared.Models.Stateless; + +public interface IFileShareRepository +{ + + void CopyFile(string from, string to); + void MoveFile(string from, string to); + Uri Append(Uri uri, params string[] paths); + void FileWrite(string path, string contents); + HttpResponseMessage ReadFile(HttpClient httpClient, Uri uri); + void CopyFile(HttpClient httpClient, string from, string to); + void MoveFile(HttpClient httpClient, string from, string to); + void FileWrite(HttpClient httpClient, string path, string contents); + List GetNginxFileSystemSortableCollection(HttpClient httpClient, Uri uri, string? endsWith); + +} \ No newline at end of file diff --git a/Shared/Models/Stateless/IReactorsRepository.cs b/Shared/Models/Stateless/IReactorsRepository.cs deleted file mode 100644 index faccabc..0000000 --- a/Shared/Models/Stateless/IReactorsRepository.cs +++ /dev/null @@ -1,13 +0,0 @@ - -using OI.Metrology.Shared.DataModels; - -namespace OI.Metrology.Shared.Models.Stateless; - -public interface IReactorsRepository -{ - - Result EvenReactors(); - Result OddReactors(); - string? GetKey(WorkMaterialOut workMaterialOut, bool save); - -} \ No newline at end of file diff --git a/Shared/Models/Stateless/IToolTypesRepository.cs b/Shared/Models/Stateless/IToolTypesRepository.cs index 6f65ee6..df91cb6 100644 --- a/Shared/Models/Stateless/IToolTypesRepository.cs +++ b/Shared/Models/Stateless/IToolTypesRepository.cs @@ -8,13 +8,14 @@ public interface IToolTypesRepository { Result Index(IMetrologyRepository metrologyRepository); - Result GetToolTypeMetadata(IMetrologyRepository metrologyRepository, int id, string sortby = ""); - Result GetHeaders(IMetrologyRepository metrologyRepository, int id, string? datebegin, string? dateend, int? page, int? pagesize, long? headerid); - Result GetHeaderTitles(IMetrologyRepository metrologyRepository, int id, int? page, int? pagesize); - Result GetHeaderFields(IMetrologyRepository metrologyRepository, int id, long headerid); Result GetData(IMetrologyRepository metrologyRepository, int id, long headerid); - (string?, string?, Stream?) GetAttachment(IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService, int toolTypeId, string tabletype, string attachmentId, string filename); - string? OIExport(IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService, string attachmentPath, Dictionary tableToPath, int toolTypeId, long headerid); - Result GetExportData(IMetrologyRepository metrologyRepository, int toolTypeId, string? datebegin, string? dateend); + Result GetHeaderFields(IMetrologyRepository metrologyRepository, int id, long headerid); byte[] GetCSVExport(IMetrologyRepository metrologyRepository, int toolTypeId, string? datebegin, string? dateend); + Result GetHeaderTitles(IMetrologyRepository metrologyRepository, int id, int? page, int? pagesize); + Result GetToolTypeMetadata(IMetrologyRepository metrologyRepository, int id, string sortby = ""); + Result GetExportData(IMetrologyRepository metrologyRepository, int toolTypeId, string? datebegin, string? dateend); + string? OIExport(IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService, int toolTypeId, long headerid); + Result GetHeaders(IMetrologyRepository metrologyRepository, int id, string? datebegin, string? dateend, int? page, int? pagesize, long? headerid); + (string?, string?, Stream?) GetAttachment(IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService, int toolTypeId, string tabletype, string attachmentId, string filename); + } \ No newline at end of file diff --git a/Shared/Models/WorkingDirectory.cs b/Shared/Models/WorkingDirectory.cs deleted file mode 100644 index 92d902f..0000000 --- a/Shared/Models/WorkingDirectory.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace OI.Metrology.Shared.Models; - -internal abstract class WorkingDirectory -{ - - internal static string GetWorkingDirectory(string? executingAssemblyName, string subDirectoryName) - { - string result = string.Empty; - if (executingAssemblyName is null) - throw new Exception(); - string traceFile; - List directories = new(); - List specialFolders = new() - { - Environment.SpecialFolder.LocalApplicationData, - Environment.SpecialFolder.ApplicationData, - Environment.SpecialFolder.History, - Environment.SpecialFolder.CommonApplicationData, - Environment.SpecialFolder.InternetCache - }; - foreach (Environment.SpecialFolder specialFolder in specialFolders) - directories.Add(Path.Combine(Environment.GetFolderPath(specialFolder), subDirectoryName, executingAssemblyName)); - foreach (string directory in directories) - { - for (int i = 1; i < 3; i++) - { - if (i == 1) - result = directory; - else - result = string.Concat("D", directory[1..]); - try - { - if (!Directory.Exists(result)) - _ = Directory.CreateDirectory(result); - traceFile = string.Concat(result, @"\", DateTime.Now.Ticks, ".txt"); - File.WriteAllText(traceFile, traceFile); - File.Delete(traceFile); - break; - } - catch (Exception) { result = string.Empty; } - } - if (!string.IsNullOrEmpty(result)) - break; - } - if (string.IsNullOrEmpty(result)) - throw new Exception("Unable to set working directory!"); - return result; - } - -} \ No newline at end of file diff --git a/Shared/Services/IAttachmentsService.cs b/Shared/Services/IAttachmentsService.cs index 5b570f5..ceaf20a 100644 --- a/Shared/Services/IAttachmentsService.cs +++ b/Shared/Services/IAttachmentsService.cs @@ -7,6 +7,6 @@ public interface IAttachmentsService { Stream GetAttachmentStreamByTitle(ToolType toolType, bool header, string title, string filename); Stream GetAttachmentStreamByAttachmentId(ToolType toolType, bool header, Guid attachmentId, string filename); + string? GetProcessDataStandardFormat(IMetrologyRepository metrologyRepository, int toolTypeId, long headerId); void SaveAttachment(ToolType toolType, long headerId, string dataUniqueId, string filename, object uploadedFile); - string? GetProcessDataStandardFormat(IMetrologyRepository metrologyRepository, string attachmentPath, int toolTypeId, long headerId); } \ No newline at end of file diff --git a/Tests/UnitTestExportController.cs b/Tests/UnitTestExportController.cs index a442c2a..2bd6f97 100644 --- a/Tests/UnitTestExportController.cs +++ b/Tests/UnitTestExportController.cs @@ -47,7 +47,7 @@ public class UnitTestExportController } private static HeaderCommon GetHeaderCommon() => - new() { PSN = "5008", Reactor = "61", RDS = "579487", ID = 1678209360 }; + new() { PSN = "5131", Reactor = "23", RDS = "631836", ID = 1710783849 }; private static StringContent GetStringContent() => new(System.Text.Json.JsonSerializer.Serialize(GetHeaderCommon()), Encoding.UTF8, "application/json"); diff --git a/Tests/UnitTestReactorController.cs b/Tests/UnitTestFileShareController.cs similarity index 57% rename from Tests/UnitTestReactorController.cs rename to Tests/UnitTestFileShareController.cs index 42a96aa..7cfa2ff 100644 --- a/Tests/UnitTestReactorController.cs +++ b/Tests/UnitTestFileShareController.cs @@ -1,13 +1,12 @@ using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using OI.Metrology.Shared.DataModels; using OI.Metrology.Shared.Models.Stateless; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestReactorController +public class UnitTestFileShareController { #pragma warning disable CS8618 @@ -26,7 +25,7 @@ public class UnitTestReactorController _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); - _ControllerName = nameof(Server.ApiControllers.ReactorsController)[..^10]; + _ControllerName = nameof(Server.ApiControllers.FileShareController)[..^10]; } private static void NonThrowTryCatch() @@ -40,46 +39,45 @@ public class UnitTestReactorController public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); - Assert.AreEqual(IReactorsController.GetRouteName(), _ControllerName); + Assert.AreEqual(IFileShareController.GetRouteName(), _ControllerName); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } + [Ignore] [TestMethod] - public void GetReactors() - { - _Logger?.LogInformation("Starting Web Application"); - IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; - IReactorsRepository? reactorsRepository = serviceProvider?.GetRequiredService(); - Result? result = reactorsRepository?.EvenReactors(); - Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); - NonThrowTryCatch(); - } - - [TestMethod] - public async Task GetReactorsApi() + public async Task CopyFileApi() { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); Assert.IsTrue(httpClient is not null); - string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/true/"); - File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetReactors)}.json"), json); - Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); - Assert.IsNotNull(result?.Results); + string? response = await httpClient.GetStringAsync($"api/v1/file-share/copy-file/?from=\\\\mesfs.infineon.com\\EC_Metrology_Si\\MetrologyAttachments\\CDERunHeader_\\2024\\WW11\\247233\\CDE5_240315162756858.pdsf&to=\\\\messa01ec.infineon.com\\apps\\Metrology\\MET08RESIMAPCDE\\Test\\a.pdsf"); + Assert.IsNotNull(response); + _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); + NonThrowTryCatch(); + } + + [Ignore] + [TestMethod] + public async Task MoveFileApi() + { + HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); + _Logger?.LogInformation("Starting Web Application"); + Assert.IsTrue(httpClient is not null); + string? response = await httpClient.GetStringAsync($"api/v1/file-share/move-file/?from=\\\\mesfs.infineon.com\\EC_Metrology_Si\\MetrologyAttachments\\CDERunHeader_\\2024\\WW11\\247233\\CDE5_240315162756858.pdsf&to=\\\\messa01ec.infineon.com\\apps\\Metrology\\MET08RESIMAPCDE\\Test\\a.pdsf"); + Assert.IsNotNull(response); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } [TestMethod] - public void GetKey() + public async Task FileWriteApi() { + HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; - IReactorsRepository? reactorsRepository = serviceProvider?.GetRequiredService(); - WorkMaterialOut workMaterialOut = new() { RunDataSheet = "123456", Username = "phares" }; - string? result = reactorsRepository?.GetKey(workMaterialOut, save: false); - Assert.IsNotNull(result); + Assert.IsTrue(httpClient is not null); + string? response = await httpClient.GetStringAsync($"api/v1/file-share/file-write/?path=\\\\messa01ec.infineon.com\\apps\\Metrology\\MET08RESIMAPCDE\\Test\\b.pdsf&contents=b"); + Assert.IsNotNull(response); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } diff --git a/Tests/UnitTestInfinityQSV4Controller.cs b/Tests/UnitTestInfinityQSV4Controller.cs index 70d9be6..edfb1cd 100644 --- a/Tests/UnitTestInfinityQSV4Controller.cs +++ b/Tests/UnitTestInfinityQSV4Controller.cs @@ -282,9 +282,9 @@ public class UnitTestInfinityQSV4Controller List production = new(); foreach (int rds in rdsCollection) { - + if (rds is 0) + continue; production.Add(""); - } foreach (string part in new string[] { "4992" }) { diff --git a/Tests/UnitTestToolTypesController.cs b/Tests/UnitTestToolTypesController.cs index 87b53c5..28708c3 100644 --- a/Tests/UnitTestToolTypesController.cs +++ b/Tests/UnitTestToolTypesController.cs @@ -283,7 +283,7 @@ public class UnitTestToolTypesController _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); } - [Ignore] + // [Ignore] [TestMethod] public void OIExport() { @@ -296,7 +296,7 @@ public class UnitTestToolTypesController Assert.IsTrue(appSettings is not null); Assert.IsTrue(attachmentsService is not null); Assert.IsTrue(metrologyRepository is not null); - string? message = toolTypesRepository?.OIExport(metrologyRepository, attachmentsService, appSettings.AttachmentPath, appSettings.TableToPath, toolTypeId: 1, headerid: 1); + string? message = toolTypesRepository?.OIExport(metrologyRepository, attachmentsService, toolTypeId: 1, headerid: 1); Assert.IsTrue(message is null); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); } diff --git a/Tests/UnitTestWaferCounterController.cs b/Tests/UnitTestWaferCounterController.cs index 1ba42ea..77ae2be 100644 --- a/Tests/UnitTestWaferCounterController.cs +++ b/Tests/UnitTestWaferCounterController.cs @@ -60,6 +60,10 @@ public class UnitTestWaferCounterController Assert.AreEqual("0101010101010101010101010", result); result = waferCounterRepository?.GetSlotMap("T13", "P1555555"); Assert.AreEqual("1010101010101010101010101", result); + result = waferCounterRepository?.GetSlotMap("T20", "P0EFFFF8"); + Assert.AreEqual("0111011111111111111111000", result); + result = waferCounterRepository?.GetSlotMap("T20", "P07FFFF8"); + Assert.AreEqual("0011111111111111111111000", result); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } @@ -70,7 +74,7 @@ public class UnitTestWaferCounterController _Logger?.LogInformation("Starting Web Application"); IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IWaferCounterRepository? waferCounterRepository = serviceProvider?.GetRequiredService(); - WaferCounter? result = waferCounterRepository?.GetLastQuantityAndSlotMap("EPP-East", "8INCH", "123456"); + WaferCounter? result = waferCounterRepository?.GetLastQuantityAndSlotMap("EPP-East", "8INCH"); Assert.IsNotNull(result); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); diff --git a/View/Models/Binder/AppSettings.cs b/View/Models/Binder/AppSettings.cs index 9129bcb..350a32a 100644 --- a/View/Models/Binder/AppSettings.cs +++ b/View/Models/Binder/AppSettings.cs @@ -62,7 +62,10 @@ public class AppSettings public static Models.AppSettings Get(IConfigurationRoot configurationRoot) { Models.AppSettings result; +#pragma warning disable IL3050, IL2026 AppSettings? appSettings = configurationRoot.Get(); +#pragma warning restore IL3050, IL2026 + PreVerify(configurationRoot, appSettings); result = Get(appSettings); return result; }