Bug fix: Attachment
This commit is contained in:
parent
6317c385f6
commit
f53ae8c1c8
@ -13,6 +13,7 @@ public record AppSettings(string ApiFileShare,
|
|||||||
string EcCharacterizationSi,
|
string EcCharacterizationSi,
|
||||||
string EcMesaFileShareCharacterizationSi,
|
string EcMesaFileShareCharacterizationSi,
|
||||||
string EcMesaFileShareMetrologySi,
|
string EcMesaFileShareMetrologySi,
|
||||||
|
string EcMetrologySi,
|
||||||
string GitCommitSeven,
|
string GitCommitSeven,
|
||||||
string InboundApiAllowedIPList,
|
string InboundApiAllowedIPList,
|
||||||
string IqsColumns,
|
string IqsColumns,
|
||||||
|
@ -17,6 +17,7 @@ public class AppSettings
|
|||||||
public string? EcCharacterizationSi { get; set; }
|
public string? EcCharacterizationSi { get; set; }
|
||||||
public string? EcMesaFileShareCharacterizationSi { get; set; }
|
public string? EcMesaFileShareCharacterizationSi { get; set; }
|
||||||
public string? EcMesaFileShareMetrologySi { get; set; }
|
public string? EcMesaFileShareMetrologySi { get; set; }
|
||||||
|
public string? EcMetrologySi { get; set; }
|
||||||
public string? GitCommitSeven { get; set; }
|
public string? GitCommitSeven { get; set; }
|
||||||
public string? InboundApiAllowedIPList { get; set; }
|
public string? InboundApiAllowedIPList { get; set; }
|
||||||
public string? IqsColumns { get; set; }
|
public string? IqsColumns { get; set; }
|
||||||
@ -74,6 +75,7 @@ public class AppSettings
|
|||||||
if (appSettings.EcCharacterizationSi is null) throw new NullReferenceException(nameof(EcCharacterizationSi));
|
if (appSettings.EcCharacterizationSi is null) throw new NullReferenceException(nameof(EcCharacterizationSi));
|
||||||
if (appSettings.EcMesaFileShareCharacterizationSi is null) throw new NullReferenceException(nameof(EcMesaFileShareCharacterizationSi));
|
if (appSettings.EcMesaFileShareCharacterizationSi is null) throw new NullReferenceException(nameof(EcMesaFileShareCharacterizationSi));
|
||||||
if (appSettings.EcMesaFileShareMetrologySi is null) throw new NullReferenceException(nameof(EcMesaFileShareMetrologySi));
|
if (appSettings.EcMesaFileShareMetrologySi is null) throw new NullReferenceException(nameof(EcMesaFileShareMetrologySi));
|
||||||
|
if (appSettings.EcMetrologySi is null) throw new NullReferenceException(nameof(EcMetrologySi));
|
||||||
if (appSettings.GitCommitSeven is null) throw new NullReferenceException(nameof(GitCommitSeven));
|
if (appSettings.GitCommitSeven is null) throw new NullReferenceException(nameof(GitCommitSeven));
|
||||||
if (appSettings.InboundApiAllowedIPList is null) throw new NullReferenceException(nameof(InboundApiAllowedIPList));
|
if (appSettings.InboundApiAllowedIPList is null) throw new NullReferenceException(nameof(InboundApiAllowedIPList));
|
||||||
if (appSettings.IqsColumns is null) throw new NullReferenceException(nameof(IqsColumns));
|
if (appSettings.IqsColumns is null) throw new NullReferenceException(nameof(IqsColumns));
|
||||||
@ -104,6 +106,7 @@ public class AppSettings
|
|||||||
appSettings.EcCharacterizationSi,
|
appSettings.EcCharacterizationSi,
|
||||||
appSettings.EcMesaFileShareCharacterizationSi,
|
appSettings.EcMesaFileShareCharacterizationSi,
|
||||||
appSettings.EcMesaFileShareMetrologySi,
|
appSettings.EcMesaFileShareMetrologySi,
|
||||||
|
appSettings.EcMetrologySi,
|
||||||
appSettings.GitCommitSeven,
|
appSettings.GitCommitSeven,
|
||||||
appSettings.InboundApiAllowedIPList,
|
appSettings.InboundApiAllowedIPList,
|
||||||
appSettings.IqsColumns,
|
appSettings.IqsColumns,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using OI.Metrology.Shared.Models;
|
using OI.Metrology.Shared.Models;
|
||||||
using OI.Metrology.Shared.Models.Stateless;
|
using OI.Metrology.Shared.Models.Stateless;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
namespace OI.Metrology.Server.Repository;
|
namespace OI.Metrology.Server.Repository;
|
||||||
|
|
||||||
@ -49,7 +50,9 @@ public class FileShareRepository : IFileShareRepository
|
|||||||
void IFileShareRepository.CopyFile(HttpClient httpClient, string from, string to)
|
void IFileShareRepository.CopyFile(HttpClient httpClient, string from, string to)
|
||||||
{
|
{
|
||||||
Uri uri = GetEndPoint(httpClient, "copy-file");
|
Uri uri = GetEndPoint(httpClient, "copy-file");
|
||||||
Task<HttpResponseMessage> httpResponseMessage = httpClient.GetAsync(uri);
|
string encodedTo = HttpUtility.UrlEncode(to);
|
||||||
|
string encodedFrom = HttpUtility.UrlEncode(from);
|
||||||
|
Task<HttpResponseMessage> httpResponseMessage = httpClient.GetAsync($"{uri.OriginalString}?from={encodedFrom}&to={encodedTo}");
|
||||||
httpResponseMessage.Wait();
|
httpResponseMessage.Wait();
|
||||||
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
|
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
|
||||||
throw new Exception(httpResponseMessage.Result.StatusCode.ToString());
|
throw new Exception(httpResponseMessage.Result.StatusCode.ToString());
|
||||||
@ -58,7 +61,9 @@ public class FileShareRepository : IFileShareRepository
|
|||||||
void IFileShareRepository.MoveFile(HttpClient httpClient, string from, string to)
|
void IFileShareRepository.MoveFile(HttpClient httpClient, string from, string to)
|
||||||
{
|
{
|
||||||
Uri uri = GetEndPoint(httpClient, "move-file");
|
Uri uri = GetEndPoint(httpClient, "move-file");
|
||||||
Task<HttpResponseMessage> httpResponseMessage = httpClient.GetAsync(uri);
|
string encodedTo = HttpUtility.UrlEncode(to);
|
||||||
|
string encodedFrom = HttpUtility.UrlEncode(from);
|
||||||
|
Task<HttpResponseMessage> httpResponseMessage = httpClient.GetAsync($"{uri.OriginalString}?from={encodedFrom}&to={encodedTo}");
|
||||||
httpResponseMessage.Wait();
|
httpResponseMessage.Wait();
|
||||||
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
|
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
|
||||||
throw new Exception(httpResponseMessage.Result.StatusCode.ToString());
|
throw new Exception(httpResponseMessage.Result.StatusCode.ToString());
|
||||||
|
@ -85,50 +85,28 @@ public class AttachmentsService : IAttachmentsService
|
|||||||
throw new NullReferenceException($"{nameof(attachment.HeaderId)}");
|
throw new NullReferenceException($"{nameof(attachment.HeaderId)}");
|
||||||
if (attachment.AttachmentId is null)
|
if (attachment.AttachmentId is null)
|
||||||
throw new NullReferenceException($"{nameof(attachment.AttachmentId)}");
|
throw new NullReferenceException($"{nameof(attachment.AttachmentId)}");
|
||||||
if (attachment.SourceFileName is null)
|
|
||||||
throw new NullReferenceException($"{nameof(attachment.SourceFileName)}");
|
|
||||||
if (attachment.DestinationFileName is null)
|
if (attachment.DestinationFileName is null)
|
||||||
throw new NullReferenceException($"{nameof(attachment.DestinationFileName)}");
|
throw new NullReferenceException($"{nameof(attachment.DestinationFileName)}");
|
||||||
string? tableName;
|
|
||||||
DateTime insertDate;
|
|
||||||
using System.Transactions.TransactionScope trans = _MetrologyRepository.StartTransaction();
|
|
||||||
if (string.IsNullOrWhiteSpace(attachment.UniqueId))
|
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);
|
_MetrologyRepository.SetHeaderAttachmentID(toolType.ID, attachment.HeaderId.Value, attachment.AttachmentId);
|
||||||
insertDate = Convert.ToDateTime(_MetrologyRepository.GetHeaderInsertDate(toolType.ID, attachment.HeaderId.Value));
|
|
||||||
tableName = toolType.HeaderTableName;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
_MetrologyRepository.SetDataAttachmentID(toolType.ID, attachment.HeaderId.Value, attachment.UniqueId, attachment.AttachmentId);
|
_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? IAttachmentsService.GetProcessDataStandardFormat(IMetrologyRepository metrologyRepository, int toolTypeId, long headerId)
|
||||||
{
|
{
|
||||||
string? result;
|
string? result;
|
||||||
int weekNum;
|
int weekNum;
|
||||||
|
string file;
|
||||||
string year;
|
string year;
|
||||||
|
string directory;
|
||||||
Task<string> json;
|
Task<string> json;
|
||||||
Uri weekDirectory;
|
Uri weekDirectory;
|
||||||
Uri checkDirectory;
|
Uri checkDirectory;
|
||||||
List<string> files = new();
|
List<string> files = new();
|
||||||
|
string[] collection = ["-", string.Empty];
|
||||||
NginxFileSystem[]? nginxFileSystemCollection;
|
NginxFileSystem[]? nginxFileSystemCollection;
|
||||||
Task<HttpResponseMessage> httpResponseMessage;
|
Task<HttpResponseMessage> httpResponseMessage;
|
||||||
HttpClient httpClient = _HttpClientFactory.CreateClient();
|
HttpClient httpClient = _HttpClientFactory.CreateClient();
|
||||||
@ -137,21 +115,32 @@ public class AttachmentsService : IAttachmentsService
|
|||||||
ToolType toolType = metrologyRepository.GetToolTypeByID(toolTypeId) ?? throw new Exception("Invalid tool type ID");
|
ToolType toolType = metrologyRepository.GetToolTypeByID(toolTypeId) ?? throw new Exception("Invalid tool type ID");
|
||||||
foreach (DateTime dateTime in dateTimes)
|
foreach (DateTime dateTime in dateTimes)
|
||||||
{
|
{
|
||||||
year = dateTime.Year.ToString();
|
foreach (string item in collection)
|
||||||
weekNum = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
|
{
|
||||||
weekDirectory = _FileShareRepository.Append(mesaFileShareMetrologySi, "MetrologyAttachments", $"{toolType.HeaderTableName}_", year, $"WW{weekNum:00}");
|
year = dateTime.Year.ToString();
|
||||||
checkDirectory = _FileShareRepository.Append(weekDirectory, $"-{headerId}");
|
weekNum = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
|
||||||
httpResponseMessage = httpClient.GetAsync(checkDirectory);
|
weekDirectory = _FileShareRepository.Append(mesaFileShareMetrologySi, "MetrologyAttachments", $"{toolType.HeaderTableName}_", year, $"WW{weekNum:00}");
|
||||||
httpResponseMessage.Wait();
|
checkDirectory = _FileShareRepository.Append(weekDirectory, $"{item}{headerId}");
|
||||||
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
|
directory = Path.Combine(_AppSettings.EcMetrologySi, "MetrologyAttachments", $"{toolType.HeaderTableName}_", year, $"WW{weekNum:00}", $"{item}{headerId}");
|
||||||
continue;
|
httpResponseMessage = httpClient.GetAsync(checkDirectory);
|
||||||
json = httpResponseMessage.Result.Content.ReadAsStringAsync();
|
httpResponseMessage.Wait();
|
||||||
json.Wait();
|
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
|
||||||
nginxFileSystemCollection = JsonSerializer.Deserialize(json.Result, NginxFileSystemCollectionSourceGenerationContext.Default.NginxFileSystemArray);
|
continue;
|
||||||
if (nginxFileSystemCollection is null)
|
json = httpResponseMessage.Result.Content.ReadAsStringAsync();
|
||||||
continue;
|
json.Wait();
|
||||||
foreach (NginxFileSystem nginxFileSystem in nginxFileSystemCollection)
|
nginxFileSystemCollection = JsonSerializer.Deserialize(json.Result, NginxFileSystemCollectionSourceGenerationContext.Default.NginxFileSystemArray);
|
||||||
files.Add(_FileShareRepository.Append(checkDirectory, nginxFileSystem.Name).AbsoluteUri);
|
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)
|
if (files.Count != 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user