mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Removed primitives from services in Program.cs
This will make it easier to move dependency registration to a system without having to new up all the services first. Moved the primitives to an IConfiguration which is much easier to inject.
This commit is contained in:
parent
25c2267a89
commit
0d5fbcb031
14
Emby.Server.Implementations/ConfigurationOptions.cs
Normal file
14
Emby.Server.Implementations/ConfigurationOptions.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Emby.Server.Implementations.IO;
|
||||||
|
|
||||||
|
namespace Emby.Server.Implementations
|
||||||
|
{
|
||||||
|
public static class ConfigurationOptions
|
||||||
|
{
|
||||||
|
public static readonly Dictionary<string, string> Configuration = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{"ManagedFileSystem:DefaultDirectory", null},
|
||||||
|
{"ManagedFileSystem:EnableSeparateFileAndDirectoryQueries", "True"}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -46,4 +46,10 @@
|
|||||||
<EmbeddedResource Include="Localization\Ratings\*.csv" />
|
<EmbeddedResource Include="Localization\Ratings\*.csv" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
|
||||||
|
<HintPath>..\..\..\.nuget\packages\microsoft.extensions.configuration.abstractions\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -4,8 +4,10 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
using MediaBrowser.Model.System;
|
using MediaBrowser.Model.System;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Emby.Server.Implementations.IO
|
namespace Emby.Server.Implementations.IO
|
||||||
@ -20,30 +22,30 @@ namespace Emby.Server.Implementations.IO
|
|||||||
private readonly bool _supportsAsyncFileStreams;
|
private readonly bool _supportsAsyncFileStreams;
|
||||||
private char[] _invalidFileNameChars;
|
private char[] _invalidFileNameChars;
|
||||||
private readonly List<IShortcutHandler> _shortcutHandlers = new List<IShortcutHandler>();
|
private readonly List<IShortcutHandler> _shortcutHandlers = new List<IShortcutHandler>();
|
||||||
private bool EnableSeparateFileAndDirectoryQueries;
|
private readonly bool EnableSeparateFileAndDirectoryQueries;
|
||||||
|
|
||||||
private string _tempPath;
|
private readonly string _tempPath;
|
||||||
|
|
||||||
private IEnvironmentInfo _environmentInfo;
|
private readonly IEnvironmentInfo _environmentInfo;
|
||||||
private bool _isEnvironmentCaseInsensitive;
|
private readonly bool _isEnvironmentCaseInsensitive;
|
||||||
|
|
||||||
private string _defaultDirectory;
|
private readonly string _defaultDirectory;
|
||||||
|
|
||||||
public ManagedFileSystem(
|
public ManagedFileSystem(
|
||||||
ILoggerFactory loggerFactory,
|
ILoggerFactory loggerFactory,
|
||||||
IEnvironmentInfo environmentInfo,
|
IEnvironmentInfo environmentInfo,
|
||||||
string defaultDirectory,
|
IApplicationPaths applicationPaths,
|
||||||
string tempPath,
|
IConfiguration configuration)
|
||||||
bool enableSeparateFileAndDirectoryQueries)
|
|
||||||
{
|
{
|
||||||
Logger = loggerFactory.CreateLogger("FileSystem");
|
Logger = loggerFactory.CreateLogger("FileSystem");
|
||||||
_supportsAsyncFileStreams = true;
|
_supportsAsyncFileStreams = true;
|
||||||
_tempPath = tempPath;
|
_tempPath = applicationPaths.TempDirectory;
|
||||||
_environmentInfo = environmentInfo;
|
_environmentInfo = environmentInfo;
|
||||||
_defaultDirectory = defaultDirectory;
|
_defaultDirectory = configuration["ManagedFileSystem:DefaultDirectory"];
|
||||||
|
|
||||||
// On Linux with mono, this needs to be true or symbolic links are ignored
|
// On Linux with mono, this needs to be true or symbolic links are ignored
|
||||||
EnableSeparateFileAndDirectoryQueries = enableSeparateFileAndDirectoryQueries;
|
EnableSeparateFileAndDirectoryQueries =
|
||||||
|
bool.Parse(configuration["ManagedFileSystem:EnableSeparateFileAndDirectoryQueries"]);
|
||||||
|
|
||||||
SetInvalidFileNameChars(environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows);
|
SetInvalidFileNameChars(environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows);
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ namespace Jellyfin.Server
|
|||||||
private static readonly ILoggerFactory _loggerFactory = new SerilogLoggerFactory();
|
private static readonly ILoggerFactory _loggerFactory = new SerilogLoggerFactory();
|
||||||
private static ILogger _logger;
|
private static ILogger _logger;
|
||||||
private static bool _restartOnShutdown;
|
private static bool _restartOnShutdown;
|
||||||
|
private static IConfiguration appConfig;
|
||||||
|
|
||||||
public static async Task Main(string[] args)
|
public static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
@ -78,7 +79,11 @@ namespace Jellyfin.Server
|
|||||||
|
|
||||||
// $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager
|
// $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager
|
||||||
Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath);
|
Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath);
|
||||||
await CreateLogger(appPaths).ConfigureAwait(false);
|
|
||||||
|
appConfig = await CreateConfiguration(appPaths).ConfigureAwait(false);
|
||||||
|
|
||||||
|
await CreateLogger(appConfig, appPaths).ConfigureAwait(false);
|
||||||
|
|
||||||
_logger = _loggerFactory.CreateLogger("Main");
|
_logger = _loggerFactory.CreateLogger("Main");
|
||||||
|
|
||||||
AppDomain.CurrentDomain.UnhandledException += (sender, e)
|
AppDomain.CurrentDomain.UnhandledException += (sender, e)
|
||||||
@ -121,7 +126,7 @@ namespace Jellyfin.Server
|
|||||||
// Allow all https requests
|
// Allow all https requests
|
||||||
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; } );
|
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; } );
|
||||||
|
|
||||||
var fileSystem = new ManagedFileSystem(_loggerFactory, environmentInfo, null, appPaths.TempDirectory, true);
|
var fileSystem = new ManagedFileSystem(_loggerFactory, environmentInfo, appPaths, appConfig);
|
||||||
|
|
||||||
using (var appHost = new CoreAppHost(
|
using (var appHost = new CoreAppHost(
|
||||||
appPaths,
|
appPaths,
|
||||||
@ -309,9 +314,7 @@ namespace Jellyfin.Server
|
|||||||
return new ServerApplicationPaths(dataDir, logDir, configDir, cacheDir);
|
return new ServerApplicationPaths(dataDir, logDir, configDir, cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task CreateLogger(IApplicationPaths appPaths)
|
private static async Task<IConfiguration> CreateConfiguration(IApplicationPaths appPaths)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, "logging.json");
|
string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, "logging.json");
|
||||||
|
|
||||||
@ -326,12 +329,18 @@ namespace Jellyfin.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var configuration = new ConfigurationBuilder()
|
return new ConfigurationBuilder()
|
||||||
.SetBasePath(appPaths.ConfigurationDirectoryPath)
|
.SetBasePath(appPaths.ConfigurationDirectoryPath)
|
||||||
.AddJsonFile("logging.json")
|
.AddJsonFile("logging.json")
|
||||||
.AddEnvironmentVariables("JELLYFIN_")
|
.AddEnvironmentVariables("JELLYFIN_")
|
||||||
|
.AddInMemoryCollection(ConfigurationOptions.Configuration)
|
||||||
.Build();
|
.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task CreateLogger(IConfiguration configuration, IApplicationPaths appPaths)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
// Serilog.Log is used by SerilogLoggerFactory when no logger is specified
|
// Serilog.Log is used by SerilogLoggerFactory when no logger is specified
|
||||||
Serilog.Log.Logger = new LoggerConfiguration()
|
Serilog.Log.Logger = new LoggerConfiguration()
|
||||||
.ReadFrom.Configuration(configuration)
|
.ReadFrom.Configuration(configuration)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user