Exemplo n.º 1
0
        void currentSession_BlockReceived(object sender, BlockReceivedEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(blockReceivedHandler, new object[] { sender, e });
            }
            else
            {
                string receivedBlock = currentSession.ReadBlock();

                /*
                 * if (_connectionSettings.TerminalType==TerminalType.CharacterBuffer)
                 * {
                 *  if (receivedBlock.IndexOf("\x1b\x5bJ") != -1)
                 *  {
                 *      ClearText();
                 *      receivedBlock = receivedBlock.Substring(receivedBlock.IndexOf("\x1b\x5bJ") + 1);
                 *  }
                 *
                 *  AppendText(receivedBlock);
                 *  MoveCursorToEnd();
                 * }
                 * else*/
                {
                    terminalBuffer.Write(receivedBlock);
                    ShowTerminalBuffer();
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Notifies the client that a block is available to be read
 /// </summary>
 /// <param name="args"></param>
 protected void OnBlockReceived(BlockReceivedEventArgs args)
 {
     if (BlockReceived != null)
     {
         BlockReceived(this, args);
     }
 }
Exemplo n.º 3
0
        void currentSession_BlockReceived(object sender, BlockReceivedEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(blockReceivedHandler, new object[] { sender, e });
            }
            else
            {
                string receivedBlock = currentSession.ReadBlock();
                /*
                if (_connectionSettings.TerminalType==TerminalType.CharacterBuffer)
                {
                    if (receivedBlock.IndexOf("\x1b\x5bJ") != -1)
                    {
                        ClearText();
                        receivedBlock = receivedBlock.Substring(receivedBlock.IndexOf("\x1b\x5bJ") + 1);
                    }

                    AppendText(receivedBlock);
                    MoveCursorToEnd();
                }
                else*/
                {
                    terminalBuffer.Write(receivedBlock);
                    ShowTerminalBuffer();
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Main thread for the worker process that reads from the telnet thread's socket
        /// </summary>
        public void ReaderLoop()
        {
            ASCIIEncoding ae = new ASCIIEncoding();
            StringBuilder sb = new StringBuilder();

            Interlocked.Increment(ref _readLines);

            SessionStatusChangeEventArgs args = new SessionStatusChangeEventArgs();

            OnSessionStatusChanged(args);
            args.ChangedSessionStatus = SessionStatusChangeEventArgs.SessionStatus.Established;

            while (true)
            {
                try
                {
                    if (_networkStream.DataAvailable)
                    {
                        int readSize  = (_socket.Available > readBufferSize) ? readBufferSize : _socket.Available;
                        int readCount = _readerStream.ReadBlock(_receivedBuffer, 0, readSize);
                        if (readCount > 0)
                        {
                            Interlocked.Increment(ref _readLines);
                            sb.Append(_receivedBuffer, 0, readCount);
                            string newValue = sb.ToString();
                            Debug.WriteLine(String.Format("Received Line:{0}", newValue));
                            _messageQueue.Enqueue(newValue);
                            BlockReceivedEventArgs brea = new BlockReceivedEventArgs();
                            brea.BlockLength = sb.Length;
                            sb.Length        = 0;
                            OnBlockReceived(brea);
                        }
                    }
                    else
                    {
                        Thread.Sleep(10);
                    }
                }
                catch (Exception exc)
                {
                    Debug.WriteLine(exc.Message);
                }
            }
        }