Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2168


Ignore:
Timestamp:
07/18/09 00:59:56 (15 years ago)
Author:
swagner
Message:

Fixed loading sequence of plugins (#552)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/Loader.cs

    r1897 r2168  
    325325      }
    326326
     327      Queue<IPlugin> pluginsToLoad = new Queue<IPlugin>();
    327328      DiscoveryService service = new DiscoveryService();
    328329      // now search and instantiate an IPlugin type in each loaded assembly
     330      // and prepare the queue to load all plugins
    329331      foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) {
    330332        // don't search for plugins in the PluginInfrastructure
     
    335337          if (!pluginType.IsAbstract && !pluginType.IsInterface && !pluginType.HasElementType) {
    336338            IPlugin plugin = (IPlugin)Activator.CreateInstance(pluginType);
    337             PluginAction(this, new PluginManagerActionEventArgs(plugin.Name, PluginManagerAction.InitializingPlugin));
    338             plugin.OnLoad();
     339            pluginsToLoad.Enqueue(plugin);
    339340            pluginsByName.Add(plugin.Name, plugin);
    340341          }
     
    342343      }
    343344
    344       foreach (IPlugin plugin in pluginsByName.Values) {
     345      // load all plugins respecting their dependencies
     346      while (pluginsToLoad.Count > 0) {
     347        IPlugin plugin = pluginsToLoad.Dequeue();
    345348        PluginInfo pluginInfo = GetPluginInfo(plugin);
    346         allPlugins.Add(pluginInfo, plugin);
    347         PluginAction(this, new PluginManagerActionEventArgs(plugin.Name, PluginManagerAction.InitializedPlugin));
     349        bool canLoad = true;
     350        foreach (PluginInfo dependency in pluginInfo.Dependencies) {
     351          if (!allPlugins.ContainsKey(dependency)) {
     352            canLoad = false;
     353            break;
     354          }
     355        }
     356        if (canLoad) {
     357          PluginAction(this, new PluginManagerActionEventArgs(plugin.Name, PluginManagerAction.InitializingPlugin));
     358          plugin.OnLoad();
     359          allPlugins.Add(pluginInfo, plugin);
     360          PluginAction(this, new PluginManagerActionEventArgs(plugin.Name, PluginManagerAction.InitializedPlugin));
     361        } else {
     362          pluginsToLoad.Enqueue(plugin);
     363        }
    348364      }
    349365    }
Note: See TracChangeset for help on using the changeset viewer.