< 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: 46
Coverable lines: 46
Total lines: 103
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            WebSocketPortNumber = _applicationHost.HttpPort,
 057            CompletedInstallations = _installationManager.CompletedInstallations.ToArray(),
 058            Id = _applicationHost.SystemId,
 059            ProgramDataPath = _applicationPaths.ProgramDataPath,
 060            WebPath = _applicationPaths.WebPath,
 061            LogPath = _applicationPaths.LogDirectoryPath,
 062            ItemsByNamePath = _applicationPaths.InternalMetadataPath,
 063            InternalMetadataPath = _applicationPaths.InternalMetadataPath,
 064            CachePath = _applicationPaths.CachePath,
 065            TranscodingTempPath = _configurationManager.GetTranscodePath(),
 066            ServerName = _applicationHost.FriendlyName,
 067            LocalAddress = _applicationHost.GetSmartApiUrl(request),
 068            SupportsLibraryMonitor = true,
 069            PackageName = _startupOptions.PackageName,
 070            CastReceiverApplications = _configurationManager.Configuration.CastReceiverApplications
 071        };
 72    }
 73
 74    /// <inheritdoc />
 75    public PublicSystemInfo GetPublicSystemInfo(HttpRequest request)
 76    {
 077        return new PublicSystemInfo
 078        {
 079            Version = _applicationHost.ApplicationVersionString,
 080            ProductName = _applicationHost.Name,
 081            Id = _applicationHost.SystemId,
 082            ServerName = _applicationHost.FriendlyName,
 083            LocalAddress = _applicationHost.GetSmartApiUrl(request),
 084            StartupWizardCompleted = _configurationManager.CommonConfiguration.IsStartupWizardCompleted
 085        };
 86    }
 87
 88    /// <inheritdoc />
 089    public void Restart() => ShutdownInternal(true);
 90
 91    /// <inheritdoc />
 092    public void Shutdown() => ShutdownInternal(false);
 93
 94    private void ShutdownInternal(bool restart)
 95    {
 096        Task.Run(async () =>
 097        {
 098            await Task.Delay(100).ConfigureAwait(false);
 099            _applicationHost.ShouldRestart = restart;
 0100            _applicationLifetime.StopApplication();
 0101        });
 0102    }
 103}