private void LoadDependencies(PluginModule p1) { foreach (Plugin dependency in p1.Dependencies) { PluginModule p2 = FindPluginByID( _loadedPlugins, dependency.ID); if (p2 == null) { throw new Exception(String.Format( Resources.PluginDependencyError1, p1.Name, dependency.Name) ); } if (p2.Version < dependency.Version) { throw new Exception(String.Format( Resources.PluginDependencyError2, p1.Name, dependency.Name, dependency.Version, p2.Version) ); } LoadDependencies(p2); } if (FindPluginByID(_registeredPlugins, p1.ID) == null) { _registeredPlugins.Add(p1); } }
private string GetPluginDetails(PluginModule plugin) { StringBuilder sb = new StringBuilder(); sb.Append(plugin.Name); sb.Append("\r\n["); sb.Append(plugin.ID); sb.Append(":"); sb.Append(plugin.Version); sb.Append("]\r\n\r\n"); sb.Append(plugin.Description); sb.Append("\r\n\r\n"); sb.Append(Resources.AboutRequires); sb.Append(":\r\n"); if (plugin.Dependencies.Count == 0) { sb.Append(Resources.AboutDependenciesNone); sb.Append("\r\n"); } else { foreach (Plugin dep in plugin.Dependencies) { sb.Append(dep.Name); sb.Append(" ["); sb.Append(dep.ID); sb.Append(":"); sb.Append(dep.Version); sb.Append("]\r\n"); } } sb.Append("\r\n"); sb.Append(Resources.AboutRequiredBy); sb.Append(":\r\n"); List <String> dependents = GetDependents(plugin); if (dependents.Count == 0) { sb.Append(Resources.AboutDependenciesNone); sb.Append("\r\n"); } else { foreach (String dep in dependents) { sb.Append(dep); } } return(sb.ToString()); }
private void PluginListBox_SelectedIndexChanged( object sender, EventArgs e) { PluginModule plugin = _pluginListBox.SelectedItem as PluginModule; if (plugin != null) { _pluginDescriptionTextBox.Text = GetPluginDetails(plugin); } else { _pluginDescriptionTextBox.Text = ""; } }
/********************************************************************** * PLUGIN MANAGEMENT * * Plugin loading is a three stage process: * * 1. LoadPlugins finds the plugin DLLs. The must be located in the * application directory and must implement IQuickSharpPlugin. * The details of each plugin are added to the list _loadedPlugins. * * 2. RegisterPlugins checks the dependencies of each plugin making * sure each one exists and adding each to a second list * _registeredPlugins which sorts them into the correct loading * order. Any unsatisfied dependency (either the dependency doesn't * exist or is an insufficient version number) will cause a fatal * error and the application will aborted. * * 3. ActivatePlugins works through _registedPlugins and calls the * Activate method on each DLL passing a reference to the application * main form. * **********************************************************************/ /// <summary> /// Loads the plugins available to the application. /// These must be located in the application directory and must /// implement IQuickSharpPlugin. /// </summary> public void LoadPlugins() { string[] dlls = Directory.GetFiles( _applicationManager.QuickSharpHome, "*.dll"); foreach (string dll in dlls) { List <IQuickSharpPlugin> plugins = GetPluginsFromAssembly(dll); foreach (IQuickSharpPlugin plugin in plugins) { string pluginID = plugin.GetID(); if (String.IsNullOrEmpty(pluginID)) { throw new Exception(String.Format( "Plugin \"{0}\" has an invalid ID.", plugin.GetName())); } pluginID = pluginID.ToUpper(); if (_loadedPluginIDs.Contains(pluginID)) { throw new Exception(String.Format( "Plugin \"{0}\" has a duplicate ID.", plugin.GetName())); } PluginModule p = new PluginModule(plugin, plugin.GetID(), plugin.GetName(), plugin.GetVersion(), plugin.GetDescription()); foreach (Plugin dependency in plugin.GetDependencies()) { p.AddDependency(dependency); } _loadedPlugins.Add(p); _loadedPluginIDs.Add(p.ID); } } }
private List <String> GetDependents(PluginModule plugin) { List <String> idList = new List <String>(); List <String> depList = new List <String>(); foreach (PluginModule pm in _pluginManager.RegisteredPlugins) { foreach (Plugin p in pm.Dependencies) { if (plugin.ID == p.ID && !idList.Contains(pm.ID)) { idList.Add(pm.ID); depList.Add(String.Format("{0}\r\n", pm.Name)); break; } } } return(depList); }
/// <summary> /// Determine if a plugin has been registered. /// </summary> /// <param name="pluginID">The plugin ID.</param> /// <returns>True if the plugin has been registered.</returns> public bool HavePlugin(string pluginID) { PluginModule pm = FindPluginByID(_registeredPlugins, pluginID); return(pm != null); }