From 705d4a3d021734c096ba0346f1663f25434d4b70 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 29 Jul 2014 23:23:43 -0700 Subject: [PATCH] New: show mono version on System -> Info --- .../Mappers/StaticResourceMapperBase.cs | 2 +- src/NzbDrone.Api/NancyBootstrapper.cs | 2 +- src/NzbDrone.Api/System/SystemModule.cs | 8 ++-- .../EnvironmentProviderTest.cs | 2 +- .../EnvironmentInfo/IRuntimeInfo.cs | 16 ++++++++ .../{RuntimeInfo.cs => RuntimeInfoBase.cs} | 31 ++++++++------- .../Instrumentation/ExceptronTarget.cs | 2 +- .../Instrumentation/LogTargets.cs | 4 +- .../Instrumentation/LogglyTarget.cs | 2 +- src/NzbDrone.Common/NzbDrone.Common.csproj | 4 +- .../Processes/IRuntimeProvider.cs | 9 ----- .../HealthCheck/Checks/MonoVersionCheck.cs | 9 ++--- .../Housekeeping/HousekeepingService.cs | 2 +- src/NzbDrone.Mono/MonoRuntimeProvider.cs | 38 ++++++++++--------- src/NzbDrone.Windows/DotNetRuntimeProvider.cs | 17 +++++++-- .../System/Info/About/AboutViewTemplate.html | 7 ++++ 16 files changed, 91 insertions(+), 64 deletions(-) create mode 100644 src/NzbDrone.Common/EnvironmentInfo/IRuntimeInfo.cs rename src/NzbDrone.Common/EnvironmentInfo/{RuntimeInfo.cs => RuntimeInfoBase.cs} (85%) delete mode 100644 src/NzbDrone.Common/Processes/IRuntimeProvider.cs diff --git a/src/NzbDrone.Api/Frontend/Mappers/StaticResourceMapperBase.cs b/src/NzbDrone.Api/Frontend/Mappers/StaticResourceMapperBase.cs index 1dd542692..75cd56180 100644 --- a/src/NzbDrone.Api/Frontend/Mappers/StaticResourceMapperBase.cs +++ b/src/NzbDrone.Api/Frontend/Mappers/StaticResourceMapperBase.cs @@ -21,7 +21,7 @@ namespace NzbDrone.Api.Frontend.Mappers _diskProvider = diskProvider; _logger = logger; - if (!RuntimeInfo.IsProduction) + if (!RuntimeInfoBase.IsProduction) { _caseSensitive = true; } diff --git a/src/NzbDrone.Api/NancyBootstrapper.cs b/src/NzbDrone.Api/NancyBootstrapper.cs index 0f5e89721..cd9809a9e 100644 --- a/src/NzbDrone.Api/NancyBootstrapper.cs +++ b/src/NzbDrone.Api/NancyBootstrapper.cs @@ -27,7 +27,7 @@ namespace NzbDrone.Api { _logger.Info("Starting NzbDrone API"); - if (RuntimeInfo.IsProduction) + if (RuntimeInfoBase.IsProduction) { DiagnosticsHook.Disable(pipelines); } diff --git a/src/NzbDrone.Api/System/SystemModule.cs b/src/NzbDrone.Api/System/SystemModule.cs index e951a8da0..ca1bab855 100644 --- a/src/NzbDrone.Api/System/SystemModule.cs +++ b/src/NzbDrone.Api/System/SystemModule.cs @@ -3,6 +3,7 @@ using Nancy.Routing; using NzbDrone.Common; using NzbDrone.Api.Extensions; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Processes; using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; using NzbDrone.Core.Lifecycle; @@ -46,9 +47,9 @@ namespace NzbDrone.Api.System Version = BuildInfo.Version.ToString(), BuildTime = BuildInfo.BuildDateTime, IsDebug = BuildInfo.IsDebug, - IsProduction = RuntimeInfo.IsProduction, + IsProduction = RuntimeInfoBase.IsProduction, IsAdmin = _runtimeInfo.IsAdmin, - IsUserInteractive = _runtimeInfo.IsUserInteractive, + IsUserInteractive = RuntimeInfoBase.IsUserInteractive, StartupPath = _appFolderInfo.StartUpFolder, AppData = _appFolderInfo.GetAppDataPath(), OsVersion = OsInfo.Version.ToString(), @@ -61,7 +62,8 @@ namespace NzbDrone.Api.System Authentication = _configFileProvider.AuthenticationEnabled, StartOfWeek = (int)OsInfo.FirstDayOfWeek, SqliteVersion = _database.Version, - UrlBase = _configFileProvider.UrlBase + UrlBase = _configFileProvider.UrlBase, + RuntimeVersion = OsInfo.IsMono ? _runtimeInfo.RuntimeVersion : null }.AsResponse(); } diff --git a/src/NzbDrone.Common.Test/EnvironmentProviderTest.cs b/src/NzbDrone.Common.Test/EnvironmentProviderTest.cs index 920064f70..98f6d862b 100644 --- a/src/NzbDrone.Common.Test/EnvironmentProviderTest.cs +++ b/src/NzbDrone.Common.Test/EnvironmentProviderTest.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Common.Test [Test] public void IsProduction_should_return_false_when_run_within_nunit() { - RuntimeInfo.IsProduction.Should().BeFalse("Process name is " + Process.GetCurrentProcess().ProcessName + " Folder is " + Directory.GetCurrentDirectory()); + RuntimeInfoBase.IsProduction.Should().BeFalse("Process name is " + Process.GetCurrentProcess().ProcessName + " Folder is " + Directory.GetCurrentDirectory()); } [Test] diff --git a/src/NzbDrone.Common/EnvironmentInfo/IRuntimeInfo.cs b/src/NzbDrone.Common/EnvironmentInfo/IRuntimeInfo.cs new file mode 100644 index 000000000..fbcc600d4 --- /dev/null +++ b/src/NzbDrone.Common/EnvironmentInfo/IRuntimeInfo.cs @@ -0,0 +1,16 @@ +using System; + +namespace NzbDrone.Common.EnvironmentInfo +{ + public interface IRuntimeInfo + { + Boolean IsUserInteractive { get; } + Boolean IsAdmin { get; } + Boolean IsWindowsService { get; } + Boolean IsConsole { get; } + Boolean IsRunning { get; set; } + Boolean RestartPending { get; set; } + String ExecutingApplication { get; } + String RuntimeVersion { get; } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs b/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfoBase.cs similarity index 85% rename from src/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs rename to src/NzbDrone.Common/EnvironmentInfo/RuntimeInfoBase.cs index 679fe2f1c..6f8de3f9a 100644 --- a/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs +++ b/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfoBase.cs @@ -9,23 +9,12 @@ using NzbDrone.Common.Processes; namespace NzbDrone.Common.EnvironmentInfo { - public interface IRuntimeInfo - { - bool IsUserInteractive { get; } - bool IsAdmin { get; } - bool IsWindowsService { get; } - bool IsConsole { get; } - bool IsRunning { get; set; } - bool RestartPending { get; set; } - string ExecutingApplication { get; } - } - - public class RuntimeInfo : IRuntimeInfo + public abstract class RuntimeInfoBase : IRuntimeInfo { private readonly Logger _logger; private static readonly string ProcessName = Process.GetCurrentProcess().ProcessName.ToLower(); - public RuntimeInfo(Logger logger, IServiceProvider serviceProvider) + public RuntimeInfoBase(IServiceProvider serviceProvider, Logger logger) { _logger = logger; @@ -43,16 +32,24 @@ namespace NzbDrone.Common.EnvironmentInfo } } - static RuntimeInfo() + static RuntimeInfoBase() { IsProduction = InternalIsProduction(); } - public bool IsUserInteractive + public static bool IsUserInteractive { get { return Environment.UserInteractive; } } + bool IRuntimeInfo.IsUserInteractive + { + get + { + return IsUserInteractive; + } + } + public bool IsAdmin { get @@ -79,7 +76,7 @@ namespace NzbDrone.Common.EnvironmentInfo return (OsInfo.IsWindows && IsUserInteractive && ProcessName.Equals(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME, StringComparison.InvariantCultureIgnoreCase)) || - OsInfo.IsMono; + OsInfo.IsMono; } } @@ -87,6 +84,8 @@ namespace NzbDrone.Common.EnvironmentInfo public bool RestartPending { get; set; } public string ExecutingApplication { get; private set; } + public abstract string RuntimeVersion { get; } + public static bool IsProduction { get; private set; } private static bool InternalIsProduction() diff --git a/src/NzbDrone.Common/Instrumentation/ExceptronTarget.cs b/src/NzbDrone.Common/Instrumentation/ExceptronTarget.cs index b45b76a00..09efb03e3 100644 --- a/src/NzbDrone.Common/Instrumentation/ExceptronTarget.cs +++ b/src/NzbDrone.Common/Instrumentation/ExceptronTarget.cs @@ -30,7 +30,7 @@ namespace NzbDrone.Common.Instrumentation IncludeMachineName = true, }; - if (RuntimeInfo.IsProduction) + if (RuntimeInfoBase.IsProduction) { config.ApiKey = "cc4728a35aa9414f9a0baa8eed56bc67"; } diff --git a/src/NzbDrone.Common/Instrumentation/LogTargets.cs b/src/NzbDrone.Common/Instrumentation/LogTargets.cs index 099dd71bc..4628540af 100644 --- a/src/NzbDrone.Common/Instrumentation/LogTargets.cs +++ b/src/NzbDrone.Common/Instrumentation/LogTargets.cs @@ -32,7 +32,7 @@ namespace NzbDrone.Common.Instrumentation } else { - if (inConsole && (OsInfo.IsMono || new RuntimeInfo(null, new ServiceProvider(new ProcessProvider())).IsUserInteractive)) + if (inConsole && (OsInfo.IsMono || RuntimeInfoBase.IsUserInteractive)) { RegisterConsole(); } @@ -59,7 +59,7 @@ namespace NzbDrone.Common.Instrumentation { var level = LogLevel.Trace; - if (RuntimeInfo.IsProduction) + if (RuntimeInfoBase.IsProduction) { level = LogLevel.Info; } diff --git a/src/NzbDrone.Common/Instrumentation/LogglyTarget.cs b/src/NzbDrone.Common/Instrumentation/LogglyTarget.cs index ae246eb41..ba4f0b984 100644 --- a/src/NzbDrone.Common/Instrumentation/LogglyTarget.cs +++ b/src/NzbDrone.Common/Instrumentation/LogglyTarget.cs @@ -22,7 +22,7 @@ namespace NzbDrone.Common.Instrumentation { string apiKey = string.Empty; - if (RuntimeInfo.IsProduction) + if (RuntimeInfoBase.IsProduction) { apiKey = "4c4ecb69-d1b9-4e2a-b54b-b0c4cc143a95"; } diff --git a/src/NzbDrone.Common/NzbDrone.Common.csproj b/src/NzbDrone.Common/NzbDrone.Common.csproj index ad6f21b9a..8d4a98d3d 100644 --- a/src/NzbDrone.Common/NzbDrone.Common.csproj +++ b/src/NzbDrone.Common/NzbDrone.Common.csproj @@ -98,7 +98,8 @@ - + + @@ -130,7 +131,6 @@ - diff --git a/src/NzbDrone.Common/Processes/IRuntimeProvider.cs b/src/NzbDrone.Common/Processes/IRuntimeProvider.cs deleted file mode 100644 index 96f7a1e62..000000000 --- a/src/NzbDrone.Common/Processes/IRuntimeProvider.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace NzbDrone.Common.Processes -{ - public interface IRuntimeProvider - { - String GetVersion(); - } -} diff --git a/src/NzbDrone.Core/HealthCheck/Checks/MonoVersionCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/MonoVersionCheck.cs index 43f385e8e..048c90e1c 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/MonoVersionCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/MonoVersionCheck.cs @@ -2,19 +2,18 @@ using System.Text.RegularExpressions; using NLog; using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Common.Processes; namespace NzbDrone.Core.HealthCheck.Checks { public class MonoVersionCheck : HealthCheckBase { - private readonly IRuntimeProvider _runtimeProvider; + private readonly IRuntimeInfo _runtimeInfo; private readonly Logger _logger; private static readonly Regex VersionRegex = new Regex(@"(?<=\W|^)(?\d+\.\d+\.\d+(\.\d+)?)(?=\W)", RegexOptions.Compiled | RegexOptions.IgnoreCase); - public MonoVersionCheck(IRuntimeProvider runtimeProvider, Logger logger) + public MonoVersionCheck(IRuntimeInfo runtimeInfo, Logger logger) { - _runtimeProvider = runtimeProvider; + _runtimeInfo = runtimeInfo; _logger = logger; } @@ -25,7 +24,7 @@ namespace NzbDrone.Core.HealthCheck.Checks return new HealthCheck(GetType()); } - var versionString = _runtimeProvider.GetVersion(); + var versionString = _runtimeInfo.RuntimeVersion; var versionMatch = VersionRegex.Match(versionString); if (versionMatch.Success) diff --git a/src/NzbDrone.Core/Housekeeping/HousekeepingService.cs b/src/NzbDrone.Core/Housekeeping/HousekeepingService.cs index 9199fea9d..a059aa8f6 100644 --- a/src/NzbDrone.Core/Housekeeping/HousekeepingService.cs +++ b/src/NzbDrone.Core/Housekeeping/HousekeepingService.cs @@ -39,7 +39,7 @@ namespace NzbDrone.Core.Housekeeping } //Only Vaccuum the DB in production - if (RuntimeInfo.IsProduction) + if (RuntimeInfoBase.IsProduction) { // Vacuuming the log db isn't needed since that's done hourly at the TrimLogCommand. _logger.Debug("Compressing main database after housekeeping"); diff --git a/src/NzbDrone.Mono/MonoRuntimeProvider.cs b/src/NzbDrone.Mono/MonoRuntimeProvider.cs index af0fe4115..b7a97d288 100644 --- a/src/NzbDrone.Mono/MonoRuntimeProvider.cs +++ b/src/NzbDrone.Mono/MonoRuntimeProvider.cs @@ -1,41 +1,45 @@ using System; using System.Reflection; using NLog; -using NzbDrone.Common.Processes; +using NzbDrone.Common.EnvironmentInfo; namespace NzbDrone.Mono { - public class MonoRuntimeProvider : IRuntimeProvider + public class MonoRuntimeProvider : RuntimeInfoBase { private readonly Logger _logger; - public MonoRuntimeProvider(Logger logger) + public MonoRuntimeProvider(Common.IServiceProvider serviceProvider, Logger logger) + :base(serviceProvider, logger) { _logger = logger; } - public String GetVersion() + public override String RuntimeVersion { - try + get { - var type = Type.GetType("Mono.Runtime"); - - if (type != null) + try { - var displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); + var type = Type.GetType("Mono.Runtime"); - if (displayName != null) + if (type != null) { - return displayName.Invoke(null, null).ToString(); + var displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); + + if (displayName != null) + { + return displayName.Invoke(null, null).ToString(); + } } } - } - catch (Exception ex) - { - _logger.ErrorException("Unable to get mono version: " + ex.Message, ex); - } + catch (Exception ex) + { + _logger.ErrorException("Unable to get mono version: " + ex.Message, ex); + } - return String.Empty; + return String.Empty; + } } } } diff --git a/src/NzbDrone.Windows/DotNetRuntimeProvider.cs b/src/NzbDrone.Windows/DotNetRuntimeProvider.cs index 40203278d..6f1a82733 100644 --- a/src/NzbDrone.Windows/DotNetRuntimeProvider.cs +++ b/src/NzbDrone.Windows/DotNetRuntimeProvider.cs @@ -1,13 +1,22 @@ using System; -using NzbDrone.Common.Processes; +using NLog; +using NzbDrone.Common.EnvironmentInfo; namespace NzbDrone.Windows { - public class DotNetRuntimeProvider : IRuntimeProvider + public class DotNetRuntimeProvider : RuntimeInfoBase { - public String GetVersion() + public DotNetRuntimeProvider(Common.IServiceProvider serviceProvider, Logger logger) + : base(serviceProvider, logger) { - return Environment.Version.ToString(); + } + + public override string RuntimeVersion + { + get + { + return Environment.Version.ToString(); + } } } } diff --git a/src/UI/System/Info/About/AboutViewTemplate.html b/src/UI/System/Info/About/AboutViewTemplate.html index 57c32bc4e..02bd9b7dd 100644 --- a/src/UI/System/Info/About/AboutViewTemplate.html +++ b/src/UI/System/Info/About/AboutViewTemplate.html @@ -4,8 +4,15 @@
Version
{{version}}
+ + {{#if isMono}} +
Mono Version
+
{{runtimeVersion}}
+ {{/if}} +
AppData directory
{{appData}}
+
Startup directory
{{startupPath}}