Hi all i'm trying to make a plugin supported windows MDI application but my brain has stopped! i can't build algorithm!
First of all my program will read dll's from plugin directory which is located at the same directory of my MDI parent application,
i don't know what will i use for interfaces and classes, for the moment i created an interface which has to set name and i use that name for placing a button on a panel and i created a dll with that sdk, now its working but i want to add forms to that dll and when i click on my button that forms will appear as MDI child in my parent application..
codes that i worked on:
SDKLib.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
namespace drSDK
{
public interface IPlugIn
{
string name();
}
public class Plug
{
public string pName;
public string pPath;
public string pFName;
}
public class Kit
{
public static List<Plug> getAllPlugIns(string path)
{
List<Plug> myPlugs = new List<Plug>();//list
if (!Directory.Exists(path))
return myPlugs;//null
string[] dlls = Directory.GetFiles(path, "*.dll");//arry dlls
foreach (string dll in dlls)//all dlls in list
{
Assembly asm = Assembly.LoadFile(dll);//open as asm
Type[] tipler = asm.GetTypes();
foreach (Type tip in tipler)
{
if (tip.GetInterface("IPlugIn") != null)//Thats my SDK!
{
Plug myP = new Plug();
myP.pFName = tip.FullName;
myP.pPath = dll;
object obj = asm.CreateInstance(tip.FullName);//dll instance
myP.pName = obj.GetType().InvokeMember("name", BindingFlags.InvokeMethod, null, obj, null).ToString(); //name from interface
myPlugs.Add(myP);
}
}
}
return myPlugs;
}
public static object createObject(Plug p)
{
Assembly asm = Assembly.LoadFile(p.pPath);
object obj = asm.CreateInstance(p.pFName);
return obj;
}
}
}
using drSDK;
.
.
.
List<Plug> myList = null;//Plugin list
private void Form1_Load(object sender, EventArgs e)
{
myList = Kit.getAllPlugIns(Application.StartupPath + "//plugins");//plugin directory
foreach (Plug p in myList)//4 every plug
{
Button b = new Button();
b.Text = p.pName;
b.Click += new EventHandler(b_Click);
NavigatorGroupItemContainerPanel1.Controls.Add(b);
}
void b_Click(object sender, EventArgs e)
{
foreach (Plug p in myList)
{
if (p.pName == (sender as Button).Text)//wats clicked
{
run(p);
}
}
}
void run(Plug p)
{
IPlugIn obj = (IPlugIn)Kit.createObject(p);
.
. [B]//I HAVE TO DO SMTH HERE (IN MY OPINION)[/B]
.
.
}
void Pencereler(Form pencere)
{
bool acik = false;
foreach (Form eleman in this.MdiChildren)
{
if (eleman.Text == pencere.Text)
{
acik = true;
eleman.Activate();
}
if (acik == false)
{
pencere.MdiParent = this;
pencere.Show();
}
}
}