public Device CreateDevice()
        {
            Device device = new Device();
            // Tạo tên cho device
            string name = $"Device_{random.Next(1000, 10000).ToString()}_{DateTime.Now.ToString("yyyyMMdd-HHmmss")}";

            device.Name = name;
            // Thêm thông tin host
            device.HostId = DeviceVariablesService.MyHost.Id;
            // Tạo Ld mới
            LdPlayerService.Create(device.Name);
            Thread.Sleep(TimeSpan.FromSeconds(DeviceVariablesService.TimeCreateDevice));
            // Config device
            LdPlayerService.PropertySetting(device.Name, DeviceVariablesService.ConfigDevice);
            Thread.Sleep(TimeSpan.FromSeconds(DeviceVariablesService.TimeCreateDevice));
            // Rundevice
            LdPlayerService.Run(device.Name);
            Thread.Sleep(TimeSpan.FromSeconds(DeviceVariablesService.TimeRunDevice));
            // Đọc ip tất cả device
            List <String> deviceIps = KAutoHelper.ADBHelper.GetDevices();

            foreach (var dvIp in deviceIps)
            {
                int index = DeviceVariablesService.DeviceIpsRunning.FindIndex(drning => drning == dvIp);
                if (index == -1)
                {
                    device.DeviceIp = dvIp;
                }
            }
            // Thêm thông tin deviceIp đang chạy
            DeviceVariablesService.DeviceIpsRunning.Add(device.DeviceIp);
            // Cài phần mềm
            for (int i = 0; i < 5; i++)
            {
                string apkBrowser = $"{DeviceVariablesService.ApkPath}{DeviceVariablesService.ApkBrowserName}{i + 1}.apk";
                LdPlayerService.InstallApp(device.Name, apkBrowser);

                Thread.Sleep(TimeSpan.FromSeconds(DeviceVariablesService.TimeInstallApp));
                // Thêm thông tin Browser đã cài vào Device
                Browser br = new Browser($"{DeviceVariablesService.BrowserName}{i + 1}", apkBrowser);
                device.Browsers.Add(br);
            }
            string apkFbName = $@"{DeviceVariablesService.ApkPath}{DeviceVariablesService.ApkFacebookName}";

            LdPlayerService.InstallApp(device.Name, apkFbName);
            Thread.Sleep(TimeSpan.FromSeconds(DeviceVariablesService.TimeInstallApp));

            // Lấy ra device mới chạy
            device.Status = true;
            // Lưu thông tin device vào Db
            device = devicesRepo.Add(device);
            return(device);
        }
Esempio n. 2
0
        /// <summary>
        /// - Điều khiển LD tạo tài khoản mới cho đến khi đủ tài khoản
        /// - Khi đủ tài khoản, cho biết "VariablesService.threadRunning" giảm 1 và đóng Thread
        /// </summary>
        public void CreateAccountsLD()
        {
            // Khởi động LD
            LdPlayerService.Run(ld.Name);
            Thread.Sleep(TimeSpan.FromSeconds(DeviceVariablesService.TimeRunDevice));
            // Run app
            // Kiểm tra số browser đã có tài khoản
            // Trong LD đã có thông tin Browser
            int    nError           = 0;
            string browserNameError = null;

            for (int i = 0; i < ld.Browsers.Count; i++)
            {
                // TH: Nếu Browser chưa được sử dụng
                if (!ld.Browsers[i].Status)
                {
                    if (nError == 2)
                    {
                        // Show Error
                        ErrorService.SimThue_GetSmsError();
                        return;
                    }
                    // Tạo tài khoản mới trên Browser này
                    Account acc = new Account();
                    // Tạo Account Name
                    AddAccountName(ld.Browsers[i].Name);
                    AddBrithday();
                    string phoneNumber = null;
                    if (SimVariablesService.UseSimThue)
                    {
                        simthue.CreateRequest();
                        int n = 0;
                        while (phoneNumber == null)
                        {
                            // Lỗi lấy sđt 5 lần
                            if (n == 3)
                            {
                                ErrorService.SimThue_GetNumberError();
                                return;
                            }
                            phoneNumber = AddPhoneNumber();
                            if (phoneNumber == null)
                            {
                                DelayService.Seconds(1);
                                simthue.CreateRequest();
                            }
                            n++;
                        }
                    }
                    acc.PhoneNumber = phoneNumber;
                    string pass = AddPassWord();
                    acc.Password = pass;
                    bool smsOk = RequestSms();
                    // TH không lấy được Message
                    if (!smsOk)
                    {
                        // Xóa browser
                        LdPlayerService.UnInstallApp(ld.Name, ld.Browsers[i].Name);
                        DelayService.Minutes(1);
                        // Cài lại
                        LdPlayerService.InstallApp(ld.Name, ld.Browsers[i].FileName);
                        DelayService.Seconds(40);
                        // Cho chạy lại trình duyệt này
                        i--;
                        if (browserNameError == null)
                        {
                            browserNameError = ld.Browsers[i].Name;
                            nError++;
                        }
                        else if (browserNameError == ld.Browsers[i].Name)
                        {
                            nError++;
                        }
                        else
                        {
                            browserNameError = ld.Browsers[i].Name;
                            nError           = 1;
                        }
                    }
                    UpAddress();
                    AddFriend();
                    //string code2Fa = Setup2Fa();
                    //acc.Fb2FACode = code2Fa;
                    // Đọc User ID

                    // Lưu Account vào Db
                }
            }
            // Tạo các tài khoản còn lại

            //TESTING
            Thread.Sleep(TimeSpan.FromMinutes(5));
            LdPlayerService.Quit(ld.Name);
            DeviceVariablesService.ThreadRunning -= 1;
        }