diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-11-23 18:10:41 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-11-23 18:10:41 -0500 |
| commit | 2df4273ee08425858f93cf86092df45a5a6deecc (patch) | |
| tree | daa20b4be88311cd070a6293ebc322ee141432e2 /MediaBrowser.Server.Mono/Native | |
| parent | 1923de72bf3c502ba9b942ef6caa5f73a33f43d6 (diff) | |
consolidate os display name
Diffstat (limited to 'MediaBrowser.Server.Mono/Native')
| -rw-r--r-- | MediaBrowser.Server.Mono/Native/BaseMonoApp.cs | 193 | ||||
| -rw-r--r-- | MediaBrowser.Server.Mono/Native/NativeApp.cs | 178 |
2 files changed, 196 insertions, 175 deletions
diff --git a/MediaBrowser.Server.Mono/Native/BaseMonoApp.cs b/MediaBrowser.Server.Mono/Native/BaseMonoApp.cs new file mode 100644 index 000000000..ce81326fb --- /dev/null +++ b/MediaBrowser.Server.Mono/Native/BaseMonoApp.cs @@ -0,0 +1,193 @@ +using MediaBrowser.Common.Net; +using MediaBrowser.IsoMounter; +using MediaBrowser.Model.Logging; +using MediaBrowser.Server.Mono.Networking; +using MediaBrowser.Server.Startup.Common; +using Mono.Unix.Native; +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text.RegularExpressions; + +namespace MediaBrowser.Server.Mono.Native +{ + public abstract class BaseMonoApp : INativeApp + { + /// <summary> + /// Shutdowns this instance. + /// </summary> + public abstract void Shutdown(); + + /// <summary> + /// Restarts this instance. + /// </summary> + public void Restart() + { + + } + + /// <summary> + /// Determines whether this instance [can self restart]. + /// </summary> + /// <returns><c>true</c> if this instance [can self restart]; otherwise, <c>false</c>.</returns> + public bool CanSelfRestart + { + get + { + return false; + } + } + + /// <summary> + /// Gets a value indicating whether this instance can self update. + /// </summary> + /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value> + public bool CanSelfUpdate + { + get + { + return false; + } + } + + public bool SupportsAutoRunAtStartup + { + get { return false; } + } + + public void PreventSystemStandby() + { + + } + + public List<Assembly> GetAssembliesWithParts() + { + var list = new List<Assembly>(); + + if (Environment.OperatingSystem == Startup.Common.OperatingSystem.Linux) + { + list.AddRange(GetLinuxAssemblies()); + } + + list.Add(GetType().Assembly); + + return list; + } + + private IEnumerable<Assembly> GetLinuxAssemblies() + { + var list = new List<Assembly>(); + + list.Add(typeof(LinuxIsoManager).Assembly); + + return list; + } + + public void AuthorizeServer(int httpServerPort, string httpServerUrlPrefix, int udpPort, string tempDirectory) + { + } + + private NativeEnvironment _nativeEnvironment; + public NativeEnvironment Environment + { + get { return _nativeEnvironment ?? (_nativeEnvironment = GetEnvironmentInfo()); } + } + + public bool SupportsRunningAsService + { + get + { + return false; + } + } + + public bool IsRunningAsService + { + get + { + return false; + } + } + + public void ConfigureAutoRun(bool autorun) + { + } + + public INetworkManager CreateNetworkManager(ILogger logger) + { + return new NetworkManager(logger); + } + + private NativeEnvironment GetEnvironmentInfo() + { + var info = new NativeEnvironment + { + OperatingSystem = Startup.Common.OperatingSystem.Linux + }; + + var uname = GetUnixName(); + + var sysName = uname.sysname ?? string.Empty; + + if (string.Equals(sysName, "Darwin", StringComparison.OrdinalIgnoreCase)) + { + info.OperatingSystem = Startup.Common.OperatingSystem.Osx; + } + else if (string.Equals(sysName, "Linux", StringComparison.OrdinalIgnoreCase)) + { + info.OperatingSystem = Startup.Common.OperatingSystem.Linux; + } + else if (string.Equals(sysName, "BSD", StringComparison.OrdinalIgnoreCase)) + { + // TODO: How to detect BSD? + info.OperatingSystem = Startup.Common.OperatingSystem.Bsd; + } + + var archX86 = new Regex("(i|I)[3-6]86"); + + if (archX86.IsMatch(uname.machine)) + { + info.SystemArchitecture = Architecture.X86; + } + else if (string.Equals(uname.machine, "x86_64", StringComparison.OrdinalIgnoreCase)) + { + info.SystemArchitecture = Architecture.X86_X64; + } + else if (uname.machine.StartsWith("arm", StringComparison.OrdinalIgnoreCase)) + { + info.SystemArchitecture = Architecture.Arm; + } + + info.OperatingSystemVersionString = string.IsNullOrWhiteSpace(sysName) ? + System.Environment.OSVersion.VersionString : + sysName; + + return info; + } + + private NativeApp.Uname _unixName; + private NativeApp.Uname GetUnixName() + { + if (_unixName == null) + { + var uname = new NativeApp.Uname(); + Utsname utsname; + var callResult = Syscall.uname(out utsname); + if (callResult == 0) + { + uname.sysname = utsname.sysname; + uname.machine = utsname.machine; + } + + _unixName = uname; + } + return _unixName; + } + + public class Uname + { + public string sysname = string.Empty; + public string machine = string.Empty; + } + } +} diff --git a/MediaBrowser.Server.Mono/Native/NativeApp.cs b/MediaBrowser.Server.Mono/Native/NativeApp.cs index 541b2bd7d..b71b74a66 100644 --- a/MediaBrowser.Server.Mono/Native/NativeApp.cs +++ b/MediaBrowser.Server.Mono/Native/NativeApp.cs @@ -1,189 +1,17 @@ -using MediaBrowser.Common.Net; -using MediaBrowser.IsoMounter; -using MediaBrowser.Model.Logging; -using MediaBrowser.Server.Mono.Networking; -using MediaBrowser.Server.Startup.Common; -using Mono.Unix.Native; -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Text.RegularExpressions; - + namespace MediaBrowser.Server.Mono.Native { /// <summary> /// Class NativeApp /// </summary> - public class NativeApp : INativeApp + public class NativeApp : BaseMonoApp { /// <summary> /// Shutdowns this instance. /// </summary> - public void Shutdown() + public override void Shutdown() { MainClass.Shutdown(); } - - /// <summary> - /// Restarts this instance. - /// </summary> - public void Restart() - { - - } - - /// <summary> - /// Determines whether this instance [can self restart]. - /// </summary> - /// <returns><c>true</c> if this instance [can self restart]; otherwise, <c>false</c>.</returns> - public bool CanSelfRestart - { - get - { - return false; - } - } - - /// <summary> - /// Gets a value indicating whether this instance can self update. - /// </summary> - /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value> - public bool CanSelfUpdate - { - get - { - return false; - } - } - - public bool SupportsAutoRunAtStartup - { - get { return false; } - } - - public void PreventSystemStandby() - { - - } - - public List<Assembly> GetAssembliesWithParts() - { - var list = new List<Assembly>(); - - if (Environment.OperatingSystem == Startup.Common.OperatingSystem.Linux) - { - list.AddRange(GetLinuxAssemblies()); - } - - list.Add(GetType().Assembly); - - return list; - } - - private List<Assembly> GetLinuxAssemblies() - { - var list = new List<Assembly>(); - - list.Add(typeof(LinuxIsoManager).Assembly); - - return list; - } - - public void AuthorizeServer(int httpServerPort, string httpServerUrlPrefix, int udpPort, string tempDirectory) - { - } - - private NativeEnvironment _nativeEnvironment; - public NativeEnvironment Environment - { - get { return _nativeEnvironment ?? (_nativeEnvironment = GetEnvironmentInfo()); } - } - - public bool SupportsRunningAsService - { - get - { - return false; - } - } - - public bool IsRunningAsService - { - get - { - return false; - } - } - - public void ConfigureAutoRun(bool autorun) - { - } - - public INetworkManager CreateNetworkManager(ILogger logger) - { - return new NetworkManager(logger); - } - - private NativeEnvironment GetEnvironmentInfo() - { - var info = new NativeEnvironment - { - OperatingSystem = Startup.Common.OperatingSystem.Linux - }; - - var uname = GetUnixName(); - - var sysName = uname.sysname ?? string.Empty; - - if (string.Equals(sysName, "Darwin", StringComparison.OrdinalIgnoreCase)) - { - info.OperatingSystem = Startup.Common.OperatingSystem.Osx; - } - else if (string.Equals(sysName, "Linux", StringComparison.OrdinalIgnoreCase)) - { - info.OperatingSystem = Startup.Common.OperatingSystem.Linux; - } - else if (string.Equals(sysName, "BSD", StringComparison.OrdinalIgnoreCase)) - { - // TODO: How to detect BSD? - info.OperatingSystem = Startup.Common.OperatingSystem.Bsd; - } - - var archX86 = new Regex("(i|I)[3-6]86"); - - if (archX86.IsMatch(uname.machine)) - { - info.SystemArchitecture = Architecture.X86; - } - else if (string.Equals(uname.machine, "x86_64", StringComparison.OrdinalIgnoreCase)) - { - info.SystemArchitecture = Architecture.X86_X64; - } - else if (uname.machine.StartsWith("arm", StringComparison.OrdinalIgnoreCase)) - { - info.SystemArchitecture = Architecture.Arm; - } - - return info; - } - - private static Uname GetUnixName() - { - var uname = new Uname(); - Utsname utsname; - var callResult = Syscall.uname(out utsname); - if (callResult == 0) - { - uname.sysname = utsname.sysname; - uname.machine = utsname.machine; - } - return uname; - } - - public class Uname - { - public string sysname = string.Empty; - public string machine = string.Empty; - } } } |
