Click here to Skip to main content
15,895,606 members
Articles / Programming Languages / C#

Plugins Manager

Rate me:
Please Sign up or sign in to vote.
4.00/5 (6 votes)
22 May 2008CPOL3 min read 50.9K   1.9K   62  
A plugins manager class to manage a plugins structure
/*
 * Creato da SharpDevelop.
 * Utente: lucabonotto
 * Data: 22/05/2008
 * Ora: 10.59
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.IO;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using LBSoft.PluginManager;
using TestInterface;

namespace PluginTest
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
								  , ILBPluginsManager
								  , ITestProvider
	{
		private PluginsManager	piMng = new PluginsManager();
		private ILBPlugin 		pi =null;
		
		public MainForm()
		{
			InitializeComponent();
			
			piMng.Provider = this;
			piMng.ShowMessages = false;
			piMng.LoadPluginsConfig ();
		}
		
		void menuExit_Click(object sender, EventArgs e)
		{
			this.piMng.UnloadPlugin ( this.pi );
			this.Close();
		}
		
		void menuLoadPlugin_Click(object sender, EventArgs e)
		{
			this.pi = piMng.LoadPlugin ( "Test1");
			if ( this.pi == null )
				return;
			
			ITestInterface piTest = pi as ITestInterface;
			
			piTest.Provider = this;
			Control ctrl = piTest.PluginControl;
			
			ctrl.Dock = System.Windows.Forms.DockStyle.Fill;
			ctrl.Location = new System.Drawing.Point(0, 24);
			ctrl.Name = "test1Control";
			ctrl.Size = new System.Drawing.Size(510, 314);
			ctrl.TabIndex = 0;

			this.panelCtrl.Controls.Add ( piTest.PluginControl );
		}
		
		
		public void OutputMessage( string message, bool addEndLine )
		{
			this.OutputMessage ( message, addEndLine, MessageType.Normal );
		}
		

		public void OutputMessage( string message, bool addEndLine, MessageType type )
		{
			MessageBoxIcon mi = MessageBoxIcon.None;
			switch ( type )
			{
				case MessageType.Error:
					mi = MessageBoxIcon.Error;
					break;
					
				case MessageType.Warning:
					mi = MessageBoxIcon.Warning;
					break;						
			}
			
			MessageBox.Show ( message, this.GetType().Name, MessageBoxButtons.OK, mi );			
		}
		
		
		public void Message( string msg )
		{
			this.OutputMessage ( msg, false );
		}
	}
}

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 Code Project Open License (CPOL)


Written By
Software Developer (Senior) Promax Srl
Italy Italy
Software developer with over 16 years of experience, specializing on MFC/C++, C# and software architecture


Company : Promax S.r.l.


Comments and Discussions