- Timestamp:
- 03/22/11 16:45:46 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/DefaultApplicationManager.cs
r5445 r5796 100 100 foreach (var desc in PluginDescriptionIterator.IterateDependenciesBottomUp(plugins.Where(x => x.PluginState != PluginState.Disabled))) { 101 101 foreach (string fileName in desc.AssemblyLocations) { 102 var asm = Assembly.LoadFrom(fileName); 102 // load assembly reflection only first to get the full assembly name 103 var reflectionOnlyAssembly = Assembly.ReflectionOnlyLoadFrom(fileName); 104 // load the assembly into execution context using full assembly name 105 var asm = Assembly.Load(reflectionOnlyAssembly.FullName); 103 106 RegisterLoadedAssembly(asm); 104 107 // instantiate and load all plugins in this assembly … … 255 258 return from t in assembly.GetTypes() 256 259 where CheckTypeCompatibility(type, t) 257 where onlyInstantiable == false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType) 260 where onlyInstantiable == false || 261 (!t.IsAbstract && !t.IsInterface && !t.HasElementType) 262 where !IsNonDiscoverableType(t) 258 263 select BuildType(t, type); 264 } 265 266 private static bool IsNonDiscoverableType(Type t) { 267 return t.GetCustomAttributes(typeof(NonDiscoverableTypeAttribute), false).Any(); 259 268 } 260 269 -
branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/HeuristicLab.PluginInfrastructure-3.3.csproj
r5163 r5796 21 21 </UpgradeBackupLocation> 22 22 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 23 <TargetFrameworkProfile></TargetFrameworkProfile> 23 <TargetFrameworkProfile> 24 </TargetFrameworkProfile> 24 25 <PublishUrl>publish\</PublishUrl> 25 26 <Install>true</Install> … … 213 214 <Compile Include="Attributes\ApplicationAttribute.cs" /> 214 215 <Compile Include="Attributes\ContactInformationAttribute.cs" /> 216 <Compile Include="Attributes\NonDiscoverableTypeAttribute.cs" /> 215 217 <Compile Include="Attributes\PluginAttribute.cs" /> 216 218 <Compile Include="Attributes\PluginDependencyAttribute.cs" /> -
branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/LightweightApplicationManager.cs
r5445 r5796 122 122 where CheckTypeCompatibility(type, t) 123 123 where onlyInstantiable == false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType) 124 where !IsNonDiscoverableType(t) 124 125 select BuildType(t, type); 125 126 } … … 130 131 return Enumerable.Empty<Type>(); 131 132 } 133 } 134 135 private static bool IsNonDiscoverableType(Type t) { 136 return t.GetCustomAttributes(typeof(NonDiscoverableTypeAttribute), false).Any(); 132 137 } 133 138 -
branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/Manager/ApplicationDescription.cs
r5445 r5796 27 27 /// </summary> 28 28 [Serializable] 29 internalsealed class ApplicationDescription : IApplicationDescription {29 public sealed class ApplicationDescription : IApplicationDescription { 30 30 private string name; 31 31 -
branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/Manager/PluginManager.cs
r5445 r5796 54 54 /// Gets all installed applications. 55 55 /// </summary> 56 internalIEnumerable<ApplicationDescription> Applications {56 public IEnumerable<ApplicationDescription> Applications { 57 57 get { return applications; } 58 58 } … … 75 75 AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; 76 76 setup.PrivateBinPath = pluginDir; 77 // probing should only occur in PrivateBinPath (not in ApplicationBase). This is enforced by the value string.Empty 78 setup.PrivateBinPathProbe = string.Empty; 77 79 AppDomain pluginDomain = null; 78 80 try { 79 81 pluginDomain = AppDomain.CreateDomain("plugin domain", null, setup); 80 82 Type pluginValidatorType = typeof(PluginValidator); 81 PluginValidator remoteValidator = (PluginValidator)pluginDomain.CreateInstanceAndUnwrap(pluginValidatorType.Assembly.FullName, pluginValidatorType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null , null);83 PluginValidator remoteValidator = (PluginValidator)pluginDomain.CreateInstanceAndUnwrap(pluginValidatorType.Assembly.FullName, pluginValidatorType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null); 82 84 remoteValidator.PluginDir = pluginDir; 83 85 // forward all events from the remoteValidator to listeners … … 110 112 /// </summary> 111 113 /// <param name="appInfo">application to run</param> 112 internalvoid Run(ApplicationDescription appInfo) {114 public void Run(ApplicationDescription appInfo) { 113 115 if (!initialized) throw new InvalidOperationException("PluginManager is not initialized. DiscoverAndCheckPlugins() must be called before Run()"); 114 116 // create a separate AppDomain for the application … … 124 126 Type applicationManagerType = typeof(DefaultApplicationManager); 125 127 DefaultApplicationManager applicationManager = 126 (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null , null);128 (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null); 127 129 applicationManager.PluginLoaded += applicationManager_PluginLoaded; 128 130 applicationManager.PluginUnloaded += applicationManager_PluginUnloaded; -
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 -
branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/Sandboxing/SandboxManager.cs
r5445 r5796 85 85 Type applicationManagerType = typeof(DefaultApplicationManager); 86 86 DefaultApplicationManager applicationManager = 87 (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null , null);87 (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null); 88 88 PluginManager pm = new PluginManager(applicationBase); 89 89 pm.DiscoverAndCheckPlugins();
Note: See TracChangeset
for help on using the changeset viewer.