Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/22/11 16:45:46 (13 years ago)
Author:
mkommend
Message:

#1418: Merged trunk changes into branch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/Manager/PluginValidator.cs

    r5445 r5796  
    117117      CheckPluginDependencyCycles(pluginDescriptions);
    118118
    119       // recursively check if all necessary plugins are available and not disabled
    120       // disable plugins with missing or disabled dependencies
     119      // 1st time recursively check if all necessary plugins are available and not disabled
     120      // disable plugins with missing or disabled dependencies
     121      // to prevent that plugins with missing dependencies are loaded into the execution context
     122      // in the next step
    121123      CheckPluginDependencies(pluginDescriptions);
    122124
     
    124126      // disables plugins that are not loaded correctly
    125127      CheckExecutionContextLoad(pluginDescriptions);
     128
     129      // 2nd time recursively check if all necessary plugins have been loaded successfully and not disabled
     130      // disable plugins with for which dependencies could not be loaded successfully
     131      CheckPluginDependencies(pluginDescriptions);
    126132
    127133      // mark all plugins as enabled that were not disabled in CheckPluginFiles, CheckPluginAssemblies,
     
    135141
    136142      plugins = pluginDescriptions;
    137       DiscoverApplications();
    138     }
    139 
    140     private void DiscoverApplications() {
     143      DiscoverApplications(pluginDescriptions);
     144    }
     145
     146    private void DiscoverApplications(IEnumerable<PluginDescription> pluginDescriptions) {
    141147      applications = new List<ApplicationDescription>();
    142 
    143       foreach (IApplication application in GetApplications()) {
     148      foreach (IApplication application in GetApplications(pluginDescriptions)) {
    144149        Type appType = application.GetType();
    145150        ApplicationAttribute attr = (from x in appType.GetCustomAttributes(typeof(ApplicationAttribute), false)
    146151                                     select (ApplicationAttribute)x).Single();
    147         var declaringPlugin = GetDeclaringPlugin(appType, plugins);
    148152        ApplicationDescription info = new ApplicationDescription();
     153        PluginDescription declaringPlugin = GetDeclaringPlugin(appType, pluginDescriptions);
    149154        info.Name = application.Name;
    150155        info.Version = declaringPlugin.Version;
     
    158163    }
    159164
    160     private static IEnumerable<IApplication> GetApplications() {
     165    private static IEnumerable<IApplication> GetApplications(IEnumerable<PluginDescription> pluginDescriptions) {
    161166      return from asm in AppDomain.CurrentDomain.GetAssemblies()
    162167             from t in asm.GetTypes()
    163168             where typeof(IApplication).IsAssignableFrom(t) &&
    164169               !t.IsAbstract && !t.IsInterface && !t.HasElementType
     170             where GetDeclaringPlugin(t, pluginDescriptions).PluginState != PluginState.Disabled
    165171             select (IApplication)Activator.CreateInstance(t);
    166172    }
     
    173179      }
    174180      // try to load each .dll file in the plugin directory into the reflection only context
    175       foreach (string filename in Directory.GetFiles(baseDir, "*.dll")) {
     181      foreach (string filename in Directory.GetFiles(baseDir, "*.dll").Union(Directory.GetFiles(baseDir, "*.exe"))) {
    176182        try {
    177183          Assembly asm = Assembly.ReflectionOnlyLoadFrom(filename);
     
    500506                                                                                .Where(x => x.PluginState != PluginState.Disabled))) {
    501507        foreach (string assemblyLocation in desc.AssemblyLocations) {
    502           try {
    503             // now load the assemblies into the execution context 
    504             // this can still lead to an exception
    505             // even when the assembly was successfully loaded into the reflection only context before
    506             var asm = Assembly.LoadFrom(assemblyLocation);
    507           }
    508           catch (BadImageFormatException) {
    509             desc.Disable(Path.GetFileName(assemblyLocation) + " is not a valid assembly.");
    510           }
    511           catch (FileLoadException) {
    512             desc.Disable("Can't load file " + Path.GetFileName(assemblyLocation));
    513           }
    514           catch (FileNotFoundException) {
    515             desc.Disable("File " + Path.GetFileName(assemblyLocation) + " is missing.");
    516           }
    517           catch (SecurityException) {
    518             desc.Disable("File " + Path.GetFileName(assemblyLocation) + " can't be loaded because of security constraints.");
     508          if (desc.PluginState != PluginState.Disabled) {
     509            try {
     510              string assemblyName = (from assembly in AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies()
     511                                     where string.Equals(Path.GetFullPath(assembly.Location), Path.GetFullPath(assemblyLocation), StringComparison.CurrentCultureIgnoreCase)
     512                                     select assembly.FullName).Single();
     513              // now load the assemblies into the execution context 
     514              // this can still lead to an exception
     515              // even when the assemby was successfully loaded into the reflection only context before
     516              var asm = Assembly.Load(assemblyName);
     517            }
     518            catch (BadImageFormatException) {
     519              desc.Disable(Path.GetFileName(assemblyLocation) + " is not a valid assembly.");
     520            }
     521            catch (FileLoadException) {
     522              desc.Disable("Can't load file " + Path.GetFileName(assemblyLocation));
     523            }
     524            catch (FileNotFoundException) {
     525              desc.Disable("File " + Path.GetFileName(assemblyLocation) + " is missing.");
     526            }
     527            catch (SecurityException) {
     528              desc.Disable("File " + Path.GetFileName(assemblyLocation) + " can't be loaded because of security constraints.");
     529            }
     530            catch (NotSupportedException ex) {
     531              // disable the plugin
     532              desc.Disable("Problem while loading plugin assemblies:" + Environment.NewLine + "NotSupportedException: " + ex.Message);
     533            }
    519534          }
    520535        }
     
    533548          foreach (string assemblyLocation in desc.AssemblyLocations) {
    534549            var asm = (from assembly in assemblies
    535                       where string.Equals(Path.GetFullPath(assembly.Location), Path.GetFullPath(assemblyLocation), StringComparison.CurrentCultureIgnoreCase)
    536                       select assembly)
     550                       where string.Equals(Path.GetFullPath(assembly.Location), Path.GetFullPath(assemblyLocation), StringComparison.CurrentCultureIgnoreCase)
     551                       select assembly)
    537552                      .Single();
    538553
     
    582597    }
    583598
    584     private PluginDescription GetDeclaringPlugin(Type appType, IEnumerable<PluginDescription> plugins) {
     599    private static PluginDescription GetDeclaringPlugin(Type appType, IEnumerable<PluginDescription> plugins) {
    585600      return (from p in plugins
    586601              from asmLocation in p.AssemblyLocations
Note: See TracChangeset for help on using the changeset viewer.