MonoAppHost.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using Emby.Server.Core;
  5. using Emby.Server.Core.Data;
  6. using Emby.Server.Implementations;
  7. using Emby.Server.Implementations.FFMpeg;
  8. using MediaBrowser.IsoMounter;
  9. using MediaBrowser.Model.IO;
  10. using MediaBrowser.Model.Logging;
  11. using MediaBrowser.Model.System;
  12. using MediaBrowser.Server.Mono.Native;
  13. namespace MediaBrowser.Server.Mono
  14. {
  15. public class MonoAppHost : ApplicationHost
  16. {
  17. public MonoAppHost(ServerApplicationPaths applicationPaths, ILogManager logManager, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, IMemoryStreamFactory memoryStreamFactory, MediaBrowser.Common.Net.INetworkManager networkManager, Action<string, string> certificateGenerator, Func<string> defaultUsernameFactory) : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, memoryStreamFactory, networkManager, certificateGenerator, defaultUsernameFactory)
  18. {
  19. }
  20. public override bool CanSelfRestart
  21. {
  22. get
  23. {
  24. // A restart script must be provided
  25. return StartupOptions.ContainsOption("-restartpath");
  26. }
  27. }
  28. public override bool CanSelfUpdate
  29. {
  30. get
  31. {
  32. return false;
  33. }
  34. }
  35. protected override FFMpegInstallInfo GetFfmpegInstallInfo()
  36. {
  37. var info = new FFMpegInstallInfo();
  38. // Windows builds: http://ffmpeg.zeranoe.com/builds/
  39. // Linux builds: http://johnvansickle.com/ffmpeg/
  40. // OS X builds: http://ffmpegmac.net/
  41. // OS X x64: http://www.evermeet.cx/ffmpeg/
  42. var environment = (MonoEnvironmentInfo) EnvironmentInfo;
  43. if (environment.IsBsd)
  44. {
  45. }
  46. else if (environment.OperatingSystem == Model.System.OperatingSystem.Linux)
  47. {
  48. info.ArchiveType = "7z";
  49. info.Version = "20160215";
  50. }
  51. // No version available - user requirement
  52. info.DownloadUrls = new string[] { };
  53. return info;
  54. }
  55. protected override void RestartInternal()
  56. {
  57. MainClass.Restart(StartupOptions);
  58. }
  59. protected override List<Assembly> GetAssembliesWithPartsInternal()
  60. {
  61. var list = new List<Assembly>();
  62. list.Add(GetType().Assembly);
  63. list.AddRange(GetLinuxAssemblies());
  64. return list;
  65. }
  66. private IEnumerable<Assembly> GetLinuxAssemblies()
  67. {
  68. var list = new List<Assembly>();
  69. list.Add(typeof(LinuxIsoManager).Assembly);
  70. return list;
  71. }
  72. protected override void ShutdownInternal()
  73. {
  74. MainClass.Shutdown();
  75. }
  76. protected override bool SupportsDualModeSockets
  77. {
  78. get
  79. {
  80. return GetMonoVersion() >= new Version(4, 6);
  81. }
  82. }
  83. private static Version GetMonoVersion()
  84. {
  85. Type type = Type.GetType("Mono.Runtime");
  86. if (type != null)
  87. {
  88. MethodInfo displayName = type.GetTypeInfo().GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
  89. var displayNameValue = displayName.Invoke(null, null).ToString().Trim().Split(' ')[0];
  90. Version version;
  91. if (Version.TryParse(displayNameValue, out version))
  92. {
  93. return version;
  94. }
  95. }
  96. return new Version(1, 0);
  97. }
  98. protected override void AuthorizeServer()
  99. {
  100. throw new NotImplementedException();
  101. }
  102. protected override IDbConnector GetDbConnector()
  103. {
  104. return new DbConnector(Logger);
  105. }
  106. protected override void ConfigureAutoRunInternal(bool autorun)
  107. {
  108. throw new NotImplementedException();
  109. }
  110. public override void LaunchUrl(string url)
  111. {
  112. throw new NotImplementedException();
  113. }
  114. protected override void EnableLoopbackInternal(string appName)
  115. {
  116. }
  117. public override bool SupportsRunningAsService
  118. {
  119. get
  120. {
  121. return false;
  122. }
  123. }
  124. public override bool SupportsAutoRunAtStartup
  125. {
  126. get { return false; }
  127. }
  128. public override bool IsRunningAsService
  129. {
  130. get
  131. {
  132. return false;
  133. }
  134. }
  135. }
  136. }