Better data (BioRad)

EC / IFX
FromBody bug fix
Made ID optional and are get all files now
This commit is contained in:
Mike Phares 2023-03-08 12:47:22 -07:00
parent de048b6842
commit 8040a7c6b5
6 changed files with 248 additions and 87 deletions

View File

@ -152,7 +152,7 @@
"params": [], "params": [],
"body": { "body": {
"type": "json", "type": "json",
"raw": "{\n \"PSN\": \"5296\",\n \"RDS\": \"578280\",\n \"Reactor\": \"37\",\n \"ID\": 1678216576\n}", "raw": "{\n \"PSN\": \"4698\",\n \"RDS\": \"578824\",\n \"Reactor\": \"62\",\n \"ID\": 1678296039\n}",
"form": [] "form": []
}, },
"tests": [] "tests": []
@ -166,12 +166,12 @@
"method": "POST", "method": "POST",
"sortNum": 0, "sortNum": 0,
"created": "2023-03-07T17:21:05.219Z", "created": "2023-03-07T17:21:05.219Z",
"modified": "2023-03-08T16:39:11.451Z", "modified": "2023-03-08T18:18:04.054Z",
"headers": [], "headers": [],
"params": [], "params": [],
"body": { "body": {
"type": "json", "type": "json",
"raw": "{\n \"MesEntity\": \"CDE5\",\n \"Employee\": \"Operator\",\n \"Layer\": \"-\",\n \"PSN\": \"5008\",\n \"RDS\": \"579487\",\n \"Reactor\": \"61\",\n \"Recipe\": \"LSL8IN \\\\ 10PT_5mm\",\n \"Zone\": \"-\",\n \"Ticks\": 638137811504314166,\n \"ID\": 1678209360\n}", "raw": "{\n \"PSN\": \"4698\",\n \"RDS\": \"578824\",\n \"Reactor\": \"62\",\n \"ID\": 1678296039\n}",
"form": [] "form": []
}, },
"tests": [] "tests": []
@ -185,12 +185,12 @@
"method": "GET", "method": "GET",
"sortNum": 0, "sortNum": 0,
"created": "2023-03-07T17:21:05.219Z", "created": "2023-03-07T17:21:05.219Z",
"modified": "2023-03-08T16:05:18.727Z", "modified": "2023-03-08T19:05:54.744Z",
"headers": [], "headers": [],
"params": [], "params": [],
"body": { "body": {
"type": "json", "type": "json",
"raw": "{\n \"MesEntity\": \"CDE5\",\n \"Employee\": \"Operator\",\n \"Layer\": \"-\",\n \"PSN\": \"5008\",\n \"RDS\": \"579487\",\n \"Reactor\": \"61\",\n \"Recipe\": \"LSL8IN \\\\ 10PT_5mm\",\n \"Zone\": \"-\",\n \"Ticks\": 638137811504314166,\n \"ID\": 1678209360\n}", "raw": "{\n \"PSN\": \"4698\",\n \"RDS\": \"578824\",\n \"Reactor\": \"62\",\n \"ID\": -1678296039\n}",
"form": [] "form": []
}, },
"tests": [] "tests": []

View File

@ -5,5 +5,19 @@
"created": "2023-02-27T20:07:11.913Z", "created": "2023-02-27T20:07:11.913Z",
"sortNum": 10000, "sortNum": 10000,
"folders": [] "folders": []
},
{
"_id": "fb96b15a-0cc4-48c7-8767-34f1242750e8",
"colName": "Export EC",
"created": "2023-03-08T17:16:29.420Z",
"sortNum": 20000,
"folders": []
},
{
"_id": "5bfd00bc-b58c-49d3-9f27-5acadd060a51",
"colName": "Export IFX",
"created": "2023-03-08T17:31:19.468Z",
"sortNum": 30000,
"folders": []
} }
] ]

View File

