Remove with Text
Remove GetEngineeringSpcReview Better error message EnforceCodeStyleInBuild NginxFileSystem Remove Reactors and Working Directory AppSettings Delete self contained Thunder Tests Back to .net8.0 api/v4/InfinityQS ApiExplorerSettings Wafer Counter
This commit is contained in:
@ -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<ExportRepository> _Logger;
|
||||
private readonly IHttpClientFactory _HttpClientFactory;
|
||||
private readonly IFileShareRepository _FileShareRepository;
|
||||
private readonly Dictionary<string, Dictionary<long, HeaderCommon>> _RdsToHeaderCommonCollection;
|
||||
|
||||
public ExportRepository(ILogger<ExportRepository> logger, AppSettings appSettings)
|
||||
public ExportRepository(ILogger<ExportRepository> 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<string> GetFiles(HeaderCommon headerCommon, string searchPattern)
|
||||
private NginxFileSystemSortable[] GetNginxFileSystemSortableCollection(HeaderCommon headerCommon, HttpClient httpClient, string endsWith)
|
||||
{
|
||||
List<string> results = new();
|
||||
string directory;
|
||||
List<NginxFileSystemSortable> results = new();
|
||||
Uri uri;
|
||||
string[] weeks = Get();
|
||||
List<NginxFileSystemSortable> 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<string> lines = httpResponseMessage.Content.ReadAsStringAsync();
|
||||
lines.Wait();
|
||||
result = lines.Result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
string IExportRepository.GetExport(HeaderCommon headerCommon)
|
||||
{
|
||||
string result;
|
||||
List<string> 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<string> 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<HeaderCommon>(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<HeaderCommon> results = new();
|
||||
string json;
|
||||
HeaderCommon? hc;
|
||||
List<string> 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<HeaderCommon>(json);
|
||||
if (hc is null)
|
||||
continue;
|
||||
@ -132,11 +154,9 @@ public class ExportRepository : IExportRepository
|
||||
string IExportRepository.GetProcessDataStandardFormat(HeaderCommon headerCommon)
|
||||
{
|
||||
string result;
|
||||
List<string> 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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user