refactor: Eliminate generics for config type

pull/201/head
Robert Dailey 1 year ago
parent ea59e71b18
commit 7dec45a07a

@ -42,7 +42,7 @@ public class CacheStoragePath : ICacheStoragePath
public IFileInfo CalculatePath(string cacheObjectName) public IFileInfo CalculatePath(string cacheObjectName)
{ {
return _paths.CacheDirectory return _paths.CacheDirectory
.SubDirectory(_config.ServiceName.ToLower(CultureInfo.CurrentCulture)) .SubDirectory(_config.ServiceType.ToString().ToLower(CultureInfo.CurrentCulture))
.SubDirectory(BuildUniqueServiceDir()) .SubDirectory(BuildUniqueServiceDir())
.File(cacheObjectName + ".json"); .File(cacheObjectName + ".json");
} }

@ -1,4 +1,5 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Recyclarr.TrashLib.Config;
using Recyclarr.TrashLib.Config.Services; using Recyclarr.TrashLib.Config.Services;
namespace Recyclarr.TrashLib.TestLibrary; namespace Recyclarr.TrashLib.TestLibrary;
@ -6,5 +7,5 @@ namespace Recyclarr.TrashLib.TestLibrary;
[UsedImplicitly] [UsedImplicitly]
public class TestConfig : ServiceConfiguration public class TestConfig : ServiceConfiguration
{ {
public override string ServiceName => "Test"; public override SupportedServices ServiceType => SupportedServices.Sonarr;
} }

@ -2,6 +2,7 @@ using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using Recyclarr.TrashLib.Config; using Recyclarr.TrashLib.Config;
using Recyclarr.TrashLib.Config.Parsing; using Recyclarr.TrashLib.Config.Parsing;
using Recyclarr.TrashLib.Config.Services;
using Recyclarr.TrashLib.Services.Radarr.Config; using Recyclarr.TrashLib.Services.Radarr.Config;
using Recyclarr.TrashLib.Services.Sonarr.Config; using Recyclarr.TrashLib.Services.Sonarr.Config;
@ -14,17 +15,41 @@ public class ConfigRegistryTest
[Test] [Test]
public void Get_configs_by_type() public void Get_configs_by_type()
{ {
var configs = new[] var configs = new IServiceConfiguration[]
{ {
new SonarrConfiguration {InstanceName = "one"}, new SonarrConfiguration {InstanceName = "one"},
new SonarrConfiguration {InstanceName = "two"} new SonarrConfiguration {InstanceName = "two"},
new RadarrConfiguration {InstanceName = "three"}
}; };
var sut = new ConfigRegistry(); var sut = new ConfigRegistry();
sut.Add(SupportedServices.Sonarr, configs[0]); foreach (var c in configs)
sut.Add(SupportedServices.Sonarr, configs[1]); {
sut.Add(c);
}
var result = sut.GetConfigsOfType(SupportedServices.Sonarr);
result.Should().Equal(configs.Take(2));
}
[Test]
public void Null_service_type_returns_configs_of_all_types()
{
var configs = new IServiceConfiguration[]
{
new SonarrConfiguration {InstanceName = "one"},
new SonarrConfiguration {InstanceName = "two"},
new RadarrConfiguration {InstanceName = "three"}
};
var sut = new ConfigRegistry();
foreach (var c in configs)
{
sut.Add(c);
}
var result = sut.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr); var result = sut.GetConfigsOfType(null);
result.Should().Equal(configs); result.Should().Equal(configs);
} }
@ -33,9 +58,9 @@ public class ConfigRegistryTest
public void Get_empty_collection_when_no_configs_of_type() public void Get_empty_collection_when_no_configs_of_type()
{ {
var sut = new ConfigRegistry(); var sut = new ConfigRegistry();
sut.Add(SupportedServices.Sonarr, new SonarrConfiguration()); sut.Add(new SonarrConfiguration());
var result = sut.GetConfigsOfType<RadarrConfiguration>(SupportedServices.Radarr); var result = sut.GetConfigsOfType(SupportedServices.Radarr);
result.Should().BeEmpty(); result.Should().BeEmpty();
} }