@ -265,5 +265,157 @@
"value": "2" "value": "2"
} }
] ]
},
{
"_id": "0aafd6ed-26a6-4a07-825c-8c1fee603b6a",
"colId": "fb96b15a-0cc4-48c7-8767-34f1242750e8",
"containerId": "",
"name": "GetHeaders",
"url": "https://oi-metrology-viewer-prod.mes.infineon.com/api/export/headers",
"method": "GET",
"sortNum": 10000,
"created": "2023-03-08T17:16:56.561Z",
"modified": "2023-03-08T17:17:39.783Z",
"headers": [],
"params": [],
"body": {
"type": "json",
"raw": "{\n \"PSN\": \"4698\",\n \"RDS\": \"578824\",\n \"Reactor\": \"62\",\n \"ID\": 1678296039\n}",
"form": []
},
"tests": []
},
{
"_id": "af298148-482d-4822-80ba-1abb86e1f9c2",
"colId": "fb96b15a-0cc4-48c7-8767-34f1242750e8",
"containerId": "",
"name": "GetExport",
"url": "https://oi-metrology-viewer-prod.mes.infineon.com/api/export/export",
"method": "GET",
"sortNum": 15000,
"created": "2023-03-08T17:17:47.597Z",
"modified": "2023-03-08T17:19:13.764Z",
"headers": [],
"params": [],
"body": {
"type": "json",
"raw": "{\n \"PSN\": \"4698\",\n \"RDS\": \"578824\",\n \"Reactor\": \"62\",\n \"ID\": 1678296039\n}",
"form": []
},
"tests": []
},
{
"_id": "a787c81d-381e-451d-9d96-e607f06efdaf",
"colId": "fb96b15a-0cc4-48c7-8767-34f1242750e8",
"containerId": "",
"name": "GetLogistics",
"url": "https://oi-metrology-viewer-prod.mes.infineon.com/api/export/logistics",
"method": "GET",
"sortNum": 30000,
"created": "2023-03-08T17:18:38.179Z",
"modified": "2023-03-08T17:19:21.874Z",
"headers": [],
"params": [],
"body": {
"type": "json",
"raw": "{\n \"PSN\": \"4698\",\n \"RDS\": \"578824\",\n \"Reactor\": \"62\",\n \"ID\": 1678296039\n}",
"form": []
},
"tests": []
},
{
"_id": "7e19c7d4-2d93-46e1-88fd-ba5312885713",
"colId": "fb96b15a-0cc4-48c7-8767-34f1242750e8",
"containerId": "",
"name": "GetProcessDataStandardFormat",
"url": "https://oi-metrology-viewer-prod.mes.infineon.com/api/export/pdsf",
"method": "GET",
"sortNum": 40000,
"created": "2023-03-08T17:18:49.042Z",
"modified": "2023-03-08T17:19:27.119Z",
"headers": [],
"params": [],
"body": {
"type": "json",
"raw": "{\n \"PSN\": \"4698\",\n \"RDS\": \"578824\",\n \"Reactor\": \"62\",\n \"ID\": 1678296039\n}",
"form": []
},
"tests": []
},
{
"_id": "25eb571f-064c-4b3f-8c20-666c66c1b123",
"colId": "5bfd00bc-b58c-49d3-9f27-5acadd060a51",
"containerId": "",
"name": "GetHeaders",
"url": "https://mestsa008.infineon.com:50302/api/export/headers",
"method": "GET",
"sortNum": 10000,
"created": "2023-03-08T17:31:19.471Z",
"modified": "2023-03-08T18:48:51.819Z",
"headers": [],
"params": [],
"body": {
"type": "json",
"raw": "{\n \"PSN\": \"4698\",\n \"RDS\": \"578824\",\n \"Reactor\": \"62\",\n \"ID\": 1678296039\n}",
"form": []
},
"tests": []
},
{
"_id": "f5feb8e3-0e82-4b47-a15e-97ef069a1539",
"colId": "5bfd00bc-b58c-49d3-9f27-5acadd060a51",
"containerId": "",
"name": "GetExport",
"url": "https://mestsa008.infineon.com:50302/api/export/export",
"method": "GET",
"sortNum": 15000,
"created": "2023-03-08T17:31:19.472Z",
"modified": "2023-03-08T17:31:19.472Z",
"headers": [],
"params": [],
"body": {
"type": "json",
"raw": "{\n \"PSN\": \"4698\",\n \"RDS\": \"578824\",\n \"Reactor\": \"62\",\n \"ID\": 1678296039\n}",
"form": []
},
"tests": []
},
{
"_id": "7fddba99-14a2-4c6a-bf4a-4b94391929cf",
"colId": "5bfd00bc-b58c-49d3-9f27-5acadd060a51",
"containerId": "",
"name": "GetLogistics",
"url": "https://mestsa008.infineon.com:50302/api/export/logistics",
"method": "GET",
"sortNum": 30000,
"created": "2023-03-08T17:31:19.473Z",
"modified": "2023-03-08T17:31:19.473Z",
"headers": [],
"params": [],
"body": {
"type": "json",
"raw": "{\n \"PSN\": \"4698\",\n \"RDS\": \"578824\",\n \"Reactor\": \"62\",\n \"ID\": 1678296039\n}",
"form": []
},
"tests": []
},
{
"_id": "07d5b0c3-684a-4cad-8a48-b164e8da87b0",
"colId": "5bfd00bc-b58c-49d3-9f27-5acadd060a51",
"containerId": "",
"name": "GetProcessDataStandardFormat",
"url": "https://mestsa008.infineon.com:50302/api/export/pdsf",
"method": "GET",
"sortNum": 40000,
"created": "2023-03-08T17:31:19.474Z",
"modified": "2023-03-08T17:31:19.474Z",
"headers": [],
"params": [],
"body": {
"type": "json",
"raw": "{\n \"PSN\": \"4698\",\n \"RDS\": \"578824\",\n \"Reactor\": \"62\",\n \"ID\": 1678296039\n}",
"form": []
},
"tests": []
} }
] ]

