refactor: new trashlib project

Move non-CLI specific code from Trash project to TrashLib. This is for
future code sharing with Recyclarr. Trash project is officially
deprecated and will eventually go away in favor of the web app.
recyclarr
Robert Dailey 3 years ago
parent e197fb2bd0
commit 1db23e6be9

@ -1,9 +1,9 @@
using System.Collections.Generic;
using Common.Extensions;
using FluentAssertions;
using NUnit.Framework;
using Trash.Extensions;
namespace Trash.Tests.Extensions
namespace Common.Tests.Extensions
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -1,2 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="YamlDotNet" />
</ItemGroup>
</Project>

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Trash.Extensions
namespace Common.Extensions
{
public static class DictionaryExtensions
{

@ -2,7 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
namespace Trash.Extensions
namespace Common.Extensions
{
internal static class LinqExtensions
{

@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
namespace Trash.Extensions
namespace Common.Extensions
{
public static class RegexExtensions
{

@ -1,7 +1,7 @@
using System;
using System.Globalization;
namespace Trash.Extensions
namespace Common.Extensions
{
public static class StringExtensions
{

@ -2,7 +2,7 @@ using System;
using System.Collections;
using System.ComponentModel.DataAnnotations;
namespace Trash.YamlDotNet
namespace Common.YamlDotNet
{
[AttributeUsage(AttributeTargets.Property)]
public sealed class CannotBeEmptyAttribute : RequiredAttribute

@ -3,9 +3,9 @@ using System.ComponentModel.DataAnnotations;
using YamlDotNet.Core;
using YamlDotNet.Serialization;
namespace Trash.YamlDotNet
namespace Common.YamlDotNet
{
public class ValidatingDeserializer : INodeDeserializer
internal class ValidatingDeserializer : INodeDeserializer
{
private readonly INodeDeserializer _nodeDeserializer;

@ -2,7 +2,7 @@
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NodeDeserializers;
namespace Trash.YamlDotNet
namespace Common.YamlDotNet
{
public static class YamlDotNetExtensions
{

@ -3,11 +3,11 @@ using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
namespace Trash.YamlDotNet
namespace Common.YamlDotNet
{
// A workaround for nullable enums in YamlDotNet taken from:
// https://github.com/aaubry/YamlDotNet/issues/544#issuecomment-778062351
internal class YamlNullableEnumTypeConverter : IYamlTypeConverter
public class YamlNullableEnumTypeConverter : IYamlTypeConverter
{
public bool Accepts(Type type)
{

@ -1,5 +1,5 @@
using System.Linq;
using Trash.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models;
namespace Trash.TestLibrary
{

@ -3,7 +3,7 @@ using System.Collections.Generic;
using Autofac;
using FluentAssertions;
using NUnit.Framework;
using Trash.Command;
using Trash.Command.Helpers;
namespace Trash.Tests.Command
{

@ -6,15 +6,16 @@ using System.IO.Abstractions;
using System.Linq;
using System.Text;
using Common;
using Common.Extensions;
using FluentAssertions;
using JetBrains.Annotations;
using NSubstitute;
using NUnit.Framework;
using TestLibrary;
using Trash.Config;
using Trash.Extensions;
using Trash.Sonarr;
using Trash.Sonarr.ReleaseProfile;
using TrashLib.Config;
using TrashLib.Sonarr;
using TrashLib.Sonarr.ReleaseProfile;
using YamlDotNet.Serialization.ObjectFactories;
namespace Trash.Tests.Config
@ -38,16 +39,16 @@ namespace Trash.Tests.Config
public string BaseUrl { get; init; } = "";
public string ApiKey { get; init; } = "";
public string BuildUrl()
{
throw new NotImplementedException();
}
public bool IsValid(out string msg)
{
msg = Msg;
return false;
}
public string BuildUrl()
{
throw new NotImplementedException();
}
}
[SuppressMessage("Microsoft.Design", "CA1034",
@ -58,16 +59,16 @@ namespace Trash.Tests.Config
public string BaseUrl { get; init; } = "";
public string ApiKey { get; init; } = "";
public string BuildUrl()
{
throw new NotImplementedException();
}
public bool IsValid(out string msg)
{
msg = "";
return true;
}
public string BuildUrl()
{
throw new NotImplementedException();
}
}
[Test]

@ -6,6 +6,7 @@ using JetBrains.Annotations;
using NSubstitute;
using NUnit.Framework;
using Trash.Config;
using TrashLib.Config;
using YamlDotNet.Core;
using YamlDotNet.Serialization.ObjectFactories;

@ -4,7 +4,7 @@ using CliFx.Infrastructure;
using NSubstitute;
using NUnit.Framework;
using Serilog;
using Trash.CreateConfig;
using Trash.Command;
// ReSharper disable MethodHasAsyncOverload

@ -8,7 +8,7 @@ using Common;
using JetBrains.Annotations;
using Serilog;
namespace Trash.CreateConfig
namespace Trash.Command
{
[Command("create-config", Description = "Create a starter YAML configuration file")]
[UsedImplicitly]

@ -1,6 +1,6 @@
using System;
namespace Trash.Command
namespace Trash.Command.Helpers
{
public class ActiveServiceCommandProvider : IActiveServiceCommandProvider
{

@ -1,7 +1,7 @@
using System;
using Trash.Command;
using TrashLib.Cache;
namespace Trash.Cache
namespace Trash.Command.Helpers
{
public class CacheStoragePath : ICacheStoragePath
{

@ -1,7 +1,7 @@
using System;
using Autofac;
namespace Trash.Command
namespace Trash.Command.Helpers
{
internal static class CliTypeActivator
{

@ -1,4 +1,4 @@
namespace Trash.Command
namespace Trash.Command.Helpers
{
public enum ExitCode
{

@ -1,4 +1,4 @@
namespace Trash.Command
namespace Trash.Command.Helpers
{
public interface IActiveServiceCommandProvider
{

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Trash.Command
namespace Trash.Command.Helpers
{
public interface IServiceCommand
{

@ -14,7 +14,7 @@ using Serilog.Core;
using Serilog.Events;
using YamlDotNet.Core;
namespace Trash.Command
namespace Trash.Command.Helpers
{
public abstract class ServiceCommand : ICommand, IServiceCommand
{

@ -6,27 +6,28 @@ using Flurl.Http;
using JetBrains.Annotations;
using Serilog;
using Serilog.Core;
using Trash.Command;
using Trash.Command.Helpers;
using Trash.Config;
using Trash.Radarr.CustomFormat;
using Trash.Radarr.QualityDefinition;
using TrashLib.Radarr;
using TrashLib.Radarr.CustomFormat;
using TrashLib.Radarr.QualityDefinition;
namespace Trash.Radarr
namespace Trash.Command
{
[Command("radarr", Description = "Perform operations on a Radarr instance")]
[UsedImplicitly]
public class RadarrCommand : ServiceCommand, IRadarrCommand
public class RadarrCommand : ServiceCommand
{
private readonly IConfigurationLoader<RadarrConfiguration> _configLoader;
private readonly Func<ICustomFormatUpdater> _customFormatUpdaterFactory;
private readonly Func<RadarrQualityDefinitionUpdater> _qualityUpdaterFactory;
private readonly Func<IRadarrQualityDefinitionUpdater> _qualityUpdaterFactory;
public RadarrCommand(
ILogger logger,
LoggingLevelSwitch loggingLevelSwitch,
ILogJanitor logJanitor,
IConfigurationLoader<RadarrConfiguration> configLoader,
Func<RadarrQualityDefinitionUpdater> qualityUpdaterFactory,
Func<IRadarrQualityDefinitionUpdater> qualityUpdaterFactory,
Func<ICustomFormatUpdater> customFormatUpdaterFactory)
: base(logger, loggingLevelSwitch, logJanitor)
{
@ -46,12 +47,12 @@ namespace Trash.Radarr
{
if (config.QualityDefinition != null)
{
await _qualityUpdaterFactory().Process(this, config);
await _qualityUpdaterFactory().Process(Preview, config);
}
if (config.CustomFormats.Count > 0)
{
await _customFormatUpdaterFactory().Process(this, config);
await _customFormatUpdaterFactory().Process(Preview, config);
}
}
}

@ -6,28 +6,29 @@ using Flurl.Http;
using JetBrains.Annotations;
using Serilog;
using Serilog.Core;
using Trash.Command;
using Trash.Command.Helpers;
using Trash.Config;
using Trash.Sonarr.QualityDefinition;
using Trash.Sonarr.ReleaseProfile;
using TrashLib.Sonarr;
using TrashLib.Sonarr.QualityDefinition;
using TrashLib.Sonarr.ReleaseProfile;
namespace Trash.Sonarr
namespace Trash.Command
{
[Command("sonarr", Description = "Perform operations on a Sonarr instance")]
[UsedImplicitly]
public class SonarrCommand : ServiceCommand, ISonarrCommand
public class SonarrCommand : ServiceCommand
{
private readonly IConfigurationLoader<SonarrConfiguration> _configLoader;
private readonly Func<ReleaseProfileUpdater> _profileUpdaterFactory;
private readonly Func<SonarrQualityDefinitionUpdater> _qualityUpdaterFactory;
private readonly Func<IReleaseProfileUpdater> _profileUpdaterFactory;
private readonly Func<ISonarrQualityDefinitionUpdater> _qualityUpdaterFactory;
public SonarrCommand(
ILogger logger,
LoggingLevelSwitch loggingLevelSwitch,
ILogJanitor logJanitor,
IConfigurationLoader<SonarrConfiguration> configLoader,
Func<ReleaseProfileUpdater> profileUpdaterFactory,
Func<SonarrQualityDefinitionUpdater> qualityUpdaterFactory)
Func<IReleaseProfileUpdater> profileUpdaterFactory,
Func<ISonarrQualityDefinitionUpdater> qualityUpdaterFactory)
: base(logger, loggingLevelSwitch, logJanitor)
{
_configLoader = configLoader;
@ -48,12 +49,12 @@ namespace Trash.Sonarr
{
if (config.ReleaseProfiles.Count > 0)
{
await _profileUpdaterFactory().Process(this, config);
await _profileUpdaterFactory().Process(Preview, config);
}
if (config.QualityDefinition.HasValue)
{
await _qualityUpdaterFactory().Process(this, config);
await _qualityUpdaterFactory().Process(Preview, config);
}
}
}

@ -3,24 +3,15 @@ using System.IO;
using System.IO.Abstractions;
using System.Reflection;
using Autofac;
using Autofac.Extras.AggregateService;
using CliFx;
using Serilog;
using Serilog.Core;
using Trash.Cache;
using Trash.Command;
using Trash.Command.Helpers;
using Trash.Config;
using Trash.Radarr.CustomFormat;
using Trash.Radarr.CustomFormat.Api;
using Trash.Radarr.CustomFormat.Guide;
using Trash.Radarr.CustomFormat.Processors;
using Trash.Radarr.CustomFormat.Processors.GuideSteps;
using Trash.Radarr.CustomFormat.Processors.PersistenceSteps;
using Trash.Radarr.QualityDefinition;
using Trash.Radarr.QualityDefinition.Api;
using Trash.Sonarr.Api;
using Trash.Sonarr.QualityDefinition;
using Trash.Sonarr.ReleaseProfile;
using TrashLib.Cache;
using TrashLib.Config;
using TrashLib.Radarr;
using TrashLib.Sonarr;
using YamlDotNet.Serialization;
namespace Trash
@ -48,69 +39,16 @@ namespace Trash
.SingleInstance();
}
private static void SonarrRegistrations(ContainerBuilder builder)
{
builder.RegisterType<SonarrApi>().As<ISonarrApi>();
// Release Profile Support
builder.RegisterType<ReleaseProfileUpdater>();
builder.RegisterType<ReleaseProfileGuideParser>().As<IReleaseProfileGuideParser>();
// Quality Definition Support
builder.RegisterType<SonarrQualityDefinitionUpdater>();
builder.RegisterType<SonarrQualityDefinitionGuideParser>().As<ISonarrQualityDefinitionGuideParser>();
}
private static void RadarrRegistrations(ContainerBuilder builder)
{
// Services
builder.RegisterType<QualityDefinitionService>().As<IQualityDefinitionService>();
builder.RegisterType<CustomFormatService>().As<ICustomFormatService>();
builder.RegisterType<QualityProfileService>().As<IQualityProfileService>();
builder.Register(c =>
{
var config = c.Resolve<IConfigurationProvider>().ActiveConfiguration;
return new ServerInfo(config.BaseUrl, config.ApiKey);
})
.As<IServerInfo>();
// Quality Definition Support
builder.RegisterType<RadarrQualityDefinitionUpdater>();
builder.RegisterType<RadarrQualityDefinitionGuideParser>().As<IRadarrQualityDefinitionGuideParser>();
// Custom Format Support
builder.RegisterType<CustomFormatUpdater>().As<ICustomFormatUpdater>();
builder.RegisterType<GithubCustomFormatJsonRequester>().As<IRadarrGuideService>();
builder.RegisterType<CachePersister>().As<ICachePersister>();
// Guide Processor
builder.RegisterType<GuideProcessor>().As<IGuideProcessor>(); // todo: register as singleton to avoid parsing guide multiple times when using 2 or more instances in config
builder.RegisterAggregateService<IGuideProcessorSteps>();
builder.RegisterType<CustomFormatStep>().As<ICustomFormatStep>();
builder.RegisterType<ConfigStep>().As<IConfigStep>();
builder.RegisterType<QualityProfileStep>().As<IQualityProfileStep>();
// Persistence Processor
builder.RegisterType<PersistenceProcessor>().As<IPersistenceProcessor>();
builder.RegisterAggregateService<IPersistenceProcessorSteps>();
builder.RegisterType<JsonTransactionStep>().As<IJsonTransactionStep>();
builder.RegisterType<CustomFormatApiPersistenceStep>().As<ICustomFormatApiPersistenceStep>();
builder.RegisterType<QualityProfileApiPersistenceStep>().As<IQualityProfileApiPersistenceStep>();
}
private static void ConfigurationRegistrations(ContainerBuilder builder)
{
builder.RegisterModule<ConfigAutofacModule>();
builder.RegisterType<ObjectFactory>()
.As<IObjectFactory>();
builder.RegisterGeneric(typeof(ConfigurationLoader<>))
.As(typeof(IConfigurationLoader<>));
builder.RegisterType<ConfigurationProvider>()
.As<IConfigurationProvider>()
.SingleInstance();
// note: Do not allow consumers to resolve IServiceConfiguration directly; if this gets cached
// they end up using the wrong configuration when multiple instances are used.
// builder.Register(c => c.Resolve<IConfigurationProvider>().ActiveConfiguration)
@ -140,15 +78,17 @@ namespace Trash
public static IContainer Setup(ContainerBuilder builder)
{
builder.RegisterType<FileSystem>().As<IFileSystem>();
builder.RegisterType<ServiceCache>().As<IServiceCache>();
builder.RegisterModule<CacheAutofacModule>();
builder.RegisterType<CacheStoragePath>().As<ICacheStoragePath>();
ConfigurationRegistrations(builder);
CommandRegistrations(builder);
SetupLogging(builder);
SonarrRegistrations(builder);
RadarrRegistrations(builder);
builder.RegisterModule<SonarrAutofacModule>();
builder.RegisterModule<RadarrAutofacModule>();
// builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
return builder.Build();

@ -2,7 +2,8 @@
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using Trash.YamlDotNet;
using Common.YamlDotNet;
using TrashLib.Config;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
using TrashLib.Config;
namespace Trash.Config
{

@ -1,7 +1,7 @@
using System.Threading.Tasks;
using Autofac;
using CliFx;
using Trash.Command;
using Trash.Command.Helpers;
namespace Trash
{

@ -1,10 +0,0 @@
using System.Threading.Tasks;
using Trash.Command;
namespace Trash.Radarr.CustomFormat
{
public interface ICustomFormatUpdater
{
Task Process(IServiceCommand args, RadarrConfiguration config);
}
}

@ -1,8 +0,0 @@
using Trash.Command;
namespace Trash.Radarr
{
public interface IRadarrCommand : IServiceCommand
{
}
}

@ -1,8 +0,0 @@
using Trash.Command;
namespace Trash.Sonarr
{
public interface ISonarrCommand : IServiceCommand
{
}
}

@ -6,23 +6,19 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" />
<PackageReference Include="Autofac.Extras.AggregateService" />
<PackageReference Include="Autofac" />
<PackageReference Include="CliFx" />
<PackageReference Include="Flurl.Http" />
<PackageReference Include="Flurl" />
<PackageReference Include="morelinq" />
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Serilog.Sinks.File" />
<PackageReference Include="Serilog" />
<PackageReference Include="System.Data.HashFunction.FNV" />
<PackageReference Include="System.IO.Abstractions" />
<PackageReference Include="YamlDotNet" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\TrashLib\TrashLib.csproj" />
</ItemGroup>
<ItemGroup>

@ -9,10 +9,10 @@ using NSubstitute;
using NUnit.Framework;
using Serilog;
using TestLibrary.NSubstitute;
using Trash.Cache;
using Trash.Config;
using TrashLib.Cache;
using TrashLib.Config;
namespace Trash.Tests.Cache
namespace TrashLib.Tests.Cache
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -4,13 +4,13 @@ using Newtonsoft.Json.Linq;
using NSubstitute;
using NUnit.Framework;
using Serilog;
using Trash.Cache;
using Trash.Radarr.CustomFormat;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using Trash.Radarr.CustomFormat.Processors.PersistenceSteps;
using TrashLib.Cache;
using TrashLib.Radarr.CustomFormat;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
namespace Trash.Tests.Radarr.CustomFormat
namespace TrashLib.Tests.Radarr.CustomFormat
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -4,9 +4,9 @@ using System.Threading.Tasks;
using FluentAssertions;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using Trash.Radarr.CustomFormat.Guide;
using TrashLib.Radarr.CustomFormat.Guide;
namespace Trash.Tests.Radarr.CustomFormat.Guide
namespace TrashLib.Tests.Radarr.CustomFormat.Guide
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -7,14 +7,14 @@ using Newtonsoft.Json.Linq;
using NUnit.Framework;
using Serilog;
using TestLibrary.FluentAssertions;
using Trash.Radarr;
using Trash.Radarr.CustomFormat.Guide;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Processors;
using Trash.Radarr.CustomFormat.Processors.GuideSteps;
using Trash.TestLibrary;
using TrashLib.Radarr;
using TrashLib.Radarr.CustomFormat.Guide;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Processors;
using TrashLib.Radarr.CustomFormat.Processors.GuideSteps;
namespace Trash.Tests.Radarr.CustomFormat.Processors
namespace TrashLib.Tests.Radarr.CustomFormat.Processors
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -2,12 +2,12 @@ using System.Collections.Generic;
using FluentAssertions;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using Trash.Radarr;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using Trash.Radarr.CustomFormat.Processors.GuideSteps;
using TrashLib.Radarr;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.GuideSteps;
namespace Trash.Tests.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -5,12 +5,12 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using TestLibrary.FluentAssertions;
using Trash.Radarr;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using Trash.Radarr.CustomFormat.Processors.GuideSteps;
using TrashLib.Radarr;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.GuideSteps;
namespace Trash.Tests.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -2,12 +2,12 @@ using System.Collections.Generic;
using FluentAssertions;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using Trash.Radarr;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Processors.GuideSteps;
using Trash.TestLibrary;
using TrashLib.Radarr;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Processors.GuideSteps;
namespace Trash.Tests.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -4,14 +4,14 @@ using System.Collections.ObjectModel;
using Newtonsoft.Json.Linq;
using NSubstitute;
using NUnit.Framework;
using Trash.Config;
using Trash.Radarr;
using Trash.Radarr.CustomFormat.Api;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using Trash.Radarr.CustomFormat.Processors;
namespace Trash.Tests.Radarr.CustomFormat.Processors
using TrashLib.Config;
using TrashLib.Radarr;
using TrashLib.Radarr.CustomFormat.Api;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors;
namespace TrashLib.Tests.Radarr.CustomFormat.Processors
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -3,12 +3,12 @@ using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using NSubstitute;
using NUnit.Framework;
using Trash.Radarr.CustomFormat.Api;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using Trash.Radarr.CustomFormat.Processors.PersistenceSteps;
using TrashLib.Radarr.CustomFormat.Api;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
namespace Trash.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -5,9 +5,9 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using TestLibrary.FluentAssertions;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using Trash.Radarr.CustomFormat.Processors.PersistenceSteps;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
/* Sample Custom Format response from Radarr API
{
@ -37,7 +37,7 @@ using Trash.Radarr.CustomFormat.Processors.PersistenceSteps;
}
*/
namespace Trash.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -6,13 +6,13 @@ using Newtonsoft.Json.Linq;
using NSubstitute;
using NUnit.Framework;
using TestLibrary.NSubstitute;
using Trash.Radarr.CustomFormat.Api;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using Trash.Radarr.CustomFormat.Processors.PersistenceSteps;
using Trash.TestLibrary;
using TrashLib.Radarr.CustomFormat.Api;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
namespace Trash.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -1,8 +1,8 @@
using FluentAssertions;
using NUnit.Framework;
using Trash.Radarr.QualityDefinition;
using TrashLib.Radarr.QualityDefinition;
namespace Trash.Tests.Radarr.QualityDefinition
namespace TrashLib.Tests.Radarr.QualityDefinition
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -6,11 +6,12 @@ using FluentAssertions;
using NSubstitute;
using NUnit.Framework;
using Trash.Config;
using Trash.Radarr;
using TrashLib.Config;
using TrashLib.Radarr;
using YamlDotNet.Core;
using YamlDotNet.Serialization.ObjectFactories;
namespace Trash.Tests.Radarr
namespace TrashLib.Tests.Radarr
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -1,8 +1,8 @@
using FluentAssertions;
using NUnit.Framework;
using Trash.Sonarr.QualityDefinition;
using TrashLib.Sonarr.QualityDefinition;
namespace Trash.Tests.Sonarr.QualityDefinition
namespace TrashLib.Tests.Sonarr.QualityDefinition
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -1,10 +1,10 @@
using System.Collections.Generic;
using FluentAssertions;
using NUnit.Framework;
using Trash.Sonarr;
using Trash.Sonarr.ReleaseProfile;
using TrashLib.Sonarr;
using TrashLib.Sonarr.ReleaseProfile;
namespace Trash.Tests.Sonarr.ReleaseProfile
namespace TrashLib.Tests.Sonarr.ReleaseProfile
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -6,10 +6,10 @@ using NUnit.Framework;
using Serilog;
using Serilog.Sinks.TestCorrelator;
using TestLibrary;
using Trash.Sonarr;
using Trash.Sonarr.ReleaseProfile;
using TrashLib.Sonarr;
using TrashLib.Sonarr.ReleaseProfile;
namespace Trash.Tests.Sonarr.ReleaseProfile
namespace TrashLib.Tests.Sonarr.ReleaseProfile
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -1,8 +1,8 @@
using FluentAssertions;
using NUnit.Framework;
using Trash.Sonarr.ReleaseProfile;
using TrashLib.Sonarr.ReleaseProfile;
namespace Trash.Tests.Sonarr.ReleaseProfile
namespace TrashLib.Tests.Sonarr.ReleaseProfile
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -1,11 +1,11 @@
using NSubstitute;
using NUnit.Framework;
using Serilog;
using Trash.Sonarr;
using Trash.Sonarr.Api;
using Trash.Sonarr.ReleaseProfile;
using TrashLib.Sonarr;
using TrashLib.Sonarr.Api;
using TrashLib.Sonarr.ReleaseProfile;
namespace Trash.Tests.Sonarr
namespace TrashLib.Tests.Sonarr
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
@ -13,7 +13,6 @@ namespace Trash.Tests.Sonarr
{
private class Context
{
public ISonarrCommand Args { get; } = Substitute.For<ISonarrCommand>();
public IReleaseProfileGuideParser Parser { get; } = Substitute.For<IReleaseProfileGuideParser>();
public ISonarrApi Api { get; } = Substitute.For<ISonarrApi>();
public ILogger Logger { get; } = Substitute.For<ILogger>();
@ -25,7 +24,7 @@ namespace Trash.Tests.Sonarr
var context = new Context();
var logic = new ReleaseProfileUpdater(context.Logger, context.Parser, context.Api);
logic.Process(context.Args, new SonarrConfiguration());
logic.Process(false, new SonarrConfiguration());
context.Parser.DidNotReceive().GetMarkdownData(Arg.Any<ReleaseProfileType>());
}
@ -42,7 +41,7 @@ namespace Trash.Tests.Sonarr
};
var logic = new ReleaseProfileUpdater(context.Logger, context.Parser, context.Api);
logic.Process(context.Args, config);
logic.Process(false, config);
context.Parser.Received().ParseMarkdown(config.ReleaseProfiles[0], "theMarkdown");
}

@ -5,11 +5,12 @@ using FluentAssertions;
using NSubstitute;
using NUnit.Framework;
using Trash.Config;
using Trash.Sonarr;
using TrashLib.Config;
using TrashLib.Sonarr;
using YamlDotNet.Core;
using YamlDotNet.Serialization.ObjectFactories;
namespace Trash.Tests.Sonarr
namespace TrashLib.Tests.Sonarr
{
[TestFixture]
[Parallelizable(ParallelScope.All)]

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TestLibrary\TestLibrary.csproj" />
<ProjectReference Include="..\Trash.TestLibrary\Trash.TestLibrary.csproj" />
<ProjectReference Include="..\Trash\Trash.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,13 @@
using Autofac;
namespace TrashLib.Cache
{
public class CacheAutofacModule : Module
{
protected override void Load(ContainerBuilder builder)
{
// Clients must register their own implementation of ICacheStoragePath
builder.RegisterType<ServiceCache>().As<IServiceCache>();
}
}
}

@ -1,9 +1,9 @@
using System;
namespace Trash.Cache
namespace TrashLib.Cache
{
[AttributeUsage(AttributeTargets.Class)]
public sealed class CacheObjectNameAttribute : Attribute
internal sealed class CacheObjectNameAttribute : Attribute
{
public CacheObjectNameAttribute(string name)
{

@ -1,4 +1,4 @@
namespace Trash.Cache
namespace TrashLib.Cache
{
public interface ICacheStoragePath
{

@ -1,4 +1,4 @@
namespace Trash.Cache
namespace TrashLib.Cache
{
public interface IServiceCache
{

@ -9,11 +9,11 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using Serilog;
using Trash.Config;
using TrashLib.Config;
namespace Trash.Cache
namespace TrashLib.Cache
{
public class ServiceCache : IServiceCache
internal class ServiceCache : IServiceCache
{
private static readonly Regex AllowedObjectNameCharacters = new(@"^[\w-]+$", RegexOptions.Compiled);
private readonly IConfigurationProvider _configProvider;

@ -0,0 +1,14 @@
using Autofac;
namespace TrashLib.Config
{
public class ConfigAutofacModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<ConfigurationProvider>()
.As<IConfigurationProvider>()
.SingleInstance();
}
}
}

@ -1,6 +1,6 @@
using System;
namespace Trash.Config
namespace TrashLib.Config
{
internal class ConfigurationProvider : IConfigurationProvider
{

@ -1,4 +1,4 @@
namespace Trash.Config
namespace TrashLib.Config
{
public interface IConfigurationProvider
{

@ -1,4 +1,4 @@
namespace Trash.Config
namespace TrashLib.Config
{
public interface IServiceConfiguration
{

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Trash.Config
namespace TrashLib.Config
{
public abstract class ServiceConfiguration : IServiceConfiguration
{

@ -0,0 +1,12 @@
using System;
namespace TrashLib.ExceptionTypes
{
public class VersionException : Exception
{
public VersionException(string msg)
: base(msg)
{
}
}
}

@ -1,4 +1,4 @@
namespace Trash.Config
namespace TrashLib
{
public interface IServerInfo
{

@ -3,10 +3,9 @@ using System.Threading.Tasks;
using Flurl;
using Flurl.Http;
using Newtonsoft.Json.Linq;
using Trash.Config;
using Trash.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models;
namespace Trash.Radarr.CustomFormat.Api
namespace TrashLib.Radarr.CustomFormat.Api
{
internal class CustomFormatService : ICustomFormatService
{

@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Trash.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models;
namespace Trash.Radarr.CustomFormat.Api
namespace TrashLib.Radarr.CustomFormat.Api
{
public interface ICustomFormatService
{

@ -2,7 +2,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace Trash.Radarr.CustomFormat.Api
namespace TrashLib.Radarr.CustomFormat.Api
{
public interface IQualityProfileService
{

@ -3,9 +3,8 @@ using System.Threading.Tasks;
using Flurl;
using Flurl.Http;
using Newtonsoft.Json.Linq;
using Trash.Config;
namespace Trash.Radarr.CustomFormat.Api
namespace TrashLib.Radarr.CustomFormat.Api
{
internal class QualityProfileService : IQualityProfileService
{

@ -1,4 +1,4 @@
namespace Trash.Radarr.CustomFormat
namespace TrashLib.Radarr.CustomFormat
{
public enum ApiOperationType
{

@ -1,13 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using Serilog;
using Trash.Cache;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using TrashLib.Cache;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
namespace Trash.Radarr.CustomFormat
namespace TrashLib.Radarr.CustomFormat
{
public class CachePersister : ICachePersister
internal class CachePersister : ICachePersister
{
private readonly IServiceCache _cache;

@ -1,13 +1,12 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Common.Extensions;
using Serilog;
using Trash.Command;
using Trash.Extensions;
using Trash.Radarr.CustomFormat.Processors;
using Trash.Radarr.CustomFormat.Processors.PersistenceSteps;
using TrashLib.Radarr.CustomFormat.Processors;
using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
namespace Trash.Radarr.CustomFormat
namespace TrashLib.Radarr.CustomFormat
{
internal class CustomFormatUpdater : ICustomFormatUpdater
{
@ -29,7 +28,7 @@ namespace Trash.Radarr.CustomFormat
private ILogger Log { get; }
public async Task Process(IServiceCommand args, RadarrConfiguration config)
public async Task Process(bool isPreview, RadarrConfiguration config)
{
_cache.Load();
@ -40,7 +39,7 @@ namespace Trash.Radarr.CustomFormat
return;
}
if (args.Preview)
if (isPreview)
{
PreviewCustomFormats();
}
@ -49,7 +48,7 @@ namespace Trash.Radarr.CustomFormat
await _persistenceProcessor.PersistCustomFormats(_guideProcessor.ProcessedCustomFormats,
_guideProcessor.DeletedCustomFormatsInCache, _guideProcessor.ProfileScores);
PrintApiStatistics(args, _persistenceProcessor.Transactions);
PrintApiStatistics(_persistenceProcessor.Transactions);
PrintQualityProfileUpdates();
// Cache all the custom formats (using ID from API response).
@ -92,7 +91,7 @@ namespace Trash.Radarr.CustomFormat
}
}
private void PrintApiStatistics(IServiceCommand args, CustomFormatTransactionData transactions)
private void PrintApiStatistics(CustomFormatTransactionData transactions)
{
var created = transactions.NewCustomFormats;
if (created.Count > 0)
@ -108,14 +107,11 @@ namespace Trash.Radarr.CustomFormat
updated.Select(r => r.Name));
}
if (args.Debug)
var skipped = transactions.UnchangedCustomFormats;
if (skipped.Count > 0)
{
var skipped = transactions.UnchangedCustomFormats;
if (skipped.Count > 0)
{
Log.Debug("Skipped {Count} Custom Formats that did not change: {CustomFormats}", skipped.Count,
skipped.Select(r => r.Name));
}
Log.Debug("Skipped {Count} Custom Formats that did not change: {CustomFormats}", skipped.Count,
skipped.Select(r => r.Name));
}
var deleted = transactions.DeletedCustomFormatIds;

@ -7,9 +7,9 @@ using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Trash.Radarr.CustomFormat.Guide
namespace TrashLib.Radarr.CustomFormat.Guide
{
public class GithubCustomFormatJsonRequester : IRadarrGuideService
internal class GithubCustomFormatJsonRequester : IRadarrGuideService
{
private readonly ISerializer _flurlSerializer;

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Trash.Radarr.CustomFormat.Guide
namespace TrashLib.Radarr.CustomFormat.Guide
{
public interface IRadarrGuideService
{

@ -1,8 +1,8 @@
using System.Collections.Generic;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
namespace Trash.Radarr.CustomFormat
namespace TrashLib.Radarr.CustomFormat
{
public interface ICachePersister
{

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace TrashLib.Radarr.CustomFormat
{
public interface ICustomFormatUpdater
{
Task Process(bool isPreview, RadarrConfiguration config);
}
}

@ -1,7 +1,7 @@
using System.Collections.Generic;
using Trash.Cache;
using TrashLib.Cache;
namespace Trash.Radarr.CustomFormat.Models.Cache
namespace TrashLib.Radarr.CustomFormat.Models.Cache
{
[CacheObjectName("custom-format-cache")]
public class CustomFormatCache

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Trash.Radarr.CustomFormat.Models
namespace TrashLib.Radarr.CustomFormat.Models
{
public class ProcessedConfigData
{

@ -1,9 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Linq;
using Trash.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Models.Cache;
namespace Trash.Radarr.CustomFormat.Models
namespace TrashLib.Radarr.CustomFormat.Models
{
public class ProcessedCustomFormatData
{

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Trash.Radarr.CustomFormat.Models
namespace TrashLib.Radarr.CustomFormat.Models
{
public record FormatMappingEntry(ProcessedCustomFormatData CustomFormat, int Score);

@ -1,4 +1,4 @@
namespace Trash.Radarr.CustomFormat.Models
namespace TrashLib.Radarr.CustomFormat.Models
{
public enum FormatScoreUpdateReason
{

@ -3,12 +3,12 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Serilog;
using Trash.Radarr.CustomFormat.Guide;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using Trash.Radarr.CustomFormat.Processors.GuideSteps;
using TrashLib.Radarr.CustomFormat.Guide;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.GuideSteps;
namespace Trash.Radarr.CustomFormat.Processors
namespace TrashLib.Radarr.CustomFormat.Processors
{
public interface IGuideProcessorSteps
{

@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Common.Extensions;
using MoreLinq.Extensions;
using Trash.Extensions;
using Trash.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models;
namespace Trash.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
public class ConfigStep : IConfigStep
internal class ConfigStep : IConfigStep
{
public List<string> CustomFormatsNotInGuide { get; } = new();
public List<ProcessedConfigData> ConfigData { get; } = new();

@ -1,14 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Common.Extensions;
using Newtonsoft.Json.Linq;
using Trash.Extensions;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
namespace Trash.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
public class CustomFormatStep : ICustomFormatStep
internal class CustomFormatStep : ICustomFormatStep
{
public List<(string, string)> CustomFormatsWithOutdatedNames { get; } = new();
public List<ProcessedCustomFormatData> ProcessedCustomFormats { get; } = new();

@ -1,7 +1,7 @@
using System.Collections.Generic;
using Trash.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models;
namespace Trash.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
public interface IConfigStep
{

@ -1,8 +1,8 @@
using System.Collections.Generic;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
namespace Trash.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
public interface ICustomFormatStep
{

@ -1,7 +1,7 @@
using System.Collections.Generic;
using Trash.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models;
namespace Trash.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
public interface IQualityProfileStep
{

@ -1,9 +1,9 @@
using System.Collections.Generic;
using Trash.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models;
namespace Trash.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
public class QualityProfileStep : IQualityProfileStep
internal class QualityProfileStep : IQualityProfileStep
{
public Dictionary<string, QualityProfileCustomFormatScoreMapping> ProfileScores { get; } = new();
public List<(string name, string trashId, string profileName)> CustomFormatsWithoutScore { get; } = new();

@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
namespace Trash.Radarr.CustomFormat.Processors
namespace TrashLib.Radarr.CustomFormat.Processors
{
internal interface IGuideProcessor
{

@ -1,10 +1,10 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using Trash.Radarr.CustomFormat.Processors.PersistenceSteps;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
namespace Trash.Radarr.CustomFormat.Processors
namespace TrashLib.Radarr.CustomFormat.Processors
{
public interface IPersistenceProcessor
{

@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Trash.Config;
using Trash.Radarr.CustomFormat.Api;
using Trash.Radarr.CustomFormat.Models;
using Trash.Radarr.CustomFormat.Models.Cache;
using Trash.Radarr.CustomFormat.Processors.PersistenceSteps;
using TrashLib.Config;
using TrashLib.Radarr.CustomFormat.Api;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
namespace Trash.Radarr.CustomFormat.Processors
namespace TrashLib.Radarr.CustomFormat.Processors
{
public interface IPersistenceProcessorSteps
{

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save