Changeset 5796 for branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/Manager/PluginValidator.cs
- Timestamp:
- 03/22/11 16:45:46 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/Manager/PluginValidator.cs
r5445 r5796 117 117 CheckPluginDependencyCycles(pluginDescriptions); 118 118 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 121 123 CheckPluginDependencies(pluginDescriptions); 122 124 … … 124 126 // disables plugins that are not loaded correctly 125 127 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); 126 132 127 133 // mark all plugins as enabled that were not disabled in CheckPluginFiles, CheckPluginAssemblies, … … 135 141 136 142 plugins = pluginDescriptions; 137 DiscoverApplications( );138 } 139 140 private void DiscoverApplications( ) {143 DiscoverApplications(pluginDescriptions); 144 } 145 146 private void DiscoverApplications(IEnumerable<PluginDescription> pluginDescriptions) { 141 147 applications = new List<ApplicationDescription>(); 142 143 foreach (IApplication application in GetApplications()) { 148 foreach (IApplication application in GetApplications(pluginDescriptions)) { 144 149 Type appType = application.GetType(); 145 150 ApplicationAttribute attr = (from x in appType.GetCustomAttributes(typeof(ApplicationAttribute), false) 146 151 select (ApplicationAttribute)x).Single(); 147 var declaringPlugin = GetDeclaringPlugin(appType, plugins);148 152 ApplicationDescription info = new ApplicationDescription(); 153 PluginDescription declaringPlugin = GetDeclaringPlugin(appType, pluginDescriptions); 149 154 info.Name = application.Name; 150 155 info.Version = declaringPlugin.Version; … … 158 163 } 159 164 160 private static IEnumerable<IApplication> GetApplications( ) {165 private static IEnumerable<IApplication> GetApplications(IEnumerable<PluginDescription> pluginDescriptions) { 161 166 return from asm in AppDomain.CurrentDomain.GetAssemblies() 162 167 from t in asm.GetTypes() 163 168 where typeof(IApplication).IsAssignableFrom(t) && 164 169 !t.IsAbstract && !t.IsInterface && !t.HasElementType 170 where GetDeclaringPlugin(t, pluginDescriptions).PluginState != PluginState.Disabled 165 171 select (IApplication)Activator.CreateInstance(t); 166 172 } … … 173 179 } 174 180 // 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"))) { 176 182 try { 177 183 Assembly asm = Assembly.ReflectionOnlyLoadFrom(filename); … … 500 506 .Where(x => x.PluginState != PluginState.Disabled))) { 501 507 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 } 519 534 } 520 535 } … … 533 548 foreach (string assemblyLocation in desc.AssemblyLocations) { 534 549 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) 537 552 .Single(); 538 553 … … 582 597 } 583 598 584 private PluginDescription GetDeclaringPlugin(Type appType, IEnumerable<PluginDescription> plugins) {599 private static PluginDescription GetDeclaringPlugin(Type appType, IEnumerable<PluginDescription> plugins) { 585 600 return (from p in plugins 586 601 from asmLocation in p.AssemblyLocations
Note: See TracChangeset
for help on using the changeset viewer.