Пример #1
0
 private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
 {
     //TODO update all villages
     villagefirst.UpdateResources();
 }
Пример #2
0
        public async void LogginIn()
        {
            //Launching browser
            try
            {
                ChromeOptions options = new ChromeOptions();
                options.AddArguments("--incognito");
                driver = new ChromeDriver("./", options);
                driver.Navigate().GoToUrl(StaticVariables.TribalWarsURL);
                driver.Navigate().GoToUrl(StaticVariables.TribalWarsURL);
            }catch (Exception ex)
            {
                MessageBox.Show("Problem with launching chromedriver : " + ex);
                throw new Exception("Problem occured while launching chromedriver : " + ex);
            }

            if (autologin.Checked)
            {
                //logging
                try
                {
                    driver.FindElement(By.Id("user")).SendKeys(usernamebox.Text);
                    driver.FindElement(By.Id("password")).SendKeys(passwordbox.Text);
                    var pagecontent = driver.PageSource;
                    driver.FindElement(By.ClassName("btn-login")).Click();
                    int timeout = 10000;
                    while (pagecontent == driver.PageSource)
                    {
                        timeout--;
                        if (timeout < 0)
                        {
                            BotStatusLabel.Text      = "LOGIN IN FAILED";
                            BotStatusLabel.ForeColor = Color.Red;
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Error while loggin in " + ex);
                }
                //Entering world
                try
                {
checkforworlds:
                    List <IWebElement> activeworlds = new List <IWebElement>(driver.FindElements(By.ClassName("world_button_active")));
                    if (activeworlds.Count == 0)
                    {
                        goto checkforworlds;
                    }
                    bool worldlocated = false;
                    foreach (IWebElement element in activeworlds)
                    {
                        string worldnumber = element.Text;
                        if (-1 < worldnumber.IndexOf(WorldNumberBox.Text))
                        {
                            worldlocated = true;
                            element.Click();
                            break;
                        }
                    }
                    if (!worldlocated)
                    {
                        //throw error
                    }
                    //Enabling village
                    //TODO Find all villages
                    villagefirst = new Village(driver);
                    villagefirst.UpdateResources();
                    bot = new Bot(villagefirst, driver, this);
                    //Starting timer for update villages
                    aTimer           = new System.Timers.Timer();
                    aTimer.Interval  = 2000;
                    aTimer.Elapsed  += OnTimedEvent;
                    aTimer.AutoReset = true;
                    aTimer.Enabled   = true;
                }
                catch (Exception ex)
                {
                    throw new Exception("Problem while entering world" + ex);
                }
            }
            else
            {
                throw new NotImplementedException("Manual loggin feauture is disabled for now");
            }
        }