2011-03-03 18:34:33 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-04-14 02:29:13 +00:00
|
|
|
using System.Reflection;
|
2013-12-16 01:04:17 +00:00
|
|
|
using FileSystemIDandChk.ImagePlugins;
|
2014-04-14 02:29:13 +00:00
|
|
|
using FileSystemIDandChk.PartPlugins;
|
|
|
|
|
using FileSystemIDandChk.Plugins;
|
2011-03-03 18:34:33 +00:00
|
|
|
|
|
|
|
|
namespace FileSystemIDandChk
|
|
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
public class PluginBase
|
|
|
|
|
{
|
|
|
|
|
public Dictionary<string, Plugin> PluginsList;
|
|
|
|
|
public Dictionary<string, PartPlugin> PartPluginsList;
|
2013-12-16 01:04:17 +00:00
|
|
|
public Dictionary<string, ImagePlugin> ImagePluginsList;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
|
|
|
public PluginBase()
|
|
|
|
|
{
|
|
|
|
|
PluginsList = new Dictionary<string, Plugin>();
|
|
|
|
|
PartPluginsList = new Dictionary<string, PartPlugin>();
|
|
|
|
|
ImagePluginsList = new Dictionary<string, ImagePlugin>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegisterAllPlugins()
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
|
|
|
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
|
|
|
|
|
|
|
|
foreach (Type type in assembly.GetTypes())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-12-16 01:04:17 +00:00
|
|
|
if (type.IsSubclassOf(typeof(ImagePlugin)))
|
|
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
ImagePlugin plugin = (ImagePlugin)type.GetConstructor(new [] { typeof(PluginBase) }).Invoke(new object[] { this });
|
|
|
|
|
RegisterImagePlugin(plugin);
|
2013-12-16 01:04:17 +00:00
|
|
|
}
|
2011-03-03 18:34:33 +00:00
|
|
|
if (type.IsSubclassOf(typeof(Plugin)))
|
|
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
Plugin plugin = (Plugin)type.GetConstructor(new [] { typeof(PluginBase) }).Invoke(new object[] { this });
|
|
|
|
|
RegisterPlugin(plugin);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
2014-04-14 02:29:13 +00:00
|
|
|
else if (type.IsSubclassOf(typeof(PartPlugin)))
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
PartPlugin partplugin = (PartPlugin)type.GetConstructor(new [] { typeof(PluginBase) }).Invoke(new object[] { this });
|
|
|
|
|
RegisterPartPlugin(partplugin);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
Console.WriteLine(exception);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
void RegisterImagePlugin(ImagePlugin plugin)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
if (!ImagePluginsList.ContainsKey(plugin.Name.ToLower()))
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
ImagePluginsList.Add(plugin.Name.ToLower(), plugin);
|
2013-12-16 01:04:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
void RegisterPlugin(Plugin plugin)
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
if (!PluginsList.ContainsKey(plugin.Name.ToLower()))
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
PluginsList.Add(plugin.Name.ToLower(), plugin);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
void RegisterPartPlugin(PartPlugin partplugin)
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
if (!PartPluginsList.ContainsKey(partplugin.Name.ToLower()))
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
PartPluginsList.Add(partplugin.Name.ToLower(), partplugin);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
|