private static void CreatePluginList(Assembly pluginAssembly, List <Type> pluginClientTypeList, Guid embeddedPluginGuid, ITracer logger, out List <IPluginClient> pluginList) { pluginList = new List <IPluginClient>(); foreach (Type ClientType in pluginClientTypeList) { try { Contract.RequireNotNull(ClientType.FullName, out string FullName); object?PluginHandle = pluginAssembly.CreateInstance(FullName); if (PluginHandle != null) { string?PluginName = PluginProperty <string?>(PluginHandle, nameof(IPluginClient.Name)); Guid PluginGuid = PluginProperty <Guid>(PluginHandle, nameof(IPluginClient.Guid)); bool PluginRequireElevated = PluginProperty <bool>(PluginHandle, nameof(IPluginClient.RequireElevated)); bool PluginHasClickHandler = PluginProperty <bool>(PluginHandle, nameof(IPluginClient.HasClickHandler)); if (PluginName != null && PluginName.Length > 0 && PluginGuid != Guid.Empty) { bool createdNew; EventWaitHandle?InstanceEvent; if (PluginGuid != embeddedPluginGuid) { InstanceEvent = new EventWaitHandle(false, EventResetMode.ManualReset, GuidToString(PluginGuid), out createdNew); } else { createdNew = true; InstanceEvent = null; } if (createdNew && PluginName != null) { IPluginClient NewPlugin = new PluginClient(PluginHandle, PluginName, PluginGuid, PluginRequireElevated, PluginHasClickHandler, InstanceEvent); pluginList.Add(NewPlugin); } else { logger.Write(Category.Warning, "Another instance of a plugin is already running"); InstanceEvent?.Close(); InstanceEvent = null; } } } } catch { } } }
private static void CreatePluginList(Assembly pluginAssembly, List <Type> PluginClientTypeList, Guid embeddedPluginGuid, IPluginLogger logger, out List <IPluginClient> PluginList) { PluginList = new List <IPluginClient>(); foreach (Type ClientType in PluginClientTypeList) { try { object PluginHandle = pluginAssembly.CreateInstance(ClientType.FullName); if (PluginHandle != null) { string PluginName = PluginHandle.GetType().InvokeMember(nameof(IPluginClient.Name), BindingFlags.Default | BindingFlags.GetProperty, null, PluginHandle, null) as string; Guid PluginGuid = (Guid)PluginHandle.GetType().InvokeMember(nameof(IPluginClient.Guid), BindingFlags.Default | BindingFlags.GetProperty, null, PluginHandle, null); bool PluginRequireElevated = (bool)PluginHandle.GetType().InvokeMember(nameof(IPluginClient.RequireElevated), BindingFlags.Default | BindingFlags.GetProperty, null, PluginHandle, null); bool PluginHasClickHandler = (bool)PluginHandle.GetType().InvokeMember(nameof(IPluginClient.HasClickHandler), BindingFlags.Default | BindingFlags.GetProperty, null, PluginHandle, null); if (!string.IsNullOrEmpty(PluginName) && PluginGuid != Guid.Empty) { bool createdNew; EventWaitHandle InstanceEvent; if (PluginGuid != embeddedPluginGuid) { InstanceEvent = new EventWaitHandle(false, EventResetMode.ManualReset, GuidToString(PluginGuid), out createdNew); } else { createdNew = true; InstanceEvent = null; } if (createdNew) { IPluginClient NewPlugin = new PluginClient(PluginHandle, PluginName, PluginGuid, PluginRequireElevated, PluginHasClickHandler, InstanceEvent); PluginList.Add(NewPlugin); } else { logger.AddLog("Another instance of a plugin is already running"); InstanceEvent.Close(); InstanceEvent = null; } } } } catch { } } }
// Someone called Exit on the application. Time to clean things up. private void OnExit(object sender, ExitEventArgs e) { Logger.AddLog("Exiting application"); // Set this flag to minimize asynchronous activities. IsExiting = true; StopPlugInManager(); CleanupTaskbarIcon(); CleanupTimer(); if (InstanceEvent != null) { InstanceEvent.Close(); InstanceEvent = null; } // Explicit display of the last message since timed debug is not running anymore. Logger.AddLog("Done"); UpdateLogger(); }