using System.Collections.Concurrent; using System.Text.RegularExpressions; using Common.Configuration.ContentBlocker; using Common.Configuration.QueueCleaner; using Domain.Enums; using Infrastructure.Verticals.ContentBlocker; using Infrastructure.Verticals.ItemStriker; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Infrastructure.Verticals.DownloadClient; public abstract class DownloadServiceBase : IDownloadService { protected readonly ILogger _logger; protected readonly QueueCleanerConfig _queueCleanerConfig; protected readonly ContentBlockerConfig _contentBlockerConfig; protected readonly FilenameEvaluator _filenameEvaluator; protected readonly Striker _striker; protected DownloadServiceBase( ILogger logger, IOptions queueCleanerConfig, IOptions contentBlockerConfig, FilenameEvaluator filenameEvaluator, Striker striker ) { _logger = logger; _queueCleanerConfig = queueCleanerConfig.Value; _contentBlockerConfig = contentBlockerConfig.Value; _filenameEvaluator = filenameEvaluator; _striker = striker; } public abstract void Dispose(); public abstract Task LoginAsync(); public abstract Task ShouldRemoveFromArrQueueAsync(string hash); /// public abstract Task BlockUnwantedFilesAsync( string hash, BlocklistType blocklistType, ConcurrentBag patterns, ConcurrentBag regexes ); /// public abstract Task Delete(string hash); /// /// Strikes an item and checks if the limit has been reached. /// /// The torrent hash. /// The name or title of the item. /// True if the limit has been reached; otherwise, false. protected bool StrikeAndCheckLimit(string hash, string itemName) { return _striker.StrikeAndCheckLimit(hash, itemName, _queueCleanerConfig.StalledMaxStrikes, StrikeType.Stalled); } }