protected virtual Assembly LoadAssemblyFrom(AssemblyFileName assyName, string path, Func <string, Assembly> assemblyResolver = null) { string fullPath = Path.Combine(path, assyName.Value); Assembly assembly = null; if (!File.Exists(fullPath)) { throw new ApplicationException("Module " + fullPath + " not found.\r\n."); // Assert.Not(assemblyResolver == null, "Module " + fullPath + " not found.\r\n. An assemblyResolver must be defined when attempting to load modules from the application's resources or specify the optionalPath to locate the assembly."); // assembly = assemblyResolver(assyName.Value); } else { try { assembly = Assembly.LoadFile(fullPath); } catch (Exception ex) { throw new ModuleManagerException("Unable to load module " + assyName.Value + ": " + ex.Message); } } return(assembly); }
/// <summary> /// Return the full path of the executing application (here we assume that ModuleManager.dll is in that path) and concatenate the assembly name of the module. /// .NET requires the the full path in order to load the associated assembly. /// </summary> protected virtual FullPath GetFullPath(AssemblyFileName assemblyName, OptionalPath optionalPath) { string appLocation; string assyLocation = Assembly.GetExecutingAssembly().Location; // An assembly that is loaded as a resource will have its assembly location as "". if (assyLocation == "") { Assert.Not(optionalPath == null, "Assemblies embedded as resources require that the optionalPath parameter specify the path to resolve assemblies."); appLocation = optionalPath.Value; // Must be specified! Here the optional path is the full path? This gives two different meanings to how optional path is used! } else { appLocation = Path.GetDirectoryName(assyLocation); if (optionalPath != null) { appLocation = Path.Combine(appLocation, optionalPath.Value); } } string fullPath = Path.Combine(appLocation, assemblyName.Value); return FullPath.Create(fullPath); }
/// <summary> /// Return the full path of the executing application (here we assume that ModuleManager.dll is in that path) and concatenate the assembly name of the module. /// .NET requires the the full path in order to load the associated assembly. /// </summary> protected virtual FullPath GetFullPath(AssemblyFileName assemblyName, OptionalPath optionalPath) { string appLocation; string assyLocation = Assembly.GetExecutingAssembly().Location; // An assembly that is loaded as a resource will have its assembly location as "". if (assyLocation == "") { Assert.Not(optionalPath == null, "Assemblies embedded as resources require that the optionalPath parameter specify the path to resolve assemblies."); appLocation = optionalPath.Value; // Must be specified! Here the optional path is the full path? This gives two different meanings to how optional path is used! } else { appLocation = Path.GetDirectoryName(assyLocation); if (optionalPath != null) { appLocation = Path.Combine(appLocation, optionalPath.Value); } } string fullPath = Path.Combine(appLocation, assemblyName.Value); return(FullPath.Create(fullPath)); }
/// <summary> /// Load and return an assembly given the assembly filename so we can proceed with /// instantiating the module and so the module can register its services. /// </summary> protected virtual Assembly LoadAssembly(AssemblyFileName assyName, OptionalPath optionalPath, Func <string, Assembly> assemblyResolver) { FullPath fullPath = GetFullPath(assyName, optionalPath); Assembly assembly = null; if (!File.Exists(fullPath.Value)) { Assert.Not(assemblyResolver == null, "assemblyResolver must be defined when attempting to load modules from the application's resources."); assembly = assemblyResolver(assyName.Value); } else { try { assembly = Assembly.LoadFile(fullPath.Value); } catch (Exception ex) { throw new ModuleManagerException("Unable to load module " + assyName.Value + ": " + ex.Message); } } return(assembly); }
/// <summary> /// Load and return an assembly given the assembly filename so we can proceed with /// instantiating the module and so the module can register its services. /// </summary> protected virtual Assembly LoadAssembly(AssemblyFileName assyName, OptionalPath optionalPath, Func<string, Assembly> assemblyResolver) { FullPath fullPath = GetFullPath(assyName, optionalPath); Assembly assembly = null; if (!File.Exists(fullPath.Value)) { Assert.Not(assemblyResolver == null, "Module " + fullPath.Value + " not found.\r\n. An assemblyResolver must be defined when attempting to load modules from the application's resources or specify the optionalPath to locate the assembly."); assembly = assemblyResolver(assyName.Value); } else { try { assembly = Assembly.LoadFile(fullPath.Value); } catch (Exception ex) { throw new ModuleManagerException("Unable to load module " + assyName.Value + ": " + ex.Message); } } return assembly; }
/// <summary> /// Returns the list of modules specified in the XML document so we know what /// modules to instantiate. /// </summary> static private List <AssemblyFileName> GetModuleList(XDocument xdoc) { List <AssemblyFileName> assemblies = new List <AssemblyFileName>(); (from module in xdoc.Element("Modules").Elements("Module") select module.Attribute("AssemblyName").Value).ForEach(s => assemblies.Add(AssemblyFileName.Create(s))); return(assemblies); }