mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Expose some methods in Program.cs so they can be used to initialize the application for integration tests
This commit is contained in:
parent
3cf2fce983
commit
51b610b999
@ -161,23 +161,7 @@ namespace Jellyfin.Server
|
|||||||
|
|
||||||
ApplicationHost.LogEnvironmentInfo(_logger, appPaths);
|
ApplicationHost.LogEnvironmentInfo(_logger, appPaths);
|
||||||
|
|
||||||
// Make sure we have all the code pages we can get
|
PerformStaticInitialization();
|
||||||
// Ref: https://docs.microsoft.com/en-us/dotnet/api/system.text.codepagesencodingprovider.instance?view=netcore-3.0#remarks
|
|
||||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
||||||
|
|
||||||
// Increase the max http request limit
|
|
||||||
// The default connection limit is 10 for ASP.NET hosted applications and 2 for all others.
|
|
||||||
ServicePointManager.DefaultConnectionLimit = Math.Max(96, ServicePointManager.DefaultConnectionLimit);
|
|
||||||
|
|
||||||
// Disable the "Expect: 100-Continue" header by default
|
|
||||||
// http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c
|
|
||||||
ServicePointManager.Expect100Continue = false;
|
|
||||||
|
|
||||||
Batteries_V2.Init();
|
|
||||||
if (raw.sqlite3_enable_shared_cache(1) != raw.SQLITE_OK)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Failed to enable shared cache for SQLite");
|
|
||||||
}
|
|
||||||
|
|
||||||
var appHost = new CoreAppHost(
|
var appHost = new CoreAppHost(
|
||||||
appPaths,
|
appPaths,
|
||||||
@ -206,7 +190,7 @@ namespace Jellyfin.Server
|
|||||||
ServiceCollection serviceCollection = new ServiceCollection();
|
ServiceCollection serviceCollection = new ServiceCollection();
|
||||||
await appHost.InitAsync(serviceCollection, startupConfig).ConfigureAwait(false);
|
await appHost.InitAsync(serviceCollection, startupConfig).ConfigureAwait(false);
|
||||||
|
|
||||||
var webHost = CreateWebHostBuilder(appHost, serviceCollection, options, startupConfig, appPaths).Build();
|
var webHost = new WebHostBuilder().ConfigureWebHostBuilder(appHost, serviceCollection, options, startupConfig, appPaths).Build();
|
||||||
|
|
||||||
// Re-use the web host service provider in the app host since ASP.NET doesn't allow a custom service collection.
|
// Re-use the web host service provider in the app host since ASP.NET doesn't allow a custom service collection.
|
||||||
appHost.ServiceProvider = webHost.Services;
|
appHost.ServiceProvider = webHost.Services;
|
||||||
@ -252,14 +236,49 @@ namespace Jellyfin.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IWebHostBuilder CreateWebHostBuilder(
|
/// <summary>
|
||||||
|
/// Call static initialization methods for the application.
|
||||||
|
/// </summary>
|
||||||
|
public static void PerformStaticInitialization()
|
||||||
|
{
|
||||||
|
// Make sure we have all the code pages we can get
|
||||||
|
// Ref: https://docs.microsoft.com/en-us/dotnet/api/system.text.codepagesencodingprovider.instance?view=netcore-3.0#remarks
|
||||||
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
|
|
||||||
|
// Increase the max http request limit
|
||||||
|
// The default connection limit is 10 for ASP.NET hosted applications and 2 for all others.
|
||||||
|
ServicePointManager.DefaultConnectionLimit = Math.Max(96, ServicePointManager.DefaultConnectionLimit);
|
||||||
|
|
||||||
|
// Disable the "Expect: 100-Continue" header by default
|
||||||
|
// http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c
|
||||||
|
ServicePointManager.Expect100Continue = false;
|
||||||
|
|
||||||
|
Batteries_V2.Init();
|
||||||
|
if (raw.sqlite3_enable_shared_cache(1) != raw.SQLITE_OK)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Failed to enable shared cache for SQLite");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configure the web host builder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">The builder to configure.</param>
|
||||||
|
/// <param name="appHost">The application host.</param>
|
||||||
|
/// <param name="serviceCollection">The application service collection.</param>
|
||||||
|
/// <param name="commandLineOpts">The command line options passed to the application.</param>
|
||||||
|
/// <param name="startupConfig">The application configuration.</param>
|
||||||
|
/// <param name="appPaths">The application paths.</param>
|
||||||
|
/// <returns>The configured web host builder.</returns>
|
||||||
|
public static IWebHostBuilder ConfigureWebHostBuilder(
|
||||||
|
this IWebHostBuilder builder,
|
||||||
ApplicationHost appHost,
|
ApplicationHost appHost,
|
||||||
IServiceCollection serviceCollection,
|
IServiceCollection serviceCollection,
|
||||||
StartupOptions commandLineOpts,
|
StartupOptions commandLineOpts,
|
||||||
IConfiguration startupConfig,
|
IConfiguration startupConfig,
|
||||||
IApplicationPaths appPaths)
|
IApplicationPaths appPaths)
|
||||||
{
|
{
|
||||||
return new WebHostBuilder()
|
return builder
|
||||||
.UseKestrel((builderContext, options) =>
|
.UseKestrel((builderContext, options) =>
|
||||||
{
|
{
|
||||||
var addresses = appHost.ServerConfigurationManager
|
var addresses = appHost.ServerConfigurationManager
|
||||||
@ -492,7 +511,9 @@ namespace Jellyfin.Server
|
|||||||
/// Initialize the logging configuration file using the bundled resource file as a default if it doesn't exist
|
/// Initialize the logging configuration file using the bundled resource file as a default if it doesn't exist
|
||||||
/// already.
|
/// already.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static async Task InitLoggingConfigFile(IApplicationPaths appPaths)
|
/// <param name="appPaths">The application paths.</param>
|
||||||
|
/// <returns>A task representing the creation of the configuration file, or a completed task if the file already exists.</returns>
|
||||||
|
public static async Task InitLoggingConfigFile(IApplicationPaths appPaths)
|
||||||
{
|
{
|
||||||
// Do nothing if the config file already exists
|
// Do nothing if the config file already exists
|
||||||
string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, LoggingConfigFileDefault);
|
string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, LoggingConfigFileDefault);
|
||||||
@ -512,7 +533,13 @@ namespace Jellyfin.Server
|
|||||||
await resource.CopyToAsync(dst).ConfigureAwait(false);
|
await resource.CopyToAsync(dst).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IConfiguration CreateAppConfiguration(StartupOptions commandLineOpts, IApplicationPaths appPaths)
|
/// <summary>
|
||||||
|
/// Create the application configuration.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="commandLineOpts">The command line options passed to the program.</param>
|
||||||
|
/// <param name="appPaths">The application paths.</param>
|
||||||
|
/// <returns>The application configuration.</returns>
|
||||||
|
public static IConfiguration CreateAppConfiguration(StartupOptions commandLineOpts, IApplicationPaths appPaths)
|
||||||
{
|
{
|
||||||
return new ConfigurationBuilder()
|
return new ConfigurationBuilder()
|
||||||
.ConfigureAppConfiguration(commandLineOpts, appPaths)
|
.ConfigureAppConfiguration(commandLineOpts, appPaths)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user