mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-02-20 12:43:28 +02:00
no more Nzbdrone.Web in any of the paths.
This commit is contained in:
parent
c55c56f322
commit
150b1902e9
@ -160,7 +160,7 @@ namespace NzbDrone.Common.Test
|
||||
[Test]
|
||||
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().BeBefore(DateTime.UtcNow);
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
@ -9,38 +7,25 @@ using NzbDrone.Test.Common;
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class EnvironmentProviderTest : TestBase
|
||||
public class EnvironmentProviderTest : TestBase<EnvironmentProvider>
|
||||
{
|
||||
readonly EnvironmentProvider environmentProvider = new EnvironmentProvider();
|
||||
|
||||
[Test]
|
||||
public void StartupPath_should_not_be_empty()
|
||||
{
|
||||
environmentProvider.StartUpPath.Should().NotBeBlank();
|
||||
Path.IsPathRooted(environmentProvider.StartUpPath).Should().BeTrue("Path is not rooted");
|
||||
Subject.StartUpPath.Should().NotBeBlank();
|
||||
Path.IsPathRooted(Subject.StartUpPath).Should().BeTrue("Path is not rooted");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ApplicationPath_should_not_be_empty()
|
||||
{
|
||||
environmentProvider.ApplicationPath.Should().NotBeBlank();
|
||||
Path.IsPathRooted(environmentProvider.ApplicationPath).Should().BeTrue("Path is not rooted");
|
||||
Subject.WorkingDirectory.Should().NotBeBlank();
|
||||
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]
|
||||
public void IsProduction_should_return_false_when_run_within_nunit()
|
||||
@ -52,14 +37,8 @@ namespace NzbDrone.Common.Test
|
||||
[TestCase("1.0.0.0")]
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace NzbDrone.Common.Test
|
||||
{
|
||||
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\");
|
||||
|
||||
@ -62,13 +62,6 @@ namespace NzbDrone.Common.Test
|
||||
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]
|
||||
public void Sanbox()
|
||||
{
|
||||
|
@ -7,30 +7,26 @@ namespace NzbDrone.Common
|
||||
{
|
||||
public class EnvironmentProvider
|
||||
{
|
||||
public const string NZBDRONE_PATH = "NZBDRONE_PATH";
|
||||
public const string NZBDRONE_PID = "NZBDRONE_PID";
|
||||
public const string ROOT_MARKER = "IISExpress";
|
||||
private static readonly string ProcessName = Process.GetCurrentProcess().ProcessName.ToLower();
|
||||
|
||||
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 static readonly EnvironmentProvider instance = new EnvironmentProvider();
|
||||
private const string NZBDRONE_PID = "NZBDRONE_PID";
|
||||
|
||||
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
|
||||
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("nunit")) return false;
|
||||
if (lowerProcessName.Contains("jetbrain")) 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;
|
||||
}
|
||||
@ -57,7 +53,6 @@ namespace NzbDrone.Common
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
#if DEBUG
|
||||
return true;
|
||||
#else
|
||||
@ -73,44 +68,16 @@ namespace NzbDrone.Common
|
||||
get { return Environment.UserInteractive; }
|
||||
}
|
||||
|
||||
public virtual string ApplicationPath
|
||||
public virtual string WorkingDirectory
|
||||
{
|
||||
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
|
||||
{
|
||||
get
|
||||
{
|
||||
var path = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName;
|
||||
|
||||
if (path.StartsWith(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
|
||||
StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
path = Directory.GetCurrentDirectory();
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
@ -137,7 +104,7 @@ namespace NzbDrone.Common
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int NzbDroneProcessIdFromEnviroment
|
||||
public virtual int NzbDroneProcessIdFromEnvironment
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -150,14 +117,6 @@ namespace NzbDrone.Common
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string NzbDronePathFromEnvironment
|
||||
{
|
||||
get
|
||||
{
|
||||
return Environment.GetEnvironmentVariable(NZBDRONE_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Version GetOsVersion()
|
||||
{
|
||||
OperatingSystem os = Environment.OSVersion;
|
||||
|
@ -1,22 +1,14 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public static class PathExtensions
|
||||
{
|
||||
private const string WEB_FOLDER = "NzbDrone.Web\\";
|
||||
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";
|
||||
|
||||
public const string NZBDRONE_EXE = "NzbDrone.exe";
|
||||
|
||||
public const string OBJ_DB_FOLDER = "objDb";
|
||||
public const string NZBDRONE_DB = "nzbdrone.db";
|
||||
|
||||
private const string NZBDRONE_DB = "nzbdrone.db";
|
||||
private const string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip";
|
||||
|
||||
private const string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update\\";
|
||||
@ -28,6 +20,8 @@ namespace NzbDrone.Common
|
||||
|
||||
public static string NormalizePath(this string path)
|
||||
{
|
||||
Ensure.That(() => path).IsNotNullOrWhiteSpace();
|
||||
|
||||
if (String.IsNullOrWhiteSpace(path))
|
||||
throw new ArgumentException("Path can not be null or empty");
|
||||
|
||||
@ -41,59 +35,24 @@ namespace NzbDrone.Common
|
||||
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)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetWebRoot(), 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);
|
||||
return Path.Combine(environmentProvider.WorkingDirectory, APP_DATA);
|
||||
}
|
||||
|
||||
public static string GetConfigPath(this EnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.ApplicationPath, APP_CONFIG_FILE);
|
||||
}
|
||||
|
||||
public static string GetObjectDbFolder(this EnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), OBJ_DB_FOLDER);
|
||||
return Path.Combine(environmentProvider.WorkingDirectory, APP_CONFIG_FILE);
|
||||
}
|
||||
|
||||
public static string GetMediaCoverPath(this EnvironmentProvider environmentProvider)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetWebRoot(), "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");
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), "MediaCover");
|
||||
}
|
||||
|
||||
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)
|
||||
@ -131,11 +90,6 @@ namespace NzbDrone.Common
|
||||
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)
|
||||
{
|
||||
return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_DB);
|
||||
|
@ -110,7 +110,7 @@ namespace NzbDrone.Core.Test.JobTests
|
||||
var updateClientPath = Mocker.GetMock<EnvironmentProvider>().Object.GetUpdateClientExePath();
|
||||
|
||||
Mocker.GetMock<EnvironmentProvider>()
|
||||
.SetupGet(c => c.NzbDroneProcessIdFromEnviroment).Returns(12);
|
||||
.SetupGet(c => c.NzbDroneProcessIdFromEnvironment).Returns(12);
|
||||
|
||||
|
||||
StartUpdate();
|
||||
|
@ -1,6 +1,4 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Jobs;
|
||||
@ -9,17 +8,16 @@ namespace NzbDrone.Core.Lifecycle
|
||||
{
|
||||
public class AppShutdownJob : IJob
|
||||
{
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly ProcessProvider _processProvider;
|
||||
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;
|
||||
_serviceProvider = serviceProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public string Name
|
||||
@ -35,21 +33,21 @@ namespace NzbDrone.Core.Lifecycle
|
||||
public virtual void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
notification.CurrentMessage = "Shutting down NzbDrone";
|
||||
logger.Info("Shutting down NzbDrone");
|
||||
_logger.Info("Shutting down NzbDrone");
|
||||
|
||||
if (_serviceProvider.ServiceExist(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);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
logger.Debug("Stopping NzbDrone console");
|
||||
_logger.Debug("Stopping NzbDrone console");
|
||||
|
||||
var pid = _environmentProvider.NzbDroneProcessIdFromEnviroment;
|
||||
_processProvider.Kill(pid);
|
||||
var currentProcess = _processProvider.GetCurrentProcess();
|
||||
_processProvider.Kill(currentProcess.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ namespace NzbDrone.Core.Lifecycle
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
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);
|
||||
|
@ -118,7 +118,7 @@ namespace NzbDrone.Test.Common
|
||||
protected void WithTempAsAppPath()
|
||||
{
|
||||
Mocker.GetMock<EnvironmentProvider>()
|
||||
.SetupGet(c => c.ApplicationPath)
|
||||
.SetupGet(c => c.WorkingDirectory)
|
||||
.Returns(VirtualPath);
|
||||
}
|
||||
|
||||
|
@ -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/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FPARAMETER/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"><ExtraRule Prefix="" Suffix="" Style="AaBb" /></Policy></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>
|
||||
|
@ -43,7 +43,7 @@ namespace NzbDrone
|
||||
|
||||
ReportingService.RestProvider = container.Resolve<RestProvider>();
|
||||
|
||||
logger.Info("Start-up Path:'{0}'", environmentProvider.ApplicationPath);
|
||||
logger.Info("Start-up Path:'{0}'", environmentProvider.WorkingDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user