diff --git a/MP.AppAuth/HwSwInfo.cs b/MP.AppAuth/HwSwInfo.cs index c08ebfbe..464ff70c 100644 --- a/MP.AppAuth/HwSwInfo.cs +++ b/MP.AppAuth/HwSwInfo.cs @@ -46,13 +46,6 @@ namespace MP.AppAuth #endregion Public Constructors -#if false - /// - /// Singleton! - /// - public static HwSwInfo man = new HwSwInfo(); -#endif - #region Public Properties /// diff --git a/MP.Land/Data/AppAuthService.cs b/MP.Land/Data/AppAuthService.cs index 74092871..3c052c46 100644 --- a/MP.Land/Data/AppAuthService.cs +++ b/MP.Land/Data/AppAuthService.cs @@ -1,19 +1,15 @@ using Microsoft.Extensions.Configuration; -using System; using Microsoft.Extensions.Logging; +using MP.AppAuth.Controllers; +using MP.AppAuth.Models; +using Newtonsoft.Json; +using NLog; +using StackExchange.Redis; +using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; -using NLog; -using Microsoft.Extensions.Caching.Distributed; -using Microsoft.Extensions.Caching.Memory; -using System.Diagnostics; -using System.Text; -using Newtonsoft.Json; -using System.Diagnostics.Eventing.Reader; -using MP.AppAuth.Models; -using StackExchange.Redis; -using MP.AppAuth.Controllers; namespace MP.Land.Data { @@ -24,15 +20,15 @@ namespace MP.Land.Data // diritti (cablòato) public const string RoleSuperAdmin = "MoonPro_SuperAdmin"; - public static AppAuth.Controllers.AppAuthController dbController; - public static AppAuth.Controllers.MPController MpDbController; - public static AppAuth.Controllers.MPUserController userController; + public static AppAuthController dbController; + public static MPController MpDbController; + public static MPUserController userController; #endregion Public Fields #region Public Constructors - public AppAuthService(IConfiguration configuration, ILogger logger, IConnectionMultiplexer redisConnMult, IMemoryCache memoryCache, IDistributedCache distributedCache) + public AppAuthService(IConfiguration configuration, ILogger logger, IConnectionMultiplexer redisConnMult) { _logger = logger; _configuration = configuration; @@ -51,11 +47,6 @@ namespace MP.Land.Data ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; -#if false - // conf cache - this.memoryCache = memoryCache; - this.distributedCache = distributedCache; -#endif // conf DB string connStr = _configuration.GetConnectionString("MP.Land"); if (string.IsNullOrEmpty(connStr)) @@ -241,16 +232,6 @@ namespace MP.Land.Data { source = "REDIS"; var tempResult = JsonConvert.DeserializeObject>(rawData); -#if false - if (tempResult == null) - { - dbResult = new List(); - } - else - { - dbResult = tempResult; - } -#endif dbResult = tempResult ?? new List(); } else @@ -330,10 +311,6 @@ namespace MP.Land.Data { RedisValue pattern = new RedisValue($"{redisBaseAddr}:*"); bool answ = await ExecFlushRedisPattern(pattern); -#if false - string cacheKey = ":MP:VOCAB"; - await distributedCache.RemoveAsync(cacheKey); -#endif // reset in RAM Vocabolario = new Dictionary(); await CheckVoc(); @@ -485,11 +462,6 @@ namespace MP.Land.Data private static Logger Log = LogManager.GetCurrentClassLogger(); private static string Modulo = ""; -#if false - private readonly IDistributedCache distributedCache; - - private readonly IMemoryCache memoryCache; -#endif /// /// Durata cache lunga IN SECONDI @@ -501,19 +473,6 @@ namespace MP.Land.Data /// private int cacheTtlShort = 60 * 1; -#if false - /// - /// Durata assoluta massima della cache - /// - private int chAbsExp = 15; - - /// - /// Durata della cache in modalità inattiva (non acceduta) prima di venire rimossa NON - /// estende oltre il tempo massimo di validità della cache (chAbsExp) - /// - private int chSliExp = 5; -#endif - /// /// Oggetto per connessione a REDIS /// @@ -532,24 +491,6 @@ namespace MP.Land.Data #region Private Properties -#if false - private DistributedCacheEntryOptions cacheOpt - { - get - { - return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddMinutes(chAbsExp)).SetSlidingExpiration(TimeSpan.FromMinutes(chSliExp)); - } - } - - private DistributedCacheEntryOptions cacheOptLong - { - get - { - return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddMinutes(chAbsExp * 10)).SetSlidingExpiration(TimeSpan.FromMinutes(chSliExp)); - } - } -#endif - private string CodApp { get; set; } = ""; /// diff --git a/MP.Land/Data/LicenseService.cs b/MP.Land/Data/LicenseService.cs index ede92400..440e8a88 100644 --- a/MP.Land/Data/LicenseService.cs +++ b/MP.Land/Data/LicenseService.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging; using MP.AppAuth.Models; using Newtonsoft.Json; using RestSharp; +using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; @@ -28,12 +29,20 @@ namespace MP.Land.Data /// /// /// - /// - public LicenseService(IConfiguration configuration, ILogger logger, IDistributedCache distributedCache) + /// + public LicenseService(IConfiguration configuration, ILogger logger, IConnectionMultiplexer redisConnMult) { _logger = logger; _configuration = configuration; - this.distributedCache = distributedCache; + // Conf cache + redisConn = redisConnMult; + redisDb = this.redisConn.GetDatabase(); + + // json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/ + JSSettings = new JsonSerializerSettings() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }; } #endregion Public Constructors @@ -281,7 +290,8 @@ namespace MP.Land.Data bool fatto = false; string cacheKey = $"{rKeyAttByLic}:{MasterKey}"; var rawData = JsonConvert.SerializeObject(newActList); - await setRSV(cacheKey, rawData, numDays * cacheFact * 24); + TimeSpan cacheTs = TimeSpan.FromDays(numDays); + await setRSV(cacheKey, rawData, cacheTs); fatto = true; if (EA_InfoUpdated != null) { @@ -295,7 +305,8 @@ namespace MP.Land.Data bool fatto = false; string cacheKey = $"{rkeyAppInfo}:{MasterKey}"; var rawData = JsonConvert.SerializeObject(newAppInfo); - await setRSV(cacheKey, rawData, numDays * cacheFact * 24); + TimeSpan cacheTs = TimeSpan.FromDays(numDays); + await setRSV(cacheKey, rawData, cacheTs); fatto = true; if (EA_InfoUpdated != null) { @@ -362,12 +373,8 @@ namespace MP.Land.Data /// protected async Task getRSV(string rKey) { - string answ = ""; - var redisDataList = await distributedCache.GetAsync(rKey); - if (redisDataList != null) - { - answ = Encoding.UTF8.GetString(redisDataList); - } + var rawData = await redisDb.StringGetAsync(rKey); + string answ = rawData.HasValue ? $"{rawData}" : ""; return answ; } @@ -376,14 +383,11 @@ namespace MP.Land.Data /// /// /// - /// + /// /// - protected async Task setRSV(string rKey, string rVal, int cacheMult) + protected async Task setRSV(string rKey, string rVal, TimeSpan cacheTS) { - bool fatto = false; - var redisDataList = Encoding.UTF8.GetBytes(rVal); - await distributedCache.SetAsync(rKey, redisDataList, cacheOpt(cacheMult)); - fatto = true; + bool fatto = await redisDb.StringSetAsync(rKey, rVal, cacheTS); return fatto; } @@ -392,14 +396,11 @@ namespace MP.Land.Data /// /// /// - /// + /// /// - protected async Task setRSV(string rKey, int rValInt, int cacheMult) + protected async Task setRSV(string rKey, int rValInt, TimeSpan cacheTS) { - bool fatto = false; - var redisDataList = Encoding.UTF8.GetBytes($"{rValInt}"); - await distributedCache.SetAsync(rKey, redisDataList, cacheOpt(cacheMult)); - fatto = true; + bool fatto = await setRSV(rkeyAppInfo, $"{rValInt}", cacheTS); return fatto; } @@ -426,34 +427,40 @@ namespace MP.Land.Data /// private static string apiUrl = "https://liman.egalware.com/ELM.API/"; + private static JsonSerializerSettings? JSSettings; + /// /// Chiave redis x info della licenza /// private static string rkeyAppInfo = "LongCache:AppInfo"; - //private static string apiUrl = "https://localhost:44351/"; - private readonly IDistributedCache distributedCache; - /// /// Elenco obj in cache /// private List cachedDataList = new List(); /// - /// Fattorte conversione cache sliding --> 1 h + /// Durata cache lunga IN SECONDI /// - private int cacheFact = 12; + private int cacheTtlLong = 60 * 5; /// - /// Durata assoluta massima della cache IN SECONDI + /// Durata cache breve IN SECONDI /// - private int chAbsExp = 60 * 5; + private int cacheTtlShort = 60 * 1; /// - /// Durata della cache IN SECONDI in modalità inattiva (non acceduta) prima di venire - /// rimossa NON estende oltre il tempo massimo di validità della cache (chAbsExp) + /// Oggetto per connessione a REDIS /// - private int chSliExp = 60 * 1; + private IConnectionMultiplexer redisConn; + + //ISubscriber sub = redis.GetSubscriber(); + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + private IDatabase redisDb = null!; + + private Random rnd = new Random(); #endregion Private Fields @@ -465,18 +472,6 @@ namespace MP.Land.Data #region Private Methods - /// - /// Opzioni cache con moltiplicatore durata risp durata base (1/5 minuti) - /// - /// - /// - private DistributedCacheEntryOptions cacheOpt(int multFact) - { - var numSecAbsExp = chAbsExp * multFact; - var numSecSliExp = chSliExp * multFact; - return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp)); - } - /// /// Elenco attivazioni attuali /// diff --git a/MP.Land/MP.Land.csproj b/MP.Land/MP.Land.csproj index 6e529e7a..e5d70a47 100644 --- a/MP.Land/MP.Land.csproj +++ b/MP.Land/MP.Land.csproj @@ -3,7 +3,7 @@ net6.0 MP.Land - 6.16.2409.0317 + 6.16.2409.0318 @@ -51,11 +51,11 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/MP.Land/Resources/ChangeLog.html b/MP.Land/Resources/ChangeLog.html index 9f01dd6e..8eb6498d 100644 --- a/MP.Land/Resources/ChangeLog.html +++ b/MP.Land/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo Tablet MAPO - DotNet6 -

