internal object GetInstance() { if (_ClassType == null) { _ClassType = _Manager.LoadAssembly().GetType(_ClassName, true, false); _ClassName = null; } return(Activator.CreateInstance(_ClassType, false)); }
internal ModuleAction GetInstance() { if (_ClassType == null) { _ClassType = _Manager.LoadAssembly().GetType(_ClassName, true, false); _ClassName = null; } return((ModuleAction)ModuleManager.CreateEntry(_ClassType)); }
/// <summary> /// Loads the module assembly. /// </summary> /// <param name="fileName">The assembly path to load a module from.</param> void LoadModule(string fileName) { Log.Source.TraceInformation("Load module {0}", fileName); // use the file info to reduce file access var fileInfo = new FileInfo(fileName); if (!fileInfo.Exists) { Log.Source.TraceInformation("Module is not found."); return; } // load from the cache if (ReadCache(fileInfo)) { return; } // add new module manager now, it will be removed on errors ModuleManager manager = new ModuleManager(fileInfo.FullName); _Managers.Add(manager.ModuleName, manager); // read and load data var settings = manager.ReadSettings(); manager.LoadData(settings); bool done = false; try { Log.Source.TraceInformation("Load module {0}", manager.ModuleName); int actionCount = 0; Assembly assembly = manager.LoadAssembly(); foreach (Type type in assembly.GetExportedTypes()) { if (typeof(BaseModuleItem).IsAssignableFrom(type) && !type.IsAbstract) { actionCount += LoadType(manager, settings, type); } else if (!manager.HasSettings && typeof(ApplicationSettingsBase).IsAssignableFrom(type) && !type.IsAbstract) { manager.HasSettings = true; } } // if the module has the host to load then load it now, if it is not loaded then the module should be cached if (!manager.LoadLoadableModuleHost()) { if (0 == actionCount) { throw new ModuleException("A module must have a public action or a pre-loadable host."); } SaveModuleCache(manager, fileInfo); } // done done = true; } finally { if (!done) { RemoveModuleManager(manager); } } }
/// <summary> /// Loads the module assembly. /// </summary> /// <param name="fileName">The assembly path to load a module from.</param> void LoadModule(string fileName) { Log.Source.TraceInformation("Load module {0}", fileName); // use the file info to reduce file access var fileInfo = new FileInfo(fileName); if (!fileInfo.Exists) { Log.Source.TraceInformation("Module is not found."); return; } // load from the cache if (ReadCache(fileInfo)) return; // add new module manager now, it will be removed on errors ModuleManager manager = new ModuleManager(fileInfo.FullName); _Managers.Add(manager.ModuleName, manager); // read and load data var settings = manager.ReadSettings(); manager.LoadData(settings); bool done = false; try { Log.Source.TraceInformation("Load module {0}", manager.ModuleName); int actionCount = 0; Assembly assembly = manager.LoadAssembly(); foreach (Type type in assembly.GetExportedTypes()) { if (typeof(BaseModuleItem).IsAssignableFrom(type) && !type.IsAbstract) actionCount += LoadType(manager, settings, type); else if (!manager.HasSettings && typeof(ApplicationSettingsBase).IsAssignableFrom(type) && !type.IsAbstract) manager.HasSettings = true; } // if the module has the host to load then load it now, if it is not loaded then the module should be cached if (!manager.LoadLoadableModuleHost()) { if (0 == actionCount) throw new ModuleException("A module must have a public action or a pre-loadable host."); SaveModuleCache(manager, fileInfo); } // done done = true; } finally { if (!done) RemoveModuleManager(manager); } }