Changeset 413


Ignore:
Timestamp:
9/27/2008 9:02:36 AM (6 years ago)
Author:
lowjoel
Message:

Added an AssemblyResolve? handler since the Initialisation phase of plugins may require unserialisation. Loading plugins should be looked to for the assembly objects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/Manager/Plugins.cs

    r384 r413  
    107107        public DefaultHost() 
    108108        { 
     109            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve); 
    109110            foreach (string fileName in Directory.GetFiles(PLUGINSFOLDER)) 
    110111            { 
     
    149150                if (typeInterface != null) 
    150151                { 
     152                    //Create the PluginInstance structure 
     153                    PluginInstance instance = new PluginInstance(assembly, filePath, null); 
     154 
     155                    //Add the plugin to the list of loaded plugins 
     156                    lock (plugins) 
     157                        plugins.Add(instance); 
     158 
    151159                    //Initialize the plugin 
    152160                    IPlugin pluginInterface = (IPlugin)Activator.CreateInstance( 
    153161                        assembly.GetType(type.ToString())); 
    154162                    pluginInterface.Initialize(this); 
    155  
    156                     //Create the PluginInstance structure 
    157                     PluginInstance instance = new PluginInstance(assembly, filePath, pluginInterface); 
    158  
    159                     //Add the plugin to the list of loaded plugins 
    160                     lock (plugins) 
    161                         plugins.Add(instance); 
     163                    instance.Plugin = pluginInterface; 
     164 
     165                    //And broadcast the plugin load event 
    162166                    OnPluginLoad(instance); 
    163167                } 
     
    165169        } 
    166170 
     171        Assembly AssemblyResolve(object sender, ResolveEventArgs args) 
     172        { 
     173            lock (plugins) 
     174                foreach (PluginInstance instance in plugins) 
     175                    if (instance.Assembly.FullName == args.Name) 
     176                        return instance.Assembly; 
     177            return null; 
     178        } 
     179 
    167180        public override void RegisterErasureMethod(ErasureMethod method) 
    168181        { 
     
    181194    /// Structure holding the instance values of the plugin like handle and path. 
    182195    /// </summary> 
    183     public struct PluginInstance 
     196    public class PluginInstance 
    184197    { 
    185198        internal PluginInstance(Assembly assembly, string path, IPlugin plugin) 
Note: See TracChangeset for help on using the changeset viewer.