Пример #1
0
        /// <summary>
        /// 带有超时重试功能的fastboot指令执行器
        /// </summary>
        /// <param name="executor"></param>
        /// <param name="args"></param>
        /// <param name="retryTimes"></param>
        /// <param name="maxTimeout"></param>
        /// <exception cref="TimeoutException">超过重试次数</exception>
        /// <exception cref="ArgumentException">参数不合理</exception>
        /// <returns></returns>
        public static CommandResult FastbootWithRetry(this ICommandExecutor executor, string args,
                                                      IDevice?device = null, int retryTimes = 10, int maxTimeout = 300)
        {
            if (retryTimes * maxTimeout <= 0)
            {
                throw new ArgumentException("retryTimes and maxTimeout should not be smaller than 0");
            }
            const int INTERVAL_BETWEEN_PER_RETRY = 20;

            /*
             * 由于某些原因,部分设备上的fastboot指令会有玄学问题
             *因此此处实现了一个重试机制,尽可能获取到正确的值
             */
            CommandResult?result = null;

            for (int crtTime = 1; crtTime <= retryTimes; crtTime++)
            {
                CommandResult routine()
                {
                    return(device == null?executor.Fastboot(args) : executor.Fastboot(device, args));
                }

                Task.Run(() =>
                {
                    result = routine();
                });

                Thread.Sleep((int)maxTimeout);

                if (result != null && !result.Output.Contains("GetVar Variable Not found"))
                {
                    break;
                }
                else
                {
                    executor.CancelCurrent();
                    Thread.Sleep(INTERVAL_BETWEEN_PER_RETRY);
                }
            }
            if (result == null)
            {
                throw new TimeoutException();
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 开始执行
        /// </summary>
        /// <exception cref="CommandErrorException">达到重试上限</exception>
        /// <returns></returns>
        public CommandResult Execute()
        {
            CommandResult?result = null;

            for (int crtTime = 1; crtTime <= MaxTimes; crtTime++)
            {
                Task.Run(() => result = executor.Fastboot(device, command));
                Thread.Sleep(WAIT_TIME);
                if (result == null)
                {
                    executor.CancelCurrent();
                    Thread.Sleep(INTERVAL);
                }
                else
                {
                    break;
                }
            }
            return(result ?? throw new CommandErrorException("Reachec limit of try."));
        }
Пример #3
0
        public void EntryPoint(ILeafUI ui, ICommandExecutor executor)
        {
            var textCarrier = new TextCarrier();

            using (ui)
            {
                ui.Show();
                string     input    = null;
                IPEndPoint endPoint = null;
                do
                {
                    if (input != null)//输入错误
                    {
                        if (!ui.DoYN(textCarrier.RxGetClassText("input_error"), textCarrier.RxGetClassText("input_retry"), textCarrier.RxGetClassText("input_cancel")))
                        {
                            ui.EShutdown();
                        }
                    }
                    input = ui.InputString(textCarrier.RxGetClassText("input_hint"), input ?? "192.168.XX.X:5555");
                    if (input == null)
                    {
                        ui.EShutdown();
                    }
                } while (!TryParse(input, out endPoint));
                ui.Closing += (s, e) =>
                {
                    executor.CancelCurrent();
                    return(true);
                };
                executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);
                if (executor.Adb($"connect {endPoint}").ExitCode == 0)
                {
                    ui.Finish(StatusMessages.Success);
                }
                else
                {
                    ui.Finish(StatusMessages.Failed);
                }
            }
        }