1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

no more Nzbdrone.Web in any of the paths.

This commit is contained in:
kay.one 2013-03-30 14:29:02 -07:00
parent c55c56f322
commit 150b1902e9
12 changed files with 39 additions and 157 deletions

View File

@ -160,7 +160,7 @@ public void empty_folder_should_return_folder_modified_date()
[Test] [Test]
public void folder_should_return_correct_value_for_last_write() public void folder_should_return_correct_value_for_last_write()
{ {
var appPath = new EnvironmentProvider().ApplicationPath; var appPath = new EnvironmentProvider().WorkingDirectory;
Mocker.Resolve<DiskProvider>().GetLastDirectoryWrite(appPath).Should().BeOnOrAfter(DateTime.UtcNow.AddMinutes(-10)); Mocker.Resolve<DiskProvider>().GetLastDirectoryWrite(appPath).Should().BeOnOrAfter(DateTime.UtcNow.AddMinutes(-10));
Mocker.Resolve<DiskProvider>().GetLastDirectoryWrite(appPath).Should().BeBefore(DateTime.UtcNow); Mocker.Resolve<DiskProvider>().GetLastDirectoryWrite(appPath).Should().BeBefore(DateTime.UtcNow);
} }

View File

@ -1,6 +1,4 @@
 using System;
using System;
using System.IO; using System.IO;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
@ -9,38 +7,25 @@
namespace NzbDrone.Common.Test namespace NzbDrone.Common.Test
{ {
[TestFixture] [TestFixture]
public class EnvironmentProviderTest : TestBase public class EnvironmentProviderTest : TestBase<EnvironmentProvider>
{ {
readonly EnvironmentProvider environmentProvider = new EnvironmentProvider();
[Test] [Test]
public void StartupPath_should_not_be_empty() public void StartupPath_should_not_be_empty()
{ {
environmentProvider.StartUpPath.Should().NotBeBlank(); Subject.StartUpPath.Should().NotBeBlank();
Path.IsPathRooted(environmentProvider.StartUpPath).Should().BeTrue("Path is not rooted"); Path.IsPathRooted(Subject.StartUpPath).Should().BeTrue("Path is not rooted");
} }
[Test] [Test]
public void ApplicationPath_should_not_be_empty() public void ApplicationPath_should_not_be_empty()
{ {
environmentProvider.ApplicationPath.Should().NotBeBlank(); Subject.WorkingDirectory.Should().NotBeBlank();
Path.IsPathRooted(environmentProvider.ApplicationPath).Should().BeTrue("Path is not rooted"); Path.IsPathRooted(Subject.WorkingDirectory).Should().BeTrue("Path is not rooted");
} }
[Test]
public void ApplicationPath_should_find_root_in_current_folder()
{
Directory.CreateDirectory(EnvironmentProvider.ROOT_MARKER);
environmentProvider.ApplicationPath.Should().BeEquivalentTo(Directory.GetCurrentDirectory());
}
[Test]
public void crawl_should_return_null_if_cant_find_root()
{
environmentProvider.CrawlToRoot("C:\\").Should().BeNullOrEmpty();
}
[Test] [Test]
public void IsProduction_should_return_false_when_run_within_nunit() public void IsProduction_should_return_false_when_run_within_nunit()
@ -52,14 +37,8 @@ public void IsProduction_should_return_false_when_run_within_nunit()
[TestCase("1.0.0.0")] [TestCase("1.0.0.0")]
public void Application_version_should_not_be_default(string version) public void Application_version_should_not_be_default(string version)
{ {
environmentProvider.Version.Should().NotBe(new Version(version)); Subject.Version.Should().NotBe(new Version(version));
} }
[TearDown]
public void TearDown()
{
if (Directory.Exists(EnvironmentProvider.ROOT_MARKER))
Directory.Delete(EnvironmentProvider.ROOT_MARKER);
}
} }
} }

View File