View File

@ -15,20 +15,28 @@ public class ExportController : Controller, IExportController<IActionResult>
public ExportController(IExportRepository exportRepository) => public ExportController(IExportRepository exportRepository) =>
_ExportRepository = exportRepository; _ExportRepository = exportRepository;
private static HeaderCommon GetHeaderCommon(Stream stream) private static string? GetJson(Stream stream)
{ {
HeaderCommon? result; string? result;
if (!stream.CanRead) if (!stream.CanRead)
result = new(); result = null;
else else
{ {
Task<string> task = new StreamReader(stream).ReadToEndAsync(); Task<string> task = new StreamReader(stream).ReadToEndAsync();
result = string.IsNullOrEmpty(task.Result) ? null : JsonSerializer.Deserialize<HeaderCommon>(task.Result); result = task.Result;
result ??= new();
} }
return result; return result;
} }
private static HeaderCommon GetHeaderCommon(Stream stream)
{
HeaderCommon? result;
string? json = GetJson(stream);
result = string.IsNullOrEmpty(json) ? null : JsonSerializer.Deserialize<HeaderCommon>(json);
result ??= new();
return result;
}
[HttpGet] [HttpGet]
[Route("export")] [Route("export")]
public IActionResult GetExport() => public IActionResult GetExport() =>

View File

