Changeset 2690
- Timestamp:
- 01/27/10 17:08:03 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.PluginInfrastructure
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/Advanced/InstallationManager.cs
r2688 r2690 127 127 // or there was a problem loading the assemblies 128 128 builder.AppendLine("There was a problem while loading assemblies: "); 129 foreach ( AssemblyName assembly in desc.AssemblyNames) {130 builder.AppendLine(assembly .FullName);129 foreach (string assemblyLocation in desc.AssemblyLocations) { 130 builder.AppendLine(assemblyLocation + ": " + AssemblyName.GetAssemblyName(assemblyLocation).FullName); 131 131 } 132 132 return builder.ToString(); -
trunk/sources/HeuristicLab.PluginInfrastructure/ApplicationManager.cs
r2688 r2690 75 75 loadedAssemblies = new Dictionary<string, Assembly>(); 76 76 loadedPlugins = new List<IPlugin>(); 77 // needed for the special case when assemblies are loaded dynamically via LoadAssemblies()78 77 AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { 79 78 if (loadedAssemblies.ContainsKey(args.Name)) { … … 103 102 // load all loadable plugins (all dependencies available) into the execution context 104 103 foreach (var desc in PluginDescriptionIterator.IterateDependenciesBottomUp(plugins.Where(x => x.PluginState != PluginState.Disabled))) { 105 foreach ( AssemblyName assemblyName in desc.AssemblyNames) {106 var asm = Assembly.Load (assemblyName);107 104 foreach (string fileName in desc.AssemblyLocations) { 105 var asm = Assembly.LoadFrom(fileName); 106 RegisterLoadedAssembly(asm); 108 107 // instantiate and load all plugins in this assembly 109 108 foreach (var plugin in GetInstances<IPlugin>(asm)) { … … 213 212 PluginDescription pluginDesc = (PluginDescription)pluginDescription; 214 213 return from asm in AppDomain.CurrentDomain.GetAssemblies() 215 where pluginDesc.Assembly Names.Any(asmName => asmName.FullName.Equals(asm.GetName().FullName))214 where pluginDesc.AssemblyLocations.Any(location => location.Equals(Path.GetFullPath(asm.Location), StringComparison.CurrentCultureIgnoreCase)) 216 215 from t in GetTypes(type, asm, onlyInstantiable) 217 216 select t; … … 283 282 public IPluginDescription GetDeclaringPlugin(Type type) { 284 283 foreach (PluginDescription info in Plugins) { 285 if (info.Assembly Names.Contains(type.Assembly.GetName())) return info;284 if (info.AssemblyLocations.Contains(Path.GetFullPath(type.Assembly.Location))) return info; 286 285 } 287 286 return null; -
trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginDescription.cs
r2688 r2690 106 106 } 107 107 108 private List<AssemblyName> assemblyNames = new List<AssemblyName>();108 109 109 /// <summary> 110 /// Gets the namesof the assemblies that belong to this plugin.110 /// Gets the locations (file names) of the assemblies that belong to this plugin. 111 111 /// </summary> 112 public IEnumerable<AssemblyName> AssemblyNames { 113 get { return assemblyNames; } 114 } 115 116 internal void AddAssemblyNames(IEnumerable<AssemblyName> assemblyNames) { 117 this.assemblyNames.AddRange(assemblyNames); 112 public IEnumerable<string> AssemblyLocations { 113 get { return Files.Where(f => f.Type == PluginFileType.Assembly).Select(f => f.Name); } 118 114 } 119 115 -
trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginValidator.cs
r2688 r2690 68 68 } 69 69 70 private Dictionary<string, Assembly> reflectionOnlyAssemblies = new Dictionary<string, Assembly>(); 70 71 private Assembly ReflectionOnlyAssemblyResolveEventHandler(object sender, ResolveEventArgs args) { 71 return Assembly.ReflectionOnlyLoad(args.Name); 72 if (reflectionOnlyAssemblies.ContainsKey(args.Name)) 73 return reflectionOnlyAssemblies[args.Name]; 74 else 75 return Assembly.ReflectionOnlyLoad(args.Name); 72 76 } 73 77 … … 147 151 } 148 152 149 private staticIEnumerable<Assembly> ReflectionOnlyLoadDlls(string baseDir) {153 private IEnumerable<Assembly> ReflectionOnlyLoadDlls(string baseDir) { 150 154 List<Assembly> assemblies = new List<Assembly>(); 151 155 // recursively load .dll files in subdirectories … … 156 160 foreach (string filename in Directory.GetFiles(baseDir, "*.dll")) { 157 161 try { 158 assemblies.Add(Assembly.ReflectionOnlyLoadFrom(filename)); 162 Assembly asm = Assembly.ReflectionOnlyLoadFrom(filename); 163 RegisterLoadedAssembly(asm); 164 assemblies.Add(asm); 159 165 } 160 166 catch (BadImageFormatException) { } // just ignore the case that the .dll file is not a CLR assembly (e.g. a native dll) … … 172 178 foreach (var desc in pluginDescriptions.Where(x => x.PluginState != PluginState.Disabled)) { 173 179 try { 174 foreach (var asmName in desc.AssemblyNames) { 175 Assembly.ReflectionOnlyLoad(asmName.FullName); 180 foreach (var asmLocation in desc.AssemblyLocations) { 181 // the assembly must have been loaded in ReflectionOnlyDlls 182 // so we simply determine the name of the assembly and try to find it in the cache of loaded assemblies 183 var asmName = AssemblyName.GetAssemblyName(asmLocation); 184 185 if (!reflectionOnlyAssemblies.ContainsKey(asmName.FullName)) { 186 desc.Disable(); 187 break; // as soon as one assembly is not available disable the plugin and check the next plugin description 188 } 176 189 } 177 190 } … … 237 250 // get all attributes of that type 238 251 IList<CustomAttributeData> attributes = CustomAttributeData.GetCustomAttributes(pluginType); 239 List<AssemblyName> pluginAssemblyNames = new List<AssemblyName>();240 252 List<string> pluginDependencies = new List<string>(); 241 253 List<PluginFile> pluginFiles = new List<PluginFile>(); … … 255 267 PluginFileType fileType = (PluginFileType)attributeData.ConstructorArguments[1].Value; 256 268 pluginFiles.Add(new PluginFile(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName)), fileType)); 257 if (fileType == PluginFileType.Assembly) {258 pluginAssemblyNames.Add(AssemblyName.GetAssemblyName(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName))));259 }260 269 } 261 270 } … … 267 276 // minimal sanity check of the attribute values 268 277 if (!string.IsNullOrEmpty(pluginName) && 269 pluginFiles.Count > 0 && 270 plugin AssemblyNames.Count > 0 &&271 buildDates.Count() == 1) { 278 pluginFiles.Count > 0 && // at least on file 279 pluginFiles.Any(f => f.Type == PluginFileType.Assembly) && // at least on assembly 280 buildDates.Count() == 1) { // build date must be declared 272 281 // create a temporary PluginDescription that contains the attribute values 273 282 PluginDescription info = new PluginDescription(); … … 276 285 info.Version = pluginType.Assembly.GetName().Version; 277 286 info.BuildDate = DateTime.Parse(buildDates.Single(), System.Globalization.CultureInfo.InvariantCulture); 278 info.AddAssemblyNames(pluginAssemblyNames);279 287 info.AddFiles(pluginFiles); 280 288 … … 349 357 .Where(x => x.PluginState != PluginState.Disabled))) { 350 358 List<Type> types = new List<Type>(); 351 foreach (AssemblyName assemblyName in desc.AssemblyNames) { 352 var asm = Assembly.Load(assemblyName); 359 foreach (string assemblyLocation in desc.AssemblyLocations) { 360 // now load the assemblies into the execution context 361 var asm = Assembly.LoadFrom(assemblyLocation); 353 362 foreach (Type t in asm.GetTypes()) { 354 363 if (typeof(IPlugin).IsAssignableFrom(t)) { … … 393 402 } 394 403 404 // register assembly in the assembly cache for the ReflectionOnlyAssemblyResolveEvent 405 private void RegisterLoadedAssembly(Assembly asm) { 406 reflectionOnlyAssemblies.Add(asm.FullName, asm); 407 reflectionOnlyAssemblies.Add(asm.GetName().Name, asm); // add short name 408 } 409 395 410 internal void OnPluginLoaded(PluginInfrastructureEventArgs e) { 396 411 if (PluginLoaded != null)
Note: See TracChangeset
for help on using the changeset viewer.