mirror of
https://github.com/Radarr/Radarr.git
synced 2024-08-16 23:39:44 +02:00
back to tiny for now
This commit is contained in:
parent
2912561d0e
commit
4deecde092
@ -8,9 +8,9 @@ namespace NzbDrone.Api.Directories
|
||||
{
|
||||
public class DirectoryModule : NzbDroneApiModule
|
||||
{
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
|
||||
public DirectoryModule(DiskProvider diskProvider)
|
||||
public DirectoryModule(IDiskProvider diskProvider)
|
||||
: base("/directories")
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
|
@ -6,11 +6,11 @@
|
||||
|
||||
namespace NzbDrone.Api.ErrorManagement
|
||||
{
|
||||
public class ErrorPipeline
|
||||
public class NzbDroneErrorPipeline
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ErrorPipeline(Logger logger)
|
||||
public NzbDroneErrorPipeline(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
@ -13,11 +13,11 @@ public interface IProcessStaticResource
|
||||
|
||||
public class StaticResourceProvider : IProcessStaticResource
|
||||
{
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IMapHttpRequestsToDisk _requestMapper;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public StaticResourceProvider(DiskProvider diskProvider, IMapHttpRequestsToDisk requestMapper, Logger logger)
|
||||
public StaticResourceProvider(IDiskProvider diskProvider, IMapHttpRequestsToDisk requestMapper, Logger logger)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_requestMapper = requestMapper;
|
||||
|
@ -5,14 +5,14 @@
|
||||
using NzbDrone.Api.ErrorManagement;
|
||||
using NzbDrone.Api.Extensions;
|
||||
using NzbDrone.Api.Frontend;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Api
|
||||
{
|
||||
[Singleton]
|
||||
public class NancyBootstrapper : TinyIoCNancyBootstrapper
|
||||
{
|
||||
private readonly TinyIoCContainer _tinyIoCContainer;
|
||||
@ -28,18 +28,12 @@ protected override void ApplicationStartup(TinyIoCContainer container, IPipeline
|
||||
{
|
||||
_logger.Info("Starting NzbDrone API");
|
||||
AutomapperBootstraper.InitializeAutomapper();
|
||||
RegisterReporting(container);
|
||||
|
||||
container.Resolve<IMessageAggregator>().PublishEvent(new ApplicationStartedEvent());
|
||||
|
||||
ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve<ErrorPipeline>().HandleException);
|
||||
ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve<NzbDroneErrorPipeline>().HandleException);
|
||||
}
|
||||
|
||||
private void RegisterReporting(TinyIoCContainer container)
|
||||
{
|
||||
EnvironmentProvider.UGuid = container.Resolve<ConfigService>().UGuid;
|
||||
ReportingService.RestProvider = container.Resolve<RestProvider>();
|
||||
}
|
||||
|
||||
protected override TinyIoCContainer GetApplicationContainer()
|
||||
{
|
||||
|
@ -131,7 +131,7 @@
|
||||
<Compile Include="NancyBootstrapper.cs" />
|
||||
<Compile Include="ErrorManagement\ErrorHandler.cs" />
|
||||
<Compile Include="ErrorManagement\ErrorModel.cs" />
|
||||
<Compile Include="ErrorManagement\ErrorPipeline.cs" />
|
||||
<Compile Include="ErrorManagement\NzbDroneErrorPipeline.cs" />
|
||||
<Compile Include="Exceptions\InvalidApiKeyException.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="NzbDroneApiModule.cs" />
|
||||
|
@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.AspNet.SignalR.Json;
|
||||
using NzbDrone.Common.Composition;
|
||||
|
||||
namespace NzbDrone.Api.SignalR
|
||||
{
|
||||
[Singleton]
|
||||
public class Serializer : IJsonSerializer
|
||||
{
|
||||
private readonly Common.IJsonSerializer _nzbDroneSerializer;
|
||||
@ -35,7 +37,7 @@ public object Parse(string json, Type targetType)
|
||||
{
|
||||
return _nzbDroneSerializer.Deserialize(json, targetType);
|
||||
}
|
||||
|
||||
|
||||
return _signalRSerializer.Parse(json, targetType);
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.SignalR;
|
||||
using Microsoft.AspNet.SignalR.Json;
|
||||
using TinyIoC;
|
||||
using NzbDrone.Common.Composition;
|
||||
|
||||
namespace NzbDrone.Api.SignalR
|
||||
{
|
||||
public class SignalrDependencyResolver : DefaultDependencyResolver
|
||||
{
|
||||
private readonly TinyIoCContainer _container;
|
||||
private readonly IContainer _container;
|
||||
|
||||
public static void Register(TinyIoCContainer container)
|
||||
public static void Register(IContainer container)
|
||||
{
|
||||
GlobalHost.DependencyResolver = new SignalrDependencyResolver(container);
|
||||
|
||||
container.Register<IJsonSerializer, Serializer>().AsSingleton();
|
||||
}
|
||||
|
||||
private SignalrDependencyResolver(TinyIoCContainer container)
|
||||
private SignalrDependencyResolver(IContainer container)
|
||||
{
|
||||
_container = container;
|
||||
}
|
||||
|
||||
public override object GetService(Type serviceType)
|
||||
{
|
||||
return _container.CanResolve(serviceType) ? _container.Resolve(serviceType) : base.GetService(serviceType);
|
||||
}
|
||||
if (_container.IsTypeRegistered(serviceType))
|
||||
{
|
||||
return _container.Resolve(serviceType);
|
||||
}
|
||||
|
||||
public override IEnumerable<object> GetServices(Type serviceType)
|
||||
{
|
||||
var objects = _container.CanResolve(serviceType) ? _container.ResolveAll(serviceType) : new object[] { };
|
||||
return objects.Concat(base.GetServices(serviceType));
|
||||
return base.GetService(serviceType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,10 @@ public class MonitoringProviderTest : TestBase<PriorityMonitor>
|
||||
[Test]
|
||||
public void Ensure_priority_doesnt_fail_on_invalid_iis_proccess_id()
|
||||
{
|
||||
Mocker.GetMock<ProcessProvider>().Setup(c => c.GetCurrentProcess())
|
||||
Mocker.GetMock<IProcessProvider>().Setup(c => c.GetCurrentProcess())
|
||||
.Returns(Builder<ProcessInfo>.CreateNew().With(c => c.Priority == ProcessPriorityClass.Normal).Build());
|
||||
|
||||
Mocker.GetMock<ProcessProvider>().Setup(c => c.GetProcessById(It.IsAny<int>())).Returns((ProcessInfo)null);
|
||||
Mocker.GetMock<IProcessProvider>().Setup(c => c.GetProcessById(It.IsAny<int>())).Returns((ProcessInfo)null);
|
||||
|
||||
Subject.EnsurePriority(null);
|
||||
}
|
||||
@ -26,7 +26,7 @@ public void Ensure_priority_doesnt_fail_on_invalid_iis_proccess_id()
|
||||
[Test]
|
||||
public void Ensure_should_log_warn_exception_rather_than_throw()
|
||||
{
|
||||
Mocker.GetMock<ProcessProvider>().Setup(c => c.GetCurrentProcess()).Throws<InvalidOperationException>();
|
||||
Mocker.GetMock<IProcessProvider>().Setup(c => c.GetCurrentProcess()).Throws<InvalidOperationException>();
|
||||
Subject.EnsurePriority(null);
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
|
@ -44,11 +44,11 @@ public void GetApplicationMode_two_args(string a, string b, ApplicationModes mod
|
||||
[Test]
|
||||
public void Route_should_call_install_service_when_application_mode_is_install()
|
||||
{
|
||||
var serviceProviderMock = Mocker.GetMock<ServiceProvider>(MockBehavior.Strict);
|
||||
var serviceProviderMock = Mocker.GetMock<IServiceProvider>(MockBehavior.Strict);
|
||||
serviceProviderMock.Setup(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME));
|
||||
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
|
||||
serviceProviderMock.Setup(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME));
|
||||
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
Mocker.GetMock<IEnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
|
||||
Subject.Route(ApplicationModes.InstallService);
|
||||
|
||||
@ -59,9 +59,9 @@ public void Route_should_call_install_service_when_application_mode_is_install()
|
||||
[Test]
|
||||
public void Route_should_call_uninstall_service_when_application_mode_is_uninstall()
|
||||
{
|
||||
var serviceProviderMock = Mocker.GetMock<ServiceProvider>();
|
||||
var serviceProviderMock = Mocker.GetMock<IServiceProvider>();
|
||||
serviceProviderMock.Setup(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME));
|
||||
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
Mocker.GetMock<IEnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
|
||||
|
||||
Subject.Route(ApplicationModes.UninstallService);
|
||||
@ -72,7 +72,7 @@ public void Route_should_call_uninstall_service_when_application_mode_is_uninsta
|
||||
[Test]
|
||||
public void Route_should_call_console_service_when_application_mode_is_console()
|
||||
{
|
||||
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
Mocker.GetMock<IEnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
Mocker.GetMock<IConsoleService>().SetupGet(c => c.IsConsoleApplication).Returns(true);
|
||||
|
||||
Subject.Route(ApplicationModes.Console);
|
||||
@ -87,8 +87,8 @@ public void Route_should_call_console_service_when_application_mode_is_console()
|
||||
[TestCase(ApplicationModes.Help)]
|
||||
public void Route_should_call_service_start_when_run_in_service_more(ApplicationModes applicationModes)
|
||||
{
|
||||
var envMock = Mocker.GetMock<EnvironmentProvider>();
|
||||
var serviceProvider = Mocker.GetMock<ServiceProvider>();
|
||||
var envMock = Mocker.GetMock<IEnvironmentProvider>();
|
||||
var serviceProvider = Mocker.GetMock<IServiceProvider>();
|
||||
|
||||
envMock.SetupGet(c => c.IsUserInteractive).Returns(false);
|
||||
|
||||
@ -104,8 +104,8 @@ public void Route_should_call_service_start_when_run_in_service_more(Application
|
||||
public void show_error_on_install_if_service_already_exist()
|
||||
{
|
||||
var consoleMock = Mocker.GetMock<IConsoleService>();
|
||||
var serviceMock = Mocker.GetMock<ServiceProvider>();
|
||||
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
var serviceMock = Mocker.GetMock<IServiceProvider>();
|
||||
Mocker.GetMock<IEnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
|
||||
consoleMock.Setup(c => c.PrintServiceAlreadyExist());
|
||||
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
|
||||
@ -119,8 +119,8 @@ public void show_error_on_install_if_service_already_exist()
|
||||
public void show_error_on_uninstall_if_service_doesnt_exist()
|
||||
{
|
||||
var consoleMock = Mocker.GetMock<IConsoleService>();
|
||||
var serviceMock = Mocker.GetMock<ServiceProvider>();
|
||||
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
var serviceMock = Mocker.GetMock<IServiceProvider>();
|
||||
Mocker.GetMock<IEnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
|
||||
consoleMock.Setup(c => c.PrintServiceDoestExist());
|
||||
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
|
||||
|
@ -1,17 +1,14 @@
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Model;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class ConfigFileProviderTest : TestBase
|
||||
|
||||
public class ConfigFileProviderTest : TestBase<ConfigFileProvider>
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
@ -19,7 +16,7 @@ public void SetUp()
|
||||
WithTempAsAppPath();
|
||||
|
||||
//Reset config file
|
||||
var configFile = Mocker.Resolve<EnvironmentProvider>().GetConfigPath();
|
||||
var configFile = Mocker.Resolve<IEnvironmentProvider>().GetConfigPath();
|
||||
|
||||
if (File.Exists(configFile))
|
||||
File.Delete(configFile);
|
||||
@ -31,10 +28,10 @@ public void GetValue_Success()
|
||||
const string key = "Port";
|
||||
const string value = "8989";
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
||||
|
||||
|
||||
var result = Subject.GetValue(key, value);
|
||||
|
||||
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
@ -44,10 +41,10 @@ public void GetInt_Success()
|
||||
const string key = "Port";
|
||||
const int value = 8989;
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
|
||||
|
||||
|
||||
var result = Subject.GetValueInt(key, value);
|
||||
|
||||
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
@ -57,20 +54,20 @@ public void GetBool_Success()
|
||||
const string key = "LaunchBrowser";
|
||||
const bool value = true;
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
|
||||
|
||||
|
||||
var result = Subject.GetValueBoolean(key, value);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLaunchBrowser_Success()
|
||||
{
|
||||
|
||||
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
||||
|
||||
|
||||
var result = Subject.LaunchBrowser;
|
||||
|
||||
|
||||
result.Should().Be(true);
|
||||
}
|
||||
|
||||
@ -79,10 +76,10 @@ public void GetPort_Success()
|
||||
{
|
||||
const int value = 8989;
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ConfigFileProvider>().Port;
|
||||
|
||||
|
||||
var result = Subject.Port;
|
||||
|
||||
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
@ -92,11 +89,11 @@ public void SetValue_bool()
|
||||
const string key = "LaunchBrowser";
|
||||
const bool value = false;
|
||||
|
||||
|
||||
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
||||
Subject.SetValue(key, value);
|
||||
|
||||
|
||||
var result = Subject.LaunchBrowser;
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
@ -106,11 +103,11 @@ public void SetValue_int()
|
||||
const string key = "Port";
|
||||
const int value = 12345;
|
||||
|
||||
|
||||
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ConfigFileProvider>().Port;
|
||||
Subject.SetValue(key, value);
|
||||
|
||||
|
||||
var result = Subject.Port;
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
@ -120,10 +117,10 @@ public void GetValue_New_Key()
|
||||
const string key = "Hello";
|
||||
const string value = "World";
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
||||
|
||||
|
||||
var result = Subject.GetValue(key, value);
|
||||
|
||||
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
@ -131,10 +128,10 @@ public void GetValue_New_Key()
|
||||
public void GetAuthenticationType_No_Existing_Value()
|
||||
{
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
||||
|
||||
|
||||
var result = Subject.AuthenticationType;
|
||||
|
||||
|
||||
result.Should().Be(AuthenticationType.Anonymous);
|
||||
}
|
||||
|
||||
@ -142,24 +139,24 @@ public void GetAuthenticationType_No_Existing_Value()
|
||||
public void GetAuthenticationType_Windows()
|
||||
{
|
||||
|
||||
Mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
|
||||
Subject.SetValue("AuthenticationType", 1);
|
||||
|
||||
|
||||
var result = Subject.AuthenticationType;
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
||||
|
||||
|
||||
result.Should().Be(AuthenticationType.Windows);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Guid_should_return_the_same_every_time()
|
||||
{
|
||||
|
||||
var firstResponse = Mocker.Resolve<ConfigFileProvider>().Guid;
|
||||
var secondResponse = Mocker.Resolve<ConfigFileProvider>().Guid;
|
||||
|
||||
var firstResponse = Subject.Guid;
|
||||
var secondResponse = Subject.Guid;
|
||||
|
||||
|
||||
|
||||
|
||||
secondResponse.Should().Be(firstResponse);
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,6 @@
|
||||
<Compile Include="EventingTests\MessageAggregatorCommandTests.cs" />
|
||||
<Compile Include="EventingTests\MessageAggregatorEventTests.cs" />
|
||||
<Compile Include="ReflectionExtensions.cs" />
|
||||
<Compile Include="ReportingService_ReportParseError_Fixture.cs" />
|
||||
<Compile Include="PathExtensionFixture.cs" />
|
||||
<Compile Include="DiskProviderFixture.cs" />
|
||||
<Compile Include="EnviromentProviderTest.cs" />
|
||||
|
@ -1,77 +0,0 @@
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Contract;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class ReportingService_ReportParseError_Fixture : TestBase
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
ReportingService.ClearCache();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
ReportingService.ClearCache();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void report_parse_error_should_send_report_to_server()
|
||||
{
|
||||
const string badTitle = "Bad Title";
|
||||
|
||||
ReportingService.ReportParseError(badTitle);
|
||||
MockedRestProvider.Verify(p => p.PostData(It.Is<string>(c => c.ToLower().StartsWith("http://services.nzbdrone.com/")), It.Is<ParseErrorReport>(c => c.Title == badTitle)), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void report_parse_error_should_send_duplicated_report_once()
|
||||
{
|
||||
const string badTitle = "Bad Title";
|
||||
|
||||
ReportingService.ReportParseError(badTitle);
|
||||
ReportingService.ReportParseError(badTitle);
|
||||
|
||||
MockedRestProvider.Verify(p => p.PostData(It.IsAny<string>(), It.IsAny<ReportBase>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void report_parse_error_should_send_duplicated_report_once_with_diffrent_casing()
|
||||
{
|
||||
const string badTitle = "Bad Title";
|
||||
|
||||
ReportingService.ReportParseError(badTitle.ToUpper());
|
||||
ReportingService.ReportParseError(badTitle);
|
||||
|
||||
MockedRestProvider.Verify(p => p.PostData(It.IsAny<string>(), It.IsAny<ReportBase>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void report_parse_error_should_send_multiple_reports_if_titles_are_diffrent()
|
||||
{
|
||||
ReportingService.ReportParseError("title 1");
|
||||
ReportingService.ReportParseError("title 2");
|
||||
|
||||
MockedRestProvider.Verify(p => p.PostData(It.IsAny<string>(), It.IsAny<ReportBase>()), Times.Exactly(2));
|
||||
MockedRestProvider.Verify(p => p.PostData(It.IsAny<string>(), It.Is<ParseErrorReport>(c => c.Title == "title 1")), Times.Once());
|
||||
MockedRestProvider.Verify(p => p.PostData(It.IsAny<string>(), It.Is<ParseErrorReport>(c => c.Title == "title 2")), Times.Once());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void report_parse_error()
|
||||
{
|
||||
ReportingService.RestProvider = new RestProvider(new EnvironmentProvider());
|
||||
ReportingService.ReportParseError("Test error");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
99
NzbDrone.Common/Composition/Container.cs
Normal file
99
NzbDrone.Common/Composition/Container.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Common.Composition
|
||||
{
|
||||
public class Container : IContainer
|
||||
{
|
||||
private readonly TinyIoCContainer _container;
|
||||
|
||||
public Container(TinyIoCContainer container)
|
||||
{
|
||||
_container = container;
|
||||
//_container.Options.AllowOverridingRegistrations = true;
|
||||
|
||||
|
||||
//_container.RegisterSingle(LogManager.GetCurrentClassLogger());
|
||||
|
||||
_container.Register<IContainer>(this);
|
||||
//container.RegisterWithContext(dependencyContext => LogManager.GetLogger(dependencyContext.ImplementationType.Name));
|
||||
}
|
||||
|
||||
public void Register<TService, TImplementation>()
|
||||
where TImplementation : class, TService
|
||||
where TService : class
|
||||
{
|
||||
_container.Register<TService, TImplementation>();
|
||||
}
|
||||
|
||||
public TinyIoCContainer TinyContainer { get { return _container; } }
|
||||
|
||||
public void Register<T>(T instance) where T : class
|
||||
{
|
||||
_container.Register<T>(instance);
|
||||
}
|
||||
|
||||
public T Resolve<T>() where T : class
|
||||
{
|
||||
return _container.Resolve<T>();
|
||||
}
|
||||
|
||||
public object Resolve(Type type)
|
||||
{
|
||||
return _container.Resolve(type);
|
||||
}
|
||||
|
||||
public void Register(Type serviceType, Type implementationType)
|
||||
{
|
||||
_container.Register(serviceType, implementationType);
|
||||
}
|
||||
|
||||
public void Register<TService>(Func<IContainer, TService> factory) where TService : class
|
||||
{
|
||||
_container.Register((c, n) => factory(this));
|
||||
}
|
||||
|
||||
public void RegisterSingleton<TService, TImplementation>()
|
||||
where TImplementation : class, TService
|
||||
where TService : class
|
||||
{
|
||||
_container.Register<TService, TImplementation>().AsSingleton();
|
||||
}
|
||||
|
||||
public void RegisterSingleton<T>() where T : class
|
||||
{
|
||||
_container.Register<T, T>().AsSingleton();
|
||||
}
|
||||
|
||||
public void RegisterSingleton(Type service, Type implementation)
|
||||
{
|
||||
_container.Register(service, implementation).AsSingleton();
|
||||
}
|
||||
|
||||
public IEnumerable<T> ResolveAll<T>() where T : class
|
||||
{
|
||||
return _container.ResolveAll<T>();
|
||||
}
|
||||
|
||||
public IEnumerable<object> ResolveAll(Type type)
|
||||
{
|
||||
return _container.ResolveAll(type);
|
||||
}
|
||||
|
||||
public void Register(Type registrationType, object instance)
|
||||
{
|
||||
_container.Register(registrationType, instance);
|
||||
}
|
||||
|
||||
public void RegisterAll(Type registrationType, IEnumerable<Type> implementationList)
|
||||
{
|
||||
_container.RegisterMultiple(registrationType, implementationList);
|
||||
}
|
||||
|
||||
public bool IsTypeRegistered(Type type)
|
||||
{
|
||||
return _container.CanResolve(type);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,21 +2,22 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using TinyIoC;
|
||||
using NzbDrone.Common.Reflection;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
|
||||
namespace NzbDrone.Common.Composition
|
||||
{
|
||||
public abstract class ContainerBuilderBase
|
||||
{
|
||||
protected readonly TinyIoCContainer Container;
|
||||
private readonly List<Type> _loadedTypes;
|
||||
|
||||
public IContainer Container { get; private set; }
|
||||
|
||||
protected ContainerBuilderBase(params string[] assemblies)
|
||||
{
|
||||
Container = new TinyIoCContainer();
|
||||
Container = new Container(new TinyIoCContainer());
|
||||
|
||||
_loadedTypes = new List<Type>();
|
||||
|
||||
@ -30,16 +31,13 @@ protected ContainerBuilderBase(params string[] assemblies)
|
||||
|
||||
private void AutoRegisterInterfaces()
|
||||
{
|
||||
var simpleInterfaces = _loadedTypes.Where(t => t.IsInterface).ToList();
|
||||
var appliedInterfaces = _loadedTypes.SelectMany(t => t.GetInterfaces()).Where(i => i.Assembly.FullName.Contains("NzbDrone")).ToList();
|
||||
var loadedInterfaces = _loadedTypes.Where(t => t.IsInterface).ToList();
|
||||
var implementedInterfaces = _loadedTypes.SelectMany(t => t.GetInterfaces()).Where(i => !i.Assembly.FullName.StartsWith("System")).ToList();
|
||||
|
||||
var contracts = simpleInterfaces.Union(appliedInterfaces)
|
||||
.Except(new List<Type> { typeof(IMessage), typeof(ICommand), typeof(IEvent) });
|
||||
var contracts = loadedInterfaces.Union(implementedInterfaces).Where(c => !c.IsGenericTypeDefinition && !string.IsNullOrWhiteSpace(c.FullName))
|
||||
.Except(new List<Type> { typeof(IMessage), typeof(ICommand), typeof(IEvent), typeof(IContainer) }).Distinct().OrderBy(c => c.FullName);
|
||||
|
||||
|
||||
var count = contracts.Count();
|
||||
|
||||
foreach (var contract in simpleInterfaces.Union(contracts))
|
||||
foreach (var contract in contracts)
|
||||
{
|
||||
AutoRegisterImplementations(contract);
|
||||
}
|
||||
@ -52,7 +50,14 @@ protected void AutoRegisterImplementations<TContract>()
|
||||
|
||||
private void AutoRegisterImplementations(Type contractType)
|
||||
{
|
||||
var implementations = GetImplementations(contractType).ToList();
|
||||
if (contractType.Name.Contains("oots"))
|
||||
{
|
||||
int adawd = 12;
|
||||
}
|
||||
|
||||
var implementations = GetImplementations(contractType).Where(c => !c.IsGenericTypeDefinition).ToList();
|
||||
|
||||
|
||||
|
||||
if (implementations.Count == 0)
|
||||
{
|
||||
@ -60,20 +65,20 @@ private void AutoRegisterImplementations(Type contractType)
|
||||
}
|
||||
if (implementations.Count == 1)
|
||||
{
|
||||
if (implementations.Single().HasAttribute<SingletonAttribute>())
|
||||
var impl = implementations.Single();
|
||||
|
||||
if (impl.HasAttribute<SingletonAttribute>())
|
||||
{
|
||||
Container.Register(contractType, implementations.Single()).AsSingleton();
|
||||
Container.RegisterSingleton(contractType, impl);
|
||||
}
|
||||
else
|
||||
{
|
||||
Container.Register(contractType, implementations.Single()).AsMultiInstance();
|
||||
Container.Register(contractType, impl);
|
||||
}
|
||||
|
||||
Container.RegisterMultiple(contractType, implementations).AsMultiInstance();
|
||||
}
|
||||
else
|
||||
{
|
||||
Container.RegisterMultiple(contractType, implementations).AsMultiInstance();
|
||||
Container.RegisterAll(contractType, implementations);
|
||||
}
|
||||
}
|
||||
|
30
NzbDrone.Common/Composition/IContainer.cs
Normal file
30
NzbDrone.Common/Composition/IContainer.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Common.Composition
|
||||
{
|
||||
public interface IContainer
|
||||
{
|
||||
TinyIoCContainer TinyContainer { get; }
|
||||
void Register<T>(T instance) where T : class;
|
||||
|
||||
void Register<TService, TImplementation>()
|
||||
where TImplementation : class, TService
|
||||
where TService : class;
|
||||
T Resolve<T>() where T : class;
|
||||
object Resolve(Type type);
|
||||
void Register(Type serviceType, Type implementationType);
|
||||
void Register<TService>(Func<IContainer, TService> factory) where TService : class;
|
||||
void RegisterSingleton<TService, TImplementation>()
|
||||
where TImplementation : class, TService
|
||||
where TService : class;
|
||||
void RegisterSingleton<T>() where T : class;
|
||||
void RegisterSingleton(Type service, Type implementation);
|
||||
IEnumerable<T> ResolveAll<T>() where T : class;
|
||||
IEnumerable<object> ResolveAll(Type type);
|
||||
void Register(Type registrationType, object instance);
|
||||
void RegisterAll(Type registrationType, IEnumerable<Type> implementationList);
|
||||
bool IsTypeRegistered(Type type);
|
||||
}
|
||||
}
|
@ -19,11 +19,11 @@ public interface IHttpProvider
|
||||
|
||||
public class HttpProvider : IHttpProvider
|
||||
{
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly string _userAgent;
|
||||
|
||||
public HttpProvider(EnvironmentProvider environmentProvider)
|
||||
public HttpProvider(IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_userAgent = String.Format("NzbDrone {0}", _environmentProvider.Version);
|
||||
|
@ -6,13 +6,25 @@
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public class ConfigFileProvider
|
||||
public interface IConfigFileProvider
|
||||
{
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
Guid Guid { get; }
|
||||
int Port { get; set; }
|
||||
bool LaunchBrowser { get; set; }
|
||||
AuthenticationType AuthenticationType { get; set; }
|
||||
int GetValueInt(string key, int defaultValue);
|
||||
bool GetValueBoolean(string key, bool defaultValue);
|
||||
string GetValue(string key, object defaultValue);
|
||||
void SetValue(string key, object value);
|
||||
}
|
||||
|
||||
public class ConfigFileProvider : IConfigFileProvider
|
||||
{
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
|
||||
private readonly string _configFile;
|
||||
|
||||
public ConfigFileProvider(EnvironmentProvider environmentProvider)
|
||||
public ConfigFileProvider(IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_configFile = _environmentProvider.GetConfigPath();
|
||||
@ -20,10 +32,6 @@ public ConfigFileProvider(EnvironmentProvider environmentProvider)
|
||||
CreateDefaultConfigFile();
|
||||
}
|
||||
|
||||
public ConfigFileProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual Guid Guid
|
||||
{
|
@ -7,7 +7,38 @@
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public class DiskProvider
|
||||
public interface IDiskProvider
|
||||
{
|
||||
DateTime GetLastFolderWrite(string path);
|
||||
DateTime GetLastFileWrite(string path);
|
||||
void EnsureFolder(string path);
|
||||
bool FolderExists(string path);
|
||||
bool FileExists(string path);
|
||||
string[] GetDirectories(string path);
|
||||
string[] GetFiles(string path, SearchOption searchOption);
|
||||
long GetDirectorySize(string path);
|
||||
long GetSize(string path);
|
||||
String CreateFolder(string path);
|
||||
void CopyDirectory(string source, string target);
|
||||
void MoveDirectory(string source, string destination);
|
||||
void DeleteFile(string path);
|
||||
void MoveFile(string source, string destination);
|
||||
void DeleteFolder(string path, bool recursive);
|
||||
DateTime DirectoryDateCreated(string path);
|
||||
IEnumerable<FileInfo> GetFileInfos(string path, string pattern, SearchOption searchOption);
|
||||
void InheritFolderPermissions(string filename);
|
||||
long GetAvilableSpace(string path);
|
||||
string ReadAllText(string filePath);
|
||||
void WriteAllText(string filename, string contents);
|
||||
void FileSetLastWriteTimeUtc(string path, DateTime dateTime);
|
||||
void DirectorySetLastWriteTimeUtc(string path, DateTime dateTime);
|
||||
bool IsFolderLocked(string path);
|
||||
bool IsFileLocked(FileInfo file);
|
||||
bool IsChildOfPath(string child, string parent);
|
||||
string GetPathRoot(string path);
|
||||
}
|
||||
|
||||
public class DiskProvider : IDiskProvider
|
||||
{
|
||||
enum TransferAction
|
||||
{
|
||||
@ -214,7 +245,7 @@ public virtual long GetAvilableSpace(string path)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return DriveFreeSpaceEx(path);
|
||||
}
|
||||
|
@ -5,11 +5,22 @@
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public class EnvironmentProvider
|
||||
public interface IEnvironmentProvider
|
||||
{
|
||||
bool IsUserInteractive { get; }
|
||||
string WorkingDirectory { get; }
|
||||
string StartUpPath { get; }
|
||||
String SystemTemp { get; }
|
||||
Version Version { get; }
|
||||
DateTime BuildDateTime { get; }
|
||||
Version GetOsVersion();
|
||||
}
|
||||
|
||||
public class EnvironmentProvider : IEnvironmentProvider
|
||||
{
|
||||
private static readonly string ProcessName = Process.GetCurrentProcess().ProcessName.ToLower();
|
||||
|
||||
private static readonly EnvironmentProvider Instance = new EnvironmentProvider();
|
||||
private static readonly IEnvironmentProvider Instance = new EnvironmentProvider();
|
||||
|
||||
public static bool IsProduction
|
||||
{
|
@ -7,19 +7,32 @@
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public class ProcessProvider
|
||||
public interface IProcessProvider
|
||||
{
|
||||
ProcessInfo GetCurrentProcess();
|
||||
ProcessInfo GetProcessById(int id);
|
||||
IEnumerable<ProcessInfo> GetProcessByName(string name);
|
||||
void Start(string path);
|
||||
Process Start(ProcessStartInfo startInfo);
|
||||
void WaitForExit(Process process);
|
||||
void Kill(int processId);
|
||||
void SetPriority(int processId, ProcessPriorityClass priority);
|
||||
void KillAll(string processName);
|
||||
}
|
||||
|
||||
public class ProcessProvider : IProcessProvider
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public const string NzbDroneProcessName = "NzbDrone";
|
||||
public const string NzbDroneConsoleProcessName = "NzbDrone.Console";
|
||||
|
||||
public virtual ProcessInfo GetCurrentProcess()
|
||||
public ProcessInfo GetCurrentProcess()
|
||||
{
|
||||
return ConvertToProcessInfo(Process.GetCurrentProcess());
|
||||
}
|
||||
|
||||
public virtual ProcessInfo GetProcessById(int id)
|
||||
public ProcessInfo GetProcessById(int id)
|
||||
{
|
||||
Logger.Trace("Finding process with Id:{0}", id);
|
||||
|
||||
@ -37,17 +50,17 @@ public virtual ProcessInfo GetProcessById(int id)
|
||||
return processInfo;
|
||||
}
|
||||
|
||||
public virtual IEnumerable<ProcessInfo> GetProcessByName(string name)
|
||||
public IEnumerable<ProcessInfo> GetProcessByName(string name)
|
||||
{
|
||||
return Process.GetProcessesByName(name).Select(ConvertToProcessInfo).Where(p => p != null);
|
||||
}
|
||||
|
||||
public virtual void Start(string path)
|
||||
public void Start(string path)
|
||||
{
|
||||
Process.Start(path);
|
||||
}
|
||||
|
||||
public virtual Process Start(ProcessStartInfo startInfo)
|
||||
public Process Start(ProcessStartInfo startInfo)
|
||||
{
|
||||
Logger.Info("Starting process. [{0}]", startInfo.FileName);
|
||||
|
||||
@ -59,13 +72,13 @@ public virtual Process Start(ProcessStartInfo startInfo)
|
||||
return process;
|
||||
}
|
||||
|
||||
public virtual void WaitForExit(Process process)
|
||||
public void WaitForExit(Process process)
|
||||
{
|
||||
Logger.Trace("Waiting for process {0} to exit.", process.ProcessName);
|
||||
process.WaitForExit();
|
||||
}
|
||||
|
||||
public virtual void Kill(int processId)
|
||||
public void Kill(int processId)
|
||||
{
|
||||
if (processId == 0 || Process.GetProcesses().All(p => p.Id != processId))
|
||||
{
|
||||
@ -87,7 +100,7 @@ public virtual void Kill(int processId)
|
||||
Logger.Info("[{0}]: Process terminated successfully", process.Id);
|
||||
}
|
||||
|
||||
public virtual void SetPriority(int processId, ProcessPriorityClass priority)
|
||||
public void SetPriority(int processId, ProcessPriorityClass priority)
|
||||
{
|
||||
var process = Process.GetProcessById(processId);
|
||||
|
||||
@ -112,7 +125,7 @@ private static ProcessInfo ConvertToProcessInfo(Process process)
|
||||
};
|
||||
}
|
||||
|
||||
public virtual void KillAll(string processName)
|
||||
public void KillAll(string processName)
|
||||
{
|
||||
var processToKill = GetProcessByName(processName);
|
||||
|
@ -8,7 +8,19 @@
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public class ServiceProvider
|
||||
public interface IServiceProvider
|
||||
{
|
||||
bool ServiceExist(string name);
|
||||
bool IsServiceRunning(string name);
|
||||
void Install(string serviceName);
|
||||
void UnInstall(string serviceName);
|
||||
void Run(ServiceBase service);
|
||||
ServiceController GetService(string serviceName);
|
||||
void Stop(string serviceName);
|
||||
void Start(string serviceName);
|
||||
}
|
||||
|
||||
public class ServiceProvider : IServiceProvider
|
||||
{
|
||||
public const string NZBDRONE_SERVICE_NAME = "NzbDrone";
|
||||
|
@ -2,9 +2,11 @@
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Composition;
|
||||
|
||||
namespace NzbDrone.Common.Messaging
|
||||
{
|
||||
[Singleton]
|
||||
public class MessageAggregator : IMessageAggregator
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
@ -79,8 +79,10 @@
|
||||
<Compile Include="Cache\Cached.cs" />
|
||||
<Compile Include="Cache\CacheManger.cs" />
|
||||
<Compile Include="Cache\ICached.cs" />
|
||||
<Compile Include="Composition\Class1.cs" />
|
||||
<Compile Include="ContainerBuilderBase.cs" />
|
||||
<Compile Include="Composition\Container.cs" />
|
||||
<Compile Include="Composition\IContainer.cs" />
|
||||
<Compile Include="Composition\SingletonAttribute.cs" />
|
||||
<Compile Include="Composition\ContainerBuilderBase.cs" />
|
||||
<Compile Include="EnsureThat\Ensure.cs" />
|
||||
<Compile Include="EnsureThat\EnsureBoolExtensions.cs" />
|
||||
<Compile Include="EnsureThat\EnsureCollectionExtensions.cs" />
|
||||
@ -122,22 +124,21 @@
|
||||
<Compile Include="ServiceFactory.cs" />
|
||||
<Compile Include="StringExtention.cs" />
|
||||
<Compile Include="HttpProvider.cs" />
|
||||
<Compile Include="ConfigFileProvider.cs" />
|
||||
<Compile Include="IConfigFileProvider.cs" />
|
||||
<Compile Include="ConsoleService.cs" />
|
||||
<Compile Include="Contract\ReportBase.cs" />
|
||||
<Compile Include="Contract\ParseErrorReport.cs" />
|
||||
<Compile Include="Model\AuthenticationType.cs" />
|
||||
<Compile Include="PathExtensions.cs" />
|
||||
<Compile Include="DiskProvider.cs" />
|
||||
<Compile Include="EnvironmentProvider.cs" />
|
||||
<Compile Include="IDiskProvider.cs" />
|
||||
<Compile Include="IEnvironmentProvider.cs" />
|
||||
<Compile Include="Model\ProcessInfo.cs" />
|
||||
<Compile Include="ProcessProvider.cs" />
|
||||
<Compile Include="IProcessProvider.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\SharedAssemblyInfo.cs" />
|
||||
<Compile Include="ReportingService.cs" />
|
||||
<Compile Include="RestProvider.cs" />
|
||||
<Compile Include="SecurityProvider.cs" />
|
||||
<Compile Include="ServiceProvider.cs" />
|
||||
<Compile Include="IServiceProvider.cs" />
|
||||
<Compile Include="TinyIoC.cs" />
|
||||
<Compile Include="TryParseExtension.cs" />
|
||||
<Compile Include="UdpProvider.cs" />
|
||||
|
@ -49,62 +49,62 @@ public static string GetActualCasing(this string filename)
|
||||
}
|
||||
|
||||
|
||||
public static string GetAppDataPath(this EnvironmentProvider environmentProvider)
|
||||
public static string GetAppDataPath(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.WorkingDirectory, APP_DATA);
|
||||
}
|
||||
|
||||
public static string GetConfigPath(this EnvironmentProvider environmentProvider)
|
||||
public static string GetConfigPath(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.WorkingDirectory, APP_CONFIG_FILE);
|
||||
}
|
||||
|
||||
public static string GetMediaCoverPath(this EnvironmentProvider environmentProvider)
|
||||
public static string GetMediaCoverPath(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), "MediaCover");
|
||||
}
|
||||
|
||||
public static string GetUpdateLogFolder(this EnvironmentProvider environmentProvider)
|
||||
public static string GetUpdateLogFolder(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.WorkingDirectory, UPDATE_LOG_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetUpdateSandboxFolder(this EnvironmentProvider environmentProvider)
|
||||
public static string GetUpdateSandboxFolder(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.SystemTemp, UPDATE_SANDBOX_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetUpdateBackUpFolder(this EnvironmentProvider environmentProvider)
|
||||
public static string GetUpdateBackUpFolder(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetUpdateSandboxFolder(), UPDATE_BACKUP_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetUpdatePackageFolder(this EnvironmentProvider environmentProvider)
|
||||
public static string GetUpdatePackageFolder(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetUpdateSandboxFolder(), UPDATE_PACKAGE_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetUpdateClientFolder(this EnvironmentProvider environmentProvider)
|
||||
public static string GetUpdateClientFolder(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetUpdatePackageFolder(), UPDATE_CLIENT_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetUpdateClientExePath(this EnvironmentProvider environmentProvider)
|
||||
public static string GetUpdateClientExePath(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetUpdateSandboxFolder(), UPDATE_CLIENT_EXE);
|
||||
}
|
||||
|
||||
public static string GetSandboxLogFolder(this EnvironmentProvider environmentProvider)
|
||||
public static string GetSandboxLogFolder(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetUpdateSandboxFolder(), UPDATE_LOG_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetConfigBackupFile(this EnvironmentProvider environmentProvider)
|
||||
public static string GetConfigBackupFile(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), BACKUP_ZIP_FILE);
|
||||
}
|
||||
|
||||
public static string GetNzbDroneDatabase(this EnvironmentProvider environmentProvider)
|
||||
public static string GetNzbDroneDatabase(this IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_DB);
|
||||
}
|
||||
|
@ -1,73 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Contract;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public static class ReportingService
|
||||
{
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private const string SERVICE_URL = "http://services.nzbdrone.com/reporting";
|
||||
private const string PARSE_URL = SERVICE_URL + "/ParseError";
|
||||
|
||||
public static RestProvider RestProvider { get; set; }
|
||||
|
||||
|
||||
private static readonly HashSet<string> parserErrorCache = new HashSet<string>();
|
||||
|
||||
public static void ClearCache()
|
||||
{
|
||||
lock (parserErrorCache)
|
||||
{
|
||||
parserErrorCache.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReportParseError(string title)
|
||||
{
|
||||
try
|
||||
{
|
||||
VerifyDependencies();
|
||||
|
||||
lock (parserErrorCache)
|
||||
{
|
||||
if (parserErrorCache.Contains(title.ToLower())) return;
|
||||
|
||||
parserErrorCache.Add(title.ToLower());
|
||||
}
|
||||
|
||||
var report = new ParseErrorReport { Title = title };
|
||||
RestProvider.PostData(PARSE_URL, report);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (!EnvironmentProvider.IsProduction)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
e.Data.Add("title", title);
|
||||
logger.InfoException("Unable to report parse error", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void VerifyDependencies()
|
||||
{
|
||||
if (RestProvider == null)
|
||||
{
|
||||
if (EnvironmentProvider.IsProduction)
|
||||
{
|
||||
logger.Warn("Rest provider wasn't provided. creating new one!");
|
||||
RestProvider = new RestProvider(new EnvironmentProvider());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("REST Provider wasn't configured correctly.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -15,10 +15,10 @@ public class RestProvider
|
||||
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
|
||||
|
||||
public RestProvider(EnvironmentProvider environmentProvider)
|
||||
public RestProvider(IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ public interface ISecurityProvider
|
||||
|
||||
public class SecurityProvider : ISecurityProvider
|
||||
{
|
||||
private readonly ConfigFileProvider _configFileProvider;
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly ProcessProvider _processProvider;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public SecurityProvider(ConfigFileProvider configFileProvider, EnvironmentProvider environmentProvider,
|
||||
ProcessProvider processProvider, Logger logger)
|
||||
public SecurityProvider(IConfigFileProvider configFileProvider, IEnvironmentProvider environmentProvider,
|
||||
IProcessProvider processProvider, Logger logger)
|
||||
{
|
||||
_configFileProvider = configFileProvider;
|
||||
_environmentProvider = environmentProvider;
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using TinyIoC;
|
||||
using NzbDrone.Common.Composition;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
@ -14,9 +14,9 @@ public interface IServiceFactory
|
||||
|
||||
public class ServiceFactory : IServiceFactory
|
||||
{
|
||||
private readonly TinyIoCContainer _container;
|
||||
private readonly IContainer _container;
|
||||
|
||||
public ServiceFactory(TinyIoCContainer container)
|
||||
public ServiceFactory(IContainer container)
|
||||
{
|
||||
_container = container;
|
||||
}
|
||||
|
@ -122,18 +122,18 @@ public void set_fields_should_only_update_selected_filed()
|
||||
{
|
||||
var childModel = new ScheduledTask
|
||||
{
|
||||
Name = "Address",
|
||||
TypeName = "Address",
|
||||
Interval = 12
|
||||
};
|
||||
|
||||
Subject.Insert(childModel);
|
||||
|
||||
childModel.Name = "A";
|
||||
childModel.TypeName = "A";
|
||||
childModel.Interval = 0;
|
||||
|
||||
Subject.SetFields(childModel, t => t.Name);
|
||||
Subject.SetFields(childModel, t => t.TypeName);
|
||||
|
||||
Db.All<ScheduledTask>().Single().Name.Should().Be("A");
|
||||
Db.All<ScheduledTask>().Single().TypeName.Should().Be("A");
|
||||
Db.All<ScheduledTask>().Single().Interval.Should().Be(12);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ public void Setup()
|
||||
|
||||
private void WithExistingFile()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>().Setup(c => c.FileExists(nzbPath)).Returns(true);
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(nzbPath)).Returns(true);
|
||||
}
|
||||
|
||||
private void WithFailedDownload()
|
||||
|
@ -31,7 +31,7 @@ public void Setup()
|
||||
|
||||
private void WithExistingFile()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>().Setup(c => c.FileExists(nzbPath)).Returns(true);
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(nzbPath)).Returns(true);
|
||||
}
|
||||
|
||||
private void WithFailedDownload()
|
||||
|
@ -104,7 +104,7 @@ public void should_use_EpisodeFiles_quality()
|
||||
.Setup(e => e.BuildFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".mkv"))
|
||||
.Returns(fi);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FileExists(currentFilename))
|
||||
.Returns(true);
|
||||
|
||||
|
@ -27,7 +27,7 @@ private void GiveEpisodeFiles(IEnumerable<EpisodeFile> episodeFiles)
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(e => e.FileExists(It.Is<String>(c => c != DeletedPath)))
|
||||
.Returns(true);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public void Setup()
|
||||
@"C:\Test\movie.exe"
|
||||
};
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetFiles(It.IsAny<String>(), SearchOption.AllDirectories))
|
||||
.Returns(_files);
|
||||
}
|
||||
@ -39,8 +39,8 @@ public void should_check_all_directories()
|
||||
|
||||
Subject.GetVideoFiles(path);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once());
|
||||
Mocker.GetMock<DiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -50,8 +50,8 @@ public void should_check_all_directories_when_allDirectories_is_true()
|
||||
|
||||
Subject.GetVideoFiles(path, true);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once());
|
||||
Mocker.GetMock<DiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -61,8 +61,8 @@ public void should_check_top_level_directory_only_when_allDirectories_is_false()
|
||||
|
||||
Subject.GetVideoFiles(path, false);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Never());
|
||||
Mocker.GetMock<DiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Once());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Never());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -56,7 +56,7 @@ private void GivenFileSize(long size)
|
||||
{
|
||||
_fileSize = size;
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(d => d.GetSize(It.IsAny<String>()))
|
||||
.Returns(size);
|
||||
}
|
||||
@ -221,7 +221,7 @@ public void should_import_if_file_size_is_under_70MB_but_runTime_over_3_minutes(
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
VerifyFileImport(result);
|
||||
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -30,24 +30,24 @@ public void Setup()
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Returns(_videoFiles);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
|
||||
.Returns(_subFolders);
|
||||
}
|
||||
|
||||
private void WithOldWrite()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetLastFolderWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.Now.AddDays(-5));
|
||||
}
|
||||
|
||||
private void WithRecentFolderWrite()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetLastFolderWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.UtcNow);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetLastFileWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.UtcNow);
|
||||
}
|
||||
@ -125,7 +125,7 @@ public void should_not_attempt_move_if_nothing_is_imported()
|
||||
public void should_skip_if_folder_is_in_use_by_another_process()
|
||||
{
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
|
||||
.Returns(true);
|
||||
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
|
@ -19,19 +19,19 @@ public class CleanupFixture : CoreTest
|
||||
|
||||
private void WithExpired()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetLastFolderWrite(It.IsAny<String>()))
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetLastFolderWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.UtcNow.AddDays(-10));
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetLastFileWrite(It.IsAny<String>()))
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetLastFileWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.UtcNow.AddDays(-10));
|
||||
}
|
||||
|
||||
private void WithNonExpired()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetLastFolderWrite(It.IsAny<String>()))
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetLastFolderWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.UtcNow.AddDays(-3));
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetLastFileWrite(It.IsAny<String>()))
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetLastFileWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.UtcNow.AddDays(-3));
|
||||
}
|
||||
|
||||
@ -40,10 +40,10 @@ public void Setup()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().SetupGet(s => s.RecycleBin).Returns(RecycleBin);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectories(RecycleBin))
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetDirectories(RecycleBin))
|
||||
.Returns(new [] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" });
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetFiles(RecycleBin, SearchOption.TopDirectoryOnly))
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(RecycleBin, SearchOption.TopDirectoryOnly))
|
||||
.Returns(new [] { @"C:\Test\RecycleBin\File1.avi", @"C:\Test\RecycleBin\File2.mkv" });
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ public void should_return_if_recycleBin_not_configured()
|
||||
|
||||
Mocker.Resolve<RecycleBinProvider>().Cleanup();
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.GetDirectories(It.IsAny<String>()), Times.Never());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetDirectories(It.IsAny<String>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -63,7 +63,7 @@ public void should_delete_all_expired_folders()
|
||||
WithExpired();
|
||||
Mocker.Resolve<RecycleBinProvider>().Cleanup();
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.DeleteFolder(It.IsAny<String>(), true), Times.Exactly(3));
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.DeleteFolder(It.IsAny<String>(), true), Times.Exactly(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -72,7 +72,7 @@ public void should_delete_all_expired_files()
|
||||
WithExpired();
|
||||
Mocker.Resolve<RecycleBinProvider>().Cleanup();
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.DeleteFile(It.IsAny<String>()), Times.Exactly(2));
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.DeleteFile(It.IsAny<String>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -81,7 +81,7 @@ public void should_not_delete_all_non_expired_folders()
|
||||
WithNonExpired();
|
||||
Mocker.Resolve<RecycleBinProvider>().Cleanup();
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.DeleteFolder(It.IsAny<String>(), true), Times.Never());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.DeleteFolder(It.IsAny<String>(), true), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -90,7 +90,7 @@ public void should_not_delete_all_non_expired_files()
|
||||
WithNonExpired();
|
||||
Mocker.Resolve<RecycleBinProvider>().Cleanup();
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.DeleteFile(It.IsAny<String>()), Times.Never());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.DeleteFile(It.IsAny<String>()), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public void should_use_delete_when_recycleBin_is_not_configured()
|
||||
|
||||
Mocker.Resolve<RecycleBinProvider>().DeleteDirectory(path);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.DeleteFolder(path, true), Times.Once());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.DeleteFolder(path, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -55,7 +55,7 @@ public void should_use_move_when_recycleBin_is_configured()
|
||||
|
||||
Mocker.Resolve<RecycleBinProvider>().DeleteDirectory(path);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.MoveDirectory(path, @"C:\Test\Recycle Bin\30 Rock"), Times.Once());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.MoveDirectory(path, @"C:\Test\Recycle Bin\30 Rock"), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -67,7 +67,7 @@ public void should_call_directorySetLastWriteTime()
|
||||
|
||||
Mocker.Resolve<RecycleBinProvider>().DeleteDirectory(path);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.DirectorySetLastWriteTimeUtc(@"C:\Test\Recycle Bin\30 Rock", It.IsAny<DateTime>()), Times.Once());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.DirectorySetLastWriteTimeUtc(@"C:\Test\Recycle Bin\30 Rock", It.IsAny<DateTime>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -76,12 +76,12 @@ public void should_call_fileSetLastWriteTime_for_each_file()
|
||||
WithRecycleBin();
|
||||
var path = @"C:\Test\TV\30 Rock";
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetFiles(@"C:\Test\Recycle Bin\30 Rock", SearchOption.AllDirectories))
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(@"C:\Test\Recycle Bin\30 Rock", SearchOption.AllDirectories))
|
||||
.Returns(new[]{ "File1", "File2", "File3" });
|
||||
|
||||
Mocker.Resolve<RecycleBinProvider>().DeleteDirectory(path);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.FileSetLastWriteTimeUtc(It.IsAny<String>(), It.IsAny<DateTime>()), Times.Exactly(3));
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.FileSetLastWriteTimeUtc(It.IsAny<String>(), It.IsAny<DateTime>()), Times.Exactly(3));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public void should_use_delete_when_recycleBin_is_not_configured()
|
||||
|
||||
Mocker.Resolve<RecycleBinProvider>().DeleteFile(path);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.DeleteFile(path), Times.Once());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.DeleteFile(path), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -55,7 +55,7 @@ public void should_use_move_when_recycleBin_is_configured()
|
||||
|
||||
Mocker.Resolve<RecycleBinProvider>().DeleteFile(path);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.MoveFile(path, @"C:\Test\Recycle Bin\S01E01.avi"), Times.Once());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.MoveFile(path, @"C:\Test\Recycle Bin\S01E01.avi"), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -67,7 +67,7 @@ public void should_call_fileSetLastWriteTime_for_each_file()
|
||||
|
||||
Mocker.Resolve<RecycleBinProvider>().DeleteFile(path);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.FileSetLastWriteTimeUtc(@"C:\Test\Recycle Bin\S01E01.avi", It.IsAny<DateTime>()), Times.Once());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.FileSetLastWriteTimeUtc(@"C:\Test\Recycle Bin\S01E01.avi", It.IsAny<DateTime>()), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ public void Setup()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().SetupGet(s => s.RecycleBin).Returns(RecycleBin);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectories(RecycleBin))
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetDirectories(RecycleBin))
|
||||
.Returns(new [] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" });
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetFiles(RecycleBin, SearchOption.TopDirectoryOnly))
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(RecycleBin, SearchOption.TopDirectoryOnly))
|
||||
.Returns(new [] { @"C:\Test\RecycleBin\File1.avi", @"C:\Test\RecycleBin\File2.mkv" });
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ public void should_return_if_recycleBin_not_configured()
|
||||
|
||||
Mocker.Resolve<RecycleBinProvider>().Empty();
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.GetDirectories(It.IsAny<String>()), Times.Never());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetDirectories(It.IsAny<String>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -53,7 +53,7 @@ public void should_delete_all_folders()
|
||||
{
|
||||
Mocker.Resolve<RecycleBinProvider>().Empty();
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.DeleteFolder(It.IsAny<String>(), true), Times.Exactly(3));
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.DeleteFolder(It.IsAny<String>(), true), Times.Exactly(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -61,7 +61,7 @@ public void should_delete_all_files()
|
||||
{
|
||||
Mocker.Resolve<RecycleBinProvider>().Empty();
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(v => v.DeleteFile(It.IsAny<String>()), Times.Exactly(2));
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.DeleteFile(It.IsAny<String>()), Times.Exactly(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ public void should_return_one_drive_when_only_one_root_dir_exists()
|
||||
.Setup(s => s.All())
|
||||
.Returns(new List<RootFolder> { new RootFolder { Id = 1, Path = @"C:\Test\TV" } });
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
|
||||
.Returns(@"C:\");
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetAvilableSpace(@"C:\"))
|
||||
.Returns(123456);
|
||||
|
||||
@ -46,11 +46,11 @@ public void should_return_one_drive_when_two_rootDirs_on_the_same_drive_exist()
|
||||
.Returns(new List<RootFolder> { new RootFolder { Id = 1, Path = @"C:\Test\TV" },
|
||||
new RootFolder { Id = 2, Path = @"C:\Test\TV2" }});
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetPathRoot(It.IsAny<String>()))
|
||||
.Returns(@"C:\");
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetAvilableSpace(@"C:\"))
|
||||
.Returns(123456);
|
||||
|
||||
@ -67,15 +67,15 @@ public void should_return_two_drives_when_two_rootDirs_on_the_different_drive_ex
|
||||
.Returns(new List<RootFolder> { new RootFolder { Id = 1, Path = @"C:\Test\TV" },
|
||||
new RootFolder { Id = 2, Path = @"D:\Test\TV" }});
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
|
||||
.Returns(@"C:\");
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetPathRoot(@"D:\Test\TV"))
|
||||
.Returns(@"D:\");
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetAvilableSpace(It.IsAny<string>()))
|
||||
.Returns(123456);
|
||||
|
||||
@ -91,11 +91,11 @@ public void should_skip_rootDir_if_not_found_on_disk()
|
||||
.Setup(s => s.All())
|
||||
.Returns(new List<RootFolder> { new RootFolder { Id = 1, Path = @"C:\Test\TV" } });
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
|
||||
.Returns(@"C:\");
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetAvilableSpace(It.IsAny<string>()))
|
||||
.Throws(new DirectoryNotFoundException());
|
||||
|
||||
|
@ -21,7 +21,7 @@ public class RootFolderServiceFixture : CoreTest<RootFolderService>
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(m => m.FolderExists(It.IsAny<string>()))
|
||||
.Returns(true);
|
||||
|
||||
@ -32,7 +32,7 @@ public void Setup()
|
||||
|
||||
private void WithNoneExistingFolder()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(m => m.FolderExists(It.IsAny<string>()))
|
||||
.Returns(false);
|
||||
}
|
||||
@ -75,7 +75,7 @@ public void None_existing_folder_returns_empty_list()
|
||||
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeEmpty();
|
||||
Mocker.GetMock<DiskProvider>().Verify(c => c.GetDirectories(It.IsAny<String>()), Times.Never());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(c => c.GetDirectories(It.IsAny<String>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -17,9 +17,9 @@ public void Setup()
|
||||
{
|
||||
WithTempAsAppPath();
|
||||
|
||||
_updateLogFolder = Mocker.GetMock<EnvironmentProvider>().Object.GetUpdateLogFolder();
|
||||
_updateLogFolder = Mocker.GetMock<IEnvironmentProvider>().Object.GetUpdateLogFolder();
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetFiles(_updateLogFolder, SearchOption.TopDirectoryOnly))
|
||||
.Returns(new[]
|
||||
{
|
||||
@ -28,7 +28,7 @@ public void Setup()
|
||||
"C:\\nzbdrone\\update\\2011.12.20-21-08.txt"
|
||||
});
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FolderExists(_updateLogFolder))
|
||||
.Returns(true);
|
||||
}
|
||||
@ -37,7 +37,7 @@ public void Setup()
|
||||
[Test]
|
||||
public void get_logs_should_return_empty_list_if_directory_doesnt_exist()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FolderExists(_updateLogFolder))
|
||||
.Returns(false);
|
||||
|
||||
|
@ -30,13 +30,13 @@ public class UpdateServiceFixture : CoreTest<UpdateService>
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.SystemTemp).Returns(TempFolder);
|
||||
Mocker.GetMock<ConfigFileProvider>().SetupGet(c => c.Guid).Returns(_clientGuid);
|
||||
Mocker.GetMock<IEnvironmentProvider>().SetupGet(c => c.SystemTemp).Returns(TempFolder);
|
||||
Mocker.GetMock<IConfigFileProvider>().SetupGet(c => c.Guid).Returns(_clientGuid);
|
||||
Mocker.GetMock<IUpdatePackageProvider>().Setup(c => c.GetLatestUpdate()).Returns(_updatePackage);
|
||||
|
||||
Mocker.GetMock<ProcessProvider>().Setup(c => c.GetCurrentProcess()).Returns(new ProcessInfo { Id = 12 });
|
||||
Mocker.GetMock<IProcessProvider>().Setup(c => c.GetCurrentProcess()).Returns(new ProcessInfo { Id = 12 });
|
||||
|
||||
_sandboxFolder = Mocker.GetMock<EnvironmentProvider>().Object.GetUpdateSandboxFolder();
|
||||
_sandboxFolder = Mocker.GetMock<IEnvironmentProvider>().Object.GetUpdateSandboxFolder();
|
||||
}
|
||||
|
||||
|
||||
@ -44,21 +44,21 @@ public void Setup()
|
||||
[Test]
|
||||
public void should_delete_sandbox_before_update_if_folder_exists()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>().Setup(c => c.FolderExists(_sandboxFolder)).Returns(true);
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(_sandboxFolder)).Returns(true);
|
||||
|
||||
Subject.InstallAvailableUpdate();
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(c => c.DeleteFolder(_sandboxFolder, true));
|
||||
Mocker.GetMock<IDiskProvider>().Verify(c => c.DeleteFolder(_sandboxFolder, true));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_delete_sandbox_before_update_if_folder_doesnt_exists()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>().Setup(c => c.FolderExists(_sandboxFolder)).Returns(false);
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(_sandboxFolder)).Returns(false);
|
||||
|
||||
Subject.InstallAvailableUpdate();
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(c => c.DeleteFolder(_sandboxFolder, true), Times.Never());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(c => c.DeleteFolder(_sandboxFolder, true), Times.Never());
|
||||
}
|
||||
|
||||
|
||||
@ -85,25 +85,25 @@ public void Should_extract_update_package()
|
||||
[Test]
|
||||
public void Should_copy_update_client_to_root_of_sandbox()
|
||||
{
|
||||
var updateClientFolder = Mocker.GetMock<EnvironmentProvider>().Object.GetUpdateClientFolder();
|
||||
var updateClientFolder = Mocker.GetMock<IEnvironmentProvider>().Object.GetUpdateClientFolder();
|
||||
|
||||
Subject.InstallAvailableUpdate();
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(c => c.MoveDirectory(updateClientFolder, _sandboxFolder));
|
||||
Mocker.GetMock<IDiskProvider>().Verify(c => c.MoveDirectory(updateClientFolder, _sandboxFolder));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_start_update_client()
|
||||
{
|
||||
var updateClientPath = Mocker.GetMock<EnvironmentProvider>().Object.GetUpdateClientExePath();
|
||||
var updateClientPath = Mocker.GetMock<IEnvironmentProvider>().Object.GetUpdateClientExePath();
|
||||
|
||||
|
||||
|
||||
Subject.InstallAvailableUpdate();
|
||||
|
||||
|
||||
Mocker.GetMock<ProcessProvider>().Verify(
|
||||
Mocker.GetMock<IProcessProvider>().Verify(
|
||||
c => c.Start(It.Is<ProcessStartInfo>(p =>
|
||||
p.FileName == updateClientPath &&
|
||||
p.Arguments == "12 " + _clientGuid.ToString())
|
||||
@ -126,11 +126,11 @@ public void Should_download_and_extract_to_temp_folder()
|
||||
{
|
||||
UseRealHttp();
|
||||
|
||||
var updateSubFolder = new DirectoryInfo(Mocker.GetMock<EnvironmentProvider>().Object.GetUpdateSandboxFolder());
|
||||
var updateSubFolder = new DirectoryInfo(Mocker.GetMock<IEnvironmentProvider>().Object.GetUpdateSandboxFolder());
|
||||
|
||||
updateSubFolder.Exists.Should().BeFalse();
|
||||
|
||||
Mocker.Resolve<DiskProvider>();
|
||||
Mocker.Resolve<IDiskProvider>();
|
||||
Mocker.Resolve<ArchiveProvider>();
|
||||
|
||||
Subject.InstallAvailableUpdate();
|
||||
|
@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Marr.Data;
|
||||
using Marr.Data.QGen;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
@ -190,5 +188,6 @@ public void SetFields(TModel model, params Expression<Func<TModel, object>>[] pr
|
||||
.Entity(model)
|
||||
.Execute();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using FluentMigrator.Runner;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Composition;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||
{
|
||||
[Singleton]
|
||||
public class MigrationLogger : IAnnouncer
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
@ -92,7 +92,7 @@ protected override void MainDbUpgrade()
|
||||
.WithColumn("Name").AsString().Unique();
|
||||
|
||||
Create.TableForModel("ScheduledTasks")
|
||||
.WithColumn("Name").AsString().Unique()
|
||||
.WithColumn("TypeName").AsString().Unique()
|
||||
.WithColumn("Interval").AsInt32()
|
||||
.WithColumn("LastExecution").AsDateTime();
|
||||
|
||||
|
@ -15,12 +15,12 @@ public class BlackholeProvider : IDownloadClient
|
||||
{
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
|
||||
public BlackholeProvider(IConfigService configService, IHttpProvider httpProvider,
|
||||
DiskProvider diskProvider, Logger logger)
|
||||
IDiskProvider diskProvider, Logger logger)
|
||||
{
|
||||
_configService = configService;
|
||||
_httpProvider = httpProvider;
|
||||
|
@ -19,12 +19,12 @@ public class PneumaticClient : IDownloadClient
|
||||
{
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public PneumaticClient(IConfigService configService, IHttpProvider httpProvider,
|
||||
DiskProvider diskProvider)
|
||||
IDiskProvider diskProvider)
|
||||
{
|
||||
_configService = configService;
|
||||
_httpProvider = httpProvider;
|
||||
|
@ -10,6 +10,7 @@ public interface IScheduledTaskRepository : IBasicRepository<ScheduledTask>
|
||||
{
|
||||
IList<ScheduledTask> GetPendingJobs();
|
||||
ScheduledTask GetDefinition(Type type);
|
||||
void SetLastExecutionTime(int id, DateTime executionTime);
|
||||
}
|
||||
|
||||
|
||||
@ -23,7 +24,7 @@ public ScheduledTaskRepository(IDatabase database, IMessageAggregator messageAgg
|
||||
|
||||
public ScheduledTask GetDefinition(Type type)
|
||||
{
|
||||
return Query.Single(c => c.Name == type.FullName);
|
||||
return Query.Single(c => c.TypeName == type.FullName);
|
||||
}
|
||||
|
||||
|
||||
@ -31,5 +32,16 @@ public IList<ScheduledTask> GetPendingJobs()
|
||||
{
|
||||
return Query.Where(c => c.Interval != 0).ToList().Where(c => c.LastExecution < DateTime.Now.AddMinutes(-c.Interval)).ToList();
|
||||
}
|
||||
|
||||
public void SetLastExecutionTime(int id, DateTime executionTime)
|
||||
{
|
||||
var task = new ScheduledTask
|
||||
{
|
||||
Id = id,
|
||||
LastExecution = executionTime
|
||||
};
|
||||
|
||||
SetFields(task, scheduledTask => scheduledTask.LastExecution);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ namespace NzbDrone.Core.Jobs
|
||||
{
|
||||
public class ScheduledTask : ModelBase
|
||||
{
|
||||
public String Name { get; set; }
|
||||
public String TypeName { get; set; }
|
||||
public Int32 Interval { get; set; }
|
||||
public DateTime LastExecution { get; set; }
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Timers;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
@ -13,12 +14,14 @@ public class Scheduler :
|
||||
{
|
||||
private readonly ITaskManager _taskManager;
|
||||
private readonly IMessageAggregator _messageAggregator;
|
||||
private readonly Logger _logger;
|
||||
private static readonly Timer Timer = new Timer();
|
||||
|
||||
public Scheduler(ITaskManager taskManager, IMessageAggregator messageAggregator)
|
||||
public Scheduler(ITaskManager taskManager, IMessageAggregator messageAggregator, Logger logger)
|
||||
{
|
||||
_taskManager = taskManager;
|
||||
_messageAggregator = messageAggregator;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
@ -34,10 +37,23 @@ private void ExecuteCommands()
|
||||
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
var commandType = Type.GetType(task.Name);
|
||||
var command = (ICommand)Activator.CreateInstance(commandType);
|
||||
try
|
||||
{
|
||||
var commandType = Type.GetType(task.TypeName);
|
||||
var command = (ICommand)Activator.CreateInstance(commandType);
|
||||
|
||||
_messageAggregator.PublishCommand(command);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("Error occured while execution task " + task.TypeName, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_taskManager.SetLastExecutionTime(task.Id);
|
||||
}
|
||||
|
||||
|
||||
_messageAggregator.PublishCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
@ -11,6 +12,7 @@ namespace NzbDrone.Core.Jobs
|
||||
public interface ITaskManager
|
||||
{
|
||||
IList<ScheduledTask> GetPending();
|
||||
void SetLastExecutionTime(int taskId);
|
||||
}
|
||||
|
||||
public class TaskManager : IHandle<ApplicationStartedEvent>, ITaskManager
|
||||
@ -30,12 +32,17 @@ public IList<ScheduledTask> GetPending()
|
||||
return _scheduledTaskRepository.GetPendingJobs();
|
||||
}
|
||||
|
||||
public void SetLastExecutionTime(int taskId)
|
||||
{
|
||||
_scheduledTaskRepository.SetLastExecutionTime(taskId, DateTime.UtcNow);
|
||||
}
|
||||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
{
|
||||
var defaultTasks = new[]
|
||||
{
|
||||
new ScheduledTask{ Interval = 25, Name = typeof(RssSyncCommand).FullName},
|
||||
new ScheduledTask{ Interval = 24*60, Name = typeof(UpdateXemMappings).FullName}
|
||||
new ScheduledTask{ Interval = 25, TypeName = typeof(RssSyncCommand).FullName},
|
||||
new ScheduledTask{ Interval = 24*60, TypeName = typeof(UpdateXemMappings).FullName}
|
||||
};
|
||||
|
||||
var currentTasks = _scheduledTaskRepository.All();
|
||||
@ -46,16 +53,16 @@ public void Handle(ApplicationStartedEvent message)
|
||||
|
||||
foreach (var job in currentTasks)
|
||||
{
|
||||
if (!defaultTasks.Any(c => c.Name == job.Name))
|
||||
if (!defaultTasks.Any(c => c.TypeName == job.TypeName))
|
||||
{
|
||||
_logger.Debug("Removing job from database '{0}'", job.Name);
|
||||
_logger.Debug("Removing job from database '{0}'", job.TypeName);
|
||||
_scheduledTaskRepository.Delete(job.Id);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var defaultTask in defaultTasks)
|
||||
{
|
||||
var currentDefinition = currentTasks.SingleOrDefault(c => c.Name == defaultTask.Name);
|
||||
var currentDefinition = currentTasks.SingleOrDefault(c => c.TypeName == defaultTask.TypeName);
|
||||
|
||||
if (currentDefinition == null)
|
||||
{
|
||||
|
@ -13,12 +13,12 @@ public class MediaCoverService :
|
||||
IHandleAsync<SeriesDeletedEvent>
|
||||
{
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private readonly string _coverRootFolder;
|
||||
|
||||
public MediaCoverService(IHttpProvider httpProvider, DiskProvider diskProvider, EnvironmentProvider environmentProvider, Logger logger)
|
||||
public MediaCoverService(IHttpProvider httpProvider, IDiskProvider diskProvider, IEnvironmentProvider environmentProvider, Logger logger)
|
||||
{
|
||||
_httpProvider = httpProvider;
|
||||
_diskProvider = diskProvider;
|
||||
|
@ -22,10 +22,10 @@ public class MoveEpisodeFiles : IMoveEpisodeFiles
|
||||
private readonly IBuildFileNames _buildFileNames;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly IMessageAggregator _messageAggregator;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public MoveEpisodeFiles(ISeriesRepository seriesRepository, IEpisodeService episodeService, IBuildFileNames buildFileNames, IMediaFileService mediaFileService, IMessageAggregator messageAggregator, DiskProvider diskProvider, Logger logger)
|
||||
public MoveEpisodeFiles(ISeriesRepository seriesRepository, IEpisodeService episodeService, IBuildFileNames buildFileNames, IMediaFileService mediaFileService, IMessageAggregator messageAggregator, IDiskProvider diskProvider, Logger logger)
|
||||
{
|
||||
_seriesRepository = seriesRepository;
|
||||
_episodeService = episodeService;
|
||||
|
@ -13,10 +13,10 @@ public interface ICleanGhostFiles
|
||||
public class GhostFileCleanupService : ICleanGhostFiles
|
||||
{
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public GhostFileCleanupService(IMediaFileService mediaFileService, DiskProvider diskProvider, Logger logger)
|
||||
public GhostFileCleanupService(IMediaFileService mediaFileService, IDiskProvider diskProvider, Logger logger)
|
||||
{
|
||||
_mediaFileService = mediaFileService;
|
||||
_diskProvider = diskProvider;
|
||||
|
@ -11,12 +11,12 @@ namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
public class RecycleBinProvider : IHandleAsync<SeriesDeletedEvent>, IExecute<CleanUpRecycleBinCommand>
|
||||
{
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public RecycleBinProvider(DiskProvider diskProvider, IConfigService configService)
|
||||
public RecycleBinProvider(IDiskProvider diskProvider, IConfigService configService)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_configService = configService;
|
||||
|
@ -134,7 +134,6 @@ public static ParsedEpisodeInfo ParseTitle(string title)
|
||||
}
|
||||
|
||||
Logger.Trace("Unable to parse {0}", title);
|
||||
ReportingService.ReportParseError(title);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,10 @@ namespace NzbDrone.Core.Providers
|
||||
{
|
||||
public class BackupProvider
|
||||
{
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public BackupProvider(EnvironmentProvider environmentProvider)
|
||||
public BackupProvider(IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
}
|
||||
|
@ -15,14 +15,14 @@ public interface IDropFolderImportService
|
||||
|
||||
public class DropFolderImportService : IDropFolderImportService
|
||||
{
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IDiskScanService _diskScanService;
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IMoveEpisodeFiles _episodeFileMover;
|
||||
private readonly IParsingService _parsingService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public DropFolderImportService(DiskProvider diskProvider,
|
||||
public DropFolderImportService(IDiskProvider diskProvider,
|
||||
IDiskScanService diskScanService,
|
||||
ISeriesService seriesService,
|
||||
IMoveEpisodeFiles episodeFileMover,
|
||||
|
@ -21,13 +21,13 @@ public class DiskScanService : IDiskScanService
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private static readonly string[] MediaExtensions = new[] { ".mkv", ".avi", ".wmv", ".mp4", ".mpg", ".mpeg", ".xvid", ".flv", ".mov", ".rm", ".rmvb", ".divx", ".dvr-ms", ".ts", ".ogm", ".m4v", ".strm" };
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly ICleanGhostFiles _ghostFileCleaner;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly IVideoFileInfoReader _videoFileInfoReader;
|
||||
private readonly IParsingService _parsingService;
|
||||
|
||||
public DiskScanService(DiskProvider diskProvider, ICleanGhostFiles ghostFileCleaner, IMediaFileService mediaFileService, IVideoFileInfoReader videoFileInfoReader,
|
||||
public DiskScanService(IDiskProvider diskProvider, ICleanGhostFiles ghostFileCleaner, IMediaFileService mediaFileService, IVideoFileInfoReader videoFileInfoReader,
|
||||
IParsingService parsingService)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
|
@ -15,11 +15,11 @@ public interface IVideoFileInfoReader
|
||||
|
||||
public class VideoFileInfoReader : IVideoFileInfoReader
|
||||
{
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
|
||||
public VideoFileInfoReader(DiskProvider diskProvider, Logger logger)
|
||||
public VideoFileInfoReader(IDiskProvider diskProvider, Logger logger)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_logger = logger;
|
||||
|
@ -23,10 +23,10 @@ public class RootFolderService : IRootFolderService
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IBasicRepository<RootFolder> _rootFolderRepository;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
|
||||
public RootFolderService(IBasicRepository<RootFolder> rootFolderRepository, DiskProvider diskProvider,ISeriesRepository seriesRepository)
|
||||
public RootFolderService(IBasicRepository<RootFolder> rootFolderRepository, IDiskProvider diskProvider,ISeriesRepository seriesRepository)
|
||||
{
|
||||
_rootFolderRepository = rootFolderRepository;
|
||||
_diskProvider = diskProvider;
|
||||
|
@ -46,12 +46,12 @@ public class SeriesService : ISeriesService, IHandleAsync<SeriesAddedEvent>
|
||||
private readonly IMessageAggregator _messageAggregator;
|
||||
private readonly ISceneMappingService _sceneMappingService;
|
||||
private readonly IRootFolderService _rootFolderService;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService,
|
||||
IProvideSeriesInfo seriesInfoProxy, IMessageAggregator messageAggregator, ISceneMappingService sceneMappingService,
|
||||
IRootFolderService rootFolderService, DiskProvider diskProvider, Logger logger)
|
||||
IRootFolderService rootFolderService, IDiskProvider diskProvider, Logger logger)
|
||||
{
|
||||
_seriesRepository = seriesRepository;
|
||||
_configService = configServiceService;
|
||||
|
@ -20,18 +20,18 @@ public interface IUpdateService
|
||||
public class UpdateService : IUpdateService
|
||||
{
|
||||
private readonly IUpdatePackageProvider _updatePackageProvider;
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly ConfigFileProvider _configFileProvider;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly ArchiveProvider _archiveProvider;
|
||||
private readonly ProcessProvider _processProvider;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
|
||||
public UpdateService(IUpdatePackageProvider updatePackageProvider, EnvironmentProvider environmentProvider, DiskProvider diskProvider,
|
||||
IHttpProvider httpProvider, ConfigFileProvider configFileProvider, ArchiveProvider archiveProvider, ProcessProvider processProvider, Logger logger)
|
||||
public UpdateService(IUpdatePackageProvider updatePackageProvider, IEnvironmentProvider environmentProvider, IDiskProvider diskProvider,
|
||||
IHttpProvider httpProvider, IConfigFileProvider configFileProvider, ArchiveProvider archiveProvider, IProcessProvider processProvider, Logger logger)
|
||||
{
|
||||
_updatePackageProvider = updatePackageProvider;
|
||||
_environmentProvider = environmentProvider;
|
||||
|
@ -10,12 +10,12 @@
|
||||
using NzbDrone.Api.Commands;
|
||||
using NzbDrone.Api.RootFolders;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Integration.Test.Client;
|
||||
using NzbDrone.Owin;
|
||||
using NzbDrone.Owin.MiddleWare;
|
||||
using RestSharp;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Integration.Test
|
||||
{
|
||||
@ -28,7 +28,7 @@ public abstract class IntegrationTest
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetLogger("TEST");
|
||||
|
||||
protected TinyIoCContainer Container { get; private set; }
|
||||
protected IContainer Container { get; private set; }
|
||||
|
||||
|
||||
protected SeriesClient Series;
|
||||
@ -72,7 +72,7 @@ private void InitDatabase()
|
||||
Logger.Info("DB Na: {0}", dbPath);
|
||||
|
||||
|
||||
Container.Register((c, p) => c.Resolve<IDbFactory>().Create(dbPath));
|
||||
Container.Register(c => c.Resolve<IDbFactory>().Create(dbPath));
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
@ -82,10 +82,10 @@ public void SmokeTestSetup()
|
||||
|
||||
InitDatabase();
|
||||
|
||||
_bootstrapper = new NancyBootstrapper(Container);
|
||||
_bootstrapper = new NancyBootstrapper(Container.TinyContainer);
|
||||
|
||||
|
||||
var _hostConfig = new Mock<ConfigFileProvider>();
|
||||
var _hostConfig = new Mock<IConfigFileProvider>();
|
||||
_hostConfig.SetupGet(c => c.Port).Returns(1313);
|
||||
|
||||
_hostController = new OwinHostController(_hostConfig.Object, new[] { new NancyMiddleWare(_bootstrapper) }, Logger);
|
||||
|
@ -82,7 +82,6 @@ public void TestBaseSetup()
|
||||
TempFolder = Path.Combine(Directory.GetCurrentDirectory(), "_temp_" + DateTime.Now.Ticks);
|
||||
|
||||
MockedRestProvider = new Mock<RestProvider>();
|
||||
ReportingService.RestProvider = MockedRestProvider.Object;
|
||||
|
||||
Directory.CreateDirectory(TempFolder);
|
||||
}
|
||||
@ -137,7 +136,7 @@ protected void LinuxOnly()
|
||||
|
||||
protected void WithTempAsAppPath()
|
||||
{
|
||||
Mocker.GetMock<EnvironmentProvider>()
|
||||
Mocker.GetMock<IEnvironmentProvider>()
|
||||
.SetupGet(c => c.WorkingDirectory)
|
||||
.Returns(VirtualPath);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public void should_call_update_with_corret_path()
|
||||
{
|
||||
const string ProcessPath = @"C:\NzbDrone\nzbdrone.exe";
|
||||
|
||||
Mocker.GetMock<ProcessProvider>().Setup(c => c.GetProcessById(12))
|
||||
Mocker.GetMock<IProcessProvider>().Setup(c => c.GetProcessById(12))
|
||||
.Returns(new ProcessInfo() { StartPath = ProcessPath });
|
||||
|
||||
|
||||
|
@ -20,36 +20,36 @@ public class UpdateProviderStartFixture : TestBase
|
||||
private const string TARGET_FOLDER = @"C:\NzbDrone\";
|
||||
private const string UPDATE_LOG_FOLDER = @"C:\NzbDrone\UpdateLogs\";
|
||||
|
||||
Mock<EnvironmentProvider> _environmentProvider;
|
||||
Mock<IEnvironmentProvider> _environmentProvider;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
|
||||
_environmentProvider = Mocker.GetMock<EnvironmentProvider>();
|
||||
_environmentProvider = Mocker.GetMock<IEnvironmentProvider>();
|
||||
|
||||
_environmentProvider.SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\");
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FolderExists(UPDATE_FOLDER))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FolderExists(TARGET_FOLDER))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
private void WithInstalledService()
|
||||
{
|
||||
Mocker.GetMock<ServiceProvider>()
|
||||
Mocker.GetMock<IServiceProvider>()
|
||||
.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
private void WithServiceRunning(bool state)
|
||||
{
|
||||
Mocker.GetMock<ServiceProvider>()
|
||||
Mocker.GetMock<IServiceProvider>()
|
||||
.Setup(c => c.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(state);
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ public void should_stop_nzbdrone_service_if_installed_and_running()
|
||||
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
||||
|
||||
|
||||
Mocker.GetMock<ServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
||||
Mocker.GetMock<IServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -76,7 +76,7 @@ public void should_not_stop_nzbdrone_service_if_installed_but_not_running()
|
||||
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
||||
|
||||
|
||||
Mocker.GetMock<ServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Never());
|
||||
Mocker.GetMock<IServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -86,7 +86,7 @@ public void should_not_stop_nzbdrone_service_if_service_isnt_installed()
|
||||
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
||||
|
||||
|
||||
Mocker.GetMock<ServiceProvider>().Verify(c => c.Stop(It.IsAny<string>()), Times.Never());
|
||||
Mocker.GetMock<IServiceProvider>().Verify(c => c.Stop(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -94,7 +94,7 @@ public void should_kill_nzbdrone_process_if_running()
|
||||
{
|
||||
var proccesses = Builder<ProcessInfo>.CreateListOfSize(2).Build().ToList();
|
||||
|
||||
Mocker.GetMock<ProcessProvider>()
|
||||
Mocker.GetMock<IProcessProvider>()
|
||||
.Setup(c => c.GetProcessByName(ProcessProvider.NzbDroneProcessName))
|
||||
.Returns(proccesses);
|
||||
|
||||
@ -102,13 +102,13 @@ public void should_kill_nzbdrone_process_if_running()
|
||||
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
||||
|
||||
|
||||
Mocker.GetMock<ProcessProvider>().Verify(c => c.KillAll(ProcessProvider.NzbDroneProcessName), Times.Once());
|
||||
Mocker.GetMock<IProcessProvider>().Verify(c => c.KillAll(ProcessProvider.NzbDroneProcessName), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_kill_nzbdrone_process_not_running()
|
||||
{
|
||||
Mocker.GetMock<ProcessProvider>()
|
||||
Mocker.GetMock<IProcessProvider>()
|
||||
.Setup(c => c.GetProcessByName(ProcessProvider.NzbDroneProcessName))
|
||||
.Returns(new List<ProcessInfo>());
|
||||
|
||||
@ -116,13 +116,13 @@ public void should_not_kill_nzbdrone_process_not_running()
|
||||
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
||||
|
||||
|
||||
Mocker.GetMock<ProcessProvider>().Verify(c => c.Kill(It.IsAny<int>()), Times.Never());
|
||||
Mocker.GetMock<IProcessProvider>().Verify(c => c.Kill(It.IsAny<int>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_create_backup_of_current_installation()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.CopyDirectory(TARGET_FOLDER, BACKUP_FOLDER));
|
||||
|
||||
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
||||
@ -131,10 +131,10 @@ public void should_create_backup_of_current_installation()
|
||||
[Test]
|
||||
public void should_copy_update_package_to_target()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER));
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.DeleteFolder(UPDATE_FOLDER, true));
|
||||
|
||||
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
||||
@ -143,7 +143,7 @@ public void should_copy_update_package_to_target()
|
||||
[Test]
|
||||
public void should_restore_if_update_fails()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER))
|
||||
.Throws(new IOException());
|
||||
|
||||
@ -151,7 +151,7 @@ public void should_restore_if_update_fails()
|
||||
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(c => c.CopyDirectory(BACKUP_FOLDER, TARGET_FOLDER), Times.Once());
|
||||
ExceptionVerification.ExpectedFatals(1);
|
||||
}
|
||||
@ -188,7 +188,7 @@ public void should_restart_service_if_service_was_running_and_update_fails()
|
||||
WithInstalledService();
|
||||
WithServiceRunning(true);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER))
|
||||
.Throws(new IOException());
|
||||
|
||||
@ -206,7 +206,7 @@ public void should_restart_process_if_service_was_not_running_and_update_fails()
|
||||
WithInstalledService();
|
||||
WithServiceRunning(false);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER))
|
||||
.Throws(new IOException());
|
||||
|
||||
@ -220,19 +220,19 @@ public void should_restart_process_if_service_was_not_running_and_update_fails()
|
||||
|
||||
private void VerifyServiceRestart()
|
||||
{
|
||||
Mocker.GetMock<ServiceProvider>()
|
||||
Mocker.GetMock<IServiceProvider>()
|
||||
.Verify(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
||||
|
||||
Mocker.GetMock<ProcessProvider>()
|
||||
Mocker.GetMock<IProcessProvider>()
|
||||
.Verify(c => c.Start(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
private void VerifyProcessRestart()
|
||||
{
|
||||
Mocker.GetMock<ServiceProvider>()
|
||||
Mocker.GetMock<IServiceProvider>()
|
||||
.Verify(c => c.Start(It.IsAny<string>()), Times.Never());
|
||||
|
||||
Mocker.GetMock<ProcessProvider>()
|
||||
Mocker.GetMock<IProcessProvider>()
|
||||
.Verify(c => c.Start(TARGET_FOLDER + "NzbDrone.exe"), Times.Once());
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,10 @@ public class UpdateProviderVerifyFixture : TestBase
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.GetMock<EnvironmentProvider>()
|
||||
Mocker.GetMock<IEnvironmentProvider>()
|
||||
.Setup(c => c.StartUpPath).Returns(@"C:\Temp\NzbDrone_update\");
|
||||
|
||||
Mocker.GetMock<EnvironmentProvider>()
|
||||
Mocker.GetMock<IEnvironmentProvider>()
|
||||
.Setup(c => c.SystemTemp).Returns(@"C:\Temp\");
|
||||
}
|
||||
|
||||
@ -49,11 +49,11 @@ public void update_should_throw_if_update_folder_doesnt_exist()
|
||||
const string sandboxFolder = @"C:\Temp\NzbDrone_update\nzbdrone";
|
||||
const string targetFolder = "c:\\NzbDrone\\";
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FolderExists(targetFolder))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FolderExists(sandboxFolder))
|
||||
.Returns(false);
|
||||
|
||||
|
@ -2,20 +2,20 @@
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Update.Providers;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Update
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private readonly UpdateProvider _updateProvider;
|
||||
private readonly ProcessProvider _processProvider;
|
||||
private static TinyIoCContainer _container;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private static IContainer _container;
|
||||
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public Program(UpdateProvider updateProvider, ProcessProvider processProvider)
|
||||
public Program(UpdateProvider updateProvider, IProcessProvider processProvider)
|
||||
{
|
||||
_updateProvider = updateProvider;
|
||||
_processProvider = processProvider;
|
||||
@ -29,7 +29,7 @@ public static void Main(string[] args)
|
||||
|
||||
_container = UpdateContainerBuilder.Build();
|
||||
|
||||
logger.Info("Updating NzbDrone to version {0}", _container.Resolve<EnvironmentProvider>().Version);
|
||||
logger.Info("Updating NzbDrone to version {0}", _container.Resolve<IEnvironmentProvider>().Version);
|
||||
_container.Resolve<Program>().Start(args);
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -44,8 +44,8 @@ private static void TransferUpdateLogs()
|
||||
{
|
||||
try
|
||||
{
|
||||
var environmentProvider = _container.Resolve<EnvironmentProvider>();
|
||||
var diskProvider = _container.Resolve<DiskProvider>();
|
||||
var environmentProvider = _container.Resolve<IEnvironmentProvider>();
|
||||
var diskProvider = _container.Resolve<IDiskProvider>();
|
||||
logger.Info("Copying log files to application directory.");
|
||||
diskProvider.CopyDirectory(environmentProvider.GetSandboxLogFolder(), environmentProvider.GetUpdateLogFolder());
|
||||
}
|
||||
|
@ -2,19 +2,20 @@
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using IServiceProvider = NzbDrone.Common.IServiceProvider;
|
||||
|
||||
namespace NzbDrone.Update.Providers
|
||||
{
|
||||
public class UpdateProvider
|
||||
{
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly ServiceProvider _serviceProvider;
|
||||
private readonly ProcessProvider _processProvider;
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public UpdateProvider(DiskProvider diskProvider, ServiceProvider serviceProvider,
|
||||
ProcessProvider processProvider, EnvironmentProvider environmentProvider)
|
||||
public UpdateProvider(IDiskProvider diskProvider, IServiceProvider serviceProvider,
|
||||
IProcessProvider processProvider, IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_serviceProvider = serviceProvider;
|
||||
|
@ -1,5 +1,5 @@
|
||||
using NzbDrone.Common;
|
||||
using TinyIoC;
|
||||
using NzbDrone.Common.Composition;
|
||||
|
||||
namespace NzbDrone.Update
|
||||
{
|
||||
@ -11,7 +11,7 @@ public UpdateContainerBuilder()
|
||||
|
||||
}
|
||||
|
||||
public static TinyIoCContainer Build()
|
||||
public static IContainer Build()
|
||||
{
|
||||
return new UpdateContainerBuilder().Container;
|
||||
}
|
||||
|
@ -14,17 +14,17 @@ public interface INzbDroneServiceFactory
|
||||
|
||||
public class NzbDroneServiceFactory : ServiceBase, INzbDroneServiceFactory
|
||||
{
|
||||
private readonly ConfigFileProvider _configFileProvider;
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IHostController _hostController;
|
||||
private readonly ProcessProvider _processProvider;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly PriorityMonitor _priorityMonitor;
|
||||
private readonly SecurityProvider _securityProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public NzbDroneServiceFactory(ConfigFileProvider configFileProvider, IHostController hostController,
|
||||
EnvironmentProvider environmentProvider,
|
||||
ProcessProvider processProvider, PriorityMonitor priorityMonitor,
|
||||
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider, IHostController hostController,
|
||||
IEnvironmentProvider environmentProvider,
|
||||
IProcessProvider processProvider, PriorityMonitor priorityMonitor,
|
||||
SecurityProvider securityProvider, Logger logger)
|
||||
{
|
||||
_configFileProvider = configFileProvider;
|
||||
|
@ -1,17 +1,14 @@
|
||||
using System.IO;
|
||||
using FluentMigrator.Runner;
|
||||
using NLog;
|
||||
using Nancy.Bootstrapper;
|
||||
using NzbDrone.Api;
|
||||
using NzbDrone.Api.SignalR;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
using NzbDrone.Core.ExternalNotification;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone
|
||||
{
|
||||
@ -19,7 +16,7 @@ public class MainAppContainerBuilder : ContainerBuilderBase
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetLogger("ContainerBuilderBase");
|
||||
|
||||
public static TinyIoCContainer BuildContainer()
|
||||
public static IContainer BuildContainer()
|
||||
{
|
||||
return new MainAppContainerBuilder().Container;
|
||||
}
|
||||
@ -29,20 +26,17 @@ private MainAppContainerBuilder()
|
||||
: base("NzbDrone", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api")
|
||||
{
|
||||
AutoRegisterImplementations<ExternalNotificationBase>();
|
||||
|
||||
Container.Register<IMessageAggregator, MessageAggregator>().AsSingleton();
|
||||
Container.Register<INancyBootstrapper, NancyBootstrapper>().AsSingleton();
|
||||
Container.Register<IAnnouncer, MigrationLogger>().AsSingleton();
|
||||
Container.Register<Router>().AsSingleton();
|
||||
|
||||
Container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>)).AsMultiInstance();
|
||||
Container.Register(typeof(IBasicRepository<NamingConfig>), typeof(BasicRepository<NamingConfig>)).AsMultiInstance();
|
||||
|
||||
AutoRegisterImplementations<NzbDronePersistentConnection>();
|
||||
|
||||
Container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>));
|
||||
Container.Register(typeof(IBasicRepository<NamingConfig>), typeof(BasicRepository<NamingConfig>));
|
||||
|
||||
Container.Register<INancyBootstrapper, NancyBootstrapper>();
|
||||
|
||||
InitDatabase();
|
||||
|
||||
ReportingService.RestProvider = Container.Resolve<RestProvider>();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void InitDatabase()
|
||||
@ -58,7 +52,7 @@ private void InitDatabase()
|
||||
Directory.CreateDirectory(appDataPath);
|
||||
}
|
||||
|
||||
Container.Register((c, p) => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase()));
|
||||
Container.Register(c => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase()));
|
||||
}
|
||||
}
|
||||
}
|
@ -21,11 +21,11 @@
|
||||
</target>
|
||||
<target xsi:type="File" name="rollingFileLogger" fileName="nzbdrone.log.txt" autoFlush="true" keepFileOpen="false"
|
||||
concurrentWrites="false" concurrentWriteAttemptDelay="50" concurrentWriteAttempts ="10"
|
||||
archiveAboveSize="512000" maxArchiveFiles="1" enableFileDelete="true" archiveNumbering ="Rolling"
|
||||
archiveAboveSize="1024000" maxArchiveFiles="5" enableFileDelete="true" archiveNumbering ="Rolling"
|
||||
layout="${date:format=yy-M-d HH\:mm\:ss.f}|${logger}}|${level}|${message}|${exception:format=ToString}"/>
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Trace" writeTo="consoleLogger"/>
|
||||
<logger name="*" minlevel="Debug" writeTo="consoleLogger"/>
|
||||
<logger name="*" minlevel="Off" writeTo="udpTarget"/>
|
||||
<logger name="*" minlevel="Warn" writeTo="rollingFileLogger"/>
|
||||
</rules>
|
||||
|
@ -153,7 +153,6 @@
|
||||
<Compile Include="SysTray\SysTrayApp.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysTray\SysTrayProvider.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
|
@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.SignalR;
|
||||
using NzbDrone.Api.SignalR;
|
||||
using NzbDrone.Common.Composition;
|
||||
using Owin;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Owin.MiddleWare
|
||||
{
|
||||
@ -12,7 +12,7 @@ public class SignalRMiddleWare : IOwinMiddleWare
|
||||
|
||||
public int Order { get { return 0; } }
|
||||
|
||||
public SignalRMiddleWare(IEnumerable<NzbDronePersistentConnection> persistentConnections, TinyIoCContainer container)
|
||||
public SignalRMiddleWare(IEnumerable<NzbDronePersistentConnection> persistentConnections, IContainer container)
|
||||
{
|
||||
_persistentConnections = persistentConnections;
|
||||
|
||||
|
@ -14,12 +14,12 @@ namespace NzbDrone.Owin
|
||||
{
|
||||
public class OwinHostController : IHostController
|
||||
{
|
||||
private readonly ConfigFileProvider _configFileProvider;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IEnumerable<IOwinMiddleWare> _owinMiddleWares;
|
||||
private readonly Logger _logger;
|
||||
private IDisposable _host;
|
||||
|
||||
public OwinHostController(ConfigFileProvider configFileProvider, IEnumerable<IOwinMiddleWare> owinMiddleWares, Logger logger)
|
||||
public OwinHostController(IConfigFileProvider configFileProvider, IEnumerable<IOwinMiddleWare> owinMiddleWares, Logger logger)
|
||||
{
|
||||
_configFileProvider = configFileProvider;
|
||||
_owinMiddleWares = owinMiddleWares;
|
||||
|
@ -9,12 +9,12 @@ namespace NzbDrone
|
||||
{
|
||||
public class PriorityMonitor
|
||||
{
|
||||
private readonly ProcessProvider _processProvider;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private Timer _processPriorityCheckTimer;
|
||||
|
||||
public PriorityMonitor(ProcessProvider processProvider, Logger logger)
|
||||
public PriorityMonitor(IProcessProvider processProvider, Logger logger)
|
||||
{
|
||||
_processProvider = processProvider;
|
||||
_logger = logger;
|
||||
|
@ -3,27 +3,30 @@
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.SysTray;
|
||||
using IServiceProvider = NzbDrone.Common.IServiceProvider;
|
||||
|
||||
namespace NzbDrone
|
||||
{
|
||||
[Singleton]
|
||||
public class Router
|
||||
{
|
||||
private readonly INzbDroneServiceFactory _nzbDroneServiceFactory;
|
||||
private readonly ServiceProvider _serviceProvider;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IConsoleService _consoleService;
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly SysTrayProvider _sysTrayProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly ISystemTrayApp _systemTrayProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public Router(INzbDroneServiceFactory nzbDroneServiceFactory, ServiceProvider serviceProvider,
|
||||
IConsoleService consoleService, EnvironmentProvider environmentProvider, SysTrayProvider sysTrayProvider, Logger logger)
|
||||
public Router(INzbDroneServiceFactory nzbDroneServiceFactory, IServiceProvider serviceProvider,
|
||||
IConsoleService consoleService, IEnvironmentProvider environmentProvider, ISystemTrayApp systemTrayProvider, Logger logger)
|
||||
{
|
||||
_nzbDroneServiceFactory = nzbDroneServiceFactory;
|
||||
_serviceProvider = serviceProvider;
|
||||
_consoleService = consoleService;
|
||||
_environmentProvider = environmentProvider;
|
||||
_sysTrayProvider = sysTrayProvider;
|
||||
_systemTrayProvider = systemTrayProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -60,7 +63,7 @@ public void Route(ApplicationModes applicationModes)
|
||||
}
|
||||
else
|
||||
{
|
||||
_sysTrayProvider.Start();
|
||||
_systemTrayProvider.Start();
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -7,27 +7,29 @@
|
||||
|
||||
namespace NzbDrone.SysTray
|
||||
{
|
||||
public class SysTrayApp : Form
|
||||
public interface ISystemTrayApp
|
||||
{
|
||||
private readonly ProcessProvider _processProvider;
|
||||
void Start();
|
||||
}
|
||||
|
||||
public class SystemTrayApp : Form, ISystemTrayApp
|
||||
{
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly IHostController _hostController;
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
|
||||
private readonly NotifyIcon _trayIcon = new NotifyIcon();
|
||||
private readonly ContextMenu _trayMenu = new ContextMenu();
|
||||
|
||||
public SysTrayApp(ProcessProvider processProvider, IHostController hostController, EnvironmentProvider environmentProvider)
|
||||
public SystemTrayApp(IProcessProvider processProvider, IHostController hostController, IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
_processProvider = processProvider;
|
||||
_hostController = hostController;
|
||||
_environmentProvider = environmentProvider;
|
||||
}
|
||||
|
||||
public SysTrayApp()
|
||||
{
|
||||
}
|
||||
|
||||
public void Create()
|
||||
public void Start()
|
||||
{
|
||||
_trayMenu.MenuItems.Add("Launch Browser", LaunchBrowser);
|
||||
_trayMenu.MenuItems.Add("-");
|
||||
@ -38,6 +40,9 @@ public void Create()
|
||||
|
||||
_trayIcon.ContextMenu = _trayMenu;
|
||||
_trayIcon.Visible = true;
|
||||
|
||||
|
||||
Application.Run(this);
|
||||
}
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
|
@ -1,25 +0,0 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace NzbDrone.SysTray
|
||||
{
|
||||
public class SysTrayProvider
|
||||
{
|
||||
private readonly SysTrayApp _sysTrayApp;
|
||||
|
||||
public SysTrayProvider(SysTrayApp sysTrayApp)
|
||||
{
|
||||
_sysTrayApp = sysTrayApp;
|
||||
}
|
||||
|
||||
public SysTrayProvider()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
_sysTrayApp.Create();
|
||||
|
||||
Application.Run(_sysTrayApp);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user