@ -30,18 +30,23 @@ public partial class InboundController : ControllerBase, IInboundController<IAct
_MetrologyRepository = metrologyRepository; _MetrologyRepository = metrologyRepository;
} }
private static JToken GetJToken(Stream stream) private static string? GetJson(Stream stream)
{ {
JToken jsonbody; string? result;
if (!stream.CanRead) if (!stream.CanRead)
jsonbody = JToken.Parse("{}"); result = null;
else else
{ {
if (stream.CanSeek) Task<string> task = new StreamReader(stream).ReadToEndAsync();
_ = stream.Seek(0, SeekOrigin.Begin); result = task.Result;
string json = new StreamReader(stream).ReadToEnd();
jsonbody = JToken.Parse(json);
} }
return result;
}
private static JToken GetJToken(Stream stream)
{
string? json = GetJson(stream);
JToken jsonbody = string.IsNullOrEmpty(json) ? JToken.Parse("{}") : JToken.Parse(json);
return jsonbody; return jsonbody;
} }

View File

@ -9,7 +9,6 @@ namespace OI.Metrology.Server.Repository;
public class ExportRepository : IExportRepository public class ExportRepository : IExportRepository
{ {
private readonly string _MockRoot;
private readonly Serilog.ILogger _Log; private readonly Serilog.ILogger _Log;
private readonly string _RepositoryName; private readonly string _RepositoryName;
private readonly AppSettings _AppSettings; private readonly AppSettings _AppSettings;
@ -18,7 +17,6 @@ public class ExportRepository : IExportRepository
public ExportRepository(AppSettings appSettings) public ExportRepository(AppSettings appSettings)
{ {
_AppSettings = appSettings; _AppSettings = appSettings;
_MockRoot = appSettings.MockRoot;
_RdsToHeaderCommonCollection = new(); _RdsToHeaderCommonCollection = new();
_RepositoryName = nameof(ExportRepository)[..^10]; _RepositoryName = nameof(ExportRepository)[..^10];
_Log = Serilog.Log.ForContext<ExportRepository>(); _Log = Serilog.Log.ForContext<ExportRepository>();
@ -41,10 +39,13 @@ public class ExportRepository : IExportRepository
string[] weeks = Get(); string[] weeks = Get();
foreach (string weekYear in weeks) foreach (string weekYear in weeks)
{ {
directory = Path.Combine(_AppSettings.ApiExportPath, weekYear, $"-{headerCommon.PSN}", $"-{headerCommon.Reactor}", $"-{headerCommon.RDS}", $"-{headerCommon.ID}"); if (headerCommon.ID < 1)
directory = Path.Combine(_AppSettings.ApiExportPath, weekYear, $"-{headerCommon.PSN}", $"-{headerCommon.Reactor}", $"-{headerCommon.RDS}");
else
directory = Path.Combine(_AppSettings.ApiExportPath, weekYear, $"-{headerCommon.PSN}", $"-{headerCommon.Reactor}", $"-{headerCommon.RDS}", $"-{headerCommon.ID}");
if (!Directory.Exists(directory)) if (!Directory.Exists(directory))
continue; continue;
results.AddRange(Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly)); results.AddRange(Directory.GetFiles(directory, searchPattern, SearchOption.AllDirectories));
} }
return results; return results;
} }
@ -52,98 +53,79 @@ public class ExportRepository : IExportRepository
string IExportRepository.GetExport(HeaderCommon headerCommon) string IExportRepository.GetExport(HeaderCommon headerCommon)
{ {
string result; string result;
if (!string.IsNullOrEmpty(_MockRoot)) List<string> files = GetFiles(headerCommon, "*.txt");
result = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), $"{_RepositoryName}-{nameof(IExportRepository.GetExport)}.txt")); if (files.Count != 1)
result = string.Empty;
else else
{ result = File.ReadAllText(files.First());
List<string> files = GetFiles(headerCommon, "*.txt");
if (files.Count != 1)
result = string.Empty;
else
result = File.ReadAllText(files.First());
}
return result; return result;
} }
Result<HeaderCommon[]> IExportRepository.GetHeaders(HeaderCommon headerCommon) Result<HeaderCommon[]> IExportRepository.GetHeaders(HeaderCommon headerCommon)
{ {
Result<HeaderCommon[]>? result; Result<HeaderCommon[]>? result;
if (!string.IsNullOrEmpty(_MockRoot)) List<HeaderCommon> results = new();
string json;
HeaderCommon? hc;
string ticks = "Ticks";
JsonElement? jsonElement;
JsonProperty[] jsonProperties;
List<string> files = GetFiles(headerCommon, "*.json");
foreach (string file in files)
{ {
string json = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), $"{_RepositoryName}-{nameof(IExportRepository.GetHeaders)}.json")); json = File.ReadAllText(file);
result = JsonSerializer.Deserialize<Result<HeaderCommon[]>>(json); jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
if (result is null) if (jsonElement is null || jsonElement.Value.ValueKind != JsonValueKind.Object)
throw new NullReferenceException(nameof(result)); continue;
jsonProperties = (from l in jsonElement.Value.EnumerateObject() where l.Name == ticks select l).ToArray();
if (!jsonProperties.Any() || !long.TryParse(jsonProperties[0].Value.ToString(), out long ticksValue))
continue;
hc = JsonSerializer.Deserialize<HeaderCommon>(json);
if (hc is null)
continue;
hc.ID = ticksValue;
hc.Date = new(ticksValue);
results.Add(hc);
} }
else result = new()
{ {
List<HeaderCommon> results = new(); Results = results.ToArray(),
string json; TotalRows = results.Count,
HeaderCommon? hc; };
List<string> files = GetFiles(headerCommon, "*.json");
foreach (string file in files)
{
json = File.ReadAllText(file);
hc = JsonSerializer.Deserialize<HeaderCommon>(json);
if (hc is null)
continue;
results.Add(hc);
}
result = new()
{
Results = results.ToArray(),
TotalRows = results.Count,
};
}
return result; return result;
} }
Result<HeaderCommon[]> IExportRepository.GetLogistics(HeaderCommon headerCommon) Result<HeaderCommon[]> IExportRepository.GetLogistics(HeaderCommon headerCommon)
{ {
Result<HeaderCommon[]>? result; Result<HeaderCommon[]>? result;
if (!string.IsNullOrEmpty(_MockRoot)) List<HeaderCommon> results = new();
string json;
HeaderCommon? hc;
List<string> files = GetFiles(headerCommon, "*.json");
foreach (string file in files)
{ {
string json = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), $"{_RepositoryName}-{nameof(IExportRepository.GetLogistics)}.json")); json = File.ReadAllText(file);
result = JsonSerializer.Deserialize<Result<HeaderCommon[]>>(json); hc = JsonSerializer.Deserialize<HeaderCommon>(json);
if (result is null) if (hc is null)
throw new NullReferenceException(nameof(result)); continue;
results.Add(hc);
} }
else result = new()
{ {
List<HeaderCommon> results = new(); Results = results.ToArray(),
string json; TotalRows = results.Count,
HeaderCommon? hc; };
List<string> files = GetFiles(headerCommon, "*.json");
foreach (string file in files)
{
json = File.ReadAllText(file);
hc = JsonSerializer.Deserialize<HeaderCommon>(json);
if (hc is null)
continue;
results.Add(hc);
}
result = new()
{
Results = results.ToArray(),
TotalRows = results.Count,
};
}
return result; return result;
} }
string IExportRepository.GetProcessDataStandardFormat(HeaderCommon headerCommon) string IExportRepository.GetProcessDataStandardFormat(HeaderCommon headerCommon)
{ {
string result; string result;
if (!string.IsNullOrEmpty(_MockRoot)) List<string> files = GetFiles(headerCommon, "*.pdsf");
result = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), $"{_RepositoryName}-{nameof(IExportRepository.GetProcessDataStandardFormat)}.pdsf")); if (files.Count != 1)
result = string.Empty;
else else
{ result = File.ReadAllText(files.First());
List<string> files = GetFiles(headerCommon, "*.pdsf");
if (files.Count != 1)
result = string.Empty;
else
result = File.ReadAllText(files.First());
}
return result; return result;
} }