From fe9ea62f5be2bd60db9bc8f41ec08e02637790ac Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 14 Nov 2023 12:20:51 +0100 Subject: [PATCH] commit parziale (OK SOLO SE niente F5) --- MP-TAB-SERV/Components/CmpTop.razor | 4 +- MP-TAB-SERV/Components/CmpTop.razor.cs | 11 +- MP-TAB-SERV/MP-TAB-SERV.csproj | 2 +- MP-TAB-SERV/Pages/Logout.razor.cs | 2 +- MP-TAB-SERV/Pages/RegNewDevice.razor | 2 +- MP-TAB-SERV/Pages/RegNewDevice.razor.cs | 12 +- MP-TAB-SERV/Resources/ChangeLog.html | 2 +- MP-TAB-SERV/Resources/VersNum.txt | 2 +- MP-TAB-SERV/Resources/manifest.xml | 2 +- MP.Data/Constants.cs | 3 + MP.Data/Controllers/MpTabController.cs | 2 +- MP.Data/Services/MessageService.cs | 42 ++- MP.Data/Services/TabDataService.cs | 365 ++++++++++++------------ 13 files changed, 245 insertions(+), 206 deletions(-) diff --git a/MP-TAB-SERV/Components/CmpTop.razor b/MP-TAB-SERV/Components/CmpTop.razor index 6d93e3d9..203ef85c 100644 --- a/MP-TAB-SERV/Components/CmpTop.razor +++ b/MP-TAB-SERV/Components/CmpTop.razor @@ -2,9 +2,9 @@
- Username + @UserName - [999] + [@MatrOpr]
diff --git a/MP-TAB-SERV/Components/CmpTop.razor.cs b/MP-TAB-SERV/Components/CmpTop.razor.cs index 2c8c859d..176342e7 100644 --- a/MP-TAB-SERV/Components/CmpTop.razor.cs +++ b/MP-TAB-SERV/Components/CmpTop.razor.cs @@ -71,12 +71,21 @@ namespace MP_TAB_SERV.Components NavMan.NavigateTo("/", true); } + private string UserName + { + get => MsgServ.CognomeNome; + } + private int MatrOpr + { + get => MsgServ.MatrOpr; + } + protected override async Task OnInitializedAsync() { await Task.Delay(1); CurrOprTknLS = await MsgServ.getCurrOperDtoAsync(); var decodedUrl = Uri.UnescapeDataString(CurrOprTknLS); - CurrOprTknRedis = await TDService.OperatoreGetRedis(MsgServ.MatrOpr); + CurrOprTknRedis = await TDService.OperatoreGetRedis(MatrOpr); if (CurrOprTknRedis == "") { if (!NavMan.Uri.Contains("reg-new-device")) diff --git a/MP-TAB-SERV/MP-TAB-SERV.csproj b/MP-TAB-SERV/MP-TAB-SERV.csproj index 654471b0..899a778f 100644 --- a/MP-TAB-SERV/MP-TAB-SERV.csproj +++ b/MP-TAB-SERV/MP-TAB-SERV.csproj @@ -3,7 +3,7 @@ net6.0 enable - 6.16.2311.1411 + 6.16.2311.1412 enable MP_TAB_SERV diff --git a/MP-TAB-SERV/Pages/Logout.razor.cs b/MP-TAB-SERV/Pages/Logout.razor.cs index 7d75c64a..c09f4486 100644 --- a/MP-TAB-SERV/Pages/Logout.razor.cs +++ b/MP-TAB-SERV/Pages/Logout.razor.cs @@ -41,7 +41,7 @@ namespace MP_TAB_SERV.Pages await Task.Delay(1); await localStorage.SetItemAsync("currTkn", ""); await TDService.OperatoreDeleteRedis(MsgServ.MatrOpr); - NavMan.NavigateTo("regnewdevice"); + NavMan.NavigateTo("reg-new-device"); } } } \ No newline at end of file diff --git a/MP-TAB-SERV/Pages/RegNewDevice.razor b/MP-TAB-SERV/Pages/RegNewDevice.razor index f7faf040..0cf38925 100644 --- a/MP-TAB-SERV/Pages/RegNewDevice.razor +++ b/MP-TAB-SERV/Pages/RegNewDevice.razor @@ -1,4 +1,4 @@ -@page "/regnewdevice" +@page "/reg-new-device" @using ZXingBlazor.Components
diff --git a/MP-TAB-SERV/Pages/RegNewDevice.razor.cs b/MP-TAB-SERV/Pages/RegNewDevice.razor.cs index 583780f6..60740dd8 100644 --- a/MP-TAB-SERV/Pages/RegNewDevice.razor.cs +++ b/MP-TAB-SERV/Pages/RegNewDevice.razor.cs @@ -62,7 +62,7 @@ namespace MP_TAB_SERV.Pages protected async Task logIn() { await Task.Delay(1); - rigaOpr = await TDService.LoginOperatore(matrOpr, authKey); + rigaOpr = await TDService.OperatoreSearch(matrOpr, authKey); if (rigaOpr != null) { userTknDTO newUserTkn = new userTknDTO() @@ -72,7 +72,7 @@ namespace MP_TAB_SERV.Pages }; var jsonTkn = JsonConvert.SerializeObject(newUserTkn); - string hash = TDService.EncriptData(jsonTkn); + string hash = TDService.EncryptData(jsonTkn); MsgServ.RigaOper = rigaOpr; await MsgServ.setCurrOperDtoAsync(hash); await TDService.OperatoreSetRedis(matrOpr, hash); @@ -117,11 +117,11 @@ namespace MP_TAB_SERV.Pages } - rigaOpr = await TDService.LoginOperatore(matrOpr, authKey); + rigaOpr = await TDService.OperatoreSearch(matrOpr, authKey); if (rigaOpr == null) { - var deHash = TDService.DeriptData(authKey); - rigaOpr = await TDService.LoginOperatore(matrOpr, deHash); + var deHash = TDService.DecryptData(authKey); + rigaOpr = await TDService.OperatoreSearch(matrOpr, deHash); } if (rigaOpr != null) { @@ -132,7 +132,7 @@ namespace MP_TAB_SERV.Pages }; var jsonTkn = JsonConvert.SerializeObject(newUserTkn); - string hash = TDService.EncriptData(jsonTkn); + string hash = TDService.EncryptData(jsonTkn); MsgServ.RigaOper = rigaOpr; await MsgServ.setCurrOperDtoAsync(hash); await TDService.OperatoreSetRedis(matrOpr, hash); diff --git a/MP-TAB-SERV/Resources/ChangeLog.html b/MP-TAB-SERV/Resources/ChangeLog.html index 6e880a19..0b60a31d 100644 --- a/MP-TAB-SERV/Resources/ChangeLog.html +++ b/MP-TAB-SERV/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2311.1411

