fixed merge conflicts

This commit is contained in:
Flaminel
2025-02-26 22:29:24 +02:00
parent c27ee326f7
commit 6b33075a21
9 changed files with 35 additions and 28 deletions
@@ -57,7 +57,7 @@ public class DownloadServiceFixture : IDisposable
var filenameEvaluator = Substitute.For<IFilenameEvaluator>(); var filenameEvaluator = Substitute.For<IFilenameEvaluator>();
var notifier = Substitute.For<INotificationPublisher>(); var notifier = Substitute.For<INotificationPublisher>();
var dryRunInterceptor = Substitute.For<IDryRunInterceptor>(); var dryRunInterceptor = Substitute.For<IDryRunInterceptor>();
var hardlinkFileService = Substitute.For<IHardlinkFileService>(); var hardlinkFileService = Substitute.For<IHardLinkFileService>();
return new TestDownloadService( return new TestDownloadService(
Logger, Logger,
@@ -27,10 +27,10 @@ public class TestDownloadService : DownloadService
IStriker striker, IStriker striker,
INotificationPublisher notifier, INotificationPublisher notifier,
IDryRunInterceptor dryRunInterceptor, IDryRunInterceptor dryRunInterceptor,
IHardlinkFileService hardlinkFileService IHardLinkFileService hardLinkFileService
) : base( ) : base(
logger, queueCleanerConfig, contentBlockerConfig, downloadCleanerConfig, cache, logger, queueCleanerConfig, contentBlockerConfig, downloadCleanerConfig, cache,
filenameEvaluator, striker, notifier, dryRunInterceptor, hardlinkFileService filenameEvaluator, striker, notifier, dryRunInterceptor, hardLinkFileService
) )
{ {
} }
@@ -35,10 +35,10 @@ public class DelugeService : DownloadService, IDelugeService
IStriker striker, IStriker striker,
INotificationPublisher notifier, INotificationPublisher notifier,
IDryRunInterceptor dryRunInterceptor, IDryRunInterceptor dryRunInterceptor,
IHardlinkFileService hardlinkFileService IHardLinkFileService hardLinkFileService
) : base( ) : base(
logger, queueCleanerConfig, contentBlockerConfig, downloadCleanerConfig, cache, logger, queueCleanerConfig, contentBlockerConfig, downloadCleanerConfig, cache,
filenameEvaluator, striker, notifier, dryRunInterceptor, hardlinkFileService filenameEvaluator, striker, notifier, dryRunInterceptor, hardLinkFileService
) )
{ {
config.Value.Validate(); config.Value.Validate();
@@ -252,7 +252,7 @@ public class DelugeService : DownloadService, IDelugeService
continue; continue;
} }
await _dryRunInterceptor.InterceptAsync(DeleteDownload, download.Hash); await _dryRunInterceptor.InterceptAsync(DeleteDownloadAsync, download.Hash);
_logger.LogInformation( _logger.LogInformation(
"download cleaned | {reason} reached | {name}", "download cleaned | {reason} reached | {name}",
@@ -32,7 +32,7 @@ public abstract class DownloadService : IDownloadService
protected readonly MemoryCacheEntryOptions _cacheOptions; protected readonly MemoryCacheEntryOptions _cacheOptions;
protected readonly INotificationPublisher _notifier; protected readonly INotificationPublisher _notifier;
protected readonly IDryRunInterceptor _dryRunInterceptor; protected readonly IDryRunInterceptor _dryRunInterceptor;
protected readonly IHardlinkFileService _hardlinkFileService; protected readonly IHardLinkFileService _hardLinkFileService;
protected DownloadService( protected DownloadService(
ILogger<DownloadService> logger, ILogger<DownloadService> logger,
@@ -44,7 +44,7 @@ public abstract class DownloadService : IDownloadService
IStriker striker, IStriker striker,
INotificationPublisher notifier, INotificationPublisher notifier,
IDryRunInterceptor dryRunInterceptor, IDryRunInterceptor dryRunInterceptor,
IHardlinkFileService hardlinkFileService IHardLinkFileService hardLinkFileService
) )
{ {
_logger = logger; _logger = logger;
@@ -56,7 +56,7 @@ public abstract class DownloadService : IDownloadService
_striker = striker; _striker = striker;
_notifier = notifier; _notifier = notifier;
_dryRunInterceptor = dryRunInterceptor; _dryRunInterceptor = dryRunInterceptor;
_hardlinkFileService = hardlinkFileService; _hardLinkFileService = hardLinkFileService;
_cacheOptions = new MemoryCacheEntryOptions() _cacheOptions = new MemoryCacheEntryOptions()
.SetSlidingExpiration(StaticConfiguration.TriggerValue + Constants.CacheLimitBuffer); .SetSlidingExpiration(StaticConfiguration.TriggerValue + Constants.CacheLimitBuffer);
} }
@@ -26,10 +26,10 @@ public class DummyDownloadService : DownloadService
IStriker striker, IStriker striker,
NotificationPublisher notifier, NotificationPublisher notifier,
IDryRunInterceptor dryRunInterceptor, IDryRunInterceptor dryRunInterceptor,
IHardlinkFileService hardlinkFileService IHardLinkFileService hardLinkFileService
) : base( ) : base(
logger, queueCleanerConfig, contentBlockerConfig, downloadCleanerConfig, logger, queueCleanerConfig, contentBlockerConfig, downloadCleanerConfig,
cache, filenameEvaluator, striker, notifier, dryRunInterceptor, hardlinkFileService cache, filenameEvaluator, striker, notifier, dryRunInterceptor, hardLinkFileService
) )
{ {
} }
@@ -38,10 +38,10 @@ public class QBitService : DownloadService, IQBitService
IStriker striker, IStriker striker,
INotificationPublisher notifier, INotificationPublisher notifier,
IDryRunInterceptor dryRunInterceptor, IDryRunInterceptor dryRunInterceptor,
IHardlinkFileService hardlinkFileService IHardLinkFileService hardLinkFileService
) : base( ) : base(
logger, queueCleanerConfig, contentBlockerConfig, downloadCleanerConfig, cache, logger, queueCleanerConfig, contentBlockerConfig, downloadCleanerConfig, cache,
filenameEvaluator, striker, notifier, dryRunInterceptor, hardlinkFileService filenameEvaluator, striker, notifier, dryRunInterceptor, hardLinkFileService
) )
{ {
_config = config.Value; _config = config.Value;
@@ -286,7 +286,7 @@ public class QBitService : DownloadService, IQBitService
continue; continue;
} }
await _dryRunInterceptor.InterceptAsync(DeleteDownload, download.Hash); await _dryRunInterceptor.InterceptAsync(DeleteDownloadAsync, download.Hash);
_logger.LogInformation( _logger.LogInformation(
"download cleaned | {reason} reached | {name}", "download cleaned | {reason} reached | {name}",
@@ -404,7 +404,7 @@ public class QBitService : DownloadService, IQBitService
continue; continue;
} }
await ((QBitService)Proxy).ChangeCategory(download.Hash, _downloadCleanerConfig.NoHardLinksCategory); await _dryRunInterceptor.InterceptAsync(ChangeCategory, download.Hash, _downloadCleanerConfig.NoHardLinksCategory);
_logger.LogInformation("category changed for {name}", download.Name); _logger.LogInformation("category changed for {name}", download.Name);
@@ -40,10 +40,10 @@ public class TransmissionService : DownloadService, ITransmissionService
IStriker striker, IStriker striker,
INotificationPublisher notifier, INotificationPublisher notifier,
IDryRunInterceptor dryRunInterceptor, IDryRunInterceptor dryRunInterceptor,
IHardlinkFileService hardlinkFileService IHardLinkFileService hardLinkFileService
) : base( ) : base(
logger, queueCleanerConfig, contentBlockerConfig, downloadCleanerConfig, cache, logger, queueCleanerConfig, contentBlockerConfig, downloadCleanerConfig, cache,
filenameEvaluator, striker, notifier, dryRunInterceptor, hardlinkFileService filenameEvaluator, striker, notifier, dryRunInterceptor, hardLinkFileService
) )
{ {
_config = config.Value; _config = config.Value;
@@ -9,4 +9,6 @@ public interface INotificationPublisher
Task NotifyQueueItemDeleted(bool removeFromClient, DeleteReason reason); Task NotifyQueueItemDeleted(bool removeFromClient, DeleteReason reason);
Task NotifyDownloadCleaned(double ratio, TimeSpan seedingTime, string categoryName, CleanReason reason); Task NotifyDownloadCleaned(double ratio, TimeSpan seedingTime, string categoryName, CleanReason reason);
Task NotifyCategoryChanged(string oldCategory, string newCategory);
} }
@@ -48,10 +48,10 @@ public class NotificationPublisher : INotificationPublisher
switch (strikeType) switch (strikeType)
{ {
case StrikeType.Stalled: case StrikeType.Stalled:
await _dryRunInterceptor.InterceptAsync(Notify<StalledStrikeNotification>, notification.Adapt<StalledStrikeNotification>()); await NotifyInternal(notification.Adapt<StalledStrikeNotification>());
break; break;
case StrikeType.ImportFailed: case StrikeType.ImportFailed:
await _dryRunInterceptor.InterceptAsync(Notify<FailedImportStrikeNotification>, notification.Adapt<FailedImportStrikeNotification>()); await NotifyInternal(notification.Adapt<FailedImportStrikeNotification>());
break; break;
} }
} }
@@ -79,7 +79,7 @@ public class NotificationPublisher : INotificationPublisher
Fields = [new() { Title = "Removed from download client?", Text = removeFromClient ? "Yes" : "No" }] Fields = [new() { Title = "Removed from download client?", Text = removeFromClient ? "Yes" : "No" }]
}; };
await _dryRunInterceptor.InterceptAsync(Notify<QueueItemDeletedNotification>, notification); await NotifyInternal(notification);
} }
public virtual async Task NotifyDownloadCleaned(double ratio, TimeSpan seedingTime, string categoryName, CleanReason reason) public virtual async Task NotifyDownloadCleaned(double ratio, TimeSpan seedingTime, string categoryName, CleanReason reason)
@@ -98,15 +98,9 @@ public class NotificationPublisher : INotificationPublisher
Level = NotificationLevel.Important Level = NotificationLevel.Important
}; };
await _dryRunInterceptor.InterceptAsync(Notify<DownloadCleanedNotification>, notification); await NotifyInternal(notification);
} }
[DryRunSafeguard]
private Task Notify<T>(T message) where T: notnull
{
return _messageBus.Publish(message);
}
[DryRunSafeguard] [DryRunSafeguard]
public virtual async Task NotifyCategoryChanged(string oldCategory, string newCategory) public virtual async Task NotifyCategoryChanged(string oldCategory, string newCategory)
{ {
@@ -126,6 +120,17 @@ public class NotificationPublisher : INotificationPublisher
await _messageBus.Publish(notification); await _messageBus.Publish(notification);
} }
private Task NotifyInternal<T>(T message) where T: notnull
{
return _dryRunInterceptor.InterceptAsync(Notify<T>, message);
}
[DryRunSafeguard]
private Task Notify<T>(T message) where T: notnull
{
return _messageBus.Publish(message);
}
private static Uri GetImageFromContext(QueueRecord record, InstanceType instanceType) => private static Uri GetImageFromContext(QueueRecord record, InstanceType instanceType) =>
instanceType switch instanceType switch
{ {