Removed HttpContext.Session

This commit is contained in:
2023-02-09 22:58:49 -07:00
parent 4514678556
commit 2481c2b3ff
6 changed files with 124 additions and 138 deletions

View File

@ -36,83 +36,106 @@ public class PinRepository : IPinRepository
}
}
Result<Pinned[]> IPinRepository.GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? rds, string? bioRad, string? cde)
private (HeaderCommon?, HeaderCommon?) GetBoth(string rds, long bioRadId, long cdeId)
{
Result<Pinned[]>? r;
HeaderCommon? cdeHeader = cde is null ? null : JsonSerializer.Deserialize<HeaderCommon>(cde);
long cdeId = cdeHeader is null ? (long)IPinRepository.ToolId.CDE : cdeHeader.ToolTypeID;
HeaderCommon? bioRadHeader = bioRad is null ? null : JsonSerializer.Deserialize<HeaderCommon>(bioRad);
long bioRadId = bioRadHeader is null ? (long)IPinRepository.ToolId.BioRad : bioRadHeader.ToolTypeID;
if (!string.IsNullOrEmpty(rds) && (cdeHeader is null || bioRadHeader is null))
HeaderCommon? cdeHeader, bioRadHeader;
cdeHeader = null;
bioRadHeader = null;
Dictionary<long, HeaderCommon>? toolIdToHeader;
if (!_RdsToHeaderCommonCollection.TryGetValue(rds, out toolIdToHeader))
{
Dictionary<long, HeaderCommon>? toolIdToHeader;
_RdsToHeaderCommonCollection.Add(rds, new());
if (!_RdsToHeaderCommonCollection.TryGetValue(rds, out toolIdToHeader))
{
_RdsToHeaderCommonCollection.Add(rds, new());
if (!_RdsToHeaderCommonCollection.TryGetValue(rds, out toolIdToHeader))
throw new Exception();
}
if (cdeHeader is null && toolIdToHeader.ContainsKey(cdeId))
cdeHeader = toolIdToHeader[cdeId];
if (bioRadHeader is null && toolIdToHeader.ContainsKey(bioRadId))
bioRadHeader = toolIdToHeader[bioRadId];
throw new Exception();
}
if (cdeId != id && bioRadId != id)
r = new() { Results = Array.Empty<Pinned>(), TotalRows = 0 };
if (cdeHeader is null && toolIdToHeader.ContainsKey(cdeId))
cdeHeader = toolIdToHeader[cdeId];
if (bioRadHeader is null && toolIdToHeader.ContainsKey(bioRadId))
bioRadHeader = toolIdToHeader[bioRadId];
return new(bioRadHeader, cdeHeader);
}
private static Pinned? GetPinned(IMetrologyRepository metrologyRepository, HeaderCommon bioRadHeader, int points, int column)
{
Pinned? result;
List<string> values;
System.Data.DataTable dataTable = metrologyRepository.GetData((int)bioRadHeader.ToolTypeID, bioRadHeader.ID);
if (dataTable.Rows.Count <= points || dataTable.Columns.Count <= column)
result = null;
else
{
if (!string.IsNullOrEmpty(_MockRoot))
values = new();
for (int i = 0; i < dataTable.Rows.Count - 1; i++)
{
string json = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), "GetPinnedTableApi.json"));
r = JsonSerializer.Deserialize<Result<Pinned[]>>(json);
if (r is null)
throw new NullReferenceException(nameof(r));
if (dataTable.Rows[i]?.ItemArray[column] is null)
break;
values.Add(string.Concat(dataTable.Rows[i].ItemArray[column]));
}
if (values.Count <= points)
result = null;
else
result = new(bioRadHeader, values);
}
return result;
}
private static Pinned? GetCDE(IMetrologyRepository metrologyRepository, int points, HeaderCommon bioRadHeader)
{
Pinned? result;
List<string> values;
const int thickness = 5;
System.Data.DataTable dataTable = metrologyRepository.GetData((int)bioRadHeader.ToolTypeID, bioRadHeader.ID);
if (dataTable.Rows.Count <= points || dataTable.Columns.Count <= thickness)
result = null;
else
{
values = new();
for (int i = 0; i < dataTable.Rows.Count - 1; i++)
{
if (dataTable.Rows[i]?.ItemArray[thickness] is null)
break;
values.Add(string.Concat(dataTable.Rows[i].ItemArray[thickness]));
}
if (values.Count <= points)
result = null;
else
result = new(bioRadHeader, values);
}
return result;
}
Result<Pinned[]> IPinRepository.GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? biorad_id, string? cde_id, string? rds)
{
Result<Pinned[]>? r;
if (!string.IsNullOrEmpty(_MockRoot))
{
string json = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), "GetPinnedTableApi.json"));
r = JsonSerializer.Deserialize<Result<Pinned[]>>(json);
if (r is null)
throw new NullReferenceException(nameof(r));
}
else
{
if (string.IsNullOrEmpty(rds) || !long.TryParse(biorad_id, out long bioRadId) || !long.TryParse(cde_id, out long cdeId))
r = new() { Results = Array.Empty<Pinned>(), TotalRows = 0 };
else
{
List<string> values;
const int points = 9;
Pinned headerCommond;
List<Pinned> results = new();
(HeaderCommon? cdeHeader, HeaderCommon? bioRadHeader) = GetBoth(rds, bioRadId, cdeId);
if (bioRadHeader is not null)
{
const int thickness = 5;
System.Data.DataTable dataTable = metrologyRepository.GetData((int)bioRadHeader.ToolTypeID, bioRadHeader.ID);
if (dataTable.Rows.Count > points && dataTable.Columns.Count > thickness)
{
values = new();
for (int i = 0; i < dataTable.Rows.Count - 1; i++)
{
if (dataTable.Rows[i]?.ItemArray[thickness] is null)
break;
values.Add(string.Concat(dataTable.Rows[i].ItemArray[thickness]));
}
if (values.Count > points)
{
headerCommond = new(bioRadHeader, values);
results.Add(headerCommond);
}
}
Pinned? pinned = GetPinned(metrologyRepository, bioRadHeader, points, column: thickness);
if (pinned is not null)
results.Add(pinned);
}
if (cdeHeader is not null)
{
const int rs = 6;
System.Data.DataTable dataTable = metrologyRepository.GetData((int)cdeHeader.ToolTypeID, cdeHeader.ID);
if (dataTable.Rows.Count > points && dataTable.Columns.Count > rs)
{
values = new();
for (int i = 0; i < dataTable.Rows.Count - 1; i++)
{
if (dataTable.Rows[i]?.ItemArray[rs] is null)
break;
values.Add(string.Concat(dataTable.Rows[i].ItemArray[rs]));
}
if (values.Count > points)
{
headerCommond = new(cdeHeader, values);
results.Add(headerCommond);
}
}
Pinned? pinned = GetPinned(metrologyRepository, cdeHeader, points, column: rs);
if (pinned is not null)
results.Add(pinned);
}
r = new()
{