+

Versione: 6.16.2311.1412


Note di rilascio:
  • diff --git a/MP-TAB-SERV/Resources/VersNum.txt b/MP-TAB-SERV/Resources/VersNum.txt index 56646032..6b0c35dd 100644 --- a/MP-TAB-SERV/Resources/VersNum.txt +++ b/MP-TAB-SERV/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2311.1411 +6.16.2311.1412 diff --git a/MP-TAB-SERV/Resources/manifest.xml b/MP-TAB-SERV/Resources/manifest.xml index b9d9e968..8ab793a7 100644 --- a/MP-TAB-SERV/Resources/manifest.xml +++ b/MP-TAB-SERV/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2311.1411 + 6.16.2311.1412 https://nexus.steamware.net/repository/SWS/MP-TAB-SERV/stable/LAST/MP-TAB-SERV.zip https://nexus.steamware.net/repository/SWS/MP-TAB-SERV/stable/LAST/ChangeLog.html false diff --git a/MP.Data/Constants.cs b/MP.Data/Constants.cs index ea73a57c..4c988efc 100644 --- a/MP.Data/Constants.cs +++ b/MP.Data/Constants.cs @@ -22,6 +22,9 @@ public static string redisMseKey = "MP:MON:Cache:MSE"; public static string redisMseKeySingle = "MP:MON:Cache:MseSingle"; + // passphrase cifratura + public const string passPhrase = "7871D817-C71F-4DFC-BF12-00A95BE507B5"; + #endregion Public Fields } } \ No newline at end of file diff --git a/MP.Data/Controllers/MpTabController.cs b/MP.Data/Controllers/MpTabController.cs index 1af0eb73..2804c301 100644 --- a/MP.Data/Controllers/MpTabController.cs +++ b/MP.Data/Controllers/MpTabController.cs @@ -80,7 +80,7 @@ namespace MP.Data.Controllers /// /// /// /// /// - public AnagOperatoriModel LoginOperatore(int matrOpr, string authKey) + public AnagOperatoriModel OperatoreSearch(int matrOpr, string authKey) { AnagOperatoriModel dbResult = null; AnagOperatoriModel answ = new AnagOperatoriModel(); diff --git a/MP.Data/Services/MessageService.cs b/MP.Data/Services/MessageService.cs index faeb93c4..36b8c517 100644 --- a/MP.Data/Services/MessageService.cs +++ b/MP.Data/Services/MessageService.cs @@ -1,5 +1,6 @@ using Blazored.LocalStorage; using Blazored.SessionStorage; +using EgwCoreLib.Utils; using Microsoft.Extensions.Configuration; using MP.Data.DatabaseModels; using MP.Data.DTO; @@ -93,8 +94,7 @@ namespace MP.Data.Services { get { - int answ = 102; - //int answ = -1; + int answ = -1; if (_rigaOper != null) { answ = _rigaOper.MatrOpr; @@ -410,7 +410,45 @@ namespace MP.Data.Services #region Private Fields + public string DecryptData(string encData) + { + return SteamCrypto.DecryptString(encData, Constants.passPhrase); + } + private AnagOperatoriModel? _rigaOper; + //{ + // get + // { + // AnagOperatoriModel answ = new AnagOperatoriModel(); + // string rawData = ""; + // var pUpd = Task.Run(async () => + // { + // rawData = await getCurrOperDtoAsync(); + // }); + // pUpd.Wait(); + // var decodedUrl = Uri.UnescapeDataString(rawData); + // var decrData = DecryptData(decodedUrl); + // answ = JsonConvert.DeserializeObject(decodedUrl); + // return answ; + // } + // set + // { + // var serVal = JsonConvert.SerializeObject(value); + // var encData = EncryptData(serVal); + // var escdata = Uri.EscapeDataString(encData); + // var pUpd = Task.Run(async () => + // { + // await setCurrOperDtoAsync(escdata); + // }); + // pUpd.Wait(); + // } + //} + public string EncryptData(string rawData) + { + return SteamCrypto.EncryptString(rawData, Constants.passPhrase); + } + + /// /// Durata cache lunga IN SECONDI diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs index c223ef70..d8a99882 100644 --- a/MP.Data/Services/TabDataService.cs +++ b/MP.Data/Services/TabDataService.cs @@ -176,41 +176,6 @@ 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 /// @@ -224,159 +189,6 @@ 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:login:{matrOpr}"; - //RedisValue rawData = await redisDb.StringGetAsync(currKey); - //if (rawData.HasValue) - //{ - //var encrData = SteamCrypto.DecryptString(rawData, passPhrase); - //answ = JsonConvert.DeserializeObject($"{rawData}"); - //source = "REDIS"; - //} - //else - //{ - // serializzo e salvo... - //rawData = JsonConvert.SerializeObject(answ); - //var encrData = SteamCrypto.EncryptString(rawData, passPhrase); - //await redisDb.StringSetAsync(currKey, rawData, ConfigCache); - //} - answ = dbTabController.LoginOperatore(matrOpr, authKey); - 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 = $"{redisUserDataKey}: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; - } - /// - /// Delete dell'oggetto opr serializzato - /// - /// - /// - public async Task OperatoreDeleteRedis(int matrOpr) - { - string source = "REDIS"; - Stopwatch sw = new Stopwatch(); - sw.Start(); - bool answ = false; - // cerco in redis... - string currKey = $"{redisBaseKey}:CurrOpr:{matrOpr}"; - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - var done = await ExecFlushRedisPattern(currKey); - if (done) - { - - answ = true; - } - } - sw.Stop(); - Log.Debug($"OperatoreDeleteRedis | {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 = $"{redisUserDataKey}: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 /// @@ -755,6 +567,11 @@ namespace MP.Data.Services return dbTabController.DDB_getNext(idxMacchina, inizioStato); } + public string DecryptData(string encData) + { + return SteamCrypto.DecryptString(encData, Constants.passPhrase); + } + public void Dispose() { // Clear database controller @@ -786,6 +603,45 @@ namespace MP.Data.Services return answ; } + /// + /// 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; + } + + public string EncryptData(string rawData) + { + return SteamCrypto.EncryptString(rawData, Constants.passPhrase); + } + /// /// Elimina una riga in EventList se trovata /// @@ -1708,6 +1564,116 @@ namespace MP.Data.Services return answ; } + /// + /// Delete dell'oggetto opr serializzato + /// + /// + /// + public async Task OperatoreDeleteRedis(int matrOpr) + { + string source = "REDIS"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + bool answ = false; + // cerco in redis... + string currKey = $"{redisUserDataKey}:CurrOpr:{matrOpr}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + var done = await ExecFlushRedisPattern(currKey); + if (done) + { + answ = true; + } + } + sw.Stop(); + Log.Debug($"OperatoreDeleteRedis | {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 = $"{redisUserDataKey}: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; + } + + /// + /// Log in operatore + /// + /// matricola operatore + /// Auth Key + /// + public async Task OperatoreSearch(int matrOpr, string authKey) + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + AnagOperatoriModel answ = null; + answ = dbTabController.OperatoreSearch(matrOpr, authKey); + if (answ == null) + { + answ = new AnagOperatoriModel(); + } + sw.Stop(); + Log.Debug($"LoginOperatore | {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 = $"{redisUserDataKey}: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; + } + /// /// Stato prod macchina /// @@ -3003,6 +2969,8 @@ namespace MP.Data.Services #region Protected Fields + protected int expDays = 1; + /// /// Oggetto per connessione a REDIS /// @@ -3015,6 +2983,27 @@ namespace MP.Data.Services #endregion Protected Fields + #region Protected Properties + + /// + /// Durata cache data dal valore in config + /// + protected TimeSpan ConfigCache + { + get => TimeSpan.FromDays(expDays); + } + + #endregion Protected Properties + + #region Protected Methods + + protected void setExpDays() + { + ConfigGetVal("cookieDayExpire", ref expDays); + } + + #endregion Protected Methods + #region Private Fields private static Logger Log = LogManager.GetCurrentClassLogger();