diff --git a/MP-TAB-SERV/Components/CmpTop.razor b/MP-TAB-SERV/Components/CmpTop.razor new file mode 100644 index 00000000..6d93e3d9 --- /dev/null +++ b/MP-TAB-SERV/Components/CmpTop.razor @@ -0,0 +1,24 @@ +
+
+ + + Username + + [999] +
+
+ +   + MapoTAB2 +   + + +
+
+
+
+ +
+
+
+
\ No newline at end of file diff --git a/MP-TAB-SERV/Components/CmpTop.razor.cs b/MP-TAB-SERV/Components/CmpTop.razor.cs new file mode 100644 index 00000000..796476d5 --- /dev/null +++ b/MP-TAB-SERV/Components/CmpTop.razor.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using System.Net.Http; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Components.Routing; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.Web.Virtualization; +using Microsoft.JSInterop; +using MP_TAB_SERV; +using MP_TAB_SERV.Shared; +using MP_TAB_SERV.Components; +using MP.Data; +using MP.Data.DatabaseModels; +using MP.Data.DTO; +using MP.Data.Services; +using Newtonsoft.Json; +using NLog; +using EgwCoreLib.Razor; +using MP_TAB_SERV.Pages; +using NLog.Fluent; +using System.Diagnostics; + +namespace MP_TAB_SERV.Components +{ + public partial class CmpTop + { + [Inject] + protected ListSelectDataSrv MDataService { get; set; } = null!; + + [Inject] + protected MessageService MsgServ { get; set; } = null!; + + [Inject] + protected SharedMemService MStor { get; set; } = null!; + + [Inject] + protected NavigationManager NavMan { get; set; } = null!; + + [Inject] + protected TabDataService TDService { get; set; } = null!; + + [Parameter] + public List CurrMenuItems { get; set; } = new List(); + + + protected string ResetClass = "btn-primary"; + + protected async Task ReloadMemStor() + { + // in primis svuoto... + MStor.ClearCache(); + // rileggo link + var allData = await MDataService.ListLinkAll(); + MStor.SetupMenu(allData); + // fix config... + var allConf = await MDataService.ConfigGetAll(); + MStor.SetConfig(allConf); + // fix MSFD... + var allMSFD = await TDService.VMSFDGetAll(); + MStor.SetMsfd(allMSFD); + // fix slave + var macSlave = await TDService.Macchine2Slave(); + MStor.SetM2S(macSlave); + + // fix elenco eventi + var allEvents = await TDService.AnagEventiGetAll(); + MStor.SetEventi(allEvents); + // fix elenco stati + var allStati = await TDService.AnaStatiGetAll(); + MStor.SetStati(allStati); + // non da farsi globalmente // fix macchine var allMach = await + // MDataService.MacchineByMatrOper(0); MStor.DictMacchine = allMach.ToDictionary(x => + // x.IdxMacchina, x => $"{x.IdxMacchina} | {x.Nome}"); + + // fix vocabolario + var allVoc = TDService.VocabolarioGetAll(); + MStor.SetVocab(allVoc); + + // resetto il tabDServ + await TDService.FlushCache(); + // ricarica la config... + TDService.SetupConfig(); + } + + protected async Task ForceReload() + { + Stopwatch sw = new Stopwatch(); + sw.Start(); + Log.Info("Start ForceReload"); + ResetClass = "btn-warning"; + await InvokeAsync(StateHasChanged); + // reset cache varie + await MsgServ.ClearLocalStor(); + await MsgServ.ClearSessionStor(); + await MDataService.FlushCache(); + // reload MStor + await ReloadMemStor(); + // calcolo tempo esecuzione + sw.Stop(); + int delta = 500 - (int)sw.ElapsedMilliseconds; + delta = delta > 0 ? delta : 50; + await Task.Delay(delta); + ResetClass = "btn-primary"; + // await InvokeAsync(StateHasChanged); + Log.Info($"ForceReload completed in {sw.ElapsedMilliseconds}ms"); + // ricarica pagina! + NavMan.NavigateTo("/", true); + } + + protected override async Task OnInitializedAsync() + { + await Task.Delay(1); + CurrOprTknLS = await MsgServ.getCurrOperDtoAsync(); + var decodedUrl = Uri.UnescapeDataString(CurrOprTknLS); + CurrOprTknRedis = await TDService.OperatoreGetRedis(MsgServ.MatrOpr); + if (CurrOprTknRedis == "") + { + if (!NavMan.Uri.Contains("regnewdevice")) + { + NavMan.NavigateTo("regnewdevice", true); + } + } + else if (CurrOprTknRedis != "") + { + if (!NavMan.Uri.Contains("status-map")) + { + NavMan.NavigateTo("status-map", true); + } + } + } + protected string CurrOprTknLS { get; set; } = null!; + protected string CurrOprTknRedis { get; set; } = null!; + } +} \ No newline at end of file diff --git a/MP-TAB-SERV/MP-TAB-SERV.csproj b/MP-TAB-SERV/MP-TAB-SERV.csproj index d9f262ea..07368b64 100644 --- a/MP-TAB-SERV/MP-TAB-SERV.csproj +++ b/MP-TAB-SERV/MP-TAB-SERV.csproj @@ -20,6 +20,7 @@ + diff --git a/MP-TAB-SERV/Pages/RegNewDevice.razor b/MP-TAB-SERV/Pages/RegNewDevice.razor new file mode 100644 index 00000000..f7faf040 --- /dev/null +++ b/MP-TAB-SERV/Pages/RegNewDevice.razor @@ -0,0 +1,67 @@ +@page "/regnewdevice" +@using ZXingBlazor.Components + +
+ QR-Scan USER LOGIN +
+
+
+ + + +
+
+ +@if (ShowScanBarcode) +{ + + +} + + + +@if (oprsList.Count > 0) +{ +
+ Selezionare un operatore + +
+
+ User Auth Key + +
+} + +
+
+ +
+
+ +
+
+ +@if (rigaOpr != null) +{ +
@($"{MsgServ.UserAuthKey} {MsgServ.MatrOpr}")
+} + +@*@if (done) +{ +
Logged In
+} +else +{ +
Not logged in
+}*@ + diff --git a/MP-TAB-SERV/Pages/RegNewDevice.razor.cs b/MP-TAB-SERV/Pages/RegNewDevice.razor.cs new file mode 100644 index 00000000..583780f6 --- /dev/null +++ b/MP-TAB-SERV/Pages/RegNewDevice.razor.cs @@ -0,0 +1,200 @@ +using EgwCoreLib.Utils; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.WebUtilities; +//using MongoDB.Bson.IO; +using MP.Data.DatabaseModels; +using MP.Data.DTO; +using MP.Data.Services; +using Newtonsoft.Json; + +namespace MP_TAB_SERV.Pages +{ + public partial class RegNewDevice + { + [Inject] + protected TabDataService TDService { get; set; } = null!; + + [Inject] + protected MessageService MsgServ { get; set; } = null!; + + [Inject] + protected NavigationManager NavMan { get; set; } = null!; + + protected List oprsList { get; set; } = new List(); + + protected override async Task OnInitializedAsync() + { + await Task.Delay(1); + + //var currOpr = await TDService.LoginOperatore(matrOpr, authKey); + //if (currOpr.MatrOpr != 0) + //{ + // MsgServ.RigaOper = currOpr; + //} + TDService.ConfigGetVal("cookieDayExpire", ref expDays); + + expDT = DateTime.Now.AddDays(expDays); + + //CurrOprTknLS = await MsgServ.getCurrOperDtoAsync(); + //var decodedUrl = Uri.UnescapeDataString(CurrOprTknLS); + //CurrOprTknRedis = await TDService.OperatoreGetRedis(decodedUrl); + + //if (CurrOprTknRedis != "") + //{ + // NavMan.NavigateTo("status-map"); + //} + + //if (MsgServ.RigaOper != null) + //{ + // NavMan.NavigateTo("status-map", true); + //} + oprsList = await TDService.ElencoOperatori(); + } + + protected int expDays = 1; + protected int matrOpr { get; set; } = 0; + protected string authKey { get; set; } = ""; + protected AnagOperatoriModel rigaOpr { get; set; } = null!; + protected string CurrOprTknLS { get; set; } = null!; + protected string CurrOprTknRedis { get; set; } = null!; + + protected DateTime expDT { get; set; } = DateTime.Now; + protected async Task logIn() + { + await Task.Delay(1); + rigaOpr = await TDService.LoginOperatore(matrOpr, authKey); + if (rigaOpr != null) + { + userTknDTO newUserTkn = new userTknDTO() + { + currOpr = rigaOpr, + expTime = expDT + }; + + var jsonTkn = JsonConvert.SerializeObject(newUserTkn); + string hash = TDService.EncriptData(jsonTkn); + MsgServ.RigaOper = rigaOpr; + await MsgServ.setCurrOperDtoAsync(hash); + await TDService.OperatoreSetRedis(matrOpr, hash); + NavMan.NavigateTo("status-map"); + } + //StateHasChanged(); + } + + protected async Task btnMode() + { + await Task.Delay(1); + ShowScanBarcode = !ShowScanBarcode; + } + + protected DateTime vetoScan = DateTime.Now; + + protected async Task ScanDoneHandler(string value) + { + DateTime adesso = DateTime.Now; + // non nullo + if (!string.IsNullOrEmpty(value)) + { + // non veto... + if (adesso.Subtract(vetoScan).TotalMinutes > 0) + { + vetoScan = adesso.AddSeconds(4); + //NavManager.NavigateTo($"CodeProcess/{value}"); + var uri = NavMan.ToAbsoluteUri(value); + if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("MatrOpr", out var _matrOpr)) + { + if (!string.IsNullOrEmpty(_matrOpr)) + { + matrOpr = int.Parse(_matrOpr); + } + } + if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("UserAuthKey", out var _authKey)) + { + if (!string.IsNullOrEmpty(_authKey)) + { + authKey = _authKey; + } + } + + + rigaOpr = await TDService.LoginOperatore(matrOpr, authKey); + if (rigaOpr == null) + { + var deHash = TDService.DeriptData(authKey); + rigaOpr = await TDService.LoginOperatore(matrOpr, deHash); + } + if (rigaOpr != null) + { + userTknDTO newUserTkn = new userTknDTO() + { + currOpr = rigaOpr, + expTime = expDT + }; + + var jsonTkn = JsonConvert.SerializeObject(newUserTkn); + string hash = TDService.EncriptData(jsonTkn); + MsgServ.RigaOper = rigaOpr; + await MsgServ.setCurrOperDtoAsync(hash); + await TDService.OperatoreSetRedis(matrOpr, hash); + NavMan.NavigateTo("status-map"); + } + } + } + } + + private bool ShowScanBarcode { get; set; } = false; + + + //private async Task ProcessBarcode(string Barcode) + //{ + // if (OrderCode != Barcode) + // { + // await InvokeAsync(() => + // { + // OrderCode = Barcode; + // }); + // var ordine = await DataService.OrderGetByCode(Barcode); + // if (ordine != null) + // { + // if (ordine.DtExecEnd > ordine.DtOrder) + // { + // await InvokeAsync(() => + // { + // errorDescription = "Errore: ordine già completato"; + // }); + // await Task.Run(() => + // { + // Thread.Sleep(3000); + // forceReset(); + // }); + // } + // else if (ordine.PlantId != SelPlantId) + // { + // await InvokeAsync(() => + // { + // errorDescription = "Errore: ordine destinato ad altro impianto"; + // }); + + // await Task.Run(() => + // { + // Thread.Sleep(3000); + // forceReset(); + // }); + // } + // else + // { + // // salvo... + // MessageService.SelPlantId = $"{SelPlantId}"; + // MessageService.SelOrderCode = Barcode; + // // rimando a pagina load.... + // NavManager.NavigateTo($"GasStationLoad"); + // } + // } + // else + // { + // errorDescription = "Errore: ordine non trovato"; + // } + // } + //} + } +} \ No newline at end of file diff --git a/MP-TAB-SERV/Pages/_Layout.cshtml b/MP-TAB-SERV/Pages/_Layout.cshtml index 24f41386..1958df59 100644 --- a/MP-TAB-SERV/Pages/_Layout.cshtml +++ b/MP-TAB-SERV/Pages/_Layout.cshtml @@ -38,6 +38,9 @@ 🗙 + + + diff --git a/MP-TAB-SERV/Shared/MainLayout.razor b/MP-TAB-SERV/Shared/MainLayout.razor index d18e77a9..8a029f91 100644 --- a/MP-TAB-SERV/Shared/MainLayout.razor +++ b/MP-TAB-SERV/Shared/MainLayout.razor @@ -7,7 +7,7 @@
-
+ @*
@@ -30,7 +30,10 @@
-
+ *@ + + +
diff --git a/MP-TAB-SERV/Shared/MainLayout.razor.cs b/MP-TAB-SERV/Shared/MainLayout.razor.cs index c20d5162..0dc08eec 100644 --- a/MP-TAB-SERV/Shared/MainLayout.razor.cs +++ b/MP-TAB-SERV/Shared/MainLayout.razor.cs @@ -55,31 +55,6 @@ namespace MP_TAB_SERV.Shared #region Protected Methods - protected async Task ForceReload() - { - Stopwatch sw = new Stopwatch(); - sw.Start(); - Log.Info("Start ForceReload"); - ResetClass = "btn-warning"; - await InvokeAsync(StateHasChanged); - // reset cache varie - await MServ.ClearLocalStor(); - await MServ.ClearSessionStor(); - await MDataService.FlushCache(); - // reload MStor - await ReloadMemStor(); - // calcolo tempo esecuzione - sw.Stop(); - int delta = 500 - (int)sw.ElapsedMilliseconds; - delta = delta > 0 ? delta : 50; - await Task.Delay(delta); - ResetClass = "btn-primary"; - // await InvokeAsync(StateHasChanged); - Log.Info($"ForceReload completed in {sw.ElapsedMilliseconds}ms"); - // ricarica pagina! - NavMan.NavigateTo("/", true); - } - /// /// Init struttura dati /// diff --git a/MP-TAB-SERV/Shared/MainLayout.razor.css b/MP-TAB-SERV/Shared/MainLayout.razor.css index 20fe1add..a80c3036 100644 --- a/MP-TAB-SERV/Shared/MainLayout.razor.css +++ b/MP-TAB-SERV/Shared/MainLayout.razor.css @@ -13,29 +13,7 @@ main { padding: 0 10px 0 0; } -.top-row { - background-color: #05173d; - /*border-bottom: 1px solid #d6d5d5;*/ - justify-content: flex-end; - height: 3.5rem; - display: flex; - align-items: center; -} - .top-row ::deep a, .top-row ::deep .btn-link { - white-space: nowrap; - /*margin-left: 1.5rem;*/ - text-decoration: none; - } - - .top-row ::deep a:hover, .top-row ::deep .btn-link:hover { - text-decoration: underline; - } - - .top-row ::deep a:first-child { - overflow: hidden; - text-overflow: ellipsis; - } @media (min-width: 640.98px) { .slideMen:not(.auth) { @@ -48,26 +26,6 @@ main { } - - -@media (max-width: 640.98px) { - .top-row:not(.auth) { - display: none; - } - - #mainBody { - width: 100%; - } - - .top-row.auth { - justify-content: space-between; - } - - .top-row ::deep a, .top-row ::deep .btn-link { - margin-left: 0; - } -} - @media (min-width: 641px) { .page { flex-direction: row; @@ -82,22 +40,6 @@ main { } } -.top-row { - position: sticky; - top: 0; - z-index: 1; -} - - .top-row.auth ::deep a:first-child { - flex: 1; - text-align: right; - width: 0; - } - -.top-row, article { - padding-left: 1rem !important; - padding-right: .5rem !important; -} #blazor-error-ui { background: lightyellow; diff --git a/MP-TAB-SERV/wwwroot/css/site.css b/MP-TAB-SERV/wwwroot/css/site.css index 924a71e9..508a0b26 100644 --- a/MP-TAB-SERV/wwwroot/css/site.css +++ b/MP-TAB-SERV/wwwroot/css/site.css @@ -101,4 +101,56 @@ a, } .blazor-error-boundary::after { content: "An error has occurred."; +} +.top-row { + background-color: #05173d; + /*border-bottom: 1px solid #d6d5d5;*/ + justify-content: flex-end; + height: 3.5rem; + display: flex; + align-items: center; +} +.top-row ::deep a, +.top-row ::deep .btn-link { + white-space: nowrap; + /*margin-left: 1.5rem;*/ + text-decoration: none; +} +.top-row ::deep a:hover, +.top-row ::deep .btn-link:hover { + text-decoration: underline; +} +.top-row ::deep a:first-child { + overflow: hidden; + text-overflow: ellipsis; +} +@media (max-width: 640.98px) { + .top-row:not(.auth) { + display: none; + } + #mainBody { + width: 100%; + } + .top-row.auth { + justify-content: space-between; + } + .top-row ::deep a, + .top-row ::deep .btn-link { + margin-left: 0; + } +} +.top-row { + position: sticky; + top: 0; + z-index: 1; +} +.top-row.auth ::deep a:first-child { + flex: 1; + text-align: right; + width: 0; +} +.top-row, +article { + padding-left: 1rem !important; + padding-right: 0.5rem !important; } \ No newline at end of file diff --git a/MP-TAB-SERV/wwwroot/css/site.less b/MP-TAB-SERV/wwwroot/css/site.less index f1f08aa8..3623ea46 100644 --- a/MP-TAB-SERV/wwwroot/css/site.less +++ b/MP-TAB-SERV/wwwroot/css/site.less @@ -114,3 +114,63 @@ html, body { .blazor-error-boundary::after { content: "An error has occurred." } + +.top-row { + background-color: #05173d; + /*border-bottom: 1px solid #d6d5d5;*/ + justify-content: flex-end; + height: 3.5rem; + display: flex; + align-items: center; +} + +.top-row ::deep a, .top-row ::deep .btn-link { + white-space: nowrap; + /*margin-left: 1.5rem;*/ + text-decoration: none; +} + +.top-row ::deep a:hover, .top-row ::deep .btn-link:hover { + text-decoration: underline; +} + +.top-row ::deep a:first-child { + overflow: hidden; + text-overflow: ellipsis; +} + + +@media (max-width: 640.98px) { + .top-row:not(.auth) { + display: none; + } + + #mainBody { + width: 100%; + } + + .top-row.auth { + justify-content: space-between; + } + + .top-row ::deep a, .top-row ::deep .btn-link { + margin-left: 0; + } +} + +.top-row { + position: sticky; + top: 0; + z-index: 1; +} + +.top-row.auth ::deep a:first-child { + flex: 1; + text-align: right; + width: 0; +} + +.top-row, article { + padding-left: 1rem !important; + padding-right: .5rem !important; +} \ No newline at end of file diff --git a/MP-TAB-SERV/wwwroot/css/site.min.css b/MP-TAB-SERV/wwwroot/css/site.min.css index 9ec2a048..c429c6c5 100644 --- a/MP-TAB-SERV/wwwroot/css/site.min.css +++ b/MP-TAB-SERV/wwwroot/css/site.min.css @@ -1 +1 @@ -@import url('open-iconic/font/css/open-iconic-bootstrap.min.css');html,body{font-family:'Open Sans Condensed',sans-serif;background-color:#151321;color:#ededed;}.cardObj{border-radius:.375rem;background:linear-gradient(121deg,rgba(255,255,255,.2) -.71%,rgba(255,255,255,.05) 97.66%);box-shadow:0 4px 24px -1px rgba(0,0,0,.25);flex-shrink:0;}.cardObjNoBL{border-radius:.375rem 0 0 .375rem;background:linear-gradient(121deg,rgba(255,255,255,.2) -.71%,rgba(255,255,255,.05) 97.66%);box-shadow:0 4px 24px -1px rgba(0,0,0,.25);flex-shrink:0;}.cardFullHeight{border-radius:.375rem;background:linear-gradient(121deg,rgba(255,255,255,.2) -.71%,rgba(255,255,255,.05) 97.66%);box-shadow:0 4px 24px -1px rgba(0,0,0,.25);flex-shrink:0;height:100%;}.longStopListNotes{height:100%;}@media(max-width:640.98px){.longStopListNotes{max-height:120px;}}.borderStd{border-radius:.375rem;}.table-dark{--bs-table-color:#fff;--bs-table-bg:transparent;--bs-table-border-color:#4d5154;--bs-table-striped-bg:#2c3034;--bs-table-striped-color:#fff;--bs-table-active-bg:#373b3e;--bs-table-active-color:#fff;--bs-table-hover-bg:#323539;--bs-table-hover-color:#fff;color:var(--bs-table-color);border-color:var(--bs-table-border-color);}h1:focus{outline:0;}a,.btn-link{color:#0071c1;}.btn-primary{color:#fff;background-color:#1b6ec2;border-color:#1861ac;}.content{padding-top:1.1rem;}.valid.modified:not([type=checkbox]){outline:1px solid #26b050;}.invalid{outline:1px solid #f00;}.validation-message{color:#f00;}#blazor-error-ui{background:#ffffe0;bottom:0;box-shadow:0 -1px 2px rgba(0,0,0,.2);display:none;left:0;padding:.6rem 1.25rem .7rem 1.25rem;position:fixed;width:100%;z-index:1000;}#blazor-error-ui .dismiss{cursor:pointer;position:absolute;right:.75rem;top:.5rem;}.blazor-error-boundary{background:url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxk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ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem,#b32121;padding:1rem 1rem 1rem 3.7rem;color:#fff;}.blazor-error-boundary::after{content:"An error has occurred.";} \ No newline at end of file +@import url('open-iconic/font/css/open-iconic-bootstrap.min.css');html,body{font-family:'Open Sans Condensed',sans-serif;background-color:#151321;color:#ededed;}.cardObj{border-radius:.375rem;background:linear-gradient(121deg,rgba(255,255,255,.2) -.71%,rgba(255,255,255,.05) 97.66%);box-shadow:0 4px 24px -1px rgba(0,0,0,.25);flex-shrink:0;}.cardObjNoBL{border-radius:.375rem 0 0 .375rem;background:linear-gradient(121deg,rgba(255,255,255,.2) -.71%,rgba(255,255,255,.05) 97.66%);box-shadow:0 4px 24px -1px rgba(0,0,0,.25);flex-shrink:0;}.cardFullHeight{border-radius:.375rem;background:linear-gradient(121deg,rgba(255,255,255,.2) -.71%,rgba(255,255,255,.05) 97.66%);box-shadow:0 4px 24px -1px rgba(0,0,0,.25);flex-shrink:0;height:100%;}.longStopListNotes{height:100%;}@media(max-width:640.98px){.longStopListNotes{max-height:120px;}}.borderStd{border-radius:.375rem;}.table-dark{--bs-table-color:#fff;--bs-table-bg:transparent;--bs-table-border-color:#4d5154;--bs-table-striped-bg:#2c3034;--bs-table-striped-color:#fff;--bs-table-active-bg:#373b3e;--bs-table-active-color:#fff;--bs-table-hover-bg:#323539;--bs-table-hover-color:#fff;color:var(--bs-table-color);border-color:var(--bs-table-border-color);}h1:focus{outline:0;}a,.btn-link{color:#0071c1;}.btn-primary{color:#fff;background-color:#1b6ec2;border-color:#1861ac;}.content{padding-top:1.1rem;}.valid.modified:not([type=checkbox]){outline:1px solid #26b050;}.invalid{outline:1px solid #f00;}.validation-message{color:#f00;}#blazor-error-ui{background:#ffffe0;bottom:0;box-shadow:0 -1px 2px rgba(0,0,0,.2);display:none;left:0;padding:.6rem 1.25rem .7rem 1.25rem;position:fixed;width:100%;z-index:1000;}#blazor-error-ui .dismiss{cursor:pointer;position:absolute;right:.75rem;top:.5rem;}.blazor-error-boundary{background:url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4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undary::after{content:"An error has occurred.";}.top-row{background-color:#05173d;justify-content:flex-end;height:3.5rem;display:flex;align-items:center;}.top-row ::deep a,.top-row ::deep .btn-link{white-space:nowrap;text-decoration:none;}.top-row ::deep a:hover,.top-row ::deep .btn-link:hover{text-decoration:underline;}.top-row ::deep a:first-child{overflow:hidden;text-overflow:ellipsis;}@media(max-width:640.98px){.top-row:not(.auth){display:none;}#mainBody{width:100%;}.top-row.auth{justify-content:space-between;}.top-row ::deep a,.top-row ::deep .btn-link{margin-left:0;}}.top-row{position:sticky;top:0;z-index:1;}.top-row.auth ::deep a:first-child{flex:1;text-align:right;width:0;}.top-row,article{padding-left:1rem!important;padding-right:.5rem!important;} \ No newline at end of file diff --git a/MP.Data/Controllers/MpTabController.cs b/MP.Data/Controllers/MpTabController.cs index bee0b466..af3a4a36 100644 --- a/MP.Data/Controllers/MpTabController.cs +++ b/MP.Data/Controllers/MpTabController.cs @@ -54,6 +54,51 @@ namespace MP.Data.Controllers return dbResult; } + + /// + /// Elenco operatori + /// + /// + public List ElencoOperatori() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbOperatori + .Where(s => s.MatrOpr > 0) + .AsNoTracking() + .OrderBy(x => x.MatrOpr) + .ToList(); + } + return dbResult; + } + + /// + /// login operatori + /// + /// /// + /// /// + /// + public AnagOperatoriModel LoginOperatore(int matrOpr, string authKey) + { + AnagOperatoriModel dbResult = null; + AnagOperatoriModel answ = new AnagOperatoriModel(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbOperatori + .Where(s => (s.MatrOpr > 0) && (s.MatrOpr == matrOpr) && (s.authKey == authKey)) + .AsNoTracking() + .FirstOrDefault(); + if (dbResult != null) + { + answ = dbResult; + } + } + return answ; + } + /// /// Registrato ACK allarme /// diff --git a/MP.Data/DTO/userTknDTO.cs b/MP.Data/DTO/userTknDTO.cs new file mode 100644 index 00000000..bc9a8db5 --- /dev/null +++ b/MP.Data/DTO/userTknDTO.cs @@ -0,0 +1,15 @@ +using MP.Data.DatabaseModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.Data.DTO +{ + public class userTknDTO + { + public AnagOperatoriModel currOpr { get; set; } = null; + public DateTime expTime { get; set; } = DateTime.Now; + } +} diff --git a/MP.Data/Services/MessageService.cs b/MP.Data/Services/MessageService.cs index 6d751191..faeb93c4 100644 --- a/MP.Data/Services/MessageService.cs +++ b/MP.Data/Services/MessageService.cs @@ -2,6 +2,7 @@ using Blazored.SessionStorage; using Microsoft.Extensions.Configuration; using MP.Data.DatabaseModels; +using MP.Data.DTO; using Newtonsoft.Json; using NLog; using StackExchange.Redis; @@ -339,6 +340,7 @@ namespace MP.Data.Services return answ; } + /// /// Recupero singola preferenza utente /// @@ -482,6 +484,35 @@ namespace MP.Data.Services return fatto; } + + /// + /// Restituisce il record OperatoreDTO da localstorage + /// + /// + public async Task getCurrOperDtoAsync() + { + string answ = ""; + var result = await localStorage.GetItemAsync("currTkn"); + if (result != null) + { + //var data = JsonConvert.DeserializeObject(result); + answ = result; + } + return answ; + } + + /// + /// scrive il record OperatoreDTO nel localstorage + /// + /// + public async Task setCurrOperDtoAsync(string currTkn) + { + bool answ = false; + await localStorage.SetItemAsync("currTkn", currTkn); + answ = true; + return answ; + } + #endregion Private Methods #if false diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs index 27ef61d0..f13db5d4 100644 --- a/MP.Data/Services/TabDataService.cs +++ b/MP.Data/Services/TabDataService.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using EgwCoreLib.Utils; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using MP.Data.DatabaseModels; using MP.Data.DTO; @@ -175,6 +176,41 @@ namespace MP.Data.Services return result; } + + /// + /// Elenco operatori + /// + /// + public async Task> ElencoOperatori() + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:ElencoOpr"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbTabController.ElencoOperatori(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"ElencoOperatori | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + /// /// Registrato ACK allarme /// @@ -188,6 +224,129 @@ namespace MP.Data.Services return answ; } + public string EncriptData(string rawData) + { + return SteamCrypto.EncryptString(rawData, passPhrase); + } + public string DeriptData(string encData) + { + return SteamCrypto.DecryptString(encData, passPhrase); + } + + protected const string passPhrase = "7871D817-C71F-4DFC-BF12-00A95BE507B5"; + + protected int expDays = 1; + + protected void setExpDays() + { + ConfigGetVal("cookieDayExpire", ref expDays); + } + + /// + /// Log in operatore + /// + /// matricola operatore + /// Auth Key + /// + public async Task LoginOperatore(int matrOpr, string authKey) + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + AnagOperatoriModel answ = null; + // cerco in redis... + string currKey = $"{redisBaseKey}:CurrOpr:{matrOpr}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + //var encrData = SteamCrypto.DecryptString(rawData, passPhrase); + answ = JsonConvert.DeserializeObject($"{rawData}"); + source = "REDIS"; + } + else + { + answ = dbTabController.LoginOperatore(matrOpr, authKey); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(answ); + //var encrData = SteamCrypto.EncryptString(rawData, passPhrase); + await redisDb.StringSetAsync(currKey, rawData, ConfigCache); + } + if (answ == null) + { + answ = new AnagOperatoriModel(); + } + sw.Stop(); + Log.Debug($"LoginOperatore | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + await Task.Delay(1); + return answ; + } + + /// + /// Scrive l'hash dell'oggetto curr opr + /// + /// + /// + public async Task OperatoreGetRedis(int matrOpr) + { + string source = "REDIS"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + string answ = ""; + // cerco in redis... + string currKey = $"{redisBaseKey}:CurrOpr:{matrOpr}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + //var encrData = SteamCrypto.DecryptString(rawData, passPhrase); + //answ = JsonConvert.DeserializeObject(rawData); + answ = rawData; + } + if (answ == null) + { + answ = ""; + } + sw.Stop(); + Log.Debug($"OperatoreGetRedis | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + await Task.Delay(1); + return answ; + } + /// + /// legge l'hash dell'oggetto curr opr + /// + /// + /// + public async Task OperatoreSetRedis(int matrOpr, string currOpr) + { + string source = "REDIS"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + string answ = ""; + // cerco in redis... + string currKey = $"{redisBaseKey}:CurrOpr:{matrOpr}"; + //RedisValue rawData = await redisDb.StringGetAsync(currKey); + // serializzo e salvo... + //rawData = JsonConvert.SerializeObject(currOpr); + answ = currOpr; + //var encrData = SteamCrypto.EncryptString(rawData, passPhrase); + await redisDb.StringSetAsync(currKey, currOpr, ConfigCache); + if (answ == null) + { + answ = ""; + } + sw.Stop(); + Log.Debug($"OperatoreSetRedis | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + await Task.Delay(1); + return answ; + } + + /// + /// Durata cache data dal valore in config + /// + protected TimeSpan ConfigCache + { + get => TimeSpan.FromDays(expDays); + } + /// /// Registrato ACK allarme ///