mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Update ApplicationHost.cs
This commit is contained in:
parent
0738a2dc4b
commit
ba685d8092
@ -128,7 +128,7 @@ namespace Emby.Server.Implementations
|
|||||||
private ISessionManager _sessionManager;
|
private ISessionManager _sessionManager;
|
||||||
private IHttpClientFactory _httpClientFactory;
|
private IHttpClientFactory _httpClientFactory;
|
||||||
private IWebSocketManager _webSocketManager;
|
private IWebSocketManager _webSocketManager;
|
||||||
|
private Dictionary<Type, Assembly> _pluginRegistrations;
|
||||||
private string[] _urlPrefixes;
|
private string[] _urlPrefixes;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -262,6 +262,8 @@ namespace Emby.Server.Implementations
|
|||||||
|
|
||||||
ServiceCollection = serviceCollection;
|
ServiceCollection = serviceCollection;
|
||||||
|
|
||||||
|
_pluginRegistrations = new Dictionary<Type, Assembly>();
|
||||||
|
|
||||||
_networkManager = networkManager;
|
_networkManager = networkManager;
|
||||||
networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets;
|
networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets;
|
||||||
|
|
||||||
@ -499,24 +501,11 @@ namespace Emby.Server.Implementations
|
|||||||
HttpsPort = ServerConfiguration.DefaultHttpsPort;
|
HttpsPort = ServerConfiguration.DefaultHttpsPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Plugins != null)
|
|
||||||
{
|
|
||||||
var pluginBuilder = new StringBuilder();
|
|
||||||
|
|
||||||
foreach (var plugin in Plugins)
|
|
||||||
{
|
|
||||||
pluginBuilder.Append(plugin.Name)
|
|
||||||
.Append(' ')
|
|
||||||
.Append(plugin.Version)
|
|
||||||
.AppendLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.LogInformation("Plugins: {Plugins}", pluginBuilder.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscoverTypes();
|
DiscoverTypes();
|
||||||
|
|
||||||
RegisterServices();
|
RegisterServices();
|
||||||
|
|
||||||
|
RegisterPlugIns();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -781,10 +770,24 @@ namespace Emby.Server.Implementations
|
|||||||
|
|
||||||
ConfigurationManager.AddParts(GetExports<IConfigurationFactory>());
|
ConfigurationManager.AddParts(GetExports<IConfigurationFactory>());
|
||||||
_plugins = GetExports<IPlugin>()
|
_plugins = GetExports<IPlugin>()
|
||||||
.Select(LoadPlugin)
|
|
||||||
.Where(i => i != null)
|
.Where(i => i != null)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
if (Plugins != null)
|
||||||
|
{
|
||||||
|
var pluginBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
foreach (var plugin in Plugins)
|
||||||
|
{
|
||||||
|
pluginBuilder.Append(plugin.Name)
|
||||||
|
.Append(' ')
|
||||||
|
.Append(plugin.Version)
|
||||||
|
.AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.LogInformation("Plugins: {Plugins}", pluginBuilder.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
_urlPrefixes = GetUrlPrefixes().ToArray();
|
_urlPrefixes = GetUrlPrefixes().ToArray();
|
||||||
_webSocketManager.Init(GetExports<IWebSocketListener>());
|
_webSocketManager.Init(GetExports<IWebSocketListener>());
|
||||||
|
|
||||||
@ -850,8 +853,6 @@ namespace Emby.Server.Implementations
|
|||||||
{
|
{
|
||||||
hasPluginConfiguration.SetStartupInfo(s => Directory.CreateDirectory(s));
|
hasPluginConfiguration.SetStartupInfo(s => Directory.CreateDirectory(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.RegisterServices(ServiceCollection);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -872,6 +873,24 @@ namespace Emby.Server.Implementations
|
|||||||
_allConcreteTypes = GetTypes(GetComposablePartAssemblies()).ToArray();
|
_allConcreteTypes = GetTypes(GetComposablePartAssemblies()).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RegisterPlugIns()
|
||||||
|
{
|
||||||
|
foreach ((var pluginType, var assembly) in _pluginRegistrations)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var pluginRegistration = Activator.CreateInstance(pluginType);
|
||||||
|
pluginType.InvokeMember("RegisterServices", BindingFlags.InvokeMethod, null, pluginRegistration, new object[] { ServiceCollection }, CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError(ex, "Error registering {Assembly} with D.I.", assembly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_pluginRegistrations.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerable<Type> GetTypes(IEnumerable<Assembly> assemblies)
|
private IEnumerable<Type> GetTypes(IEnumerable<Assembly> assemblies)
|
||||||
{
|
{
|
||||||
foreach (var ass in assemblies)
|
foreach (var ass in assemblies)
|
||||||
@ -881,19 +900,10 @@ namespace Emby.Server.Implementations
|
|||||||
{
|
{
|
||||||
exportedTypes = ass.GetExportedTypes();
|
exportedTypes = ass.GetExportedTypes();
|
||||||
|
|
||||||
try
|
Type reg = (Type)exportedTypes.Where(p => string.Equals(p.Name, "PluginRegistration", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||||
|
if (reg != null)
|
||||||
{
|
{
|
||||||
Type reg = (Type)exportedTypes.Where(p => string.Equals(p.Name, "PluginRegistration", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
_pluginRegistrations.Add(ass, reg);
|
||||||
if (reg != null)
|
|
||||||
{
|
|
||||||
var pluginRegistration = Activator.CreateInstance(reg);
|
|
||||||
reg.InvokeMember("RegisterServices", BindingFlags.InvokeMethod, null, pluginRegistration, new object[] { ServiceCollection }, CultureInfo.InvariantCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.LogError(ex, "Error registering {Assembly} with D.I.", ass.FullName);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException ex)
|
catch (FileNotFoundException ex)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user