101 lines
3.0 KiB
C#
101 lines
3.0 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using Microsoft.Extensions.Logging;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using NLog;
|
|
using Microsoft.Extensions.Caching.Distributed;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
namespace MP.Land.Data
|
|
{
|
|
public class AppAuthService : IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
|
|
private static ILogger<AppAuthService> _logger;
|
|
|
|
private static List<MP.AppAuth.Models.Macchine> ElencoMacchine = new List<MP.AppAuth.Models.Macchine>();
|
|
|
|
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 Public Fields
|
|
|
|
public static AppAuth.Controllers.AppAuthController dbController;
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public AppAuthService(IConfiguration configuration, ILogger<AppAuthService> logger, IMemoryCache memoryCache, IDistributedCache distributedCache)
|
|
{
|
|
_logger = logger;
|
|
_configuration = configuration;
|
|
// conf cache
|
|
this.memoryCache = memoryCache;
|
|
this.distributedCache = distributedCache;
|
|
// conf DB
|
|
string connStr = _configuration.GetConnectionString("MP.Land");
|
|
if (string.IsNullOrEmpty(connStr))
|
|
{
|
|
_logger.LogError("ConnString empty!");
|
|
}
|
|
else
|
|
{
|
|
dbController = new AppAuth.Controllers.AppAuthController(configuration);
|
|
_logger.LogInformation("DbController OK");
|
|
}
|
|
}
|
|
|
|
#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 Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |