예제 #1
0
        private void moduleMenager_OnActivateModule(ModuleObject moduleObject)
        {
            Assembly assembly = null;
            Type pluginType = null;
            IModule moduleInstance = null;

            try
            {
                if (moduleManager.IsActive(moduleObject.Instance) == true)
                {
                    MessageBox.Show("Aktivane vec");
                    return;
                }

                //AppDomainSetup info = new AppDomainSetup();

                //moduleObject.AppDomain = AppDomain.CreateDomain("ModuleActive" + new Random().Next(100), null, info);
                assembly = null;
                assembly = Assembly.LoadFile(moduleObject.Path);
                ///
                ////ModuleLoader lp = (ModuleLoader)moduleObject.AppDomain.CreateInstanceAndUnwrap("UberToolsPlugins", "DamirM.Module.ModuleLoader");
                //ModuleLoader lp = (ModuleLoader)moduleObject.AppDomain.CreateInstanceAndUnwrap("UberTools", "UberTools.Class.ModuleLoader");
                ////assembly = lp.LoadAssambly(moduleObject.Path);

                ////    - - - - fix neki -    -- -- - -temp
                //FileStream fs = new FileStream(moduleObject.Path, FileMode.Open);
                //byte[] buffer = new byte[(int)fs.Length];
                //fs.Read(buffer, 0, buffer.Length);
                //fs.Close();

                //assembly = Assembly.Load(buffer);

                if (assembly != null)
                {
                    foreach (Type type in assembly.GetTypes())
                    {
                        if (type.IsAbstract) continue;
                        // if this type have Module attribute then this is ubertools module
                        if (type.IsDefined(typeof(ModuleAttribute), true))
                        {
                            pluginType = type;
                            break;
                        }
                    }

                    if (pluginType != null)
                    {
                        Log.Write("Loading module: " + moduleObject.Name, this, "moduleMenager_OnActivateModule", Log.LogType.DEBUG);
                        // crete new domain, TEST
                        //AppDomain domain = AppDomain.CreateDomain("NewAppDomain");
                        //domain.CreateInstance(assembly.GetName,

                        //domain.CreateInstance(assembly.GetName().ToString(), pluginType.FullName);

                        // Create module instace
                        moduleInstance = (IModule)Activator.CreateInstance(pluginType);
                        // subscribe to module unload event
                        moduleInstance.Unload += new ModuleManager.delModule(plugin_Unload);

                        // save instance of this module
                        moduleObject.Instance = moduleInstance;

                        // set moduleobject to module instance
                        //moduleInstance.ModuleObject = moduleObject;

                        ModuleParams uberToolsPluginParams = new ModuleParams();
                        uberToolsPluginParams.DataPath = Common.BuildPath(Application.StartupPath, "data");
                        moduleInstance.ModuleParams = uberToolsPluginParams;

                        moduleInstance.GetModuleLog.OnLog += new ModuleLog.delLog(Log.Write);

                        ModuleMainFormBase moduleMainForm = moduleInstance.ShowDialog(this, true);
                        // subscribe to events
                        moduleMainForm.Enter += new EventHandler(toolsWindowsMenager.Activate);
                        moduleMainForm.Deactivate += new EventHandler(toolsWindowsMenager.LostFocus);

                        moduleMainForm.WindowState = FormWindowState.Maximized;
                        if (moduleMainForm.ToolsWindows() != null)
                        {
                            toolsWindowsMenager.AddControls(moduleMainForm.ToolsWindows());
                        }
                    }
                    else
                    {
                        Log.Write(new string[] { "Error loading module: " + moduleObject.Path, "Invalid module type" }, this, "moduleMenager_OnActivateModule", Log.LogType.ERROR);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write("Error loading plugin " + moduleObject.Path, this, "moduleMenager_OnActivateModule", Log.LogType.DEBUG);
                Log.Write(ex, this, "moduleMenager_OnActivateModule", Log.LogType.ERROR, true);
            }
        }
예제 #2
0
 public ModuleObject Add(string path, string name)
 {
     ModuleObject moduleObject = new ModuleObject(path, name, OnActivateModule);
     list.Add(moduleObject);
     return moduleObject;
 }