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:
@ -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<string> json;
|
||||
Uri weekDirectory;
|
||||
Uri checkDirectory;
|
||||
List<string> files = new();
|
||||
NginxFileSystem[]? nginxFileSystemCollection;
|
||||
Task<HttpResponseMessage> 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user