# Conflicts: # Emby.Server.Implementations/Net/SocketFactory.cs # RSSDP/SsdpCommunicationsServer.cs # RSSDP/SsdpDeviceLocator.cs # RSSDP/SsdpDevicePublisher.cspull/10366/head
commit
8d7e4229ca
@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Updates;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Model.System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Emby.Server.Implementations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class SystemManager : ISystemManager
|
||||
{
|
||||
private readonly IHostApplicationLifetime _applicationLifetime;
|
||||
private readonly IServerApplicationHost _applicationHost;
|
||||
private readonly IServerApplicationPaths _applicationPaths;
|
||||
private readonly IServerConfigurationManager _configurationManager;
|
||||
private readonly IStartupOptions _startupOptions;
|
||||
private readonly IInstallationManager _installationManager;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SystemManager"/> class.
|
||||
/// </summary>
|
||||
/// <param name="applicationLifetime">Instance of <see cref="IHostApplicationLifetime"/>.</param>
|
||||
/// <param name="applicationHost">Instance of <see cref="IServerApplicationHost"/>.</param>
|
||||
/// <param name="applicationPaths">Instance of <see cref="IServerApplicationPaths"/>.</param>
|
||||
/// <param name="configurationManager">Instance of <see cref="IServerConfigurationManager"/>.</param>
|
||||
/// <param name="startupOptions">Instance of <see cref="IStartupOptions"/>.</param>
|
||||
/// <param name="installationManager">Instance of <see cref="IInstallationManager"/>.</param>
|
||||
public SystemManager(
|
||||
IHostApplicationLifetime applicationLifetime,
|
||||
IServerApplicationHost applicationHost,
|
||||
IServerApplicationPaths applicationPaths,
|
||||
IServerConfigurationManager configurationManager,
|
||||
IStartupOptions startupOptions,
|
||||
IInstallationManager installationManager)
|
||||
{
|
||||
_applicationLifetime = applicationLifetime;
|
||||
_applicationHost = applicationHost;
|
||||
_applicationPaths = applicationPaths;
|
||||
_configurationManager = configurationManager;
|
||||
_startupOptions = startupOptions;
|
||||
_installationManager = installationManager;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public SystemInfo GetSystemInfo(HttpRequest request)
|
||||
{
|
||||
return new SystemInfo
|
||||
{
|
||||
HasPendingRestart = _applicationHost.HasPendingRestart,
|
||||
IsShuttingDown = _applicationLifetime.ApplicationStopping.IsCancellationRequested,
|
||||
Version = _applicationHost.ApplicationVersionString,
|
||||
WebSocketPortNumber = _applicationHost.HttpPort,
|
||||
CompletedInstallations = _installationManager.CompletedInstallations.ToArray(),
|
||||
Id = _applicationHost.SystemId,
|
||||
ProgramDataPath = _applicationPaths.ProgramDataPath,
|
||||
WebPath = _applicationPaths.WebPath,
|
||||
LogPath = _applicationPaths.LogDirectoryPath,
|
||||
ItemsByNamePath = _applicationPaths.InternalMetadataPath,
|
||||
InternalMetadataPath = _applicationPaths.InternalMetadataPath,
|
||||
CachePath = _applicationPaths.CachePath,
|
||||
TranscodingTempPath = _configurationManager.GetTranscodePath(),
|
||||
ServerName = _applicationHost.FriendlyName,
|
||||
LocalAddress = _applicationHost.GetSmartApiUrl(request),
|
||||
SupportsLibraryMonitor = true,
|
||||
PackageName = _startupOptions.PackageName
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public PublicSystemInfo GetPublicSystemInfo(HttpRequest request)
|
||||
{
|
||||
return new PublicSystemInfo
|
||||
{
|
||||
Version = _applicationHost.ApplicationVersionString,
|
||||
ProductName = _applicationHost.Name,
|
||||
Id = _applicationHost.SystemId,
|
||||
ServerName = _applicationHost.FriendlyName,
|
||||
LocalAddress = _applicationHost.GetSmartApiUrl(request),
|
||||
StartupWizardCompleted = _configurationManager.CommonConfiguration.IsStartupWizardCompleted
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Restart() => ShutdownInternal(true);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Shutdown() => ShutdownInternal(false);
|
||||
|
||||
private void ShutdownInternal(bool restart)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100).ConfigureAwait(false);
|
||||
_applicationHost.ShouldRestart = restart;
|
||||
_applicationLifetime.StopApplication();
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,193 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Provides extension methods for <see cref="XmlReader"/> to parse <see cref="BaseItem"/>'s.
|
||||
/// </summary>
|
||||
public static class XmlReaderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads a trimmed string from the current node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <returns>The trimmed content.</returns>
|
||||
public static string ReadNormalizedString(this XmlReader reader)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
|
||||
return reader.ReadElementContentAsString().Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an int from the current node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <param name="value">The parsed <c>int</c>.</param>
|
||||
/// <returns>A value indicating whether the parsing succeeded.</returns>
|
||||
public static bool TryReadInt(this XmlReader reader, out int value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
|
||||
return int.TryParse(reader.ReadElementContentAsString(), CultureInfo.InvariantCulture, out value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a <see cref="DateTime"/> from the current node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <param name="value">The parsed <see cref="DateTime"/>.</param>
|
||||
/// <returns>A value indicating whether the parsing succeeded.</returns>
|
||||
public static bool TryReadDateTime(this XmlReader reader, out DateTime value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
|
||||
return DateTime.TryParse(
|
||||
reader.ReadElementContentAsString(),
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a <see cref="DateTime"/> from the current node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <param name="formatString">The date format string.</param>
|
||||
/// <param name="value">The parsed <see cref="DateTime"/>.</param>
|
||||
/// <returns>A value indicating whether the parsing succeeded.</returns>
|
||||
public static bool TryReadDateTimeExact(this XmlReader reader, string formatString, out DateTime value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
ArgumentNullException.ThrowIfNull(formatString);
|
||||
|
||||
return DateTime.TryParseExact(
|
||||
reader.ReadElementContentAsString(),
|
||||
formatString,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a <see cref="PersonInfo"/> from the xml node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <returns>A <see cref="PersonInfo"/>, or <c>null</c> if none is found.</returns>
|
||||
public static PersonInfo? GetPersonFromXmlNode(this XmlReader reader)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
|
||||
if (reader.IsEmptyElement)
|
||||
{
|
||||
reader.Read();
|
||||
return null;
|
||||
}
|
||||
|
||||
var name = string.Empty;
|
||||
var type = PersonKind.Actor; // If type is not specified assume actor
|
||||
var role = string.Empty;
|
||||
int? sortOrder = null;
|
||||
string? imageUrl = null;
|
||||
|
||||
using var subtree = reader.ReadSubtree();
|
||||
subtree.MoveToContent();
|
||||
subtree.Read();
|
||||
|
||||
while (subtree is { EOF: false, ReadState: ReadState.Interactive })
|
||||
{
|
||||
if (subtree.NodeType != XmlNodeType.Element)
|
||||
{
|
||||
subtree.Read();
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (subtree.Name)
|
||||
{
|
||||
case "name":
|
||||
case "Name":
|
||||
name = subtree.ReadNormalizedString();
|
||||
break;
|
||||
case "role":
|
||||
case "Role":
|
||||
role = subtree.ReadNormalizedString();
|
||||
break;
|
||||
case "type":
|
||||
case "Type":
|
||||
Enum.TryParse(subtree.ReadElementContentAsString(), true, out type);
|
||||
break;
|
||||
case "order":
|
||||
case "sortorder":
|
||||
case "SortOrder":
|
||||
if (subtree.TryReadInt(out var sortOrderVal))
|
||||
{
|
||||
sortOrder = sortOrderVal;
|
||||
}
|
||||
|
||||
break;
|
||||
case "thumb":
|
||||
imageUrl = subtree.ReadNormalizedString();
|
||||
break;
|
||||
default:
|
||||
subtree.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PersonInfo
|
||||
{
|
||||
Name = name,
|
||||
Role = role,
|
||||
Type = type,
|
||||
SortOrder = sortOrder,
|
||||
ImageUrl = imageUrl
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to split names of comma or pipe delimited genres and people.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <returns>IEnumerable{System.String}.</returns>
|
||||
public static IEnumerable<string> GetStringArray(this XmlReader reader)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
var value = reader.ReadElementContentAsString();
|
||||
|
||||
// Only split by comma if there is no pipe in the string
|
||||
// We have to be careful to not split names like Matthew, Jr.
|
||||
var separator = !value.Contains('|', StringComparison.Ordinal)
|
||||
&& !value.Contains(';', StringComparison.Ordinal)
|
||||
? new[] { ',' }
|
||||
: new[] { '|', ';' };
|
||||
|
||||
foreach (var part in value.Trim().Trim(separator).Split(separator))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(part))
|
||||
{
|
||||
yield return part.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a <see cref="PersonInfo"/> array from the xml node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <param name="personKind">The <see cref="PersonKind"/>.</param>
|
||||
/// <returns>The <see cref="IEnumerable{PersonInfo}"/>.</returns>
|
||||
public static IEnumerable<PersonInfo> GetPersonArray(this XmlReader reader, PersonKind personKind)
|
||||
=> reader.GetStringArray()
|
||||
.Select(part => new PersonInfo { Name = part, Type = personKind });
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using MediaBrowser.Model.System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace MediaBrowser.Controller;
|
||||
|
||||
/// <summary>
|
||||
/// A service for managing the application instance.
|
||||
/// </summary>
|
||||
public interface ISystemManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the system info.
|
||||
/// </summary>
|
||||
/// <param name="request">The HTTP request.</param>
|
||||
/// <returns>The <see cref="SystemInfo"/>.</returns>
|
||||
SystemInfo GetSystemInfo(HttpRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the public system info.
|
||||
/// </summary>
|
||||
/// <param name="request">The HTTP request.</param>
|
||||
/// <returns>The <see cref="PublicSystemInfo"/>.</returns>
|
||||
PublicSystemInfo GetPublicSystemInfo(HttpRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Starts the application restart process.
|
||||
/// </summary>
|
||||
void Restart();
|
||||
|
||||
/// <summary>
|
||||
/// Starts the application shutdown process.
|
||||
/// </summary>
|
||||
void Shutdown();
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
namespace MediaBrowser.Model.Net;
|
||||
|
||||
/// <summary>
|
||||
/// Class holding information for a published server URI override.
|
||||
/// </summary>
|
||||
public class PublishedServerUriOverride
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PublishedServerUriOverride"/> class.
|
||||
/// </summary>
|
||||
/// <param name="data">The <see cref="IPData"/>.</param>
|
||||
/// <param name="overrideUri">The override.</param>
|
||||
/// <param name="internalOverride">A value indicating whether the override is for internal requests.</param>
|
||||
/// <param name="externalOverride">A value indicating whether the override is for external requests.</param>
|
||||
public PublishedServerUriOverride(IPData data, string overrideUri, bool internalOverride, bool externalOverride)
|
||||
{
|
||||
Data = data;
|
||||
OverrideUri = overrideUri;
|
||||
IsInternalOverride = internalOverride;
|
||||
IsExternalOverride = externalOverride;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the object's IP address.
|
||||
/// </summary>
|
||||
public IPData Data { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the override URI.
|
||||
/// </summary>
|
||||
public string OverrideUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the override should be applied to internal requests.
|
||||
/// </summary>
|
||||
public bool IsInternalOverride { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the override should be applied to external requests.
|
||||
/// </summary>
|
||||
public bool IsExternalOverride { get; set; }
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue