Changeset 4534 for trunk/sources
- Timestamp:
- 09/28/10 16:22:40 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Manager/PluginValidator.cs
r4482 r4534 121 121 CheckPluginDependencies(pluginDescriptions); 122 122 123 // test full loading (in contrast to reflection only loading) of plugins 124 // disables plugins that are not loaded correctly 125 CheckExecutionContextLoad(pluginDescriptions); 126 123 127 // mark all plugins as enabled that were not disabled in CheckPluginFiles, CheckPluginAssemblies, 124 // CheckCircularDependencies, or CheckPluginDependencies128 // CheckCircularDependencies, CheckPluginDependencies and CheckExecutionContextLoad 125 129 foreach (var desc in pluginDescriptions) 126 130 if (desc.PluginState != PluginState.Disabled) 127 131 desc.Enable(); 128 132 129 // test full loading (in contrast to reflection only loading) of plugins 130 // disables plugins that are not loaded correctly 133 // load the enabled plugins 131 134 LoadPlugins(pluginDescriptions); 132 135 … … 490 493 } 491 494 492 private void LoadPlugins(IEnumerable<PluginDescription> pluginDescriptions) { 495 // tries to load all plugin assemblies into the execution context 496 // if an assembly of a plugin cannot be loaded the plugin is disabled 497 private void CheckExecutionContextLoad(IEnumerable<PluginDescription> pluginDescriptions) { 493 498 // load all loadable plugins (all dependencies available) into the execution context 494 499 foreach (var desc in PluginDescriptionIterator.IterateDependenciesBottomUp(pluginDescriptions 495 500 .Where(x => x.PluginState != PluginState.Disabled))) { 496 List<Type> types = new List<Type>();497 501 foreach (string assemblyLocation in desc.AssemblyLocations) { 498 // now load the assemblies into the execution context 499 var asm = Assembly.LoadFrom(assemblyLocation); 500 foreach (Type t in asm.GetTypes()) { 501 if (typeof(IPlugin).IsAssignableFrom(t)) { 502 types.Add(t); 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."); 519 } 520 } 521 } 522 } 523 524 // assumes that all plugin assemblies have been loaded into the execution context via CheckExecutionContextLoad 525 // for each enabled plugin: 526 // calls OnLoad method of the plugin 527 // and raises the PluginLoaded event 528 private void LoadPlugins(IEnumerable<PluginDescription> pluginDescriptions) { 529 List<Assembly> assemblies = new List<Assembly>(AppDomain.CurrentDomain.GetAssemblies()); 530 foreach (var desc in pluginDescriptions) { 531 if (desc.PluginState == PluginState.Enabled) { 532 // cannot use ApplicationManager to retrieve types because it is not yet instantiated 533 foreach (string assemblyLocation in desc.AssemblyLocations) { 534 var asm = (from assembly in assemblies 535 where string.Equals(Path.GetFullPath(assembly.Location), Path.GetFullPath(assemblyLocation), StringComparison.CurrentCultureIgnoreCase) 536 select assembly) 537 .Single(); 538 539 foreach (Type pluginType in asm.GetTypes()) { 540 if (typeof(IPlugin).IsAssignableFrom(pluginType) && !pluginType.IsAbstract && !pluginType.IsInterface && !pluginType.HasElementType) { 541 IPlugin plugin = (IPlugin)Activator.CreateInstance(pluginType); 542 plugin.OnLoad(); 543 OnPluginLoaded(new PluginInfrastructureEventArgs(desc)); 544 } 503 545 } 504 } 505 } 506 507 foreach (Type pluginType in types) { 508 if (!pluginType.IsAbstract && !pluginType.IsInterface && !pluginType.HasElementType) { 509 IPlugin plugin = (IPlugin)Activator.CreateInstance(pluginType); 510 plugin.OnLoad(); 511 OnPluginLoaded(new PluginInfrastructureEventArgs(desc)); 512 } 513 } 514 desc.Load(); 515 } 546 } // end foreach assembly in plugin 547 desc.Load(); 548 } 549 } // end foreach plugin description 516 550 } 517 551
Note: See TracChangeset
for help on using the changeset viewer.