back to tiny for now

This commit is contained in:
Keivan Beigi 2013-05-10 16:53:50 -07:00 committed by kay.one
parent 2912561d0e
commit 4deecde092
84 changed files with 617 additions and 558 deletions

View File

@ -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;

View File

@ -6,11 +6,11 @@ using NzbDrone.Api.Extensions;
namespace NzbDrone.Api.ErrorManagement
{
public class ErrorPipeline
public class NzbDroneErrorPipeline
{
private readonly Logger _logger;
public ErrorPipeline(Logger logger)
public NzbDroneErrorPipeline(Logger logger)
{
_logger = logger;
}

View File

@ -13,11 +13,11 @@ namespace NzbDrone.Api.Frontend
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;

View File

@ -5,14 +5,14 @@ using Nancy.Diagnostics;
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 @@ namespace NzbDrone.Api
{
_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()
{

View File

@ -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" />

View File

@ -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;

View File

@ -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);
}
}
}

View File

@ -15,10 +15,10 @@ namespace NzbDrone.App.Test
[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 @@ namespace NzbDrone.App.Test
[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);

View File

@ -44,11 +44,11 @@ namespace NzbDrone.App.Test
[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 @@ namespace NzbDrone.App.Test
[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 @@ namespace NzbDrone.App.Test
[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 @@ namespace NzbDrone.App.Test
[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 @@ namespace NzbDrone.App.Test
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 @@ namespace NzbDrone.App.Test
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);

View File

@ -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 @@ namespace NzbDrone.Common.Test
WithTempAsAppPath();
//Reset config file
var configFile = Mocker.Resolve<EnvironmentProvider>().GetConfigPath();
var configFile = Mocker.Resolve<IEnvironmentProvider>().GetConfigPath();
if (File.Exists(configFile))
File.Delete(configFile);
@ -32,7 +29,7 @@ namespace NzbDrone.Common.Test
const string value = "8989";
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
var result = Subject.GetValue(key, value);
result.Should().Be(value);
@ -45,7 +42,7 @@ namespace NzbDrone.Common.Test
const int value = 8989;
var result = Mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
var result = Subject.GetValueInt(key, value);
result.Should().Be(value);
@ -58,7 +55,7 @@ namespace NzbDrone.Common.Test
const bool value = true;
var result = Mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
var result = Subject.GetValueBoolean(key, value);
result.Should().BeTrue();
@ -68,7 +65,7 @@ namespace NzbDrone.Common.Test
public void GetLaunchBrowser_Success()
{
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
var result = Subject.LaunchBrowser;
result.Should().Be(true);
@ -80,7 +77,7 @@ namespace NzbDrone.Common.Test
const int value = 8989;
var result = Mocker.Resolve<ConfigFileProvider>().Port;
var result = Subject.Port;
result.Should().Be(value);
@ -93,10 +90,10 @@ namespace NzbDrone.Common.Test
const bool value = false;
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
Subject.SetValue(key, value);
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
var result = Subject.LaunchBrowser;
result.Should().Be(value);
}
@ -107,10 +104,10 @@ namespace NzbDrone.Common.Test
const int value = 12345;
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
Subject.SetValue(key, value);
var result = Mocker.Resolve<ConfigFileProvider>().Port;
var result = Subject.Port;
result.Should().Be(value);
}
@ -121,7 +118,7 @@ namespace NzbDrone.Common.Test
const string value = "World";
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
var result = Subject.GetValue(key, value);
result.Should().Be(value);
@ -132,7 +129,7 @@ namespace NzbDrone.Common.Test
{
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
var result = Subject.AuthenticationType;
result.Should().Be(AuthenticationType.Anonymous);
@ -142,10 +139,10 @@ namespace NzbDrone.Common.Test
public void GetAuthenticationType_Windows()
{
Mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
Subject.SetValue("AuthenticationType", 1);
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
var result = Subject.AuthenticationType;
result.Should().Be(AuthenticationType.Windows);
@ -155,8 +152,8 @@ namespace NzbDrone.Common.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;

View File

@ -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" />

View File

@ -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");
}
}
}

View 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);
}
}
}

View File

