Ejemplo n.º 1
0
        private static void LoadBrowsers(double browsersNum)
        {
            var count = Utils.DriverList.Count;

            for (var i = count; i < browsersNum + count; i++)
            {
                try
                {
                    var options = new ChromeOptions();
                    if (File.Exists("extension.crx"))
                    {
                        options.AddExtension(Path.GetFullPath("extension.crx"));
                    }
                    else
                    {
                        options.AddArgument("-incognito");
                    }

                    var driver       = new ChromeDriver(options);
                    var driverStruct = new DriverStruct
                    {
                        Driver    = driver,
                        Num       = i,
                        IsEnabled = true
                    };
                    Utils.DriverList.Add(driverStruct);
                }
                catch (Exception ex)
                {
                    Informer.RaiseOnResultReceived(ex);
                }
            }
        }
Ejemplo n.º 2
0
        public DriverStruct[] GetManufactureChipsetControl()
        {
            DriverStruct[] MyDriverStruct;
            int            i = 0;

            // protected DutStruct[] MyDutStruct;
            DtMyDutInf = new DataTable();

            string StrTableName = "GlobalManufactureChipsetControl";

            string StrSelectconditions = "select * from " + StrTableName + " where PID= " + ProductionNameId + " order by ID";

            DtMyDutInf = MyDataio.GetDataTable(StrSelectconditions, StrTableName);// 获得环境的DataTable

            MyDriverStruct = new DriverStruct[DtMyDutInf.Rows.Count];
            // MyDutStructArray.
            foreach (DataRow dr in DtMyDutInf.Rows)
            {
                DriverStruct dutDriverStruct = new DriverStruct();
                dutDriverStruct.FiledName       = Convert.ToString(dr["ItemName"]).Trim().ToUpper();
                dutDriverStruct.MoudleLine      = Convert.ToByte(dr["ModuleLine"]);
                dutDriverStruct.ChipLine        = Convert.ToByte(dr["ChipLine"]);
                dutDriverStruct.DriverType      = Convert.ToByte(dr["DriveType"]);
                dutDriverStruct.RegisterAddress = Convert.ToByte(dr["RegisterAddress"]); //         RegisterAddress
                dutDriverStruct.Length          = Convert.ToByte(dr["Length"]);          //         RegisterAddress
                MyDriverStruct[i] = dutDriverStruct;

                i++;
            }

            return(MyDriverStruct);
        }
Ejemplo n.º 3
0
        private static async void GetNoCaptcha(DriverStruct drStr)
        {
            drStr.IsEnabled = false;
            var result = await GetCaptcha.GetNoCaptcha(Settings.Default.AntigateKey, drStr);

            drStr.IsEnabled = true;
            if (!result.Answer.StartsWith("Error message") || result.Answer.Contains("Stopped") ||
                result.Answer.Contains("Отменена задача"))
            {
                Utils.CaptchaQueue = result;
            }
        }
