Better data (BioRad)
EC / IFX FromBody bug fix Made ID optional and are get all files now
This commit is contained in:
@ -9,7 +9,6 @@ namespace OI.Metrology.Server.Repository;
|
||||
public class ExportRepository : IExportRepository
|
||||
{
|
||||
|
||||
private readonly string _MockRoot;
|
||||
private readonly Serilog.ILogger _Log;
|
||||
private readonly string _RepositoryName;
|
||||
private readonly AppSettings _AppSettings;
|
||||
@ -18,7 +17,6 @@ public class ExportRepository : IExportRepository
|
||||
public ExportRepository(AppSettings appSettings)
|
||||
{
|
||||
_AppSettings = appSettings;
|
||||
_MockRoot = appSettings.MockRoot;
|
||||
_RdsToHeaderCommonCollection = new();
|
||||
_RepositoryName = nameof(ExportRepository)[..^10];
|
||||
_Log = Serilog.Log.ForContext<ExportRepository>();
|
||||
@ -41,10 +39,13 @@ public class ExportRepository : IExportRepository
|
||||
string[] weeks = Get();
|
||||
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))
|
||||
continue;
|
||||
results.AddRange(Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly));
|
||||
results.AddRange(Directory.GetFiles(directory, searchPattern, SearchOption.AllDirectories));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
@ -52,98 +53,79 @@ public class ExportRepository : IExportRepository
|
||||
string IExportRepository.GetExport(HeaderCommon headerCommon)
|
||||
{
|
||||
string result;
|
||||
if (!string.IsNullOrEmpty(_MockRoot))
|
||||
result = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), $"{_RepositoryName}-{nameof(IExportRepository.GetExport)}.txt"));
|
||||
List<string> files = GetFiles(headerCommon, "*.txt");
|
||||
if (files.Count != 1)
|
||||
result = string.Empty;
|
||||
else
|
||||
{
|
||||
List<string> files = GetFiles(headerCommon, "*.txt");
|
||||
if (files.Count != 1)
|
||||
result = string.Empty;
|
||||
else
|
||||
result = File.ReadAllText(files.First());
|
||||
}
|
||||
result = File.ReadAllText(files.First());
|
||||
return result;
|
||||
}
|
||||
|
||||
Result<HeaderCommon[]> IExportRepository.GetHeaders(HeaderCommon headerCommon)
|
||||
{
|
||||
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"));
|
||||
result = JsonSerializer.Deserialize<Result<HeaderCommon[]>>(json);
|
||||
if (result is null)
|
||||
throw new NullReferenceException(nameof(result));
|
||||
json = File.ReadAllText(file);
|
||||
jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
|
||||
if (jsonElement is null || jsonElement.Value.ValueKind != JsonValueKind.Object)
|
||||
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();
|
||||
string json;
|
||||
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,
|
||||
};
|
||||
}
|
||||
Results = results.ToArray(),
|
||||
TotalRows = results.Count,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
Result<HeaderCommon[]> IExportRepository.GetLogistics(HeaderCommon headerCommon)
|
||||
{
|
||||
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"));
|
||||
result = JsonSerializer.Deserialize<Result<HeaderCommon[]>>(json);
|
||||
if (result is null)
|
||||
throw new NullReferenceException(nameof(result));
|
||||
json = File.ReadAllText(file);
|
||||
hc = JsonSerializer.Deserialize<HeaderCommon>(json);
|
||||
if (hc is null)
|
||||
continue;
|
||||
results.Add(hc);
|
||||
}
|
||||
else
|
||||
result = new()
|
||||
{
|
||||
List<HeaderCommon> results = new();
|
||||
string json;
|
||||
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,
|
||||
};
|
||||
}
|
||||
Results = results.ToArray(),
|
||||
TotalRows = results.Count,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
string IExportRepository.GetProcessDataStandardFormat(HeaderCommon headerCommon)
|
||||
{
|
||||
string result;
|
||||
if (!string.IsNullOrEmpty(_MockRoot))
|
||||
result = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), $"{_RepositoryName}-{nameof(IExportRepository.GetProcessDataStandardFormat)}.pdsf"));
|
||||
List<string> files = GetFiles(headerCommon, "*.pdsf");
|
||||
if (files.Count != 1)
|
||||
result = string.Empty;
|
||||
else
|
||||
{
|
||||
List<string> files = GetFiles(headerCommon, "*.pdsf");
|
||||
if (files.Count != 1)
|
||||
result = string.Empty;
|
||||
else
|
||||
result = File.ReadAllText(files.First());
|
||||
}
|
||||
result = File.ReadAllText(files.First());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user