Files
oi-metrology/Server/Repositories/FileShareRepository.cs
phares@iscn5cg20977xq 8e294ab83f Refactor navigation links in Metrology static pages to update "FI Backlog" to "Reporting Services" with new URL.
- 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.
2025-09-03 08:13:35 -07:00

111 lines
5.0 KiB
C#

using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Models;
using OI.Metrology.Shared.Models.Stateless;
using System.Collections.ObjectModel;
using System.Text.Json;
using System.Web;
namespace OI.Metrology.Server.Repository;
public class FileShareRepository : IFileShareRepository
{
Uri IFileShareRepository.Append(Uri uri, params string[] paths) =>
new(paths.Aggregate(uri.AbsoluteUri, (current, path) => string.Format("{0}/{1}", current.TrimEnd('/'), path.TrimStart('/'))));
private Uri GetEndPoint(HttpClient httpClient, string method)
{
Uri result;
if (httpClient.BaseAddress is null)
throw new NullReferenceException(nameof(httpClient.BaseAddress));
IFileShareRepository fileShareRepository = this;
result = fileShareRepository.Append(httpClient.BaseAddress, "api", "v1", "file-share", method);
return result;
}
void IFileShareRepository.CopyFile(string from, string to)
{
string directory = Path.GetDirectoryName(to) ?? throw new NullReferenceException();
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
File.Copy(from, to);
}
void IFileShareRepository.MoveFile(string from, string to)
{
string directory = Path.GetDirectoryName(to) ?? throw new NullReferenceException();
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
if (File.Exists(to))
File.Move(to, $"{to}.{DateTime.Now.Ticks}.old");
File.Move(from, to);
}
void IFileShareRepository.FileWrite(string path, string contents)
{
string directory = Path.GetDirectoryName(path) ?? throw new NullReferenceException();
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
File.WriteAllText(path, contents);
}
void IFileShareRepository.CopyFile(HttpClient httpClient, string from, string to)
{
Uri uri = GetEndPoint(httpClient, "copy-file");
string encodedTo = HttpUtility.UrlEncode(to);
string encodedFrom = HttpUtility.UrlEncode(from);
Task<HttpResponseMessage> httpResponseMessage = httpClient.GetAsync($"{uri.OriginalString}?from={encodedFrom}&to={encodedTo}");
httpResponseMessage.Wait();
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception(httpResponseMessage.Result.StatusCode.ToString());
}
void IFileShareRepository.MoveFile(HttpClient httpClient, string from, string to)
{
Uri uri = GetEndPoint(httpClient, "move-file");
string encodedTo = HttpUtility.UrlEncode(to);
string encodedFrom = HttpUtility.UrlEncode(from);
Task<HttpResponseMessage> httpResponseMessage = httpClient.GetAsync($"{uri.OriginalString}?from={encodedFrom}&to={encodedTo}");
httpResponseMessage.Wait();
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception(httpResponseMessage.Result.StatusCode.ToString());
}
HttpResponseMessage IFileShareRepository.ReadFile(HttpClient httpClient, Uri uri)
{
HttpResponseMessage result;
Task<HttpResponseMessage> httpResponseMessage = httpClient.GetAsync(uri);
httpResponseMessage.Wait();
result = httpResponseMessage.Result;
return result;
}
ReadOnlyCollection<NginxFileSystemSortable> IFileShareRepository.GetNginxFileSystemSortableCollection(HttpClient httpClient, Uri uri, string[] endsWithCollection)
{
List<NginxFileSystemSortable> results = new();
Task<HttpResponseMessage> httpResponseMessage = httpClient.GetAsync(uri);
httpResponseMessage.Wait();
if (httpResponseMessage.Result.StatusCode == System.Net.HttpStatusCode.OK)
{
FileShareRepository fileShareRepository = this;
Task<string> json = httpResponseMessage.Result.Content.ReadAsStringAsync();
json.Wait();
NginxFileSystem[]? nginxFileSystemCollection = JsonSerializer.Deserialize(json.Result, NginxFileSystemCollectionSourceGenerationContext.Default.NginxFileSystemArray);
List<NginxFileSystemSortable> nginxFileSystemSortableCollection = NginxFileSystemSortable.Convert(fileShareRepository, uri, nginxFileSystemCollection);
foreach (NginxFileSystemSortable nginxFileSystemSortable in nginxFileSystemSortableCollection.OrderByDescending(l => l.DateTime))
{
if (!endsWithCollection.Any(l => string.IsNullOrEmpty(l) && !nginxFileSystemSortable.Name.EndsWith(l)))
continue;
results.Add(nginxFileSystemSortable);
}
}
return new(results);
}
ReadOnlyCollection<CharacterizationInfo> IFileShareRepository.GetArchiveData(CharacterizationParameters archiveParameters) =>
throw new NotImplementedException();
ReadOnlyCollection<ToolTypeNameId> IFileShareRepository.GetEquipmentIds() =>
throw new NotImplementedException();
}