Ejemplo n.º 4
0
        public static async Task <CaptchaStruct> GetNoCaptcha(string agKey, DriverStruct drStr)
        {
            try
            {
                var challenge = string.Empty;
                while (true)
                {
                    var WebDriver = drStr.Driver;
                    WebDriver.Manage().Cookies.DeleteAllCookies();
                    try
                    {
                        if (!Utils.IsPermit)
                        {
                            return(new CaptchaStruct
                            {
                                Answer = "Error message: Stopped",
                                Challenge = string.Empty,
                                Date = DateTime.Now
                            });
                        }

                        WebDriver.Navigate().GoToUrl("http://www.gog.com/redeem");
                        await Task.Delay(PictureOpen);

                        try
                        {
                            WebDriver.SwitchTo()
                            .Frame(WebDriver.FindElement(By.XPath("//iframe[@title='recaptcha widget']")));
                        }
                        catch (Exception)
                        {
                            WebDriver.SwitchTo()
                            .Frame(WebDriver.FindElement(By.XPath("//iframe[@title='виджет reCAPTCHA']")));
                        }

                        WebDriver.FindElement(By.XPath("//div[@class='recaptcha-checkbox-checkmark']")).Click();
                        WebDriver.SwitchTo().DefaultContent();

                        await Task.Delay(PictureOpen);

                        try
                        {
                            WebDriver.SwitchTo()
                            .Frame(WebDriver.FindElement(By.XPath("//iframe[@title='recaptcha challenge']")));
                        }
                        catch (Exception)
                        {
                            WebDriver.SwitchTo()
                            .Frame(WebDriver.FindElement(By.XPath("//iframe[@title='проверка recaptcha']")));
                        }

                        while (true)
                        {
                            if (!Utils.IsPermit)
                            {
                                return(new CaptchaStruct
                                {
                                    Answer = "Error message: Stopped",
                                    Challenge = string.Empty,
                                    Date = DateTime.Now
                                });
                            }
                            var answ = await GetCaptchaResult(WebDriver, agKey);

                            if (string.IsNullOrEmpty(answ))
                            {
                                if (!Utils.IsPermit)
                                {
                                    return(new CaptchaStruct
                                    {
                                        Answer = "Error message: Stopped",
                                        Challenge = string.Empty,
                                        Date = DateTime.Now
                                    });
                                }
                                continue;
                            }

                            var picNums        = Regex.Matches(answ, @"\d+");
                            var imageSelectors =
                                WebDriver.FindElements(By.XPath("//div[@class='rc-image-tile-wrapper']"));

                            try
                            {
                                foreach (var z in from object x in picNums select int.Parse(x.ToString()) - 1)
                                {
                                    imageSelectors[z].Click();
                                }
                            }
                            catch (Exception)
                            {
                                challenge = WebDriver.FindElement(By.Id("recaptcha-token"))
                                            .GetAttribute("value");
                                break;
                            }

                            WebDriver.FindElement(By.Id("recaptcha-verify-button")).Click();
                            await Task.Delay(2000);

                            var incorrect =
                                WebDriver.FindElement(
                                    By.XPath("//div[@class='rc-imageselect-incorrect-response']"))
                                .Text;
                            var more =
                                WebDriver.FindElement(
                                    By.XPath("//div[@class='rc-imageselect-error-select-more']"))
                                .Text;
                            var one =
                                WebDriver.FindElement(By.XPath("//div[@class='rc-imageselect-error-dynamic-more']"))
                                .Text;

                            if (incorrect == "" && more == "" && one == "")
                            {
                                challenge = WebDriver.FindElement(By.Id("recaptcha-token"))
                                            .GetAttribute("value");
                                break;
                            }

                            if (one != "" || more != "")
                            {
                                break;
                            }
                        }

                        if (string.IsNullOrEmpty(challenge))
                        {
                            continue;
                        }
                        break;
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.Contains("no such element"))
                        {
                            challenge = string.Empty;
                            continue;
                        }

                        if (ex.Message.Contains("unexpected alert open"))
                        {
                            throw new Exception("Reload");
                        }
                        if (ex.Message.Contains("Antigate server did not respond"))
                        {
                            throw new Exception(ex.Message);
                        }
                        if (ex.Message.Contains("Индекс за пределами диапазона"))
                        {
                            //throw new Exception("Wrong captcha type");
                        }
                        else if (ex.Message.Contains("Произошла одна или несколько ошибок") ||
                                 ex.Message.Contains("One or more errors occurred"))
                        {
                            if (!ex.InnerException.Message.Contains("Captcha unsolvable") &&
                                !ex.InnerException.Message.Contains("Image file size too big"))
                            {
                                throw new Exception(ex.InnerException.Message);
                            }
                        }
                        else
                        {
                            throw new Exception(ex.Message);
                        }
                    }
                }
                return(new CaptchaStruct {
                    Answer = string.Empty, Challenge = challenge, Date = DateTime.Now
                });
            }
            catch (Exception ex)
            {
                return(new CaptchaStruct
                {
                    Answer = $"Error message: {ex.Message}  => Browser №{drStr.Num + 1}",
                    Challenge = "",
                    Date = DateTime.Now
                });
            }
        }