Exemple #1
0
 private static void _RunScript(bool KeepRunning, ScriptInterface script)
 {
     if (script != null)
     {
         do
         {
             try
             {
                 script.Script();
                 errornum = 0;
             }
             catch (Exception ex)
             {
                 script.ResetScript();
                 if (ex is SocketException || ex is DeviceNotFoundException || ex is AdbException)
                 {
                     BotCore.server.RestartServer();
                     if (!CheckDeviceOnline())
                     {
                         BotCore.RestartEmulator();
                     }
                     BotCore.Delay(10000);
                     BotCore.ConnectAndroidEmulator();
                     continue;
                 }
                 else if (ex is ThreadAbortException) //Bot stopped
                 {
                 }
                 else
                 {
                     ThrowException(ex);
                     continue;
                 }
             }
         }while (KeepRunning && Run);
     }
     else
     {
         throw new Exception("No script dll found!");
     }
     Run = false;
 }
Exemple #2
0
        private static void _RunScript(bool KeepRunning, ScriptInterface script)
        {
            if (script != null)
            {
                do
                {
                    try
                    {
                        if (TimeDelay(out double delay))
                        {
                            Variables.ScriptLog("Time delay over 30 seconds! Trying to fix it!", Color.Red);
                            try
                            {
                                string year   = DateTime.Now.Year.ToString("0000");
                                string month  = DateTime.Now.Month.ToString("00");
                                string day    = DateTime.Now.Day.ToString("00");
                                string hour   = DateTime.Now.Hour.ToString("00");
                                string minute = DateTime.Now.Minute.ToString("00");
                                string second = DateTime.Now.Second.ToString("00");
                                BotCore.AdbCommand("su 0 toolbox date -s " + year + month + day + "." + hour + minute + second);
                                BotCore.AdbCommand("su 0 toybox date " + month + day + hour + minute + year + "." + second);
                            }
                            catch
                            {
                                Variables.ScriptLog("Failed to fix time delay! We will try to restart the emulator!", Color.Red);
                                BotCore.RestartEmulator();
                            }
                        }
                        else
                        {
                            Variables.AdvanceLog("Current time delay with android is " + delay + " second(s)!");
                        }
                        script.Script();
                        errornum = 0;
                    }
                    catch (Exception ex)
                    {
                        script.ResetScript();
                        if (ex is SocketException || ex is DeviceNotFoundException || ex is AdbException)
                        {
Start:
                            try
                            {
                                BotCore.server.RestartServer();
                            }
                            catch
                            {
                                Variables.ScriptLog("Adb start failed! Retrying in 3 seconds!");
                                BotCore.Delay(3000);
                                goto Start;
                            }
                            if (!CheckDeviceOnline())
                            {
                                BotCore.RestartEmulator();
                            }
                            BotCore.Delay(10000);
                            BotCore.ConnectAndroidEmulator();
                            continue;
                        }
                        else if (ex is ThreadAbortException) //Bot stopped
                        {
                        }
                        else
                        {
                            ThrowException(ex);
                            continue;
                        }
                    }
                }while (KeepRunning && Run);
            }
            else
            {
                throw new DllNotFoundException("No script dll found!");
            }
            Run = false;
        }