/// <summary>
 /// Create a new plugin representation.
 /// </summary>
 /// <param name="plugin">The plugin to represent.</param>
 /// <param name="name">The name of the plugin.</param>
 /// <param name="version">The version of the plugin.</param>
 /// <param name="author">The author of the plugin.</param>
 public PluginRepresentation(Plugin plugin, string name, string version, string author)
 {
     Plugin = plugin;
     PluginName = name;
     PluginVersion = version;
     PluginAuthor = author;
 }
Exemple #2
0
 /// <summary>
 /// Adds a plugin to the list of loaded plugins.
 /// </summary>
 /// <param name="plugin">The plugin to load.</param>
 /// <param name="pluginName">The name of the plugin.</param>
 /// <param name="pluginVersion">The version of the plugin.</param>
 /// <param name="pluginAuthor">The author of the plugin.</param>
 static void AddPluginToList(Plugin plugin, string pluginName, string pluginVersion, string pluginAuthor = "Anonymous")
 {
     LoadedPlugins.Add(new PluginRepresentation(
         plugin,
         pluginName,
         pluginVersion,
         pluginAuthor));
     Events.Enqueue(String.Format("Loaded plugin {0} ({1}) by {2}",
         pluginName,
         pluginVersion,
         pluginAuthor));
 }
Exemple #3
0
 /// <summary>
 /// Load a specific plugin into program memory.
 /// </summary>
 /// <param name="pluginType">The System.Type object representing the plugin.</param>
 /// <param name="newPlugin">The plugin as an object.</param>
 /// <param name="attribute">The attribute representing the plugin's details.</param>
 private static void LoadPlugin(Type pluginType, Plugin newPlugin, PluginAttribute attribute)
 {
     bool enablePlugin = newPlugin.Settings
         .Element("enabled")
         .Value.ToLower() == "true";
     if (enablePlugin)
     {
         if (attribute != null)
         {
             AddPluginToList(newPlugin,
                 attribute.PluginName,
                 attribute.PluginVersion,
                 attribute.PluginAuthor);
         }
         else
         {
             Events.Enqueue("Missing attributes for " + pluginType.Name);
         }
     }
     else
     {
         Events.Enqueue("Plugin disabled: " + pluginType.Name);
     }
 }
Exemple #4
0
 /// <summary>
 /// Get the LINQ-to-XML settings element for this specific plugin.
 /// </summary>
 /// <param name="plugin">The plugin.</param>
 /// <param name="attribute">The attribute holding this plugin's details.</param>
 /// <param name="returnNullIfNotExists">
 /// True if you want to return a null if the element doesn't exist.
 /// Otherwise, this prompts the user to create the element.
 /// </param>
 /// <returns>The LINQ-to-XML settings element for this specific plugin.</returns>
 static XElement GetSettingsElementFor(Plugin plugin, PluginAttribute attribute, bool returnNullIfNotExists = false)
 {
     XElement[] element = Settings.Root
         .Element("plugins")
         .Elements("plugin")
         .Where(x => x.Attribute("name").Value == attribute.PluginName &&
             x.Attribute("author").Value == attribute.PluginAuthor)
             .ToArray();
     if (element.Length > 0 || returnNullIfNotExists)
     {
         return element.First();
         // if returnNullIfNotExists, this will be called regardless,
         // meaning that a null will be returned if element.Length == 0
     }
     else
     {
         return GetNewSettingsElementFor(plugin, attribute);
     }
 }
Exemple #5
0
 /// <summary>
 /// Prompts the user if they want to enable a new plugin, disable a new plugin, or skip loading it.
 /// The plugin will be processed according to the user's input.
 /// </summary>
 /// <param name="plugin">The plugin to load.</param>
 /// <param name="attribute">The PluginAttribute representing the plugin to load.</param>
 /// <returns>A new XElement object representing the plugin and its' settings, or null if the user chose not to load it.</returns>
 private static XElement GetNewSettingsElementFor(Plugin plugin, PluginAttribute attribute)
 {
     DialogResult result = MessageBox.Show(
         "Plugin " + attribute.PluginName + " by " + attribute.PluginAuthor + " has not been used before.\r\n" +
         "Do you want to enable this plugin? Click Cancel to skip this plugin.", "Enable Plugin",
         MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
     if (result != DialogResult.Cancel)
     {
         Settings.Root
             .Element("plugins")
             .Add(new XElement("plugin",
                 new XAttribute("name", attribute.PluginName),
                 new XAttribute("author", attribute.PluginAuthor),
                 new XElement("enabled", result == DialogResult.Yes)));
         return GetSettingsElementFor(plugin, attribute, true);
     }
     else
     {
         return null;
     }
 }