using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using IceImportDAL.DTO.IceMapFtpSource; using IceImportDAL.Query.IceMapFtpSource; namespace IceImportDAL.CustomCode.IceMapFtpSource; public class IceMapFtpSourceDAL : IIceMapFtpSourceDAL { private readonly IQueryExecutor _qe; public IceMapFtpSourceDAL(IQueryExecutor qe) => _qe = qe; public async Task GetByIceMapIdAsync(int iceMapId, LoginDTO login, CancellationToken ct) => await _qe.QuerySingleAsync( login, IceMapFtpSourceQB.GET_BY_ICEMAPID, new { IceMapId = iceMapId }, cancellationToken: ct) .ConfigureAwait(false); public async Task SaveAsync(MicemapFtpSourceDTO config, LoginDTO login, CancellationToken ct) => await _qe.ExecuteAsync(login, IceMapFtpSourceQB.SAVE, new { config.IceMapId, config.ConnectionType, config.HostVaultRef, config.UsernameVaultRef, config.CredentialVaultRef, config.RemoteFolderPath, config.FileNamePattern, config.PostProcessAction, config.ArchiveFolderPath }, cancellationToken: ct).ConfigureAwait(false); public async Task IsFileAlreadyProcessedAsync( int iceMapId, string remoteFileName, DateTime? lastModifiedUtc, LoginDTO login, CancellationToken ct) { var stored = await _qe.QueryAsync( login, IceMapFtpSourceQB.GET_PROCESSED_LAST_MODIFIED, new { IceMapId = iceMapId, RemoteFileName = remoteFileName }, cancellationToken: ct) .ConfigureAwait(false); // QueryAsync (not QuerySingleAsync) so "no row yet" (never processed) is a plain empty // sequence rather than an exception — QuerySingleAsync semantics for zero rows are not // guaranteed safe here across every IQueryExecutor implementation. if (!stored.Any()) return false; var storedLastModified = stored.First(); return storedLastModified == lastModifiedUtc; } public async Task MarkFileProcessedAsync( int iceMapId, string remoteFileName, DateTime? lastModifiedUtc, long? runId, LoginDTO login, CancellationToken ct) => await _qe.ExecuteAsync(login, IceMapFtpSourceQB.MARK_PROCESSED, new { IceMapId = iceMapId, RemoteFileName = remoteFileName, RemoteFileLastModifiedUtc = lastModifiedUtc, RunId = runId }, cancellationToken: ct).ConfigureAwait(false); }