public DataConsumer(IVirtualTerminalController controller)
 {
     Controller = controller;
 }
Exemple #2
0
        public static void ProcessSequence(TerminalSequence sequence, IVirtualTerminalController controller)
        {
            if (sequence is CharacterSequence)
            {
                var handler = Handlers.Where(x => x.SequenceType == SequenceHandler.ESequenceType.Character).SingleOrDefault();
                if (handler == null)
                {
                    throw new Exception("There are no sequence handlers configured for type CharacterSequence");
                }

                handler.Handler(sequence, controller);

                return;
            }

            if (sequence is CsiSequence)
            {
                var handler = Handlers
                              .Where(x =>
                                     x.SequenceType == SequenceHandler.ESequenceType.CSI &&
                                     x.CsiCommand == sequence.Command &&
                                     x.Query == sequence.IsQuery &&
                                     x.Send == sequence.IsSend &&
                                     x.Bang == sequence.IsBang &&
                                     (
                                         x.Param0.Length == 0 ||
                                         x.Param0.Contains(
                                             (sequence.Parameters == null || sequence.Parameters.Count < 1) ?
                                             0 :
                                             sequence.Parameters[0]
                                             )
                                     ) &&
                                     (
                                         x.ExactParameterCount == -1 ||
                                         (sequence.Parameters != null || x.ExactParameterCount == sequence.Parameters.Count)
                                     ) &&
                                     (
                                         x.ExactParameterCountOrDefault == -1 ||
                                         (
                                             sequence.Parameters == null ||
                                             sequence.Parameters.Count == 0 ||
                                             x.ExactParameterCountOrDefault == sequence.Parameters.Count
                                         )
                                     )
                                     )
                              .SingleOrDefault();

                if (handler == null)
                {
                    throw new Exception("There are no CsiSequence handlers configured for sequence: " + sequence.ToString());
                }

                handler.Handler(sequence, controller);

                return;
            }

            if (sequence is OscSequence)
            {
                if (sequence.Parameters.Count < 1)
                {
                    throw new Exception("OSC sequence doesn't have any parameters");
                }

                var handler = Handlers.Where(x => x.SequenceType == SequenceHandler.ESequenceType.OSC && x.Param0.Contains(sequence.Parameters[0])).SingleOrDefault();
                if (handler == null)
                {
                    throw new Exception("There are no sequence handlers configured for type OscSequence with param0 = " + sequence.Parameters[0].ToString());
                }

                handler.Handler(sequence, controller);

                return;
            }

            if (sequence is CharacterSetSequence)
            {
                var handler = Handlers.Where(x => x.SequenceType == SequenceHandler.ESequenceType.CharacterSet).SingleOrDefault();
                if (handler == null)
                {
                    throw new EscapeSequenceException("There are no sequence handlers configured for type CharacterSetSequence " + sequence.ToString(), sequence);
                }

                handler.Handler(sequence, controller);

                return;
            }

            if (sequence is EscapeSequence)
            {
                var handler = Handlers
                              .Where(x =>
                                     x.SequenceType == SequenceHandler.ESequenceType.Escape &&
                                     x.CsiCommand == sequence.Command
                                     )
                              .SingleOrDefault();

                if (handler == null)
                {
                    throw new EscapeSequenceException("There are no sequence handlers configured for type EscapeSequence " + sequence.ToString(), sequence);
                }

                handler.Handler(sequence, controller);

                return;
            }

            if (sequence is CharacterSizeSequence)
            {
                var handler = Handlers.Where(x => x.SequenceType == SequenceHandler.ESequenceType.CharacterSize).SingleOrDefault();
                if (handler == null)
                {
                    throw new EscapeSequenceException("There are no sequence handlers configured for type CharacterSizeSequence " + sequence.ToString(), sequence);
                }

                handler.Handler(sequence, controller);

                return;
            }

            if (sequence is UnicodeSequence)
            {
                var handler = Handlers
                              .Where(x =>
                                     x.SequenceType == SequenceHandler.ESequenceType.Unicode &&
                                     x.CsiCommand == sequence.Command
                                     )
                              .SingleOrDefault();

                if (handler == null)
                {
                    throw new EscapeSequenceException("There are no sequence handlers configured for type UnicodeSequence " + sequence.ToString(), sequence);
                }

                handler.Handler(sequence, controller);

                return;
            }

            System.Diagnostics.Debug.WriteLine("Unhandled sequence -> " + sequence.ToString());
        }