Ejemplo n.º 1
0
        private void client_ExecuteAsyncCompleted(RestResponse response)
        {
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(response.Content);

            List<Account> data = new List<Account>();

            var nodes = from e in doc.DocumentNode.DescendantNodes()
                        where e.Name == "li" &&
                              e.Attributes.Contains("class") == true &&
                              e.Attributes["class"].Value == "account"
                        select e;
            foreach (HtmlNode node in nodes)
            {
                Account a = new Account();
                a.Name = (from e in node.DescendantNodes()
                          where e.Name == "span" &&
                                e.Attributes.Contains("class") == true &&
                                e.Attributes["class"].Value == "nickname"
                          select e).First().InnerText;
                a.Balance = (from e in node.DescendantNodes()
                             where e.Name == "span" &&
                                   e.Attributes.Contains("class") == true &&
                                   e.Attributes["class"].Value == "balance"
                             select e).First().InnerText;
                a.LastUpdated = (from e in node.DescendantNodes()
                                 where e.Name == "span" &&
                                       e.Attributes.Contains("class") == true &&
                                       e.Attributes["class"].Value == "last-updated"
                                 select e).First().InnerText;

                data.Add(a);
            }

            this.listBox1.ItemsSource = data.OrderBy(i => i.Name);

            double total = 0.00;
            foreach (Account a in data)
            {
                total += Convert.ToDouble(a.Balance.Replace("$", "").Replace("–", "-"));
            }

            this.textBlock1.Text = String.Format("{0:c}", total);

            this.ToggleProgressBar();
        }
Ejemplo n.º 2
0
        private void RenderAccounts(HtmlDocument doc)
        {
            List<Account> data = new List<Account>();

            try
            {
                var nodes = from e in doc.DocumentNode.DescendantNodes()
                            where e.Name == "li" &&
                                  e.Attributes.Contains("class") == true &&
                                  e.Attributes["class"].Value.Contains("account")
                            select e;
                foreach (HtmlNode node in nodes)
                {
                    Account a = new Account();
                    a.Name = (from e in node.DescendantNodes()
                              where e.Name == "span" &&
                                    e.Attributes.Contains("class") == true &&
                                    e.Attributes["class"].Value.Contains("nickname")
                              select e).First().InnerText;
                    a.Balance = (from e in node.DescendantNodes()
                                 where e.Name == "span" &&
                                       e.Attributes.Contains("class") == true &&
                                       e.Attributes["class"].Value.Contains("balance")
                                 select e).First().InnerText;
                    a.LastUpdated = (from e in node.DescendantNodes()
                                     where e.Name == "span" &&
                                           e.Attributes.Contains("class") == true &&
                                           e.Attributes["class"].Value.Contains("last-updated")
                                     select e).First().InnerText;

                    data.Add(a);
                }

                this.accounts_listBox1.ItemsSource = data.OrderBy(i => i.Name);

                double total = 0.00;
                foreach (Account a in data)
                {
                    total += Convert.ToDouble(a.Balance.Replace("$", "").Replace("–", "-"));
                }

                this.accounts_textBlock1.Text = String.Format("{0:c}", total);

                this.UpdateLiveTile(total);
            }
            catch
            {
                this.accounts_listBox1.Visibility = System.Windows.Visibility.Collapsed;
                this.accounts_textBlock1.Visibility = System.Windows.Visibility.Collapsed;
                this.accounts_textBlock0.Visibility = System.Windows.Visibility.Visible;
            }
        }