diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2019-03-27 21:35:09 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-27 21:35:09 -0400 |
| commit | 2dbc1153e8b96d562a5e4489e6fe883e8711839f (patch) | |
| tree | da403647315cd7910a33dfbb197cc81c8045e939 /Emby.Server.Implementations | |
| parent | cc2edc4d6693cb2fc9c612ad307f554fc1b46d23 (diff) | |
| parent | c6188e26afa0034c5c255a19b2fc71aa42311e26 (diff) | |
Merge pull request #934 from Bond-009/plugin
WIP - Don't require a restart for 75% of plugins
Diffstat (limited to 'Emby.Server.Implementations')
| -rw-r--r-- | Emby.Server.Implementations/ApplicationHost.cs | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index a265d5418..1c9a4776a 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -173,11 +173,17 @@ namespace Emby.Server.Implementations /// <value>The logger.</value> protected ILogger Logger { get; set; } + private IPlugin[] _plugins; + /// <summary> /// Gets the plugins. /// </summary> /// <value>The plugins.</value> - public IPlugin[] Plugins { get; protected set; } + public IPlugin[] Plugins + { + get => _plugins; + protected set => _plugins = value; + } /// <summary> /// Gets or sets the logger factory. @@ -1036,6 +1042,41 @@ namespace Emby.Server.Implementations CollectionFolder.JsonSerializer = JsonSerializer; CollectionFolder.ApplicationHost = this; AuthenticatedAttribute.AuthService = AuthService; + + InstallationManager.PluginInstalled += PluginInstalled; + } + + private async void PluginInstalled(object sender, GenericEventArgs<PackageVersionInfo> args) + { + string dir = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(args.Argument.targetFilename)); + var types = Directory.EnumerateFiles(dir, "*.dll", SearchOption.TopDirectoryOnly) + .Select(x => Assembly.LoadFrom(x)) + .SelectMany(x => x.ExportedTypes) + .Where(x => x.IsClass && !x.IsAbstract && !x.IsInterface && !x.IsGenericType) + .ToList(); + + types.AddRange(types); + + var plugins = types.Where(x => x.IsAssignableFrom(typeof(IPlugin))) + .Select(CreateInstanceSafe) + .Where(x => x != null) + .Cast<IPlugin>() + .Select(LoadPlugin) + .Where(x => x != null) + .ToArray(); + + int oldLen = _plugins.Length; + Array.Resize<IPlugin>(ref _plugins, _plugins.Length + plugins.Length); + plugins.CopyTo(_plugins, oldLen); + + var entries = types.Where(x => x.IsAssignableFrom(typeof(IServerEntryPoint))) + .Select(CreateInstanceSafe) + .Where(x => x != null) + .Cast<IServerEntryPoint>() + .ToList(); + + await Task.WhenAll(StartEntryPoints(entries, true)); + await Task.WhenAll(StartEntryPoints(entries, false)); } /// <summary> |
