Ejemplo n.º 1
0
        public void Connect()
        {
            #region old stuff
            /*
            Poderosa.ConnectionParam.LogType logType = Poderosa.ConnectionParam.LogType.Default;
            string file = null;
            if (this.TerminalPane.Connection != null)
            {
                logType = this.TerminalPane.Connection.LogType;
                file = this.TerminalPane.Connection.LogPath;
                //GApp.GetConnectionCommandTarget().Close();
                this.TerminalPane.Connection.Close();
                this.TerminalPane.Detach();
            }

            SSHTerminalParam p = new SSHTerminalParam((Poderosa.ConnectionParam.ConnectionMethod)this.Method, this.Host, this.UserName, this.Password);

            GApp.GlobalCommandTarget.SilentNewConnection(p);

            if (file != null)
                this.SetLog((LogType) logType, file, true);
            */
            #endregion

            // Save old log info in case this is a reconnect
            Poderosa.ConnectionParam.LogType logType = Poderosa.ConnectionParam.LogType.Default;
            string file = null;
            if (this.TerminalPane.Connection != null)
            {
                logType = this.TerminalPane.Connection.LogType;
                file = this.TerminalPane.Connection.LogPath;
                //GApp.GetConnectionCommandTarget().Close();
                this.TerminalPane.Connection.Close();
                this.TerminalPane.Detach();
            }

            //------------------------------------------------------------------------
            SSHTerminalParam sshp = new SSHTerminalParam((Poderosa.ConnectionParam.ConnectionMethod)this.Method, this.Host, this.UserName, this.Password);
            sshp.AuthType = this.AuthType;
            sshp.IdentityFile = this.IdentifyFile;
            sshp.Encoding = EncodingType.ISO8859_1;
            sshp.Port = 22;
            sshp.RenderProfile = new RenderProfile();
            sshp.TerminalType = TerminalType.XTerm;

            CommunicationUtil.SilentClient s = new CommunicationUtil.SilentClient();
            Size sz = this.Size;

            SocketWithTimeout swt;
            swt = new SSHConnector((Poderosa.ConnectionParam.SSHTerminalParam)sshp, sz, sshp.Passphrase, (HostKeyCheckCallback)null);
            swt.AsyncConnect(s, sshp.Host, sshp.Port);
            ConnectionTag ct = s.Wait(swt);

            if (ct == null)
                throw new SSHException(swt.ErrorMessage);

            this.TerminalPane.FakeVisible = true;

            this.TerminalPane.Attach(ct);
            ct.Receiver.Listen();
            //-------------------------------------------------------------
            if (file != null)
                this.SetLog((LogType)logType, file, true);
            this.TerminalPane.ConnectionTag.RenderProfile = new RenderProfile();
            this.SetPaneColors(Color.LightBlue, Color.Black);
        }