@ -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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
}
if (implementations.Count == 1)
{
if (implementations.Single().HasAttribute<SingletonAttribute>())
{
Container.Register(contractType, implementations.Single()).AsSingleton();
}
else
{
Container.Register(contractType, implementations.Single()).AsMultiInstance();
}
var impl = implementations.Single();
Container.RegisterMultiple(contractType, implementations).AsMultiInstance();
if (impl.HasAttribute<SingletonAttribute>())
{
Container.RegisterSingleton(contractType, impl);
}
else
{
Container.RegisterMultiple(contractType, implementations).AsMultiInstance();
Container.Register(contractType, impl);
}
}
else
{
Container.RegisterAll(contractType, implementations);
}
}

View 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);
}
}

View File

@ -19,11 +19,11 @@ namespace NzbDrone.Common
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);

View File

@ -6,13 +6,25 @@ using NzbDrone.Common.Model;
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 @@ namespace NzbDrone.Common
CreateDefaultConfigFile();
}
public ConfigFileProvider()
{
}
public virtual Guid Guid
{

View File

@ -7,7 +7,38 @@ using NLog;
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
{

View File

@ -5,11 +5,22 @@ using System.Reflection;
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
{

View File

@ -7,19 +7,32 @@ using NzbDrone.Common.Model;
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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
};
}
public virtual void KillAll(string processName)
public void KillAll(string processName)
{
var processToKill = GetProcessByName(processName);

View File

@ -8,7 +8,19 @@ using NLog;
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";

View File

@ -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;

View File

@ -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" />

View File

@ -49,62 +49,62 @@ namespace NzbDrone.Common
}
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);
}

View File

@ -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.");
}
}
}
}
}

View File

@ -15,10 +15,10 @@ namespace NzbDrone.Common
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;
}

View File

@ -20,13 +20,13 @@ namespace NzbDrone.Common
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;

View File

@ -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 @@ namespace NzbDrone.Common
public class ServiceFactory : IServiceFactory
{
private readonly TinyIoCContainer _container;
private readonly IContainer _container;
public ServiceFactory(TinyIoCContainer container)
public ServiceFactory(IContainer container)
{
_container = container;
}

View File

@ -122,18 +122,18 @@ namespace NzbDrone.Core.Test.Datastore
{
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);
}

View File

@ -28,7 +28,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
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()

View File

@ -31,7 +31,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
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()

View File

@ -104,7 +104,7 @@ namespace NzbDrone.Core.Test.MediaFileTests
.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);

View File

@ -27,7 +27,7 @@ namespace NzbDrone.Core.Test.MediaFileTests
[SetUp]
public void SetUp()
{
Mocker.GetMock<DiskProvider>()
Mocker.GetMock<IDiskProvider>()
.Setup(e => e.FileExists(It.Is<String>(c => c != DeletedPath)))
.Returns(true);
}

View File

@ -27,7 +27,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
@"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 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
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]

View File

@ -56,7 +56,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
{
_fileSize = size;
Mocker.GetMock<DiskProvider>()
Mocker.GetMock<IDiskProvider>()
.Setup(d => d.GetSize(It.IsAny<String>()))
.Returns(size);
}
@ -221,7 +221,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
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]

View File

@ -30,24 +30,24 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
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\\");

View File

@ -19,19 +19,19 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
{
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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());
}
}
}

View File

@ -43,7 +43,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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));
}
}
}

View File

@ -43,7 +43,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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());
}
}
}

View File

@ -31,10 +31,10 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
{
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
{
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 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
{
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));
}
}
}

View File

@ -25,11 +25,11 @@ namespace NzbDrone.Core.Test.RootFolderTests
.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 @@ namespace NzbDrone.Core.Test.RootFolderTests
.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 @@ namespace NzbDrone.Core.Test.RootFolderTests
.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 @@ namespace NzbDrone.Core.Test.RootFolderTests
.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());

View File

