1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00

New: show mono version on System -> Info

This commit is contained in:
Mark McDowall 2014-07-29 23:23:43 -07:00
parent e71de9cc29
commit 705d4a3d02
16 changed files with 91 additions and 64 deletions

View File

@ -21,7 +21,7 @@ protected StaticResourceMapperBase(IDiskProvider diskProvider, Logger logger)
_diskProvider = diskProvider;
_logger = logger;
if (!RuntimeInfo.IsProduction)
if (!RuntimeInfoBase.IsProduction)
{
_caseSensitive = true;
}

View File

@ -27,7 +27,7 @@ protected override void ApplicationStartup(TinyIoCContainer container, IPipeline
{
_logger.Info("Starting NzbDrone API");
if (RuntimeInfo.IsProduction)
if (RuntimeInfoBase.IsProduction)
{
DiagnosticsHook.Disable(pipelines);
}

View File

@ -3,6 +3,7 @@
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 @@ private Response GetStatus()
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 @@ private Response GetStatus()
Authentication = _configFileProvider.AuthenticationEnabled,
StartOfWeek = (int)OsInfo.FirstDayOfWeek,
SqliteVersion = _database.Version,
UrlBase = _configFileProvider.UrlBase
UrlBase = _configFileProvider.UrlBase,
RuntimeVersion = OsInfo.IsMono ? _runtimeInfo.RuntimeVersion : null
}.AsResponse();
}

View File

@ -29,7 +29,7 @@ public void ApplicationPath_should_not_be_empty()
[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]

View File

@ -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; }
}
}

View File

@ -9,23 +9,12 @@
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 @@ public RuntimeInfo(Logger logger, IServiceProvider serviceProvider)
}
}
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 @@ public bool IsConsole
return (OsInfo.IsWindows &&
IsUserInteractive &&
ProcessName.Equals(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME, StringComparison.InvariantCultureIgnoreCase)) ||
OsInfo.IsMono;
OsInfo.IsMono;
}
}
@ -87,6 +84,8 @@ public bool IsConsole
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()

View File

@ -30,7 +30,7 @@ protected override void InitializeTarget()
IncludeMachineName = true,
};
if (RuntimeInfo.IsProduction)
if (RuntimeInfoBase.IsProduction)
{
config.ApiKey = "cc4728a35aa9414f9a0baa8eed56bc67";
}

View File

@ -32,7 +32,7 @@ public static void Register(IStartupContext startupContext, bool updateApp, bool
}
else
{
if (inConsole && (OsInfo.IsMono || new RuntimeInfo(null, new ServiceProvider(new ProcessProvider())).IsUserInteractive))
if (inConsole && (OsInfo.IsMono || RuntimeInfoBase.IsUserInteractive))
{
RegisterConsole();
}
@ -59,7 +59,7 @@ private static void RegisterConsole()
{
var level = LogLevel.Trace;
if (RuntimeInfo.IsProduction)
if (RuntimeInfoBase.IsProduction)
{
level = LogLevel.Info;
}

View File

@ -22,7 +22,7 @@ protected override void InitializeTarget()
{
string apiKey = string.Empty;
if (RuntimeInfo.IsProduction)
if (RuntimeInfoBase.IsProduction)
{
apiKey = "4c4ecb69-d1b9-4e2a-b54b-b0c4cc143a95";
}

View File

@ -98,7 +98,8 @@
<Compile Include="EnvironmentInfo\AppFolderInfo.cs" />
<Compile Include="EnvironmentInfo\BuildInfo.cs" />
<Compile Include="EnvironmentInfo\OsInfo.cs" />
<Compile Include="EnvironmentInfo\RuntimeInfo.cs" />
<Compile Include="EnvironmentInfo\IRuntimeInfo.cs" />
<Compile Include="EnvironmentInfo\RuntimeInfoBase.cs" />
<Compile Include="EnvironmentInfo\StartupContext.cs" />
<Compile Include="Exceptions\NotParentException.cs" />
<Compile Include="Exceptions\NzbDroneException.cs" />
@ -130,7 +131,6 @@
<Compile Include="Model\ProcessInfo.cs" />
<Compile Include="PathEqualityComparer.cs" />
<Compile Include="PathExtensions.cs" />
<Compile Include="Processes\IRuntimeProvider.cs" />
<Compile Include="Processes\PidFileProvider.cs" />
<Compile Include="Processes\ProcessOutput.cs" />
<Compile Include="Processes\ProcessProvider.cs" />

View File

@ -1,9 +0,0 @@
using System;
namespace NzbDrone.Common.Processes
{
public interface IRuntimeProvider
{
String GetVersion();
}
}

View File

@ -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|^)(?<version>\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 @@ public override HealthCheck Check()
return new HealthCheck(GetType());
}
var versionString = _runtimeProvider.GetVersion();
var versionString = _runtimeInfo.RuntimeVersion;
var versionMatch = VersionRegex.Match(versionString);
if (versionMatch.Success)

View File

@ -39,7 +39,7 @@ private void Clean()
}
//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");

View File

@ -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;
}
}
}
}

View File

@ -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();
}
}
}
}

View File

@ -4,8 +4,15 @@
<dl class="dl-horizontal">
<dt>Version</dt>
<dd>{{version}}</dd>
{{#if isMono}}
<dt>Mono Version</dt>
<dd>{{runtimeVersion}}</dd>
{{/if}}
<dt>AppData directory</dt>
<dd>{{appData}}</dd>
<dt>Startup directory</dt>
<dd>{{startupPath}}</dd>
</dl>