BaseMonoApp.cs 4.2 KB

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