private void OnTTYFormClose(TTYForm tty) { lblAppStatus.Text = "Closed " + tty.Session.Type.ToString() + " session to " + tty.Session.Host; numOpenTTYs--; if (numOpenTTYs < 0) { numOpenTTYs = 0; } if (numOpenTTYs == 0) { lblNoSessionsStarted.Show(); } }
public void openTTY(SessionInfo session) { while (!File.Exists(puttyPath)) { DialogResult res = MessageBox.Show("PuTTY is not installed. Please put your putty.exe in the following path:\n" + puttyPath, "PuTTY not installed", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); if (res == DialogResult.Cancel) { return; } } ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.FileName = puttyPath; string args = ""; switch (session.Type) { case SessionType.SSH: args += "-ssh "; break; default: MessageBox.Show("Unsupported session type: " + session.Type, "Unsupported session type", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (session.Username.Length > 0) { args += session.Username + "@"; } args += session.Host; processStartInfo.Arguments = args; Process process = Process.Start(processStartInfo); ttyDisposalJob.AddProcess(process.Handle); while (!Win32.IsWindowVisible(process.MainWindowHandle)) { Thread.Sleep(50); } // Wait another 100ms just to be sure putty has loaded Thread.Sleep(100); var tty = new TTYForm(process, session); tty.Dock = DockStyle.Fill; tty.DockAreas = DockAreas.Document; tty.Show(dockPanel, DockState.Document); tty.StartPosition = FormStartPosition.CenterParent; tty.FormBorderStyle = FormBorderStyle.None; tty.BackColor = Color.Aqua; tty.OnClose.Add(OnTTYFormClose); numOpenTTYs++; lblAppStatus.Text = "Opened new " + session.Type.ToString() + " session to " + session.Host; lblNoSessionsStarted.Hide(); }