- Updated links in the following files: - Static/Metrology/AwaitingDispo/index.html - Static/Metrology/Export/index.html - Static/Metrology/RunHeaders/index.html - Static/Metrology/RunInfo/index.html - Static/Metrology/index.html - Static/RunHeaders/index.html - Static/RunInfo/index.html - Static/awaiting-disposition.html - Static/export.html - Static/files.html - Static/index.html - Static/run-headers.html Removed obsolete HTTP request files from Tests/.vscode directory. - Deleted files: - tc_col_metrology-viewer-dev.http - tc_col_metrology-viewer-v1.http - tc_col_metrology-viewer-v2.http - tc_col_metrology-viewer-v3.http - tc_col_metrology-viewer-v4.http - tc_col_metrology-viewer.http - wafer-counter.http Added new HTTP request files for development and production environments. - Added files: - api-metrology-viewer-dev.http - api-metrology-viewer.http - api-v1-InfinityQS.http - api-v1-wafer-counter.http - api-v2-InfinityQS.http - api-v3-InfinityQS.http - api-v4-InfinityQS.http Updated Unit Tests for Inbound and WaferCounter controllers to reflect changes in repository methods and test scenarios. - Modified UnitTestWaferCounterController.cs to change area and wafer size parameters. - Removed UnitInboundController.cs and added new tests for InboundController functionality. Refactored FileShareRepository and WaferCounterRepository to improve file handling and data retrieval logic. - Updated methods to handle multiple file extensions and improve error handling. - Adjusted logic for retrieving last quantity and slot map based on file type. Added static pipeline configuration for deployment. - Created static-pipeline.yml for automated deployment process.
239 lines
9.8 KiB
C#
239 lines
9.8 KiB
C#
using OI.Metrology.Shared.DataModels;
|
|
using OI.Metrology.Shared.Models;
|
|
using OI.Metrology.Shared.Models.Stateless;
|
|
using OI.Metrology.Wafer.Counter.Helper;
|
|
using OI.Metrology.Wafer.Counter.Models;
|
|
using System.Collections.ObjectModel;
|
|
using System.Globalization;
|
|
using System.Text.Json;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace OI.Metrology.Wafer.Counter.Repository;
|
|
|
|
public class WaferCounterRepository : IWaferCounterRepository
|
|
{
|
|
|
|
private record Record(int Check,
|
|
int Total,
|
|
string? SlotMap);
|
|
|
|
private readonly Regex _Regex;
|
|
private readonly string _MockRoot;
|
|
private readonly string _RepositoryName;
|
|
private readonly AppSettings _AppSettings;
|
|
private readonly IHttpClientFactory _HttpClientFactory;
|
|
private readonly IFileShareRepository _FileShareRepository;
|
|
|
|
public WaferCounterRepository(AppSettings appSettings, IHttpClientFactory httpClientFactory, IFileShareRepository fileShareRepository)
|
|
{
|
|
_AppSettings = appSettings;
|
|
_MockRoot = appSettings.MockRoot;
|
|
_HttpClientFactory = httpClientFactory;
|
|
_Regex = RegexHelper.WindowsFileSystem();
|
|
_FileShareRepository = fileShareRepository;
|
|
_RepositoryName = nameof(WaferCounterRepository)[..^10];
|
|
}
|
|
|
|
private void MoveFile(string area, string waferSize, WaferCounter? waferCounter, string windowsFileSystemSafeText, string waferSizeDirectory, NginxFileSystemSortable nginxFileSystemSortable)
|
|
{
|
|
string equipmentId = $"{area}-{waferSize}";
|
|
WaferCounterArchive waferCounterArchive = new()
|
|
{
|
|
Date = nginxFileSystemSortable.DateTime,
|
|
MesEntity = equipmentId,
|
|
RDS = windowsFileSystemSafeText,
|
|
SlotMap = waferCounter?.SlotMap,
|
|
Text = waferCounter?.Text,
|
|
Total = waferCounter?.Total,
|
|
};
|
|
Calendar calendar = new CultureInfo("en-US").Calendar;
|
|
string from = Path.Combine(waferSizeDirectory, nginxFileSystemSortable.Name);
|
|
string archive = Path.Combine(_AppSettings.EcCharacterizationSi, "Archive", equipmentId);
|
|
string weekOfYear = $"{nginxFileSystemSortable.DateTime:yyyy}_Week_{calendar.GetWeekOfYear(nginxFileSystemSortable.DateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}";
|
|
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(waferCounterArchive, WaferCounterArchiveSourceGenerationContext.Default.WaferCounterArchive);
|
|
_FileShareRepository.FileWrite(file, json);
|
|
string to = Path.Combine(directory, nginxFileSystemSortable.Name);
|
|
_FileShareRepository.MoveFile(from, to);
|
|
}
|
|
|
|
private static Record GetRecord(string line1, string line2)
|
|
{
|
|
Record result;
|
|
string? slotMap = string.IsNullOrEmpty(line2) || line2.Length != 8 ? null : line2.Substring(1, 1);
|
|
int check = slotMap == "1" ? 1 : 0;
|
|
#pragma warning disable IDE0057
|
|
int total = int.Parse(line1.Substring(1));
|
|
foreach (char item in line2.Substring(2))
|
|
#pragma warning restore IDE0057
|
|
{
|
|
switch (item)
|
|
{
|
|
case '0':
|
|
check += 0;
|
|
slotMap += "0000";
|
|
break;
|
|
case '1':
|
|
check += 1;
|
|
slotMap += "0001";
|
|
break;
|
|
case '2':
|
|
check += 1;
|
|
slotMap += "0010";
|
|
break;
|
|
case '3':
|
|
check += 2;
|
|
slotMap += "0011";
|
|
break;
|
|
case '4':
|
|
check += 1;
|
|
slotMap += "0100";
|
|
break;
|
|
case '5':
|
|
check += 2;
|
|
slotMap += "0101";
|
|
break;
|
|
case '6':
|
|
check += 2;
|
|
slotMap += "0110";
|
|
break;
|
|
case '7':
|
|
check += 3;
|
|
slotMap += "0111";
|
|
break;
|
|
case '8':
|
|
check += 1;
|
|
slotMap += "1000";
|
|
break;
|
|
case '9':
|
|
check += 2;
|
|
slotMap += "1001";
|
|
break;
|
|
case 'A':
|
|
check += 2;
|
|
slotMap += "1010";
|
|
break;
|
|
case 'B':
|
|
check += 3;
|
|
slotMap += "1011";
|
|
break;
|
|
case 'C':
|
|
check += 2;
|
|
slotMap += "1100";
|
|
break;
|
|
case 'D':
|
|
check += 3;
|
|
slotMap += "1101";
|
|
break;
|
|
case 'E':
|
|
check += 3;
|
|
slotMap += "1110";
|
|
break;
|
|
case 'F':
|
|
check += 4;
|
|
slotMap += "1111";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
result = new(check, total, slotMap);
|
|
return result;
|
|
}
|
|
|
|
private Uri GetWaferSizeUri(string area, string waferSize) =>
|
|
_FileShareRepository.Append(new Uri(_AppSettings.EcMesaFileShareCharacterizationSi), "WaferCounter", area, waferSize);
|
|
|
|
private string GetWaferSizeDirectory(string area, string waferSize, bool destination) =>
|
|
destination ? Path.Combine(_AppSettings.WaferCounterDestinationDirectory, area, waferSize) : Path.Combine(_AppSettings.EcCharacterizationSi, "WaferCounter", area, waferSize);
|
|
|
|
string? IWaferCounterRepository.GetSlotMap(string line1, string line2) =>
|
|
GetRecord(line1, line2).SlotMap;
|
|
|
|
private List<NginxFileSystemSortable> GetNginxFileSystemSortableCollection(HttpClient httpClient, Uri waferSizeUri)
|
|
{
|
|
List<NginxFileSystemSortable> results = new();
|
|
DateTime dateTime = DateTime.Now;
|
|
string[] endsWithCollection = [".wc", ".pdsf"];
|
|
ReadOnlyCollection<NginxFileSystemSortable> collection;
|
|
long ticks = dateTime.AddSeconds(_AppSettings.WaferCounterTwoFileSecondsWait).Ticks;
|
|
for (int i = 0; i < int.MaxValue; i++)
|
|
{
|
|
collection = _FileShareRepository.GetNginxFileSystemSortableCollection(httpClient, waferSizeUri, endsWithCollection);
|
|
results.AddRange(collection);
|
|
if (results.Count > 0 || DateTime.Now.Ticks > ticks)
|
|
break;
|
|
Thread.Sleep(250);
|
|
}
|
|
return results;
|
|
}
|
|
|
|
private static WaferCounter? GetLastQuantityAndSlotMap(string area, string waferSize, HttpClient httpClient, NginxFileSystemSortable nginxFileSystemSortable)
|
|
{
|
|
WaferCounter? result;
|
|
Task<string> value = httpClient.GetStringAsync(nginxFileSystemSortable.Uri);
|
|
value.Wait();
|
|
string? line1;
|
|
string? line2;
|
|
string[] lines = value.Result.Split("\r\n");
|
|
if (nginxFileSystemSortable.Name.EndsWith(".wc") && lines.Length > 2)
|
|
{
|
|
line1 = lines[^3];
|
|
line2 = lines[^2];
|
|
}
|
|
else if (nginxFileSystemSortable.Name.EndsWith(".pdsf") && lines.Length > 14)
|
|
{
|
|
line1 = lines[7].Split('\t')[^1];
|
|
line2 = lines[8].Split('\t')[^1];
|
|
}
|
|
else
|
|
{
|
|
line1 = null;
|
|
line2 = null;
|
|
}
|
|
if (string.IsNullOrEmpty(line1) || string.IsNullOrEmpty(line2))
|
|
result = WaferCounter.GetWaferCounter("Incomplete file length!");
|
|
else
|
|
{
|
|
string text = string.Empty;
|
|
Record record = GetRecord(line1, line2);
|
|
if (string.IsNullOrEmpty(record.SlotMap) || record.SlotMap.Length != 25)
|
|
result = WaferCounter.GetWaferCounter("Wrong length for slot-map!");
|
|
else
|
|
{
|
|
if (record.Total != record.Check)
|
|
result = WaferCounter.GetWaferCounter($"Checksum has failed. {record.Total} != {record.Check}");
|
|
else
|
|
result = new(DateTime: nginxFileSystemSortable.DateTime,
|
|
DateTimeFormatted: nginxFileSystemSortable.DateTime.ToString("yyyy-MM-dd hh:mm tt"),
|
|
EquipmentId: $"{area}-{waferSize}",
|
|
Message: string.Empty,
|
|
Text: text,
|
|
Total: record.Total,
|
|
SlotMap: record.SlotMap);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
WaferCounter? IWaferCounterRepository.GetLastQuantityAndSlotMap(string area, string waferSize, string text)
|
|
{
|
|
WaferCounter? result;
|
|
Uri waferSizeUri = GetWaferSizeUri(area, waferSize);
|
|
HttpClient httpClient = _HttpClientFactory.CreateClient();
|
|
string waferSizeDirectory = GetWaferSizeDirectory(area, waferSize, destination: false);
|
|
List<NginxFileSystemSortable> nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(httpClient, waferSizeUri);
|
|
if (nginxFileSystemSortableCollection.Count < 1)
|
|
result = WaferCounter.GetWaferCounter("No files!");
|
|
else
|
|
{
|
|
string windowsFileSystemSafeText = _Regex.Replace(text, ".");
|
|
result = GetLastQuantityAndSlotMap(area, waferSize, httpClient, nginxFileSystemSortableCollection[0]);
|
|
for (int i = 0; i < nginxFileSystemSortableCollection.Count; i++)
|
|
MoveFile(area, waferSize, result, windowsFileSystemSafeText, waferSizeDirectory, nginxFileSystemSortableCollection[i]);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
} |