mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 03:52:33 +02:00
broke up EnvironmentProvider into different services
This commit is contained in:
parent
4d874829e8
commit
6b0a24e28e
@ -5,6 +5,7 @@
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
@ -13,24 +14,24 @@ namespace NzbDrone.Api.Client
|
||||
{
|
||||
public class ClientSettings : IHandle<ApplicationStartedEvent>
|
||||
{
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
|
||||
private static readonly Regex VersionRegex = new Regex(@"(?<=Version:\s')(.*)(?=')", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
private static readonly Regex BuildDateRegex = new Regex(@"(?<=BuildDate:\s)('.*')", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
public ClientSettings(EnvironmentProvider environmentProvider)
|
||||
public ClientSettings(IAppDirectoryInfo appDirectoryInfo)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
}
|
||||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
{
|
||||
//TODO: Update the APIKey (when we have it)
|
||||
|
||||
var appFile = Path.Combine(_environmentProvider.StartUpPath, "UI", "app.js");
|
||||
var appFile = Path.Combine(_appDirectoryInfo.StartUpPath, "UI", "app.js");
|
||||
var contents = File.ReadAllText(appFile);
|
||||
var version = _environmentProvider.Version;
|
||||
var date = _environmentProvider.BuildDateTime;
|
||||
var version = BuildInfo.Version;
|
||||
var date = BuildInfo.BuildDateTime;
|
||||
|
||||
contents = VersionRegex.Replace(contents, version.ToString());
|
||||
contents = BuildDateRegex.Replace(contents, date.ToUniversalTime().ToJson());
|
||||
|
@ -1,15 +1,16 @@
|
||||
using System.IO;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Api.Frontend
|
||||
{
|
||||
public class MediaCoverMapper : IMapHttpRequestsToDisk
|
||||
{
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
|
||||
public MediaCoverMapper(IEnvironmentProvider environmentProvider)
|
||||
public MediaCoverMapper(IAppDirectoryInfo appDirectoryInfo)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
}
|
||||
|
||||
public string Map(string resourceUrl)
|
||||
@ -17,7 +18,7 @@ public string Map(string resourceUrl)
|
||||
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
||||
path = path.Trim(Path.DirectorySeparatorChar).ToLower();
|
||||
|
||||
return Path.Combine(_environmentProvider.GetAppDataPath(), path);
|
||||
return Path.Combine(_appDirectoryInfo.GetAppDataPath(), path);
|
||||
}
|
||||
|
||||
public bool CanHandle(string resourceUrl)
|
||||
|
@ -2,12 +2,13 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Api.Frontend
|
||||
{
|
||||
public class StaticResourceMapper : IMapHttpRequestsToDisk
|
||||
{
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
private static readonly string[] Extensions = new[] {
|
||||
".css",
|
||||
".js",
|
||||
@ -24,9 +25,9 @@ public class StaticResourceMapper : IMapHttpRequestsToDisk
|
||||
".eot"
|
||||
};
|
||||
|
||||
public StaticResourceMapper(IEnvironmentProvider environmentProvider)
|
||||
public StaticResourceMapper(IAppDirectoryInfo appDirectoryInfo)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
}
|
||||
|
||||
public string Map(string resourceUrl)
|
||||
@ -35,7 +36,7 @@ public string Map(string resourceUrl)
|
||||
path = path.Trim(Path.DirectorySeparatorChar).ToLower();
|
||||
|
||||
|
||||
return Path.Combine(_environmentProvider.StartUpPath, "ui", path);
|
||||
return Path.Combine(_appDirectoryInfo.StartUpPath, "ui", path);
|
||||
}
|
||||
|
||||
public bool CanHandle(string resourceUrl)
|
||||
|
@ -2,19 +2,21 @@
|
||||
using Nancy.Routing;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Api.Extensions;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Api.System
|
||||
{
|
||||
public class SystemModule : NzbDroneApiModule
|
||||
{
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
private readonly IRuntimeInfo _runtimeInfo;
|
||||
private readonly IRouteCacheProvider _routeCacheProvider;
|
||||
|
||||
public SystemModule(IEnvironmentProvider environmentProvider, IRouteCacheProvider routeCacheProvider)
|
||||
public SystemModule(IAppDirectoryInfo appDirectoryInfo, IRuntimeInfo runtimeInfo, IRouteCacheProvider routeCacheProvider)
|
||||
: base("system")
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
_runtimeInfo = runtimeInfo;
|
||||
_routeCacheProvider = routeCacheProvider;
|
||||
Get["/status"] = x => GetStatus();
|
||||
Get["/routes"] = x => GetRoutes();
|
||||
@ -24,17 +26,17 @@ private Response GetStatus()
|
||||
{
|
||||
return new
|
||||
{
|
||||
Version = _environmentProvider.Version.ToString(),
|
||||
AppData = _environmentProvider.GetAppDataPath(),
|
||||
IsAdmin = _environmentProvider.IsAdmin,
|
||||
IsUserInteractive = _environmentProvider.IsUserInteractive,
|
||||
BuildTime = _environmentProvider.BuildDateTime,
|
||||
StartupPath = _environmentProvider.StartUpPath,
|
||||
OsVersion = _environmentProvider.GetOsVersion().ToString(),
|
||||
IsMono = EnvironmentProvider.IsMono,
|
||||
IsProduction = EnvironmentProvider.IsProduction,
|
||||
IsDebug = EnvironmentProvider.IsDebug,
|
||||
IsLinux = EnvironmentProvider.IsLinux,
|
||||
Version = BuildInfo.Version.ToString(),
|
||||
BuildTime = BuildInfo.BuildDateTime,
|
||||
IsDebug = BuildInfo.IsDebug,
|
||||
IsProduction = RuntimeInfo.IsProduction,
|
||||
IsAdmin = _runtimeInfo.IsAdmin,
|
||||
IsUserInteractive = _runtimeInfo.IsUserInteractive,
|
||||
StartupPath = _appDirectoryInfo.StartUpPath,
|
||||
AppData = _appDirectoryInfo.GetAppDataPath(),
|
||||
OsVersion = OsInfo.Version.ToString(),
|
||||
IsMono = OsInfo.IsMono,
|
||||
IsLinux = OsInfo.IsLinux,
|
||||
}.AsResponse();
|
||||
|
||||
}
|
||||
|
@ -8,17 +8,17 @@ namespace NzbDrone.Api.Update
|
||||
{
|
||||
public class UpdateModule : NzbDroneRestModule<UpdateResource>
|
||||
{
|
||||
private readonly IUpdateService _updateService;
|
||||
private readonly ICheckUpdateService _checkUpdateService;
|
||||
|
||||
public UpdateModule(IUpdateService updateService)
|
||||
public UpdateModule(ICheckUpdateService checkUpdateService)
|
||||
{
|
||||
_updateService = updateService;
|
||||
_checkUpdateService = checkUpdateService;
|
||||
GetResourceAll = GetAvailableUpdate;
|
||||
}
|
||||
|
||||
private List<UpdateResource> GetAvailableUpdate()
|
||||
{
|
||||
var update = _updateService.AvailableUpdate();
|
||||
var update = _checkUpdateService.AvailableUpdate();
|
||||
var response = new List<UpdateResource>();
|
||||
|
||||
if (update != null)
|
||||
|
@ -3,6 +3,7 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.App.Test
|
||||
@ -48,7 +49,7 @@ public void Route_should_call_install_service_when_application_mode_is_install()
|
||||
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<IEnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
|
||||
Subject.Route(ApplicationModes.InstallService);
|
||||
|
||||
@ -61,7 +62,7 @@ public void Route_should_call_uninstall_service_when_application_mode_is_uninsta
|
||||
{
|
||||
var serviceProviderMock = Mocker.GetMock<IServiceProvider>();
|
||||
serviceProviderMock.Setup(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME));
|
||||
Mocker.GetMock<IEnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
|
||||
|
||||
Subject.Route(ApplicationModes.UninstallService);
|
||||
@ -72,7 +73,7 @@ public void Route_should_call_uninstall_service_when_application_mode_is_uninsta
|
||||
[Test]
|
||||
public void Route_should_call_console_service_when_application_mode_is_console()
|
||||
{
|
||||
Mocker.GetMock<IEnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
Mocker.GetMock<IConsoleService>().SetupGet(c => c.IsConsoleApplication).Returns(true);
|
||||
|
||||
Subject.Route(ApplicationModes.Console);
|
||||
@ -87,7 +88,7 @@ public void Route_should_call_console_service_when_application_mode_is_console()
|
||||
[TestCase(ApplicationModes.Help)]
|
||||
public void Route_should_call_service_start_when_run_in_service_more(ApplicationModes applicationModes)
|
||||
{
|
||||
var envMock = Mocker.GetMock<IEnvironmentProvider>();
|
||||
var envMock = Mocker.GetMock<IRuntimeInfo>();
|
||||
var serviceProvider = Mocker.GetMock<IServiceProvider>();
|
||||
|
||||
envMock.SetupGet(c => c.IsUserInteractive).Returns(false);
|
||||
@ -105,7 +106,7 @@ public void show_error_on_install_if_service_already_exist()
|
||||
{
|
||||
var consoleMock = Mocker.GetMock<IConsoleService>();
|
||||
var serviceMock = Mocker.GetMock<IServiceProvider>();
|
||||
Mocker.GetMock<IEnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
|
||||
consoleMock.Setup(c => c.PrintServiceAlreadyExist());
|
||||
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
|
||||
@ -120,7 +121,7 @@ public void show_error_on_uninstall_if_service_doesnt_exist()
|
||||
{
|
||||
var consoleMock = Mocker.GetMock<IConsoleService>();
|
||||
var serviceMock = Mocker.GetMock<IServiceProvider>();
|
||||
Mocker.GetMock<IEnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
|
||||
consoleMock.Setup(c => c.PrintServiceDoestExist());
|
||||
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Model;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Test.Common;
|
||||
@ -17,7 +18,7 @@ public void SetUp()
|
||||
WithTempAsAppPath();
|
||||
|
||||
//Reset config file
|
||||
var configFile = Mocker.Resolve<IEnvironmentProvider>().GetConfigPath();
|
||||
var configFile = Mocker.Resolve<IAppDirectoryInfo>().GetConfigPath();
|
||||
|
||||
if (File.Exists(configFile))
|
||||
File.Delete(configFile);
|
||||
|
@ -3,6 +3,7 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
@ -165,7 +166,7 @@ public void empty_folder_should_return_folder_modified_date()
|
||||
[Test]
|
||||
public void folder_should_return_correct_value_for_last_write()
|
||||
{
|
||||
var appPath = new EnvironmentProvider().WorkingDirectory;
|
||||
var appPath = new AppDirectoryInfo().WorkingDirectory;
|
||||
|
||||
TestLogger.Info("Path is: {0}", appPath);
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class EnvironmentProviderTest : TestBase<EnvironmentProvider>
|
||||
public class IAppDirectoryInfoTest : TestBase<AppDirectoryInfo>
|
||||
{
|
||||
|
||||
[Test]
|
||||
@ -30,15 +30,7 @@ public void ApplicationPath_should_not_be_empty()
|
||||
[Test]
|
||||
public void IsProduction_should_return_false_when_run_within_nunit()
|
||||
{
|
||||
EnvironmentProvider.IsProduction.Should().BeFalse();
|
||||
RuntimeInfo.IsProduction.Should().BeFalse();
|
||||
}
|
||||
|
||||
[TestCase("0.0.0.0")]
|
||||
[TestCase("1.0.0.0")]
|
||||
public void Application_version_should_not_be_default(string version)
|
||||
{
|
||||
Subject.Version.Should().NotBe(new Version(version));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test.EnvironmentTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class BuildInfoTest : TestBase
|
||||
{
|
||||
|
||||
[TestCase("0.0.0.0")]
|
||||
[TestCase("1.0.0.0")]
|
||||
public void Application_version_should_not_be_default(string version)
|
||||
{
|
||||
BuildInfo.Version.Should().NotBe(new Version(version));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -82,6 +82,7 @@
|
||||
<Compile Include="CacheTests\CachedFixture.cs" />
|
||||
<Compile Include="ConfigFileProviderTest.cs" />
|
||||
<Compile Include="EnsureTest\PathExtensionFixture.cs" />
|
||||
<Compile Include="EnvironmentTests\EnviromentProviderTest.cs" />
|
||||
<Compile Include="EventingTests\MessageAggregatorCommandTests.cs" />
|
||||
<Compile Include="EventingTests\MessageAggregatorEventTests.cs" />
|
||||
<Compile Include="ReflectionExtensions.cs" />
|
||||
@ -123,6 +124,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="EnviromentTests\" />
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
@ -2,6 +2,7 @@
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.Categories;
|
||||
|
||||
@ -11,9 +12,9 @@ namespace NzbDrone.Common.Test
|
||||
public class PathExtensionFixture : TestBase
|
||||
{
|
||||
|
||||
private EnvironmentProvider GetEnvironmentProvider()
|
||||
private IAppDirectoryInfo GetIAppDirectoryInfo()
|
||||
{
|
||||
var fakeEnvironment = new Mock<EnvironmentProvider>();
|
||||
var fakeEnvironment = new Mock<IAppDirectoryInfo>();
|
||||
|
||||
fakeEnvironment.SetupGet(c => c.WorkingDirectory).Returns(@"C:\NzbDrone\");
|
||||
|
||||
@ -73,44 +74,44 @@ public void normalize_path_exception_null()
|
||||
[Test]
|
||||
public void AppDataDirectory_path_test()
|
||||
{
|
||||
GetEnvironmentProvider().GetAppDataPath().Should().BeEquivalentTo(@"C:\NzbDrone\");
|
||||
GetIAppDirectoryInfo().GetAppDataPath().Should().BeEquivalentTo(@"C:\NzbDrone\");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Config_path_test()
|
||||
{
|
||||
GetEnvironmentProvider().GetConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\Config.xml");
|
||||
GetIAppDirectoryInfo().GetConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\Config.xml");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Sanbox()
|
||||
{
|
||||
GetEnvironmentProvider().GetUpdateSandboxFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\");
|
||||
GetIAppDirectoryInfo().GetUpdateSandboxFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUpdatePackageFolder()
|
||||
{
|
||||
GetEnvironmentProvider().GetUpdatePackageFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\");
|
||||
GetIAppDirectoryInfo().GetUpdatePackageFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUpdateClientFolder()
|
||||
{
|
||||
GetEnvironmentProvider().GetUpdateClientFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\NzbDrone.Update\");
|
||||
GetIAppDirectoryInfo().GetUpdateClientFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\NzbDrone.Update\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUpdateClientExePath()
|
||||
{
|
||||
GetEnvironmentProvider().GetUpdateClientExePath().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone.Update.exe");
|
||||
GetIAppDirectoryInfo().GetUpdateClientExePath().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone.Update.exe");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUpdateLogFolder()
|
||||
{
|
||||
GetEnvironmentProvider().GetUpdateLogFolder().Should().BeEquivalentTo(@"C:\NzbDrone\UpdateLogs\");
|
||||
GetIAppDirectoryInfo().GetUpdateLogFolder().Should().BeEquivalentTo(@"C:\NzbDrone\UpdateLogs\");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Common.EnsureThat.Resources;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common.EnsureThat
|
||||
{
|
||||
@ -105,7 +106,7 @@ public static Param<string> IsValidPath(this Param<string> param)
|
||||
if (string.IsNullOrWhiteSpace(param.Value))
|
||||
throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotNullOrWhiteSpace);
|
||||
|
||||
if (EnvironmentProvider.IsLinux)
|
||||
if (OsInfo.IsLinux)
|
||||
{
|
||||
if (!param.Value.StartsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
|
38
NzbDrone.Common/EnvironmentInfo/AppDirectoryInfo.cs
Normal file
38
NzbDrone.Common/EnvironmentInfo/AppDirectoryInfo.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace NzbDrone.Common.EnvironmentInfo
|
||||
{
|
||||
public interface IAppDirectoryInfo
|
||||
{
|
||||
string WorkingDirectory { get; }
|
||||
string SystemTemp { get; }
|
||||
string StartUpPath { get; }
|
||||
}
|
||||
|
||||
public class AppDirectoryInfo : IAppDirectoryInfo
|
||||
{
|
||||
public string WorkingDirectory
|
||||
{
|
||||
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create), "NzbDrone"); }
|
||||
}
|
||||
|
||||
public string StartUpPath
|
||||
{
|
||||
get
|
||||
{
|
||||
var path = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName;
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
public String SystemTemp
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.GetTempPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
35
NzbDrone.Common/EnvironmentInfo/BuildInfo.cs
Normal file
35
NzbDrone.Common/EnvironmentInfo/BuildInfo.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace NzbDrone.Common.EnvironmentInfo
|
||||
{
|
||||
public static class BuildInfo
|
||||
{
|
||||
public static Version Version
|
||||
{
|
||||
get { return Assembly.GetExecutingAssembly().GetName().Version; }
|
||||
}
|
||||
|
||||
public static DateTime BuildDateTime
|
||||
{
|
||||
get
|
||||
{
|
||||
var fileLocation = Assembly.GetCallingAssembly().Location;
|
||||
return new FileInfo(fileLocation).LastWriteTimeUtc;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsDebug
|
||||
{
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
NzbDrone.Common/EnvironmentInfo/OsInfo.cs
Normal file
36
NzbDrone.Common/EnvironmentInfo/OsInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace NzbDrone.Common.EnvironmentInfo
|
||||
{
|
||||
public static class OsInfo
|
||||
{
|
||||
|
||||
public static Version Version
|
||||
{
|
||||
get
|
||||
{
|
||||
OperatingSystem os = Environment.OSVersion;
|
||||
Version version = os.Version;
|
||||
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsMono
|
||||
{
|
||||
get
|
||||
{
|
||||
return Type.GetType("Mono.Runtime") != null;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsLinux
|
||||
{
|
||||
get
|
||||
{
|
||||
int p = (int)Environment.OSVersion.Platform;
|
||||
return (p == 4) || (p == 6) || (p == 128);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
65
NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs
Normal file
65
NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Principal;
|
||||
using NLog;
|
||||
|
||||
namespace NzbDrone.Common.EnvironmentInfo
|
||||
{
|
||||
|
||||
public interface IRuntimeInfo
|
||||
{
|
||||
bool IsUserInteractive { get; }
|
||||
bool IsAdmin { get; }
|
||||
}
|
||||
|
||||
public class RuntimeInfo : IRuntimeInfo
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public RuntimeInfo(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public bool IsUserInteractive
|
||||
{
|
||||
get { return Environment.UserInteractive; }
|
||||
}
|
||||
|
||||
public bool IsAdmin
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
|
||||
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.WarnException("Error checking if the current user is an administrator.", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly string ProcessName = Process.GetCurrentProcess().ProcessName.ToLower();
|
||||
|
||||
public static bool IsProduction
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BuildInfo.IsDebug || Debugger.IsAttached) return false;
|
||||
if (BuildInfo.Version.Revision > 10000) return false; //Official builds will never have such a high revision
|
||||
|
||||
var lowerProcessName = ProcessName.ToLower();
|
||||
if (lowerProcessName.Contains("vshost")) return false;
|
||||
if (lowerProcessName.Contains("nunit")) return false;
|
||||
if (lowerProcessName.Contains("jetbrain")) return false;
|
||||
if (lowerProcessName.Contains("resharper")) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
@ -25,14 +26,12 @@ public class HttpProvider : IHttpProvider
|
||||
|
||||
public const string ContentLenghtHeader = "Content-Length";
|
||||
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly string _userAgent;
|
||||
|
||||
public HttpProvider(IEnvironmentProvider environmentProvider)
|
||||
public HttpProvider()
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_userAgent = String.Format("NzbDrone {0}", _environmentProvider.Version);
|
||||
_userAgent = String.Format("NzbDrone {0}", BuildInfo.Version);
|
||||
}
|
||||
|
||||
public string DownloadString(string address)
|
||||
|
@ -5,6 +5,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
@ -285,7 +286,7 @@ public virtual long GetAvilableSpace(string path)
|
||||
|
||||
if (driveInfo == null)
|
||||
{
|
||||
if (EnvironmentProvider.IsLinux)
|
||||
if (OsInfo.IsLinux)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,149 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.Principal;
|
||||
using NLog;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public interface IEnvironmentProvider
|
||||
{
|
||||
bool IsUserInteractive { get; }
|
||||
bool IsAdmin { get; }
|
||||
string WorkingDirectory { get; }
|
||||
string SystemTemp { get; }
|
||||
Version Version { get; }
|
||||
DateTime BuildDateTime { get; }
|
||||
string StartUpPath { get; }
|
||||
Version GetOsVersion();
|
||||
}
|
||||
|
||||
public class EnvironmentProvider : IEnvironmentProvider
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
private static readonly string ProcessName = Process.GetCurrentProcess().ProcessName.ToLower();
|
||||
|
||||
private static readonly IEnvironmentProvider Instance = new EnvironmentProvider();
|
||||
|
||||
|
||||
public EnvironmentProvider()
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
|
||||
public static bool IsProduction
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDebug || Debugger.IsAttached) return false;
|
||||
if (Instance.Version.Revision > 10000) return false; //Official builds will never have such a high revision
|
||||
|
||||
var lowerProcessName = ProcessName.ToLower();
|
||||
if (lowerProcessName.Contains("vshost")) return false;
|
||||
if (lowerProcessName.Contains("nunit")) return false;
|
||||
if (lowerProcessName.Contains("jetbrain")) return false;
|
||||
if (lowerProcessName.Contains("resharper")) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsMono
|
||||
{
|
||||
get
|
||||
{
|
||||
return Type.GetType("Mono.Runtime") != null;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsLinux
|
||||
{
|
||||
get
|
||||
{
|
||||
int p = (int)Environment.OSVersion.Platform;
|
||||
return (p == 4) || (p == 6) || (p == 128);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsDebug
|
||||
{
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static Guid UGuid { get; set; }
|
||||
|
||||
public virtual bool IsUserInteractive
|
||||
{
|
||||
get { return Environment.UserInteractive; }
|
||||
}
|
||||
|
||||
public bool IsAdmin
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
|
||||
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.WarnException("Error checking if the current user is an administrator.", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string WorkingDirectory
|
||||
{
|
||||
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NzbDrone"); }
|
||||
}
|
||||
|
||||
public virtual string StartUpPath
|
||||
{
|
||||
get
|
||||
{
|
||||
var path = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName;
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual String SystemTemp
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.GetTempPath();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Version Version
|
||||
{
|
||||
get { return Assembly.GetExecutingAssembly().GetName().Version; }
|
||||
}
|
||||
|
||||
public virtual DateTime BuildDateTime
|
||||
{
|
||||
get
|
||||
{
|
||||
var fileLocation = Assembly.GetCallingAssembly().Location;
|
||||
return new FileInfo(fileLocation).LastWriteTimeUtc;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Version GetOsVersion()
|
||||
{
|
||||
OperatingSystem os = Environment.OSVersion;
|
||||
Version version = os.Version;
|
||||
|
||||
return version;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.LayoutRenderers;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation
|
||||
{
|
||||
@ -14,7 +15,7 @@ public class ApplicationLogLayoutRenderer : LayoutRenderer
|
||||
|
||||
public ApplicationLogLayoutRenderer()
|
||||
{
|
||||
_appData = Path.Combine(new EnvironmentProvider().GetLogFolder(), "nzbdrone.txt");
|
||||
_appData = Path.Combine(new AppDirectoryInfo().GetLogFolder(), "nzbdrone.txt");
|
||||
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
using NLog.Config;
|
||||
using NLog.Layouts;
|
||||
using NLog.Targets;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation
|
||||
{
|
||||
@ -43,12 +44,12 @@ protected override void InitializeTarget()
|
||||
IncludeMachineName = true,
|
||||
};
|
||||
|
||||
if (EnvironmentProvider.IsProduction)
|
||||
if (RuntimeInfo.IsProduction)
|
||||
{
|
||||
config.ApiKey = "cc4728a35aa9414f9a0baa8eed56bc67";
|
||||
}
|
||||
|
||||
ExceptronClient = new ExceptronClient(config, new EnvironmentProvider().Version);
|
||||
ExceptronClient = new ExceptronClient(config, BuildInfo.Version);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
using NLog.Config;
|
||||
using NLog.Layouts;
|
||||
using NLog.Targets;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using Logger = Loggly.Logger;
|
||||
|
||||
@ -10,7 +11,7 @@ namespace NzbDrone.Common.Instrumentation
|
||||
{
|
||||
public class LogglyTarget : TargetWithLayout
|
||||
{
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
private Logger _logger;
|
||||
|
||||
public void Register(LogLevel minLevel)
|
||||
@ -25,16 +26,16 @@ public void Register(LogLevel minLevel)
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
|
||||
public LogglyTarget(IEnvironmentProvider environmentProvider)
|
||||
public LogglyTarget(IAppDirectoryInfo appDirectoryInfo)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
}
|
||||
|
||||
protected override void InitializeTarget()
|
||||
{
|
||||
string apiKey = string.Empty;
|
||||
|
||||
if (EnvironmentProvider.IsProduction)
|
||||
if (RuntimeInfo.IsProduction)
|
||||
{
|
||||
apiKey = "4c4ecb69-d1b9-4e2a-b54b-b0c4cc143a95";
|
||||
}
|
||||
@ -67,7 +68,7 @@ protected override void Write(NLog.LogEventInfo logEvent)
|
||||
dictionary.Add("method", Layout.Render(logEvent));
|
||||
dictionary.Add("level", logEvent.Level.Name);
|
||||
dictionary.Add("message", logEvent.GetFormattedMessage());
|
||||
dictionary.Add("ver", _environmentProvider.Version.ToString());
|
||||
dictionary.Add("ver", BuildInfo.Version.ToString());
|
||||
|
||||
_logger.Log(dictionary.ToJson());
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.LayoutRenderers;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation
|
||||
{
|
||||
@ -15,7 +16,7 @@ public class UpdateLogLayoutRenderer : LayoutRenderer
|
||||
|
||||
public UpdateLogLayoutRenderer()
|
||||
{
|
||||
_appData = Path.Combine(new EnvironmentProvider().GetUpdateLogFolder(), DateTime.Now.ToString("yy.MM.d-HH.mm") + ".txt");
|
||||
_appData = Path.Combine(new AppDirectoryInfo().GetUpdateLogFolder(), DateTime.Now.ToString("yy.MM.d-HH.mm") + ".txt");
|
||||
|
||||
}
|
||||
|
||||
|
@ -103,6 +103,9 @@
|
||||
<Compile Include="EnsureThat\ExpressionExtensions.cs" />
|
||||
<Compile Include="EnsureThat\Param.cs" />
|
||||
<Compile Include="EnsureThat\Resources\ExceptionMessages.Designer.cs" />
|
||||
<Compile Include="EnvironmentInfo\BuildInfo.cs" />
|
||||
<Compile Include="EnvironmentInfo\RuntimeInfo.cs" />
|
||||
<Compile Include="EnvironmentInfo\OsInfo.cs" />
|
||||
<Compile Include="Instrumentation\GlobalExceptionHandlers.cs" />
|
||||
<Compile Include="Instrumentation\ExceptronTarget.cs" />
|
||||
<Compile Include="Messaging\LimitedConcurrencyLevelTaskScheduler.cs" />
|
||||
@ -146,7 +149,7 @@
|
||||
<Compile Include="Model\AuthenticationType.cs" />
|
||||
<Compile Include="PathExtensions.cs" />
|
||||
<Compile Include="IDiskProvider.cs" />
|
||||
<Compile Include="IEnvironmentProvider.cs" />
|
||||
<Compile Include="EnvironmentInfo\AppDirectoryInfo.cs" />
|
||||
<Compile Include="Model\ProcessInfo.cs" />
|
||||
<Compile Include="IProcessProvider.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.IO;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
@ -55,69 +56,69 @@ public static string GetActualCasing(this string filename)
|
||||
}
|
||||
|
||||
|
||||
public static string GetAppDataPath(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetAppDataPath(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return environmentProvider.WorkingDirectory;
|
||||
return IAppDirectoryInfo.WorkingDirectory;
|
||||
}
|
||||
|
||||
public static string GetLogFolder(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetLogFolder(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), "logs");
|
||||
return Path.Combine(GetAppDataPath(IAppDirectoryInfo), "logs");
|
||||
}
|
||||
|
||||
public static string GetConfigPath(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetConfigPath(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), APP_CONFIG_FILE);
|
||||
return Path.Combine(GetAppDataPath(IAppDirectoryInfo), APP_CONFIG_FILE);
|
||||
}
|
||||
|
||||
public static string GetMediaCoverPath(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetMediaCoverPath(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), "MediaCover");
|
||||
return Path.Combine(GetAppDataPath(IAppDirectoryInfo), "MediaCover");
|
||||
}
|
||||
|
||||
public static string GetUpdateLogFolder(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetUpdateLogFolder(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), UPDATE_LOG_FOLDER_NAME);
|
||||
return Path.Combine(GetAppDataPath(IAppDirectoryInfo), UPDATE_LOG_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetUpdateSandboxFolder(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetUpdateSandboxFolder(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.SystemTemp, UPDATE_SANDBOX_FOLDER_NAME);
|
||||
return Path.Combine(IAppDirectoryInfo.SystemTemp, UPDATE_SANDBOX_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetUpdateBackUpFolder(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetUpdateBackUpFolder(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetUpdateSandboxFolder(), UPDATE_BACKUP_FOLDER_NAME);
|
||||
return Path.Combine(GetUpdateSandboxFolder(IAppDirectoryInfo), UPDATE_BACKUP_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetUpdatePackageFolder(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetUpdatePackageFolder(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetUpdateSandboxFolder(), UPDATE_PACKAGE_FOLDER_NAME);
|
||||
return Path.Combine(GetUpdateSandboxFolder(IAppDirectoryInfo), UPDATE_PACKAGE_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetUpdateClientFolder(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetUpdateClientFolder(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetUpdatePackageFolder(), UPDATE_CLIENT_FOLDER_NAME);
|
||||
return Path.Combine(GetUpdatePackageFolder(IAppDirectoryInfo), UPDATE_CLIENT_FOLDER_NAME);
|
||||
}
|
||||
|
||||
public static string GetUpdateClientExePath(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetUpdateClientExePath(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetUpdateSandboxFolder(), UPDATE_CLIENT_EXE);
|
||||
return Path.Combine(GetUpdateSandboxFolder(IAppDirectoryInfo), UPDATE_CLIENT_EXE);
|
||||
}
|
||||
|
||||
public static string GetConfigBackupFile(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetConfigBackupFile(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), BACKUP_ZIP_FILE);
|
||||
return Path.Combine(GetAppDataPath(IAppDirectoryInfo), BACKUP_ZIP_FILE);
|
||||
}
|
||||
|
||||
public static string GetNzbDroneDatabase(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetNzbDroneDatabase(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_DB);
|
||||
return Path.Combine(GetAppDataPath(IAppDirectoryInfo), NZBDRONE_DB);
|
||||
}
|
||||
|
||||
public static string GetLogDatabase(this IEnvironmentProvider environmentProvider)
|
||||
public static string GetLogDatabase(this IAppDirectoryInfo IAppDirectoryInfo)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_LOG_DB);
|
||||
return Path.Combine(GetAppDataPath(IAppDirectoryInfo), NZBDRONE_LOG_DB);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,36 +6,20 @@
|
||||
using NLog;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Common.Contract;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
|
||||
public class RestProvider
|
||||
{
|
||||
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
|
||||
|
||||
public RestProvider(IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
}
|
||||
|
||||
public RestProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private const int TIMEOUT = 15000;
|
||||
private const string METHOD = "POST";
|
||||
|
||||
public virtual void PostData(string url, ReportBase reportBase)
|
||||
{
|
||||
reportBase.UGuid = EnvironmentProvider.UGuid;
|
||||
reportBase.Version = _environmentProvider.Version.ToString();
|
||||
reportBase.IsProduction = EnvironmentProvider.IsProduction;
|
||||
reportBase.Version = BuildInfo.Version.ToString();
|
||||
reportBase.IsProduction = RuntimeInfo.IsProduction;
|
||||
|
||||
PostData(url, reportBase as object);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ protected string ReadAllText(params string[] path)
|
||||
|
||||
protected void UseRealHttp()
|
||||
{
|
||||
Mocker.SetConstant<IHttpProvider>(new HttpProvider(new EnvironmentProvider()));
|
||||
Mocker.SetConstant<IHttpProvider>(new HttpProvider());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using System.Linq;
|
||||
@ -16,9 +17,9 @@ public class MediaCoverServiceFixture : CoreTest<MediaCoverService>
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
//Mocker.SetConstant(new HttpProvider(new EnvironmentProvider()));
|
||||
//Mocker.SetConstant(new HttpProvider(new IAppDirectoryInfo()));
|
||||
//Mocker.SetConstant(new DiskProvider());
|
||||
Mocker.SetConstant<IEnvironmentProvider>(new EnvironmentProvider());
|
||||
Mocker.SetConstant(new AppDirectoryInfo());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -216,7 +216,6 @@
|
||||
<Compile Include="Qualities\QualityProfileFixture.cs" />
|
||||
<Compile Include="TvTests\SeriesServiceFixture.cs" />
|
||||
<Compile Include="UpdateTests\UpdatePackageProviderFixture.cs" />
|
||||
<Compile Include="UpdateTests\GetUpdateLogFixture.cs" />
|
||||
<Compile Include="XbmcVersionTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -87,7 +87,7 @@ public void ParseTitle_single(string postTitle, string title, int seasonNumber,
|
||||
result.EpisodeNumbers.Should().HaveCount(1);
|
||||
result.SeasonNumber.Should().Be(seasonNumber);
|
||||
result.EpisodeNumbers.First().Should().Be(episodeNumber);
|
||||
result.SeriesTitle.Should().Be(Parser.Parser.CleanSeriesTitle(title));
|
||||
result.SeriesTitle.Should().Be(title.CleanSeriesTitle());
|
||||
}
|
||||
|
||||
[TestCase(@"z:\tv shows\battlestar galactica (2003)\Season 3\S03E05 - Collaborators.mkv", 3, 5)]
|
||||
@ -161,7 +161,7 @@ public void TitleParse_multi(string postTitle, string title, int season, int[] e
|
||||
var result = Parser.Parser.ParseTitle(postTitle);
|
||||
result.SeasonNumber.Should().Be(season);
|
||||
result.EpisodeNumbers.Should().BeEquivalentTo(episodes);
|
||||
result.SeriesTitle.Should().Be(Parser.Parser.CleanSeriesTitle(title));
|
||||
result.SeriesTitle.Should().Be(title.CleanSeriesTitle());
|
||||
}
|
||||
|
||||
|
||||
@ -180,7 +180,7 @@ public void parse_daily_episodes(string postTitle, string title, int year, int m
|
||||
var result = Parser.Parser.ParseTitle(postTitle);
|
||||
var airDate = new DateTime(year, month, day);
|
||||
result.Should().NotBeNull();
|
||||
result.SeriesTitle.Should().Be(Parser.Parser.CleanSeriesTitle(title));
|
||||
result.SeriesTitle.Should().Be(title.CleanSeriesTitle());
|
||||
result.AirDate.Should().Be(airDate);
|
||||
result.EpisodeNumbers.Should().BeNull();
|
||||
}
|
||||
@ -233,7 +233,7 @@ public void full_season_release_parse(string postTitle, string title, int season
|
||||
{
|
||||
var result = Parser.Parser.ParseTitle(postTitle);
|
||||
result.SeasonNumber.Should().Be(season);
|
||||
result.SeriesTitle.Should().Be(Parser.Parser.CleanSeriesTitle(title));
|
||||
result.SeriesTitle.Should().Be(title.CleanSeriesTitle());
|
||||
result.EpisodeNumbers.Length.Should().Be(0);
|
||||
result.FullSeason.Should().BeTrue();
|
||||
}
|
||||
@ -245,7 +245,7 @@ public void full_season_release_parse(string postTitle, string title, int season
|
||||
[TestCase("Parenthood.2010", "parenthood2010")]
|
||||
public void series_name_normalize(string parsedSeriesName, string seriesName)
|
||||
{
|
||||
var result = Parser.Parser.CleanSeriesTitle(parsedSeriesName);
|
||||
var result = parsedSeriesName.CleanSeriesTitle();
|
||||
result.Should().Be(seriesName);
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ public void series_name_normalize(string parsedSeriesName, string seriesName)
|
||||
[TestCase("24", "24")]
|
||||
public void Normalize_Title(string dirty, string clean)
|
||||
{
|
||||
var result = Parser.Parser.CleanSeriesTitle(dirty);
|
||||
var result = dirty.CleanSeriesTitle();
|
||||
result.Should().Be(clean);
|
||||
}
|
||||
|
||||
@ -285,7 +285,7 @@ public void Normalize_removed_common_words(string word)
|
||||
foreach (var s in dirtyFormat)
|
||||
{
|
||||
var dirty = String.Format(s, word);
|
||||
Parser.Parser.CleanSeriesTitle(dirty).Should().Be("wordword");
|
||||
dirty.CleanSeriesTitle().Should().Be("wordword");
|
||||
}
|
||||
|
||||
}
|
||||
@ -311,7 +311,7 @@ public void Normalize_not_removed_common_words_in_the_middle(string word)
|
||||
foreach (var s in dirtyFormat)
|
||||
{
|
||||
var dirty = String.Format(s, word);
|
||||
Parser.Parser.CleanSeriesTitle(dirty).Should().Be(("word" + word.ToLower() + "word"));
|
||||
dirty.CleanSeriesTitle().Should().Be(("word" + word.ToLower() + "word"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -328,7 +328,7 @@ public void Normalize_not_removed_common_words_in_the_middle(string word)
|
||||
public void parse_series_name(string postTitle, string title)
|
||||
{
|
||||
var result = Parser.Parser.ParseSeriesName(postTitle);
|
||||
result.Should().Be(Parser.Parser.CleanSeriesTitle(title));
|
||||
result.Should().Be(title.CleanSeriesTitle());
|
||||
}
|
||||
|
||||
[TestCase("Castle.2009.S01E14.English.HDTV.XviD-LOL", Language.English)]
|
||||
@ -373,7 +373,7 @@ public void parse_season_info(string postTitle, string seriesName, int seasonNum
|
||||
{
|
||||
var result = Parser.Parser.ParseTitle(postTitle);
|
||||
|
||||
result.SeriesTitle.Should().Be(Parser.Parser.CleanSeriesTitle(seriesName));
|
||||
result.SeriesTitle.Should().Be(seriesName.CleanSeriesTitle());
|
||||
result.SeasonNumber.Should().Be(seasonNumber);
|
||||
result.FullSeason.Should().BeTrue();
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Update;
|
||||
|
||||
namespace NzbDrone.Core.Test.UpdateTests
|
||||
{
|
||||
public class GetUpdateLogFixture : CoreTest<UpdateService>
|
||||
{
|
||||
String _updateLogFolder;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
WithTempAsAppPath();
|
||||
|
||||
_updateLogFolder = Mocker.GetMock<IEnvironmentProvider>().Object.GetUpdateLogFolder();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetFiles(_updateLogFolder, SearchOption.TopDirectoryOnly))
|
||||
.Returns(new[]
|
||||
{
|
||||
"C:\\nzbdrone\\update\\2011.09.20-19-08.txt",
|
||||
"C:\\nzbdrone\\update\\2011.10.20-20-08.txt",
|
||||
"C:\\nzbdrone\\update\\2011.12.20-21-08.txt"
|
||||
});
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FolderExists(_updateLogFolder))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void get_logs_should_return_empty_list_if_directory_doesnt_exist()
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FolderExists(_updateLogFolder))
|
||||
.Returns(false);
|
||||
|
||||
Subject.GetUpdateLogFiles().Should().BeEmpty();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void get_logs_should_return_list_of_files_in_log_folder()
|
||||
{
|
||||
var logs = Subject.GetUpdateLogFiles();
|
||||
logs.Should().HaveCount(3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Update;
|
||||
@ -15,26 +16,26 @@
|
||||
namespace NzbDrone.Core.Test.UpdateTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class UpdateServiceFixture : CoreTest<UpdateService>
|
||||
public class UpdateServiceFixture : CoreTest<InstallUpdateService>
|
||||
{
|
||||
private string _sandboxFolder;
|
||||
|
||||
private readonly UpdatePackage _updatePackage = new UpdatePackage
|
||||
{
|
||||
FileName = "NzbDrone.kay.one.0.6.0.2031.zip",
|
||||
Url = "http://update.nzbdrone.com/_test/NzbDrone.zip",
|
||||
Version = new Version("0.6.0.2031")
|
||||
FileName = "NzbDrone.vnext.0.8.1.226.zip",
|
||||
Url = "http://update.nzbdrone.com/vnext/NzbDrone.vnext.0.8.1.226.zip",
|
||||
Version = new Version("0.8.1.226")
|
||||
};
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.GetMock<IEnvironmentProvider>().SetupGet(c => c.SystemTemp).Returns(TempFolder);
|
||||
Mocker.GetMock<IUpdatePackageProvider>().Setup(c => c.GetLatestUpdate()).Returns(_updatePackage);
|
||||
Mocker.GetMock<IAppDirectoryInfo>().SetupGet(c => c.SystemTemp).Returns(TempFolder);
|
||||
Mocker.GetMock<ICheckUpdateService>().Setup(c => c.AvailableUpdate()).Returns(_updatePackage);
|
||||
|
||||
Mocker.GetMock<IProcessProvider>().Setup(c => c.GetCurrentProcess()).Returns(new ProcessInfo { Id = 12 });
|
||||
|
||||
_sandboxFolder = Mocker.GetMock<IEnvironmentProvider>().Object.GetUpdateSandboxFolder();
|
||||
_sandboxFolder = Mocker.GetMock<IAppDirectoryInfo>().Object.GetUpdateSandboxFolder();
|
||||
}
|
||||
|
||||
|
||||
@ -86,7 +87,7 @@ public void Should_extract_update_package()
|
||||
[Test]
|
||||
public void Should_copy_update_client_to_root_of_sandbox()
|
||||
{
|
||||
var updateClientFolder = Mocker.GetMock<IEnvironmentProvider>().Object.GetUpdateClientFolder();
|
||||
var updateClientFolder = Mocker.GetMock<IAppDirectoryInfo>().Object.GetUpdateClientFolder();
|
||||
|
||||
Subject.Execute(new ApplicationUpdateCommand());
|
||||
|
||||
@ -109,7 +110,7 @@ public void should_start_update_client()
|
||||
[Test]
|
||||
public void when_no_updates_are_available_should_return_without_error_or_warnings()
|
||||
{
|
||||
Mocker.GetMock<IUpdatePackageProvider>().Setup(c => c.GetLatestUpdate()).Returns<UpdatePackage>(null);
|
||||
Mocker.GetMock<ICheckUpdateService>().Setup(c => c.AvailableUpdate()).Returns<UpdatePackage>(null);
|
||||
|
||||
Subject.Execute(new ApplicationUpdateCommand());
|
||||
|
||||
@ -123,7 +124,7 @@ public void Should_download_and_extract_to_temp_folder()
|
||||
{
|
||||
UseRealHttp();
|
||||
|
||||
var updateSubFolder = new DirectoryInfo(Mocker.GetMock<IEnvironmentProvider>().Object.GetUpdateSandboxFolder());
|
||||
var updateSubFolder = new DirectoryInfo(Mocker.GetMock<IAppDirectoryInfo>().Object.GetUpdateSandboxFolder());
|
||||
|
||||
updateSubFolder.Exists.Should().BeFalse();
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
using System.Xml.Linq;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Model;
|
||||
|
||||
namespace NzbDrone.Core.Configuration
|
||||
@ -24,16 +25,16 @@ public interface IConfigFileProvider
|
||||
|
||||
public class ConfigFileProvider : IConfigFileProvider
|
||||
{
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
private readonly ICached<string> _cache;
|
||||
|
||||
private readonly string _configFile;
|
||||
|
||||
public ConfigFileProvider(IEnvironmentProvider environmentProvider, ICacheManger cacheManger)
|
||||
public ConfigFileProvider(IAppDirectoryInfo appDirectoryInfo, ICacheManger cacheManger)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
_cache = cacheManger.GetCache<string>(this.GetType());
|
||||
_configFile = _environmentProvider.GetConfigPath();
|
||||
_configFile = _appDirectoryInfo.GetConfigPath();
|
||||
}
|
||||
|
||||
public Dictionary<string, object> GetConfigDictionary()
|
||||
|
@ -3,6 +3,7 @@
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Tv.Events;
|
||||
@ -21,7 +22,7 @@ public class MediaCoverService :
|
||||
|
||||
private readonly string _coverRootFolder;
|
||||
|
||||
public MediaCoverService(IHttpProvider httpProvider, IDiskProvider diskProvider, IEnvironmentProvider environmentProvider,
|
||||
public MediaCoverService(IHttpProvider httpProvider, IDiskProvider diskProvider, IAppDirectoryInfo appDirectoryInfo,
|
||||
ICoverExistsSpecification coverExistsSpecification, Logger logger)
|
||||
{
|
||||
_httpProvider = httpProvider;
|
||||
@ -29,7 +30,7 @@ public MediaCoverService(IHttpProvider httpProvider, IDiskProvider diskProvider,
|
||||
_coverExistsSpecification = coverExistsSpecification;
|
||||
_logger = logger;
|
||||
|
||||
_coverRootFolder = environmentProvider.GetMediaCoverPath();
|
||||
_coverRootFolder = appDirectoryInfo.GetMediaCoverPath();
|
||||
}
|
||||
|
||||
public void HandleAsync(SeriesUpdatedEvent message)
|
||||
|
@ -525,9 +525,10 @@
|
||||
<Compile Include="Tv\SeriesStatusType.cs" />
|
||||
<Compile Include="Tv\RefreshSeriesService.cs" />
|
||||
<Compile Include="Update\Commands\ApplicationUpdateCommand.cs" />
|
||||
<Compile Include="Update\InstallUpdateService.cs" />
|
||||
<Compile Include="Update\UpdatePackageProvider.cs" />
|
||||
<Compile Include="Update\UpdatePackage.cs" />
|
||||
<Compile Include="Update\UpdateService.cs" />
|
||||
<Compile Include="Update\UpdateCheckService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
|
||||
|
@ -1,30 +1,28 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Ionic.Zip;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Core.Providers
|
||||
{
|
||||
public class BackupProvider
|
||||
{
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public BackupProvider(IEnvironmentProvider environmentProvider)
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
|
||||
public BackupProvider(IAppDirectoryInfo appDirectoryInfo)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
}
|
||||
|
||||
public BackupProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual string CreateBackupZip()
|
||||
{
|
||||
var configFile = _environmentProvider.GetConfigPath();
|
||||
var zipFile = _environmentProvider.GetConfigBackupFile();
|
||||
var configFile = _appDirectoryInfo.GetConfigPath();
|
||||
var zipFile = _appDirectoryInfo.GetConfigBackupFile();
|
||||
|
||||
using (var zip = new ZipFile())
|
||||
{
|
||||
|
86
NzbDrone.Core/Update/InstallUpdateService.cs
Normal file
86
NzbDrone.Core/Update/InstallUpdateService.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Update.Commands;
|
||||
|
||||
namespace NzbDrone.Core.Update
|
||||
{
|
||||
public class InstallUpdateService : IExecute<ApplicationUpdateCommand>
|
||||
{
|
||||
private readonly ICheckUpdateService _checkUpdateService;
|
||||
private readonly Logger _logger;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly ArchiveProvider _archiveProvider;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
|
||||
|
||||
public InstallUpdateService(ICheckUpdateService checkUpdateService, IAppDirectoryInfo appDirectoryInfo,
|
||||
IDiskProvider diskProvider, IHttpProvider httpProvider,
|
||||
ArchiveProvider archiveProvider, IProcessProvider processProvider, Logger logger)
|
||||
{
|
||||
_checkUpdateService = checkUpdateService;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
_diskProvider = diskProvider;
|
||||
_httpProvider = httpProvider;
|
||||
_archiveProvider = archiveProvider;
|
||||
_processProvider = processProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Execute(ApplicationUpdateCommand message)
|
||||
{
|
||||
var latestAvailable = _checkUpdateService.AvailableUpdate();
|
||||
|
||||
if (latestAvailable != null)
|
||||
{
|
||||
InstallUpdate(latestAvailable);
|
||||
}
|
||||
}
|
||||
|
||||
private void InstallUpdate(UpdatePackage updatePackage)
|
||||
{
|
||||
var updateSandboxFolder = _appDirectoryInfo.GetUpdateSandboxFolder();
|
||||
|
||||
var packageDestination = Path.Combine(updateSandboxFolder, updatePackage.FileName);
|
||||
|
||||
if (_diskProvider.FolderExists(updateSandboxFolder))
|
||||
{
|
||||
_logger.Info("Deleting old update files");
|
||||
_diskProvider.DeleteFolder(updateSandboxFolder, true);
|
||||
}
|
||||
|
||||
_logger.Info("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination);
|
||||
_httpProvider.DownloadFile(updatePackage.Url, packageDestination);
|
||||
_logger.Info("Download completed for update package from [{0}]", updatePackage.FileName);
|
||||
|
||||
_logger.Info("Extracting Update package");
|
||||
_archiveProvider.ExtractArchive(packageDestination, updateSandboxFolder);
|
||||
_logger.Info("Update package extracted successfully");
|
||||
|
||||
_logger.Info("Preparing client");
|
||||
_diskProvider.MoveDirectory(_appDirectoryInfo.GetUpdateClientFolder(),
|
||||
updateSandboxFolder);
|
||||
|
||||
|
||||
_logger.Info("Starting update client");
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = _appDirectoryInfo.GetUpdateClientExePath(),
|
||||
Arguments = _processProvider.GetCurrentProcess().Id.ToString()
|
||||
};
|
||||
|
||||
var process = _processProvider.Start(startInfo);
|
||||
|
||||
_processProvider.WaitForExit(process);
|
||||
|
||||
_logger.Error("Update process failed");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
38
NzbDrone.Core/Update/UpdateCheckService.cs
Normal file
38
NzbDrone.Core/Update/UpdateCheckService.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Core.Update
|
||||
{
|
||||
public interface ICheckUpdateService
|
||||
{
|
||||
UpdatePackage AvailableUpdate();
|
||||
}
|
||||
|
||||
|
||||
public class CheckUpdateService : ICheckUpdateService
|
||||
{
|
||||
private readonly IUpdatePackageProvider _updatePackageProvider;
|
||||
|
||||
private readonly Logger _logger;
|
||||
|
||||
|
||||
public CheckUpdateService(IUpdatePackageProvider updatePackageProvider, Logger logger)
|
||||
{
|
||||
_updatePackageProvider = updatePackageProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public UpdatePackage AvailableUpdate()
|
||||
{
|
||||
var latestAvailable = _updatePackageProvider.GetLatestUpdate();
|
||||
|
||||
if (latestAvailable == null || latestAvailable.Version <= BuildInfo.Version)
|
||||
{
|
||||
_logger.Debug("No update available.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return latestAvailable;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Update.Commands;
|
||||
|
||||
namespace NzbDrone.Core.Update
|
||||
{
|
||||
public interface IUpdateService : IExecute<ApplicationUpdateCommand>
|
||||
{
|
||||
Dictionary<DateTime, string> GetUpdateLogFiles();
|
||||
UpdatePackage AvailableUpdate();
|
||||
}
|
||||
|
||||
public class UpdateService : IUpdateService
|
||||
{
|
||||
private readonly IUpdatePackageProvider _updatePackageProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly ArchiveProvider _archiveProvider;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
|
||||
public UpdateService(IUpdatePackageProvider updatePackageProvider, IEnvironmentProvider environmentProvider,
|
||||
IDiskProvider diskProvider,
|
||||
IHttpProvider httpProvider, IConfigFileProvider configFileProvider,
|
||||
ArchiveProvider archiveProvider, IProcessProvider processProvider, Logger logger)
|
||||
{
|
||||
_updatePackageProvider = updatePackageProvider;
|
||||
_environmentProvider = environmentProvider;
|
||||
_diskProvider = diskProvider;
|
||||
_httpProvider = httpProvider;
|
||||
_configFileProvider = configFileProvider;
|
||||
_archiveProvider = archiveProvider;
|
||||
_processProvider = processProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
||||
private void InstallUpdate(UpdatePackage updatePackage)
|
||||
{
|
||||
var updateSandboxFolder = _environmentProvider.GetUpdateSandboxFolder();
|
||||
|
||||
var packageDestination = Path.Combine(updateSandboxFolder, updatePackage.FileName);
|
||||
|
||||
if (_diskProvider.FolderExists(updateSandboxFolder))
|
||||
{
|
||||
_logger.Info("Deleting old update files");
|
||||
_diskProvider.DeleteFolder(updateSandboxFolder, true);
|
||||
}
|
||||
|
||||
_logger.Info("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination);
|
||||
_httpProvider.DownloadFile(updatePackage.Url, packageDestination);
|
||||
_logger.Info("Download completed for update package from [{0}]", updatePackage.FileName);
|
||||
|
||||
_logger.Info("Extracting Update package");
|
||||
_archiveProvider.ExtractArchive(packageDestination, updateSandboxFolder);
|
||||
_logger.Info("Update package extracted successfully");
|
||||
|
||||
_logger.Info("Preparing client");
|
||||
_diskProvider.MoveDirectory(_environmentProvider.GetUpdateClientFolder(),
|
||||
updateSandboxFolder);
|
||||
|
||||
|
||||
_logger.Info("Starting update client");
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = _environmentProvider.GetUpdateClientExePath(),
|
||||
Arguments = _processProvider.GetCurrentProcess().Id.ToString()
|
||||
};
|
||||
|
||||
var process = _processProvider.Start(startInfo);
|
||||
|
||||
_processProvider.WaitForExit(process);
|
||||
|
||||
_logger.Error("Update process failed");
|
||||
}
|
||||
|
||||
public Dictionary<DateTime, string> GetUpdateLogFiles()
|
||||
{
|
||||
var list = new Dictionary<DateTime, string>();
|
||||
|
||||
if (_diskProvider.FolderExists(_environmentProvider.GetUpdateLogFolder()))
|
||||
{
|
||||
var provider = CultureInfo.InvariantCulture;
|
||||
var files =
|
||||
_diskProvider.GetFiles(_environmentProvider.GetUpdateLogFolder(), SearchOption.TopDirectoryOnly)
|
||||
.ToList();
|
||||
|
||||
foreach (var file in files.Select(c => new FileInfo(c)).OrderByDescending(c => c.Name))
|
||||
{
|
||||
list.Add(
|
||||
DateTime.ParseExact(file.Name.Replace(file.Extension, string.Empty), "yyyy.MM.dd-H-mm", provider),
|
||||
file.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public UpdatePackage AvailableUpdate()
|
||||
{
|
||||
var latestAvailable = _updatePackageProvider.GetLatestUpdate();
|
||||
|
||||
if (latestAvailable == null || latestAvailable.Version <= _environmentProvider.Version)
|
||||
{
|
||||
_logger.Debug("No update available.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return latestAvailable;
|
||||
}
|
||||
|
||||
public void Execute(ApplicationUpdateCommand message)
|
||||
{
|
||||
var latestAvailable = AvailableUpdate();
|
||||
|
||||
if (latestAvailable != null)
|
||||
{
|
||||
InstallUpdate(latestAvailable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
@ -12,6 +11,7 @@
|
||||
using NzbDrone.Api.RootFolders;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Jobs;
|
||||
@ -61,19 +61,19 @@ private void InitDatabase()
|
||||
Logger.Info("Registering Database...");
|
||||
|
||||
//TODO: move this to factory
|
||||
var environmentProvider = new EnvironmentProvider();
|
||||
var appDataPath = environmentProvider.GetAppDataPath();
|
||||
var IAppDirectoryInfo = new AppDirectoryInfo();
|
||||
var appDataPath = IAppDirectoryInfo.GetAppDataPath();
|
||||
|
||||
if (!Directory.Exists(appDataPath))
|
||||
{
|
||||
Directory.CreateDirectory(appDataPath);
|
||||
}
|
||||
|
||||
var dbPath = Path.Combine(environmentProvider.WorkingDirectory, DateTime.Now.Ticks + ".db");
|
||||
var dbPath = Path.Combine(IAppDirectoryInfo.WorkingDirectory, DateTime.Now.Ticks + ".db");
|
||||
|
||||
|
||||
Logger.Info("Working Folder: {0}", environmentProvider.WorkingDirectory);
|
||||
Logger.Info("Data Folder: {0}", environmentProvider.GetAppDataPath());
|
||||
Logger.Info("Working Folder: {0}", IAppDirectoryInfo.WorkingDirectory);
|
||||
Logger.Info("Data Folder: {0}", IAppDirectoryInfo.GetAppDataPath());
|
||||
Logger.Info("DB Na: {0}", dbPath);
|
||||
|
||||
|
||||
@ -95,27 +95,31 @@ public void SmokeTestSetup()
|
||||
_bootstrapper = new NancyBootstrapper(Container.TinyContainer);
|
||||
|
||||
|
||||
var _hostConfig = new Mock<IConfigFileProvider>();
|
||||
_hostConfig.SetupGet(c => c.Port).Returns(1313);
|
||||
var hostConfig = new Mock<IConfigFileProvider>();
|
||||
hostConfig.SetupGet(c => c.Port).Returns(1313);
|
||||
|
||||
_hostController = new OwinHostController(_hostConfig.Object, new[] { new NancyMiddleWare(_bootstrapper) }, Logger);
|
||||
_hostController = new OwinHostController(hostConfig.Object, new[] { new NancyMiddleWare(_bootstrapper) }, Logger);
|
||||
|
||||
|
||||
InitRestClients();
|
||||
|
||||
_hostController.StartServer();
|
||||
}
|
||||
|
||||
private void InitRestClients()
|
||||
{
|
||||
RestClient = new RestClient(_hostController.AppUrl + "/api/");
|
||||
Series = new SeriesClient(RestClient);
|
||||
Releases = new ReleaseClient(RestClient);
|
||||
RootFolders = new ClientBase<RootFolderResource>(RestClient);
|
||||
Commands = new ClientBase<CommandResource>(RestClient);
|
||||
Indexers = new IndexerClient(RestClient);
|
||||
|
||||
_hostController.StartServer();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void SmokeTestTearDown()
|
||||
{
|
||||
_hostController.StopServer();
|
||||
|
||||
_bootstrapper.Shutdown();
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,8 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Test.Common
|
||||
@ -74,6 +74,8 @@ private string VirtualPath
|
||||
[SetUp]
|
||||
public void TestBaseSetup()
|
||||
{
|
||||
WithTempAsAppPath();
|
||||
|
||||
GetType().IsPublic.Should().BeTrue("All Test fixtures should be public to work in mono.");
|
||||
|
||||
Mocker.SetConstant<ICacheManger>(new CacheManger());
|
||||
@ -110,7 +112,7 @@ public void TestBaseTearDown()
|
||||
{
|
||||
var testName = TestContext.CurrentContext.Test.Name.ToLower();
|
||||
|
||||
if (EnvironmentProvider.IsLinux && testName.Contains("windows"))
|
||||
if (IAppDirectoryInfo.IsLinux && testName.Contains("windows"))
|
||||
{
|
||||
throw new IgnoreException("windows specific test");
|
||||
}
|
||||
@ -123,7 +125,7 @@ public void TestBaseTearDown()
|
||||
|
||||
protected void WindowsOnly()
|
||||
{
|
||||
if (EnvironmentProvider.IsLinux)
|
||||
if (OsInfo.IsLinux)
|
||||
{
|
||||
throw new IgnoreException("windows specific test");
|
||||
}
|
||||
@ -132,7 +134,7 @@ protected void WindowsOnly()
|
||||
|
||||
protected void LinuxOnly()
|
||||
{
|
||||
if (!EnvironmentProvider.IsLinux)
|
||||
if (!OsInfo.IsLinux)
|
||||
{
|
||||
throw new IgnoreException("linux specific test");
|
||||
}
|
||||
@ -140,7 +142,7 @@ protected void LinuxOnly()
|
||||
|
||||
protected void WithTempAsAppPath()
|
||||
{
|
||||
Mocker.GetMock<IEnvironmentProvider>()
|
||||
Mocker.GetMock<IAppDirectoryInfo>()
|
||||
.SetupGet(c => c.WorkingDirectory)
|
||||
.Returns(VirtualPath);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Update.UpdateEngine;
|
||||
|
||||
@ -14,7 +15,7 @@ public class InstallUpdateServiceFixture : TestBase<InstallUpdateService>
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.GetMock<IEnvironmentProvider>()
|
||||
Mocker.GetMock<IAppDirectoryInfo>()
|
||||
.Setup(c => c.SystemTemp).Returns(@"C:\Temp\");
|
||||
}
|
||||
|
||||
|
@ -19,16 +19,16 @@ public class UpdateProviderStartFixture : TestBase
|
||||
private const string BACKUP_FOLDER = @"C:\Temp\nzbdrone_update\nzbdrone_backup\";
|
||||
private const string TARGET_FOLDER = @"C:\NzbDrone\";
|
||||
|
||||
Mock<IEnvironmentProvider> _environmentProvider;
|
||||
Mock<IIAppDirectoryInfo> _IAppDirectoryInfo;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
|
||||
_environmentProvider = Mocker.GetMock<IEnvironmentProvider>();
|
||||
_IAppDirectoryInfo = Mocker.GetMock<IIAppDirectoryInfo>();
|
||||
|
||||
_environmentProvider.SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\");
|
||||
_IAppDirectoryInfo.SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\");
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FolderExists(UPDATE_FOLDER))
|
||||
|
@ -3,6 +3,7 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Instrumentation;
|
||||
using NzbDrone.Update.UpdateEngine;
|
||||
|
||||
@ -29,10 +30,10 @@ public static void Main(string[] args)
|
||||
Console.WriteLine("Starting NzbDrone Update Client");
|
||||
GlobalExceptionHandlers.Register();
|
||||
|
||||
new LogglyTarget(new EnvironmentProvider()).Register(LogLevel.Debug);
|
||||
new LogglyTarget(new AppDirectoryInfo()).Register(LogLevel.Debug);
|
||||
_container = UpdateContainerBuilder.Build();
|
||||
|
||||
logger.Info("Updating NzbDrone to version {0}", _container.Resolve<IEnvironmentProvider>().Version);
|
||||
logger.Info("Updating NzbDrone to version {0}", BuildInfo.Version);
|
||||
_container.Resolve<Program>().Start(args);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -1,5 +1,6 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Update.UpdateEngine
|
||||
{
|
||||
@ -12,27 +13,27 @@ public interface IBackupAndRestore
|
||||
public class BackupAndRestore : IBackupAndRestore
|
||||
{
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public BackupAndRestore(IDiskProvider diskProvider, IEnvironmentProvider environmentProvider, Logger logger)
|
||||
public BackupAndRestore(IDiskProvider diskProvider, IAppDirectoryInfo appDirectoryInfo, Logger logger)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void BackUp(string source)
|
||||
{
|
||||
_logger.Info("Creating backup of existing installation");
|
||||
_diskProvider.CopyDirectory(source, _environmentProvider.GetUpdateBackUpFolder());
|
||||
_diskProvider.CopyDirectory(source, _appDirectoryInfo.GetUpdateBackUpFolder());
|
||||
}
|
||||
|
||||
public void Restore(string target)
|
||||
{
|
||||
//TODO:this should ignore single file failures.
|
||||
_logger.Info("Attempting to rollback upgrade");
|
||||
_diskProvider.CopyDirectory(_environmentProvider.GetUpdateBackUpFolder(), target);
|
||||
_diskProvider.CopyDirectory(_appDirectoryInfo.GetUpdateBackUpFolder(), target);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Update.UpdateEngine
|
||||
{
|
||||
@ -15,18 +16,18 @@ public class InstallUpdateService : IInstallUpdateService
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IDetectApplicationType _detectApplicationType;
|
||||
private readonly ITerminateNzbDrone _terminateNzbDrone;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IAppDirectoryInfo _appDirectoryInfo;
|
||||
private readonly IBackupAndRestore _backupAndRestore;
|
||||
private readonly IStartNzbDrone _startNzbDrone;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public InstallUpdateService(IDiskProvider diskProvider, IDetectApplicationType detectApplicationType, ITerminateNzbDrone terminateNzbDrone,
|
||||
IProcessProvider processProvider, IEnvironmentProvider environmentProvider, IBackupAndRestore backupAndRestore, IStartNzbDrone startNzbDrone, Logger logger)
|
||||
IAppDirectoryInfo appDirectoryInfo, IBackupAndRestore backupAndRestore, IStartNzbDrone startNzbDrone, Logger logger)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_detectApplicationType = detectApplicationType;
|
||||
_terminateNzbDrone = terminateNzbDrone;
|
||||
_environmentProvider = environmentProvider;
|
||||
_appDirectoryInfo = appDirectoryInfo;
|
||||
_backupAndRestore = backupAndRestore;
|
||||
_startNzbDrone = startNzbDrone;
|
||||
_logger = logger;
|
||||
@ -43,8 +44,8 @@ private void Verify(string targetFolder)
|
||||
throw new DirectoryNotFoundException("Target folder doesn't exist " + targetFolder);
|
||||
|
||||
_logger.Info("Verifying Update Folder");
|
||||
if (!_diskProvider.FolderExists(_environmentProvider.GetUpdatePackageFolder()))
|
||||
throw new DirectoryNotFoundException("Update folder doesn't exist " + _environmentProvider.GetUpdatePackageFolder());
|
||||
if (!_diskProvider.FolderExists(_appDirectoryInfo.GetUpdatePackageFolder()))
|
||||
throw new DirectoryNotFoundException("Update folder doesn't exist " + _appDirectoryInfo.GetUpdatePackageFolder());
|
||||
}
|
||||
|
||||
public void Start(string installationFolder)
|
||||
@ -63,7 +64,7 @@ public void Start(string installationFolder)
|
||||
|
||||
try
|
||||
{
|
||||
_diskProvider.CopyDirectory(_environmentProvider.GetUpdatePackageFolder(), installationFolder);
|
||||
_diskProvider.CopyDirectory(_appDirectoryInfo.GetUpdatePackageFolder(), installationFolder);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -4,6 +4,7 @@
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertIfStatementToReturnStatement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertNullableToShortForm/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=FunctionRecursiveOnAllPaths/@EntryIndexedValue">ERROR</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InvokeAsExtensionMethod/@EntryIndexedValue">ERROR</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=NUnit_002ENonPublicMethodWithTestAttribute/@EntryIndexedValue">ERROR</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReturnTypeCanBeEnumerable_002EGlobal/@EntryIndexedValue">HINT</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseObjectOrCollectionInitializer/@EntryIndexedValue">HINT</s:String>
|
||||
|
@ -3,6 +3,7 @@
|
||||
using System.Reflection;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Instrumentation;
|
||||
|
||||
namespace NzbDrone
|
||||
@ -18,7 +19,7 @@ public static void Main(string[] args)
|
||||
{
|
||||
GlobalExceptionHandlers.Register();
|
||||
|
||||
new LogglyTarget(new EnvironmentProvider()).Register(LogLevel.Warn);
|
||||
new LogglyTarget(new AppDirectoryInfo()).Register(LogLevel.Warn);
|
||||
|
||||
|
||||
logger.Info("Starting NzbDrone Console. Version {0}", Assembly.GetExecutingAssembly().GetName().Version);
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.ServiceProcess;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Host;
|
||||
using NzbDrone.Owin;
|
||||
@ -17,7 +18,7 @@ public interface INzbDroneServiceFactory
|
||||
public class NzbDroneServiceFactory : ServiceBase, INzbDroneServiceFactory
|
||||
{
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IRuntimeInfo _runtimeInfo;
|
||||
private readonly IHostController _hostController;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly PriorityMonitor _priorityMonitor;
|
||||
@ -25,14 +26,13 @@ public class NzbDroneServiceFactory : ServiceBase, INzbDroneServiceFactory
|
||||
private readonly IUrlAclAdapter _urlAclAdapter;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider, IHostController hostController,
|
||||
IEnvironmentProvider environmentProvider,
|
||||
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider, IHostController hostController, IRuntimeInfo runtimeInfo,
|
||||
IProcessProvider processProvider, PriorityMonitor priorityMonitor,
|
||||
IFirewallAdapter firewallAdapter, IUrlAclAdapter urlAclAdapter, Logger logger)
|
||||
{
|
||||
_configFileProvider = configFileProvider;
|
||||
_hostController = hostController;
|
||||
_environmentProvider = environmentProvider;
|
||||
_runtimeInfo = runtimeInfo;
|
||||
_processProvider = processProvider;
|
||||
_priorityMonitor = priorityMonitor;
|
||||
_firewallAdapter = firewallAdapter;
|
||||
@ -47,7 +47,7 @@ protected override void OnStart(string[] args)
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (_environmentProvider.IsAdmin)
|
||||
if (_runtimeInfo.IsAdmin)
|
||||
{
|
||||
_urlAclAdapter.RefreshRegistration();
|
||||
_firewallAdapter.MakeAccessible();
|
||||
@ -55,7 +55,7 @@ public void Start()
|
||||
}
|
||||
_hostController.StartServer();
|
||||
|
||||
if (_environmentProvider.IsUserInteractive && _configFileProvider.LaunchBrowser)
|
||||
if (_runtimeInfo.IsUserInteractive && _configFileProvider.LaunchBrowser)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Host
|
||||
@ -15,20 +16,18 @@ public class UrlAclAdapter : IUrlAclAdapter
|
||||
{
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public UrlAclAdapter(IProcessProvider processProvider, IConfigFileProvider configFileProvider, IEnvironmentProvider environmentProvider, Logger logger)
|
||||
public UrlAclAdapter(IProcessProvider processProvider, IConfigFileProvider configFileProvider, Logger logger)
|
||||
{
|
||||
_processProvider = processProvider;
|
||||
_configFileProvider = configFileProvider;
|
||||
_environmentProvider = environmentProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void RefreshRegistration()
|
||||
{
|
||||
if (_environmentProvider.GetOsVersion().Major < 6)
|
||||
if (OsInfo.Version.Major < 6)
|
||||
return;
|
||||
|
||||
RegisterUrl(_configFileProvider.Port);
|
||||
|
@ -5,6 +5,7 @@
|
||||
using NzbDrone.Api.SignalR;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Instrumentation;
|
||||
@ -41,19 +42,19 @@ private void InitDatabase()
|
||||
Logger.Info("Registering Database...");
|
||||
|
||||
//TODO: move this to factory
|
||||
var environmentProvider = new EnvironmentProvider();
|
||||
var appDataPath = environmentProvider.GetAppDataPath();
|
||||
var IAppDirectoryInfo = new AppDirectoryInfo();
|
||||
var appDataPath = IAppDirectoryInfo.GetAppDataPath();
|
||||
|
||||
if (!Directory.Exists(appDataPath))
|
||||
{
|
||||
Directory.CreateDirectory(appDataPath);
|
||||
}
|
||||
|
||||
Container.Register(c => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase()));
|
||||
Container.Register(c => c.Resolve<IDbFactory>().Create(IAppDirectoryInfo.GetNzbDroneDatabase()));
|
||||
|
||||
Container.Register<ILogRepository>(c =>
|
||||
{
|
||||
var db = c.Resolve<IDbFactory>().Create(environmentProvider.GetLogDatabase(), MigrationType.Log);
|
||||
var db = c.Resolve<IDbFactory>().Create(IAppDirectoryInfo.GetLogDatabase(), MigrationType.Log);
|
||||
return new LogRepository(db, c.Resolve<IMessageAggregator>());
|
||||
});
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.SysTray;
|
||||
using IServiceProvider = NzbDrone.Common.IServiceProvider;
|
||||
|
||||
@ -14,17 +15,17 @@ public class Router
|
||||
private readonly INzbDroneServiceFactory _nzbDroneServiceFactory;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IConsoleService _consoleService;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private readonly IRuntimeInfo _runtimeInfo;
|
||||
private readonly ISystemTrayApp _systemTrayProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public Router(INzbDroneServiceFactory nzbDroneServiceFactory, IServiceProvider serviceProvider,
|
||||
IConsoleService consoleService, IEnvironmentProvider environmentProvider, ISystemTrayApp systemTrayProvider, Logger logger)
|
||||
IConsoleService consoleService, IRuntimeInfo runtimeInfo, ISystemTrayApp systemTrayProvider, Logger logger)
|
||||
{
|
||||
_nzbDroneServiceFactory = nzbDroneServiceFactory;
|
||||
_serviceProvider = serviceProvider;
|
||||
_consoleService = consoleService;
|
||||
_environmentProvider = environmentProvider;
|
||||
_runtimeInfo = runtimeInfo;
|
||||
_systemTrayProvider = systemTrayProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
@ -36,7 +37,7 @@ public void Route(IEnumerable<string> args)
|
||||
|
||||
public void Route(ApplicationModes applicationModes)
|
||||
{
|
||||
if (!_environmentProvider.IsUserInteractive)
|
||||
if (!_runtimeInfo.IsUserInteractive)
|
||||
{
|
||||
applicationModes = ApplicationModes.Service;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Owin;
|
||||
|
||||
namespace NzbDrone.SysTray
|
||||
@ -16,16 +17,14 @@ public class SystemTrayApp : Form, ISystemTrayApp
|
||||
{
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly IHostController _hostController;
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
|
||||
private readonly NotifyIcon _trayIcon = new NotifyIcon();
|
||||
private readonly ContextMenu _trayMenu = new ContextMenu();
|
||||
|
||||
public SystemTrayApp(IProcessProvider processProvider, IHostController hostController, IEnvironmentProvider environmentProvider)
|
||||
public SystemTrayApp(IProcessProvider processProvider, IHostController hostController)
|
||||
{
|
||||
_processProvider = processProvider;
|
||||
_hostController = hostController;
|
||||
_environmentProvider = environmentProvider;
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +34,7 @@ public void Start()
|
||||
_trayMenu.MenuItems.Add("-");
|
||||
_trayMenu.MenuItems.Add("Exit", OnExit);
|
||||
|
||||
_trayIcon.Text = String.Format("NzbDrone - {0}", _environmentProvider.Version);
|
||||
_trayIcon.Text = String.Format("NzbDrone - {0}", BuildInfo.Version);
|
||||
_trayIcon.Icon = new Icon(Assembly.GetEntryAssembly().GetManifestResourceStream("NzbDrone.NzbDrone.ico"));
|
||||
|
||||
_trayIcon.ContextMenu = _trayMenu;
|
||||
|
Loading…
Reference in New Issue
Block a user