Ejemplo n.º 1
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);
     }
 }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
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;
     }
 }