@ -21,7 +21,7 @@ namespace NzbDrone.Core.Test.RootFolderTests
[SetUp]
public void Setup()
{
Mocker.GetMock<DiskProvider>()
Mocker.GetMock<IDiskProvider>()
.Setup(m => m.FolderExists(It.IsAny<string>()))
.Returns(true);
@ -32,7 +32,7 @@ namespace NzbDrone.Core.Test.RootFolderTests
private void WithNoneExistingFolder()
{
Mocker.GetMock<DiskProvider>()
Mocker.GetMock<IDiskProvider>()
.Setup(m => m.FolderExists(It.IsAny<string>()))
.Returns(false);
}
@ -75,7 +75,7 @@ namespace NzbDrone.Core.Test.RootFolderTests
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]

View File

@ -17,9 +17,9 @@ namespace NzbDrone.Core.Test.UpdateTests
{
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 @@ namespace NzbDrone.Core.Test.UpdateTests
"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 @@ namespace NzbDrone.Core.Test.UpdateTests
[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);

View File

@ -30,13 +30,13 @@ namespace NzbDrone.Core.Test.UpdateTests
[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 @@ namespace NzbDrone.Core.Test.UpdateTests
[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 @@ namespace NzbDrone.Core.Test.UpdateTests
[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 @@ namespace NzbDrone.Core.Test.UpdateTests
{
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();

View File

@ -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 @@ namespace NzbDrone.Core.Datastore
.Entity(model)
.Execute();
}
}
}

View File

@ -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;

View File

@ -92,7 +92,7 @@ namespace NzbDrone.Core.Datastore.Migration
.WithColumn("Name").AsString().Unique();
Create.TableForModel("ScheduledTasks")
.WithColumn("Name").AsString().Unique()
.WithColumn("TypeName").AsString().Unique()
.WithColumn("Interval").AsInt32()
.WithColumn("LastExecution").AsDateTime();

View File

@ -15,12 +15,12 @@ namespace NzbDrone.Core.Download.Clients
{
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;

View File

@ -19,12 +19,12 @@ namespace NzbDrone.Core.Download.Clients
{
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;

View File

@ -10,6 +10,7 @@ namespace NzbDrone.Core.Jobs
{
IList<ScheduledTask> GetPendingJobs();
ScheduledTask GetDefinition(Type type);
void SetLastExecutionTime(int id, DateTime executionTime);
}
@ -23,7 +24,7 @@ namespace NzbDrone.Core.Jobs
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 @@ namespace NzbDrone.Core.Jobs
{
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);
}
}
}

View File

@ -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; }
}

View File

@ -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 @@ namespace NzbDrone.Core.Jobs
{
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,11 +37,24 @@ namespace NzbDrone.Core.Jobs
foreach (var task in tasks)
{
var commandType = Type.GetType(task.Name);
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);
}
}
}
public void Handle(ApplicationShutdownRequested message)

View File

@ -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 @@ namespace NzbDrone.Core.Jobs
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 @@ namespace NzbDrone.Core.Jobs
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)
{

View File

@ -13,12 +13,12 @@ namespace NzbDrone.Core.MediaCover
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;

View File

@ -22,10 +22,10 @@ namespace NzbDrone.Core.MediaFiles
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;

View File

@ -13,10 +13,10 @@ namespace NzbDrone.Core.MediaFiles
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;

View File

@ -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;

View File

@ -134,7 +134,6 @@ namespace NzbDrone.Core.Parser
}
Logger.Trace("Unable to parse {0}", title);
ReportingService.ReportParseError(title);
return null;
}

View File

@ -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;
}

View File

@ -15,14 +15,14 @@ namespace NzbDrone.Core.Providers
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,

View File

@ -21,13 +21,13 @@ namespace NzbDrone.Core.Providers
{
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;

View File

@ -15,11 +15,11 @@ namespace NzbDrone.Core.Providers
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;

View File

@ -23,10 +23,10 @@ namespace NzbDrone.Core.RootFolders
{
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;

View File

@ -46,12 +46,12 @@ namespace NzbDrone.Core.Tv
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;

View File

@ -20,18 +20,18 @@ namespace NzbDrone.Core.Update
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;

View File

@ -10,12 +10,12 @@ using NzbDrone.Api;
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 @@ namespace NzbDrone.Integration.Test
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 @@ namespace NzbDrone.Integration.Test
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 @@ namespace NzbDrone.Integration.Test
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);

View File

@ -82,7 +82,6 @@ namespace NzbDrone.Test.Common
TempFolder = Path.Combine(Directory.GetCurrentDirectory(), "_temp_" + DateTime.Now.Ticks);
MockedRestProvider = new Mock<RestProvider>();
ReportingService.RestProvider = MockedRestProvider.Object;
Directory.CreateDirectory(TempFolder);
}
@ -137,7 +136,7 @@ namespace NzbDrone.Test.Common
protected void WithTempAsAppPath()
{
Mocker.GetMock<EnvironmentProvider>()
Mocker.GetMock<IEnvironmentProvider>()
.SetupGet(c => c.WorkingDirectory)
.Returns(VirtualPath);
}

