From 0d1e9f07730789cb22b95ebefeb706d598515bf1 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 4 Sep 2024 09:06:23 +0200 Subject: [PATCH] PROG: - update NLog - update nuget vari --- MP.FileData/MP.FileData.csproj | 15 +- MP.Prog/Data/FileArchDataService.cs | 226 ++++++++++++++-------------- MP.Prog/MP.Prog.csproj | 16 +- MP.Prog/NLog.config | 46 ------ MP.Prog/Program.cs | 7 +- MP.Prog/Resources/ChangeLog.html | 2 +- MP.Prog/Resources/VersNum.txt | 2 +- MP.Prog/Resources/manifest.xml | 2 +- MP.Prog/Startup.cs | 20 ++- MP.Prog/appsettings.json | 73 +++++++-- 10 files changed, 210 insertions(+), 199 deletions(-) delete mode 100644 MP.Prog/NLog.config diff --git a/MP.FileData/MP.FileData.csproj b/MP.FileData/MP.FileData.csproj index 529ef021..2b9b560a 100644 --- a/MP.FileData/MP.FileData.csproj +++ b/MP.FileData/MP.FileData.csproj @@ -6,20 +6,19 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index 3839ea0d..4c0ac100 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -14,46 +14,12 @@ using System.Threading.Tasks; using System.Diagnostics; using MP.FileData.Controllers; using MP.FileData.DTO; +using StackExchange.Redis; namespace MP.Prog.Data { public class FileArchDataService : IDisposable { - #region Private Fields - - private static IConfiguration _configuration; - - private static ILogger _logger; - - private static List ElencoMacchine = new List(); - - private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - - private readonly IDistributedCache distributedCache; - - private readonly IMemoryCache memoryCache; - - /// - /// 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; - - #endregion Private Fields - - #region Protected Fields - - protected static string connStringBBM = ""; - - protected static string connStringFatt = ""; - - #endregion Protected Fields - #region Public Fields public static FileData.Controllers.FileController dbController; @@ -62,13 +28,15 @@ namespace MP.Prog.Data #region Public Constructors - public FileArchDataService(IConfiguration configuration, ILogger logger, IMemoryCache memoryCache, IDistributedCache distributedCache) + public FileArchDataService(IConfiguration configuration, ILogger logger, IConnectionMultiplexer redisConnMult) { _logger = logger; _configuration = configuration; - // conf cache - this.memoryCache = memoryCache; - this.distributedCache = distributedCache; + + // Conf cache + redisConn = redisConnMult; + redisDb = this.redisConn.GetDatabase(); + // conf DB string connStr = _configuration.GetConnectionString("MP.Prog"); if (string.IsNullOrEmpty(connStr)) @@ -84,60 +52,6 @@ namespace MP.Prog.Data #endregion Public Constructors - #region Private Properties - - 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)); - } - } - - #endregion Private Properties - - #region Internal Methods - - internal Task FileApprove(FileData.DatabaseModels.FileModel currItem) - { - return Task.FromResult(dbController.FileModApprove(currItem)); - } - - internal Task FileDelete(FileData.DatabaseModels.FileModel currItem) - { - return Task.FromResult(dbController.FileDelete(currItem)); - } - - internal Task FileExport(FileData.DatabaseModels.FileModel currItem) - { - return Task.FromResult(dbController.FileExport(currItem)); - } - - internal Task FileReject(FileData.DatabaseModels.FileModel currItem) - { - return Task.FromResult(dbController.FileModReject(currItem)); - } - - internal Task FileUpdate(FileData.DatabaseModels.FileModel updItem) - { - return Task.FromResult(dbController.FileUpdate(updItem)); - } - - internal void ResetController() - { - dbController.ResetController(); - } - - #endregion Internal Methods - #region Public Methods public void Dispose() @@ -227,24 +141,12 @@ namespace MP.Prog.Data return Task.FromResult(answ); } -#if false - protected string getCacheKey(string TableName, SelectData CurrFilter) - { - string answ = $"{TableName}:M_{CurrFilter.IdxMacchina}:A_{CurrFilter.CodArticolo}:K_{CurrFilter.KeyRichiesta}:O_{CurrFilter.IdxOdl}:D_{CurrFilter.DateStart:yyyyMMddHHmm}_{CurrFilter.DateEnd:yyyyMMddHHmm}"; - return answ; - } - - protected string getCacheKeyPaged(string TableName, SelectData CurrFilter) - { - string answ = $"{TableName}:M_{CurrFilter.IdxMacchina}:A_{CurrFilter.CodArticolo}:K_{CurrFilter.KeyRichiesta}:O_{CurrFilter.IdxOdl}:D_{CurrFilter.DateStart:yyMMddHHmm}_{CurrFilter.DateEnd:yyMMddHHmm}:R_{CurrFilter.FirstRecord}_{CurrFilter.FirstRecord + CurrFilter.NumRecord}"; - return answ; - } -#endif - /// /// Aggiorna intero archivio scansionando dati x tutte le macchine che hanno un path valido /// - /// Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite + /// + /// Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite + /// /// public async Task updateAllArchive(int numDayPre, bool forceTag) { @@ -262,7 +164,9 @@ namespace MP.Prog.Data /// Aggiorna archivio di una amcchina scansionando path relativo /// /// Codice macchina - /// Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite + /// + /// Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite + /// /// Forza la riverifica dei tags (x update da setup) /// Scrittura log verboso macchina /// @@ -342,5 +246,109 @@ namespace MP.Prog.Data } #endregion Public Methods + + #region Internal Methods + + internal Task FileApprove(FileData.DatabaseModels.FileModel currItem) + { + return Task.FromResult(dbController.FileModApprove(currItem)); + } + + internal Task FileDelete(FileData.DatabaseModels.FileModel currItem) + { + return Task.FromResult(dbController.FileDelete(currItem)); + } + + internal Task FileExport(FileData.DatabaseModels.FileModel currItem) + { + return Task.FromResult(dbController.FileExport(currItem)); + } + + internal Task FileReject(FileData.DatabaseModels.FileModel currItem) + { + return Task.FromResult(dbController.FileModReject(currItem)); + } + + internal Task FileUpdate(FileData.DatabaseModels.FileModel updItem) + { + return Task.FromResult(dbController.FileUpdate(updItem)); + } + + internal void ResetController() + { + dbController.ResetController(); + } + + #endregion Internal Methods + + #region Protected Fields + + protected static string connStringBBM = ""; + protected static string connStringFatt = ""; + + #endregion Protected Fields + + #region Private Fields + + private static IConfiguration _configuration; + + private static ILogger _logger; + + private static List ElencoMacchine = new List(); + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + /// + /// Durata cache lunga IN SECONDI + /// + private int cacheTtlLong = 60 * 5; + + /// + /// Durata cache breve IN SECONDI + /// + private int cacheTtlShort = 60 * 1; + + /// + /// Oggetto per connessione a REDIS + /// + 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 + + #region Private Properties + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan FastCache + { + get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000); + } + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan LongCache + { + get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000); + } + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan UltraLongCache + { + get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000); + } + + #endregion Private Properties } } \ No newline at end of file diff --git a/MP.Prog/MP.Prog.csproj b/MP.Prog/MP.Prog.csproj index 57016ff1..b4b1a161 100644 --- a/MP.Prog/MP.Prog.csproj +++ b/MP.Prog/MP.Prog.csproj @@ -3,7 +3,7 @@ net6.0 MP.Prog - 6.16.2402.1919 + 6.16.2409.0409 @@ -18,15 +18,11 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - + + + + + diff --git a/MP.Prog/NLog.config b/MP.Prog/NLog.config deleted file mode 100644 index b32ba10a..00000000 --- a/MP.Prog/NLog.config +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MP.Prog/Program.cs b/MP.Prog/Program.cs index 514283f1..904ca0f8 100644 --- a/MP.Prog/Program.cs +++ b/MP.Prog/Program.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using NLog; using NLog.Web; using System; using System.Collections.Generic; @@ -30,9 +31,9 @@ namespace MP.Prog public static void Main(string[] args) { // inclusione NLog: - // https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-5 - // https://codewithmukesh.com/blog/logging-with-nlog-in-aspnet-core/ - var logger = NLog.Web.NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger(); + var logger = LogManager.Setup() + .LoadConfigurationFromAppSettings() + .GetCurrentClassLogger(); try { logger.Info("MP.Prog Application Starting Up"); diff --git a/MP.Prog/Resources/ChangeLog.html b/MP.Prog/Resources/ChangeLog.html index 744b45bd..5883b33b 100644 --- a/MP.Prog/Resources/ChangeLog.html +++ b/MP.Prog/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo gestione Programmi MAPO -

Versione: 6.16.2402.1919

+

Versione: 6.16.2409.0409


Note di rilascio:
    diff --git a/MP.Prog/Resources/VersNum.txt b/MP.Prog/Resources/VersNum.txt index dad8f7b3..5916d145 100644 --- a/MP.Prog/Resources/VersNum.txt +++ b/MP.Prog/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2402.1919 +6.16.2409.0409 diff --git a/MP.Prog/Resources/manifest.xml b/MP.Prog/Resources/manifest.xml index aa988e2a..e880d563 100644 --- a/MP.Prog/Resources/manifest.xml +++ b/MP.Prog/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2402.1919 + 6.16.2409.0409 https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/MP.Prog.zip https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/ChangeLog.html false diff --git a/MP.Prog/Startup.cs b/MP.Prog/Startup.cs index 88d0719c..c54dcc14 100644 --- a/MP.Prog/Startup.cs +++ b/MP.Prog/Startup.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using MP.Prog.Data; +using StackExchange.Redis; using System; using System.Collections.Generic; using System.Globalization; @@ -116,12 +117,20 @@ namespace MP.Prog // options.ConnectionString = elmaConn; //}); +#if false services.AddStackExchangeRedisCache(options => - { - //options.Configuration = "localhost:6379"; - options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions() { KeepAlive = 180, DefaultDatabase = 5, EndPoints = { { "localhost", 6379 } } }; - options.InstanceName = "MP:Prog"; - }); + { + //options.Configuration = "localhost:6379"; + options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions() { KeepAlive = 180, DefaultDatabase = 5, EndPoints = { { "localhost", 6379 } } }; + options.InstanceName = "MP:Prog"; + }); +#endif + // REDIS setup + string connStringRedis = Configuration.GetConnectionString("Redis"); + string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":")); + // avvio oggetto shared x redis... + var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis); + services.AddLocalization(); @@ -134,6 +143,7 @@ namespace MP.Prog //services.AddSingleton(); services.AddScoped(); services.AddScoped(); + services.AddSingleton(redisMultiplexer); } #endregion Public Methods diff --git a/MP.Prog/appsettings.json b/MP.Prog/appsettings.json index fed4f415..1f253868 100644 --- a/MP.Prog/appsettings.json +++ b/MP.Prog/appsettings.json @@ -1,18 +1,61 @@ { - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - }, - "AllowedHosts": "*", - "Tags": { - "DefaultSearch": "##" - }, - "ConnectionStrings": { - "DefaultConnection": "Server=SQL2016DEV;Database=MoonPro_PROG;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.Prog;", - "MP.Prog": "Server=SQL2016DEV;Database=MoonPro_PROG;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.Prog;", - "Redis": "localhost:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false" + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" } + }, + "NLog": { + "variables": { + "baseFileDir": "${basedir}/logs/", + "layout": "${longdate} | ${uppercase:${level}} | ${logger:shortName=false} | ${message}" + }, + // "internalLogLevel": "Info", + // "internalLogFile": "c:\\temp\\internal-nlog.txt", + "extensions": [ + { "assembly": "NLog.Extensions.Logging" }, + { "assembly": "NLog.Web.AspNetCore" } + ], + "throwConfigExceptions": true, + "targets": { + "async": true, + "logfile": { + "type": "File", + "fileName": "${basedir}/logs/${shortdate}.log", + "archiveEvery": "Day", + "archiveFileName": "${basedir}/logs/old/${shortdate}_{#}.log", + "archiveNumbering": "DateAndSequence", + "archiveAboveSize": "1024000", + "archiveDateFormat": "HH", + "maxArchiveFiles": "60", + "maxArchiveDays": "30" + }, + "logconsole": { + "type": "ColoredConsole", + "layout": "${longdate} | ${uppercase:${level}} | ${logger:shortName=true} | ${message}" + } + }, + "rules": [ + { + "logger": "*", + "minLevel": "Trace", + "writeTo": "logconsole" + }, + { + "logger": "*", + "minLevel": "Info", + "writeTo": "logfile" + } + ] + }, + "AllowedHosts": "*", + "Tags": { + "DefaultSearch": "##" + }, + "ConnectionStrings": { + "DefaultConnection": "Server=SQL2016DEV;Database=MoonPro_PROG;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.Prog;", + "MP.Prog": "Server=SQL2016DEV;Database=MoonPro_PROG;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.Prog;", + "Redis": "localhost:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false" + } } \ No newline at end of file