|
using System;
using System.Collections.Generic;
using System.Text;
using Worker.Core.API;
using System.Data;
using System.Reflection;
namespace SimplePluginManager
{
public class SimplePluginManager : Worker.Core.API.IPluginManager
{
DataTable pluginTable = new DataTable();
DataSet dsManager = new DataSet();
public SimplePluginManager()
{
DataColumn name = new DataColumn("Name");
DataColumn version = new DataColumn("Version");
DataColumn path = new DataColumn("Path");
pluginTable.Columns.Add(name);
pluginTable.Columns.Add(version);
pluginTable.Columns.Add(path);
dsManager.Tables.Add(pluginTable);
}
public List<IPlugin> GetAll()
{
System.Collections.Generic.List<IPlugin> arrayPlugin = new List<IPlugin>();
foreach (DataRow dr in dsManager.Tables[0].Rows)
{
IPlugin plugin = new Plugin();
plugin.Name = dr["Name"].ToString();
plugin.Version = dr["Version"].ToString();
plugin.Path = dr["Path"].ToString();
arrayPlugin.Add(plugin);
}
return arrayPlugin;
}
public object Find(string name)
{
foreach (DataRow dr in dsManager.Tables[0].Rows)
{
if(name.Equals(dr["Name"].ToString()))
{
IPlugin plugin = new Plugin();
plugin.Name = dr["Name"].ToString();
plugin.Version = dr["Version"].ToString();
plugin.Path = dr["Path"].ToString();
return plugin;
}
}
return null;
}
public object Plug(IPlugin plugin,String type)
{
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(".\\Plugin\\" + plugin.Path));
foreach (Type ftype in asm.GetTypes())
{
foreach (Type ifc in ftype.GetInterfaces())
{
if (ifc.Name.Equals(type))
{
return Activator.CreateInstance(ftype);
}
}
}
return null;
}
public bool Register(IPlugin info)
{
DataRow dr = dsManager.Tables[0].NewRow();
dr["Name"] = info.Name;
dr["Version"] = info.Version;
dr["Path"] = info.Path;
pluginTable.Rows.Add(dr);
return true;
}
public void Persist(String source)
{
dsManager.WriteXml(source);
}
public void Load(String source)
{
dsManager.ReadXml(source);
}
}
}
|
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.
He is a software developer based on Brazil. His main interests are Software architecture, Requirements Engineering and coding. He is a MCP and MCAD developer. If you want to get in contact, please send an e-mail to andre.betim@gmail.com or access his company website
www.plugtecnologia.com