69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
using EgwCoreLib.Lux.Data.DbModel.Utils;
|
|
using EgwCoreLib.Lux.Data.Repository.Utils;
|
|
using Microsoft.Extensions.Configuration;
|
|
using StackExchange.Redis;
|
|
|
|
namespace EgwCoreLib.Lux.Data.Services.Utils
|
|
{
|
|
public class CounterService : BaseServ, ICounterService
|
|
{
|
|
#region Public Constructors
|
|
|
|
public CounterService(
|
|
IConfiguration config,
|
|
IConnectionMultiplexer redis,
|
|
ICounterRepository repo) : base(config, redis)
|
|
{
|
|
_className = "Counter";
|
|
_repo = repo;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Elenco contatori
|
|
/// </summary>
|
|
/// <param name="yearRef">Anno riferimento, se null da tutti</param>
|
|
/// <returns></returns>
|
|
public async Task<List<CounterModel>> GetAllAsync(int? yearRef = null)
|
|
{
|
|
return await TraceAsync($"{_className}.GetAll", async (activity) =>
|
|
{
|
|
return await GetOrSetCacheAsync(
|
|
$"{_redisBaseKey}:{_className}:ALL:Y{yearRef}",
|
|
async () => await _repo.GetAllAsync(yearRef),
|
|
FastCache
|
|
);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera un nuovo valore del contatore per tipo ed anno richiesto, se mancasse crea
|
|
/// </summary>
|
|
/// <param name="yearRef">Anno riferimento</param>
|
|
/// <param name="countName">Counter richiesto</param>
|
|
/// <returns></returns>
|
|
public async Task<int> GetNextAsync(int yearRef, string countName)
|
|
{
|
|
return await TraceAsync($"{_className}.GetNextAsync", async (activity) =>
|
|
{
|
|
return await GetOrSetCacheAsync(
|
|
$"{_redisBaseKey}:{_className}:{countName}:Y{yearRef}",
|
|
async () => await _repo.GetNextAsync(yearRef, countName),
|
|
UltraFastCache
|
|
);
|
|
});
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly string _className;
|
|
private readonly ICounterRepository _repo;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |