diff --git a/NzbDrone.Api/Directories/DirectoryModule.cs b/NzbDrone.Api/Directories/DirectoryModule.cs index 8f93a1524..d78d48f27 100644 --- a/NzbDrone.Api/Directories/DirectoryModule.cs +++ b/NzbDrone.Api/Directories/DirectoryModule.cs @@ -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; diff --git a/NzbDrone.Api/ErrorManagement/ErrorPipeline.cs b/NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs similarity index 92% rename from NzbDrone.Api/ErrorManagement/ErrorPipeline.cs rename to NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs index c7df4b20b..871bc0e2b 100644 --- a/NzbDrone.Api/ErrorManagement/ErrorPipeline.cs +++ b/NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs @@ -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; } diff --git a/NzbDrone.Api/Frontend/StaticResourceProvider.cs b/NzbDrone.Api/Frontend/StaticResourceProvider.cs index f7c3c1aba..95bdc5d72 100644 --- a/NzbDrone.Api/Frontend/StaticResourceProvider.cs +++ b/NzbDrone.Api/Frontend/StaticResourceProvider.cs @@ -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; diff --git a/NzbDrone.Api/NancyBootstrapper.cs b/NzbDrone.Api/NancyBootstrapper.cs index f334b7c1f..0707f4bb2 100644 --- a/NzbDrone.Api/NancyBootstrapper.cs +++ b/NzbDrone.Api/NancyBootstrapper.cs @@ -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().PublishEvent(new ApplicationStartedEvent()); - ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve().HandleException); + ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve().HandleException); } - private void RegisterReporting(TinyIoCContainer container) - { - EnvironmentProvider.UGuid = container.Resolve().UGuid; - ReportingService.RestProvider = container.Resolve(); - } protected override TinyIoCContainer GetApplicationContainer() { diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index 1787b9316..8ff94211a 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -131,7 +131,7 @@ - + diff --git a/NzbDrone.Api/SignalR/Serializer.cs b/NzbDrone.Api/SignalR/Serializer.cs index 2196a92de..dc45e6f3f 100644 --- a/NzbDrone.Api/SignalR/Serializer.cs +++ b/NzbDrone.Api/SignalR/Serializer.cs @@ -1,9 +1,11 @@ using System; using System.IO; using Microsoft.AspNet.SignalR.Json; +using NzbDrone.Common.Composition; namespace NzbDrone.Api.SignalR { + [Singleton] public class Serializer : IJsonSerializer { private readonly Common.IJsonSerializer _nzbDroneSerializer; @@ -35,7 +37,7 @@ namespace NzbDrone.Api.SignalR { return _nzbDroneSerializer.Deserialize(json, targetType); } - + return _signalRSerializer.Parse(json, targetType); } } diff --git a/NzbDrone.Api/SignalR/SignalrDependencyResolver.cs b/NzbDrone.Api/SignalR/SignalrDependencyResolver.cs index bbdc5fa14..51eeb249f 100644 --- a/NzbDrone.Api/SignalR/SignalrDependencyResolver.cs +++ b/NzbDrone.Api/SignalR/SignalrDependencyResolver.cs @@ -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().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 GetServices(Type serviceType) - { - var objects = _container.CanResolve(serviceType) ? _container.ResolveAll(serviceType) : new object[] { }; - return objects.Concat(base.GetServices(serviceType)); + return base.GetService(serviceType); } } } diff --git a/NzbDrone.App.Test/MonitoringProviderTest.cs b/NzbDrone.App.Test/MonitoringProviderTest.cs index 9ecf56be6..dcae8fc87 100644 --- a/NzbDrone.App.Test/MonitoringProviderTest.cs +++ b/NzbDrone.App.Test/MonitoringProviderTest.cs @@ -15,10 +15,10 @@ namespace NzbDrone.App.Test [Test] public void Ensure_priority_doesnt_fail_on_invalid_iis_proccess_id() { - Mocker.GetMock().Setup(c => c.GetCurrentProcess()) + Mocker.GetMock().Setup(c => c.GetCurrentProcess()) .Returns(Builder.CreateNew().With(c => c.Priority == ProcessPriorityClass.Normal).Build()); - Mocker.GetMock().Setup(c => c.GetProcessById(It.IsAny())).Returns((ProcessInfo)null); + Mocker.GetMock().Setup(c => c.GetProcessById(It.IsAny())).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().Setup(c => c.GetCurrentProcess()).Throws(); + Mocker.GetMock().Setup(c => c.GetCurrentProcess()).Throws(); Subject.EnsurePriority(null); ExceptionVerification.ExpectedWarns(1); diff --git a/NzbDrone.App.Test/RouterTest.cs b/NzbDrone.App.Test/RouterTest.cs index e0727af2f..c394b5d07 100644 --- a/NzbDrone.App.Test/RouterTest.cs +++ b/NzbDrone.App.Test/RouterTest.cs @@ -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(MockBehavior.Strict); + var serviceProviderMock = Mocker.GetMock(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().SetupGet(c => c.IsUserInteractive).Returns(true); + Mocker.GetMock().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(); + var serviceProviderMock = Mocker.GetMock(); serviceProviderMock.Setup(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME)); - Mocker.GetMock().SetupGet(c => c.IsUserInteractive).Returns(true); + Mocker.GetMock().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().SetupGet(c => c.IsUserInteractive).Returns(true); + Mocker.GetMock().SetupGet(c => c.IsUserInteractive).Returns(true); Mocker.GetMock().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(); - var serviceProvider = Mocker.GetMock(); + var envMock = Mocker.GetMock(); + var serviceProvider = Mocker.GetMock(); 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(); - var serviceMock = Mocker.GetMock(); - Mocker.GetMock().SetupGet(c => c.IsUserInteractive).Returns(true); + var serviceMock = Mocker.GetMock(); + Mocker.GetMock().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(); - var serviceMock = Mocker.GetMock(); - Mocker.GetMock().SetupGet(c => c.IsUserInteractive).Returns(true); + var serviceMock = Mocker.GetMock(); + Mocker.GetMock().SetupGet(c => c.IsUserInteractive).Returns(true); consoleMock.Setup(c => c.PrintServiceDoestExist()); serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false); diff --git a/NzbDrone.Common.Test/ConfigFileProviderTest.cs b/NzbDrone.Common.Test/ConfigFileProviderTest.cs index f2b87233d..066d8653b 100644 --- a/NzbDrone.Common.Test/ConfigFileProviderTest.cs +++ b/NzbDrone.Common.Test/ConfigFileProviderTest.cs @@ -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 { [SetUp] public void SetUp() @@ -19,7 +16,7 @@ namespace NzbDrone.Common.Test WithTempAsAppPath(); //Reset config file - var configFile = Mocker.Resolve().GetConfigPath(); + var configFile = Mocker.Resolve().GetConfigPath(); if (File.Exists(configFile)) File.Delete(configFile); @@ -31,10 +28,10 @@ namespace NzbDrone.Common.Test const string key = "Port"; const string value = "8989"; - - var result = Mocker.Resolve().GetValue(key, value); - + var result = Subject.GetValue(key, value); + + result.Should().Be(value); } @@ -44,10 +41,10 @@ namespace NzbDrone.Common.Test const string key = "Port"; const int value = 8989; - - var result = Mocker.Resolve().GetValueInt(key, value); - + var result = Subject.GetValueInt(key, value); + + result.Should().Be(value); } @@ -57,20 +54,20 @@ namespace NzbDrone.Common.Test const string key = "LaunchBrowser"; const bool value = true; - - var result = Mocker.Resolve().GetValueBoolean(key, value); - + var result = Subject.GetValueBoolean(key, value); + + result.Should().BeTrue(); } [Test] public void GetLaunchBrowser_Success() { - - var result = Mocker.Resolve().LaunchBrowser; - + var result = Subject.LaunchBrowser; + + result.Should().Be(true); } @@ -79,10 +76,10 @@ namespace NzbDrone.Common.Test { const int value = 8989; - - var result = Mocker.Resolve().Port; - + var result = Subject.Port; + + result.Should().Be(value); } @@ -92,11 +89,11 @@ namespace NzbDrone.Common.Test const string key = "LaunchBrowser"; const bool value = false; - - Mocker.Resolve().SetValue(key, value); - - var result = Mocker.Resolve().LaunchBrowser; + Subject.SetValue(key, value); + + + var result = Subject.LaunchBrowser; result.Should().Be(value); } @@ -106,11 +103,11 @@ namespace NzbDrone.Common.Test const string key = "Port"; const int value = 12345; - - Mocker.Resolve().SetValue(key, value); - - var result = Mocker.Resolve().Port; + Subject.SetValue(key, value); + + + var result = Subject.Port; result.Should().Be(value); } @@ -120,10 +117,10 @@ namespace NzbDrone.Common.Test const string key = "Hello"; const string value = "World"; - - var result = Mocker.Resolve().GetValue(key, value); - + var result = Subject.GetValue(key, value); + + result.Should().Be(value); } @@ -131,10 +128,10 @@ namespace NzbDrone.Common.Test public void GetAuthenticationType_No_Existing_Value() { - - var result = Mocker.Resolve().AuthenticationType; - + var result = Subject.AuthenticationType; + + result.Should().Be(AuthenticationType.Anonymous); } @@ -142,24 +139,24 @@ namespace NzbDrone.Common.Test public void GetAuthenticationType_Windows() { - Mocker.Resolve().SetValue("AuthenticationType", 1); + Subject.SetValue("AuthenticationType", 1); + + + var result = Subject.AuthenticationType; - - var result = Mocker.Resolve().AuthenticationType; - result.Should().Be(AuthenticationType.Windows); } [Test] public void Guid_should_return_the_same_every_time() { - - var firstResponse = Mocker.Resolve().Guid; - var secondResponse = Mocker.Resolve().Guid; + + var firstResponse = Subject.Guid; + var secondResponse = Subject.Guid; + - secondResponse.Should().Be(firstResponse); } } diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index aaaacf101..7c23c4306 100644 --- a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -84,7 +84,6 @@ - diff --git a/NzbDrone.Common.Test/ReportingService_ReportParseError_Fixture.cs b/NzbDrone.Common.Test/ReportingService_ReportParseError_Fixture.cs deleted file mode 100644 index a182e3a9f..000000000 --- a/NzbDrone.Common.Test/ReportingService_ReportParseError_Fixture.cs +++ /dev/null @@ -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(c => c.ToLower().StartsWith("http://services.nzbdrone.com/")), It.Is(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(), It.IsAny()), 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(), It.IsAny()), 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(), It.IsAny()), Times.Exactly(2)); - MockedRestProvider.Verify(p => p.PostData(It.IsAny(), It.Is(c => c.Title == "title 1")), Times.Once()); - MockedRestProvider.Verify(p => p.PostData(It.IsAny(), It.Is(c => c.Title == "title 2")), Times.Once()); - } - - - [Test] - public void report_parse_error() - { - ReportingService.RestProvider = new RestProvider(new EnvironmentProvider()); - ReportingService.ReportParseError("Test error"); - - } - - } -} \ No newline at end of file diff --git a/NzbDrone.Common/Composition/Container.cs b/NzbDrone.Common/Composition/Container.cs new file mode 100644 index 000000000..cb460298f --- /dev/null +++ b/NzbDrone.Common/Composition/Container.cs @@ -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(this); + //container.RegisterWithContext(dependencyContext => LogManager.GetLogger(dependencyContext.ImplementationType.Name)); + } + + public void Register() + where TImplementation : class, TService + where TService : class + { + _container.Register(); + } + + public TinyIoCContainer TinyContainer { get { return _container; } } + + public void Register(T instance) where T : class + { + _container.Register(instance); + } + + public T Resolve() where T : class + { + return _container.Resolve(); + } + + public object Resolve(Type type) + { + return _container.Resolve(type); + } + + public void Register(Type serviceType, Type implementationType) + { + _container.Register(serviceType, implementationType); + } + + public void Register(Func factory) where TService : class + { + _container.Register((c, n) => factory(this)); + } + + public void RegisterSingleton() + where TImplementation : class, TService + where TService : class + { + _container.Register().AsSingleton(); + } + + public void RegisterSingleton() where T : class + { + _container.Register().AsSingleton(); + } + + public void RegisterSingleton(Type service, Type implementation) + { + _container.Register(service, implementation).AsSingleton(); + } + + public IEnumerable ResolveAll() where T : class + { + return _container.ResolveAll(); + } + + public IEnumerable ResolveAll(Type type) + { + return _container.ResolveAll(type); + } + + public void Register(Type registrationType, object instance) + { + _container.Register(registrationType, instance); + } + + public void RegisterAll(Type registrationType, IEnumerable implementationList) + { + _container.RegisterMultiple(registrationType, implementationList); + } + + public bool IsTypeRegistered(Type type) + { + return _container.CanResolve(type); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Common/ContainerBuilderBase.cs b/NzbDrone.Common/Composition/ContainerBuilderBase.cs similarity index 61% rename from NzbDrone.Common/ContainerBuilderBase.cs rename to NzbDrone.Common/Composition/ContainerBuilderBase.cs index a648c6a36..6635e423a 100644 --- a/NzbDrone.Common/ContainerBuilderBase.cs +++ b/NzbDrone.Common/Composition/ContainerBuilderBase.cs @@ -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 _loadedTypes; + public IContainer Container { get; private set; } + protected ContainerBuilderBase(params string[] assemblies) { - Container = new TinyIoCContainer(); + Container = new Container(new TinyIoCContainer()); _loadedTypes = new List(); @@ -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 { typeof(IMessage), typeof(ICommand), typeof(IEvent) }); + var contracts = loadedInterfaces.Union(implementedInterfaces).Where(c => !c.IsGenericTypeDefinition && !string.IsNullOrWhiteSpace(c.FullName)) + .Except(new List { 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()) + var impl = implementations.Single(); + + if (impl.HasAttribute()) { - Container.Register(contractType, implementations.Single()).AsSingleton(); + Container.RegisterSingleton(contractType, impl); } else { - Container.Register(contractType, implementations.Single()).AsMultiInstance(); + Container.Register(contractType, impl); } - - Container.RegisterMultiple(contractType, implementations).AsMultiInstance(); } else { - Container.RegisterMultiple(contractType, implementations).AsMultiInstance(); + Container.RegisterAll(contractType, implementations); } } diff --git a/NzbDrone.Common/Composition/IContainer.cs b/NzbDrone.Common/Composition/IContainer.cs new file mode 100644 index 000000000..7fc5dea09 --- /dev/null +++ b/NzbDrone.Common/Composition/IContainer.cs @@ -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 instance) where T : class; + + void Register() + where TImplementation : class, TService + where TService : class; + T Resolve() where T : class; + object Resolve(Type type); + void Register(Type serviceType, Type implementationType); + void Register(Func factory) where TService : class; + void RegisterSingleton() + where TImplementation : class, TService + where TService : class; + void RegisterSingleton() where T : class; + void RegisterSingleton(Type service, Type implementation); + IEnumerable ResolveAll() where T : class; + IEnumerable ResolveAll(Type type); + void Register(Type registrationType, object instance); + void RegisterAll(Type registrationType, IEnumerable implementationList); + bool IsTypeRegistered(Type type); + } +} \ No newline at end of file diff --git a/NzbDrone.Common/Composition/Class1.cs b/NzbDrone.Common/Composition/SingletonAttribute.cs similarity index 100% rename from NzbDrone.Common/Composition/Class1.cs rename to NzbDrone.Common/Composition/SingletonAttribute.cs diff --git a/NzbDrone.Common/HttpProvider.cs b/NzbDrone.Common/HttpProvider.cs index 86efab450..65e7f4999 100644 --- a/NzbDrone.Common/HttpProvider.cs +++ b/NzbDrone.Common/HttpProvider.cs @@ -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); diff --git a/NzbDrone.Common/ConfigFileProvider.cs b/NzbDrone.Common/IConfigFileProvider.cs similarity index 82% rename from NzbDrone.Common/ConfigFileProvider.cs rename to NzbDrone.Common/IConfigFileProvider.cs index 5be0a3b54..2d5bf6d7a 100644 --- a/NzbDrone.Common/ConfigFileProvider.cs +++ b/NzbDrone.Common/IConfigFileProvider.cs @@ -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 { diff --git a/NzbDrone.Common/DiskProvider.cs b/NzbDrone.Common/IDiskProvider.cs similarity index 86% rename from NzbDrone.Common/DiskProvider.cs rename to NzbDrone.Common/IDiskProvider.cs index 13ed77c3b..d844236ab 100644 --- a/NzbDrone.Common/DiskProvider.cs +++ b/NzbDrone.Common/IDiskProvider.cs @@ -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 GetFileInfos(string path, string pattern, SearchOption searchOption); + void InheritFolderPermissions(string filename); + long GetAvilableSpace(string path); + string ReadAllText(string filePath); + void WriteAllText(string filename, string contents); + void FileSetLastWriteTimeUtc(string path, DateTime dateTime); + void DirectorySetLastWriteTimeUtc(string path, DateTime dateTime); + bool IsFolderLocked(string path); + bool IsFileLocked(FileInfo file); + bool IsChildOfPath(string child, string parent); + string GetPathRoot(string path); + } + + public class DiskProvider : IDiskProvider { enum TransferAction { @@ -214,7 +245,7 @@ namespace NzbDrone.Common { return 0; } - + return DriveFreeSpaceEx(path); } diff --git a/NzbDrone.Common/EnvironmentProvider.cs b/NzbDrone.Common/IEnvironmentProvider.cs similarity index 85% rename from NzbDrone.Common/EnvironmentProvider.cs rename to NzbDrone.Common/IEnvironmentProvider.cs index 0a4da1c8c..dfabe708a 100644 --- a/NzbDrone.Common/EnvironmentProvider.cs +++ b/NzbDrone.Common/IEnvironmentProvider.cs @@ -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 { diff --git a/NzbDrone.Common/ProcessProvider.cs b/NzbDrone.Common/IProcessProvider.cs similarity index 76% rename from NzbDrone.Common/ProcessProvider.cs rename to NzbDrone.Common/IProcessProvider.cs index bf4eef3bc..c10bf6af0 100644 --- a/NzbDrone.Common/ProcessProvider.cs +++ b/NzbDrone.Common/IProcessProvider.cs @@ -7,19 +7,32 @@ using NzbDrone.Common.Model; namespace NzbDrone.Common { - public class ProcessProvider + public interface IProcessProvider + { + ProcessInfo GetCurrentProcess(); + ProcessInfo GetProcessById(int id); + IEnumerable 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 GetProcessByName(string name) + public IEnumerable 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); diff --git a/NzbDrone.Common/ServiceProvider.cs b/NzbDrone.Common/IServiceProvider.cs similarity index 92% rename from NzbDrone.Common/ServiceProvider.cs rename to NzbDrone.Common/IServiceProvider.cs index 8abddd963..256ae6182 100644 --- a/NzbDrone.Common/ServiceProvider.cs +++ b/NzbDrone.Common/IServiceProvider.cs @@ -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"; diff --git a/NzbDrone.Common/Messaging/MessageAggregator.cs b/NzbDrone.Common/Messaging/MessageAggregator.cs index 041dc2cba..3d1a17ab7 100644 --- a/NzbDrone.Common/Messaging/MessageAggregator.cs +++ b/NzbDrone.Common/Messaging/MessageAggregator.cs @@ -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; diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index c69f2f66c..0bf371efd 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -79,8 +79,10 @@ - - + + + + @@ -122,22 +124,21 @@ - + - - + + - + - - + diff --git a/NzbDrone.Common/PathExtensions.cs b/NzbDrone.Common/PathExtensions.cs index 58e419edf..8ab70825b 100644 --- a/NzbDrone.Common/PathExtensions.cs +++ b/NzbDrone.Common/PathExtensions.cs @@ -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); } diff --git a/NzbDrone.Common/ReportingService.cs b/NzbDrone.Common/ReportingService.cs deleted file mode 100644 index 139ca7f09..000000000 --- a/NzbDrone.Common/ReportingService.cs +++ /dev/null @@ -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 parserErrorCache = new HashSet(); - - 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."); - } - } - } - } -} diff --git a/NzbDrone.Common/RestProvider.cs b/NzbDrone.Common/RestProvider.cs index 9ebb56a0e..4cd76eed9 100644 --- a/NzbDrone.Common/RestProvider.cs +++ b/NzbDrone.Common/RestProvider.cs @@ -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; } diff --git a/NzbDrone.Common/SecurityProvider.cs b/NzbDrone.Common/SecurityProvider.cs index fbc3cc21c..87b726b2d 100644 --- a/NzbDrone.Common/SecurityProvider.cs +++ b/NzbDrone.Common/SecurityProvider.cs @@ -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; diff --git a/NzbDrone.Common/ServiceFactory.cs b/NzbDrone.Common/ServiceFactory.cs index 29e79912a..4c91fe5f8 100644 --- a/NzbDrone.Common/ServiceFactory.cs +++ b/NzbDrone.Common/ServiceFactory.cs @@ -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; } diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index d12d414bb..588adb5fb 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -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().Single().Name.Should().Be("A"); + Db.All().Single().TypeName.Should().Be("A"); Db.All().Single().Interval.Should().Be(12); } diff --git a/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs b/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs index 246dbfb8c..ce0058cec 100644 --- a/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs +++ b/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs @@ -28,7 +28,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests private void WithExistingFile() { - Mocker.GetMock().Setup(c => c.FileExists(nzbPath)).Returns(true); + Mocker.GetMock().Setup(c => c.FileExists(nzbPath)).Returns(true); } private void WithFailedDownload() diff --git a/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs b/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs index 1c61d0ad0..fe10a6a18 100644 --- a/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs +++ b/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests private void WithExistingFile() { - Mocker.GetMock().Setup(c => c.FileExists(nzbPath)).Returns(true); + Mocker.GetMock().Setup(c => c.FileExists(nzbPath)).Returns(true); } private void WithFailedDownload() diff --git a/NzbDrone.Core.Test/MediaFileTests/EpisodeFileMoverFixture.cs b/NzbDrone.Core.Test/MediaFileTests/EpisodeFileMoverFixture.cs index 57b6cf6d0..1604fabcb 100644 --- a/NzbDrone.Core.Test/MediaFileTests/EpisodeFileMoverFixture.cs +++ b/NzbDrone.Core.Test/MediaFileTests/EpisodeFileMoverFixture.cs @@ -104,7 +104,7 @@ namespace NzbDrone.Core.Test.MediaFileTests .Setup(e => e.BuildFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv")) .Returns(fi); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.FileExists(currentFilename)) .Returns(true); diff --git a/NzbDrone.Core.Test/MediaFileTests/GhostFileCleanupFixture.cs b/NzbDrone.Core.Test/MediaFileTests/GhostFileCleanupFixture.cs index 4f8b9e32f..b2617d87c 100644 --- a/NzbDrone.Core.Test/MediaFileTests/GhostFileCleanupFixture.cs +++ b/NzbDrone.Core.Test/MediaFileTests/GhostFileCleanupFixture.cs @@ -27,7 +27,7 @@ namespace NzbDrone.Core.Test.MediaFileTests [SetUp] public void SetUp() { - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.FileExists(It.Is(c => c != DeletedPath))) .Returns(true); } diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs index 10aacd589..976562756 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs @@ -27,7 +27,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests @"C:\Test\movie.exe" }; - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) .Returns(_files); } @@ -39,8 +39,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Subject.GetVideoFiles(path); - Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once()); - Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never()); + Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once()); + Mocker.GetMock().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().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once()); - Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never()); + Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once()); + Mocker.GetMock().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().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Never()); - Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Once()); + Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Never()); + Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Once()); } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs index 5deb2f0bb..ba45d0349 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs @@ -56,7 +56,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests { _fileSize = size; - Mocker.GetMock() + Mocker.GetMock() .Setup(d => d.GetSize(It.IsAny())) .Returns(size); } @@ -221,7 +221,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests var result = Subject.ImportFile(_fakeSeries, "file.ext"); VerifyFileImport(result); - Mocker.GetMock().Verify(p => p.DeleteFile(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(p => p.DeleteFile(It.IsAny()), Times.Never()); } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/DropFolderImportServiceFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/DropFolderImportServiceFixture.cs index 07bf0561e..d7cb9ded1 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/DropFolderImportServiceFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/DropFolderImportServiceFixture.cs @@ -30,24 +30,24 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests Mocker.GetMock().Setup(c => c.GetVideoFiles(It.IsAny(), It.IsAny())) .Returns(_videoFiles); - Mocker.GetMock().Setup(c => c.GetDirectories(It.IsAny())) + Mocker.GetMock().Setup(c => c.GetDirectories(It.IsAny())) .Returns(_subFolders); } private void WithOldWrite() { - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetLastFolderWrite(It.IsAny())) .Returns(DateTime.Now.AddDays(-5)); } private void WithRecentFolderWrite() { - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetLastFolderWrite(It.IsAny())) .Returns(DateTime.UtcNow); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetLastFileWrite(It.IsAny())) .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().Setup(c => c.IsFileLocked(It.IsAny())) + Mocker.GetMock().Setup(c => c.IsFileLocked(It.IsAny())) .Returns(true); Subject.ProcessDropFolder("c:\\drop\\"); diff --git a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs index 41d35a3d2..38f560870 100644 --- a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs @@ -19,19 +19,19 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests private void WithExpired() { - Mocker.GetMock().Setup(s => s.GetLastFolderWrite(It.IsAny())) + Mocker.GetMock().Setup(s => s.GetLastFolderWrite(It.IsAny())) .Returns(DateTime.UtcNow.AddDays(-10)); - Mocker.GetMock().Setup(s => s.GetLastFileWrite(It.IsAny())) + Mocker.GetMock().Setup(s => s.GetLastFileWrite(It.IsAny())) .Returns(DateTime.UtcNow.AddDays(-10)); } private void WithNonExpired() { - Mocker.GetMock().Setup(s => s.GetLastFolderWrite(It.IsAny())) + Mocker.GetMock().Setup(s => s.GetLastFolderWrite(It.IsAny())) .Returns(DateTime.UtcNow.AddDays(-3)); - Mocker.GetMock().Setup(s => s.GetLastFileWrite(It.IsAny())) + Mocker.GetMock().Setup(s => s.GetLastFileWrite(It.IsAny())) .Returns(DateTime.UtcNow.AddDays(-3)); } @@ -40,10 +40,10 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests { Mocker.GetMock().SetupGet(s => s.RecycleBin).Returns(RecycleBin); - Mocker.GetMock().Setup(s => s.GetDirectories(RecycleBin)) + Mocker.GetMock().Setup(s => s.GetDirectories(RecycleBin)) .Returns(new [] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" }); - Mocker.GetMock().Setup(s => s.GetFiles(RecycleBin, SearchOption.TopDirectoryOnly)) + Mocker.GetMock().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().Cleanup(); - Mocker.GetMock().Verify(v => v.GetDirectories(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(v => v.GetDirectories(It.IsAny()), Times.Never()); } [Test] @@ -63,7 +63,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests WithExpired(); Mocker.Resolve().Cleanup(); - Mocker.GetMock().Verify(v => v.DeleteFolder(It.IsAny(), true), Times.Exactly(3)); + Mocker.GetMock().Verify(v => v.DeleteFolder(It.IsAny(), true), Times.Exactly(3)); } [Test] @@ -72,7 +72,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests WithExpired(); Mocker.Resolve().Cleanup(); - Mocker.GetMock().Verify(v => v.DeleteFile(It.IsAny()), Times.Exactly(2)); + Mocker.GetMock().Verify(v => v.DeleteFile(It.IsAny()), Times.Exactly(2)); } [Test] @@ -81,7 +81,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests WithNonExpired(); Mocker.Resolve().Cleanup(); - Mocker.GetMock().Verify(v => v.DeleteFolder(It.IsAny(), true), Times.Never()); + Mocker.GetMock().Verify(v => v.DeleteFolder(It.IsAny(), true), Times.Never()); } [Test] @@ -90,7 +90,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests WithNonExpired(); Mocker.Resolve().Cleanup(); - Mocker.GetMock().Verify(v => v.DeleteFile(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(v => v.DeleteFile(It.IsAny()), Times.Never()); } } } diff --git a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs index d1efd6d27..0331c8c65 100644 --- a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs @@ -43,7 +43,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests Mocker.Resolve().DeleteDirectory(path); - Mocker.GetMock().Verify(v => v.DeleteFolder(path, true), Times.Once()); + Mocker.GetMock().Verify(v => v.DeleteFolder(path, true), Times.Once()); } [Test] @@ -55,7 +55,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests Mocker.Resolve().DeleteDirectory(path); - Mocker.GetMock().Verify(v => v.MoveDirectory(path, @"C:\Test\Recycle Bin\30 Rock"), Times.Once()); + Mocker.GetMock().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().DeleteDirectory(path); - Mocker.GetMock().Verify(v => v.DirectorySetLastWriteTimeUtc(@"C:\Test\Recycle Bin\30 Rock", It.IsAny()), Times.Once()); + Mocker.GetMock().Verify(v => v.DirectorySetLastWriteTimeUtc(@"C:\Test\Recycle Bin\30 Rock", It.IsAny()), Times.Once()); } [Test] @@ -76,12 +76,12 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests WithRecycleBin(); var path = @"C:\Test\TV\30 Rock"; - Mocker.GetMock().Setup(s => s.GetFiles(@"C:\Test\Recycle Bin\30 Rock", SearchOption.AllDirectories)) + Mocker.GetMock().Setup(s => s.GetFiles(@"C:\Test\Recycle Bin\30 Rock", SearchOption.AllDirectories)) .Returns(new[]{ "File1", "File2", "File3" }); Mocker.Resolve().DeleteDirectory(path); - Mocker.GetMock().Verify(v => v.FileSetLastWriteTimeUtc(It.IsAny(), It.IsAny()), Times.Exactly(3)); + Mocker.GetMock().Verify(v => v.FileSetLastWriteTimeUtc(It.IsAny(), It.IsAny()), Times.Exactly(3)); } } } diff --git a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteFileFixture.cs index ec8d8229c..03586171a 100644 --- a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteFileFixture.cs @@ -43,7 +43,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests Mocker.Resolve().DeleteFile(path); - Mocker.GetMock().Verify(v => v.DeleteFile(path), Times.Once()); + Mocker.GetMock().Verify(v => v.DeleteFile(path), Times.Once()); } [Test] @@ -55,7 +55,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests Mocker.Resolve().DeleteFile(path); - Mocker.GetMock().Verify(v => v.MoveFile(path, @"C:\Test\Recycle Bin\S01E01.avi"), Times.Once()); + Mocker.GetMock().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().DeleteFile(path); - Mocker.GetMock().Verify(v => v.FileSetLastWriteTimeUtc(@"C:\Test\Recycle Bin\S01E01.avi", It.IsAny()), Times.Once()); + Mocker.GetMock().Verify(v => v.FileSetLastWriteTimeUtc(@"C:\Test\Recycle Bin\S01E01.avi", It.IsAny()), Times.Once()); } } } diff --git a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs index bf6fca51d..bc78125b2 100644 --- a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs @@ -31,10 +31,10 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests { Mocker.GetMock().SetupGet(s => s.RecycleBin).Returns(RecycleBin); - Mocker.GetMock().Setup(s => s.GetDirectories(RecycleBin)) + Mocker.GetMock().Setup(s => s.GetDirectories(RecycleBin)) .Returns(new [] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" }); - Mocker.GetMock().Setup(s => s.GetFiles(RecycleBin, SearchOption.TopDirectoryOnly)) + Mocker.GetMock().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().Empty(); - Mocker.GetMock().Verify(v => v.GetDirectories(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(v => v.GetDirectories(It.IsAny()), Times.Never()); } [Test] @@ -53,7 +53,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests { Mocker.Resolve().Empty(); - Mocker.GetMock().Verify(v => v.DeleteFolder(It.IsAny(), true), Times.Exactly(3)); + Mocker.GetMock().Verify(v => v.DeleteFolder(It.IsAny(), true), Times.Exactly(3)); } [Test] @@ -61,7 +61,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests { Mocker.Resolve().Empty(); - Mocker.GetMock().Verify(v => v.DeleteFile(It.IsAny()), Times.Exactly(2)); + Mocker.GetMock().Verify(v => v.DeleteFile(It.IsAny()), Times.Exactly(2)); } } } diff --git a/NzbDrone.Core.Test/RootFolderTests/FreeSpaceOnDrivesFixture.cs b/NzbDrone.Core.Test/RootFolderTests/FreeSpaceOnDrivesFixture.cs index 619aa92f9..ff3458ab1 100644 --- a/NzbDrone.Core.Test/RootFolderTests/FreeSpaceOnDrivesFixture.cs +++ b/NzbDrone.Core.Test/RootFolderTests/FreeSpaceOnDrivesFixture.cs @@ -25,11 +25,11 @@ namespace NzbDrone.Core.Test.RootFolderTests .Setup(s => s.All()) .Returns(new List { new RootFolder { Id = 1, Path = @"C:\Test\TV" } }); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetPathRoot(@"C:\Test\TV")) .Returns(@"C:\"); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetAvilableSpace(@"C:\")) .Returns(123456); @@ -46,11 +46,11 @@ namespace NzbDrone.Core.Test.RootFolderTests .Returns(new List { new RootFolder { Id = 1, Path = @"C:\Test\TV" }, new RootFolder { Id = 2, Path = @"C:\Test\TV2" }}); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetPathRoot(It.IsAny())) .Returns(@"C:\"); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetAvilableSpace(@"C:\")) .Returns(123456); @@ -67,15 +67,15 @@ namespace NzbDrone.Core.Test.RootFolderTests .Returns(new List { new RootFolder { Id = 1, Path = @"C:\Test\TV" }, new RootFolder { Id = 2, Path = @"D:\Test\TV" }}); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetPathRoot(@"C:\Test\TV")) .Returns(@"C:\"); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetPathRoot(@"D:\Test\TV")) .Returns(@"D:\"); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetAvilableSpace(It.IsAny())) .Returns(123456); @@ -91,11 +91,11 @@ namespace NzbDrone.Core.Test.RootFolderTests .Setup(s => s.All()) .Returns(new List { new RootFolder { Id = 1, Path = @"C:\Test\TV" } }); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetPathRoot(@"C:\Test\TV")) .Returns(@"C:\"); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetAvilableSpace(It.IsAny())) .Throws(new DirectoryNotFoundException()); diff --git a/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs b/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs index a6017e3f8..8d8d812f5 100644 --- a/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs +++ b/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs @@ -21,7 +21,7 @@ namespace NzbDrone.Core.Test.RootFolderTests [SetUp] public void Setup() { - Mocker.GetMock() + Mocker.GetMock() .Setup(m => m.FolderExists(It.IsAny())) .Returns(true); @@ -32,7 +32,7 @@ namespace NzbDrone.Core.Test.RootFolderTests private void WithNoneExistingFolder() { - Mocker.GetMock() + Mocker.GetMock() .Setup(m => m.FolderExists(It.IsAny())) .Returns(false); } @@ -75,7 +75,7 @@ namespace NzbDrone.Core.Test.RootFolderTests result.Should().NotBeNull(); result.Should().BeEmpty(); - Mocker.GetMock().Verify(c => c.GetDirectories(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(c => c.GetDirectories(It.IsAny()), Times.Never()); } [Test] diff --git a/NzbDrone.Core.Test/UpdateTests/GetUpdateLogFixture.cs b/NzbDrone.Core.Test/UpdateTests/GetUpdateLogFixture.cs index eed45876f..375279c40 100644 --- a/NzbDrone.Core.Test/UpdateTests/GetUpdateLogFixture.cs +++ b/NzbDrone.Core.Test/UpdateTests/GetUpdateLogFixture.cs @@ -17,9 +17,9 @@ namespace NzbDrone.Core.Test.UpdateTests { WithTempAsAppPath(); - _updateLogFolder = Mocker.GetMock().Object.GetUpdateLogFolder(); + _updateLogFolder = Mocker.GetMock().Object.GetUpdateLogFolder(); - Mocker.GetMock() + Mocker.GetMock() .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() + Mocker.GetMock() .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() + Mocker.GetMock() .Setup(c => c.FolderExists(_updateLogFolder)) .Returns(false); diff --git a/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs b/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs index 69efcc491..c78e78f37 100644 --- a/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs +++ b/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs @@ -30,13 +30,13 @@ namespace NzbDrone.Core.Test.UpdateTests [SetUp] public void Setup() { - Mocker.GetMock().SetupGet(c => c.SystemTemp).Returns(TempFolder); - Mocker.GetMock().SetupGet(c => c.Guid).Returns(_clientGuid); + Mocker.GetMock().SetupGet(c => c.SystemTemp).Returns(TempFolder); + Mocker.GetMock().SetupGet(c => c.Guid).Returns(_clientGuid); Mocker.GetMock().Setup(c => c.GetLatestUpdate()).Returns(_updatePackage); - Mocker.GetMock().Setup(c => c.GetCurrentProcess()).Returns(new ProcessInfo { Id = 12 }); + Mocker.GetMock().Setup(c => c.GetCurrentProcess()).Returns(new ProcessInfo { Id = 12 }); - _sandboxFolder = Mocker.GetMock().Object.GetUpdateSandboxFolder(); + _sandboxFolder = Mocker.GetMock().Object.GetUpdateSandboxFolder(); } @@ -44,21 +44,21 @@ namespace NzbDrone.Core.Test.UpdateTests [Test] public void should_delete_sandbox_before_update_if_folder_exists() { - Mocker.GetMock().Setup(c => c.FolderExists(_sandboxFolder)).Returns(true); + Mocker.GetMock().Setup(c => c.FolderExists(_sandboxFolder)).Returns(true); Subject.InstallAvailableUpdate(); - Mocker.GetMock().Verify(c => c.DeleteFolder(_sandboxFolder, true)); + Mocker.GetMock().Verify(c => c.DeleteFolder(_sandboxFolder, true)); } [Test] public void should_not_delete_sandbox_before_update_if_folder_doesnt_exists() { - Mocker.GetMock().Setup(c => c.FolderExists(_sandboxFolder)).Returns(false); + Mocker.GetMock().Setup(c => c.FolderExists(_sandboxFolder)).Returns(false); Subject.InstallAvailableUpdate(); - Mocker.GetMock().Verify(c => c.DeleteFolder(_sandboxFolder, true), Times.Never()); + Mocker.GetMock().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().Object.GetUpdateClientFolder(); + var updateClientFolder = Mocker.GetMock().Object.GetUpdateClientFolder(); Subject.InstallAvailableUpdate(); - Mocker.GetMock().Verify(c => c.MoveDirectory(updateClientFolder, _sandboxFolder)); + Mocker.GetMock().Verify(c => c.MoveDirectory(updateClientFolder, _sandboxFolder)); } [Test] public void should_start_update_client() { - var updateClientPath = Mocker.GetMock().Object.GetUpdateClientExePath(); + var updateClientPath = Mocker.GetMock().Object.GetUpdateClientExePath(); Subject.InstallAvailableUpdate(); - Mocker.GetMock().Verify( + Mocker.GetMock().Verify( c => c.Start(It.Is(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().Object.GetUpdateSandboxFolder()); + var updateSubFolder = new DirectoryInfo(Mocker.GetMock().Object.GetUpdateSandboxFolder()); updateSubFolder.Exists.Should().BeFalse(); - Mocker.Resolve(); + Mocker.Resolve(); Mocker.Resolve(); Subject.InstallAvailableUpdate(); diff --git a/NzbDrone.Core/Datastore/BasicRepository.cs b/NzbDrone.Core/Datastore/BasicRepository.cs index d0b5c2ff6..9b5523230 100644 --- a/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/NzbDrone.Core/Datastore/BasicRepository.cs @@ -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(); } + } } diff --git a/NzbDrone.Core/Datastore/Migration/Framework/MigrationLogger.cs b/NzbDrone.Core/Datastore/Migration/Framework/MigrationLogger.cs index cab90b90c..af52275e0 100644 --- a/NzbDrone.Core/Datastore/Migration/Framework/MigrationLogger.cs +++ b/NzbDrone.Core/Datastore/Migration/Framework/MigrationLogger.cs @@ -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; diff --git a/NzbDrone.Core/Datastore/Migration/Migration20130324.cs b/NzbDrone.Core/Datastore/Migration/Migration20130324.cs index a581b751a..e5462aaa4 100644 --- a/NzbDrone.Core/Datastore/Migration/Migration20130324.cs +++ b/NzbDrone.Core/Datastore/Migration/Migration20130324.cs @@ -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(); diff --git a/NzbDrone.Core/Download/Clients/BlackholeProvider.cs b/NzbDrone.Core/Download/Clients/BlackholeProvider.cs index 0b7af0851..1ea8f5f17 100644 --- a/NzbDrone.Core/Download/Clients/BlackholeProvider.cs +++ b/NzbDrone.Core/Download/Clients/BlackholeProvider.cs @@ -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; diff --git a/NzbDrone.Core/Download/Clients/PneumaticClient.cs b/NzbDrone.Core/Download/Clients/PneumaticClient.cs index 05096855a..86b9a980a 100644 --- a/NzbDrone.Core/Download/Clients/PneumaticClient.cs +++ b/NzbDrone.Core/Download/Clients/PneumaticClient.cs @@ -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; diff --git a/NzbDrone.Core/Jobs/JobRepository.cs b/NzbDrone.Core/Jobs/JobRepository.cs index 26d468a8b..7c0f5a273 100644 --- a/NzbDrone.Core/Jobs/JobRepository.cs +++ b/NzbDrone.Core/Jobs/JobRepository.cs @@ -10,6 +10,7 @@ namespace NzbDrone.Core.Jobs { IList 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); + } } } diff --git a/NzbDrone.Core/Jobs/ScheduledTask.cs b/NzbDrone.Core/Jobs/ScheduledTask.cs index 5e3a4e21d..99dfc5f75 100644 --- a/NzbDrone.Core/Jobs/ScheduledTask.cs +++ b/NzbDrone.Core/Jobs/ScheduledTask.cs @@ -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; } } diff --git a/NzbDrone.Core/Jobs/Scheduler.cs b/NzbDrone.Core/Jobs/Scheduler.cs index c53bd6380..44d97c9dc 100644 --- a/NzbDrone.Core/Jobs/Scheduler.cs +++ b/NzbDrone.Core/Jobs/Scheduler.cs @@ -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,10 +37,23 @@ namespace NzbDrone.Core.Jobs foreach (var task in tasks) { - var commandType = Type.GetType(task.Name); - var command = (ICommand)Activator.CreateInstance(commandType); + try + { + var commandType = Type.GetType(task.TypeName); + var command = (ICommand)Activator.CreateInstance(commandType); + + _messageAggregator.PublishCommand(command); + } + catch (Exception e) + { + _logger.ErrorException("Error occured while execution task " + task.TypeName, e); + } + finally + { + _taskManager.SetLastExecutionTime(task.Id); + } + - _messageAggregator.PublishCommand(command); } } diff --git a/NzbDrone.Core/Jobs/TaskManager.cs b/NzbDrone.Core/Jobs/TaskManager.cs index ab4b33c66..70cb49bc1 100644 --- a/NzbDrone.Core/Jobs/TaskManager.cs +++ b/NzbDrone.Core/Jobs/TaskManager.cs @@ -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 GetPending(); + void SetLastExecutionTime(int taskId); } public class TaskManager : IHandle, 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) { diff --git a/NzbDrone.Core/MediaCover/MediaCoverService.cs b/NzbDrone.Core/MediaCover/MediaCoverService.cs index eb7942072..282d39b6b 100644 --- a/NzbDrone.Core/MediaCover/MediaCoverService.cs +++ b/NzbDrone.Core/MediaCover/MediaCoverService.cs @@ -13,12 +13,12 @@ namespace NzbDrone.Core.MediaCover IHandleAsync { 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; diff --git a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs index eacb01974..7cd6921ca 100644 --- a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs +++ b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs @@ -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; diff --git a/NzbDrone.Core/MediaFiles/GhostFileCleanupService.cs b/NzbDrone.Core/MediaFiles/GhostFileCleanupService.cs index fd42666e1..efbca4182 100644 --- a/NzbDrone.Core/MediaFiles/GhostFileCleanupService.cs +++ b/NzbDrone.Core/MediaFiles/GhostFileCleanupService.cs @@ -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; diff --git a/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs b/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs index fcd8e2485..103adcc42 100644 --- a/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs +++ b/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs @@ -11,12 +11,12 @@ namespace NzbDrone.Core.MediaFiles { public class RecycleBinProvider : IHandleAsync, IExecute { - 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; diff --git a/NzbDrone.Core/Parser/Parser.cs b/NzbDrone.Core/Parser/Parser.cs index 6dacc3a25..a87f66ca0 100644 --- a/NzbDrone.Core/Parser/Parser.cs +++ b/NzbDrone.Core/Parser/Parser.cs @@ -134,7 +134,6 @@ namespace NzbDrone.Core.Parser } Logger.Trace("Unable to parse {0}", title); - ReportingService.ReportParseError(title); return null; } diff --git a/NzbDrone.Core/Providers/BackupProvider.cs b/NzbDrone.Core/Providers/BackupProvider.cs index 98aac9ad3..9833ffb1d 100644 --- a/NzbDrone.Core/Providers/BackupProvider.cs +++ b/NzbDrone.Core/Providers/BackupProvider.cs @@ -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; } diff --git a/NzbDrone.Core/Providers/DropfolderImportService.cs b/NzbDrone.Core/Providers/DropfolderImportService.cs index e490c4e20..05eb998f1 100644 --- a/NzbDrone.Core/Providers/DropfolderImportService.cs +++ b/NzbDrone.Core/Providers/DropfolderImportService.cs @@ -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, diff --git a/NzbDrone.Core/Providers/IDiskScanService.cs b/NzbDrone.Core/Providers/IDiskScanService.cs index 653c54b35..2d7ab8364 100644 --- a/NzbDrone.Core/Providers/IDiskScanService.cs +++ b/NzbDrone.Core/Providers/IDiskScanService.cs @@ -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; diff --git a/NzbDrone.Core/Providers/VideoFileInfoReader.cs b/NzbDrone.Core/Providers/VideoFileInfoReader.cs index bceb048ca..1aa8c121e 100644 --- a/NzbDrone.Core/Providers/VideoFileInfoReader.cs +++ b/NzbDrone.Core/Providers/VideoFileInfoReader.cs @@ -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; diff --git a/NzbDrone.Core/RootFolders/RootFolderService.cs b/NzbDrone.Core/RootFolders/RootFolderService.cs index 7a73d5a52..7bd810597 100644 --- a/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -23,10 +23,10 @@ namespace NzbDrone.Core.RootFolders { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private readonly IBasicRepository _rootFolderRepository; - private readonly DiskProvider _diskProvider; + private readonly IDiskProvider _diskProvider; private readonly ISeriesRepository _seriesRepository; - public RootFolderService(IBasicRepository rootFolderRepository, DiskProvider diskProvider,ISeriesRepository seriesRepository) + public RootFolderService(IBasicRepository rootFolderRepository, IDiskProvider diskProvider,ISeriesRepository seriesRepository) { _rootFolderRepository = rootFolderRepository; _diskProvider = diskProvider; diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index 379a96268..22e423f30 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -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; diff --git a/NzbDrone.Core/Update/UpdateService.cs b/NzbDrone.Core/Update/UpdateService.cs index b70c2a180..81eca56a2 100644 --- a/NzbDrone.Core/Update/UpdateService.cs +++ b/NzbDrone.Core/Update/UpdateService.cs @@ -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; diff --git a/NzbDrone.Integration.Test/IntegrationTest.cs b/NzbDrone.Integration.Test/IntegrationTest.cs index 3ac0ca7e3..02cc50418 100644 --- a/NzbDrone.Integration.Test/IntegrationTest.cs +++ b/NzbDrone.Integration.Test/IntegrationTest.cs @@ -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().Create(dbPath)); + Container.Register(c => c.Resolve().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(); + var _hostConfig = new Mock(); _hostConfig.SetupGet(c => c.Port).Returns(1313); _hostController = new OwinHostController(_hostConfig.Object, new[] { new NancyMiddleWare(_bootstrapper) }, Logger); diff --git a/NzbDrone.Test.Common/TestBase.cs b/NzbDrone.Test.Common/TestBase.cs index ca216d7d3..d423b4b3c 100644 --- a/NzbDrone.Test.Common/TestBase.cs +++ b/NzbDrone.Test.Common/TestBase.cs @@ -82,7 +82,6 @@ namespace NzbDrone.Test.Common TempFolder = Path.Combine(Directory.GetCurrentDirectory(), "_temp_" + DateTime.Now.Ticks); MockedRestProvider = new Mock(); - ReportingService.RestProvider = MockedRestProvider.Object; Directory.CreateDirectory(TempFolder); } @@ -137,7 +136,7 @@ namespace NzbDrone.Test.Common protected void WithTempAsAppPath() { - Mocker.GetMock() + Mocker.GetMock() .SetupGet(c => c.WorkingDirectory) .Returns(VirtualPath); } diff --git a/NzbDrone.Update.Test/ProgramFixture.cs b/NzbDrone.Update.Test/ProgramFixture.cs index a8e9ab5dc..c42628e6e 100644 --- a/NzbDrone.Update.Test/ProgramFixture.cs +++ b/NzbDrone.Update.Test/ProgramFixture.cs @@ -54,7 +54,7 @@ namespace NzbDrone.Update.Test { const string ProcessPath = @"C:\NzbDrone\nzbdrone.exe"; - Mocker.GetMock().Setup(c => c.GetProcessById(12)) + Mocker.GetMock().Setup(c => c.GetProcessById(12)) .Returns(new ProcessInfo() { StartPath = ProcessPath }); diff --git a/NzbDrone.Update.Test/UpdateProviderStartFixture.cs b/NzbDrone.Update.Test/UpdateProviderStartFixture.cs index 0c280b579..d01b20363 100644 --- a/NzbDrone.Update.Test/UpdateProviderStartFixture.cs +++ b/NzbDrone.Update.Test/UpdateProviderStartFixture.cs @@ -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; + Mock _environmentProvider; [SetUp] public void Setup() { - _environmentProvider = Mocker.GetMock(); + _environmentProvider = Mocker.GetMock(); _environmentProvider.SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\"); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.FolderExists(UPDATE_FOLDER)) .Returns(true); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.FolderExists(TARGET_FOLDER)) .Returns(true); } private void WithInstalledService() { - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)) .Returns(true); } private void WithServiceRunning(bool state) { - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(state); } @@ -63,7 +63,7 @@ namespace NzbDrone.Update.Test Mocker.Resolve().Start(TARGET_FOLDER); - Mocker.GetMock().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once()); + Mocker.GetMock().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once()); } [Test] @@ -76,7 +76,7 @@ namespace NzbDrone.Update.Test Mocker.Resolve().Start(TARGET_FOLDER); - Mocker.GetMock().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Never()); + Mocker.GetMock().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Never()); } [Test] @@ -86,7 +86,7 @@ namespace NzbDrone.Update.Test Mocker.Resolve().Start(TARGET_FOLDER); - Mocker.GetMock().Verify(c => c.Stop(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(c => c.Stop(It.IsAny()), Times.Never()); } [Test] @@ -94,7 +94,7 @@ namespace NzbDrone.Update.Test { var proccesses = Builder.CreateListOfSize(2).Build().ToList(); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetProcessByName(ProcessProvider.NzbDroneProcessName)) .Returns(proccesses); @@ -102,13 +102,13 @@ namespace NzbDrone.Update.Test Mocker.Resolve().Start(TARGET_FOLDER); - Mocker.GetMock().Verify(c => c.KillAll(ProcessProvider.NzbDroneProcessName), Times.Once()); + Mocker.GetMock().Verify(c => c.KillAll(ProcessProvider.NzbDroneProcessName), Times.Once()); } [Test] public void should_not_kill_nzbdrone_process_not_running() { - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetProcessByName(ProcessProvider.NzbDroneProcessName)) .Returns(new List()); @@ -116,13 +116,13 @@ namespace NzbDrone.Update.Test Mocker.Resolve().Start(TARGET_FOLDER); - Mocker.GetMock().Verify(c => c.Kill(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(c => c.Kill(It.IsAny()), Times.Never()); } [Test] public void should_create_backup_of_current_installation() { - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.CopyDirectory(TARGET_FOLDER, BACKUP_FOLDER)); Mocker.Resolve().Start(TARGET_FOLDER); @@ -131,10 +131,10 @@ namespace NzbDrone.Update.Test [Test] public void should_copy_update_package_to_target() { - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER)); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.DeleteFolder(UPDATE_FOLDER, true)); Mocker.Resolve().Start(TARGET_FOLDER); @@ -143,7 +143,7 @@ namespace NzbDrone.Update.Test [Test] public void should_restore_if_update_fails() { - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER)) .Throws(new IOException()); @@ -151,7 +151,7 @@ namespace NzbDrone.Update.Test Mocker.Resolve().Start(TARGET_FOLDER); - Mocker.GetMock() + Mocker.GetMock() .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() + Mocker.GetMock() .Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER)) .Throws(new IOException()); @@ -206,7 +206,7 @@ namespace NzbDrone.Update.Test WithInstalledService(); WithServiceRunning(false); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER)) .Throws(new IOException()); @@ -220,19 +220,19 @@ namespace NzbDrone.Update.Test private void VerifyServiceRestart() { - Mocker.GetMock() + Mocker.GetMock() .Verify(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once()); - Mocker.GetMock() + Mocker.GetMock() .Verify(c => c.Start(It.IsAny()), Times.Never()); } private void VerifyProcessRestart() { - Mocker.GetMock() + Mocker.GetMock() .Verify(c => c.Start(It.IsAny()), Times.Never()); - Mocker.GetMock() + Mocker.GetMock() .Verify(c => c.Start(TARGET_FOLDER + "NzbDrone.exe"), Times.Once()); } diff --git a/NzbDrone.Update.Test/UpdateProviderVerifyFixture.cs b/NzbDrone.Update.Test/UpdateProviderVerifyFixture.cs index c652680ef..b5c1ed80a 100644 --- a/NzbDrone.Update.Test/UpdateProviderVerifyFixture.cs +++ b/NzbDrone.Update.Test/UpdateProviderVerifyFixture.cs @@ -18,10 +18,10 @@ namespace NzbDrone.Update.Test [SetUp] public void Setup() { - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.StartUpPath).Returns(@"C:\Temp\NzbDrone_update\"); - Mocker.GetMock() + Mocker.GetMock() .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() + Mocker.GetMock() .Setup(c => c.FolderExists(targetFolder)) .Returns(true); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.FolderExists(sandboxFolder)) .Returns(false); diff --git a/NzbDrone.Update/Program.cs b/NzbDrone.Update/Program.cs index 17311ac4b..704378435 100644 --- a/NzbDrone.Update/Program.cs +++ b/NzbDrone.Update/Program.cs @@ -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().Version); + logger.Info("Updating NzbDrone to version {0}", _container.Resolve().Version); _container.Resolve().Start(args); } catch (Exception e) @@ -44,8 +44,8 @@ namespace NzbDrone.Update { try { - var environmentProvider = _container.Resolve(); - var diskProvider = _container.Resolve(); + var environmentProvider = _container.Resolve(); + var diskProvider = _container.Resolve(); logger.Info("Copying log files to application directory."); diskProvider.CopyDirectory(environmentProvider.GetSandboxLogFolder(), environmentProvider.GetUpdateLogFolder()); } diff --git a/NzbDrone.Update/Providers/UpdateProvider.cs b/NzbDrone.Update/Providers/UpdateProvider.cs index d73fe8d48..139e16486 100644 --- a/NzbDrone.Update/Providers/UpdateProvider.cs +++ b/NzbDrone.Update/Providers/UpdateProvider.cs @@ -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; diff --git a/NzbDrone.Update/UpdateContainerBuilder.cs b/NzbDrone.Update/UpdateContainerBuilder.cs index 102b32b22..604f4ac38 100644 --- a/NzbDrone.Update/UpdateContainerBuilder.cs +++ b/NzbDrone.Update/UpdateContainerBuilder.cs @@ -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; } diff --git a/NzbDrone/ApplicationServer.cs b/NzbDrone/ApplicationServer.cs index 5c33b6f88..b741c9e30 100644 --- a/NzbDrone/ApplicationServer.cs +++ b/NzbDrone/ApplicationServer.cs @@ -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; diff --git a/NzbDrone/MainAppContainerBuilder.cs b/NzbDrone/MainAppContainerBuilder.cs index d401734a0..53c14de48 100644 --- a/NzbDrone/MainAppContainerBuilder.cs +++ b/NzbDrone/MainAppContainerBuilder.cs @@ -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(); - - Container.Register().AsSingleton(); - Container.Register().AsSingleton(); - Container.Register().AsSingleton(); - Container.Register().AsSingleton(); - - Container.Register(typeof(IBasicRepository), typeof(BasicRepository)).AsMultiInstance(); - Container.Register(typeof(IBasicRepository), typeof(BasicRepository)).AsMultiInstance(); - AutoRegisterImplementations(); + Container.Register(typeof(IBasicRepository), typeof(BasicRepository)); + Container.Register(typeof(IBasicRepository), typeof(BasicRepository)); + + Container.Register(); + InitDatabase(); - ReportingService.RestProvider = Container.Resolve(); + + } private void InitDatabase() @@ -58,7 +52,7 @@ namespace NzbDrone Directory.CreateDirectory(appDataPath); } - Container.Register((c, p) => c.Resolve().Create(environmentProvider.GetNzbDroneDatabase())); + Container.Register(c => c.Resolve().Create(environmentProvider.GetNzbDroneDatabase())); } } } \ No newline at end of file diff --git a/NzbDrone/NLog.config b/NzbDrone/NLog.config index f74e2d081..23f2d521e 100644 --- a/NzbDrone/NLog.config +++ b/NzbDrone/NLog.config @@ -21,11 +21,11 @@ - + diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index f33d375d0..15e70a225 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -153,7 +153,6 @@ Form - diff --git a/NzbDrone/Owin/MiddleWare/SignalRMiddleWare.cs b/NzbDrone/Owin/MiddleWare/SignalRMiddleWare.cs index 9975ea8d5..f06278588 100644 --- a/NzbDrone/Owin/MiddleWare/SignalRMiddleWare.cs +++ b/NzbDrone/Owin/MiddleWare/SignalRMiddleWare.cs @@ -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 persistentConnections, TinyIoCContainer container) + public SignalRMiddleWare(IEnumerable persistentConnections, IContainer container) { _persistentConnections = persistentConnections; diff --git a/NzbDrone/Owin/OwinHostController.cs b/NzbDrone/Owin/OwinHostController.cs index a2f30b020..8ee42cf23 100644 --- a/NzbDrone/Owin/OwinHostController.cs +++ b/NzbDrone/Owin/OwinHostController.cs @@ -14,12 +14,12 @@ namespace NzbDrone.Owin { public class OwinHostController : IHostController { - private readonly ConfigFileProvider _configFileProvider; + private readonly IConfigFileProvider _configFileProvider; private readonly IEnumerable _owinMiddleWares; private readonly Logger _logger; private IDisposable _host; - public OwinHostController(ConfigFileProvider configFileProvider, IEnumerable owinMiddleWares, Logger logger) + public OwinHostController(IConfigFileProvider configFileProvider, IEnumerable owinMiddleWares, Logger logger) { _configFileProvider = configFileProvider; _owinMiddleWares = owinMiddleWares; diff --git a/NzbDrone/PriorityMonitor.cs b/NzbDrone/PriorityMonitor.cs index 018a8980c..0d2f301c2 100644 --- a/NzbDrone/PriorityMonitor.cs +++ b/NzbDrone/PriorityMonitor.cs @@ -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; diff --git a/NzbDrone/Router.cs b/NzbDrone/Router.cs index e513cc53b..9b248ff01 100644 --- a/NzbDrone/Router.cs +++ b/NzbDrone/Router.cs @@ -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; diff --git a/NzbDrone/SysTray/SysTrayApp.cs b/NzbDrone/SysTray/SysTrayApp.cs index 34b526cac..15ca53d2a 100644 --- a/NzbDrone/SysTray/SysTrayApp.cs +++ b/NzbDrone/SysTray/SysTrayApp.cs @@ -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) diff --git a/NzbDrone/SysTray/SysTrayProvider.cs b/NzbDrone/SysTray/SysTrayProvider.cs deleted file mode 100644 index 2b3561909..000000000 --- a/NzbDrone/SysTray/SysTrayProvider.cs +++ /dev/null @@ -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); - } - } -} \ No newline at end of file