Beispiel #1
0
        public void Run()
        {
            var rs = new RegexSurfer();

            var re = new ManualResetEventSlim(false);
            var t  = new Task(() =>
            {
                while (!re.IsSet)
                {
                    _terminal.WriteLine();
                    Thread.Sleep(100);
                }
            });

            rs.SeekForMatches(_terminal,
                              new DelegateExpectation(@"U-Boot", true, Match => t.Start()));

            rs.SeekForMatches(_terminal,
                              new DelegateExpectation(@"SMDKC100 #", true, Match =>
            {
                re.Set();
                _terminal.WriteLine("nand erase 60000");
            }));

            var bads = new List <int>();

            rs.SeekForMatches(_terminal,
                              new DelegateExpectation("OK", Match => true));
            t.Wait();
        }
 public void ProcessOutput(RegexSurfer Surfer, Terminal Terminal, CancellationToken CancellationToken, SubprocessProgressToken Progress,
                           ProgressControllerFactory ProgressControllerFactory)
 {
     using (IProgressController pc = ProgressControllerFactory.CreateController(Progress))
     {
         pc.SetDescription("Проверка прошивки...");
         pc.SetProgress(0);
         Surfer.SeekForMatches(Terminal, CancellationToken,
                               new DelegateExpectation(
                                   new Regex(@"Complete (?<progress>\d+)%.*0x(?<written>[0-9a-fA-F]+) bytes written by applet",
                                             RegexOptions.Compiled | RegexOptions.Singleline), false,
                                   m => pc.SetProgress(0.01 * int.Parse(m.Groups["progress"].Value))),
                               new DelegateExpectation(
                                   @"Sent file & Memory area content \(address: 0x[0-9a-fA-F]+, size: \d+ bytes\) (?<result>.+) !",
                                   m =>
                                   {
                                       switch (m.Groups["result"].Value)
                                       {
                                           case "match exactly":
                                               return true;
                                           case "do not match":
                                               throw new ComparingFailsSambaException();
                                           default:
                                               throw new ApplicationException("Непонятный вывод:\n\n" + Terminal.Log);
                                       }
                                   }));
     }
 }
        public void FindAnything()
        {
            var seeker      = new RegexSurfer();
            var terminal    = new Terminal(new ConstantTerminalCore(SampleOutput));
            var expectation = new TestExpectation(@"Hit any key to stop autoboot:\s+\d+\s*$");

            seeker.SeekForMatches(terminal, expectation);
            Assert.That(expectation.Match.Value, Is.EqualTo("Hit any key to stop autoboot:  0"));
        }
 public void ProcessOutput(RegexSurfer Surfer, Terminal Terminal, CancellationToken CancellationToken, SubprocessProgressToken Progress,
                           ProgressControllerFactory ProgressControllerFactory)
 {
     using (IProgressController pc = ProgressControllerFactory.CreateController(Progress))
     {
         pc.SetDescription("Стирание FLASH...");
         pc.SetProgress(0);
         Surfer.SeekForMatches(Terminal, CancellationToken, new BarrierExpectation(@"GENERIC::EraseAll"));
     }
 }
 public OperatingContext(ITerminal Terminal, RegexSurfer Surfer, UsbConnectionFactory Usb, IProgressControllerFactory ProgressControllerFactory,
                         int BlockSize)
 {
     this.BlockSize = BlockSize;
     this.ProgressControllerFactory = ProgressControllerFactory;
     this.Usb = Usb;
     this.Terminal = Terminal;
     this.Surfer = Surfer;
     State = ProgrammingContextState.Unknown;
     NandSize = ulong.MaxValue;
 }
        public void FindOneAndThenAnother()
        {
            var seeker   = new RegexSurfer();
            var terminal = new Terminal(new ConstantTerminalCore(SampleOutput));

            var expectation1 = new TestExpectation(@"DRAM:\s+\d+ MB");

            seeker.SeekForMatches(terminal, expectation1);
            Assert.That(expectation1.Match.Value, Is.EqualTo("DRAM:    256 MB"));

            var expectation2 = new TestExpectation(@"Flash:\s+\d+ kB");

            seeker.SeekForMatches(terminal, expectation2);
            Assert.That(expectation2.Match.Value, Is.EqualTo("Flash:   0 kB"));
        }
 public void ProcessOutput(RegexSurfer Surfer, Terminal Terminal, CancellationToken CancellationToken, SubprocessProgressToken Progress,
                           ProgressControllerFactory ProgressControllerFactory)
 {
     using (IProgressController pc = ProgressControllerFactory.CreateController(Progress))
     {
         pc.SetDescription("Передача прошивки {0:P0}", Progress);
         int written = 0;
         Surfer.SeekForMatches(Terminal, CancellationToken,
                               new DelegateExpectation(
                                   new Regex(@"Complete (?<progress>\d+)%.*0x(?<written>[0-9a-fA-F]+) bytes written by applet",
                                             RegexOptions.Compiled | RegexOptions.Singleline),
                                   m =>
                                   {
                                       pc.SetProgress(0.01 * int.Parse(m.Groups["progress"].Value));
                                       written += int.Parse(m.Groups["written"].Value, NumberStyles.HexNumber);
                                       return written >= _fileSize;
                                   }));
     }
 }
        public void Execute(CancellationToken CancellationToken, IProgressToken ProgressToken, string BoardName, params ISambaAction[] Actions)
        {
            var initializationProgressToken = new SubprocessProgressToken(0);
            Dictionary<ISambaAction, SubprocessProgressToken> actionsProgressTokens = Actions.ToDictionary(a => a, a => new SubprocessProgressToken(a.Weight));

            using (new CompositeProgressManager(ProgressToken, new[] { initializationProgressToken }.Concat(actionsProgressTokens.Values).ToList()))
            {
                using (TemporaryFile scriptFile = CreateScriptFile(Actions))
                {
                    Process p = _toolLauncher.Execute(_toolBody,
                                                      new ProgrammerParameter(ProgrammerPath),
                                                      new BoardNameParameter(BoardName),
                                                      new ScriptPathParameter(scriptFile.FileInfo));

                    using (CancellationToken.Register(p.Kill))
                    {
                        var rs = new RegexSurfer();
                        using (var terminal = new Terminal(new ProcessTerminalCore(p)))
                        {
                            using (IProgressController pc = _progressControllerFactory.CreateController(initializationProgressToken))
                            {
                                pc.SetDescription("Инициализация программатора...");
                                rs.SeekForMatches(terminal, CancellationToken,
                                                  new BarrierExpectation(@"Command line mode : Execute script file"),
                                                  new AbortExpectation(@"-E- Invalid device or board!", m => new DeviceIsNotConnectedSambaException()),
                                                  new AbortExpectation(@"-E- Connection (?<programmer>.*) not found",
                                                                       m => new ProgrammerIsNotConnectedSambaException(m.Groups["programmer"].Value)));
                            }

                            foreach (ISambaAction action in Actions)
                                action.ProcessOutput(rs, terminal, CancellationToken, actionsProgressTokens[action], _progressControllerFactory);
                        }
                    }
                }
            }
        }