コード例 #1
0
ファイル: ModuleManager.cs プロジェクト: somanet/clifton
        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);
        }
コード例 #2
0
ファイル: ModuleManager.cs プロジェクト: cliftonm/clifton
        /// <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);
        }
コード例 #3
0
        /// <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));
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
ファイル: ModuleManager.cs プロジェクト: cliftonm/clifton
        /// <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;
        }
コード例 #6
0
        /// <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);
        }