92 lines
2.8 KiB
C#
92 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Configuration;
|
|
using System.Text;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using GWMS.Data;
|
|
using Microsoft.Extensions.Caching.Distributed;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Newtonsoft.Json;
|
|
using System.Diagnostics;
|
|
using NLog;
|
|
|
|
namespace GWMS.UI.Data
|
|
{
|
|
public class GWMSDataService
|
|
{
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
private static ILogger<GWMSDataService> _logger;
|
|
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
private readonly IDistributedCache distributedCache;
|
|
private readonly IMemoryCache memoryCache;
|
|
|
|
/// <summary>
|
|
/// Durata assoluta massima della cache
|
|
/// </summary>
|
|
private int chAbsExp = 15;
|
|
|
|
/// <summary>
|
|
/// Durata della cache in modalità inattiva (non acceduta) prima di venire rimossa
|
|
/// NON estende oltre il tempo massimo di validità della cache (chAbsExp)
|
|
/// </summary>
|
|
private int chSliExp = 5;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Protected Fields
|
|
|
|
protected static string connStringBBM = "";
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Public Fields
|
|
|
|
public static GWMS.Data.Controllers.GWMSController dbController;
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public GWMSDataService(IConfiguration configuration, ILogger<GWMSDataService> logger, IMemoryCache memoryCache, IDistributedCache distributedCache)
|
|
{
|
|
_logger = logger;
|
|
_configuration = configuration;
|
|
// conf cache
|
|
this.memoryCache = memoryCache;
|
|
this.distributedCache = distributedCache;
|
|
// conf DB
|
|
string connStr = _configuration.GetConnectionString("GWMS.Data");
|
|
if (string.IsNullOrEmpty(connStr))
|
|
{
|
|
_logger.LogError("ConnString empty!");
|
|
}
|
|
else
|
|
{
|
|
dbController = new GWMS.Data.Controllers.GWMSController(configuration);
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine($"DbController OK");
|
|
_logger.LogInformation(sb.ToString());
|
|
}
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Private Properties
|
|
|
|
private DistributedCacheEntryOptions cacheOpt
|
|
{
|
|
get
|
|
{
|
|
return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddMinutes(chAbsExp)).SetSlidingExpiration(TimeSpan.FromMinutes(chSliExp));
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
}
|
|
} |