private void frmMain_Load(object sender, EventArgs e) { if (!this.Context.IsLoggedOn) { this.Context.Transfer(new frmLogin()); } else { ModuleGlobal mg = new ModuleGlobal(); mg.User = User; ModuleManager manager = new ModuleManager(); manager.LoadModules(mg); foreach (IModule module in manager.AvailableModules) { tvMenuModule.Nodes.Add(new TreeNode { Tag = module, Name = module.ModuleID.ToString(), Text = module.ModuleName }); if (module.Order == 1) { tvMenuModule.SelectedNode = tvMenuModule.Nodes[tvMenuModule.Nodes.Count - 1]; } } } }
public void LoadModules(ModuleGlobal mg) { DirectoryInfo di = new DirectoryInfo(Gizmox.WebGUI.Common.Global.Context.Config.GetDirectory("Modules")); FileInfo[] Files = di.GetFiles("*.dll", SearchOption.TopDirectoryOnly); foreach (FileInfo file in Files) { Assembly assembly = Assembly.LoadFrom(file.FullName); Type[] AssemblyTypes = assembly.GetTypes(); foreach (Type t in AssemblyTypes) { if (t.IsPublic) { Type moduleinterface = t.GetInterface("Odin.IModule"); if (moduleinterface != null) { AddModule(CreateModule(assembly, t, mg)); break; } } } AssemblyTypes = null; assembly = null; } AvailableModules.Sort((x, y) => x.Order.CompareTo(y.Order)); }
private IModule CreateModule(Assembly assembly, Type t, ModuleGlobal mg) { IModule module = (IModule)Activator.CreateInstance(t); module.GlobalConfig = mg; module.initialize(); return(module); }