Removed HttpContext.Session
This commit is contained in:
parent
4514678556
commit
2481c2b3ff
@ -9,13 +9,11 @@ using System.Text.Json;
|
||||
public class PinController : Controller, IPinController<IActionResult>
|
||||
{
|
||||
|
||||
private readonly ILogger _Logger;
|
||||
private readonly IPinRepository _PinRepository;
|
||||
private readonly IMetrologyRepository _MetrologyRepository;
|
||||
|
||||
public PinController(ILogger<InboundController> logger, IMetrologyRepository metrologyRepository, IPinRepository pinRepository)
|
||||
{
|
||||
_Logger = logger;
|
||||
_MetrologyRepository = metrologyRepository;
|
||||
_PinRepository = pinRepository;
|
||||
}
|
||||
@ -23,23 +21,13 @@ public class PinController : Controller, IPinController<IActionResult>
|
||||
[HttpPost("/api/pin/markAsPinned")]
|
||||
public IActionResult MarkAsPinned(Shared.DataModels.HeaderCommon headerCommon)
|
||||
{
|
||||
string toolTypeId = headerCommon.ToolTypeID.ToString();
|
||||
string json = JsonSerializer.Serialize(headerCommon, new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
string? was = HttpContext.Session.GetString(toolTypeId);
|
||||
if (was is not null)
|
||||
_Logger.LogDebug($"{toolTypeId} was: {was}");
|
||||
HttpContext.Session.SetString(toolTypeId, json);
|
||||
_PinRepository.SetPinnedTable(headerCommon);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id}/pinned/{rds}")]
|
||||
public IActionResult GetPinnedTable(int id, string rds = "")
|
||||
{
|
||||
string? cde = HttpContext.Session.GetString(((int)IPinRepository.ToolId.CDE).ToString());
|
||||
string? bioRad = HttpContext.Session.GetString(((int)IPinRepository.ToolId.BioRad).ToString());
|
||||
return Json(_PinRepository.GetPinnedTable(_MetrologyRepository, id, rds, bioRad, cde), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
}
|
||||
[Route("{id}/pinned")]
|
||||
public IActionResult GetPinnedTable(int id, string? biorad_id = null, string? cde_id = null, string? rds = null) =>
|
||||
Json(_PinRepository.GetPinnedTable(_MetrologyRepository, id, biorad_id, cde_id, rds), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
}
|
@ -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()
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"ApiUrl": "http://messa010ec.ec.local:50301/api",
|
||||
"ConnectionString": "Data Source=MESSAD1001\\TEST1,59583;Integrated Security=True;Initial Catalog=Metrology;",
|
||||
"IsDevelopment": true,
|
||||
"xMockRoot": "/Data/Tests",
|
||||
"ApiUrl": "http://messa010ec.ec.local:50301/api",
|
||||
"MockRoot": "",
|
||||
"MonAResource": "OI_Metrology_Viewer_IFX",
|
||||
"Oi2SqlConnectionString": "Data Source=MESSAD1001\\TEST1,59583;Initial Catalog=LSL2SQL;Persist Security Info=True;User ID=srpadmin;Password=0okm9ijn;",
|
||||
|
@ -1,8 +1,10 @@
|
||||
var _CdeId = null;
|
||||
var _apiUrl = null;
|
||||
var _initialHeaderAttachmentId = null;
|
||||
var _initialHeaderId = null;
|
||||
var _BioRadId = null;
|
||||
var _toolType = null;
|
||||
var _initialHeaderId = null;
|
||||
var _toolTypeMetaData = null;
|
||||
var _initialHeaderAttachmentId = null;
|
||||
|
||||
$(document).ready(function () {
|
||||
if (location.pathname == "/") {
|
||||
@ -67,13 +69,15 @@ function initExport(apiUrl, startTimeValue, endTimeValue) {
|
||||
_apiUrl = apiUrl;
|
||||
var endTime = new Date(endTimeValue);
|
||||
var startTime = new Date(startTimeValue);
|
||||
$("#ToolType").igCombo({
|
||||
dataSource: _apiUrl + '/tooltypes',
|
||||
responseDataKey: "Results",
|
||||
textKey: "ToolTypeName",
|
||||
valueKey: "ID",
|
||||
mode: "dropdown",
|
||||
width: 150
|
||||
$.getJSON(_apiUrl + '/tooltypes', function (data) {
|
||||
$("#ToolType").igCombo({
|
||||
dataSource: data,
|
||||
responseDataKey: "Results",
|
||||
textKey: "ToolTypeName",
|
||||
valueKey: "ID",
|
||||
mode: "dropdown",
|
||||
width: 150
|
||||
});
|
||||
});
|
||||
$("#StartDateControl").igDatePicker({
|
||||
dateInputFormat: "date",
|
||||
@ -174,19 +178,6 @@ function loadRunInfoRunHeaders() {
|
||||
|
||||
function initRunHeaders(apiUrl) {
|
||||
_apiUrl = apiUrl;
|
||||
// $("#ToolType").igCombo({
|
||||
// dataSource: _apiUrl + '/tooltypes',
|
||||
// responseDataKey: "Results",
|
||||
// textKey: "ToolTypeName",
|
||||
// valueKey: "ID",
|
||||
// mode: "dropdown",
|
||||
// width: 150,
|
||||
// dataBound: function (evt, ui) {
|
||||
// $("#ToolType").igCombo("index", 0);
|
||||
// loadHeaderGridRunHeaders();
|
||||
// },
|
||||
// selectionChanged: loadHeaderGridRunHeaders,
|
||||
// });
|
||||
loadHeaderGridRunHeaders();
|
||||
$("#RefreshButton").click(function () {
|
||||
$("#HeaderGrid").igGrid("dataBind");
|
||||
@ -480,21 +471,7 @@ function pinButtonRunInfo() {
|
||||
success: function (e) {
|
||||
DisplayWSMessage("info", "Marked as pinned", e);
|
||||
$("#PinButton").prop("disabled", false);
|
||||
// $.ajax({
|
||||
// type: "GET",
|
||||
// url: _apiUrl + "/pin/" + toolTypeID + "/pinned",
|
||||
// success: function (r) {
|
||||
// if ((r.Results == null) || (r.Results.HeaderId == null))
|
||||
// DisplayWSMessage("error", "B) There was an error getting pinned info.");
|
||||
// else
|
||||
// DisplayWSMessage("info", r.Results.HeaderId);
|
||||
// },
|
||||
// error: function (e) {
|
||||
// DisplayWSMessage("error", "There was an error getting pinned info.", e);
|
||||
// }
|
||||
// });
|
||||
// $.getJSON(_apiUrl + "/awaitingdispo/", function (data) {
|
||||
$.getJSON(_apiUrl + "/pin/" + rowData.ToolTypeID + "/pinned?rds=" + rowData.RDS, function (data) {
|
||||
$.getJSON(_apiUrl + "/pin/" + rowData.ToolTypeID + "/pinned?biorad_id=" + _BioRadId + "&cde_id=" + _CdeId + "&rds=" + rowData.RDS, function (data) {
|
||||
$("#PinnedGrid").igGrid({
|
||||
dataSource: data,
|
||||
responseDataKey: "Results",
|
||||
@ -555,18 +532,28 @@ function initRunInfo(apiUrl, initialToolTypeID, initialHeaderId, initialHeaderAt
|
||||
_apiUrl = apiUrl;
|
||||
_initialHeaderId = initialHeaderId;
|
||||
_initialHeaderAttachmentId = initialHeaderAttachmentId;
|
||||
$("#ToolType").igCombo({
|
||||
dataSource: _apiUrl + '/tooltypes',
|
||||
responseDataKey: "Results",
|
||||
textKey: "ToolTypeName",
|
||||
valueKey: "ID",
|
||||
mode: "dropdown",
|
||||
width: 150,
|
||||
itemsRendered: function (evt, ui) {
|
||||
loadHeaderGridRunInfo();
|
||||
},
|
||||
selectionChanged: loadHeaderGridRunInfo,
|
||||
initialSelectedItems: [{ value: initialToolTypeID }]
|
||||
$.getJSON(_apiUrl + '/tooltypes', function (data) {
|
||||
for (var i = 0; i < data.Results.length; i++) {
|
||||
if (data.Results[i].ToolTypeName === "CDE") {
|
||||
_CdeId = data.Results[i].ID;
|
||||
}
|
||||
else if (data.Results[i].ToolTypeName === "BioRad") {
|
||||
_BioRadId = data.Results[i].ID;
|
||||
}
|
||||
}
|
||||
$("#ToolType").igCombo({
|
||||
dataSource: data,
|
||||
responseDataKey: "Results",
|
||||
textKey: "ToolTypeName",
|
||||
valueKey: "ID",
|
||||
mode: "dropdown",
|
||||
width: 150,
|
||||
itemsRendered: function (evt, ui) {
|
||||
loadHeaderGridRunInfo();
|
||||
},
|
||||
selectionChanged: loadHeaderGridRunInfo,
|
||||
initialSelectedItems: [{ value: initialToolTypeID }]
|
||||
});
|
||||
});
|
||||
setInitialDateTimesRunInfo();
|
||||
$("#HeaderGrid").on("dblclick", "tr", loadDetailsRunInfo);
|
||||
|
@ -5,17 +5,7 @@ namespace OI.Metrology.Shared.Models.Stateless;
|
||||
public interface IPinRepository
|
||||
{
|
||||
|
||||
enum ToolId
|
||||
{
|
||||
BioRad = 1,
|
||||
CDE = 2,
|
||||
Tencor = 3,
|
||||
HgCV = 4,
|
||||
Stratus = 5,
|
||||
SP1 = 6,
|
||||
}
|
||||
|
||||
Result<Pinned[]> GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? rds, string? bioRad, string? cde);
|
||||
Result<Pinned[]> GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? biorad_id, string? cde_id, string? rds);
|
||||
void SetPinnedTable(HeaderCommon headerCommon);
|
||||
|
||||
|
||||
}
|
@ -43,9 +43,7 @@ public class UnitTestPinController
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IPinRepository pinRepository = serviceProvider.GetRequiredService<IPinRepository>();
|
||||
string? cde = System.Text.Json.JsonSerializer.Serialize(new HeaderCommon { ID = 196984, ToolTypeID = 2 });
|
||||
string? bioRad = System.Text.Json.JsonSerializer.Serialize(new HeaderCommon { ID = 321568, ToolTypeID = 1 });
|
||||
Result<Pinned[]> result = pinRepository.GetPinnedTable(metrologyRepository, id: 1, rds: string.Empty, bioRad, cde);
|
||||
Result<Pinned[]> result = pinRepository.GetPinnedTable(metrologyRepository, id: 1, cde_id: null, biorad_id: null, rds: null);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result.Results.Any());
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
|
Loading…
x
Reference in New Issue
Block a user