2
0

SystemManager.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System.Linq;
  2. using System.Threading.Tasks;
  3. using MediaBrowser.Common.Configuration;
  4. using MediaBrowser.Common.Updates;
  5. using MediaBrowser.Controller;
  6. using MediaBrowser.Controller.Configuration;
  7. using MediaBrowser.Model.System;
  8. using Microsoft.AspNetCore.Http;
  9. using Microsoft.Extensions.Hosting;
  10. namespace Emby.Server.Implementations;
  11. /// <inheritdoc />
  12. public class SystemManager : ISystemManager
  13. {
  14. private readonly IHostApplicationLifetime _applicationLifetime;
  15. private readonly IServerApplicationHost _applicationHost;
  16. private readonly IServerApplicationPaths _applicationPaths;
  17. private readonly IServerConfigurationManager _configurationManager;
  18. private readonly IStartupOptions _startupOptions;
  19. private readonly IInstallationManager _installationManager;
  20. /// <summary>
  21. /// Initializes a new instance of the <see cref="SystemManager"/> class.
  22. /// </summary>
  23. /// <param name="applicationLifetime">Instance of <see cref="IHostApplicationLifetime"/>.</param>
  24. /// <param name="applicationHost">Instance of <see cref="IServerApplicationHost"/>.</param>
  25. /// <param name="applicationPaths">Instance of <see cref="IServerApplicationPaths"/>.</param>
  26. /// <param name="configurationManager">Instance of <see cref="IServerConfigurationManager"/>.</param>
  27. /// <param name="startupOptions">Instance of <see cref="IStartupOptions"/>.</param>
  28. /// <param name="installationManager">Instance of <see cref="IInstallationManager"/>.</param>
  29. public SystemManager(
  30. IHostApplicationLifetime applicationLifetime,
  31. IServerApplicationHost applicationHost,
  32. IServerApplicationPaths applicationPaths,
  33. IServerConfigurationManager configurationManager,
  34. IStartupOptions startupOptions,
  35. IInstallationManager installationManager)
  36. {
  37. _applicationLifetime = applicationLifetime;
  38. _applicationHost = applicationHost;
  39. _applicationPaths = applicationPaths;
  40. _configurationManager = configurationManager;
  41. _startupOptions = startupOptions;
  42. _installationManager = installationManager;
  43. }
  44. /// <inheritdoc />
  45. public SystemInfo GetSystemInfo(HttpRequest request)
  46. {
  47. return new SystemInfo
  48. {
  49. HasPendingRestart = _applicationHost.HasPendingRestart,
  50. IsShuttingDown = _applicationLifetime.ApplicationStopping.IsCancellationRequested,
  51. Version = _applicationHost.ApplicationVersionString,
  52. WebSocketPortNumber = _applicationHost.HttpPort,
  53. CompletedInstallations = _installationManager.CompletedInstallations.ToArray(),
  54. Id = _applicationHost.SystemId,
  55. ProgramDataPath = _applicationPaths.ProgramDataPath,
  56. WebPath = _applicationPaths.WebPath,
  57. LogPath = _applicationPaths.LogDirectoryPath,
  58. ItemsByNamePath = _applicationPaths.InternalMetadataPath,
  59. InternalMetadataPath = _applicationPaths.InternalMetadataPath,
  60. CachePath = _applicationPaths.CachePath,
  61. TranscodingTempPath = _configurationManager.GetTranscodePath(),
  62. ServerName = _applicationHost.FriendlyName,
  63. LocalAddress = _applicationHost.GetSmartApiUrl(request),
  64. SupportsLibraryMonitor = true,
  65. PackageName = _startupOptions.PackageName,
  66. CastReceiverApplications = _configurationManager.Configuration.CastReceiverApplications
  67. };
  68. }
  69. /// <inheritdoc />
  70. public PublicSystemInfo GetPublicSystemInfo(HttpRequest request)
  71. {
  72. return new PublicSystemInfo
  73. {
  74. Version = _applicationHost.ApplicationVersionString,
  75. ProductName = _applicationHost.Name,
  76. Id = _applicationHost.SystemId,
  77. ServerName = _applicationHost.FriendlyName,
  78. LocalAddress = _applicationHost.GetSmartApiUrl(request),
  79. StartupWizardCompleted = _configurationManager.CommonConfiguration.IsStartupWizardCompleted
  80. };
  81. }
  82. /// <inheritdoc />
  83. public void Restart() => ShutdownInternal(true);
  84. /// <inheritdoc />
  85. public void Shutdown() => ShutdownInternal(false);
  86. private void ShutdownInternal(bool restart)
  87. {
  88. Task.Run(async () =>
  89. {
  90. await Task.Delay(100).ConfigureAwait(false);
  91. _applicationHost.ShouldRestart = restart;
  92. _applicationLifetime.StopApplication();
  93. });
  94. }
  95. }