Bug fix: Attachment
This commit is contained in:
@ -85,50 +85,28 @@ public class AttachmentsService : IAttachmentsService
|
||||
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();
|
||||
if (string.IsNullOrWhiteSpace(attachment.UniqueId))
|
||||
{
|
||||
throw new NullReferenceException($"{nameof(attachment.UniqueId)}");
|
||||
if (attachment.DestinationFileName != "Image.pdf")
|
||||
_MetrologyRepository.SetHeaderAttachmentID(toolType.ID, attachment.HeaderId.Value, attachment.AttachmentId);
|
||||
insertDate = Convert.ToDateTime(_MetrologyRepository.GetHeaderInsertDate(toolType.ID, attachment.HeaderId.Value));
|
||||
tableName = toolType.HeaderTableName;
|
||||
}
|
||||
else
|
||||
{
|
||||
_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(attachment.AttachmentId, Guid.Empty))
|
||||
{
|
||||
trans.Dispose();
|
||||
throw new Exception("Invalid attachment ID!");
|
||||
}
|
||||
const string asdf = "\\asdf\asdf";
|
||||
int weekNum = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(insertDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
|
||||
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!");
|
||||
}
|
||||
trans.Complete();
|
||||
}
|
||||
|
||||
string? IAttachmentsService.GetProcessDataStandardFormat(IMetrologyRepository metrologyRepository, int toolTypeId, long headerId)
|
||||
{
|
||||
string? result;
|
||||
int weekNum;
|
||||
string file;
|
||||
string year;
|
||||
string directory;
|
||||
Task<string> json;
|
||||
Uri weekDirectory;
|
||||
Uri checkDirectory;
|
||||
List<string> files = new();
|
||||
string[] collection = ["-", string.Empty];
|
||||
NginxFileSystem[]? nginxFileSystemCollection;
|
||||
Task<HttpResponseMessage> httpResponseMessage;
|
||||
HttpClient httpClient = _HttpClientFactory.CreateClient();
|
||||
@ -137,21 +115,32 @@ public class AttachmentsService : IAttachmentsService
|
||||
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);
|
||||
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)
|
||||
continue;
|
||||
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);
|
||||
foreach (string item in collection)
|
||||
{
|
||||
year = dateTime.Year.ToString();
|
||||
weekNum = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
|
||||
weekDirectory = _FileShareRepository.Append(mesaFileShareMetrologySi, "MetrologyAttachments", $"{toolType.HeaderTableName}_", year, $"WW{weekNum:00}");
|
||||
checkDirectory = _FileShareRepository.Append(weekDirectory, $"{item}{headerId}");
|
||||
directory = Path.Combine(_AppSettings.EcMetrologySi, "MetrologyAttachments", $"{toolType.HeaderTableName}_", year, $"WW{weekNum:00}", $"{item}{headerId}");
|
||||
httpResponseMessage = httpClient.GetAsync(checkDirectory);
|
||||
httpResponseMessage.Wait();
|
||||
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
continue;
|
||||
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)
|
||||
{
|
||||
if (!nginxFileSystem.Name.EndsWith(".pdsf"))
|
||||
continue;
|
||||
file = Path.Combine(directory, nginxFileSystem.Name);
|
||||
files.Add(file);
|
||||
}
|
||||
if (files.Count != 0)
|
||||
break;
|
||||
}
|
||||
if (files.Count != 0)
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user