BaseMonoApp.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using MediaBrowser.Common.Net;
  2. using MediaBrowser.Model.Logging;
  3. using MediaBrowser.Server.Startup.Common;
  4. using Mono.Unix.Native;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Reflection;
  8. using System.Text.RegularExpressions;
  9. using MediaBrowser.Controller.Power;
  10. namespace MediaBrowser.Server.Mac
  11. {
  12. public abstract class BaseMonoApp : INativeApp
  13. {
  14. /// <summary>
  15. /// Shutdowns this instance.
  16. /// </summary>
  17. public abstract void Shutdown();
  18. /// <summary>
  19. /// Restarts this instance.
  20. /// </summary>
  21. public virtual void Restart(StartupOptions options)
  22. {
  23. throw new NotImplementedException();
  24. }
  25. /// <summary>
  26. /// Determines whether this instance [can self restart].
  27. /// </summary>
  28. /// <returns><c>true</c> if this instance [can self restart]; otherwise, <c>false</c>.</returns>
  29. public virtual bool CanSelfRestart
  30. {
  31. get
  32. {
  33. return false;
  34. }
  35. }
  36. public virtual bool SupportsLibraryMonitor
  37. {
  38. get
  39. {
  40. return true;
  41. }
  42. }
  43. /// <summary>
  44. /// Gets a value indicating whether this instance can self update.
  45. /// </summary>
  46. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  47. public bool CanSelfUpdate
  48. {
  49. get
  50. {
  51. return false;
  52. }
  53. }
  54. public bool SupportsAutoRunAtStartup
  55. {
  56. get { return false; }
  57. }
  58. public void PreventSystemStandby()
  59. {
  60. }
  61. public List<Assembly> GetAssembliesWithParts()
  62. {
  63. var list = new List<Assembly>();
  64. list.Add(GetType().Assembly);
  65. return list;
  66. }
  67. public void AuthorizeServer(int udpPort, int httpServerPort, int httpsPort, string applicationPath, string tempDirectory)
  68. {
  69. }
  70. private NativeEnvironment _nativeEnvironment;
  71. public NativeEnvironment Environment
  72. {
  73. get { return _nativeEnvironment ?? (_nativeEnvironment = GetEnvironmentInfo()); }
  74. }
  75. public bool SupportsRunningAsService
  76. {
  77. get
  78. {
  79. return false;
  80. }
  81. }
  82. public bool IsRunningAsService
  83. {
  84. get
  85. {
  86. return false;
  87. }
  88. }
  89. public void ConfigureAutoRun(bool autorun)
  90. {
  91. }
  92. public void LaunchUrl(string url)
  93. {
  94. throw new NotImplementedException();
  95. }
  96. public INetworkManager CreateNetworkManager(ILogger logger)
  97. {
  98. return new NetworkManager(logger);
  99. }
  100. public IPowerManagement GetPowerManagement()
  101. {
  102. return new NullPowerManagement ();
  103. }
  104. private NativeEnvironment GetEnvironmentInfo()
  105. {
  106. var info = new NativeEnvironment
  107. {
  108. OperatingSystem = Startup.Common.OperatingSystem.Linux
  109. };
  110. var uname = GetUnixName();
  111. var sysName = uname.sysname ?? string.Empty;
  112. info.OperatingSystem = Startup.Common.OperatingSystem.Osx;
  113. var archX86 = new Regex("(i|I)[3-6]86");
  114. if (archX86.IsMatch(uname.machine))
  115. {
  116. info.SystemArchitecture = Architecture.X86;
  117. }
  118. else if (string.Equals(uname.machine, "x86_64", StringComparison.OrdinalIgnoreCase))
  119. {
  120. info.SystemArchitecture = Architecture.X86_X64;
  121. }
  122. else if (uname.machine.StartsWith("arm", StringComparison.OrdinalIgnoreCase))
  123. {
  124. info.SystemArchitecture = Architecture.Arm;
  125. }
  126. info.OperatingSystemVersionString = string.IsNullOrWhiteSpace(sysName) ?
  127. System.Environment.OSVersion.VersionString :
  128. sysName;
  129. return info;
  130. }
  131. private Uname _unixName;
  132. private Uname GetUnixName()
  133. {
  134. if (_unixName == null)
  135. {
  136. var uname = new Uname();
  137. Utsname utsname;
  138. var callResult = Syscall.uname(out utsname);
  139. if (callResult == 0)
  140. {
  141. uname.sysname = utsname.sysname;
  142. uname.machine = utsname.machine;
  143. }
  144. _unixName = uname;
  145. }
  146. return _unixName;
  147. }
  148. private class Uname
  149. {
  150. public string sysname = string.Empty;
  151. public string machine = string.Empty;
  152. }
  153. private class NullPowerManagement : IPowerManagement
  154. {
  155. public void ScheduleWake(DateTime utcTime)
  156. {
  157. throw new NotImplementedException ();
  158. }
  159. }
  160. }
  161. }