Changed path and Changed seconds to Alpha
This commit is contained in:
parent
c655ed5c6b
commit
2f3f1b7947
@ -1,6 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace OI.Metrology.Server.ApiControllers;
|
||||
@ -19,35 +18,7 @@ public class ReactorsController : Controller, IReactorsController<IActionResult>
|
||||
Json(even ? _ReactorsRepository.EvenReactors() : _ReactorsRepository.OddReactors(), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
[HttpPost()]
|
||||
public IActionResult Post(Shared.DataModels.WorkMaterialOut workMaterialOut)
|
||||
{
|
||||
string? result = null;
|
||||
if (workMaterialOut is null)
|
||||
throw new Exception();
|
||||
if (workMaterialOut.Username is null || workMaterialOut.Username.Length < 2)
|
||||
throw new ArgumentException(nameof(workMaterialOut.Username));
|
||||
if (workMaterialOut.RunDataSheet is null || workMaterialOut.RunDataSheet.Length < 2)
|
||||
throw new ArgumentException(nameof(workMaterialOut.RunDataSheet));
|
||||
string? fileName = null;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
string json = JsonSerializer.Serialize(workMaterialOut, new JsonSerializerOptions { WriteIndented = true });
|
||||
string weekOfYear = $"{dateTime:yyyy}_Week_{calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}";
|
||||
string directory = Path.Combine("D:/Tmp/Metrology", weekOfYear, dateTime.ToString("yyyy-MM-dd"));
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
for (int i = 1; i < int.MaxValue; i++)
|
||||
{
|
||||
result = $"{workMaterialOut.Username.ToUpper()[0]}{dateTime:mmss}";
|
||||
fileName = Path.Combine(directory, $"WMO-{result}.json");
|
||||
if (!System.IO.File.Exists(fileName))
|
||||
break;
|
||||
dateTime = dateTime.AddSeconds(i);
|
||||
}
|
||||
if (fileName is null)
|
||||
throw new Exception();
|
||||
System.IO.File.WriteAllText(fileName, json);
|
||||
return Ok(result);
|
||||
}
|
||||
public IActionResult Post(Shared.DataModels.WorkMaterialOut workMaterialOut) =>
|
||||
Ok(_ReactorsRepository.GetKey(workMaterialOut, save: true));
|
||||
|
||||
}
|
@ -40,9 +40,9 @@ public class ExportRepository : IExportRepository
|
||||
foreach (string weekYear in weeks)
|
||||
{
|
||||
if (headerCommon.ID < 1)
|
||||
directory = Path.Combine(_AppSettings.ApiExportPath, weekYear, $"-{headerCommon.PSN}", $"-{headerCommon.Reactor}", $"-{headerCommon.RDS}");
|
||||
directory = Path.Combine(_AppSettings.ApiExportPath, "Archive", "API", weekYear, $"-{headerCommon.PSN}", $"-{headerCommon.Reactor}", $"-{headerCommon.RDS}");
|
||||
else
|
||||
directory = Path.Combine(_AppSettings.ApiExportPath, weekYear, $"-{headerCommon.PSN}", $"-{headerCommon.Reactor}", $"-{headerCommon.RDS}", $"-{headerCommon.ID}");
|
||||
directory = Path.Combine(_AppSettings.ApiExportPath, "Archive", "API", weekYear, $"-{headerCommon.PSN}", $"-{headerCommon.Reactor}", $"-{headerCommon.RDS}", $"-{headerCommon.ID}");
|
||||
if (!Directory.Exists(directory))
|
||||
continue;
|
||||
results.AddRange(Directory.GetFiles(directory, searchPattern, SearchOption.AllDirectories));
|
||||
|
@ -1,11 +1,30 @@
|
||||
using OI.Metrology.Server.Models;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace OI.Metrology.Server.Repository;
|
||||
|
||||
public class ReactorsRepository : IReactorsRepository
|
||||
{
|
||||
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly Dictionary<int, char> _SecondsToAlpha;
|
||||
|
||||
public ReactorsRepository(AppSettings appSettings)
|
||||
{
|
||||
_AppSettings = appSettings;
|
||||
_SecondsToAlpha = new();
|
||||
for (int i = 65; i < 91; i++)
|
||||
{
|
||||
if (i is 73 or 79)
|
||||
continue;
|
||||
_SecondsToAlpha.Add(i - 65, (char)i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result<int[]> IReactorsRepository.EvenReactors()
|
||||
{
|
||||
Result<int[]> results;
|
||||
@ -87,4 +106,41 @@ public class ReactorsRepository : IReactorsRepository
|
||||
return results;
|
||||
}
|
||||
|
||||
string? IReactorsRepository.GetKey(WorkMaterialOut workMaterialOut, bool save)
|
||||
{
|
||||
if (workMaterialOut is null)
|
||||
throw new Exception();
|
||||
if (workMaterialOut.Username is null || workMaterialOut.Username.Length < 2)
|
||||
throw new ArgumentException(nameof(workMaterialOut.Username));
|
||||
if (workMaterialOut.RunDataSheet is null || workMaterialOut.RunDataSheet.Length < 2)
|
||||
throw new ArgumentException(nameof(workMaterialOut.RunDataSheet));
|
||||
string? result = null;
|
||||
char c;
|
||||
string? fileName = null;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
string json = JsonSerializer.Serialize(workMaterialOut, new JsonSerializerOptions { WriteIndented = true });
|
||||
string weekOfYear = $"{dateTime:yyyy}_Week_{calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}";
|
||||
string directory = Path.Combine(_AppSettings.ApiExportPath, "WorkMaterialOut", "API", weekOfYear, dateTime.ToString("yyyy-MM-dd_HH"));
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
dateTime = dateTime.AddSeconds(i);
|
||||
if (!_SecondsToAlpha.TryGetValue(dateTime.Second, out c))
|
||||
continue;
|
||||
fileName = Path.Combine(directory, $"WMO-{dateTime:mm}{c}.json");
|
||||
if (!File.Exists(fileName))
|
||||
{
|
||||
result = $"{c}{dateTime:mm}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fileName is null)
|
||||
throw new Exception();
|
||||
if (save)
|
||||
File.WriteAllText(fileName, json);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"ApiExportPath": "\\\\messdv002.na.infineon.com\\Candela\\Archive\\API",
|
||||
"ApiExportPath": "\\\\messdv002.na.infineon.com\\Candela",
|
||||
"ApiUrl": "~/api",
|
||||
"ConnectionString": "Data Source=MESSAD1001\\TEST1,59583;Integrated Security=True;Initial Catalog=Metrology;",
|
||||
"IsDevelopment": true,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"AllowedHosts": "*",
|
||||
"ApiExportPath": "\\\\messv02ecc1.ec.local\\EC_Metrology_Si\\Archive\\API",
|
||||
"ApiExportPath": "\\\\messv02ecc1.ec.local\\EC_Metrology_Si",
|
||||
"ApiLoggingContentTypes": "application/json",
|
||||
"ApiLoggingPathPrefixes": "/api/inbound",
|
||||
"ApiUrl": "~/api",
|
||||
|
@ -8,5 +8,6 @@ public interface IReactorsRepository
|
||||
|
||||
Result<int[]> EvenReactors();
|
||||
Result<int[]> OddReactors();
|
||||
string? GetKey(WorkMaterialOut workMaterialOut, bool save);
|
||||
|
||||
}
|
@ -69,4 +69,17 @@ public class UnitTestReactorController
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetKey()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IReactorsRepository reactorsRepository = serviceProvider.GetRequiredService<IReactorsRepository>();
|
||||
WorkMaterialOut workMaterialOut = new() { RunDataSheet = "123456", Username = "phares" };
|
||||
string? result = reactorsRepository.GetKey(workMaterialOut, save: false);
|
||||
Assert.IsNotNull(result);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user