Пример #1
0
        /// <summary>
        /// Scans for all available plugins and attempts to load them
        /// </summary>
        public void LoadAllPlugins()
        {
            // Get all plugin loaders, scan the plugin directory and load all reported plugins
            HashSet <Plugin> plugins = new HashSet <Plugin>();

            foreach (PluginLoader loader in extensionmanager.GetPluginLoaders())
            {
                foreach (string name in loader.ScanDirectory(plugindir))
                {
                    // Check if the plugin is already loaded
                    if (pluginmanager.GetPlugin(name) == null)
                    {
                        // Load it and watch for errors
                        try
                        {
                            Plugin plugin = loader.Load(plugindir, name);
                            plugin.OnError += plugin_OnError;
                            rootlogger.Write(LogType.Info, "Loaded plugin {0} (v{1}) by {2}", plugin.Title, plugin.Version, plugin.Author);
                            plugins.Add(plugin);
                        }
                        catch (Exception ex)
                        {
                            //rootlogger.Write(LogType.Error, "Failed to load plugin {0} ({1})", name, ex.Message);
                            //rootlogger.Write(LogType.Debug, ex.StackTrace);
                            rootlogger.WriteException(string.Format("Failed to load plugin {0}", name), ex);
                        }
                    }
                }
            }

            // Init all successfully loaded plugins
            foreach (Plugin plugin in plugins)
            {
                try
                {
                    pluginmanager.AddPlugin(plugin);
                }
                catch (Exception ex)
                {
                    //rootlogger.Write(LogType.Error, "Failed to initialise plugin {0} ({1})", plugin.Name, ex.Message);
                    //rootlogger.Write(LogType.Debug, ex.StackTrace);
                    rootlogger.WriteException(string.Format("Failed to initialise plugin {0}", plugin.Name), ex);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Scans for all available plugins and attempts to load them
        /// </summary>
        public void LoadAllPlugins()
        {
            // Get all plugin loaders, scan the plugin directory and load all reported plugins
            HashSet <Plugin> plugins = new HashSet <Plugin>();

            foreach (PluginLoader loader in extensionmanager.GetPluginLoaders())
            {
                foreach (string name in loader.ScanDirectory(PluginDirectory))
                {
                    // Check if the plugin is already loaded
                    if (pluginmanager.GetPlugin(name) == null)
                    {
                        // Load it and watch for errors
                        try
                        {
                            Plugin plugin = loader.Load(PluginDirectory, name);
                            if (plugin == null)
                            {
                                continue;                 // Async load
                            }
                            plugin.OnError += plugin_OnError;
                            rootlogger.Write(LogType.Info, "Loaded plugin {0} v{1} by {2}", plugin.Title, plugin.Version, plugin.Author);
                            plugins.Add(plugin);
                        }
                        catch (Exception ex)
                        {
                            //rootlogger.Write(LogType.Error, "Failed to load plugin {0} ({1})", name, ex.Message);
                            //rootlogger.Write(LogType.Debug, ex.StackTrace);
                            rootlogger.WriteException(string.Format("Failed to load plugin {0}", name), ex);
                        }
                    }
                }
            }

            foreach (PluginLoader loader in extensionmanager.GetPluginLoaders())
            {
                var loading_plugin_count = loader.LoadingPlugins.Count;
                if (loading_plugin_count < 1)
                {
                    continue;
                }
                // Wait until all async plugins have finished loading
                while (loader.LoadingPlugins.Count > 0)
                {
                    System.Threading.Thread.Sleep(25);
                    // Process any NextTick callbacks which other threads may have queued
                    OnFrame();
                }
            }


            // Init all successfully loaded plugins
            foreach (Plugin plugin in plugins)
            {
                try
                {
                    pluginmanager.AddPlugin(plugin);
                }
                catch (Exception ex)
                {
                    //rootlogger.Write(LogType.Error, "Failed to initialise plugin {0} ({1})", plugin.Name, ex.Message);
                    //rootlogger.Write(LogType.Debug, ex.StackTrace);
                    rootlogger.WriteException(string.Format("Failed to initialise plugin {0}", plugin.Name), ex);
                }
            }

            isInitialized = true;
        }