diff --git a/src/Common/Common.csproj b/src/Common/Common.csproj
index 5f38880a..25cebc40 100644
--- a/src/Common/Common.csproj
+++ b/src/Common/Common.csproj
@@ -1,8 +1,10 @@
-
-
+
+
+
+
diff --git a/src/Common/Extensions/RxExtensions.cs b/src/Common/Extensions/RxExtensions.cs
new file mode 100644
index 00000000..21bd9248
--- /dev/null
+++ b/src/Common/Extensions/RxExtensions.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
+using System.Threading;
+using Serilog;
+
+namespace Common.Extensions
+{
+ public static class RxExtensions
+ {
+ public static IObservable Spy(this IObservable source, ILogger log, string? opName = null)
+ {
+ opName ??= "IObservable";
+ log.Debug("{OpName}: Observable obtained on Thread: {ThreadId}",
+ opName,
+ Thread.CurrentThread.ManagedThreadId);
+
+ return Observable.Create(obs =>
+ {
+ log.Debug("{OpName}: Subscribed to on Thread: {ThreadId}",
+ opName,
+ Thread.CurrentThread.ManagedThreadId);
+
+ try
+ {
+ var subscription = source
+ .Do(
+ x => log.Debug("{OpName}: OnNext({Result}) on Thread: {ThreadId}", opName, x,
+ Thread.CurrentThread.ManagedThreadId),
+ ex => log.Debug("{OpName}: OnError({Result}) on Thread: {ThreadId}", opName, ex.Message,
+ Thread.CurrentThread.ManagedThreadId),
+ () => log.Debug("{OpName}: OnCompleted() on Thread: {ThreadId}", opName,
+ Thread.CurrentThread.ManagedThreadId))
+ .Subscribe(obs);
+ return new CompositeDisposable(
+ subscription,
+ Disposable.Create(() => log.Debug(
+ "{OpName}: Cleaned up on Thread: {ThreadId}",
+ opName,
+ Thread.CurrentThread.ManagedThreadId)));
+ }
+ finally
+ {
+ log.Debug("{OpName}: Subscription completed", opName);
+ }
+ });
+ }
+ }
+}
diff --git a/src/Trash/Command/RadarrCommand.cs b/src/Trash/Command/RadarrCommand.cs
index 3664c095..076104d6 100644
--- a/src/Trash/Command/RadarrCommand.cs
+++ b/src/Trash/Command/RadarrCommand.cs
@@ -20,17 +20,19 @@ namespace Trash.Command
{
private readonly IConfigurationLoader _configLoader;
private readonly Func _customFormatUpdaterFactory;
+ private readonly ILogger _log;
private readonly Func _qualityUpdaterFactory;
public RadarrCommand(
- ILogger logger,
+ ILogger log,
LoggingLevelSwitch loggingLevelSwitch,
ILogJanitor logJanitor,
IConfigurationLoader configLoader,
Func qualityUpdaterFactory,
Func customFormatUpdaterFactory)
- : base(logger, loggingLevelSwitch, logJanitor)
+ : base(log, loggingLevelSwitch, logJanitor)
{
+ _log = log;
_configLoader = configLoader;
_qualityUpdaterFactory = qualityUpdaterFactory;
_customFormatUpdaterFactory = customFormatUpdaterFactory;
@@ -58,7 +60,7 @@ namespace Trash.Command
}
catch (FlurlHttpException e)
{
- Log.Error(e, "HTTP error while communicating with Radarr");
+ _log.Error(e, "HTTP error while communicating with Radarr");
ExitDueToFailure();
}
}
diff --git a/src/Trash/Command/SonarrCommand.cs b/src/Trash/Command/SonarrCommand.cs
index 496a7d60..0082da0e 100644
--- a/src/Trash/Command/SonarrCommand.cs
+++ b/src/Trash/Command/SonarrCommand.cs
@@ -19,18 +19,20 @@ namespace Trash.Command
public class SonarrCommand : ServiceCommand
{
private readonly IConfigurationLoader _configLoader;
+ private readonly ILogger _log;
private readonly Func _profileUpdaterFactory;
private readonly Func _qualityUpdaterFactory;
public SonarrCommand(
- ILogger logger,
+ ILogger log,
LoggingLevelSwitch loggingLevelSwitch,
ILogJanitor logJanitor,
IConfigurationLoader configLoader,
Func profileUpdaterFactory,
Func qualityUpdaterFactory)
- : base(logger, loggingLevelSwitch, logJanitor)
+ : base(log, loggingLevelSwitch, logJanitor)
{
+ _log = log;
_configLoader = configLoader;
_profileUpdaterFactory = profileUpdaterFactory;
_qualityUpdaterFactory = qualityUpdaterFactory;
@@ -60,7 +62,7 @@ namespace Trash.Command
}
catch (FlurlHttpException e)
{
- Log.Error(e, "HTTP error while communicating with Sonarr");
+ _log.Error(e, "HTTP error while communicating with Sonarr");
ExitDueToFailure();
}
}
diff --git a/src/TrashLib.Tests/Sonarr/Api/SonarrReleaseProfileCompatibilityHandlerTest.cs b/src/TrashLib.Tests/Sonarr/Api/SonarrReleaseProfileCompatibilityHandlerTest.cs
index c76a3d2d..af4ff295 100644
--- a/src/TrashLib.Tests/Sonarr/Api/SonarrReleaseProfileCompatibilityHandlerTest.cs
+++ b/src/TrashLib.Tests/Sonarr/Api/SonarrReleaseProfileCompatibilityHandlerTest.cs
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
+using System.Reactive.Linq;
+using System.Threading.Tasks;
using AutoMapper;
using FluentAssertions;
using Newtonsoft.Json;
@@ -55,7 +57,6 @@ namespace TrashLib.Tests.Sonarr.Api
var result = sut.CompatibleReleaseProfileForReceiving(JObject.Parse(ctx.SerializeJson(dataV1)));
- _ = compat.DidNotReceive().ArraysNeededForReleaseProfileRequiredAndIgnored;
result.Should().BeEquivalentTo(new SonarrReleaseProfile
{
Ignored = new List {"one", "two", "three"}
@@ -73,38 +74,43 @@ namespace TrashLib.Tests.Sonarr.Api
var result = sut.CompatibleReleaseProfileForReceiving(JObject.Parse(ctx.SerializeJson(dataV2)));
- _ = compat.DidNotReceive().ArraysNeededForReleaseProfileRequiredAndIgnored;
result.Should().BeEquivalentTo(dataV2);
}
[Test]
- public void Send_v2_to_v1()
+ public async Task Send_v2_to_v1()
{
using var ctx = new TestContext();
var compat = Substitute.For();
- compat.ArraysNeededForReleaseProfileRequiredAndIgnored.Returns(false);
+ compat.Capabilities.Returns(new[]
+ {
+ new SonarrCapabilities {ArraysNeededForReleaseProfileRequiredAndIgnored = false}
+ }.ToObservable());
var data = new SonarrReleaseProfile {Ignored = new List {"one", "two", "three"}};
var sut = new SonarrReleaseProfileCompatibilityHandler(compat, ctx.Mapper);
- var result = sut.CompatibleReleaseProfileForSending(data);
+ var result = await sut.CompatibleReleaseProfileForSendingAsync(data);
result.Should().BeEquivalentTo(new SonarrReleaseProfileV1 {Ignored = "one,two,three"});
}
[Test]
- public void Send_v2_to_v2()
+ public async Task Send_v2_to_v2()
{
using var ctx = new TestContext();
var compat = Substitute.For();
- compat.ArraysNeededForReleaseProfileRequiredAndIgnored.Returns(true);
+ compat.Capabilities.Returns(new[]
+ {
+ new SonarrCapabilities {ArraysNeededForReleaseProfileRequiredAndIgnored = true}
+ }.ToObservable());
var data = new SonarrReleaseProfile {Ignored = new List {"one", "two", "three"}};
var sut = new SonarrReleaseProfileCompatibilityHandler(compat, ctx.Mapper);
- var result = sut.CompatibleReleaseProfileForSending(data);
+ var result = await sut.CompatibleReleaseProfileForSendingAsync(data);
result.Should().BeEquivalentTo(data);
}
diff --git a/src/TrashLib/Sonarr/Api/ISonarrReleaseProfileCompatibilityHandler.cs b/src/TrashLib/Sonarr/Api/ISonarrReleaseProfileCompatibilityHandler.cs
index 18d8bf5a..00cb77c0 100644
--- a/src/TrashLib/Sonarr/Api/ISonarrReleaseProfileCompatibilityHandler.cs
+++ b/src/TrashLib/Sonarr/Api/ISonarrReleaseProfileCompatibilityHandler.cs
@@ -1,3 +1,4 @@
+using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using TrashLib.Sonarr.Api.Objects;
@@ -5,7 +6,7 @@ namespace TrashLib.Sonarr.Api
{
public interface ISonarrReleaseProfileCompatibilityHandler
{
- object CompatibleReleaseProfileForSending(SonarrReleaseProfile profile);
+ Task