@ -6,7 +6,6 @@ using Recyclarr.Common;
using Recyclarr.TrashLib.Config; using Recyclarr.TrashLib.Config;
using Recyclarr.TrashLib.Config.EnvironmentVariables; using Recyclarr.TrashLib.Config.EnvironmentVariables;
using Recyclarr.TrashLib.Config.Parsing; using Recyclarr.TrashLib.Config.Parsing;
using Recyclarr.TrashLib.Services.Sonarr.Config;
using YamlDotNet.Core; using YamlDotNet.Core;
namespace Recyclarr.TrashLib.Tests.Config.Parsing; namespace Recyclarr.TrashLib.Tests.Config.Parsing;
@ -33,7 +32,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml)); var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr); var config = configCollection.GetConfigsOfType(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[] config.Should().BeEquivalentTo(new[]
{ {
new new
@ -58,7 +57,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml)); var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr); var config = configCollection.GetConfigsOfType(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[] config.Should().BeEquivalentTo(new[]
{ {
new new
@ -85,7 +84,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml)); var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr); var config = configCollection.GetConfigsOfType(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[] config.Should().BeEquivalentTo(new[]
{ {
new new
@ -112,7 +111,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml)); var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr); var config = configCollection.GetConfigsOfType(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[] config.Should().BeEquivalentTo(new[]
{ {
new new
@ -137,7 +136,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml)); var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr); var config = configCollection.GetConfigsOfType(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[] config.Should().BeEquivalentTo(new[]
{ {
new new
@ -161,7 +160,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml)); var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr); var config = configCollection.GetConfigsOfType(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[] config.Should().BeEquivalentTo(new[]
{ {
new new

@ -55,7 +55,7 @@ secret_rp: 1234567
}; };
var parsedSecret = configLoader.LoadFromStream(new StringReader(testYml), "sonarr"); var parsedSecret = configLoader.LoadFromStream(new StringReader(testYml), "sonarr");
parsedSecret.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr) parsedSecret.GetConfigsOfType(SupportedServices.Sonarr)
.Should().BeEquivalentTo(expected, o => o.Excluding(x => x.LineNumber)); .Should().BeEquivalentTo(expected, o => o.Excluding(x => x.LineNumber));
} }

@ -14,7 +14,6 @@ using Recyclarr.TestLibrary.AutoFixture;
using Recyclarr.TrashLib.Config; using Recyclarr.TrashLib.Config;
using Recyclarr.TrashLib.Config.Parsing; using Recyclarr.TrashLib.Config.Parsing;
using Recyclarr.TrashLib.Config.Yaml; using Recyclarr.TrashLib.Config.Yaml;
using Recyclarr.TrashLib.Services.Radarr.Config;
using Recyclarr.TrashLib.Services.Sonarr.Config; using Recyclarr.TrashLib.Services.Sonarr.Config;
using Recyclarr.TrashLib.TestLibrary; using Recyclarr.TrashLib.TestLibrary;
@ -81,10 +80,10 @@ public class ConfigurationLoaderTest : IntegrationFixture
var loader = Resolve<IConfigurationLoader>(); var loader = Resolve<IConfigurationLoader>();
var actual = loader.LoadMany(fileData.Select(x => x.Item1)); var actual = loader.LoadMany(fileData.Select(x => x.Item1));
actual.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr) actual.GetConfigsOfType(SupportedServices.Sonarr)
.Should().BeEquivalentTo(expectedSonarr); .Should().BeEquivalentTo(expectedSonarr);
actual.GetConfigsOfType<RadarrConfiguration>(SupportedServices.Radarr) actual.GetConfigsOfType(SupportedServices.Radarr)
.Should().BeEquivalentTo(expectedRadarr); .Should().BeEquivalentTo(expectedRadarr);
} }
@ -94,7 +93,7 @@ public class ConfigurationLoaderTest : IntegrationFixture
var configLoader = Resolve<ConfigurationLoader>(); var configLoader = Resolve<ConfigurationLoader>();
var configs = configLoader.LoadFromStream(GetResourceData("Load_UsingStream_CorrectParsing.yml"), "sonarr"); var configs = configLoader.LoadFromStream(GetResourceData("Load_UsingStream_CorrectParsing.yml"), "sonarr");
configs.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr) configs.GetConfigsOfType(SupportedServices.Sonarr)
.Should().BeEquivalentTo(new List<SonarrConfiguration> .Should().BeEquivalentTo(new List<SonarrConfiguration>
{ {
new() new()

@ -18,7 +18,7 @@ public class SonarrConfigurationValidatorTest : IntegrationFixture
var validator = Resolve<SonarrConfigurationValidator>(); var validator = Resolve<SonarrConfigurationValidator>();
var result = validator.TestValidate(config); var result = validator.TestValidate(config);
result.ShouldNotHaveValidationErrorFor(x => x.ServiceName); result.ShouldNotHaveValidationErrorFor(x => x.ServiceType);
} }
[Test] [Test]

@ -75,6 +75,6 @@ public class ConfigParser
throw new YamlException("Validation failed"); throw new YamlException("Validation failed");
} }
_configs.Add(_currentSection.Value, newConfig); _configs.Add(newConfig);
} }
} }

