BaseMonoApp.cs 4.4 KB

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