/// <summary> /// Notifies the client when a session is established or terminated /// </summary> /// <param name="args"></param> protected void OnSessionStatusChanged(SessionStatusChangeEventArgs args) { if (SessionStatusChanged != null) { SessionStatusChanged(this, args); } }
/// <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); } } }
void currentSession_SessionStatusChanged(object sender, SessionStatusChangeEventArgs e) { if (this.InvokeRequired) { this.Invoke(this.sessionStatusHandler, new object[] { sender, e }); } else { if (_connectionSettings.TerminalType == TerminalType.CharacterBuffer) { AppendText("\r\n\r\nNew Session Established\r\n\r\n"); MoveCursorToEnd(); } else { this.terminalBuffer.Write("New Session Established\r\n\r\n"); ShowTerminalBuffer(); } } }
void currentSession_SessionStatusChanged(object sender, SessionStatusChangeEventArgs e) { if (this.InvokeRequired) { this.Invoke(this.sessionStatusHandler, new object[] { sender, e }); } else { if (_connectionSettings.TerminalType==TerminalType.CharacterBuffer) { AppendText("\r\n\r\nNew Session Established\r\n\r\n"); MoveCursorToEnd(); } else { this.terminalBuffer.Write("New Session Established\r\n\r\n"); ShowTerminalBuffer(); } } }