@ -5,21 +5,19 @@ namespace Recyclarr.TrashLib.Config.Parsing;
public class ConfigRegistry : IConfigRegistry public class ConfigRegistry : IConfigRegistry
{ {
private readonly Dictionary<SupportedServices, List<ServiceConfiguration>> _configs = new(); private readonly Dictionary<SupportedServices, List<IServiceConfiguration>> _configs = new();
public void Add(SupportedServices configType, ServiceConfiguration config) public void Add(IServiceConfiguration config)
{ {
_configs.GetOrCreate(configType).Add(config); _configs.GetOrCreate(config.ServiceType).Add(config);
} }
public IReadOnlyCollection<T> GetConfigsOfType<T>(SupportedServices serviceType) where T : ServiceConfiguration public IReadOnlyCollection<IServiceConfiguration> GetConfigsOfType(SupportedServices? serviceType)
{ {
if (_configs.TryGetValue(serviceType, out var configs)) return _configs
{ .Where(x => serviceType is null || serviceType.Value == x.Key)
return configs.Cast<T>().ToList(); .SelectMany(x => x.Value)
} .ToList();
return Array.Empty<T>();
} }
public bool DoesConfigExist(string name) public bool DoesConfigExist(string name)

@ -4,6 +4,6 @@ namespace Recyclarr.TrashLib.Config.Parsing;
public interface IConfigRegistry public interface IConfigRegistry
{ {
IReadOnlyCollection<T> GetConfigsOfType<T>(SupportedServices serviceType) where T : ServiceConfiguration; IReadOnlyCollection<IServiceConfiguration> GetConfigsOfType(SupportedServices? serviceType);
bool DoesConfigExist(string name); bool DoesConfigExist(string name);
} }

@ -2,7 +2,7 @@ namespace Recyclarr.TrashLib.Config.Services;
public interface IServiceConfiguration public interface IServiceConfiguration
{ {
string ServiceName { get; } SupportedServices ServiceType { get; }
string? InstanceName { get; } string? InstanceName { get; }
Uri BaseUrl { get; } Uri BaseUrl { get; }
string ApiKey { get; } string ApiKey { get; }

@ -6,7 +6,7 @@ namespace Recyclarr.TrashLib.Config.Services;
public abstract class ServiceConfiguration : IServiceConfiguration public abstract class ServiceConfiguration : IServiceConfiguration
{ {
[YamlIgnore] [YamlIgnore]
public abstract string ServiceName { get; } public abstract SupportedServices ServiceType { get; }
// Name is set dynamically by ConfigurationLoader // Name is set dynamically by ConfigurationLoader
[YamlIgnore] [YamlIgnore]

@ -14,7 +14,6 @@ internal class ServiceConfigurationValidator : AbstractValidator<ServiceConfigur
IValidator<RadarrConfiguration> radarrValidator) IValidator<RadarrConfiguration> radarrValidator)
{ {
RuleFor(x => x.InstanceName).NotEmpty(); RuleFor(x => x.InstanceName).NotEmpty();
RuleFor(x => x.ServiceName).NotEmpty();
RuleFor(x => x.LineNumber).NotEqual(0); RuleFor(x => x.LineNumber).NotEqual(0);
RuleFor(x => x.BaseUrl).Must(x => x.Scheme is "http" or "https") RuleFor(x => x.BaseUrl).Must(x => x.Scheme is "http" or "https")
.WithMessage("Property 'base_url' is required and must be a valid URL"); .WithMessage("Property 'base_url' is required and must be a valid URL");

@ -1,8 +1,6 @@
using Recyclarr.TrashLib.Config.Services;
namespace Recyclarr.TrashLib.Services.Processors; namespace Recyclarr.TrashLib.Services.Processors;
public interface IServiceProcessor<T> where T : ServiceConfiguration public interface IServiceProcessor
{ {
Task Process(T config, ISyncSettings settings); Task Process(ISyncSettings settings);
} }

@ -5,38 +5,41 @@ using Recyclarr.TrashLib.Services.Radarr.Config;
namespace Recyclarr.TrashLib.Services.Processors; namespace Recyclarr.TrashLib.Services.Processors;
public class RadarrProcessor : IServiceProcessor<RadarrConfiguration> public class RadarrProcessor : IServiceProcessor
{ {
private readonly ILogger _log; private readonly ILogger _log;
private readonly ICustomFormatUpdater _cfUpdater; private readonly ICustomFormatUpdater _cfUpdater;
private readonly IQualitySizeUpdater _qualityUpdater; private readonly IQualitySizeUpdater _qualityUpdater;
private readonly RadarrGuideService _guideService; private readonly RadarrGuideService _guideService;
private readonly RadarrConfiguration _config;
public RadarrProcessor( public RadarrProcessor(
ILogger log, ILogger log,
ICustomFormatUpdater cfUpdater, ICustomFormatUpdater cfUpdater,
IQualitySizeUpdater qualityUpdater, IQualitySizeUpdater qualityUpdater,
RadarrGuideService guideService) RadarrGuideService guideService,
RadarrConfiguration config)
{ {
_log = log; _log = log;
_cfUpdater = cfUpdater; _cfUpdater = cfUpdater;
_qualityUpdater = qualityUpdater; _qualityUpdater = qualityUpdater;
_guideService = guideService; _guideService = guideService;
_config = config;
} }
public async Task Process(RadarrConfiguration config, ISyncSettings settings) public async Task Process(ISyncSettings settings)
{ {
var didWork = false; var didWork = false;
if (config.QualityDefinition != null) if (_config.QualityDefinition != null)
{ {
await _qualityUpdater.Process(settings.Preview, config.QualityDefinition, _guideService); await _qualityUpdater.Process(settings.Preview, _config.QualityDefinition, _guideService);
didWork = true; didWork = true;
} }
if (config.CustomFormats.Count > 0) if (_config.CustomFormats.Count > 0)
{ {
await _cfUpdater.Process(settings.Preview, config.CustomFormats, _guideService); await _cfUpdater.Process(settings.Preview, _config.CustomFormats, _guideService);
didWork = true; didWork = true;
} }

@ -1,6 +1,7 @@
using Autofac; using Autofac;
using JetBrains.Annotations; using JetBrains.Annotations;
using Recyclarr.Common.Autofac; using Recyclarr.Common.Autofac;
using Recyclarr.TrashLib.Config;
using Recyclarr.TrashLib.Config.Services; using Recyclarr.TrashLib.Config.Services;
namespace Recyclarr.TrashLib.Services.Processors; namespace Recyclarr.TrashLib.Services.Processors;
@ -15,14 +16,14 @@ public class ServiceProcessorFactory
_scope = scope; _scope = scope;
} }
public LifetimeScopedValue<IServiceProcessor<T>> CreateProcessor<T>(IServiceConfiguration config) public LifetimeScopedValue<IServiceProcessor> CreateProcessor(
where T : ServiceConfiguration SupportedServices serviceType, IServiceConfiguration config)
{ {
var scope = _scope.BeginLifetimeScope(builder => var scope = _scope.BeginLifetimeScope(builder =>
{ {
builder.RegisterInstance(config).As<IServiceConfiguration>(); builder.RegisterInstance(config).As<IServiceConfiguration>().AsSelf();
}); });
return new LifetimeScopedValue<IServiceProcessor<T>>(scope, scope.Resolve<IServiceProcessor<T>>()); return new LifetimeScopedValue<IServiceProcessor>(scope, scope.ResolveKeyed<IServiceProcessor>(serviceType));
} }
} }

@ -1,6 +1,5 @@
using Autofac; using Autofac;
using Recyclarr.TrashLib.Services.Radarr.Config; using Recyclarr.TrashLib.Config;
using Recyclarr.TrashLib.Services.Sonarr.Config;
namespace Recyclarr.TrashLib.Services.Processors; namespace Recyclarr.TrashLib.Services.Processors;
@ -10,8 +9,8 @@ public class ServiceProcessorsAutofacModule : Module
{ {
base.Load(builder); base.Load(builder);
builder.RegisterType<ServiceProcessorFactory>(); builder.RegisterType<ServiceProcessorFactory>();
builder.RegisterType<RadarrProcessor>().As<IServiceProcessor<RadarrConfiguration>>(); builder.RegisterType<RadarrProcessor>().Keyed<IServiceProcessor>(SupportedServices.Radarr);
builder.RegisterType<SonarrProcessor>().As<IServiceProcessor<SonarrConfiguration>>(); builder.RegisterType<SonarrProcessor>().Keyed<IServiceProcessor>(SupportedServices.Sonarr);
builder.RegisterType<ConfigCreationProcessor>().As<IConfigCreationProcessor>(); builder.RegisterType<ConfigCreationProcessor>().As<IConfigCreationProcessor>();
} }
} }

@ -7,7 +7,7 @@ using Recyclarr.TrashLib.Services.Sonarr.ReleaseProfile;
namespace Recyclarr.TrashLib.Services.Processors; namespace Recyclarr.TrashLib.Services.Processors;
public class SonarrProcessor : IServiceProcessor<SonarrConfiguration> public class SonarrProcessor : IServiceProcessor
{ {
private readonly ILogger _log; private readonly ILogger _log;
private readonly ICustomFormatUpdater _cfUpdater; private readonly ICustomFormatUpdater _cfUpdater;
@ -15,6 +15,7 @@ public class SonarrProcessor : IServiceProcessor<SonarrConfiguration>
private readonly SonarrGuideService _guideService; private readonly SonarrGuideService _guideService;
private readonly IReleaseProfileUpdater _profileUpdater; private readonly IReleaseProfileUpdater _profileUpdater;
private readonly SonarrCapabilityEnforcer _compatibilityEnforcer; private readonly SonarrCapabilityEnforcer _compatibilityEnforcer;
private readonly SonarrConfiguration _config;
public SonarrProcessor( public SonarrProcessor(
ILogger log, ILogger log,
@ -22,7 +23,8 @@ public class SonarrProcessor : IServiceProcessor<SonarrConfiguration>
IQualitySizeUpdater qualityUpdater, IQualitySizeUpdater qualityUpdater,
SonarrGuideService guideService, SonarrGuideService guideService,
IReleaseProfileUpdater profileUpdater, IReleaseProfileUpdater profileUpdater,
SonarrCapabilityEnforcer compatibilityEnforcer) SonarrCapabilityEnforcer compatibilityEnforcer,
SonarrConfiguration config)
{ {
_log = log; _log = log;
_cfUpdater = cfUpdater; _cfUpdater = cfUpdater;
@ -30,30 +32,31 @@ public class SonarrProcessor : IServiceProcessor<SonarrConfiguration>
_guideService = guideService; _guideService = guideService;
_profileUpdater = profileUpdater; _profileUpdater = profileUpdater;
_compatibilityEnforcer = compatibilityEnforcer; _compatibilityEnforcer = compatibilityEnforcer;
_config = config;
} }
public async Task Process(SonarrConfiguration config, ISyncSettings settings) public async Task Process(ISyncSettings settings)
{ {
// Any compatibility failures will be thrown as exceptions // Any compatibility failures will be thrown as exceptions
_compatibilityEnforcer.Check(config); _compatibilityEnforcer.Check(_config);
var didWork = false; var didWork = false;
if (config.ReleaseProfiles.Count > 0) if (_config.ReleaseProfiles.Count > 0)
{ {
await _profileUpdater.Process(settings.Preview, config); await _profileUpdater.Process(settings.Preview, _config);
didWork = true; didWork = true;
} }
if (config.QualityDefinition != null) if (_config.QualityDefinition != null)
{ {
await _qualityUpdater.Process(settings.Preview, config.QualityDefinition, _guideService); await _qualityUpdater.Process(settings.Preview, _config.QualityDefinition, _guideService);
didWork = true; didWork = true;
} }
if (config.CustomFormats.Count > 0) if (_config.CustomFormats.Count > 0)
{ {
await _cfUpdater.Process(settings.Preview, config.CustomFormats, _guideService); await _cfUpdater.Process(settings.Preview, _config.CustomFormats, _guideService);
didWork = true; didWork = true;
} }

@ -6,8 +6,6 @@ using Recyclarr.TrashLib.Config.Parsing;
using Recyclarr.TrashLib.Config.Services; using Recyclarr.TrashLib.Config.Services;
using Recyclarr.TrashLib.Http; using Recyclarr.TrashLib.Http;
using Recyclarr.TrashLib.Repo.VersionControl; using Recyclarr.TrashLib.Repo.VersionControl;
using Recyclarr.TrashLib.Services.Radarr.Config;
using Recyclarr.TrashLib.Services.Sonarr.Config;
using Spectre.Console; using Spectre.Console;
namespace Recyclarr.TrashLib.Services.Processors; namespace Recyclarr.TrashLib.Services.Processors;
@ -37,7 +35,7 @@ public class SyncProcessor : ISyncProcessor
public async Task<ExitStatus> ProcessConfigs(ISyncSettings settings) public async Task<ExitStatus> ProcessConfigs(ISyncSettings settings)
{ {
var failureDetected = false; bool failureDetected;
try try
{ {
var configs = _configLoader.LoadMany(_configFinder.GetConfigFiles(settings.Configs)); var configs = _configLoader.LoadMany(_configFinder.GetConfigFiles(settings.Configs));
@ -48,17 +46,7 @@ public class SyncProcessor : ISyncProcessor
_log.Warning("These instances do not exist: {Instances}", invalidInstances); _log.Warning("These instances do not exist: {Instances}", invalidInstances);
} }
if (settings.Service is null or SupportedServices.Radarr) failureDetected = await ProcessService(settings.Service, settings, configs);
{
failureDetected |=
await ProcessService<RadarrConfiguration>(SupportedServices.Radarr, settings, configs);
}
if (settings.Service is null or SupportedServices.Sonarr)
{
failureDetected |=
await ProcessService<SonarrConfiguration>(SupportedServices.Sonarr, settings, configs);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -69,11 +57,10 @@ public class SyncProcessor : ISyncProcessor
return failureDetected ? ExitStatus.Failed : ExitStatus.Succeeded; return failureDetected ? ExitStatus.Failed : ExitStatus.Succeeded;
} }
private async Task<bool> ProcessService<TConfig>( private async Task<bool> ProcessService(
SupportedServices service, ISyncSettings settings, IConfigRegistry configs) SupportedServices? serviceType, ISyncSettings settings, IConfigRegistry configs)
where TConfig : ServiceConfiguration
{ {
var serviceConfigs = configs.GetConfigsOfType<TConfig>(service); var serviceConfigs = configs.GetConfigsOfType(serviceType);
// If any config names are null, that means user specified array-style (deprecated) instances. // If any config names are null, that means user specified array-style (deprecated) instances.
if (serviceConfigs.Any(x => x.InstanceName is null)) if (serviceConfigs.Any(x => x.InstanceName is null))
@ -98,9 +85,9 @@ public class SyncProcessor : ISyncProcessor
continue; continue;
} }
PrintProcessingHeader(service.ToString(), config); PrintProcessingHeader(config.ServiceType, config);
using var processor = _factory.CreateProcessor<TConfig>(config); using var processor = _factory.CreateProcessor(config.ServiceType, config);
await processor.Value.Process(config, settings); await processor.Value.Process(settings);
} }
catch (Exception e) catch (Exception e)
{ {
@ -131,16 +118,16 @@ public class SyncProcessor : ISyncProcessor
} }
} }
private void PrintProcessingHeader(string serverName, ServiceConfiguration config) private void PrintProcessingHeader(SupportedServices serviceType, IServiceConfiguration config)
{ {
var instanceName = config.InstanceName ?? FlurlLogging.SanitizeUrl(config.BaseUrl); var instanceName = config.InstanceName ?? FlurlLogging.SanitizeUrl(config.BaseUrl);
_console.WriteLine($@" _console.WriteLine($@"
=========================================== ===========================================
Processing {serverName} Server: [{instanceName}] Processing {serviceType} Server: [{instanceName}]
=========================================== ===========================================
"); ");
_log.Debug("Processing {Server} server {Name}", serverName, instanceName); _log.Debug("Processing {Server} server {Name}", serviceType, instanceName);
} }
} }

@ -1,11 +1,9 @@
using JetBrains.Annotations;
using Recyclarr.TrashLib.Config; using Recyclarr.TrashLib.Config;
using Recyclarr.TrashLib.Config.Services; using Recyclarr.TrashLib.Config.Services;
namespace Recyclarr.TrashLib.Services.Radarr.Config; namespace Recyclarr.TrashLib.Services.Radarr.Config;
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public class RadarrConfiguration : ServiceConfiguration public class RadarrConfiguration : ServiceConfiguration
{ {
public override string ServiceName { get; } = SupportedServices.Radarr.ToString(); public override SupportedServices ServiceType => SupportedServices.Radarr;
} }

@ -6,7 +6,7 @@ namespace Recyclarr.TrashLib.Services.Sonarr.Config;
public class SonarrConfiguration : ServiceConfiguration public class SonarrConfiguration : ServiceConfiguration
{ {
public override string ServiceName { get; } = SupportedServices.Sonarr.ToString(); public override SupportedServices ServiceType => SupportedServices.Sonarr;
public IList<ReleaseProfileConfig> ReleaseProfiles { get; [UsedImplicitly] init; } = public IList<ReleaseProfileConfig> ReleaseProfiles { get; [UsedImplicitly] init; } =
Array.Empty<ReleaseProfileConfig>(); Array.Empty<ReleaseProfileConfig>();

Loading…
Cancel
Save