Exemplo n.º 1
0
        // Verifica se a aula já está reservada
        public bool IsAulaReservada(IWebDriver driver, Aula aula)
        {
            utils.Log(NLog.LogLevel.Debug, "");

            try
            {
                WebDriverWait wait            = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
                IWebElement   aulasReservadas = wait.Until <IWebElement>(d => d.FindElement(By.Id("aulas-reservadas-holder")));

                string innerHtml = aulasReservadas.Text;
                // procura todos os elementos da aula no container
                if (innerHtml.Contains(aula.Nome) && innerHtml.Contains(aula.Hora) &&
                    innerHtml.Contains(aula.Estudio) && innerHtml.Contains(aula.Duracao))
                {
                    utils.Log(NLog.LogLevel.Debug, string.Format("Aula está reservada: {0}", aula.ToString()));
                    return(true);
                }
            }
            catch (Exception ex)
            {
                utils.Log(NLog.LogLevel.Error, "ERROR getting Aulas Reservadas status! " + ex.Message);
                throw (ex);
            }
            return(false);
        }
Exemplo n.º 2
0
        // Reserva a aula
        public void ReservarAula(IWebDriver driver, Aula aula)
        {
            utils.Log(NLog.LogLevel.Debug, "");

            IWebElement aulasContainer = null;
            IWebElement aulaLink       = null;

            try
            {
                // procura os dados da aula num mesmo elemento de link <a/> com multiplos <div/>
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
                aulasContainer = wait.Until <IWebElement>(d => driver.FindElement(By.Id("aulas-holder")));
            }
            catch (Exception ex)
            {
                utils.Log(NLog.LogLevel.Debug, "ERROR getting Aulas Container! " + ex.Message);
                throw (ex);
            }

            try
            {
                aulaLink = utils.FindAulaLink(aulasContainer, aula);

                if (aulaLink != null)
                {
                    // abre a aula para reservar
                    aulaLink.Click();

                    // reserva a aula
                    utils.ClickWhenReady(driver, By.LinkText("RESERVAR AULA"), TimeSpan.FromSeconds(15));

                    // fecha a aula
                    aulaLink.Click();
                }
            }
            catch (Exception ex)
            {
                utils.Log(NLog.LogLevel.Warn, string.Format("Aula não disponível para reservar: {0}", aula.ToString()) + ex.Message);
            }
        }
Exemplo n.º 3
0
        // Devolve a lista de aulas a inscrever no dia de hoje, ordenada por hora
        public List <Aula> LoadInscricaoAulas(string filepath, DateTime day)
        {
            utils.Log(NLog.LogLevel.Debug, "");

            List <Aula> listAula = new List <Aula>();

            XmlDocument xDoc = new XmlDocument();

            try
            {
                xDoc.Load(filepath);
            }
            catch (Exception ex)
            {
                utils.Log(NLog.LogLevel.Error, "ERROR loading configuration file! " + ex.Message);
                throw (ex);
            }

            string weekday = DateTime.Today.DayOfWeek.ToString();

            try
            {
                XmlNodeList aulaNodes = xDoc.SelectNodes(string.Format("/MyHut/MapaAulas/DiaSemana[@id='{0}' and not(@inativo)]/Aula", weekday));
                foreach (XmlNode aulaNode in aulaNodes)
                {
                    XmlAttribute inativo = aulaNode.Attributes["inativo"];
                    if (inativo == null)
                    {
                        string nome    = aulaNode.SelectSingleNode("Nome").InnerText;
                        string hora    = aulaNode.SelectSingleNode("Hora").InnerText;
                        string estudio = aulaNode.SelectSingleNode("Estudio").InnerText;
                        string duracao = aulaNode.SelectSingleNode("Duracao").InnerText;

                        Aula aula = new Aula(nome, hora, estudio, duracao);

                        listAula.Add(aula);

                        utils.Log(NLog.LogLevel.Debug, string.Format("Aula carregada: {0}", aula.ToString()));
                    }
                }
            }
            catch (Exception ex)
            {
                utils.Log(NLog.LogLevel.Error, "ERROR loading Aulas from configuration file! " + ex.Message);
                throw (ex);
            }

            return(listAula);
        }