private void TerminatePlugin(PluginInfo plugin) { lock (_pluginsSync) { var exePath = Const.GetPluginExePath(plugin.Name); if (plugin.Process == null) { // stop any processes left from the previous agent launch, if any. normally this should not happen var processName = Path.GetFileNameWithoutExtension(exePath); var processes = Process.GetProcessesByName(processName); foreach (var process in processes) { KillProcess(process); } } else { KillProcess(plugin.Process); plugin.Process = null; } } }
private void StopPlugin(PluginInfo plugin) { lock (_pluginsSync) { SendPluginStopSignal(plugin); var startTime = DateTime.UtcNow; while ((DateTime.UtcNow - startTime) < WaitPluginPeriod) { if (!plugin.IsStarted) return; Thread.Sleep(TimeSpan.FromSeconds(1)); } TerminatePlugin(plugin); } }
private void SendPluginStopSignal(PluginInfo plugin) { lock (_pluginsSync) { if (!plugin.IsStarted) return; ReportEvent("Stop plugin: " + plugin.Name); try { // send signal to close var eventName = Const.GetStopEventName(plugin.Process.Id); var stopEvent = EventWaitHandle.OpenExisting(eventName); stopEvent.Set(); } catch (WaitHandleCannotBeOpenedException) { } catch (Exception exc) { Report(exc); } } }
private void EnsurePluginStarted(PluginInfo plugin) { try { if (plugin.IsStarted) return; ReportEvent("Start plugin: " + plugin.Name); var exePath = Const.GetPluginExePath(plugin.Name); var version = FileVersionInfo.GetVersionInfo(exePath).FileVersion; ReportEvent(string.Format("Plugin version: {0} {1}", plugin.Name, version)); var startInfo = new ProcessStartInfo(exePath) { UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, RedirectStandardInput = true, }; var process = Process.Start(startInfo); plugin.Process = process; } catch (Exception exc) { Report(exc); } }
private void StopPlugin(PluginInfo plugin) { SendPluginStopSignal(plugin); Thread.Sleep(WaitPluginPeriod); TerminatePlugin(plugin); }
private void EnsurePluginStarted(PluginInfo plugin) { if (plugin.Process != null) return; ReportEvent("Start plugin: " + plugin.Name); var exePath = Const.GetPluginExePath(plugin.Name); var startInfo = new ProcessStartInfo(exePath) { UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, RedirectStandardInput = true, }; var process = Process.Start(startInfo); plugin.Process = process; }