Characterization Data
FI Backlog with Ignore Tag
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
using OI.Metrology.Shared.Models;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Wafer.Counter.Models;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace OI.Metrology.Wafer.Counter.Repository;
|
||||
@ -7,6 +10,11 @@ namespace OI.Metrology.Wafer.Counter.Repository;
|
||||
public class FileShareRepository : IFileShareRepository
|
||||
{
|
||||
|
||||
private readonly AppSettings _AppSettings;
|
||||
|
||||
public FileShareRepository(AppSettings appSettings) =>
|
||||
_AppSettings = appSettings;
|
||||
|
||||
Uri IFileShareRepository.Append(Uri uri, params string[] paths) =>
|
||||
new(paths.Aggregate(uri.AbsoluteUri, (current, path) =>
|
||||
string.Format("{0}/{1}", current.TrimEnd('/'), path.TrimStart('/'))));
|
||||
@ -96,4 +104,140 @@ public class FileShareRepository : IFileShareRepository
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetValidDirectories(string equipmentDirectory, DateTime startDateTime, DateTime endDateTime)
|
||||
{
|
||||
List<string> results = [equipmentDirectory];
|
||||
DateTime dateTime;
|
||||
string weekOfYear;
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
dateTime = startDateTime.AddDays(i);
|
||||
if (dateTime > endDateTime)
|
||||
break;
|
||||
weekOfYear = $"{dateTime:yyyy}_Week_{calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}";
|
||||
results.Add(Path.Combine(equipmentDirectory, weekOfYear, dateTime.ToString("yyyy-MM-dd")));
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<FileInfo> GetCollection(CharacterizationParameters characterizationParameters, string searchPattern, DateTime startDateTime, DateTime endDateTime, ReadOnlyCollection<string> validDirectories)
|
||||
{
|
||||
FileInfo[] results;
|
||||
string[] directories;
|
||||
List<FileInfo> collection = [];
|
||||
string startDateTimeTicks = startDateTime.Ticks.ToString();
|
||||
string delta = (endDateTime.Ticks - startDateTime.Ticks).ToString();
|
||||
string ticksSearchPattern = $"{startDateTime.Ticks.ToString()[..(startDateTimeTicks.Length - delta.Length + 1)]}*";
|
||||
foreach (string validDirectory in validDirectories)
|
||||
{
|
||||
if (string.IsNullOrEmpty(validDirectory) || !Directory.Exists(validDirectory))
|
||||
continue;
|
||||
if (characterizationParameters.SearchPattern is null || searchPattern == characterizationParameters.SearchPattern)
|
||||
collection.AddRange(Directory.GetFiles(validDirectory, searchPattern, SearchOption.AllDirectories).Select(l => new FileInfo(l)));
|
||||
else
|
||||
{
|
||||
directories = Directory.GetDirectories(validDirectory, ticksSearchPattern, SearchOption.AllDirectories);
|
||||
foreach (string directory in directories)
|
||||
collection.AddRange(Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly).Select(l => new FileInfo(l)));
|
||||
}
|
||||
}
|
||||
results = (from l in collection where l.LastWriteTime >= startDateTime && l.LastWriteTime <= endDateTime orderby l.LastWriteTime descending select l).ToArray();
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetDirectoryNames(string directory)
|
||||
{
|
||||
List<string> results = new();
|
||||
string? fileName;
|
||||
string? checkDirectory = directory;
|
||||
string? pathRoot = Path.GetPathRoot(directory);
|
||||
string extension = Path.GetExtension(directory);
|
||||
if (string.IsNullOrEmpty(pathRoot))
|
||||
throw new NullReferenceException(nameof(pathRoot));
|
||||
if (Directory.Exists(directory))
|
||||
{
|
||||
fileName = Path.GetFileName(directory);
|
||||
if (!string.IsNullOrEmpty(fileName))
|
||||
results.Add(fileName);
|
||||
}
|
||||
else if ((string.IsNullOrEmpty(extension) || extension.Length > 3) && !File.Exists(directory))
|
||||
{
|
||||
fileName = Path.GetFileName(directory);
|
||||
if (!string.IsNullOrEmpty(fileName))
|
||||
results.Add(fileName);
|
||||
}
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory) || checkDirectory == pathRoot)
|
||||
break;
|
||||
fileName = Path.GetFileName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
continue;
|
||||
results.Add(fileName);
|
||||
}
|
||||
results.Add(pathRoot);
|
||||
results.Reverse();
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<CharacterizationInfo> GetCharacterizationData(CharacterizationParameters characterizationParameters, string equipmentDirectory, string searchPattern)
|
||||
{
|
||||
List<CharacterizationInfo> results = [];
|
||||
string[] lines;
|
||||
string? directoryName;
|
||||
string? checkDirectory;
|
||||
CharacterizationInfo archiveInfo;
|
||||
ReadOnlyCollection<string> directoryNames;
|
||||
DateTime endDateTime = characterizationParameters.EndTime is null ? DateTime.Now : DateTime.Parse(characterizationParameters.EndTime).ToLocalTime();
|
||||
DateTime startDateTime = characterizationParameters.StartTime is null ? DateTime.Now.AddHours(-6) : DateTime.Parse(characterizationParameters.StartTime).ToLocalTime();
|
||||
ReadOnlyCollection<string> validDirectories = GetValidDirectories(equipmentDirectory, startDateTime, endDateTime);
|
||||
ReadOnlyCollection<FileInfo> collection = GetCollection(characterizationParameters, searchPattern, startDateTime, endDateTime, validDirectories);
|
||||
foreach (FileInfo fileInfo in collection)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileInfo.DirectoryName))
|
||||
continue;
|
||||
checkDirectory = fileInfo.DirectoryName;
|
||||
directoryName = Path.GetFileName(fileInfo.DirectoryName);
|
||||
directoryNames = GetDirectoryNames(fileInfo.DirectoryName);
|
||||
foreach (string _ in directoryNames)
|
||||
{
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
continue;
|
||||
if (validDirectories.Contains(checkDirectory))
|
||||
{
|
||||
directoryName = Path.GetFileName(checkDirectory);
|
||||
break;
|
||||
}
|
||||
}
|
||||
lines = File.ReadAllLines(fileInfo.FullName);
|
||||
archiveInfo = new(directoryName, fileInfo.LastWriteTime, lines);
|
||||
results.Add(archiveInfo);
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
List<CharacterizationInfo> IFileShareRepository.GetArchiveData(CharacterizationParameters characterizationParameters)
|
||||
{
|
||||
List<CharacterizationInfo> results = [];
|
||||
string searchPattern;
|
||||
string equipmentDirectory;
|
||||
if (!string.IsNullOrEmpty(characterizationParameters.Area) && !string.IsNullOrEmpty(characterizationParameters.WaferSize))
|
||||
{
|
||||
searchPattern = characterizationParameters.SearchPattern is null ? "*" : characterizationParameters.SearchPattern;
|
||||
equipmentDirectory = Path.Combine(_AppSettings.EcCharacterizationSi, "WaferCounter", characterizationParameters.Area, characterizationParameters.WaferSize);
|
||||
if (Directory.Exists(equipmentDirectory))
|
||||
results.AddRange(GetCharacterizationData(characterizationParameters, equipmentDirectory, searchPattern));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(characterizationParameters.EquipmentId))
|
||||
{
|
||||
searchPattern = "*.json";
|
||||
equipmentDirectory = Path.Combine(_AppSettings.EcCharacterizationSi, "Archive", characterizationParameters.EquipmentId);
|
||||
if (Directory.Exists(equipmentDirectory))
|
||||
results.AddRange(GetCharacterizationData(characterizationParameters, equipmentDirectory, searchPattern));
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
}
|
11
Wafer-Counter/Repositories/RegexHelper.cs
Normal file
11
Wafer-Counter/Repositories/RegexHelper.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace OI.Metrology.Wafer.Counter.Repository;
|
||||
|
||||
public partial class RegexHelper
|
||||
{
|
||||
|
||||
[GeneratedRegex(@"[\\,\/,\:,\*,\?,\"",\<,\>,\|]")]
|
||||
internal static partial Regex WindowsFileSystem();
|
||||
|
||||
}
|
@ -3,6 +3,8 @@ using OI.Metrology.Shared.Models;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Wafer.Counter.Models;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace OI.Metrology.Wafer.Counter.Repository;
|
||||
|
||||
@ -13,6 +15,7 @@ public class WaferCounterRepository : IWaferCounterRepository
|
||||
int Total,
|
||||
string? SlotMap);
|
||||
|
||||
private readonly Regex _Regex;
|
||||
private readonly string _MockRoot;
|
||||
private readonly string _RepositoryName;
|
||||
private readonly AppSettings _AppSettings;
|
||||
@ -24,19 +27,25 @@ public class WaferCounterRepository : IWaferCounterRepository
|
||||
_AppSettings = appSettings;
|
||||
_MockRoot = appSettings.MockRoot;
|
||||
_HttpClientFactory = httpClientFactory;
|
||||
_Regex = RegexHelper.WindowsFileSystem();
|
||||
_FileShareRepository = fileShareRepository;
|
||||
_RepositoryName = nameof(WaferCounterRepository)[..^10];
|
||||
}
|
||||
|
||||
private void MoveFile(string area, string waferSize, string text, string waferSizeDirectory, NginxFileSystemSortable nginxFileSystemSortable)
|
||||
private void MoveFile(string area, string waferSize, string windowsFileSystemSafeText, string waferSizeDirectory, NginxFileSystemSortable nginxFileSystemSortable)
|
||||
{
|
||||
string equipmentId = $"{area}-{waferSize}";
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
string from = Path.Combine(waferSizeDirectory, nginxFileSystemSortable.Name);
|
||||
string archive = Path.Combine(_AppSettings.EcCharacterizationSi, "Archive", $"{area}-{waferSize}");
|
||||
string archive = Path.Combine(_AppSettings.EcCharacterizationSi, "Archive", equipmentId);
|
||||
HeaderCommon headerCommon = new() { RDS = windowsFileSystemSafeText, MesEntity = equipmentId };
|
||||
string weekOfYear = $"{nginxFileSystemSortable.DateTime:yyyy}_Week_{calendar.GetWeekOfYear(nginxFileSystemSortable.DateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}";
|
||||
string to = Path.Combine(archive, weekOfYear, nginxFileSystemSortable.DateTime.ToString("yyyy-MM-dd"), nginxFileSystemSortable.Name);
|
||||
string directory = Path.Combine(archive, weekOfYear, nginxFileSystemSortable.DateTime.ToString("yyyy-MM-dd"), windowsFileSystemSafeText);
|
||||
string file = Path.Combine(directory, nginxFileSystemSortable.DateTime.Ticks.ToString(), $"{nginxFileSystemSortable.Name}.json");
|
||||
string json = JsonSerializer.Serialize(headerCommon, new JsonSerializerOptions() { WriteIndented = true });
|
||||
_FileShareRepository.FileWrite(file, json);
|
||||
string to = Path.Combine(directory, nginxFileSystemSortable.Name);
|
||||
_FileShareRepository.MoveFile(from, to);
|
||||
_FileShareRepository.FileWrite($"{to}.txt", text);
|
||||
}
|
||||
|
||||
private static Record GetRecord(string line1, string line2)
|
||||
@ -185,9 +194,10 @@ public class WaferCounterRepository : IWaferCounterRepository
|
||||
result = WaferCounter.GetWaferCounter("No files!");
|
||||
else
|
||||
{
|
||||
string windowsFileSystemSafeText = _Regex.Replace(text, ".");
|
||||
result = GetLastQuantityAndSlotMap(waferSize, httpClient, nginxFileSystemSortableCollection[0]);
|
||||
for (int i = 0; i < nginxFileSystemSortableCollection.Count; i++)
|
||||
MoveFile(area, waferSize, text, waferSizeDirectory, nginxFileSystemSortableCollection[i]);
|
||||
MoveFile(area, waferSize, windowsFileSystemSafeText, waferSizeDirectory, nginxFileSystemSortableCollection[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user