示例#1
0
        /// <summary>
        ///   Verifies that <paramref name="packageName" /> can be found in the local packages, and
        ///   adds it to the list of loaded plugins. Called by InstallPluginAsync() after a
        ///   successful Install result from the <see cref="PackageManager" />.
        ///   (!!) A lock on PMLock should have been acquired before calling this method.
        /// </summary>
        /// <param name="packageName">The installed package name</param>
        /// <returns>Whether the package has been successfully installed</returns>
        private bool PostInstallPlugin(string packageName)
        {
            var pluginPackage = PackageManager.FindInstalledPluginById(packageName);

            if (pluginPackage == null)
            {
                throw new InvalidOperationException($"Package {packageName} installed successfully but couldn't be found");
            }

            AllPluginsInternal.Add(CreatePluginInstance(pluginPackage));

            return(true);
        }
        /// <summary>Stops all running plugins, clears all loaded plugins, scans and load available plugin</summary>
        /// <returns>The number of plugin loaded</returns>
        protected virtual async Task <int> RefreshPlugins()
        {
            try
            {
                LogTo.Information("Refreshing plugins.");

                await StopPlugins();

                AllPluginsInternal.Clear();
                ScanLocalPlugins(true)
                .Select(CreatePluginInstance)
                .Distinct()
                .ForEach(pi => AllPluginsInternal.Add(pi));

                LogTo.Information($"Found {AllPluginsInternal.Count} plugins.");

                return(AllPluginsInternal.Count);
            }
            catch (Exception ex)
            {
                LogTo.Warning(ex, "Exception caught while refreshing plugins.");
                throw;
            }
        }