@ -15,7 +15,7 @@ private EnvironmentProvider GetEnviromentProvider()
{ {
var envMoq = new Mock<EnvironmentProvider>(); var envMoq = new Mock<EnvironmentProvider>();
envMoq.SetupGet(c => c.ApplicationPath).Returns(@"C:\NzbDrone\"); envMoq.SetupGet(c => c.WorkingDirectory).Returns(@"C:\NzbDrone\");
envMoq.SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\"); envMoq.SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\");
@ -62,13 +62,6 @@ public void Config_path_test()
GetEnviromentProvider().GetConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\Config.xml"); GetEnviromentProvider().GetConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\Config.xml");
} }
[Test]
public void NlogConfig_path_test()
{
GetEnviromentProvider().GetNlogConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\NzbDrone.Web\log.config");
}
[Test] [Test]
public void Sanbox() public void Sanbox()
{ {

View File

@ -7,30 +7,26 @@ namespace NzbDrone.Common
{ {
public class EnvironmentProvider public class EnvironmentProvider
{ {
public const string NZBDRONE_PATH = "NZBDRONE_PATH"; private static readonly string ProcessName = Process.GetCurrentProcess().ProcessName.ToLower();
public const string NZBDRONE_PID = "NZBDRONE_PID";
public const string ROOT_MARKER = "IISExpress";
public static readonly char[] NewLineChars = Environment.NewLine.ToCharArray(); private static readonly EnvironmentProvider Instance = new EnvironmentProvider();
private static readonly string processName = Process.GetCurrentProcess().ProcessName.ToLower(); private const string NZBDRONE_PID = "NZBDRONE_PID";
private static readonly EnvironmentProvider instance = new EnvironmentProvider();
public static bool IsProduction public static bool IsProduction
{ {
get get
{ {
if (IsDebug || Debugger.IsAttached) return false; if (IsDebug || Debugger.IsAttached) return false;
if (instance.Version.Revision > 10000) return false; //Official builds will never have such a high revision if (Instance.Version.Revision > 10000) return false; //Official builds will never have such a high revision
var lowerProcessName = processName.ToLower(); var lowerProcessName = ProcessName.ToLower();
if (lowerProcessName.Contains("vshost")) return false; if (lowerProcessName.Contains("vshost")) return false;
if (lowerProcessName.Contains("nunit")) return false; if (lowerProcessName.Contains("nunit")) return false;
if (lowerProcessName.Contains("jetbrain")) return false; if (lowerProcessName.Contains("jetbrain")) return false;
if (lowerProcessName.Contains("resharper")) return false; if (lowerProcessName.Contains("resharper")) return false;
if (instance.StartUpPath.ToLower().Contains("_rawpackage")) return false; if (Instance.StartUpPath.ToLower().Contains("_rawpackage")) return false;
return true; return true;
} }
@ -57,7 +53,6 @@ public static bool IsDebug
{ {
get get
{ {
#if DEBUG #if DEBUG
return true; return true;
#else #else
@ -73,44 +68,16 @@ public virtual bool IsUserInteractive
get { return Environment.UserInteractive; } get { return Environment.UserInteractive; }
} }
public virtual string ApplicationPath public virtual string WorkingDirectory
{ {
get { return Directory.GetCurrentDirectory(); } get { return Directory.GetCurrentDirectory(); }
} }
public string CrawlToRoot(string dir)
{
if (String.IsNullOrWhiteSpace(dir))
return null;
var directoryInfo = new DirectoryInfo(dir);
while (!IsRoot(directoryInfo))
{
if (directoryInfo.Parent == null) return null;
directoryInfo = directoryInfo.Parent;
}
return directoryInfo.FullName;
}
private static bool IsRoot(DirectoryInfo dir)
{
return dir.GetDirectories(ROOT_MARKER).Length != 0;
}
public virtual string StartUpPath public virtual string StartUpPath
{ {
get get
{ {
var path = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName; var path = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName;
if (path.StartsWith(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
StringComparison.InvariantCultureIgnoreCase))
{
path = Directory.GetCurrentDirectory();
}
return path; return path;
} }
} }
@ -137,7 +104,7 @@ public virtual DateTime BuildDateTime
} }
} }
public virtual int NzbDroneProcessIdFromEnviroment public virtual int NzbDroneProcessIdFromEnvironment
{ {
get get
{ {
@ -150,14 +117,6 @@ public virtual int NzbDroneProcessIdFromEnviroment
} }
} }
public virtual string NzbDronePathFromEnvironment
{
get
{
return Environment.GetEnvironmentVariable(NZBDRONE_PATH);
}
}
public virtual Version GetOsVersion() public virtual Version GetOsVersion()
{ {
OperatingSystem os = Environment.OSVersion; OperatingSystem os = Environment.OSVersion;

View File

@ -1,22 +1,14 @@
using System; using System;
using System.IO; using System.IO;
using NzbDrone.Common.EnsureThat;
namespace NzbDrone.Common namespace NzbDrone.Common
{ {
public static class PathExtensions public static class PathExtensions
{ {
private const string WEB_FOLDER = "NzbDrone.Web\\";
private const string APP_DATA = "App_Data\\"; private const string APP_DATA = "App_Data\\";
private const string WEB_BIN = "bin\\";
private const string LOG_CONFIG_FILE = "log.config";
private const string APP_CONFIG_FILE = "config.xml"; private const string APP_CONFIG_FILE = "config.xml";
private const string NZBDRONE_DB = "nzbdrone.db";
public const string NZBDRONE_EXE = "NzbDrone.exe";
public const string OBJ_DB_FOLDER = "objDb";
public const string NZBDRONE_DB = "nzbdrone.db";
private const string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip"; private const string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip";
private const string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update\\"; private const string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update\\";
@ -28,6 +20,8 @@ public static class PathExtensions
public static string NormalizePath(this string path) public static string NormalizePath(this string path)
{ {
Ensure.That(() => path).IsNotNullOrWhiteSpace();
if (String.IsNullOrWhiteSpace(path)) if (String.IsNullOrWhiteSpace(path))
throw new ArgumentException("Path can not be null or empty"); throw new ArgumentException("Path can not be null or empty");
@ -41,59 +35,24 @@ public static string NormalizePath(this string path)
return info.FullName.Trim('/', '\\', ' '); return info.FullName.Trim('/', '\\', ' ');
} }
public static string GetWebRoot(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.ApplicationPath, WEB_FOLDER);
}
public static string GetAppDataPath(this EnvironmentProvider environmentProvider) public static string GetAppDataPath(this EnvironmentProvider environmentProvider)
{ {
return Path.Combine(environmentProvider.GetWebRoot(), APP_DATA); return Path.Combine(environmentProvider.WorkingDirectory, APP_DATA);
}
public static string GetWebBinPath(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetWebRoot(), WEB_BIN);
}
public static string GetNlogConfigPath(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetWebRoot(), LOG_CONFIG_FILE);
} }
public static string GetConfigPath(this EnvironmentProvider environmentProvider) public static string GetConfigPath(this EnvironmentProvider environmentProvider)
{ {
return Path.Combine(environmentProvider.ApplicationPath, APP_CONFIG_FILE); return Path.Combine(environmentProvider.WorkingDirectory, APP_CONFIG_FILE);
}
public static string GetObjectDbFolder(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetAppDataPath(), OBJ_DB_FOLDER);
} }
public static string GetMediaCoverPath(this EnvironmentProvider environmentProvider) public static string GetMediaCoverPath(this EnvironmentProvider environmentProvider)
{ {
return Path.Combine(environmentProvider.GetWebRoot(), "MediaCover"); return Path.Combine(environmentProvider.GetAppDataPath(), "MediaCover");
}
public static string GetBannerPath(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetMediaCoverPath(), "Banners");
}
public static string GetFanArtPath(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetMediaCoverPath(), "Fanarts");
}
public static string GetCacheFolder(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetWebRoot(), "Cache");
} }
public static string GetUpdateLogFolder(this EnvironmentProvider environmentProvider) public static string GetUpdateLogFolder(this EnvironmentProvider environmentProvider)
{ {
return Path.Combine(environmentProvider.ApplicationPath, UPDATE_LOG_FOLDER_NAME); return Path.Combine(environmentProvider.WorkingDirectory, UPDATE_LOG_FOLDER_NAME);
} }
public static string GetUpdateSandboxFolder(this EnvironmentProvider environmentProvider) public static string GetUpdateSandboxFolder(this EnvironmentProvider environmentProvider)
@ -131,11 +90,6 @@ public static string GetConfigBackupFile(this EnvironmentProvider environmentPro
return Path.Combine(environmentProvider.GetAppDataPath(), BACKUP_ZIP_FILE); return Path.Combine(environmentProvider.GetAppDataPath(), BACKUP_ZIP_FILE);
} }
public static string GetNzbDroneExe(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.ApplicationPath, NZBDRONE_EXE);
}
public static string GetNzbDroneDatabase(this EnvironmentProvider environmentProvider) public static string GetNzbDroneDatabase(this EnvironmentProvider environmentProvider)
{ {
return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_DB); return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_DB);

View File

@ -110,7 +110,7 @@ public void should_start_update_client()
var updateClientPath = Mocker.GetMock<EnvironmentProvider>().Object.GetUpdateClientExePath(); var updateClientPath = Mocker.GetMock<EnvironmentProvider>().Object.GetUpdateClientExePath();
Mocker.GetMock<EnvironmentProvider>() Mocker.GetMock<EnvironmentProvider>()
.SetupGet(c => c.NzbDroneProcessIdFromEnviroment).Returns(12); .SetupGet(c => c.NzbDroneProcessIdFromEnvironment).Returns(12);
StartUpdate(); StartUpdate();

View File

@ -1,6 +1,4 @@
 using System;
using System;
using System.Linq; using System.Linq;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Linq;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Jobs; using NzbDrone.Core.Jobs;
@ -9,17 +8,16 @@ namespace NzbDrone.Core.Lifecycle
{ {
public class AppShutdownJob : IJob public class AppShutdownJob : IJob
{ {
private readonly EnvironmentProvider _environmentProvider;
private readonly ProcessProvider _processProvider; private readonly ProcessProvider _processProvider;
private readonly ServiceProvider _serviceProvider; private readonly ServiceProvider _serviceProvider;
private readonly Logger _logger;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public AppShutdownJob(EnvironmentProvider environmentProvider, ProcessProvider processProvider, ServiceProvider serviceProvider) public AppShutdownJob(ProcessProvider processProvider, ServiceProvider serviceProvider, Logger logger)
{ {
_environmentProvider = environmentProvider;
_processProvider = processProvider; _processProvider = processProvider;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_logger = logger;
} }
public string Name public string Name
@ -35,21 +33,21 @@ public TimeSpan DefaultInterval
public virtual void Start(ProgressNotification notification, dynamic options) public virtual void Start(ProgressNotification notification, dynamic options)
{ {
notification.CurrentMessage = "Shutting down NzbDrone"; notification.CurrentMessage = "Shutting down NzbDrone";
logger.Info("Shutting down NzbDrone"); _logger.Info("Shutting down NzbDrone");
if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)
&& _serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME)) && _serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME))
{ {
logger.Debug("Stopping NzbDrone Service"); _logger.Debug("Stopping NzbDrone Service");
_serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME); _serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME);
} }
else else
{ {
logger.Debug("Stopping NzbDrone console"); _logger.Debug("Stopping NzbDrone console");
var pid = _environmentProvider.NzbDroneProcessIdFromEnviroment; var currentProcess = _processProvider.GetCurrentProcess();
_processProvider.Kill(pid); _processProvider.Kill(currentProcess.Id);
} }
} }
} }

