Ejemplo n.º 1
0
 public void run(object sender, ElapsedEventArgs e)
 {
     Thread.CurrentThread.IsBackground = false;
     lock (mylock)
     {
         while (isRunning)
         {
             Thread.Sleep(5);
             Dictionary <String, TerminalSession> users = TerminalRealTimeInspector.CreateInstance().currentUser;
             if (users != null && users.Count() > 0)
             {
                 lock (users)
                 {
                     long currTime = Convert.ToInt64(DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds);
                     foreach (string x in users.Keys)
                     {
                         //定时器任务,每100ms遍历执行一次
                         TerminalSession session = users[x];
                         long            current = Convert.ToInt64(DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds);
                         //超时
                         if ((current - session.getLastTime()) >= sessionTimeOutMills)
                         {
                             TerminalRealTimeInspector.CreateInstance().closeSession(x);
                         }
                         //间隔100ms
                         Thread.Sleep(100);
                     }
                 }
             }
             Thread.Sleep(1000);
         }
     }
 }
Ejemplo n.º 2
0
        public void SuccessfullyExit(ITerminalConnection connection)
        {
            ITerminalSettings terminalSettings = PoderosaTerminalEmulatorService.CreateDefaultTerminalSettings(Connection.DisplayName, null);

            TerminalSession session       = new TerminalSession(connection, terminalSettings);
            SessionHost     sessionHost   = new SessionHost(PoderosaSessionManagerPlugin, session);
            TerminalView    terminalView  = new TerminalView(null, _terminal);
            RenderProfile   renderProfile = new RenderProfile(_terminal.GetRenderProfile());

            renderProfile.BackColor = Connection.BackgroundColor;
            renderProfile.ForeColor = Connection.TextColor;

            session.TerminalSettings.BeginUpdate();
            session.TerminalSettings.RenderProfile = renderProfile;
            session.TerminalSettings.EndUpdate();

            _sshConnection = (SSHTerminalConnection)connection;

            Invoke(
                new Action(
                    () =>
            {
                _terminal.Attach(session);

                session.InternalStart(sessionHost);
                session.InternalAttachView(sessionHost.DocumentAt(0), terminalView);

                _sshConnection.ConnectionEventReceiver.NormalTermination   += ConnectionEventReceiver_NormalTermination;
                _sshConnection.ConnectionEventReceiver.AbnormalTermination += ConnectionEventReceiver_AbnormalTermination;

                ParentForm.Closing += ParentForm_OnClosing;

                OnConnected(_terminal, null);
            }));
        }
        /**
         *
         * @param terminalID
         * @param longitudel
         * @param latitude
         * @return
         */
        public TerminalSession getSession(RunRealTime status)
        {
            lock (loc)
            {
                if (!isInit)
                {
                    Init();
                }
            }
            TerminalSession session = currentUser[status.TerminalId];

            if (session != null && session.isUsing())
            {
                session.setStatus(status);
                session.setLastTime(Convert.ToInt64(DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds));
                //session.setUsedCount(session.getUsedCount() + 1);
                return(session);
            }
            else
            {
                session = new TerminalSession(status);
                currentUser[status.TerminalId] = session;
                return(session);
            }
        }
 protected override void ProcessSession(TerminalSession session)
 {
     if (_force.IsPresent || ShouldContinue("Logoff the session " + session.Id + "?", CmdletName))
     {
         session.Logoff(ShouldWait);
     }
 }
Ejemplo n.º 5
0
        protected override void ProcessSession(TerminalSession session)
        {
            if (Resolve && (session.Client != null))
            {
                session.Client.GetHostEntry();
            }

            WriteObject(session);
        }
Ejemplo n.º 6
0
        public void Connect()
        {
            try
            {
                switch (_protocol)
                {
                case ProtocolType.Cywin:
                    _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window);
                    _asyncConnection       = _basePoderosaInstance.ProtocolService.AsyncCygwinConnect(_synchronizedConnector.InterruptableConnectorClient, (ICygwinParameter)_terminalParameter);
                    _terminalConnection    = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout);
                    break;

                case ProtocolType.Raw:
                    break;

                case ProtocolType.RLogin:
                    break;

                case ProtocolType.Serial:
                    _terminalConnection = (ITerminalConnection)SerialPortUtil.CreateNewSerialConnection(_window, (SerialTerminalParam)_terminalParameter, (SerialTerminalSettings)_terminalSettings);
                    break;

                case ProtocolType.SSH1:
                case ProtocolType.SSH2:
                    _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window);
                    _asyncConnection       = _basePoderosaInstance.ProtocolService.AsyncSSHConnect(_synchronizedConnector.InterruptableConnectorClient, (ISSHLoginParameter)_terminalParameter);
                    _terminalConnection    = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout);
                    break;

                case ProtocolType.Telnet:
                    _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window);
                    _asyncConnection       = _basePoderosaInstance.ProtocolService.AsyncTelnetConnect(_synchronizedConnector.InterruptableConnectorClient, (ITCPParameter)_terminalParameter);
                    _terminalConnection    = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout);
                    break;

                default:
                    _terminalConnection = null;
                    break;
                }
                _terminalSession = new TerminalSession(_terminalConnection, _terminalSettings);
                _basePoderosaInstance.SessionManagerPlugin.StartNewSession(_terminalSession, _terminalView);
                _basePoderosaInstance.SessionManagerPlugin.ActivateDocument(_terminalSession.Terminal.IDocument, ActivateReason.InternalAction);
            }
            catch (Exception ex)
            {
                RuntimeUtil.ReportException(ex);
                //return CommandResult.Failed;
            }
        }
