Ejemplo n.º 1
0
 public void SetUp()
 {
     monitor       = new Monitor();
     commandEater  = new CommandInteractionEater();
     loggerBackend = new DummyLoggerBackend();
     Logger.AddBackend(loggerBackend, "dummy");
 }
Ejemplo n.º 2
0
 public Emul8Keywords()
 {
     interaction         = new CommandInteractionEater();
     monitor             = new Monitor();
     testers             = new Dictionary <string, TerminalTester>();
     monitor.Interaction = interaction;
 }
        public void Run(ICommandInteraction writer, StringToken command, DecimalIntegerToken delay)
        {
            var terminal = writer as CommandInteraction;

            if (terminal == null)
            {
                writer.WriteError("Watch command can be used on a full-featured terminal only");
                return;
            }

            var eater = new CommandInteractionEater();

            while (!terminal.HasNewInput)
            {
                terminal.SaveCursor();
                monitor.Parse(command.Value, eater);

                writer.Write(eater.GetContents());
                var error = eater.GetError();
                if (error.Length > 0)
                {
                    writer.WriteError(error);
                    break;
                }
                eater.Clear();

                System.Threading.Thread.Sleep((int)delay.Value);
                terminal.RestoreCursor();
                terminal.ClearToEnd();
            }
        }
Ejemplo n.º 4
0
        public void AutoLoadCommandTest()
        {
            var commandInteraction = new CommandInteractionEater();
            var commandInstance    = new TestCommand(monitor);

            monitor.Parse("help", commandInteraction);
            var contents = commandInteraction.GetContents();

            Assert.IsTrue(contents.Contains(commandInstance.Description));
        }
        public void ShouldHandleNewExtensionsFromLoadedAssembly()
        {
            var commandInteraction = new CommandInteractionEater();
            var file = GetType().Assembly.FromResourceToTemporaryFile("MockExtension.cs");

            monitor.Parse("emulation GetSeed", commandInteraction);
            monitor.Parse($"i @{file}", commandInteraction);
            monitor.Parse("emulation GetMockString", commandInteraction);
            var contentsAfter = commandInteraction.GetContents();

            Assert.IsTrue(contentsAfter.Contains("this is an extension"));
        }
Ejemplo n.º 6
0
        public PacketData Run([Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexString)] string arg)
        {
            if (!openOcdOverlay.TryProcess(arg, out var result))
            {
                var monitor = ObjectCreator.Instance.GetSurrogate <Monitor>();
                var eater   = new CommandInteractionEater();
                monitor.Parse(arg, eater);
                result = eater.HasError
                    ? eater.GetError()
                    : eater.GetContents();
            }

            return((string.IsNullOrEmpty(result)) ? PacketData.Success : new PacketData(string.Join(string.Empty, Encoding.UTF8.GetBytes(result).Select(x => x.ToString("X2")))));
        }
Ejemplo n.º 7
0
        public PacketData Run([Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexString)] string arg)
        {
            string result;
            var    monitor = ObjectCreator.Instance.GetSurrogate <Monitor>();
            var    eater   = new CommandInteractionEater();

            if (!monitor.Parse(arg, eater))
            {
                result = eater.GetError();
            }
            else
            {
                result = eater.GetContents();
                if (string.IsNullOrEmpty(result))
                {
                    return(PacketData.Success);
                }
            }
            return(new PacketData(string.Join(string.Empty, Encoding.UTF8.GetBytes(result).Select(x => x.ToString("X2")))));
        }