public Plugin(PluginContext context) : base(context) { if (CurrentPlugin != null) throw new Exception("Can be instancied only once"); CurrentPlugin = this; }
public PluginContext LoadPlugin(string libPath) { if (!File.Exists(libPath)) { throw new FileNotFoundException("File doesn't exist", libPath); } if (m_pluginContexts.Any(entry => Path.GetFullPath(entry.AssemblyPath) == Path.GetFullPath(libPath))) { throw new Exception("Plugin already loaded"); } byte[] asmData = File.ReadAllBytes(libPath); Assembly pluginAssembly = Assembly.Load(asmData); var pluginContext = new PluginContext(libPath, pluginAssembly); bool initialized = false; // search the entry point (the class that implements IPlugin) foreach (Type pluginType in pluginAssembly.GetTypes()) { if (pluginType.IsPublic && !pluginType.IsAbstract) { if (pluginType.HasInterface(typeof(IPlugin))) { if (initialized) { throw new PluginLoadException("Found 2 classes that implements IPlugin. A plugin can contains only one"); } pluginContext.Initialize(pluginType); initialized = true; RegisterPlugin(pluginContext); logger.Info("Plugin '{0}' loaded", pluginContext.Plugin.Name); } } } return(pluginContext); }
protected PluginBase(PluginContext context) { Context = context; }
private void UnRegisterPlugin(PluginContext pluginContext) { m_pluginContexts.Remove(pluginContext); OnPluginRemoved(pluginContext); }
private void RegisterPlugin(PluginContext pluginContext) { m_pluginContexts.Add(pluginContext); OnPluginAdded(pluginContext); }
protected PluginBase(PluginContext context) { Context = context; }