Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/16/09 14:25:50 (15 years ago)
Author:
gkronber
Message:

Fixed loading of plugins in correct order as defined by plugin dependencies in AppDomains for applications. (ApplicationManager) #799

Location:
branches/PluginInfrastructure Refactoring
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure.Manager/ApplicationManager.cs

    r2489 r2495  
    2828using System.Security;
    2929using System.Linq;
     30using System.IO;
    3031
    3132namespace HeuristicLab.PluginInfrastructure.Manager {
     
    7576      // load all loadable plugins (all dependencies available) into the execution context
    7677      foreach (var desc in PluginDescriptionIterator.IterateInDependencyOrder(plugins.Where(x => x.PluginState != PluginState.Disabled))) {
    77         foreach (var plugin in GetInstances<IPlugin>(desc)) {
    78           plugin.OnLoad();
    79           FirePluginLoaded(plugin.Name);
     78        foreach (string assembly in desc.Assemblies) {
     79          var asm = Assembly.LoadFrom(assembly);
     80
     81          // instantiate and load all plugins in this assembly
     82          foreach (var plugin in GetInstances<IPlugin>(asm)) {
     83            plugin.OnLoad();
     84            FirePluginLoaded(plugin.Name);
     85          }
    8086        }
    8187        desc.Load();
    8288      }
     89
    8390    }
    8491
     
    128135    }
    129136    /// <summary>
     137    /// Creates an instance of all types declared in assembly <param name="asm"/> that are subtypes or the same type of the specified type and declared in <paramref name="plugin"/>
     138    /// </summary>
     139    /// <typeparam name="T">Most general type.</typeparam>
     140    /// <param name="asm">Declaring assembly.</param>
     141    /// <returns>Enumerable of the created instances.</returns>
     142    public IEnumerable<T> GetInstances<T>(Assembly asm) where T : class {
     143      return from t in GetTypes(typeof(T), asm)
     144             where !t.IsAbstract && !t.IsInterface && !t.HasElementType
     145             select (T)Activator.CreateInstance(t);
     146    }
     147    /// <summary>
    130148    /// Creates an instance of all types that are subtypes or the same type of the specified type
    131149    /// </summary>
     
    167185    /// <returns>Enumerable of the discovered types.</returns>
    168186    public IEnumerable<Type> GetTypes(Type type, IPluginDescription pluginDescription) {
    169       throw new NotImplementedException();
    170       //return from asm in AppDomain.CurrentDomain.GetAssemblies()
    171       //       where pluginDescription.Assemblies.Contains(asm.Location)
    172       //       from t in GetTypes(type, asm)
    173       //       select t;
     187      return from asm in AppDomain.CurrentDomain.GetAssemblies()
     188             where pluginDescription.Assemblies.Any(asmPath => Path.GetFullPath(asmPath) == Path.GetFullPath(asm.Location))
     189             from t in GetTypes(type, asm)
     190             select t;
    174191    }
    175192
  • branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure.Manager/Loader.cs

    r2489 r2495  
    195195          string pluginFileName = (string)attributeData.ConstructorArguments[0].Value;
    196196          PluginFileType fileType = (PluginFileType)attributeData.ConstructorArguments[1].Value;
    197           pluginFiles.Add(PluginDir + "/" + pluginFileName);
     197          pluginFiles.Add(Path.Combine(PluginDir, pluginFileName));
    198198          if (fileType == PluginFileType.Assembly) {
    199             pluginAssemblies.Add(PluginDir + "/" + pluginFileName);
     199            pluginAssemblies.Add(Path.Combine(PluginDir, pluginFileName));
    200200          }
    201201        }
  • branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/ApplicationManager.cs

    r2488 r2495  
    3838
    3939    public static void RegisterApplicationManager(IApplicationManager manager) {
    40       if (appManager != null) throw new InvalidOperationException("An control manager has already been set.");
     40      if (appManager != null) throw new InvalidOperationException("The application manager has already been set.");
    4141      appManager = manager;
    4242    }
  • branches/PluginInfrastructure Refactoring/HeuristicLab/MainForm.cs

    r2488 r2495  
    3131using System.Threading;
    3232using HeuristicLab.PluginInfrastructure.Manager;
     33using System.IO;
    3334
    3435namespace HeuristicLab {
     
    4445
    4546      abortRequested = false;
    46       pluginManager = new PluginManager(HeuristicLab.PluginInfrastructure.Properties.Settings.Default.PluginDir);
     47      string pluginPath = Path.GetFullPath(HeuristicLab.PluginInfrastructure.Properties.Settings.Default.PluginDir);
     48      pluginManager = new PluginManager(pluginPath);
    4749      SplashScreen splashScreen = new SplashScreen(pluginManager, 1000, "Loading HeuristicLab...");
    4850      splashScreen.Owner = this;
Note: See TracChangeset for help on using the changeset viewer.