Click here to Skip to main content
15,880,608 members
Articles / Desktop Programming / Windows Forms

Storm - the world's best IDE framework for .NET

Rate me:
Please Sign up or sign in to vote.
4.96/5 (82 votes)
4 Feb 2010LGPL311 min read 273.6K   6.5K   340  
Create fast, flexible, and extensible IDE applications easily with Storm - it takes nearly no code at all!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Storm Documentation | Controls | Plugins</title>
    <link rel="stylesheet" type="text/css" href="../style/codesheet.css" />
</head>
<body>
    <h1>Plugins Library</h1>
    <p>The Plugins Library and its Controls are designed to:</p>
    <ul>
        <li>Give your applications the ability to be very extensible and flexible;</li>
        <li>Provide a way to create new features for your application for your users.</li>
    </ul>
    
    <p>Library dependencies:</p>
    <ul>
        <li>None</li>
    </ul>
    
    <h2>How to use the Plugins Library and its Controls?</h2>
    <p>The way this works is through a class called PluginManager - it is capable of loading and enabling/disabling plugins, and adding their
Controls to a given Form. The PluginManager loads plugins from .dlls it finds in a given path, and searches through its classes to find 
classes that inherit from the provided interface "IPlugin".</p>

    <p>Therefore it is a requirement for your users when they make plugins, that they, in the classes they want the PluginManager to add, add
inheting from the UserControl and the provided IPlugin. Optionally they can add an attribute to this class to make you able to display
information about the author of loaded plugins, version, description, etc. It is also a requirement that plugins are coded in VB.NET/C#/VC++.</p>

    <p>The following is a usage example of the Plugin attribute:</p>
    <pre class="csharpcode">
        [Plugin(<span class="str">"PluginConsole"</span>, <span class="str">"Theodor \"Vestras\" Storm Kristensen"</span>,
	<span class="str">"Shows the debug messages from the PluginManager."</span>, <span class="str">"1.0.0.4"</span>)]
	<span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> PluginConsole : UserControl, IPlugin
	</pre>
	
	<p>The following code will be required from the user in his/her plugin:</p>
    <pre class="csharpcode">
        <span class="kwrd">#region</span> Fields

        <span class="kwrd">private</span> PluginManager _pluginManager = <span class="kwrd">null</span>;
        <span class="kwrd">private</span> Form _formParent             = <span class="kwrd">null</span>;
        <span class="kwrd">private</span> Icon _icon                   = <span class="kwrd">null</span>;

        <span class="kwrd">private</span> Type _type       = null;
        <span class="kwrd">private</span> <span class="kwrd">string</span> _assembly = <span class="str">""</span>;
        <span class="kwrd">private</span> <span class="kwrd">bool</span> _enabled    = <span class="kwrd">false</span>;

        <span class="kwrd">#endregion</span>

        <span class="kwrd">#region</span> Properties

        <span class="kwrd">public</span> <span class="kwrd">bool</span> PluginEnabled
        {
            <span class="kwrd">get</span> { <span class="kwrd">return</span> _enabled; }
            <span class="kwrd">set</span> { _enabled = <span class="kwrd">value</span>; }
        }

        <span class="kwrd">public</span> PluginManager PluginManager
        {
            <span class="kwrd">get</span> { <span class="kwrd">return</span> _pluginManager; }
            <span class="kwrd">set</span> { _pluginManager = <span class="kwrd">value</span>; }
        }

        <span class="kwrd">public</span> Form FormParent
        {
            <span class="kwrd">get</span> { <span class="kwrd">return</span> _formParent; }
            <span class="kwrd">set</span> { _formParent = <span class="kwrd">value</span>; }
        }

        <span class="kwrd">public</span> Icon Icon
        {
            <span class="kwrd">get</span> { <span class="kwrd">return</span> _icon; }
            <span class="kwrd">set</span> { _icon = <span class="kwrd">value</span>; }
        }

        <span class="kwrd">public</span> <span class="kwrd">string</span> Assembly
        {
            <span class="kwrd">get</span> { <span class="kwrd">return</span> _assembly; }
            <span class="kwrd">set</span> { _assembly = <span class="kwrd">value</span>; }
        }
        
        <span class="kwrd">public</span> Type Type
        {
            <span class="kwrd">get</span> { <span class="kwrd">return</span> _type; }
            <span class="kwrd">set</span> { _type = <span class="kwrd">value</span>; }
        }

        <span class="kwrd">#endregion</span>
    </pre>
	
	<p>The rest of the content is up to the user. ;) Now to how you're going to implement the PluginManager into your application:</p>

	<h2>How to implement the PluginManager?</h2>
	<p>Implementing the PluginManager is very easy - you a PluginManager field to your class:</p>
	
	<pre class="csharpcode">
        <span class="kwrd">private</span> PluginManager pluginManager = null;
	</pre>
	
	<p>We will then have to initialize it:</p>
	
	<pre class="csharpcode">
        pluginManager = <span class="kwrd">new</span> PluginManager(<span class="kwrd">this</span>, Environment.CurrentDirectory);
	</pre>
	
	<p>Now that we have initialized it, we are able to load all the plugins placed in Environment.CurrentDirectory - when we have loaded them,
we have to loop through them and enable each of them.</p>

    <pre class="csharpcode">
        pluginManager.LoadPlugins();
        <span class="kwrd">foreach</span> (IPlugin plugin <span class="kwrd">in</span> pluginManager.LoadedPlugins)
            pluginManager.EnablePlugin(plugin, <span class="kwrd">true</span>);
    </pre>
    
    <a href="../libs.htm">Back</a>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)



Comments and Discussions