Example #1
0
        private static void LoginUser(OpenQA.Selenium.PhantomJS.PhantomJSDriver driver, LoginInfo login)
        {
            driver.Navigate().GoToUrl("https://login.one.com/cp/");
            var username = driver.FindElement(By.Name("displayUsername"));

            username.SendKeys(login.UserName);

            var password = driver.FindElement(By.ClassName("password"));

            password.SendKeys(login.Password);

            var button = driver.FindElement(By.ClassName("oneButton"));

            button.Click();
        }
Example #2
0
        static void Main(string[] args)
        {
            try
            {
                if (args != null && args.Length > 0)
                {
                    gitFolder = args[0];
                }
                //WriteSettings(gitFolder, new LoginInfo
                //{
                //    UserName = "",
                //    Password = ""
                //});
                //return;

                // NOTE: PLEASE NOTE THAT OUR SYNC JOB NEEDS TO RUN BEFORE THIS PROGRAM IS CALLED!

                var folderBoard       = gitFolder + "brfskagagard-styrelsen" + Path.DirectorySeparatorChar;
                var folderBoardExists = Directory.Exists(folderBoard);

                var apartments = GetApartments(gitFolder);

                Console.WriteLine(apartments.Count);

                var driverLocation = System.AppContext.BaseDirectory + "binaries" + Path.DirectorySeparatorChar;

                LoginInfo login = ReadSettings(gitFolder);

                using (var driver = new OpenQA.Selenium.PhantomJS.PhantomJSDriver(driverLocation))
                {
                    driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));

                    LoginUser(driver, login);

                    var list = GetEmails(driver);

                    foreach (var apartment in apartments)
                    {
                        var emails           = apartment.Owners.Select(o => o.Email).Where(e => !string.IsNullOrEmpty(e)).ToList();
                        var forwardsToRemove = new List <string>();

                        var email     = apartment.Number + "@brfskagagard.se";
                        var emailInfo = list.FirstOrDefault(i => i.Email == email);
                        if (emailInfo != null)
                        {
                            // temporarly store emails we should not forward to anymore
                            var forwards = new List <string>(emailInfo.ForwardAddresses);
                            foreach (var forward in forwards)
                            {
                                if (emails.Contains(forward))
                                {
                                    emails.Remove(forward);
                                }
                                else
                                {
                                    forwardsToRemove.Add(forward);
                                }
                            }

                            // add emails that was not already present
                            if (emails.Count > 0)
                            {
                                foreach (var item in emails)
                                {
                                    AddForwardEmail(driver, emailInfo, item);
                                }
                            }

                            //
                            var emailsLeft = (emailInfo.ForwardAddresses.Count + emails.Count) - forwardsToRemove.Count;
                            if (emailsLeft <= 0)
                            {
                                AddForwardEmail(driver, emailInfo, "*****@*****.**");
                            }

                            // do the actuall removal of email(s)
                            foreach (var item in forwardsToRemove)
                            {
                                RemoveForwardEmail(driver, emailInfo, item);
                            }
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                throw;
            }
        }