update gestione pref utente su redis
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>6.16.2311.708</Version>
|
||||
<Version>6.16.2311.709</Version>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>MP_TAB_SERV</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@page "/odl"
|
||||
|
||||
<MseSampler SampleMult="0.5" E_Updated="RefreshData"></MseSampler>
|
||||
<MseSampler SampleMult="0.05" E_Updated="RefreshData"></MseSampler>
|
||||
@if (string.IsNullOrEmpty(IdxMacc) || CurrMSE == null)
|
||||
{
|
||||
<EgwCoreLib.Razor.LoadingData></EgwCoreLib.Razor.LoadingData>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MAPOSPEC </i>
|
||||
<h4>Versione: 6.16.2311.708</h4>
|
||||
<h4>Versione: 6.16.2311.709</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2311.708
|
||||
6.16.2311.709
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2311.708</version>
|
||||
<version>6.16.2311.709</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-TAB-SERV/stable/LAST/MP-TAB-SERV.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-TAB-SERV/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using Blazored.LocalStorage;
|
||||
using Blazored.SessionStorage;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Data.DatabaseModels;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Services
|
||||
@@ -13,16 +16,25 @@ namespace MP.Data.Services
|
||||
{
|
||||
#region Public Fields
|
||||
|
||||
public const string KeyCommDtRif = "DtRifComm";
|
||||
public const string KeyCommText = "ValComm";
|
||||
public int orarioDip = 0;
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MessageService(ILocalStorageService genLocalStorage, ISessionStorageService sessStore)
|
||||
public MessageService(IConfiguration configuration, ILocalStorageService genLocalStorage, ISessionStorageService sessStore)
|
||||
{
|
||||
_configuration = configuration;
|
||||
|
||||
// gestione sessioni in browser
|
||||
localStorage = genLocalStorage;
|
||||
sessionStore = sessStore;
|
||||
|
||||
// setup compoenti REDIS
|
||||
redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis"));
|
||||
redisDb = redisConn.GetDatabase();
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
@@ -35,32 +47,21 @@ namespace MP.Data.Services
|
||||
|
||||
#endregion Public Events
|
||||
|
||||
#if false
|
||||
public event Action EA_DateChanged = null!;
|
||||
public event Action EA_CalModeChanged = null!;
|
||||
#region Public Properties
|
||||
|
||||
public event Action EA_TimbUpd = null!;
|
||||
#endif
|
||||
|
||||
#if false
|
||||
public RegAttivitaModel? clonedRA { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Calcola HASH del codice impiego = payload utente
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string HashDip
|
||||
public string CognomeNome
|
||||
{
|
||||
get
|
||||
{
|
||||
DataValidator cDV = new DataValidator(_rigaOper);
|
||||
string hash = cDV.HashDip;
|
||||
return hash;
|
||||
string answ = "";
|
||||
//int answ = -1;
|
||||
if (_rigaOper != null)
|
||||
{
|
||||
answ = $"{_rigaOper.Cognome} {_rigaOper.Nome}";
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario macchine
|
||||
@@ -100,19 +101,6 @@ namespace MP.Data.Services
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
public string CognomeNome
|
||||
{
|
||||
get
|
||||
{
|
||||
string answ = "";
|
||||
//int answ = -1;
|
||||
if (_rigaOper != null)
|
||||
{
|
||||
answ = $"{_rigaOper.Cognome} {_rigaOper.Nome}";
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
||||
public AnagOperatoriModel? RigaOper
|
||||
{
|
||||
@@ -141,6 +129,15 @@ namespace MP.Data.Services
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario totale preferenze utente
|
||||
/// </summary>
|
||||
public Dictionary<string, string> UsersPrefDict
|
||||
{
|
||||
get => redisHashDictGet((RedisKey)$"{redisBaseKey}:{MatrOpr}");
|
||||
set => redisHashDictSet((RedisKey)$"{redisBaseKey}:{MatrOpr}", value);
|
||||
}
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
@@ -184,18 +181,6 @@ namespace MP.Data.Services
|
||||
await sessionStore.SetItemAsync(KeyCommDtRif, DtRif);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifico esistenza chiave in session store
|
||||
/// </summary>
|
||||
/// <param name="keyName"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SessHasVal(string keyName)
|
||||
{
|
||||
bool hasKey = await sessionStore.ContainKeyAsync(keyName);
|
||||
return hasKey;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Commento fermata x recupero in editing
|
||||
/// </summary>
|
||||
@@ -303,6 +288,17 @@ namespace MP.Data.Services
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifico esistenza chiave in session store
|
||||
/// </summary>
|
||||
/// <param name="keyName"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SessHasVal(string keyName)
|
||||
{
|
||||
bool hasKey = await sessionStore.ContainKeyAsync(keyName);
|
||||
return hasKey;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scrive il valore di IPV4 del device nel localstoragee
|
||||
/// </summary>
|
||||
@@ -343,6 +339,44 @@ namespace MP.Data.Services
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero singola preferenza utente
|
||||
/// </summary>
|
||||
/// <param name="chiave"></param>
|
||||
/// <returns></returns>
|
||||
public string UserPrefGet(string chiave)
|
||||
{
|
||||
string answ = "";
|
||||
var currDict = UsersPrefDict;
|
||||
if (currDict.ContainsKey(chiave))
|
||||
{
|
||||
answ = currDict[chiave];
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Salvo singola rpeferenza utente
|
||||
/// </summary>
|
||||
/// <param name="chiave"></param>
|
||||
/// <param name="valore"></param>
|
||||
/// <returns></returns>
|
||||
public bool UserPrefSave(string chiave, string valore)
|
||||
{
|
||||
bool done = false;
|
||||
var currDict = UsersPrefDict;
|
||||
if (currDict.ContainsKey(chiave))
|
||||
{
|
||||
currDict[chiave] = valore;
|
||||
}
|
||||
else
|
||||
{
|
||||
currDict.Add(chiave, valore);
|
||||
UsersPrefDict = currDict;
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
@@ -350,20 +384,130 @@ namespace MP.Data.Services
|
||||
protected const string KeyDevIp4 = "DevIpv4";
|
||||
protected const string KeyDevSec = "DevSec";
|
||||
protected const string KeyMacDict = "MachineDict";
|
||||
protected static IConfiguration _configuration = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto per connessione a REDIS
|
||||
/// </summary>
|
||||
protected ConnectionMultiplexer redisConn = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto DB redis da impiegare x chiamate R/W
|
||||
/// </summary>
|
||||
protected IDatabase redisDb = null!;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected ILocalStorageService localStorage { get; set; } = null!;
|
||||
|
||||
protected ISessionStorageService sessionStore { get; set; } = null!;
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Private Fields
|
||||
|
||||
public const string KeyCommDtRif = "DtRifComm";
|
||||
public const string KeyCommText = "ValComm";
|
||||
private AnagOperatoriModel? _rigaOper;
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache lunga IN SECONDI
|
||||
/// </summary>
|
||||
private int cacheTtlLong = 60 * 5;
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache breve IN SECONDI
|
||||
/// </summary>
|
||||
private int cacheTtlShort = 60 * 1;
|
||||
|
||||
private Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private string redisBaseKey = "MP:TAB:User";
|
||||
private Random rnd = new Random();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string machineMse(string idxMacc)
|
||||
{
|
||||
return $"MSE_{idxMacc}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero HashSet redis come Dictionary
|
||||
/// </summary>
|
||||
/// <param name="currKey"></param>
|
||||
/// <param name="dict"></param>
|
||||
private Dictionary<string, string> redisHashDictGet(RedisKey currKey)
|
||||
{
|
||||
Dictionary<string, string> answ = new Dictionary<string, string>();
|
||||
try
|
||||
{
|
||||
answ = redisDb
|
||||
.HashGetAll(currKey)
|
||||
.ToDictionary(x => $"{x.Name}", x => $"{x.Value}");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Info($"Errore redisHashDictGet | currKey: {currKey}{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Salvataggio Dictionary come HashSet Redis
|
||||
/// </summary>
|
||||
/// <param name="currKey"></param>
|
||||
/// <param name="dict"></param>
|
||||
private bool redisHashDictSet(RedisKey currKey, Dictionary<string, string> dict)
|
||||
{
|
||||
bool fatto = false;
|
||||
try
|
||||
{
|
||||
HashEntry[] data2ins = new HashEntry[dict.Count];
|
||||
int i = 0;
|
||||
foreach (KeyValuePair<string, string> kvp in dict)
|
||||
{
|
||||
data2ins[i] = new HashEntry(kvp.Key, kvp.Value);
|
||||
i++;
|
||||
}
|
||||
// salvo!
|
||||
redisDb.HashSet(currKey, data2ins);
|
||||
fatto = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in redisHashDictSet | currKey: {currKey}{Environment.NewLine}{exc}");
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#if false
|
||||
public event Action EA_DateChanged = null!;
|
||||
public event Action EA_CalModeChanged = null!;
|
||||
|
||||
public event Action EA_TimbUpd = null!;
|
||||
#endif
|
||||
|
||||
#if false
|
||||
public RegAttivitaModel? clonedRA { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Calcola HASH del codice impiego = payload utente
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string HashDip
|
||||
{
|
||||
get
|
||||
{
|
||||
DataValidator cDV = new DataValidator(_rigaOper);
|
||||
string hash = cDV.HashDip;
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if false
|
||||
public bool IsActive
|
||||
{
|
||||
@@ -546,21 +690,6 @@ namespace MP.Data.Services
|
||||
}
|
||||
}
|
||||
#endif
|
||||
private AnagOperatoriModel? _rigaOper;
|
||||
|
||||
private Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string machineMse(string idxMacc)
|
||||
{
|
||||
return $"MSE_{idxMacc}";
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#if false
|
||||
private string _pageIcon = "";
|
||||
private string _pageName = "";
|
||||
|
||||
Reference in New Issue
Block a user