Exemple #1
0
        public override IEnumerable <EntityObject> CustomCollectionLoad(string code, string sessionUID = "", string hashUID = "", IEnumerable <EntityObject> obj = null, IEnumerable <Guid> id = null)
        {
            var result = Enumerable.Empty <EntityObject>();

            BCT.Execute(c =>
            {
                //Пока не заморачивался - передаётся базовый объект и требуется привести к типу
                var entities = Enumerable.Empty <Access>();
                if (obj.Any())
                {
                    entities = obj.Select(q => (Access)q).ToArray();
                }
                switch (code)
                {
                case "All":
                    result = AccessHelper.All();
                    break;

                case "AddAvito":
                    result = new[] { AccessHelper.AddAvito(entities.FirstOrDefault()) };
                    break;

                case "ActivateAccess":
                    AccessHelper.ActivateAccess(entities.FirstOrDefault());
                    break;

                case "GetAccessStatistics":
                    AccessHelper.GetAccessStatistics(entities.FirstOrDefault());
                    break;

                case "Remove":
                    AccessHelper.Remove(entities);
                    break;

                case "Enable":
                    AccessHelper.Enable(id);
                    break;

                case "Disable":
                    AccessHelper.Disable(id);
                    break;

                default:
                    break;
                }
            });
            return(result);
        }
Exemple #2
0
        public override AccessCache Registration(FirefoxDriver driver, AccessCache access)
        {
            var result = access;

            DCT.Execute(c =>
            {
                var tzid = -1;

                if (access.IsForwarding)
                {
                    SendMessage($"Registration => Wait ForwardNumber");
                    tzid = OnlineSimHelper.GetForward(forwardNumber).tzid;
                }
                else
                {
                    SendMessage($"Registration => Wait Number");
                    tzid = OnlineSimHelper.GetNum(ServiceType.avito).tzid;
                }
                SendMessage($"Registration => tzid: {tzid}");
                var getState = OnlineSimHelper.GetState(tzid);
                if (getState == null)
                {
                    SendMessage($"Registration => GetState is null. Abort operation");
                    return;
                }
                access.Phone     = getState.number;
                access.PhoneTZID = getState.tzid;
                SendMessage($"Registration => Phone: {access.Phone}");

                WaitExecute(driver);
                //Перехожу в регистрацию
                driver.Navigate().GoToUrl("https://www.avito.ru/registration");
                WaitExecute(driver);

                //Заполняю все поля
                DoAction(driver, By.CssSelector($"input[name='name']"), e =>
                {
                    e.Clear();
                    e.SendKeys("Валера");
                });
                DoAction(driver, By.CssSelector($"input[name='email']"), e =>
                {
                    e.Clear();
                    e.SendKeys(access.Login);
                });
                var phone = access.Phone.Replace("+7", "");
                DoAction(driver, By.CssSelector($"input[name='phone']"), e =>
                {
                    e.Clear();
                    e.SendKeys(phone);
                });

                for (int i = 0; i < 30; i++)
                {
                    DoAction(driver, By.CssSelector($"input[name='password']"), e =>
                    {
                        e.Clear();
                        e.SendKeys(access.Password);
                    });
                    var capcha     = "";
                    var capchaPath = "";
                    Find(driver, "img", "class", "form-captcha-image js-form-captcha-image", e =>
                    {
                        capchaPath = GetScreenshotElement(driver, e, access.Login);
                    });
                    capcha = FreegateHelper.ImageToText(capchaPath);
                    DoAction(driver, By.CssSelector($"input[name='captcha']"), e =>
                    {
                        e.Clear();
                        e.SendKeys(capcha);
                    });
                    FindTagByTextContains(driver, "button", "Зарегистрироваться", x => JsClick(driver, x));
                    Thread.Sleep(2000);
                    if (driver.PageSource.Contains("Регистрация. Шаг 2"))
                    {
                        break;
                    }
                }

                if (!driver.PageSource.Contains("Регистрация. Шаг 2"))
                {
                    SendMessage("Registration => Captcha is not resolved");
                    AccessHelper.Disable(access.Id);
                    return;
                }

                Find(driver, "button", "class", "button button-azure js-phone-checker-request-code", x => JsClick(driver, x));
                for (int i = 0; i < 30; i++)
                {
                    Thread.Sleep(3000);
                    var state = getState = OnlineSimHelper.GetState(tzid);
                    SendMessage($"Registration => Wait SMS, state = {state.response}");
                    if (state.responseEnum == getStateState.TZ_NUM_ANSWER)
                    {
                        DoAction(driver, By.CssSelector($"input[id='phone-checker-code']"), e =>
                        {
                            e.Clear();
                            e.SendKeys(state.msg);
                        });
                        break;
                    }
                }
                Find(driver, "button", "class", "button button-origin button-origin_large button-origin-green js-registration-form-submit", x => JsClick(driver, x));
                //Получаю смску
                Thread.Sleep(2000);
                //Подтверждаю
                AccessHelper.Enable(access.Id);
            });
            return(access);
        }