private DevComponent GetCallingContextType(Button clickedButton) { DevComponent componentType = DevComponent.None; try { string buttonTag = clickedButton.Tag.ToString(); if (!String.IsNullOrEmpty(buttonTag)) { string buttonTagText = buttonTag.ToLower(); switch (buttonTagText) { case "faux": componentType = DevComponent.FauxEngine; break; case "api": componentType = DevComponent.ConsoleAPI; break; case "web": componentType = DevComponent.ConsoleWeb; break; } } } catch (Exception ex) { } return(componentType); }
private void WriteToOutput(DevComponent terminalType, string content) { TextBox terminal = null; string decodedContent = DecodeLinuxCharacters(content); switch (terminalType) { case DevComponent.ConsoleAPI: terminal = ConsoleApiOutput; break; case DevComponent.ConsoleWeb: terminal = ConsoleWebOutput; break; case DevComponent.FauxEngine: terminal = FauxEngineOutput; break; } if (terminal != null) { try { Action AddLineToterminal = () => { terminal.AppendText(String.Format("{0}{1}", decodedContent, Environment.NewLine)); }; InvokeOnUIThread(AddLineToterminal); } catch (ObjectDisposedException) { //Do nothing. The app was just closed. } } }
public void OnPowershellEventReceived(DevComponent componentType, string message) { Dictionary <DevComponent, string> eventMessage = new Dictionary <DevComponent, string>() { { componentType, message } }; PowershellEventReceived?.Invoke(this, eventMessage); }
private void ExecuteCommands(List <string> commands, DevComponent component, ref Process activeProcess, bool shouldCloseInput) { Process commandLineProcess = activeProcess ?? new Process(); if (activeProcess is null) { commandLineProcess.StartInfo = new ProcessStartInfo() { FileName = "cmd.exe", CreateNoWindow = true, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, }; //Set the handlers for the data received. commandLineProcess.OutputDataReceived += (o, e) => OnPowershellEventReceived(component, e.Data); commandLineProcess.ErrorDataReceived += (o, e) => OnPowershellEventReceived(component, e.Data); commandLineProcess.Start(); } foreach (string command in commands) { //execute the commands. The outputs will be handled asynchronously commandLineProcess.StandardInput.WriteLine("{0}", command); commandLineProcess.StandardInput.Flush(); } if (shouldCloseInput) { commandLineProcess.StandardInput.Dispose(); } if (activeProcess is null) { commandLineProcess.BeginOutputReadLine(); commandLineProcess.BeginErrorReadLine(); activeProcess = commandLineProcess; } commandLineProcess.WaitForExit(); }
private void ClearTerminal_Click(object sender, EventArgs e) { Button activeButton = sender as Button; if (activeButton != null) { DevComponent terminalContext = GetCallingContextType(activeButton); TextBox terminalToClear = GetTerminal(terminalContext); if (terminalToClear != null) { Action ClearTerminalText = () => { terminalToClear.Text = String.Empty; }; InvokeOnUIThread(ClearTerminalText); } } }
private void RefreshTerminal_Click(object sender, EventArgs e) { Button activeButton = sender as Button; List <string> commands = new List <string>() { "rs" }; if (activeButton != null) { DevComponent terminalContext = GetCallingContextType(activeButton); if (terminalContext != DevComponent.None) { DevManager.DevEnvironmentTasks.StartNew(() => DevManager.SendCommand(terminalContext, commands)); } } }
public void SendCommand(DevComponent terminalType, List <string> commands) { Process matchingTerminalProcess = null; switch (terminalType) { case DevComponent.ConsoleAPI: matchingTerminalProcess = ConsoleAPIProcess; break; case DevComponent.ConsoleWeb: matchingTerminalProcess = ConsoleWebProcess; break; case DevComponent.FauxEngine: matchingTerminalProcess = FauxEngineProcess; break; } ExecuteCommands(commands, terminalType, ref matchingTerminalProcess, false); }
private TextBox GetTerminal(DevComponent terminalType) { TextBox terminal = null; switch (terminalType) { case DevComponent.ConsoleAPI: terminal = ConsoleApiOutput; break; case DevComponent.ConsoleWeb: terminal = ConsoleWebOutput; break; case DevComponent.FauxEngine: terminal = FauxEngineOutput; break; } return(terminal); }
private void DevManager_PowershellEventReceived(object sender, Dictionary <DevComponent, string> args) { DevComponent componentType = args.Keys.FirstOrDefault(); WriteToOutput(componentType, args[componentType]); }
internal static void Add(DevComponent component) { _devComponents.Add(component); }