private void InitializeTerminalPane() { if (GApp._frame == null) { string[] args = new string[0]; GApp.Run(args); GApp._frame._multiPaneControl.InitUI(null, GApp.Options); GEnv.InterThreadUIService.MainFrameHandle = GApp._frame.Handle; } this._terminalPane = new TerminalPane(); this.TerminalPane.Dock = DockStyle.Fill; this.Controls.Add(this.TerminalPane); }
public void Connect() { // 先判断连接状态 if (IsConnected || _isConnecting) { return; } _isConnecting = true; if (statusText == null) { statusText = new Label(); statusText.Dock = DockStyle.Fill; statusText.BackColor = Color.White; statusText.ForeColor = Color.Black; statusText.Font = new Font("Microsoft YaHei", 10); statusText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; } statusText.Text = "正在连接"; statusText.Visible = true; this.Invalidate(); this.Controls.Add(statusText); if (GApp._frame == null) { GApp.Run(new string[0]); GApp.Options.BGColor = this.BackColor; GApp.Options.TextColor = this.ForeColor; GApp.Options.RightButtonAction = RightButtonAction.Paste; GApp.Options.AutoCopyByLeftButton = true; //GApp.Options.WarningOption = WarningOption.Ignore; GApp.Options.Font = this.Font; GApp._frame._multiPaneControl.InitUI(null, GApp.Options); GEnv.InterThreadUIService.MainFrameHandle = GApp._frame.Handle; } try { //------------------------------------------------------------------------ SSHTerminalParam sshp = new SSHTerminalParam(Poderosa.ConnectionParam.ConnectionMethod.SSH2, this.Host, this.UserName, this.Password); sshp.AuthType = AuthType.Password; sshp.IdentityFile = string.Empty; sshp.Encoding = EncodingType.UTF8; sshp.Port = this._port; sshp.RenderProfile = new RenderProfile(); sshp.TerminalType = TerminalType.XTerm; CommunicationUtil.SilentClient s = new CommunicationUtil.SilentClient(); Size sz = this.Size; SocketWithTimeout swt = new SSHConnector(sshp, sz, sshp.Passphrase, null); swt.AsyncConnect(s, sshp.Host, sshp.Port, (ct, errorMessage) => { if (ct == null) { statusText.Invoke(new Action(() => { statusText.Text = "连接异常:" + errorMessage; })); return; } if (this._terminalPane == null) { this.Invoke(new Action(() => { this._terminalPane = new TerminalPane(); InitTerminalPane(ct); })); } else { this._terminalPane.Invoke(new Action(() => { this._terminalPane.Detach(); InitTerminalPane(ct); })); } }); } catch (Exception ex) { statusText.Text = "连接异常:" + ex.Message; return; } _isConnecting = false; }