Ejemplo n.º 7
0
 private void AwaitConnectResult()
 {
     mreConnect.WaitOne();
     if (_terminalConnection != null)
     {
         _terminalControl = new TerminalControl();
         _terminalSession = new TerminalSession(_terminalConnection, _terminalSettings);
         _terminalControl.Attach(_terminalSession);
         _connectCallback?.Invoke(this);
     }
     else
     {
         MessageBox.Show("Connection error : " + errorMsg, "Unable to connect", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 8
0
        private void ChangeSession(TerminalSession session)
        {
            if (session != _currentSession)
            {
                if (_currentSession != null)
                {
                    _currentSession.Active = false;
                }

                _currentSession = session;

                if (session != null)
                {
                    session.Active      = true;
                    session.Buffer.Size = _terminalSize;
                }

                terminalControl.Session = session;
                terminalControl.Focus();
            }
        }
Ejemplo n.º 9
0
        private void ChangeSession(TerminalSession session, TabDataItem tab)
        {
            if (session != _currentSession)
            {
                if (_currentSession != null)
                {
                    _currentSession.Active = false;
                    _currentTab.IsActive   = false;
                }

                _currentSession = session;
                _currentTab     = tab;

                if (session != null)
                {
                    session.Active = true;
                    session.Size   = _terminalSize;
                    tab.IsActive   = true;
                }

                terminalControl.Session = session;
                terminalControl.Focus();
            }
        }
Ejemplo n.º 10
0
 private void CloseSession(TerminalSession session)
 {
     session.Dispose();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Wires up a PowerShell runspace created via <see cref="RunspaceFactory.CreateRunspace()"/> to the terminal to display the PowerShell to the user.
        /// </summary>
        public override void Connect()
        {
            _progressBar.Value  = 0;
            _progressLabel.Text = "";

            // This is not strictly a network connection:  we're relaying information that we receive from the runspace to the terminal over a local stream
            // (a StreamConnection in this case)
            ITerminalParameter terminalParam = new EmptyTerminalParameter();
            StreamConnection   connection    = new StreamConnection(terminalParam)
            {
                Capture = false
            };

            // Attach the new "connection" to the terminal control
            try
            {
                ITerminalSettings terminalSettings = PoderosaTerminalEmulatorService.CreateDefaultTerminalSettings(Connection.DisplayName, null);
                TerminalSession   session          = new TerminalSession(connection, terminalSettings);
                SessionHost       sessionHost      = new SessionHost(PoderosaSessionManagerPlugin, session);
                TerminalView      terminalView     = new TerminalView(null, _terminal);
                RenderProfile     renderProfile    = new RenderProfile(_terminal.GetRenderProfile());

                renderProfile.BackColor = Connection.BackgroundColor;
                renderProfile.ForeColor = Connection.TextColor;
                renderProfile.FontName  = Connection.FontFamily;
                renderProfile.FontSize  = Connection.FontSize;

                session.TerminalSettings.BeginUpdate();
                session.TerminalSettings.RenderProfile = renderProfile;
                session.TerminalSettings.EndUpdate();

                _terminal.Attach(session);

                session.InternalStart(sessionHost);
                session.InternalAttachView(sessionHost.DocumentAt(0), terminalView);

                _powerShellHost = new PowerShellHost(this, _terminal, connection, ExecuteQuiet, _progressBar, _progressLabel);

                // Create the host and runspace instances for this interpreter.  If we're connecting to the local host, don't bother with the connection info.
                // ReSharper disable StringCompareIsCultureSpecific.3
                if (String.Compare(Connection.Host, "localhost", true) != 0 && Connection.Host != "127.0.0.1" &&
                    String.Compare(Connection.Host, Environment.MachineName, true) != 0)
                // ReSharper restore StringCompareIsCultureSpecific.3
                {
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo
                    {
                        ComputerName = Connection.Host
                    };

                    if (!String.IsNullOrEmpty(Connection.InheritedUsername))
                    {
                        connectionInfo.Credential = new PSCredential(Connection.InheritedUsername, Connection.InheritedPassword);
                    }

                    Runspace = RunspaceFactory.CreateRunspace(_powerShellHost, connectionInfo);
                }

                else
                {
                    Runspace = RunspaceFactory.CreateRunspace(_powerShellHost);
                }

                Runspace.Open();
            }

            catch (Exception e)
            {
                OnConnectionLost(this, new ErrorEventArgs(e));
                return;
            }

            // Start capturing input from the prompt via the input loop
            _inputThread = new Thread(InputLoop)
            {
                Name = "PowerShellConnectionForm Input Thread"
            };
            _inputThread.Start();

            ParentForm.Closing += ParentForm_Closing;

            OnConnected(this, null);
        }
Ejemplo n.º 12
0
 protected virtual void ProcessSession(TerminalSession session)
 {
 }
Ejemplo n.º 13
0
 protected override void ProcessSession(TerminalSession session)
 {
     session.Disconnect(ShouldWait);
 }