Separated Wafer-Counter

JsonElement instead of Request body
Attachment Class
Bump
Ready to test GetLastGroupIdWithValue
Changed to v4
This commit is contained in:
2024-05-21 12:40:20 -07:00
parent 5c9f0d1aff
commit 6317c385f6
38 changed files with 1231 additions and 476 deletions

View File

@ -39,7 +39,7 @@ public class AttachmentsService : IAttachmentsService
HttpClient httpClient = _HttpClientFactory.CreateClient();
Uri mesaFileShareMetrologySi = new(_AppSettings.EcMesaFileShareMetrologySi);
int weekNum = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(insertDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
Uri uri = _FileShareRepository.Append(mesaFileShareMetrologySi, $"{tableName}_", year, $"WW{weekNum:00}", attachmentId.ToString(), filename);
Uri uri = _FileShareRepository.Append(mesaFileShareMetrologySi, "MetrologyAttachments", $"{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!");
@ -77,54 +77,49 @@ public class AttachmentsService : IAttachmentsService
return GetAttachmentStream(tableName, attachmentId, filename);
}
private void SaveAttachment(ToolType toolType, long headerId, string dataUniqueId, string filename, IFormFile uploadedFile)
void IAttachmentsService.SaveAttachment(ToolType toolType, Attachment attachment)
{
if (toolType is null)
throw new Exception("Invalid tool type");
if (attachment.HeaderId is null)
throw new NullReferenceException($"{nameof(attachment.HeaderId)}");
if (attachment.AttachmentId is null)
throw new NullReferenceException($"{nameof(attachment.AttachmentId)}");
if (attachment.SourceFileName is null)
throw new NullReferenceException($"{nameof(attachment.SourceFileName)}");
if (attachment.DestinationFileName is null)
throw new NullReferenceException($"{nameof(attachment.DestinationFileName)}");
string? tableName;
DateTime insertDate;
using System.Transactions.TransactionScope trans = _MetrologyRepository.StartTransaction();
Guid attachmentId = Guid.Empty;
DateTime insertDate = new();
string? tableName = "";
if (string.IsNullOrWhiteSpace(dataUniqueId))
if (string.IsNullOrWhiteSpace(attachment.UniqueId))
{
attachmentId = _MetrologyRepository.GetHeaderAttachmentID(toolType.ID, headerId);
insertDate = Convert.ToDateTime(_MetrologyRepository.GetHeaderInsertDate(toolType.ID, headerId));
_MetrologyRepository.SetHeaderAttachmentID(toolType.ID, attachment.HeaderId.Value, attachment.AttachmentId);
insertDate = Convert.ToDateTime(_MetrologyRepository.GetHeaderInsertDate(toolType.ID, attachment.HeaderId.Value));
tableName = toolType.HeaderTableName;
}
else
{
attachmentId = _MetrologyRepository.GetDataAttachmentID(toolType.ID, headerId, dataUniqueId);
insertDate = Convert.ToDateTime(_MetrologyRepository.GetDataInsertDate(toolType.ID, headerId, dataUniqueId));
// Get Date for new directory name
_MetrologyRepository.SetDataAttachmentID(toolType.ID, attachment.HeaderId.Value, attachment.UniqueId, attachment.AttachmentId);
insertDate = Convert.ToDateTime(_MetrologyRepository.GetDataInsertDate(toolType.ID, attachment.HeaderId.Value, attachment.UniqueId));
tableName = toolType.DataTableName;
}
if (Equals(attachmentId, Guid.Empty))
if (Equals(attachment.AttachmentId, Guid.Empty))
{
trans.Dispose();
throw new Exception("Invalid attachment ID!");
}
string year = insertDate.Year.ToString();
HttpClient httpClient = _HttpClientFactory.CreateClient();
Uri mesaFileShareMetrologySi = new(_AppSettings.EcMesaFileShareMetrologySi);
const string asdf = "\\asdf\asdf";
int weekNum = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(insertDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
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)
string checkPath = Path.Combine(asdf, $"{tableName}_", insertDate.Year.ToString(), $"WW{weekNum:00}", attachment.AttachmentId.ToString(), attachment.DestinationFileName);
if (!attachment.SourceFileName.EndsWith(checkPath[asdf.Length..]))
{
trans.Dispose();
throw new Exception("Invalid attachment path!");
}
uploadedFile.CopyTo(httpResponseMessage.Content.ReadAsStream());
trans.Complete();
}
void IAttachmentsService.SaveAttachment(ToolType toolType, long headerId, string dataUniqueId, string filename, object uploadedFile)
{
IFormFile formFile = (IFormFile)uploadedFile;
SaveAttachment(toolType, headerId, dataUniqueId, filename, formFile);
}
string? IAttachmentsService.GetProcessDataStandardFormat(IMetrologyRepository metrologyRepository, int toolTypeId, long headerId)
{
string? result;
@ -144,8 +139,8 @@ public class AttachmentsService : IAttachmentsService
{
year = dateTime.Year.ToString();
weekNum = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
weekDirectory = _FileShareRepository.Append(mesaFileShareMetrologySi, $"{toolType.HeaderTableName}_", year, $"WW{weekNum:00}");
checkDirectory = _FileShareRepository.Append(weekDirectory, headerId.ToString());
weekDirectory = _FileShareRepository.Append(mesaFileShareMetrologySi, "MetrologyAttachments", $"{toolType.HeaderTableName}_", year, $"WW{weekNum:00}");
checkDirectory = _FileShareRepository.Append(weekDirectory, $"-{headerId}");
httpResponseMessage = httpClient.GetAsync(checkDirectory);
httpResponseMessage.Wait();
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)