< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.SystemManager
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/SystemManager.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 48
Coverable lines: 48
Total lines: 105
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetSystemInfo(...)100%210%
GetPublicSystemInfo(...)100%210%
Restart()100%210%
Shutdown()100%210%
ShutdownInternal(...)100%210%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/SystemManager.cs

#LineLine coverage
 1using System.Linq;
 2using System.Threading.Tasks;
 3using MediaBrowser.Common.Configuration;
 4using MediaBrowser.Common.Updates;
 5using MediaBrowser.Controller;
 6using MediaBrowser.Controller.Configuration;
 7using MediaBrowser.Model.System;
 8using Microsoft.AspNetCore.Http;
 9using Microsoft.Extensions.Hosting;
 10
 11namespace Emby.Server.Implementations;
 12
 13/// <inheritdoc />
 14public class SystemManager : ISystemManager
 15{
 16    private readonly IHostApplicationLifetime _applicationLifetime;
 17    private readonly IServerApplicationHost _applicationHost;
 18    private readonly IServerApplicationPaths _applicationPaths;
 19    private readonly IServerConfigurationManager _configurationManager;
 20    private readonly IStartupOptions _startupOptions;
 21    private readonly IInstallationManager _installationManager;
 22
 23    /// <summary>
 24    /// Initializes a new instance of the <see cref="SystemManager"/> class.
 25    /// </summary>
 26    /// <param name="applicationLifetime">Instance of <see cref="IHostApplicationLifetime"/>.</param>
 27    /// <param name="applicationHost">Instance of <see cref="IServerApplicationHost"/>.</param>
 28    /// <param name="applicationPaths">Instance of <see cref="IServerApplicationPaths"/>.</param>
 29    /// <param name="configurationManager">Instance of <see cref="IServerConfigurationManager"/>.</param>
 30    /// <param name="startupOptions">Instance of <see cref="IStartupOptions"/>.</param>
 31    /// <param name="installationManager">Instance of <see cref="IInstallationManager"/>.</param>
 32    public SystemManager(
 33        IHostApplicationLifetime applicationLifetime,
 34        IServerApplicationHost applicationHost,
 35        IServerApplicationPaths applicationPaths,
 36        IServerConfigurationManager configurationManager,
 37        IStartupOptions startupOptions,
 38        IInstallationManager installationManager)
 39    {
 040        _applicationLifetime = applicationLifetime;
 041        _applicationHost = applicationHost;
 042        _applicationPaths = applicationPaths;
 043        _configurationManager = configurationManager;
 044        _startupOptions = startupOptions;
 045        _installationManager = installationManager;
 046    }
 47
 48    /// <inheritdoc />
 49    public SystemInfo GetSystemInfo(HttpRequest request)
 50    {
 051        return new SystemInfo
 052        {
 053            HasPendingRestart = _applicationHost.HasPendingRestart,
 054            IsShuttingDown = _applicationLifetime.ApplicationStopping.IsCancellationRequested,
 055            Version = _applicationHost.ApplicationVersionString,
 056            ProductName = _applicationHost.Name,
 057            WebSocketPortNumber = _applicationHost.HttpPort,
 058            CompletedInstallations = _installationManager.CompletedInstallations.ToArray(),
 059            Id = _applicationHost.SystemId,
 060            ProgramDataPath = _applicationPaths.ProgramDataPath,
 061            WebPath = _applicationPaths.WebPath,
 062            LogPath = _applicationPaths.LogDirectoryPath,
 063            ItemsByNamePath = _applicationPaths.InternalMetadataPath,
 064            InternalMetadataPath = _applicationPaths.InternalMetadataPath,
 065            CachePath = _applicationPaths.CachePath,
 066            TranscodingTempPath = _configurationManager.GetTranscodePath(),
 067            ServerName = _applicationHost.FriendlyName,
 068            LocalAddress = _applicationHost.GetSmartApiUrl(request),
 069            StartupWizardCompleted = _configurationManager.CommonConfiguration.IsStartupWizardCompleted,
 070            SupportsLibraryMonitor = true,
 071            PackageName = _startupOptions.PackageName,
 072            CastReceiverApplications = _configurationManager.Configuration.CastReceiverApplications
 073        };
 74    }
 75
 76    /// <inheritdoc />
 77    public PublicSystemInfo GetPublicSystemInfo(HttpRequest request)
 78    {
 079        return new PublicSystemInfo
 080        {
 081            Version = _applicationHost.ApplicationVersionString,
 082            ProductName = _applicationHost.Name,
 083            Id = _applicationHost.SystemId,
 084            ServerName = _applicationHost.FriendlyName,
 085            LocalAddress = _applicationHost.GetSmartApiUrl(request),
 086            StartupWizardCompleted = _configurationManager.CommonConfiguration.IsStartupWizardCompleted
 087        };
 88    }
 89
 90    /// <inheritdoc />
 091    public void Restart() => ShutdownInternal(true);
 92
 93    /// <inheritdoc />
 094    public void Shutdown() => ShutdownInternal(false);
 95
 96    private void ShutdownInternal(bool restart)
 97    {
 098        Task.Run(async () =>
 099        {
 0100            await Task.Delay(100).ConfigureAwait(false);
 0101            _applicationHost.ShouldRestart = restart;
 0102            _applicationLifetime.StopApplication();
 0103        });
 0104    }
 105}