using FrameworkDAL.Query.Archive; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using System; using System.Data.Common; using System.Threading; using System.Threading.Tasks; namespace FrameworkDAL.CustomCode.Archive { public sealed class EventLogArchiveDAL : IEventLogArchiveDAL { private readonly IQueryExecutor _qe; public EventLogArchiveDAL(IQueryExecutor qe) => _qe = qe; public Task MoveToArchiveAsync( DateTime cutoffDate, LoginDTO login, DbTransaction tx, CancellationToken ct = default) => _qe.ExecuteAsync( login, EventLogArchiveQB.INSERT_ARCHIVE, new { TenantId = login.ClientId, CutoffDate = cutoffDate }, tx, cancellationToken: ct); public Task DeleteHotRowsAsync( DateTime cutoffDate, LoginDTO login, DbTransaction tx, CancellationToken ct = default) => _qe.ExecuteAsync( login, EventLogArchiveQB.DELETE_HOT, new { TenantId = login.ClientId, CutoffDate = cutoffDate }, tx, cancellationToken: ct); public async Task<(int HotCount, int ArchiveCount)> GetStatsAsync( LoginDTO login, CancellationToken ct = default) { var row = await _qe.QuerySingleAsync( login, EventLogArchiveQB.GET_STATS, new { TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); return ((int)row.HotCount, (int)row.ArchiveCount); } } }