示例#1
0
        public static async Task <bool> Registration(
            DeviceController.DeviceController deviceController,
            string emulatorImageName,
            string proxy,
            AppiumDevice appium,
            AbstractSmsRegistrator smsRegistrator,
            string nickname,
            string port
            )
        {
            bool banned     = false;
            int  iterations = 0;

            string command = "emulator @" + emulatorImageName;

            if (!proxy.IsNullOrEmpty())
            {
                command += " -http-proxy " + proxy;
                System.IO.File.AppendAllText("usedproxy.txt", proxy + "\n");
                System.IO.File.AppendAllText("usedproxy.txt", "\n");
            }
            command += " -wipe-data -no-snapshot-load";
            deviceController.Log("Emulator starting");
            Logger.log("Emulator starting");
            CommandExecutor.ExecuteCommandAsync(command);
            await Task.Delay(5000);

            /*Open contacts*/
            iterations = 0;
            while (iterations < 60)
            {
                try
                {
                    deviceController.Log("Running Contacts app");
                    Logger.log("Running Contacts app");
                    appium = new AppiumDevice(Apps.Contacts,
                                              Apps.ContatsActivity_Main,
                                              new Device(emulatorImageName),
                                              port
                                              );
                    ContactsScenario.GenerateVCard(deviceController);
                    break;
                }
                catch
                {
                    iterations++;
                    await Task.Delay(1000);
                }
            }
            /*Import Contacts*/
            iterations = 0;
            while (iterations < 60)
            {
                try
                {
                    deviceController.Log("Importing contacts");
                    Logger.log("Importing contacts");
                    ContactsScenario.ImportContacts(appium);
                    break;
                }
                catch
                {
                    iterations++;
                    await Task.Delay(500);
                }
            }

            /*Get number to activate*/
            string number = "";

            iterations = 0;
            while (iterations < 60)
            {
                try
                {
                    number = await smsRegistrator.GetNumber();

                    deviceController.Log("Recived number: " + number);
                    Logger.log("Recived number: " + number);
                    number = number.Remove(0, 1);
                    break;
                }
                catch
                {
                    iterations++;
                    if (iterations > 10)
                    {
                        throw new Exception("Sms registrator error");
                    }
                    await Task.Delay(2000);
                }
            }

            Random random = new Random();

            iterations = 0;
            while (iterations < 60)
            {
                try
                {
                    deviceController.Log("Registration started");
                    Logger.log("Registration started");
                    appium = new AppiumDevice(Apps.WhatsApp,
                                              Apps.WhatsAppActivity_Eula,
                                              new Device(emulatorImageName),
                                              port);
                    banned = await WhatsAppScenario.Registration(appium, number, "7");

                    if (banned)
                    {
                        deviceController.Log("Number is banned");
                        Logger.log("Number is banned");
                        appium.CloseApp();
                        smsRegistrator.SetStatus("7" + number, "10");
                        smsRegistrator.SetStatus("7" + number, "-1");
                        iterations = 0;
                        while (iterations < 60)
                        {
                            try
                            {
                                number = await smsRegistrator.GetNumber();

                                deviceController.Log("Waiting for code");
                                Logger.log("Waiting for code");
                                number = number.Remove(0, 1);
                                break;
                            }
                            catch
                            {
                                iterations++;
                                await Task.Delay(5000);
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                catch
                {
                    iterations++;
                    await Task.Delay(2000);
                }
            }

            smsRegistrator.PhoneReady("7" + number);

            iterations = 0;
            while (iterations < 1200)
            {
                try
                {
                    string code = await smsRegistrator.GetCode("7" + number);

                    if (code != "STATUS_WAIT_CODE")
                    {
                        WhatsAppScenario.VerifyCode(appium, code);
                        break;
                    }
                    else
                    {
                        iterations++;
                        await Task.Delay(1000);
                    }
                }
                catch
                {
                    iterations++;
                    await Task.Delay(1000);
                }
            }

            smsRegistrator.SetStatus("7" + number, "6");

            iterations = 0;
            while (iterations < 60)
            {
                try
                {
                    WhatsAppScenario.WriteName(appium, nickname);
                    break;
                }
                catch
                {
                    iterations++;
                    await Task.Delay(500);
                }
            }
            deviceController.Log("Registration finished");
            return(banned);
        }
示例#2
0
        public async void AutomatizationCancellable(CancellationTokenSource cancellationTokenSource)
        {
            checkActivity.Enabled = true;
            bool banned = false;
            // string command = "cd " + textBoxAppiumSendKeys.Text;
            //CommandExecutor.ExecuteCommandAsync(command);
            int    iterations = 0;
            string command    = "emulator @" + comboBoxAppium.Text;

            if (textBoxProxy.Text != "")
            {
                command += " -http-proxy " + textBoxProxy.Text;
                System.IO.File.AppendAllText("usedproxy.txt", textBoxProxy.Text + "\n");
            }
            command += " -wipe-data -no-snapshot-load";

            CommandExecutor.ExecuteCommandAsync(command);
            await Task.Delay(25000);


            iterations = 0;
            while (iterations < 60)
            {
                try
                {
                    appium = new AppiumDevice(Apps.Contacts,
                                              Apps.ContatsActivity_Main,
                                              new Device(comboBoxAppium.Text));
                    SendVCard();
                    break;
                }
                catch
                {
                    iterations++;
                    await Task.Delay(5000);
                }
            }
            iterations = 0;
            while (iterations < 60)
            {
                try
                {
                    ContactsScenario.ImportContacts(appium);
                    break;
                }
                catch
                {
                    iterations++;
                    await Task.Delay(5000);
                }
            }

            await Task.Delay(2000);


            string number = "";

            iterations = 0;
            while (iterations < 60)
            {
                try
                {
                    number = await smsActivate.GetNumber();

                    number = number.Remove(0, 1);
                    break;
                }
                catch
                {
                    iterations++;
                    await Task.Delay(5000);
                }
            }
            do
            {
                Random random = new Random();
                iterations = 0;
                while (iterations < 60)
                {
                    try
                    {
                        appium = new AppiumDevice(Apps.WhatsApp,
                                                  Apps.WhatsAppActivity_Eula,
                                                  new Device(comboBoxAppium.Text));
                        // await Task.Delay(random.Next(4000, 6000));
                        banned = await WhatsAppScenario.Registration(appium, number, "7");

                        if (banned)
                        {
                            appium.CloseApp();
                            smsActivate.setStatus("7" + number, "10");
                            smsActivate.setStatus("7" + number, "-1");
                            iterations = 0;
                            while (iterations < 60)
                            {
                                try
                                {
                                    number = await smsActivate.GetNumber();

                                    number = number.Remove(0, 1);
                                    break;
                                }
                                catch
                                {
                                    iterations++;
                                    await Task.Delay(5000);
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        iterations++;
                        await Task.Delay(5000);
                    }
                }
            } while (!banned);


            smsActivate.PhoneReady("7" + number);
            iterations = 0;
            while (iterations < 1200)
            {
                try
                {
                    string code = await smsActivate.GetCode("7" + number);

                    if (code != "STATUS_WAIT_CODE")
                    {
                        WhatsAppScenario.VerifyCode(appium, code);
                    }
                    else
                    {
                        iterations++;
                        await Task.Delay(1000);
                    }
                }
                catch (Exception ex)
                {
                    iterations++;

                    await Task.Delay(1000);
                }
            }

            smsActivate.setStatus("7" + number, "6");

            iterations = 0;
            while (iterations < 60)
            {
                try
                {
                    WhatsAppScenario.WriteName(appium, textBoxName.Text);
                }
                catch
                {
                    iterations++;
                    await Task.Delay(5000);
                }
            }

            System.Media.SoundPlayer player = new System.Media.SoundPlayer(Properties.Settings.Default.PathToDirectory + "/success.wav");
            player.Play();
            // devices.Add(new Device(comboBoxAppium.Text));
            // new DeviceForm(comboBoxAppium.Text, textBoxProxy.Text).Show();
        }