PDSF (Process Data Standard Format) to use EAF for
pushing to OI
This commit is contained in:
@ -27,14 +27,12 @@ public class AttachmentsService : IAttachmentsService
|
||||
throw new NullReferenceException(nameof(tableName));
|
||||
|
||||
DateTime insertDate = Convert.ToDateTime(_MetrologyRepository.GetAttachmentInsertDateByGUID(tableName, attachmentId));
|
||||
int year = insertDate.Year;
|
||||
DateTime d = insertDate;
|
||||
CultureInfo cul = CultureInfo.CurrentCulture;
|
||||
int weekNum = cul.Calendar.GetWeekOfYear(d, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
|
||||
string workWeek = "WW" + weekNum.ToString("00");
|
||||
string dateDir = year + @"\" + workWeek;
|
||||
|
||||
string fullPath = Path.Combine(_AppSettings.AttachmentPath, tableName + "_", dateDir, attachmentId.ToString(), filename);
|
||||
string year = insertDate.Year.ToString();
|
||||
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))
|
||||
@ -48,7 +46,7 @@ public class AttachmentsService : IAttachmentsService
|
||||
return new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
}
|
||||
|
||||
public Stream GetAttachmentStreamByTitle(ToolType toolType, bool header, string title, string filename)
|
||||
Stream IAttachmentsService.GetAttachmentStreamByTitle(ToolType toolType, bool header, string title, string filename)
|
||||
{
|
||||
if (toolType is null)
|
||||
throw new Exception("Invalid tool type");
|
||||
@ -67,7 +65,7 @@ public class AttachmentsService : IAttachmentsService
|
||||
return GetAttachmentStream(tableName, attachmentId, filename);
|
||||
}
|
||||
|
||||
public Stream GetAttachmentStreamByAttachmentId(ToolType toolType, bool header, Guid attachmentId, string filename)
|
||||
Stream IAttachmentsService.GetAttachmentStreamByAttachmentId(ToolType toolType, bool header, Guid attachmentId, string filename)
|
||||
{
|
||||
if (toolType is null)
|
||||
throw new Exception("Invalid tool type");
|
||||
@ -94,7 +92,6 @@ public class AttachmentsService : IAttachmentsService
|
||||
attachmentId = _MetrologyRepository.GetHeaderAttachmentID(toolType.ID, headerId);
|
||||
insertDate = Convert.ToDateTime(_MetrologyRepository.GetHeaderInsertDate(toolType.ID, headerId));
|
||||
tableName = toolType.HeaderTableName;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -102,37 +99,55 @@ public class AttachmentsService : IAttachmentsService
|
||||
insertDate = Convert.ToDateTime(_MetrologyRepository.GetDataInsertDate(toolType.ID, headerId, dataUniqueId));
|
||||
// Get Date for new directory name
|
||||
tableName = toolType.DataTableName;
|
||||
|
||||
}
|
||||
|
||||
int year = insertDate.Year;
|
||||
DateTime d = insertDate;
|
||||
CultureInfo cul = CultureInfo.CurrentCulture;
|
||||
|
||||
int weekNum = cul.Calendar.GetWeekOfYear(d, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
|
||||
|
||||
string workWeek = "WW" + weekNum.ToString("00");
|
||||
string dateDir = year + @"\" + workWeek;
|
||||
|
||||
if (Equals(attachmentId, Guid.Empty))
|
||||
throw new Exception("Invalid attachment ID");
|
||||
string directoryPathSecondary = Path.Combine(_AppSettings.AttachmentPath, tableName + "_", dateDir, attachmentId.ToString());
|
||||
if (!Directory.Exists(directoryPathSecondary))
|
||||
_ = Directory.CreateDirectory(directoryPathSecondary);
|
||||
|
||||
string fullPathSecondary = Path.Combine(directoryPathSecondary, filename);
|
||||
string year = insertDate.Year.ToString();
|
||||
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);
|
||||
|
||||
using (FileStream s = new(fullPathSecondary, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
|
||||
{
|
||||
uploadedFile.CopyTo(s);
|
||||
}
|
||||
string fullPath = Path.Combine(directory, filename);
|
||||
|
||||
using (FileStream fileStream = new(fullPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
|
||||
uploadedFile.CopyTo(fileStream);
|
||||
trans.Complete();
|
||||
}
|
||||
|
||||
public void SaveAttachment(ToolType toolType, long headerId, string dataUniqueId, string filename, object uploadedFile)
|
||||
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, string attachmentPath, int toolTypeId, long headerId)
|
||||
{
|
||||
string? result;
|
||||
string year;
|
||||
int weekNum;
|
||||
string directory;
|
||||
string checkDirectory;
|
||||
List<string> files = new();
|
||||
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))
|
||||
continue;
|
||||
files.AddRange(Directory.GetFiles(checkDirectory));
|
||||
if (files.Any())
|
||||
break;
|
||||
}
|
||||
result = !files.Any() ? null : files.First();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user