From cab505591fce6fd197beea6ab2c446f8dfafb10a Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Thu, 11 May 2023 08:16:16 -0500 Subject: [PATCH] chore: Remove unused code --- src/Recyclarr/Config/ConfigurationLoader.cs | 105 ------------------- src/Recyclarr/Config/IConfigurationLoader.cs | 10 -- 2 files changed, 115 deletions(-) delete mode 100644 src/Recyclarr/Config/ConfigurationLoader.cs delete mode 100644 src/Recyclarr/Config/IConfigurationLoader.cs diff --git a/src/Recyclarr/Config/ConfigurationLoader.cs b/src/Recyclarr/Config/ConfigurationLoader.cs deleted file mode 100644 index ee3fc30c..00000000 --- a/src/Recyclarr/Config/ConfigurationLoader.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System.IO.Abstractions; -using FluentValidation; -using Serilog; -using TrashLib.Config; -using TrashLib.Config.Services; -using YamlDotNet.Core; -using YamlDotNet.Core.Events; -using YamlDotNet.Serialization; - -namespace Recyclarr.Config; - -public class ConfigurationLoader : IConfigurationLoader - where T : ServiceConfiguration -{ - private readonly ILogger _log; - private readonly IDeserializer _deserializer; - private readonly IValidator _validator; - - public ConfigurationLoader( - ILogger log, - IYamlSerializerFactory yamlFactory, - IValidator validator) - { - _log = log; - _validator = validator; - _deserializer = yamlFactory.CreateDeserializer(); - } - - public IEnumerable Load(IFileInfo file, string configSection) - { - using var stream = file.OpenText(); - return LoadFromStream(stream, configSection); - } - - public IEnumerable LoadFromStream(TextReader stream, string configSection) - { - var parser = new Parser(stream); - parser.Consume(); - parser.Consume(); - parser.Consume(); - - var validConfigs = new List(); - while (parser.TryConsume(out var key)) - { - if (key.Value != configSection) - { - parser.SkipThisAndNestedEvents(); - continue; - } - - List? configs; - switch (parser.Current) - { - case MappingStart: - configs = _deserializer.Deserialize>(parser) - .Select(kvp => - { - kvp.Value.Name = kvp.Key; - return kvp.Value; - }) - .ToList(); - break; - - case SequenceStart: - _log.Warning( - "Found array-style list of instances instead of named-style. Array-style lists of Sonarr/Radarr " + - "instances are deprecated"); - configs = _deserializer.Deserialize>(parser); - break; - - default: - configs = null; - break; - } - - if (configs is not null) - { - ValidateConfigs(configSection, configs, validConfigs); - } - - parser.SkipThisAndNestedEvents(); - } - - return validConfigs; - } - - private void ValidateConfigs(string configSection, IEnumerable configs, ICollection validConfigs) - { - foreach (var config in configs) - { - var result = _validator.Validate(config); - if (result is {IsValid: false}) - { - throw new ConfigurationException(configSection, typeof(T), result.Errors); - } - - validConfigs.Add(config); - } - } - - public IEnumerable LoadMany(IEnumerable configFiles, string configSection) - { - return configFiles.SelectMany(file => Load(file, configSection)); - } -} diff --git a/src/Recyclarr/Config/IConfigurationLoader.cs b/src/Recyclarr/Config/IConfigurationLoader.cs deleted file mode 100644 index c1d4fc10..00000000 --- a/src/Recyclarr/Config/IConfigurationLoader.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.IO.Abstractions; -using TrashLib.Config.Services; - -namespace Recyclarr.Config; - -public interface IConfigurationLoader - where T : IServiceConfiguration -{ - IEnumerable LoadMany(IEnumerable configFiles, string configSection); -}