Versione: 6.16.2409.0317

+

Versione: 6.16.2409.0318


Note di rilascio:
    diff --git a/MP.Land/Resources/VersNum.txt b/MP.Land/Resources/VersNum.txt index ca913415..55015945 100644 --- a/MP.Land/Resources/VersNum.txt +++ b/MP.Land/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2409.0317 +6.16.2409.0318 diff --git a/MP.Land/Resources/manifest.xml b/MP.Land/Resources/manifest.xml index 92dd3a11..97d8c1c7 100644 --- a/MP.Land/Resources/manifest.xml +++ b/MP.Land/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2409.0317 + 6.16.2409.0318 https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/MP.Land.zip https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/ChangeLog.html false diff --git a/MP.Land/Startup.cs b/MP.Land/Startup.cs index 96c09590..50e8e855 100644 --- a/MP.Land/Startup.cs +++ b/MP.Land/Startup.cs @@ -118,14 +118,6 @@ namespace MP.Land options.FallbackPolicy = options.DefaultPolicy; }); - - services.AddStackExchangeRedisCache(options => - { - //options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions() { KeepAlive = 180, DefaultDatabase = 1, EndPoints = { { "localhost", 6379 } } }; - options.Configuration = Configuration["ConnectionStrings:Redis"]; - options.InstanceName = "MP:Land"; - }); - // REDIS setup string connStringRedis = Configuration.GetConnectionString("Redis"); string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));