aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/ApplicationHost.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/ApplicationHost.cs')
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs124
1 files changed, 36 insertions, 88 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 1bacd8aef..8c625539a 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -88,7 +88,6 @@ using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.Diagnostics;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Events;
-using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
@@ -110,9 +109,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
-using ServiceStack;
+using Microsoft.OpenApi.Models;
using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace Emby.Server.Implementations
@@ -232,7 +230,25 @@ namespace Emby.Server.Implementations
}
}
- protected IServiceProvider _serviceProvider;
+ /// <summary>
+ /// Gets or sets the service provider.
+ /// </summary>
+ public IServiceProvider ServiceProvider { get; set; }
+
+ /// <summary>
+ /// Gets the http port for the webhost.
+ /// </summary>
+ public int HttpPort { get; private set; }
+
+ /// <summary>
+ /// Gets the https port for the webhost.
+ /// </summary>
+ public int HttpsPort { get; private set; }
+
+ /// <summary>
+ /// Gets the content root for the webhost.
+ /// </summary>
+ public string ContentRoot { get; private set; }
/// <summary>
/// Gets the server configuration manager.
@@ -461,7 +477,7 @@ namespace Emby.Server.Implementations
/// <param name="type">The type.</param>
/// <returns>System.Object.</returns>
public object CreateInstance(Type type)
- => ActivatorUtilities.CreateInstance(_serviceProvider, type);
+ => ActivatorUtilities.CreateInstance(ServiceProvider, type);
/// <summary>
/// Creates an instance of type and resolves all constructor dependencies.
@@ -469,7 +485,7 @@ namespace Emby.Server.Implementations
/// /// <typeparam name="T">The type.</typeparam>
/// <returns>T.</returns>
public T CreateInstance<T>()
- => ActivatorUtilities.CreateInstance<T>(_serviceProvider);
+ => ActivatorUtilities.CreateInstance<T>(ServiceProvider);
/// <summary>
/// Creates the instance safe.
@@ -481,7 +497,7 @@ namespace Emby.Server.Implementations
try
{
Logger.LogDebug("Creating instance of {Type}", type);
- return ActivatorUtilities.CreateInstance(_serviceProvider, type);
+ return ActivatorUtilities.CreateInstance(ServiceProvider, type);
}
catch (Exception ex)
{
@@ -495,7 +511,7 @@ namespace Emby.Server.Implementations
/// </summary>
/// <typeparam name="T">The type</typeparam>
/// <returns>``0.</returns>
- public T Resolve<T>() => _serviceProvider.GetService<T>();
+ public T Resolve<T>() => ServiceProvider.GetService<T>();
/// <summary>
/// Gets the export types.
@@ -612,77 +628,14 @@ namespace Emby.Server.Implementations
await RegisterResources(serviceCollection).ConfigureAwait(false);
- FindParts();
-
- string contentRoot = ServerConfigurationManager.Configuration.DashboardSourcePath;
- if (string.IsNullOrEmpty(contentRoot))
- {
- contentRoot = ServerConfigurationManager.ApplicationPaths.WebPath;
- }
-
- var host = new WebHostBuilder()
- .UseKestrel(options =>
- {
- var addresses = ServerConfigurationManager
- .Configuration
- .LocalNetworkAddresses
- .Select(NormalizeConfiguredLocalAddress)
- .Where(i => i != null)
- .ToList();
- if (addresses.Any())
- {
- foreach (var address in addresses)
- {
- Logger.LogInformation("Kestrel listening on {ipaddr}", address);
- options.Listen(address, HttpPort);
-
- if (EnableHttps && Certificate != null)
- {
- options.Listen(address, HttpsPort, listenOptions => listenOptions.UseHttps(Certificate));
- }
- }
- }
- else
- {
- Logger.LogInformation("Kestrel listening on all interfaces");
- options.ListenAnyIP(HttpPort);
-
- if (EnableHttps && Certificate != null)
- {
- options.ListenAnyIP(HttpsPort, listenOptions => listenOptions.UseHttps(Certificate));
- }
- }
- })
- .UseContentRoot(contentRoot)
- .ConfigureServices(services =>
- {
- services.AddResponseCompression();
- services.AddHttpContextAccessor();
- })
- .Configure(app =>
- {
- app.UseWebSockets();
-
- app.UseResponseCompression();
-
- // TODO app.UseMiddleware<WebSocketMiddleware>();
- app.Use(ExecuteWebsocketHandlerAsync);
- app.Use(ExecuteHttpHandlerAsync);
- })
- .Build();
-
- try
- {
- await host.StartAsync().ConfigureAwait(false);
- }
- catch
+ ContentRoot = ServerConfigurationManager.Configuration.DashboardSourcePath;
+ if (string.IsNullOrEmpty(ContentRoot))
{
- Logger.LogError("Kestrel failed to start! This is most likely due to an invalid address or port bind - correct your bind configuration in system.xml and try again.");
- throw;
+ ContentRoot = ServerConfigurationManager.ApplicationPaths.WebPath;
}
}
- private async Task ExecuteWebsocketHandlerAsync(HttpContext context, Func<Task> next)
+ public async Task ExecuteWebsocketHandlerAsync(HttpContext context, Func<Task> next)
{
if (!context.WebSockets.IsWebSocketRequest)
{
@@ -693,7 +646,7 @@ namespace Emby.Server.Implementations
await HttpServer.ProcessWebSocketRequest(context).ConfigureAwait(false);
}
- private async Task ExecuteHttpHandlerAsync(HttpContext context, Func<Task> next)
+ public async Task ExecuteHttpHandlerAsync(HttpContext context, Func<Task> next)
{
if (context.WebSockets.IsWebSocketRequest)
{
@@ -911,7 +864,7 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton<IAuthorizationContext>(authContext);
serviceCollection.AddSingleton<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager));
- AuthService = new AuthService(authContext, ServerConfigurationManager, SessionManager, NetworkManager);
+ AuthService = new AuthService(LoggerFactory.CreateLogger<AuthService>(), authContext, ServerConfigurationManager, SessionManager, NetworkManager);
serviceCollection.AddSingleton(AuthService);
SubtitleEncoder = new MediaBrowser.MediaEncoding.Subtitles.SubtitleEncoder(LibraryManager, LoggerFactory, ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer, HttpClient, MediaSourceManager, ProcessFactory);
@@ -930,8 +883,6 @@ namespace Emby.Server.Implementations
((UserDataManager)UserDataManager).Repository = userDataRepo;
ItemRepository.Initialize(userDataRepo, UserManager);
((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
-
- _serviceProvider = serviceCollection.BuildServiceProvider();
}
public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths)
@@ -1088,9 +1039,9 @@ namespace Emby.Server.Implementations
/// <summary>
/// Finds the parts.
/// </summary>
- protected void FindParts()
+ public void FindParts()
{
- InstallationManager = _serviceProvider.GetService<IInstallationManager>();
+ InstallationManager = ServiceProvider.GetService<IInstallationManager>();
InstallationManager.PluginInstalled += PluginInstalled;
if (!ServerConfigurationManager.Configuration.IsPortAuthorized)
@@ -1219,7 +1170,7 @@ namespace Emby.Server.Implementations
private CertificateInfo CertificateInfo { get; set; }
- protected X509Certificate2 Certificate { get; private set; }
+ public X509Certificate2 Certificate { get; private set; }
private IEnumerable<string> GetUrlPrefixes()
{
@@ -1435,6 +1386,7 @@ namespace Emby.Server.Implementations
public async Task<SystemInfo> GetSystemInfo(CancellationToken cancellationToken)
{
var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false);
+ var transcodingTempPath = ConfigurationManager.GetTranscodePath();
return new SystemInfo
{
@@ -1458,7 +1410,7 @@ namespace Emby.Server.Implementations
CanSelfRestart = CanSelfRestart,
CanLaunchWebBrowser = CanLaunchWebBrowser,
HasUpdateAvailable = HasUpdateAvailable,
- TranscodingTempPath = ApplicationPaths.TranscodePath,
+ TranscodingTempPath = transcodingTempPath,
ServerName = FriendlyName,
LocalAddress = localAddress,
SupportsLibraryMonitor = true,
@@ -1603,7 +1555,7 @@ namespace Emby.Server.Implementations
return resultList;
}
- private IPAddress NormalizeConfiguredLocalAddress(string address)
+ public IPAddress NormalizeConfiguredLocalAddress(string address)
{
var index = address.Trim('/').IndexOf('/');
@@ -1679,10 +1631,6 @@ namespace Emby.Server.Implementations
? Environment.MachineName
: ServerConfigurationManager.Configuration.ServerName;
- public int HttpPort { get; private set; }
-
- public int HttpsPort { get; private set; }
-
/// <summary>
/// Shuts down.
/// </summary>