Exemplo n.º 1
0
        private void GetQuotes()
        {
            pageRandom = null;

            loading_panel.Visibility = Visibility.Visible;
            progressRing.IsActive    = true;
            DoEvents();

            list_quotes.Clear();

            Thread threadGetPage = new Thread(GetPage);

            threadGetPage.Start();

            while (pageRandom == null)
            {
                DoEvents();
            }

            loading_panel.Visibility = Visibility.Hidden;
            progressRing.IsActive    = false;

            HtmlDivision div_actions;
            HtmlDivision div_text;

            java.util.List divList = new java.util.ArrayList();

            divList = pageRandom.getByXPath("//div[@class='quote']");

            foreach (HtmlDivision div in divList.toArray())
            {
                Quote quote = new Quote();

                div_actions = (HtmlDivision)div.getFirstByXPath("./div[@class='actions']");
                HtmlSpan   rating = (HtmlSpan)div_actions.getFirstByXPath("./span[@class='rating-o']");
                HtmlSpan   date   = (HtmlSpan)div_actions.getFirstByXPath("./span[@class='date']");
                HtmlAnchor id     = (HtmlAnchor)div_actions.getFirstByXPath("./a[@class='id']");

                quote.rating     = rating.asText();
                quote.date_added = date.asText();
                quote.ID         = id.asText().Replace("#", "");

                div_text = (HtmlDivision)div.getFirstByXPath("./div[@class='text']");

                quote.quote_text = div_text.asText();

                list_quotes.Add(quote);
            }


            DoEvents();

            if (list_quotes.Count < 1)
            {
                Log("Not enough mana!");
                lblCounter.Content = "";
            }
            else
            {
                btnPrev.Visibility  = Visibility.Visible;
                btnShare.Visibility = Visibility.Visible;

                btnNext.Content = "NEXT";

                counter = 0;

                ShowQuote(counter);
            }

            try
            {
                lblCounter.Visibility = Visibility.Visible;
                lblData.Visibility    = Visibility.Visible;
                lblRating.Visibility  = Visibility.Visible;
                lblLink.Visibility    = Visibility.Visible;
                tb_content.Visibility = Visibility.Visible;
            }
            catch { }
        }