private void StopModule(PluginItem pi) { pi.IsTerminating = true; Thread gentleExit = new Thread(new ThreadStart(delegate() { System.Timers.Timer tmr = new System.Timers.Timer(); tmr.Interval = 2000; tmr.Enabled = true; tmr.Elapsed += delegate(object sender, ElapsedEventArgs e) { tmr.Stop(); if (!pi.IsTerminated && pi.IsTerminating) { //* Debug Logger.Log("Stuck module detected: " + pi.Module.Name); //*/ RegistStuckPlugin(pi); } }; tmr.Start(); pi.Module.StopModule(); pi.IsTerminated = true; })); gentleExit.Start(); }
public FunctionModule GetModuleByName(string moduleName) { PluginItem pi = GetPluginByModuleName(moduleName); if (pi != null) { return(pi.Module); } return(null); }
private void UnRegistPlugin(PluginItem pi) { if (Plugins.Contains(pi)) { StopModule(pi); pi.IsRegisted = false; } //* Debug Logger.Log(pi.Module.Name + " unregisted"); //*/ }
public bool RegistStuckPlugin(PluginItem pl) { int i = Plugins.IndexOf(pl); if (i >= 0) { PluginItem pi = (PluginItem)Plugins[i]; pi.IsModuleStuck = true; return(true); } return(false); }
//private void StartPlugins() //{ // foreach (PluginItem pl in Plugins) // { // StartPlugin(pl); // //* Debug // Logger.Log(pl.Module.Name + " is starting..."); // //*/ // } // foreach (PluginItem pl in Plugins) // { // pl.Module.StartComplete(); // //* Debug // Logger.Log(pl.Module.Name + " is running..."); // //*/ // } //} private void StartPlugin(PluginItem pi) { ThreadStart ts = new ThreadStart(delegate() { pi.Module.Start(); UnRegistPlugin(pi); }); Thread th = new Thread(ts); th.SetApartmentState(ApartmentState.STA); th.Start(); }
private void CleanUnregistedPlugins() { for (int i = Plugins.Count - 1; i >= 0; i--) { PluginItem pi = (PluginItem)Plugins[i]; if (!pi.IsRegisted) { //* Debug Logger.Log("Removing " + pi.Module.Name + " from plugin list"); //*/ Plugins.Remove(pi); } } }
private PluginItem GetPluginByModuleName(string pluginName) { PluginItem rlt = null; EnumPluginItem(delegate(PluginItem pl) { if (pl.Module.Name.Equals(pluginName)) { rlt = pl; return(false); } return(true); }); return(rlt); }
public bool EnumPluginItem(EnumPluginHandler EnumPluginItemCallback) { bool rlt = true; foreach (object obj in Plugins) { PluginItem pl = (PluginItem)obj; rlt = EnumPluginItemCallback(pl); if (!rlt) { break; } } return(rlt); }
private void DirectoryOnEnum(string path) { XReader xr; string rlt = path; if (File.Exists(path)) { string typName; Assembly asm; xr = new XReader(path); try { //instanceType = xr["Plugin"]["$Instance"].Value; asm = Assembly.LoadFrom(PluginDirectory + xr.Reset()["Plugin"]["$File"].Value); typName = xr.Reset()["Plugin"]["$Type"].Value; // ModuleBase module = (ModuleBase)asm.CreateInstance(typName); FunctionModule module = (FunctionModule)CreateModuleInstanceByTypeName(typName, asm); if (module == null) { return; } module.BaseDir = path; //module.ConfigFileFullPath = path + "\\Plugin.Config"; PluginItem pl = new PluginItem(); pl.Asm = asm; pl.Module = module; bool isRegisted = RegistPlugin(pl); if (OnPluginsLoad != null) { //OnPluginsLoad(this, pl); ClassHelper.AsyncInvokeDelegates(OnPluginsLoad, DelegateInvoke_PreInvokeCallback, DelegateInvoke_PostInvokeCallback, new object[] { this, pl }); } } catch (Exception e) { //MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Exceptions.Log(e); } } }
public bool RegistPlugin(PluginItem pl) { bool rlt; ModuleBase module = pl.Module; rlt = EnumPluginItem(delegate(PluginItem existedPl) { ModuleBase existedModule = existedPl.Module; if (module.Name.Equals(existedModule.Name)) { if (existedModule.IsSingleton) { return(false); } } return(true); }); Plugins.Add(pl); pl.IsRegisted = true; //* Debug Logger.Log("Registing: " + pl.Module.Name + " " + pl.IsRegisted); //*/ return(rlt); }