private void OnMessageReceived(object sender, IDictionary <string, object> e)
        {
            var messageType    = (byte)e[MessageKeys.Type];
            var messageContent = e[MessageKeys.Content];

            switch (messageType)
            {
            case Constants.TerminalBufferRequestIdentifier:
                var terminalId = (byte)e[MessageKeys.TerminalId];

                if (_terminalOutputHandlers.ContainsKey(terminalId))
                {
                    _terminalOutputHandlers[terminalId].Invoke((byte[])messageContent);
                }
                else
                {
                    Logger.Instance.Error("Received output for unknown terminal Id {id}", terminalId);
                }
                break;

            case TerminalExitedRequest.Identifier:
                var request = JsonConvert.DeserializeObject <TerminalExitedRequest>((string)messageContent);
                Logger.Instance.Debug("Received TerminalExitedRequest: {@request}", request);

                TerminalExited?.Invoke(this, request.ToStatus());
                break;

            default:
                Logger.Instance.Error("Received unknown message type: {messageType}", messageType);
                break;
            }
        }
예제 #2
0
        private void OnMessageReceived(object sender, IDictionary <string, string> e)
        {
            var messageType    = e[MessageKeys.Type];
            var messageContent = e[MessageKeys.Content];

            if (messageType == nameof(DisplayTerminalOutputRequest))
            {
                var request = JsonConvert.DeserializeObject <DisplayTerminalOutputRequest>(messageContent);

                if (_terminalOutputHandlers.ContainsKey(request.TerminalId))
                {
                    _terminalOutputHandlers[request.TerminalId].Invoke(request.Output);
                }
                else
                {
                    Logger.Instance.Error("Received output for unknown terminal Id {id}", request.TerminalId);
                }
            }
            else if (messageType == nameof(TerminalExitedRequest))
            {
                var request = JsonConvert.DeserializeObject <TerminalExitedRequest>(messageContent);
                Logger.Instance.Debug("Received TerminalExitedRequest: {@request}", request);

                TerminalExited?.Invoke(this, request.ToStatus());
            }
        }
예제 #3
0
        private void OnMessageReceived(object sender, IDictionary <string, string> e)
        {
            var messageType    = e[MessageKeys.Type];
            var messageContent = e[MessageKeys.Content];

            if (messageType == nameof(DisplayTerminalOutputRequest))
            {
                var request = JsonConvert.DeserializeObject <DisplayTerminalOutputRequest>(messageContent);

                if (_terminalOutputHandlers.ContainsKey(request.TerminalId))
                {
                    _terminalOutputHandlers[request.TerminalId].Invoke(request.Output);
                }
                else
                {
                    Debug.WriteLine("output was not handled: " + request.Output);
                }
            }
            else if (messageType == nameof(TerminalExitedRequest))
            {
                var request = JsonConvert.DeserializeObject <TerminalExitedRequest>(messageContent);

                TerminalExited?.Invoke(this, request.TerminalId);
            }
        }
예제 #4
0
 private void OnTerminalConnectionClosed(object sender, int exitcode)
 {
     if (sender is ITerminalSession terminal)
     {
         _terminals.Remove(terminal.Id);
         terminal.Dispose();
         TerminalExited?.Invoke(this, new TerminalExitStatus(terminal.Id, exitcode));
     }
 }
예제 #5
0
 private void OnTerminalConnectionClosed(object sender, System.EventArgs e)
 {
     if (sender is ITerminalSession terminal)
     {
         _terminals.Remove(terminal.Id);
         terminal.Dispose();
         TerminalExited?.Invoke(this, terminal.Id);
     }
 }