View File

@ -54,7 +54,7 @@ namespace NzbDrone.Update.Test
{
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 });

View File

@ -20,36 +20,36 @@ namespace NzbDrone.Update.Test
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 @@ namespace NzbDrone.Update.Test
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 @@ namespace NzbDrone.Update.Test
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 @@ namespace NzbDrone.Update.Test
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 @@ namespace NzbDrone.Update.Test
{
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 @@ namespace NzbDrone.Update.Test
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 @@ namespace NzbDrone.Update.Test
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 @@ namespace NzbDrone.Update.Test
[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 @@ namespace NzbDrone.Update.Test
[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 @@ namespace NzbDrone.Update.Test
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 @@ namespace NzbDrone.Update.Test
WithInstalledService();
WithServiceRunning(true);
Mocker.GetMock<DiskProvider>()
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER))
.Throws(new IOException());
@ -206,7 +206,7 @@ namespace NzbDrone.Update.Test
WithInstalledService();
WithServiceRunning(false);
Mocker.GetMock<DiskProvider>()
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER))
.Throws(new IOException());
@ -220,19 +220,19 @@ namespace NzbDrone.Update.Test
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());
}

View File

@ -18,10 +18,10 @@ namespace NzbDrone.Update.Test
[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 @@ namespace NzbDrone.Update.Test
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);

View File

@ -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 @@ namespace NzbDrone.Update
_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 @@ namespace NzbDrone.Update
{
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());
}

View File

@ -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;

View File

@ -1,5 +1,5 @@
using NzbDrone.Common;
using TinyIoC;
using NzbDrone.Common.Composition;
namespace NzbDrone.Update
{
@ -11,7 +11,7 @@ namespace NzbDrone.Update
}
public static TinyIoCContainer Build()
public static IContainer Build()
{
return new UpdateContainerBuilder().Container;
}

View File

@ -14,17 +14,17 @@ namespace NzbDrone
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;

View File

@ -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 @@ namespace NzbDrone
{
private static readonly Logger Logger = LogManager.GetLogger("ContainerBuilderBase");
public static TinyIoCContainer BuildContainer()
public static IContainer BuildContainer()
{
return new MainAppContainerBuilder().Container;
}
@ -29,20 +26,17 @@ namespace NzbDrone
: 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 @@ namespace NzbDrone
Directory.CreateDirectory(appDataPath);
}
Container.Register((c, p) => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase()));
Container.Register(c => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase()));
}
}
}

View File

@ -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>

View File

@ -153,7 +153,6 @@
<Compile Include="SysTray\SysTrayApp.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="SysTray\SysTrayProvider.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />

View File

@ -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 @@ namespace NzbDrone.Owin.MiddleWare
public int Order { get { return 0; } }
public SignalRMiddleWare(IEnumerable<NzbDronePersistentConnection> persistentConnections, TinyIoCContainer container)
public SignalRMiddleWare(IEnumerable<NzbDronePersistentConnection> persistentConnections, IContainer container)
{
_persistentConnections = persistentConnections;

View File

@ -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;

View File

@ -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;

View File

@ -3,27 +3,30 @@ using System.Collections.Generic;
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 @@ namespace NzbDrone
}
else
{
_sysTrayProvider.Start();
_systemTrayProvider.Start();
}
break;

View File

@ -7,27 +7,29 @@ using NzbDrone.Owin;
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 @@ namespace NzbDrone.SysTray
_trayIcon.ContextMenu = _trayMenu;
_trayIcon.Visible = true;
Application.Run(this);
}
protected override void OnClosed(EventArgs e)

View File

@ -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);
}
}
}