Ejemplo n.º 2
0
        public void Connect(Control control)
        {
            // Save old log info in case this is a reconnect
            Poderosa.ConnectionParam.LogType logType = Poderosa.ConnectionParam.LogType.Default;
            string file = null;
            if (this.TerminalPane.Connection != null)
            {
                logType = this.TerminalPane.Connection.LogType;
                file = this.TerminalPane.Connection.LogPath;
                //GApp.GetConnectionCommandTarget().Close();
                this.TerminalPane.Connection.Close();
                this.TerminalPane.Detach();
            }

            try
            {
                //------------------------------------------------------------------------
                SSHTerminalParam sshp = new SSHTerminalParam((Poderosa.ConnectionParam.ConnectionMethod)this.Method, this.Host, this.UserName, this.Password);
                sshp.AuthType = this.AuthType;
                sshp.IdentityFile = this.IdentifyFile;
                sshp.Encoding = EncodingType.ISO8859_1;
                sshp.Port = 22;
                sshp.RenderProfile = new RenderProfile();
                sshp.TerminalType = TerminalType.XTerm;

                CommunicationUtil.SilentClient s = new CommunicationUtil.SilentClient();
                Size sz = this.Size;

                SocketWithTimeout swt;
                swt = new SSHConnector((Poderosa.ConnectionParam.SSHTerminalParam)sshp, sz, sshp.Passphrase, (HostKeyCheckCallback)null);
                swt.AsyncConnect(s, sshp.Host, sshp.Port);
                //var thread = new Thread(() =>
                //    {
                        while (swt.Succeeded == false)
                        {
                            Application.DoEvents();
                        }
                        ct = s.Wait(swt);

                        control.Invoke((MethodInvoker)(
                            () =>
                            {
                                this.TerminalPane.FakeVisible = true;

                                this.TerminalPane.Attach(ct);
                                ct.Receiver.Listen();
                                //-------------------------------------------------------------
                                if (file != null)
                                    this.SetLog((LogType)logType, file, true);
                                this.TerminalPane.ConnectionTag.RenderProfile = new RenderProfile();
                                this.SetPaneColors(Color.LightBlue, Color.Black);
                            }
                            ));
                 //   });
                //start thread
                //thread.Start();
            }
            catch
            {
                //MessageBox.Show(e.Message, "Connection Error");
                return;
            }
        }
        public void Connect()
        {
            #region old stuff
            /*
            Poderosa.ConnectionParam.LogType logType = Poderosa.ConnectionParam.LogType.Default;
            string file = null;
            if (this.TerminalPane.Connection != null)
            {
                logType = this.TerminalPane.Connection.LogType;
                file = this.TerminalPane.Connection.LogPath;
                //GApp.GetConnectionCommandTarget().Close();
                this.TerminalPane.Connection.Close();
                this.TerminalPane.Detach();
            }

            SSHTerminalParam p = new SSHTerminalParam((Poderosa.ConnectionParam.ConnectionMethod)this.Method, this.Host, this.UserName, this.Password);

            GApp.GlobalCommandTarget.SilentNewConnection(p);

            if (file != null)
                this.SetLog((LogType) logType, file, true);
            */
            #endregion

            // Save old log info in case this is a reconnect
            Poderosa.ConnectionParam.LogType logType = Poderosa.ConnectionParam.LogType.Default;
            string file = null;
            if (this.TerminalPane.Connection != null)
            {
                logType = this.TerminalPane.Connection.LogType;
                file = this.TerminalPane.Connection.LogPath;
                //GApp.GetConnectionCommandTarget().Close();
                this.TerminalPane.Connection.Close();
                this.TerminalPane.Detach();
            }

            try
            {
                //------------------------------------------------------------------------
                //edited by xavier (stond niet in een thread)
                System.Threading.ThreadPool.QueueUserWorkItem(
               o =>
               {
                   SSHTerminalParam sshp = new SSHTerminalParam((Poderosa.ConnectionParam.ConnectionMethod)this.Method, this.Host, this.UserName, this.Password);
                   sshp.AuthType = this.AuthType;
                   sshp.IdentityFile = this.IdentifyFile;
                   sshp.Encoding = EncodingType.ISO8859_1;
                   sshp.Port = 22;
                   sshp.RenderProfile = new RenderProfile();
                   sshp.TerminalType = TerminalType.XTerm;
                   sshp.ControlName = this.Name;//edited by xavier

                   CommunicationUtil.SilentClient s = new CommunicationUtil.SilentClient();
                   Size sz = this.Size;

                   SocketWithTimeout swt;
                   swt = new SSHConnector((Poderosa.ConnectionParam.SSHTerminalParam)sshp, sz, sshp.Passphrase, (HostKeyCheckCallback)null);
                   swt.AsyncConnect(s, sshp.Host, sshp.Port);
                   ConnectionTag ct = s.Wait(swt);

                   GalaSoft.MvvmLight.Threading.DispatcherHelper.CheckBeginInvokeOnUI(() =>
                   {
                       this.TerminalPane.FakeVisible = true;

                       this.TerminalPane.Attach(ct);
                       ct.Receiver.Listen();
                       //-------------------------------------------------------------
                       if (file != null)
                           this.SetLog((LogType)logType, file, true);
                       this.TerminalPane.ConnectionTag.RenderProfile = new RenderProfile();
                       this.SetPaneColors(Color.White, Color.Black);
                   });
               });
            }
            catch
            {
                //MessageBox.Show(e.Message, "Connection Error");
                return;
            }
        }