View File

@ -81,7 +81,7 @@ public virtual void Start(ProgressNotification notification, dynamic options)
var startInfo = new ProcessStartInfo var startInfo = new ProcessStartInfo
{ {
FileName = _environmentProvider.GetUpdateClientExePath(), FileName = _environmentProvider.GetUpdateClientExePath(),
Arguments = string.Format("{0} {1}", _environmentProvider.NzbDroneProcessIdFromEnviroment, _configFileProvider.Guid) Arguments = string.Format("{0} {1}", _environmentProvider.NzbDroneProcessIdFromEnvironment, _configFileProvider.Guid)
}; };
var process = _processProvider.Start(startInfo); var process = _processProvider.Start(startInfo);

View File

@ -118,7 +118,7 @@ protected void WithStrictMocker()
protected void WithTempAsAppPath() protected void WithTempAsAppPath()
{ {
Mocker.GetMock<EnvironmentProvider>() Mocker.GetMock<EnvironmentProvider>()
.SetupGet(c => c.ApplicationPath) .SetupGet(c => c.WorkingDirectory)
.Returns(VirtualPath); .Returns(VirtualPath);
} }

View File

@ -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/=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/=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/=FunctionRecursiveOnAllPaths/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FPARAMETER/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FPARAMETER/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/Environment/Editor/MatchingBraceHighlighting/Position/@EntryValue">BOTH_SIDES</s:String> <s:String x:Key="/Default/Environment/Editor/MatchingBraceHighlighting/Position/@EntryValue">BOTH_SIDES</s:String>
<s:String x:Key="/Default/Environment/Editor/MatchingBraceHighlighting/Style/@EntryValue">OUTLINE</s:String> <s:String x:Key="/Default/Environment/Editor/MatchingBraceHighlighting/Style/@EntryValue">OUTLINE</s:String>

View File

@ -43,7 +43,7 @@ private static void InitializeApp()
ReportingService.RestProvider = container.Resolve<RestProvider>(); ReportingService.RestProvider = container.Resolve<RestProvider>();
logger.Info("Start-up Path:'{0}'", environmentProvider.ApplicationPath); logger.Info("Start-up Path:'{0}'", environmentProvider.WorkingDirectory);
} }
} }
} }