private void htmlDocComplete(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Error == null)
            {
                HtmlDocument htmlDoc = e.Document;


                if (htmlDoc != null)
                {
                    HtmlNode node = htmlDoc.GetElementbyId("headline_block");
                    //IEnumerable<HtmlNode>  nodeList =htmlDoc.DocumentNode.Descendants("a");
                    HtmlNode hn = HtmlNode.CreateNode(node.OuterHtml);
                    IEnumerable<HtmlNode> nodeList = hn.Descendants("a");
                    List<Recom> listContent = new List<Recom>();
                    
                    int index = 0;

                    foreach (HtmlNode item in nodeList)
                    {


                        index++;
    
                        string title = item.InnerText;

                        if (title == null || title.Length < 2)
                            continue;
                        
                        //MessageBox.Show("test-----------" + index);
                        string recomTitle = title;
                        //MessageBox.Show("out--------" + title);
                        string titlelnk = item.GetAttributeValue("href", "");
                        //MessageBox.Show("titlelnk--------" + titlelnk);
                        string viewsTitleLnk="";
                        Recom recom = new Recom();

                        if(index==1){
                            viewsTitleLnk=  titlelnk + "&&" + "/ContentViews/";
                        }else if(index==3||index==5){
                            viewsTitleLnk=  titlelnk + "&&" + "/ContentViews/indexContent.xaml";
                            recom.viweImages = "/images/cream.png";
                        }else if(index==6||index==8){
                            viewsTitleLnk = titlelnk + "&&" + "/ContentViews/nowNewsContent.xaml";
                            recom.viweImages = "/images/news.png";
                        }

                        
                        recom.recomTitle = recomTitle;
                        recom.titleLink = viewsTitleLnk;
                        listContent.Add(recom);

                        
                    }

                    this.listBox1.ItemsSource = listContent;

                }
            }

        }
        public static void OnCallback(object s, HtmlDocumentLoadCompleted htmlDocumentLoadCompleted)
        {
            if (thereIsNoErrors(htmlDocumentLoadCompleted))
            {
                var htmlDocument = htmlDocumentLoadCompleted.Document;
                HtmlNodeCollection catalogItems = htmlDocument.DocumentNode.SelectNodes(
                    "//*[@class='catalog_item_middle_center']//a[starts-with(@href,'/films/movie/id')]//img[starts-with(@src,'http://')]");

                tempList = new List<FilmData>();

                if (catalogItems != null)
                {
                    foreach (HtmlNode item in catalogItems)
                    {
                        FilmData fd = new FilmData();
                        if (item.Attributes.Contains("src"))
                        {
                            fd.imageUrl = item.Attributes["src"].Value;
                        }
                        if (item.Attributes.Contains("alt"))
                        {
                            fd.name = item.Attributes["alt"].Value.Substring(6);
                        }
                        tempList.Add(fd);
                    }
                    Networking.getImagesAsync(tempList);
                }
            }
        }
Example #3
0
 private void OnLoadCompleted(HtmlDocumentLoadCompleted htmlDocumentLoadCompleted)
 {
     if (LoadCompleted != null)
     {
         LoadCompleted(this, htmlDocumentLoadCompleted);
     }
 }
Example #4
0
		public void SiteLoaded(object sender, HtmlDocumentLoadCompleted args)
		{
			var nodes = args.Document.DocumentNode.SelectNodes("//a");
			Results.Text = String.Join(Environment.NewLine, nodes.ToList()
															.Select(x=>x.GetAttributeValue("href",string.Empty))
															.ToList());
		}
Example #5
0
 private void htmlWeb_LoadCompleted(object sender, HtmlDocumentLoadCompleted args)
 {
     System.Diagnostics.Debug.WriteLine("Lodcompleted");
     bool isLatestStatus = false;
     statusList = new List<string>();
     var nodes = args.Document.DocumentNode.Descendants("p").Where(x => x.GetAttributeValue("class", "") == "resulttext").ToArray();
     foreach (HtmlNode node in nodes)
     {
         statusList.Add(node.InnerText);
         if (isLatestStatus)
         {
             string[] text = node.InnerText.Split(';');
             timeStamp = text[0].Split('&')[0];
             latestStatus = text[1].Split('&')[0];
             isLatestStatus = false;
         }
         if (node.InnerText.ToLower().Contains("l&auml;hetystunnus"))
         {
             isLatestStatus = true;
         }
     }
     if (this.DataParsed != null)
     {
         this.DataParsed(timeStamp, latestStatus, statusList);
     }
 }
                private void hw_LoadCompleted(object sender, HtmlDocumentLoadCompleted e)
                {
                        if (e.Document != null) {
                                var txt = e.Document;

                                OnTextRetrieved(txt.DocumentNode.InnerText.Replace("\\n","\n").Replace("&nbsp;"," ").Replace("&quot;","\""));
                        }
                }
        private void DownloadCompleted(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Error == null)
            {
                HtmlDocument doc = e.Document;
                if (doc != null)
                {
                    string courseInfo = doc.DocumentNode.Element("html").
                        Element("body").
                        Elements("div").ElementAt(3).
                        Elements("table").ElementAt(0).
                        Elements("tr").ElementAt(0).
                        Element("th").InnerText;

                    string capacity = doc.DocumentNode.Element("html").
                        Element("body").
                        Elements("div").ElementAt(3).
                        Elements("table").ElementAt(0).
                        Elements("tr").ElementAt(1).
                        Element("td").
                        Element("table").
                        Element("tr").
                        Element("tr").
                        Elements("td").ElementAt(0).InnerText;

                    string actual = doc.DocumentNode.Element("html").
                        Element("body").
                        Elements("div").ElementAt(3).
                        Elements("table").ElementAt(0).
                        Elements("tr").ElementAt(1).
                        Element("td").
                        Element("table").
                        Element("tr").
                        Element("tr").
                        Elements("td").ElementAt(1).InnerText;

                    string remaining = doc.DocumentNode.Element("html").
                        Element("body").
                        Elements("div").ElementAt(3).
                        Elements("table").ElementAt(0).
                        Elements("tr").ElementAt(1).
                        Element("td").
                        Element("table").
                        Element("tr").
                        Element("tr").
                        Elements("td").ElementAt(2).InnerText;

                    courseInfoTextBlock.Text = courseInfo;
                    capacityTextBlock.Text = capacity;
                    actualTextBlock.Text = actual;
                    remainingTextBlock.Text = remaining;

                }
            }
        }
        private void htmlDocComplete(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Error == null)
            {
                HtmlDocument htmlDoc = e.Document;
                if (htmlDoc != null)
                {
                    HtmlNode node = htmlDoc.GetElementbyId("post_list");

                    //MessageBox.Show("Hellworld");
                    // string value = "";

                    List<ListContent> listContent = new List<ListContent>();
                    foreach (HtmlNode child in node.ChildNodes)
                    {

                        if (child.Attributes["class"] == null || child.Attributes["class"].Value != "post_item")
                            continue;
                        HtmlNode hn = HtmlNode.CreateNode(child.OuterHtml);
                        ListContent listContextObj = new ListContent();
                        string tuijian = hn.SelectSingleNode("//*[@class=\"diggnum\"]").InnerText;
                        string title = hn.SelectSingleNode("//*[@class=\"titlelnk\"]").InnerText;
                        string jieshao = hn.SelectSingleNode("//*[@class=\"post_item_summary\"]").InnerText;

                        string xinxi = hn.SelectSingleNode("//*[@class=\"post_item_foot\"]").InnerText;
                        string xinxi2 = hn.SelectSingleNode("//*[@class=\"lightblue\"]").InnerText.Trim();
                        string xinxi3 = hn.SelectSingleNode("//*[@class=\"article_comment\"]").InnerText.Trim();
                        string xinxi4 = hn.SelectSingleNode("//*[@class=\"article_view\"]").InnerText.Trim();


                        String titleIDValue = hn.SelectSingleNode("//*[@class=\"diggnum\"]").InnerText;
                        
                        String titlelnk = hn.SelectSingleNode("//*[@class=\"titlelnk\"]").GetAttributeValue("href", "");


                        listContextObj.recommendImage = "/images/cream.png";
                        listContextObj.recommendCount=tuijian;
                        listContextObj.Title = title;
                        listContextObj.Introduce = jieshao;
                        listContextObj.Info = xinxi2 + xinxi3 + xinxi4;
                        listContextObj.titleLink = titlelnk;
                        listContent.Add(listContextObj);


                    }
                    this.listBox1.ItemsSource = listContent;

                   

                }
            }

        }
        private static bool thereIsNoErrors(HtmlDocumentLoadCompleted htmlDocumentLoadCompleted)
        {
            if (htmlDocumentLoadCompleted.Error != null)
            {
                Networking.getHtmlFromUrl("http://stream.ru/films/index/page/" + MainPage.pageId + "/");
                return false;
            }
            else if (htmlDocumentLoadCompleted.Document.DocumentNode.InnerText.Contains("Ошибка 500"))
            {
                //Ошибка 500. Внутреняя ошибка сервера. Попробуйте перезагрузить страницу или вернуться на неё позднее (возможно, произошел случайный сбой).
                Networking.getHtmlFromUrl("http://stream.ru/films/index/page/" + MainPage.pageId + "/");
                return false;
            }

            return true;
        }
        private void htmlDocComplete(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Error == null)
            {
                HtmlDocument htmlDoc = e.Document;
                if (htmlDoc != null)
                {
                    HtmlNode node = htmlDoc.GetElementbyId("cnblogs_post_body");

                    string str = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' />" +
                    "<title></title></head><body>" + node.InnerHtml + "</body></html>";

                    string result = ConvertEncode(str);
                    myWebBrowser.NavigateToString(result);

                }
            }

        }
        private void htmlDocComplete(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Error == null)
            {
                HtmlDocument htmlDoc = e.Document;
                if (htmlDoc != null)
                {
                    HtmlNode node = htmlDoc.GetElementbyId("main");
                    //HtmlNode answerNode= htmlDoc.GetElementbyId("panelAnswerList");
                    //MessageBox.Show(node.InnerHtml);
                    string str = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' />" +
                    "<title></title></head><body>" + node.InnerHtml + "<p></p>"+"</body></html>";

                    string result = ConvertEncode(str);
                    myWebBrowser.NavigateToString(result);

                }
            }

        }
        private void htmlDocComplete(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Error == null)
            {
                HtmlDocument htmlDoc = e.Document;


                if (htmlDoc != null)
                {
                    HtmlNode node = htmlDoc.GetElementbyId("headline_block");
                    //IEnumerable<HtmlNode>  nodeList =htmlDoc.DocumentNode.Descendants("a");
                    HtmlNode hn = HtmlNode.CreateNode(node.OuterHtml);
                    IEnumerable<HtmlNode> nodeList=hn.Descendants("a");
                    List<Recom> listContent = new List<Recom>();

                    foreach (HtmlNode item in nodeList)
                    {
                        //MessageBox.Show("out--------"+item.InnerHtml);
                        //MessageBox.Show("out--------" + item.InnerText);
                        string title = item.InnerText;

                        if(title==null||title.Length<2)
                            continue;
                            string recomTitle = title;
                            //MessageBox.Show("out--------" + title);
                            string titlelnk = item.GetAttributeValue("href", "");
                            //MessageBox.Show("titlelnk--------" + titlelnk);
                            Recom recom = new Recom();
                            recom.recomTitle = recomTitle;
                            recom.titleLink = titlelnk;
                            listContent.Add(recom);

                    }

                    this.listBox1.ItemsSource = listContent;

                }
            }

        }
        /// <summary>
        /// HW_s the load completed.
        /// </summary>
        /// <param name="o">The o.</param>
        /// <param name="e">The e.</param>
        protected void hw_LoadCompleted(object o, HtmlDocumentLoadCompleted e)
        {
            HtmlDocument doc = e.Document;
            if (doc == null) return;
            HtmlNode docNode = doc.DocumentNode;

            HtmlNodeCollection tags = docNode.SelectNodes(".//p[@class='sa']");
            string scripture = tags.Count > 0 ? tags[0].InnerText : string.Empty;

            tags = docNode.SelectNodes(".//p[@class='sb']");
            string summaryText = tags.Count > 0 ? tags[0].InnerText : string.Empty;

            scripture = scripture.Replace("&nbsp;", " ");
            summaryText = summaryText.Replace("&nbsp;", " ");

            var dt = new DailyText {
                                       Scripture = scripture,
                                       SummaryText = summaryText
                                   };

            DailyTextRetrieved.Invoke(dt);
        }
Example #14
0
        void DownloadCompleted(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Error == null)
            {
                HtmlDocument doc = e.Document;
                if (doc != null)
                {

                    TimesC newC;

                    ObservableCollection<TimesC> newTimesList =
                    new ObservableCollection<TimesC>();

                    List<string> names = new List<string>();

                    foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//*[@class=\"ada\"]"))
                    {
                        try
                        {
                            string c;
                            c = link.InnerText;
                            names.Add(c);
                        }
                        catch (FormatException)
                        {

                        }
                    }

                    int i = 1;

                    HtmlNodeCollection test;
                    test = doc.DocumentNode.SelectNodes("//td[@align=\"left\"]");

                    if (test != null)
                    {
                        foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//td[@align=\"left\"]"))
                        {
                            try
                            {
                                string c;
                                c = link.InnerText;
                                names[i] += c;
                                i++;

                            }
                            catch (FormatException)
                            {

                            }
                        }
                    }

                    foreach (string name in names)
                    {
                        newC = new TimesC();
                        newC.TimesName = name;
                        newTimesList.Add(newC);
                    }

                    // copy the data over
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {

                        Vis = Visibility.Collapsed;

                        TimesList.Clear();

                        // copy the list of forecast time periods over
                        foreach (TimesC timesC in newTimesList)
                        {
                            TimesList.Add(timesC);
                        }

                    });

                }
            }
        }
        public void parse_DownloadProductReportPageCompleted(Object sender, HtmlDocumentLoadCompleted e)
        {
            if (e != null && e.Document != null && e.Document.DocumentNode != null)
            {
                IList<Block> pageBody = new List<Block>(); 
                IList<HtmlNode> hnc = e.Document.DocumentNode.DescendantNodes().ToList();
                
                Paragraph paragraph = new Paragraph();
                Boolean content_flag = false;

                foreach (HtmlNode htmlNode in hnc)
                {
                    if (htmlNode.Name.ToLower() == "h1" && htmlNode.Attributes.Count == 0)
                    {
                        PageTitle.Text = htmlNode.InnerText.Replace("�", "'");
                        content_flag = true;

                    }
                    else if (content_flag && htmlNode.Name.ToLower() == "h2")
                    {
                        if (paragraph.Inlines.Count > 0)
                        {
                            pageBody.Add(paragraph);
                            paragraph = new Paragraph();
                        }
                        if (htmlNode.InnerText == "Related Health Canada Web content:")
                        {
                            content_flag = false;
                        }
                        else
                        {
                            Paragraph h2 = new Paragraph();
                            h2.FontSize = 25.333;
                            h2.Inlines.Add(htmlNode.InnerText.Trim());
                            pageBody.Add(h2);
                        }
                    }
                    else if (content_flag && htmlNode.Name.ToLower() == "ul")
                    {
                        if (htmlNode.ParentNode.Name.ToLower() != "p")
                        {
                            if (paragraph.Inlines.Count > 0)
                            {
                                pageBody.Add(paragraph);
                                paragraph = new Paragraph();
                            }

                            Paragraph np = new Paragraph();
                            foreach (HtmlNode a in htmlNode.DescendantNodes().ToList())
                            {
                                if (a.Name.ToLower() == "a")
                                {
                                    Boolean err_flag = false;
                                    Hyperlink hl = new Hyperlink();

                                    hl.Inlines.Add(a.InnerText);
                                    foreach (HtmlAttribute att1 in a.Attributes)
                                    {
                                        if (att1.Name.ToLower() == "href")
                                        {
                                            try
                                            {
                                                if (att1.Value.ToCharArray()[0] != '#')
                                                {
                                                    hl.NavigateUri = new Uri("/ProductReportPage.xaml?external=true&href=" + att1.Value, UriKind.Relative);

                                                }
                                                else
                                                {
                                                    err_flag = true;
                                                }
                                            }
                                            catch (Exception err)
                                            {
                                                err_flag = true;
                                            }
                                            break;
                                        }
                                    }
                                    if (!err_flag)
                                    {
                                        np.Inlines.Add(hl);
                                    }
                                    else
                                    {
                                        Run r = new Run();
                                        r.Text = a.InnerText.Replace("&nbsp;", "");
                                        np.Inlines.Add(r);
                                    }
                                }
                                else if (a.Name.ToLower() == "li")
                                {
                                    Bold b = new Bold();
                                    b.Inlines.Add("- ");
                                    np.Inlines.Add(b);
                                }
                                else if (a.Name.ToLower() == "b" || a.ParentNode.Name.ToLower() == "strong")
                                {
                                    Bold b = new Bold();
                                    b.Inlines.Add(a.InnerText.Replace("&nbsp;", ""));
                                    np.Inlines.Add(b);
                                }
                                else if (a.Name.ToLower() == "i")
                                {
                                    Italic i = new Italic();
                                    i.Inlines.Add(a.InnerText.Replace("&nbsp;", ""));
                                    np.Inlines.Add(i);
                                }
                                else if (a.Name.ToLower() == "#text")
                                {
                                    if (a.ParentNode.Name.ToLower() != "a" && a.ParentNode.Name.ToLower() != "b" && a.ParentNode.Name.ToLower() != "strong" && a.ParentNode.Name.ToLower() != "i")
                                    {

                                        String str = ConvertWhitespacesToSingleSpaces(a.InnerText);
                                        if (str != " ")
                                        {
                                            str = str.Replace("&quot;", "\"");
                                            Run run = new Run();
                                            run.Text = str.Replace("&nbsp;", "");
                                            np.Inlines.Add(run);
                                        }
                                        if (a.NextSibling != null && a.NextSibling.Name.ToLower() == "li")
                                        {
                                            np.Inlines.Add(new LineBreak());
                                        }
                                    }

                                }
                            }
                            np.Inlines.Add(new LineBreak());
                            pageBody.Add(np);
                        }
                    }
                    else if (content_flag && htmlNode.Name.ToLower() == "p")
                    {
                        if (paragraph.Inlines.Count > 0)
                        {
                            pageBody.Add(paragraph);
                            paragraph = new Paragraph();
                        }

                        Paragraph np = new Paragraph();

                        foreach (HtmlNode pc in htmlNode.DescendantNodes().ToList())
                        {
                            if (content_flag && htmlNode.Name.ToLower() == "ul")
                            {
                                foreach (HtmlNode a in htmlNode.DescendantNodes().ToList())
                                {
                                    if (a.Name.ToLower() == "a")
                                    {
                                        Boolean err_flag = false;
                                        Hyperlink hl = new Hyperlink();

                                        hl.Inlines.Add(a.InnerText.Replace("&nbsp;", ""));
                                        foreach (HtmlAttribute att1 in a.Attributes)
                                        {
                                            if (att1.Name.ToLower() == "href")
                                            {
                                                try
                                                {
                                                    if (att1.Value.ToCharArray()[0] != '#')
                                                    {
                                                        hl.NavigateUri = new Uri("/ProductReportPage.xaml?external=true&href=" + att1.Value, UriKind.Relative);

                                                    }
                                                    else
                                                    {
                                                        err_flag = true;
                                                    }
                                                }
                                                catch (Exception err)
                                                {
                                                    err_flag = true;
                                                }
                                                break;
                                            }
                                        }
                                        if (!err_flag)
                                        {
                                            np.Inlines.Add(hl);
                                        }
                                        else
                                        {
                                            Run r = new Run();
                                            r.Text = a.InnerText.Replace("&nbsp;", "");
                                            np.Inlines.Add(r);
                                        }
                                    }
                                    else if (a.Name.ToLower() == "li")
                                    {
                                        Bold b = new Bold();
                                        b.Inlines.Add("- ");
                                        np.Inlines.Add(b);
                                    }
                                    else if (a.Name.ToLower() == "b" || a.ParentNode.Name.ToLower() == "strong")
                                    {
                                        Bold b = new Bold();
                                        b.Inlines.Add(a.InnerText.Replace("&nbsp;", ""));
                                        np.Inlines.Add(b);
                                    }
                                    else if (a.Name.ToLower() == "i")
                                    {
                                        Italic i = new Italic();
                                        i.Inlines.Add(a.InnerText.Replace("&nbsp;", ""));
                                        np.Inlines.Add(i);
                                    }
                                    else if (a.Name.ToLower() == "#text")
                                    {
                                        if (a.ParentNode.Name.ToLower() != "a" && a.ParentNode.Name.ToLower() != "b" && a.ParentNode.Name.ToLower() != "strong" && a.ParentNode.Name.ToLower() != "i")
                                        {

                                            String str = ConvertWhitespacesToSingleSpaces(a.InnerText);
                                            if (str != " ")
                                            {
                                                str = str.Replace("&quot;", "\"");
                                                Run run = new Run();
                                                run.Text = str.Replace("&nbsp;", "");
                                                np.Inlines.Add(run);
                                            }
                                            if (a.NextSibling != null && a.NextSibling.Name.ToLower() == "li")
                                            {
                                                np.Inlines.Add(new LineBreak());
                                            }
                                        }

                                    }
                                }
                                np.Inlines.Add(new LineBreak());
                            } else if (pc.Name.ToLower() == "a")
                            {
                                if (pc.ParentNode.Name.ToLower() != "i" && pc.ParentNode.Name.ToLower() != "b" && pc.ParentNode.Name.ToLower() != "strong")
                                {
                                    Boolean image_flag = false;
                                    Boolean flag_local = false;
                                    Hyperlink hl = new Hyperlink();

                                    hl.Inlines.Add(pc.InnerText.Replace("&nbsp;", ""));

                                    foreach (HtmlAttribute att1 in pc.Attributes)
                                    {
                                        if (att1.Name.ToLower() == "href")
                                        {
                                            try
                                            {
                                                if (att1.Value.ToCharArray()[0] != '#')
                                                {
                                                    hl.NavigateUri = new Uri("/ProductReportPage.xaml?external=true&href=" + att1.Value, UriKind.Relative);
                                                }
                                                else
                                                {
                                                    flag_local = true;
                                                }
                                            }
                                            catch (Exception err)
                                            {
                                                image_flag = true;
                                            }
                                        }
                                        else if (att1.Name.ToLower() == "class" && att1.Value == "image")
                                        {
                                            image_flag = true;
                                        }
                                    }
                                    if (!image_flag && !flag_local)
                                    {
                                        np.Inlines.Add(hl);
                                    }
                                    else if (flag_local)
                                    {
                                        Run r = new Run();
                                        r.Text = pc.InnerText.Replace("&nbsp;", "");
                                        np.Inlines.Add(r);
                                    }
                                }
                            }
                            else if (pc.Name.ToLower() == "#text")
                            {
                                if (pc.ParentNode.Name.ToLower() != "a" && pc.ParentNode.Name.ToLower() != "b" && pc.ParentNode.Name.ToLower() != "strong" && pc.ParentNode.Name.ToLower() != "i")
                                {
                                    String str = ConvertWhitespacesToSingleSpaces(pc.InnerText);
                                    if (str != " ")
                                    {
                                        str = str.Replace("&quot;", "\"");
                                        Run run = new Run();
                                        run.Text = str.Replace("&nbsp;", "");
                                        np.Inlines.Add(run);
                                    }
                                }
                            }
                            else if (pc.Name.ToLower() == "b" || pc.Name.ToLower() == "strong")
                            {
                                Bold b = new Bold();
                                foreach (HtmlNode n in pc.DescendantNodes().ToList())
                                {
                                    if (n.Name.ToLower() == "#text" && n.ParentNode.Name.ToLower() != "a")
                                    {
                                        b.Inlines.Add(n.InnerText.Replace("&nbsp;", ""));
                                    }
                                    else if (n.Name.ToLower() == "a")
                                    {
                                        Boolean image_flag = false;
                                        Boolean flag_local = false;
                                        Hyperlink hl = new Hyperlink();

                                        hl.Inlines.Add(n.InnerText.Replace("&nbsp;", ""));

                                        foreach (HtmlAttribute att1 in n.Attributes)
                                        {
                                            if (att1.Name.ToLower() == "href")
                                            {
                                                try
                                                {
                                                    if (att1.Value.ToCharArray()[0] != '#')
                                                    {
                                                        hl.NavigateUri = new Uri("/ProductReportPage.xaml?external=true&href=" + att1.Value, UriKind.Relative);
                                                    }
                                                    else
                                                    {
                                                        flag_local = true;
                                                    }
                                                }
                                                catch (Exception err)
                                                {
                                                    image_flag = true;
                                                }
                                            }
                                            else if (att1.Name.ToLower() == "class" && att1.Value == "image")
                                            {
                                                image_flag = true;
                                            }
                                        }
                                        if (!image_flag && !flag_local)
                                        {
                                            b.Inlines.Add(hl);
                                        }
                                        else
                                        {
                                            b.Inlines.Add(n.InnerText.Replace("&nbsp;", ""));
                                        }
                                    }
                                }

                                np.Inlines.Add(b);
                            }
                            else if (pc.Name.ToLower() == "br")
                            {
                               // Run r = new Run();
                               // r.Text = "\n";
                              //  np.Inlines.Add(r);
                            }
                            else if (pc.Name.ToLower() == "i")
                            {
                                Italic i = new Italic();
                                foreach (HtmlNode n in pc.DescendantNodes().ToList())
                                {
                                    if (n.Name.ToLower() == "#text" && n.ParentNode.Name.ToLower() != "a")
                                    {
                                        i.Inlines.Add(n.InnerText.Replace("&nbsp;", ""));
                                    }
                                    else if (n.Name.ToLower() == "a")
                                    {
                                        Boolean image_flag = false;
                                        Boolean flag_local = false;
                                        Hyperlink hl = new Hyperlink();

                                        hl.Inlines.Add(n.InnerText.Replace("&nbsp;", ""));

                                        foreach (HtmlAttribute att1 in n.Attributes)
                                        {
                                            if (att1.Name.ToLower() == "href")
                                            {
                                                try
                                                {
                                                    if (att1.Value.ToCharArray()[0] != '#')
                                                    {
                                                        hl.NavigateUri = new Uri("/ProductReportPage.xaml?external=true&href=" + att1.Value, UriKind.Relative);
                                                    }
                                                    else
                                                    {
                                                        flag_local = true;
                                                    }
                                                }
                                                catch (Exception err)
                                                {
                                                    image_flag = true;
                                                }
                                            }
                                            else if (att1.Name.ToLower() == "class" && att1.Value == "image")
                                            {
                                                image_flag = true;
                                            }
                                        }
                                        if (!image_flag && !flag_local)
                                        {
                                            i.Inlines.Add(hl);
                                        }
                                        else
                                        {
                                            i.Inlines.Add(n.InnerText.Replace("&nbsp;", ""));
                                        }
                                    }
                                }

                                np.Inlines.Add(i);
                            }
                        }
                        np.Inlines.Add(new LineBreak());
                        pageBody.Add(np);

                    }
                   
                }
                if (paragraph != null && paragraph.Inlines.Count > 0)
                {
                    pageBody.Add(paragraph);
                }
                foreach (Block b in pageBody)
                {
                    RichTextBox rtb = new RichTextBox();
                    rtb.IsReadOnly = true;
                    rtb.VerticalAlignment = VerticalAlignment.Top;
                    rtb.Blocks.Add(b);
                    PageBody.Children.Add(rtb);

                }
                LoadingProductScreen.IsOpen = false;
                PageBody.InvalidateArrange();
                PageBody.InvalidateMeasure();
                scrollerViewer.InvalidateArrange();
                scrollerViewer.InvalidateMeasure();
                scrollerViewer.InvalidateScrollInfo();
                Content.InvalidateArrange();
                Content.InvalidateMeasure();
            }
        }
Example #16
0
        private void OnUrlLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            _web.LoadCompleted -= OnUrlLoaded;
            DataLoadedEventArgs loadedArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                if (LoadFromHtml(args.Document.DocumentNode, loadedArgs))
                {
                    IsLoaded = true;
                    MyClubGroup.LoadFromUrl(_web, App.Settings.BuildUrl(MitbbsClubGroup.UserClubGroupUrl));
                    return;
                }
            }
            else
            {
                loadedArgs.Error = args.Error;
            }

            if (UserHomeLoaded != null)
            {
                UserHomeLoaded(this, loadedArgs);
            }
        }
        private static void ParseBandwidthDocument(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Error is WebException)
            {
                _page.ReportCredentialsError();
                return;
            }
            if (e.Error != null) return;
            var doc = e.Document;
            var summaryTable = from desc in doc.DocumentNode.Descendants()
                               where desc.Name == "td" &&
                                     desc.InnerText == "Bandwidth Class"
                               select desc.ParentNode.ParentNode;

            var resultsList = summaryTable.ElementAt(0).Elements("tr").ElementAt(1).Elements("td");
            var htmlNodes = resultsList as HtmlNode[] ?? resultsList.ToArray();
            var results = new BandwidthResults()
            {
                BandwidthClass = htmlNodes.ElementAt(0).InnerText,
                PolicyReceived = htmlNodes.ElementAt(1).InnerText,
                PolicySent = htmlNodes.ElementAt(2).InnerText,
                ActualReceived = htmlNodes.ElementAt(3).InnerText,
                ActualSent = htmlNodes.ElementAt(4).InnerText
            };
            Deployment.Current.Dispatcher.BeginInvoke(() => _page.UpdateUi(results, true));
            results.SaveToIsolatedStorage();
        }
        private void htmlDocComplete(object sender, HtmlDocumentLoadCompleted e){
            if(e.Error==null){
                HtmlDocument htmlDoc = e.Document;
                if(htmlDoc!=null){
                    List<FlashMemory> flashMemoryList = new List<FlashMemory>();

                    HtmlNode node = htmlDoc.GetElementbyId("feed_list");
                    //MessageBox.Show("node--------------"+node.InnerHtml);
                    HtmlNode hn = HtmlNode.CreateNode(node.OuterHtml);
                    IEnumerable<HtmlNode> nodeList = hn.Descendants("li");
                    foreach(HtmlNode item in nodeList){
                        //MessageBox.Show(item.InnerHtml);
                        HtmlNode hnChild = HtmlNode.CreateNode(item.OuterHtml);

                        if (item.Attributes["class"] != null && item.Attributes["class"].Value == "entry_b")
                        {
                            FlashMemory flashMemoryb = new FlashMemory();

                            IEnumerable<HtmlNode> userImageNodeList = hnChild.SelectSingleNode("//*[@class=\"feed_avatar\"]").Descendants("img");
                            string userImageLink = "";
                            foreach (HtmlNode authorImage in userImageNodeList)
                            {

                                string userImageb = authorImage.GetAttributeValue("src", "");
                                //MessageBox.Show("userImage-------"+userImageb);
                                if (userImageb.IndexOf(".gif") > 0)
                                {
                                    userImageLink = "/images/skydrive.png";
                                }
                                else
                                {
                                    userImageLink = userImageb;
                                }

                            }
                            
                            string authorb = hnChild.SelectSingleNode("//*[@class=\"ing-author\"]").InnerText.Trim();
                            string authorContentb = hnChild.SelectSingleNode("//*[@class=\"ing_body\"]").InnerText.Trim();
                            string authorReleaseDateb = hnChild.SelectSingleNode("//*[@class=\"ing_time gray\"]").InnerText.Trim();
                            /**MessageBox.Show("authorb----------" + authorb);
                            MessageBox.Show("authorContentb----------" + authorContentb);
                            MessageBox.Show("authorReleaseDateb----------" + authorReleaseDateb);*/
                            flashMemoryb.userImage=userImageLink;
                            flashMemoryb.userAuthor = authorb;
                            flashMemoryb.userContent = authorContentb;
                            flashMemoryb.userReleaseDate = authorReleaseDateb;
                            flashMemoryList.Add(flashMemoryb);
                        
                        }
                        if (item.Attributes["class"] != null && item.Attributes["class"].Value == "entry_a")
                        {
                            FlashMemory flashMemorya = new FlashMemory();

                            IEnumerable<HtmlNode> userImageNodeList = hnChild.SelectSingleNode("//*[@class=\"feed_avatar\"]").Descendants("img");
                            string userImageLink = "";
                            foreach (HtmlNode authorImage in userImageNodeList)
                            {

                                string userImagea = authorImage.GetAttributeValue("src", "");
                                //MessageBox.Show("userImagea--------"+userImagea);
                                if (userImagea.IndexOf(".gif") > 0)
                                {
                                    userImageLink = "/images/skydrive.png";
                                }
                                else
                                {
                                    userImageLink = userImagea;
                                }

                            }

                            string authora = hnChild.SelectSingleNode("//*[@class=\"ing-author\"]").InnerText.Trim();
                            string authorContenta = hnChild.SelectSingleNode("//*[@class=\"ing_body\"]").InnerText.Trim();
                            string authorReleaseDatea = hnChild.SelectSingleNode("//*[@class=\"ing_time gray\"]").InnerText.Trim();
                            /**MessageBox.Show("authora----------" + authora);
                            MessageBox.Show("authorContenta----------" + authorContenta);
                            MessageBox.Show("authorReleaseDatea----------" + authorReleaseDatea);*/

                            flashMemorya.userImage = userImageLink;
                            flashMemorya.userAuthor = authora;
                            flashMemorya.userContent = authorContenta;
                            flashMemorya.userReleaseDate = authorReleaseDatea;
                            flashMemoryList.Add(flashMemorya);
                        
                        }
                    }


                    this.listBox1.ItemsSource = flashMemoryList;

                }

            }


        }
        private void OnResultPageLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            _web.LoadCompleted -= OnResultPageLoaded;
            DataLoadedEventArgs loadedArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                try
                {
                    IEnumerable<HtmlNode> trNodes = args.Document.DocumentNode.Descendants("tr");
                    foreach (HtmlNode trNode in trNodes)
                    {
                        MitbbsTopicSearchLink searchLink = new MitbbsTopicSearchLink();
                        searchLink.ParentUrl = _resultUrl;

                        if (searchLink.LoadFromHtml(trNode))
                        {
                            TopicLinks.Insert(0, searchLink);
                        }
                    }

                    IsSearchCompleted = true;
                }
                catch (Exception e)
                {
                    loadedArgs.Error = e;
                }
            }
            else
            {
                loadedArgs.Error = args.Error;
            }

            if (SearchCompleted != null)
            {
                SearchCompleted(this, loadedArgs);
            }
        }
        private void htmlDocCompleteSearch(object sender, HtmlDocumentLoadCompleted e)
        {

            if (e.Error == null)
            {
                HtmlDocument htmlDoc = e.Document;
                if (htmlDoc != null)
                {
                    List<SearchEntity> searchList = new List<SearchEntity>();

                    HtmlNode node = htmlDoc.GetElementbyId("searchResult");

                    HtmlNodeCollection noC = node.SelectNodes("//*[@class=\"searchItem\"]");

                    foreach (HtmlNode h in noC)
                    {
                        HtmlNode hn1 = HtmlNode.CreateNode(h.OuterHtml);
                        SearchEntity search = new SearchEntity();

                        foreach (HtmlNode child in hn1.ChildNodes)
                        {

                            if (child.Attributes["class"] != null && child.Attributes["class"].Value == "searchItemTitle")
                            {
                                HtmlNode hsn = HtmlNode.CreateNode(child.OuterHtml);

                                string searchTitleValue = hsn.SelectSingleNode("//*[@class=\"searchItemTitle\"]").InnerText.Trim();
                                search.searchTitle = searchTitleValue;
                                //MessageBox.Show("searchTitle--------------" + searchTitleValue);
                            }

                            else if (child.Attributes["class"] != null && child.Attributes["class"].Value == "searchCon")
                            {
                                HtmlNode hsn = HtmlNode.CreateNode(child.OuterHtml);


                                string searchConValue = hsn.SelectSingleNode("//*[@class=\"searchCon\"]").InnerText.Trim();
                                search.searchCon = searchConValue;

                                //MessageBox.Show("searchCon--------------" + searchConValue);
                            }

                            else if (child.Attributes["class"] != null && child.Attributes["class"].Value == "searchItemInfo")
                            {


                                HtmlNode hsn = HtmlNode.CreateNode(child.OuterHtml);
                                foreach (HtmlNode searchItemInfoChild in hsn.ChildNodes)
                                {
                                    if (searchItemInfoChild.Attributes["class"] != null && searchItemInfoChild.Attributes["class"].Value == "searchItemInfo")
                                    {
                                        string userName = searchItemInfoChild.SelectSingleNode("//*[@class=\"searchItemInfo-userName\"]").InnerText.Trim();
                                        string publishDate = searchItemInfoChild.SelectSingleNode("//*[@class=\"searchItemInfo-publishDate\"]").InnerText.Trim();
                                        string good = searchItemInfoChild.SelectSingleNode("//*[@class=\"searchItemInfo-good\"]").InnerText.Trim();
                                        string comments = searchItemInfoChild.SelectSingleNode("//*[@class=\"searchItemInfo-comments\"]").InnerText.Trim();
                                        string views = searchItemInfoChild.SelectSingleNode("//*[@class=\"searchItemInfo-views\"]").InnerText.Trim();
                                        string searchInfoValue = userName + publishDate + good + comments + views;
                                        search.searchInfo = searchInfoValue;
                                        //MessageBox.Show("searchInfo--------------" + userName+publishDate+good+comments+views);
                                    }

                                    if (searchItemInfoChild.Attributes["class"] != null && searchItemInfoChild.Attributes["class"].Value == "searchURL")
                                    {
                                        string searchURLValue = searchItemInfoChild.SelectSingleNode("//*[@class=\"searchURL\"]").InnerText.Trim();
                                        search.searchURL = searchURLValue;
                                        //MessageBox.Show("searchInfo--------------" + searchURLValue);
                                    }
                                }



                                //string searchInfo = child.SelectSingleNode("//*[@class=\"searchItemInfo\"]").InnerText;
                                //MessageBox.Show("searchInfo--------------" + searchInfo);
                            }


                        }

                        searchList.Add(search);
                    }


                    this.listBox1.ItemsSource = searchList;

                }

            }

        }
        public void parse_DownloadWikiPageCompleted(Object sender, HtmlDocumentLoadCompleted e)
        {
            if (e != null && e.Document != null && e.Document.DocumentNode != null)
            {
                IList<Block> pageBody = new List<Block>();
                IList<HtmlNode> hnc = e.Document.DocumentNode.DescendantNodes().ToList();

                Paragraph paragraph = new Paragraph();
                Boolean flag = false;
                Boolean flag_table = false;
                foreach (HtmlNode htmlNode in hnc)
                {
                    try
                    {
                        if (flag_table && htmlNode.PreviousSibling != null && htmlNode.PreviousSibling.Name.ToLower() == "table")
                        {
                            flag_table = false;
                        }
                    }
                    catch (Exception err)
                    {
                        Console.Error.Write(err.StackTrace);
                    }
                    if (htmlNode.Name.ToLower() == "div")
                    {
                        foreach (HtmlAttribute att in htmlNode.Attributes)
                        {
                            if (att.Name.ToLower() == "id" && att.Value == "bodyContent")
                            {
                                flag = true;
                                break;
                            }
                            else if (att.Name.ToLower() == "class" && att.Value == "printfooter")
                            {
                                flag = false;
                                goto BreakParseLoop;
                            }
                        }
                    }
                    else if (htmlNode.Name.ToLower() == "table")
                    {
                        flag_table = true;
                    }
                    else if (flag && !flag_table && htmlNode.Name.ToLower() == "h2")
                    {

                            if (!(htmlNode.ParentNode.Name.ToLower() == "div" && htmlNode.ParentNode.Attributes.Count > 0 && htmlNode.ParentNode.Attributes[0].Value == "toctitle"))
                            {
                                if (paragraph.Inlines.Count > 0)
                                {
                                    pageBody.Add(paragraph);
                                    paragraph = new Paragraph();
                                }
                                Bold h2 = new Bold();
                                h2.Inlines.Add(htmlNode.InnerText);
                                Paragraph para = new Paragraph();
                                para.Inlines.Add(h2);
                                para.Inlines.Add(new LineBreak());
                                pageBody.Add(para);
                            }
                    }
                    else if (flag && !flag_table && htmlNode.Name.ToLower() == "h3")
                    {
                        if (paragraph.Inlines.Count > 0)
                        {
                            pageBody.Add(paragraph);
                            paragraph = new Paragraph();
                        }
                        Bold h2 = new Bold();
                        h2.Inlines.Add(htmlNode.InnerText);
                        Paragraph para = new Paragraph();
                        para.Inlines.Add(h2);
                        para.Inlines.Add(new LineBreak());

                        pageBody.Add(para);
                    }
                    else if (flag && !flag_table && htmlNode.Name.ToLower() == "#text")
                    {

                            if (htmlNode.ParentNode.Name.ToLower() != "a" && htmlNode.ParentNode.Name.ToLower() != "b" && htmlNode.ParentNode.Name.ToLower() != "p"
                                    && htmlNode.ParentNode.Name.ToLower() != "i"
                                    && htmlNode.ParentNode.Name.ToLower() != "ul" && htmlNode.ParentNode.Name.ToLower() != "li" && htmlNode.ParentNode.Name.ToLower() != "h2"
                                    && htmlNode.ParentNode.Name.ToLower() != "h3" && htmlNode.ParentNode.Name.ToLower() != "td" && htmlNode.ParentNode.Name.ToLower() != "tr"
                                    && htmlNode.ParentNode.Name.ToLower() != "table" && !(htmlNode.ParentNode.Name.ToLower() == "div" && htmlNode.ParentNode.Attributes.Count > 0 && htmlNode.ParentNode.Attributes[0].Value == "jump-to-nav")
                                    && !(htmlNode.ParentNode.Name.ToLower() == "span" && htmlNode.ParentNode.ParentNode.Name.ToLower() == "td") && !(htmlNode.ParentNode.Name.ToLower() == "span" && htmlNode.ParentNode.ParentNode.Name.ToLower() == "tr")
                                    && !(htmlNode.ParentNode.Name.ToLower() == "span" && htmlNode.ParentNode.ParentNode.Name.ToLower() == "table") && !(htmlNode.ParentNode.Name.ToLower() == "span" && htmlNode.ParentNode.ParentNode.Name.ToLower() == "li")
                                    && !(htmlNode.ParentNode.Name.ToLower() == "span" && htmlNode.ParentNode.ParentNode.Name.ToLower() == "ul")
                                    && !(htmlNode.ParentNode.Name.ToLower() == "i" && htmlNode.ParentNode.ParentNode.Name.ToLower() == "p")
                                    && !(htmlNode.ParentNode.Name.ToLower() == "div" && htmlNode.ParentNode.Attributes.Count > 0 && htmlNode.ParentNode.Attributes[0].Value == "editsection")
                                    && !(htmlNode.ParentNode.Name.ToLower() == "span" && htmlNode.ParentNode.Attributes.Count > 0 && htmlNode.ParentNode.Attributes[0].Name == "class" && htmlNode.ParentNode.Attributes[0].Value == "toctext")
                                    && !(htmlNode.ParentNode.Name.ToLower() == "span" && htmlNode.ParentNode.Attributes.Count > 0 && htmlNode.ParentNode.Attributes[0].Name == "class" && htmlNode.ParentNode.Attributes[0].Value == "tocnumber")
                                    && htmlNode.ParentNode.Name.ToLower() != "script" && htmlNode.ParentNode.Name.ToLower() != "#comment"
                                    && htmlNode.ParentNode.Name.ToLower() != "dd" && htmlNode.ParentNode.Name.ToLower() != "dl")
                            {
                                String str = ConvertWhitespacesToSingleSpaces(htmlNode.InnerText);
                                if (str != " ")
                                {
                                    Run run = new Run();
                                    run.Text = str;
                                    paragraph.Inlines.Add(run);
                                }
                            }

                    }
                    else if (flag && !flag_table && htmlNode.Name.ToLower() == "a")
                    {

                            if (htmlNode.ParentNode.Name != "p" && !(htmlNode.ParentNode.Name.ToLower() == "div" && htmlNode.ParentNode.Attributes.Count > 0 && htmlNode.ParentNode.Attributes[0].Value == "jump-to-nav")
                                && htmlNode.ParentNode.Name.ToLower() != "li" && htmlNode.ParentNode.Name.ToLower() != "ul"
                                && htmlNode.ParentNode.Name.ToLower() != "dd" && htmlNode.ParentNode.Name.ToLower() != "dl"
                                && !(htmlNode.ParentNode.Name.ToLower() == "div" && htmlNode.ParentNode.Attributes.Count > 0 && htmlNode.ParentNode.Attributes[0].Value == "editsection")
                                && !(htmlNode.ParentNode.Name.ToLower() == "i" && htmlNode.ParentNode.ParentNode.Name.ToLower() == "p"))
                            {
                                Boolean image_flag = false;
                                Boolean flag_local = false;
                                Hyperlink hl = new Hyperlink();

                                hl.Inlines.Add(htmlNode.InnerText);
                                foreach (HtmlAttribute att1 in htmlNode.Attributes)
                                {
                                    if (att1.Name.ToLower() == "href")
                                    {
                                        try
                                        {
                                            if (att1.Value.ToCharArray()[0] != '#')
                                            {
                                                hl.NavigateUri = new Uri("/WikiContentPage.xaml?href="+att1.Value, UriKind.Relative);
                                            }
                                            else
                                            {
                                                flag_local = true;
                                            }
                                        }
                                        catch (Exception err)
                                        {
                                            image_flag = true;
                                        }
                                    }
                                    else if (att1.Name.ToLower() == "class" && att1.Value == "image")
                                    {
                                        image_flag = true;
                                    }
                                }
                                if (!image_flag && !flag_local)
                                {
                                   // hl.Click += new RoutedEventHandler(hyperlink_Click);
                                    paragraph.Inlines.Add(hl);
                                }
                                else if (flag_local)
                                {
                                    Run r = new Run();
                                    r.Text = htmlNode.InnerText;
                                    paragraph.Inlines.Add(r);
                                }
                            }

                    }
                    else if (flag && !flag_table && htmlNode.Name.ToLower() == "p")
                    {
                        if (paragraph.Inlines.Count > 0)
                        {
                            pageBody.Add(paragraph);
                            paragraph = new Paragraph();
                        }

                        Paragraph np = new Paragraph();

                        foreach (HtmlNode pc in htmlNode.DescendantNodes().ToList())
                        {
                            if (pc.Name.ToLower() == "a")
                            {
                                if (pc.ParentNode.Name.ToLower() != "i" && pc.ParentNode.Name.ToLower() != "b")
                                {
                                    Boolean image_flag = false;
                                    Boolean flag_local = false;
                                    Hyperlink hl = new Hyperlink();

                                    hl.Inlines.Add(pc.InnerText);

                                    foreach (HtmlAttribute att1 in pc.Attributes)
                                    {
                                        if (att1.Name.ToLower() == "href")
                                        {
                                            try
                                            {
                                                if (att1.Value.ToCharArray()[0] != '#')
                                                {
                                                    hl.NavigateUri = new Uri("/WikiContentPage.xaml?href=" + att1.Value, UriKind.Relative);
                                                }
                                                else
                                                {
                                                    flag_local = true;
                                                }
                                            }
                                            catch (Exception err)
                                            {
                                                image_flag = true;
                                            }
                                        }
                                        else if (att1.Name.ToLower() == "class" && att1.Value == "image")
                                        {
                                            image_flag = true;
                                        }
                                    }
                                    if (!image_flag && !flag_local)
                                    {
                                        np.Inlines.Add(hl);
                                    }
                                    else if (flag_local)
                                    {
                                        Run r = new Run();
                                        r.Text = pc.InnerText;
                                        np.Inlines.Add(r);
                                    }
                                }
                                }
                                else if (pc.Name.ToLower() == "#text")
                                {
                                    if (pc.ParentNode.Name.ToLower() != "a" && pc.ParentNode.Name.ToLower() != "b" && pc.ParentNode.Name.ToLower() != "i")
                                    {
                                        String str = ConvertWhitespacesToSingleSpaces(pc.InnerText);
                                        if (str != " ")
                                        {
                                            Run run = new Run();
                                            run.Text = pc.InnerText;
                                            np.Inlines.Add(run);
                                        }
                                    }
                                }
                                else if (pc.Name.ToLower() == "b")
                                {
                                   Bold b = new Bold();
                                   foreach(HtmlNode n in pc.DescendantNodes().ToList()){
                                        if (n.Name.ToLower() == "#text" && n.ParentNode.Name.ToLower() != "a"){
                                            b.Inlines.Add(n.InnerText);
                                        }
                                        else if (n.Name.ToLower() == "a")
                                        {
                                            Boolean image_flag = false;
                                            Boolean flag_local = false;
                                            Hyperlink hl = new Hyperlink();

                                            hl.Inlines.Add(n.InnerText);

                                            foreach (HtmlAttribute att1 in n.Attributes)
                                            {
                                                if (att1.Name.ToLower() == "href")
                                                {
                                                    try
                                                    {
                                                        if (att1.Value.ToCharArray()[0] != '#')
                                                        {
                                                            hl.NavigateUri = new Uri("/WikiContentPage.xaml?href=" + att1.Value, UriKind.Relative);
                                                        }
                                                        else
                                                        {
                                                            flag_local = true;
                                                        }
                                                    }
                                                    catch (Exception err)
                                                    {
                                                        image_flag = true;
                                                    }
                                                }
                                                else if (att1.Name.ToLower() == "class" && att1.Value == "image")
                                                {
                                                    image_flag = true;
                                                }
                                            }
                                            if (!image_flag && !flag_local)
                                            {
                                                b.Inlines.Add(hl);
                                            }
                                            else
                                            {
                                                b.Inlines.Add(n.InnerText);
                                            }
                                        }
                                    }

                                    np.Inlines.Add(b);
                                }
                                else if (pc.Name.ToLower() == "i")
                                {
                                    Italic i = new Italic();
                                    foreach (HtmlNode n in pc.DescendantNodes().ToList())
                                    {
                                        if (n.Name.ToLower() == "#text" && n.ParentNode.Name.ToLower() != "a")
                                        {
                                            i.Inlines.Add(n.InnerText);
                                        }
                                        else if (n.Name.ToLower() == "a")
                                        {
                                            Boolean image_flag = false;
                                            Boolean flag_local = false;
                                            Hyperlink hl = new Hyperlink();

                                            hl.Inlines.Add(n.InnerText);

                                            foreach (HtmlAttribute att1 in n.Attributes)
                                            {
                                                if (att1.Name.ToLower() == "href")
                                                {
                                                    try
                                                    {
                                                        if (att1.Value.ToCharArray()[0] != '#')
                                                        {
                                                            hl.NavigateUri = new Uri("/WikiContentPage.xaml?href=" + att1.Value, UriKind.Relative);
                                                        }
                                                        else
                                                        {
                                                            flag_local = true;
                                                        }
                                                    }
                                                    catch (Exception err)
                                                    {
                                                        image_flag = true;
                                                    }
                                                }
                                                else if (att1.Name.ToLower() == "class" && att1.Value == "image")
                                                {
                                                    image_flag = true;
                                                }
                                            }
                                            if (!image_flag && !flag_local)
                                            {
                                                i.Inlines.Add(hl);
                                            }
                                            else
                                            {
                                                i.Inlines.Add(n.InnerText);
                                            }
                                        }
                                    }

                                    np.Inlines.Add(i);
                                }
                            }

                            pageBody.Add(np);
                    }
                    else if (flag && !flag_table && htmlNode.Name.ToLower() == "dl")
                    {
                        if (paragraph.Inlines.Count > 0)
                        {
                            pageBody.Add(paragraph);
                            paragraph = new Paragraph();
                        }
                         Paragraph np = new Paragraph();
                         np.TextAlignment = TextAlignment.Justify;

                            foreach (HtmlNode a in htmlNode.DescendantNodes().ToList())
                            {
                                if (a.Name.ToLower() == "a")
                                {
                                    Boolean err_flag = false;
                                    Hyperlink hl = new Hyperlink();

                                    hl.Inlines.Add(a.InnerText);

                                    foreach (HtmlAttribute att1 in a.Attributes)
                                    {
                                        if (att1.Name.ToLower() == "href")
                                        {
                                            try
                                            {
                                                if (att1.Value.ToCharArray()[0] != '#')
                                                {
                                                    hl.NavigateUri = new Uri("/WikiContentPage.xaml?href="+att1.Value, UriKind.Relative);
                                                }
                                                else
                                                {
                                                    err_flag = true;
                                                }
                                            }
                                            catch (Exception err)
                                            {
                                                err_flag = true;
                                            }
                                            break;
                                        }
                                    }
                                    if (!err_flag)
                                    {
                                        np.Inlines.Add(hl);
                                    }
                                    else
                                    {
                                        Run r = new Run();
                                        r.Text = a.InnerText;
                                        np.Inlines.Add(r);
                                    }
                                }
                                else if (a.Name.ToLower() == "dd")
                                {
                                    try
                                    {
                                        if (a.PreviousSibling != null & a.PreviousSibling.Name.ToLower() == "dd")
                                        {
                                            np.Inlines.Add(new LineBreak());
                                        }
                                    }
                                    catch (Exception err)
                                    {
                                        Console.Error.Write(err.StackTrace);
                                    }
                                }
                                else if (a.Name.ToLower() == "b")
                                {
                                    Bold b = new Bold();
                                    b.Inlines.Add(a.InnerText);
                                    np.Inlines.Add(b);
                                }
                                else if (a.Name.ToLower() == "i")
                                {
                                    Italic i = new Italic();
                                    i.Inlines.Add(a.InnerText);
                                    np.Inlines.Add(i);
                                }
                                else if (a.Name.ToLower() == "#text")
                                {
                                    if (a.ParentNode.Name.ToLower() != "a" && a.ParentNode.Name.ToLower() != "b" && a.ParentNode.Name.ToLower() != "i")
                                    {

                                        String str = ConvertWhitespacesToSingleSpaces(a.InnerText);
                                        if (str != " ")
                                        {
                                            Italic i = new Italic();
                                            i.Inlines.Add(str);
                                            np.Inlines.Add(i);
                                        }
                                    }

                                }
                            }

                            np.Inlines.Add(new LineBreak());
                            pageBody.Add(np);
                    }
                    else if (flag && !flag_table && htmlNode.Name.ToLower() == "ul")
                    {
                        if (paragraph.Inlines.Count > 0)
                        {
                            pageBody.Add(paragraph);
                            paragraph = new Paragraph();
                        }

                        if (htmlNode.ParentNode.Name.ToLower() != "td" && htmlNode.ParentNode.Name.ToLower() != "tr" && htmlNode.ParentNode.Name.ToLower() != "table"
                              && !(htmlNode.ParentNode.Name.ToLower() == "ul" && htmlNode.ParentNode.ParentNode != null && htmlNode.ParentNode.ParentNode.Name.ToLower() == "td")
                              && !(htmlNode.ParentNode.Name.ToLower() == "li" && htmlNode.ParentNode.ParentNode != null && htmlNode.ParentNode.ParentNode.Name.ToLower() == "ul"
                              && htmlNode.ParentNode.ParentNode.ParentNode.Name.ToLower() == "td"))
                        {
                            Paragraph np = new Paragraph();
                            foreach (HtmlNode a in htmlNode.DescendantNodes().ToList())
                            {
                                if (a.Name.ToLower() == "a")
                                {
                                    Boolean err_flag = false;
                                    Hyperlink hl = new Hyperlink();

                                    hl.Inlines.Add(a.InnerText);
                                    foreach (HtmlAttribute att1 in a.Attributes)
                                    {
                                        if (att1.Name.ToLower() == "href")
                                        {
                                            try
                                            {
                                                if (att1.Value.ToCharArray()[0] != '#')
                                                {
                                                    hl.NavigateUri = new Uri("/WikiContentPage.xaml?href=" + att1.Value, UriKind.Relative);

                                                }
                                                else
                                                {
                                                    err_flag = true;
                                                }
                                            }
                                            catch (Exception err)
                                            {
                                                err_flag = true;
                                            }
                                            break;
                                        }
                                    }
                                    if (!err_flag)
                                    {
                                        np.Inlines.Add(hl);
                                    }
                                    else
                                    {
                                        Run r = new Run();
                                        r.Text = a.InnerText;
                                        np.Inlines.Add(r);
                                    }
                                }
                                else if (a.Name.ToLower() == "li")
                                {
                                    try
                                    {
                                        if (a.PreviousSibling != null & a.PreviousSibling.Name.ToLower() == "li")
                                        {
                                            np.Inlines.Add(new LineBreak());
                                        }
                                    }
                                    catch (Exception err)
                                    {
                                        Console.Error.Write(err.StackTrace);
                                    }
                                    Bold b = new Bold();
                                    b.Inlines.Add("- ");
                                    np.Inlines.Add(b);
                                }
                                else if (a.Name.ToLower() == "b")
                                {
                                    Bold b = new Bold();
                                    b.Inlines.Add(a.InnerText);
                                    np.Inlines.Add(b);
                                }
                                else if (a.Name.ToLower() == "i")
                                {
                                    Italic i = new Italic();
                                    i.Inlines.Add(a.InnerText);
                                    np.Inlines.Add(i);
                                }
                                else if (a.Name.ToLower() == "#text")
                                {
                                    if (a.ParentNode.Name.ToLower() != "a" && a.ParentNode.Name.ToLower() != "b" && a.ParentNode.Name.ToLower() != "i")
                                    {

                                        String str = ConvertWhitespacesToSingleSpaces(a.InnerText);
                                        if (str != " ")
                                        {
                                            Run run = new Run();
                                            run.Text = str;
                                            np.Inlines.Add(run);
                                        }
                                    }

                                }
                            }

                            np.Inlines.Add(new LineBreak());
                            pageBody.Add(np);

                        }

                    }
                    else if (htmlNode.Name.ToLower() == "h1")
                    {
                        foreach (HtmlAttribute att2 in htmlNode.Attributes)
                        {
                            if (att2.Name.ToLower() == "class" && att2.Value == "firstHeading")
                            {
                                PageTitle.Text = htmlNode.InnerText;
                            }
                        }
                    }
                }
            BreakParseLoop:

                if (paragraph != null && paragraph.Inlines.Count > 0)
                {
                    pageBody.Add(paragraph);
                }
                foreach (Block b in pageBody)
                {
                    RichTextBox rtb = new RichTextBox();
                    rtb.IsReadOnly = true;
                    rtb.VerticalAlignment = VerticalAlignment.Top;
                    rtb.Blocks.Add(b);
                    PageBody.Children.Add(rtb);

                }
                PageBody.InvalidateArrange();
                PageBody.InvalidateMeasure();
                scrollViewer1.InvalidateArrange();
                scrollViewer1.InvalidateMeasure();
                scrollViewer1.InvalidateScrollInfo();
            } else {
                this.NavigationService.Navigate(new Uri("/ContentLoadError.xaml?href="+CurrentPage, UriKind.Relative));
            }
            progress.Visibility = Visibility.Collapsed;
        }
Example #22
0
        public void parse_DownloadSEPageCompleted(Object sender, HtmlDocumentLoadCompleted e)
        {
            if (e != null && e.Document != null && e.Document.DocumentNode != null)
            {
                IList<Block> pageBody = new List<Block>();
                IList<HtmlNode> hnc = e.Document.DocumentNode.DescendantNodes().ToList();

                Paragraph paragraph = new Paragraph();

                foreach (HtmlNode htmlNode in hnc)
                {
                    if (htmlNode.Name.ToLower() == "pre")
                    {
                        foreach (HtmlNode node in htmlNode.DescendantNodes().ToList())
                        {
                            if (paragraph.Inlines.Count > 0)
                            {
                                pageBody.Add(paragraph);
                                paragraph = new Paragraph();
                            }

                            if (node.Name.ToLower() == "#text" && node.ParentNode.Name.ToLower() != "a")
                            {
                                String str = ConvertWhitespacesToSingleSpaces(node.InnerText);
                                if (str != " ")
                                {
                                        string[] str1 = str.Split(new Char[]{'\n'});
                                        foreach(string s in str1)
                                        {
                                            if (s != " " && s != "")
                                            {

                                                Run run = new Run();
                                                run.Text = s;
                                                paragraph.Inlines.Add(run);
                                                paragraph.Inlines.Add(new LineBreak());
                                                pageBody.Add(paragraph);
                                                paragraph = new Paragraph();
                                            }
                                            else
                                            {
                                               // paragraph.Inlines.Add(new LineBreak());
                                            }
                                        }
                                }
                            }
                            else if (node.Name.ToLower() == "a" && !node.InnerText.Contains("[log in to unmask]"))
                            {
                                Hyperlink hl = new Hyperlink();
                                hl.Inlines.Add(node.InnerText);
                                foreach (HtmlAttribute att1 in node.Attributes)
                                {
                                    if (att1.Name.ToLower() == "href")
                                    {
                                        try
                                        {
                                            hl.NavigateUri = new Uri("/SEWorldPage.xaml?external=true&href="+Uri.EscapeUriString(att1.Value), UriKind.Relative);
                                        }
                                        catch (Exception err)
                                        {
                                        }
                                    }
                                }
                                paragraph.Inlines.Add(hl);
                                paragraph.Inlines.Add(new LineBreak());
                            }
                        }
                        break;
                    }
                }

                if (paragraph != null && paragraph.Inlines.Count > 0)
                {
                    pageBody.Add(paragraph);
                }
                foreach (Block b in pageBody)
                {
                    RichTextBox rtb = new RichTextBox();
                    rtb.IsReadOnly = true;
                    rtb.VerticalAlignment = VerticalAlignment.Top;
                    rtb.Blocks.Add(b);
                    PageBody.Children.Add(rtb);

                }
                PageBody.InvalidateArrange();
                PageBody.InvalidateMeasure();
                scrollViewer1.InvalidateArrange();
                scrollViewer1.InvalidateMeasure();
                scrollViewer1.InvalidateScrollInfo();

            }
            Loading.Visibility = Visibility.Collapsed;
        }
        private void htmlDocCompleteQuestion(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Error == null)
            {
                HtmlDocument htmlDoc = e.Document;
                if (htmlDoc != null)
                {

                    List<Question> listContent = new List<Question>();

                    HtmlNode node = htmlDoc.GetElementbyId("main");
                    HtmlNode hn = HtmlNode.CreateNode(node.OuterHtml);
                    HtmlNodeCollection noC = hn.SelectNodes("//*[@class=\"one_entity\"]");



                    foreach (HtmlNode h in noC)
                    {

                        HtmlNode hn1 = HtmlNode.CreateNode(h.OuterHtml);


                        //MessageBox.Show("hn1------"+hn1.InnerHtml);
                        foreach (HtmlNode child in hn1.ChildNodes)
                        {

                            Question question = new Question();
                            /**if (child.Attributes["class"] == null || child.Attributes["class"].Value != "answercount")
                                continue;
                                
                                HtmlNode hsn = HtmlNode.CreateNode(child.OuterHtml);
                                string answerCount = hsn.InnerText.Trim();
                                MessageBox.Show(answerCount.Substring(0,answerCount.IndexOf("回答数")).Trim());*/


                            if (child.Attributes["class"] != null && child.Attributes["class"].Value == "answercount")
                            {
                                HtmlNode hsn = HtmlNode.CreateNode(child.OuterHtml);
                                string answerCount = hsn.InnerText.Trim();
                                //MessageBox.Show(answerCount.Substring(0, answerCount.IndexOf("回答数")).Trim());//回答人数


                            }
                            else if (child.Attributes["class"] != null && child.Attributes["class"].Value == "news_item")
                            {
                                HtmlNode hsn = HtmlNode.CreateNode(child.OuterHtml);
                                HtmlNode gold = hsn.SelectSingleNode("//*[@class=\"gold\"]");
                                string goldCount = "";
                                if (gold != null)
                                {
                                    goldCount = gold.InnerText.Trim();
                                    //MessageBox.Show("gold----------" + gold.InnerText.Trim());  //悬赏金币
                                }
                                else
                                {
                                    goldCount = "0";
                                    //MessageBox.Show("gold----------0");                   //悬赏金币 空则为0
                                }

                                IEnumerable<HtmlNode> nodeList = hsn.SelectSingleNode("//*[@class=\"news_entry\"]").Descendants("a");
                                string title = "";
                                string titlelink = "";
                                foreach (HtmlNode item in nodeList)
                                {
                                    title = item.InnerHtml.Trim();
                                    titlelink = item.GetAttributeValue("href", "");

                                    //MessageBox.Show("out--------" + item.InnerHtml.Trim());  //问题标题
                                }


                                HtmlNode questionIntroduce = hsn.SelectSingleNode("//*[@class=\"news_summary\"]");
                                HtmlNode questionAuthor = hsn.SelectSingleNode("//*[@class=\"news_contributor\"]");
                                HtmlNode questionPushDate = hsn.SelectSingleNode("//*[@class=\"date\"]");

                                IEnumerable<HtmlNode> imgAuthorList = hsn.SelectSingleNode("//*[@class=\"author\"]").Descendants("img");

                                foreach (HtmlNode imgAuthor in imgAuthorList)
                                {

                                    string userImage = imgAuthor.GetAttributeValue("src", "");
                                    if (userImage.IndexOf(".gif") > -1)
                                    {
                                        question.questionUserImage = "/images/UserNo-Frame.png";
                                    }
                                    else
                                    {
                                        question.questionUserImage = userImage;
                                    }

                                    //MessageBox.Show("out--------" + item.InnerHtml.Trim());  //问题标题
                                }



                                string introduce = questionIntroduce.InnerText.Trim();
                                string author = questionAuthor.InnerText.Trim();
                                string date = questionPushDate.InnerText.Trim();

                                question.questionTitle = title;
                                question.questionLink = titlelink;
                                question.questionIntroduce = introduce;
                                question.questionInfo = author + "  " + date;
                                question.questionGoldImage = "/images/gold.png";
                                question.questionGoldCount = goldCount;

                                listContent.Add(question);
                                //MessageBox.Show("questionIntroduce------------" + questionIntroduce.InnerText.Trim());   //问题简介
                                //MessageBox.Show("news_footer----------" + questionAuthor.InnerText.Trim());    //提问者
                                //MessageBox.Show("date----------" + questionPushDate.InnerText.Trim());         //发布时间

                                //string answerCount = hsn.InnerText.Trim();



                            }
                            else
                            {
                                continue;
                            }




                        }


                        //HtmlNode newnode = hn.SelectSingleNode("/div/div/div[3]");

                        /**IEnumerable<HtmlNode> nodeList = node.Ancestors();  //获取该元素所有的父节点的集合
                        foreach (HtmlNode item in nodeList)
                        {
                            Console.Write(item.Name + " ");   //输出 div div body html #document
                        }*/


                    }

                    this.listBox2.ItemsSource = listContent;


                }

            }

        }
Example #24
0
        public void DownloadStringCompleted(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Document != null)
            {
                HtmlNodeCollection table = e.Document.DocumentNode.SelectNodes("//*[@class='consulta ']");

                var appBar = table[2].InnerHtml.Replace(" colspan=\"3\"", "").Replace(" align=\"center\"", "").Replace(" class=\"rowTable\"", "").Replace(" style=\"width:50px\"", "").Replace(" style=\"width:400px\"", "").Replace(" class=\"corUm\" align=\"right\"", "").Replace("&nbsp;", "");

                appBar = appBar.Insert(0, "<xml>").Insert(appBar.Length - 1, "</xml>");

                var tableSaldo = table[3].InnerHtml.Replace(" class=\"rowTable\"", "")
                  .Replace(" class=\"corUm fontWeightDois\"", "")
                  .Replace(" align=\"right\"", "")
                  .Replace(" class=\"corUm fontWeightDois\"", "")
                  .Replace(" style=\"width:80px\"", "")
                  .Replace("dispon&iacute;vel:", "");

                if (appBar.Contains("N&atilde;o h&aacute; movimenta&ccedil;&otilde;es para o per&iacute;odo selecionado."))
                {
                    if (appBar.Contains("N&atilde;o h&aacute; movimenta&ccedil;&otilde;es para o per&iacute;odo selecionado."))
                    {
                        foreach (var item in table.Descendants("td"))
                        {
                            var text = item.InnerHtml;

                            if (item.XPath == "/html[1]/body[1]/table[1]/tr[1]/td[2]")
                            {
                                info.DataConsulta = item.InnerHtml;
                            }
                            else if (item.XPath == "/html[1]/body[1]/table[1]/tr[3]/td[2]")
                            {
                                info.DataUltimoBeneficioDataBeneficio = item.InnerHtml;
                            }
                            else if (item.XPath == "/html[1]/body[1]/table[1]/tr[3]/td[3]")
                            {
                                info.ValorUltimoBeneficio = item.InnerHtml;
                            }

                        }

                        xDoc = XDocument.Parse(tableSaldo);
                        tbtMessage.Visibility = Visibility.Visible;
                    }
                }
                else
                {

                    // dispon&iacute;vel:
                    xDoc = XDocument.Parse(appBar);
                    XDocument xDocSaldo = XDocument.Parse(tableSaldo);

                    foreach (var item in xDocSaldo.Root.Nodes())
                    {
                        if (((System.Xml.Linq.XElement)(item)).Value.ToString().Contains("$"))
                        {
                            info.getSaldo = ((System.Xml.Linq.XElement)(item)).Value.ToString();
                            //MessageBox.Show(((System.Xml.Linq.XElement)(item)).Value.ToString());
                        }

                    }

                    foreach (var item in table.Descendants("td"))
                    {

                        var teste = item.InnerHtml;
                        //data ultima disponibilizacao
                        if (item.XPath == "/html[1]/body[1]/table[1]/tr[3]/td[2]")
                        {
                            info.DataUltimoBeneficioDataBeneficio = item.InnerHtml;
                            //MessageBox.Show(item.InnerHtml);
                        }//valor disponibilizado
                        else if (item.XPath == "/html[1]/body[1]/table[1]/tr[3]/td[3]")
                        {
                            info.ValorUltimoBeneficio = item.InnerHtml;
                            //MessageBox.Show(item.InnerHtml);
                        }///data proximo
                        else if (item.XPath == "/html[1]/body[1]/table[1]/tr[4]/td[2]")
                        {
                            // MessageBox.Show(item.InnerHtml);
                            info.DataProximoBeneficio = item.InnerHtml;
                            // MessageBox.Show(item.InnerHtml);
                        }
                        /// valor proximo
                        else if (item.XPath == "/html[1]/body[1]/table[1]/tr[4]/td[3]")
                        {
                            info.ValorProximoBeneficio = item.InnerHtml;
                            // MessageBox.Show(item.InnerHtml);
                        }
                        else if (item.XPath == "/html[1]/body[1]/table[1]/tr[1]/td[2]")
                        {
                            info.DataConsulta = item.InnerHtml.Substring(0, 10);
                        }
                        else if (item.XPath == "/html[1]/body[1]/table[1]/tr[2]/td[2]")
                        {
                            info.NumeroCartao = item.InnerHtml;
                        }

                    }

                    List<VisaValeGastos> c = new List<VisaValeGastos>();

                    foreach (var item in xDoc.Root.Nodes())
                    {
                        c.Add(new VisaValeGastos() { Local = ((System.Xml.Linq.XElement)(item)).Value.ToString().Remove(0, 5).Remove(((System.Xml.Linq.XElement)(item)).Value.IndexOf("$") - 6), Data = ((System.Xml.Linq.XElement)(item)).Value.ToString().Substring(0, 5), Valor = ((System.Xml.Linq.XElement)(item)).Value.Substring(((System.Xml.Linq.XElement)(item)).Value.IndexOf("R$")) });
                    }

                    c.Reverse();

                    listaGastos.ItemsSource = c;
                    listaGastos.Foreground = new SolidColorBrush(Colors.Black);
                    var coldata = listaGastos.Columns["Data"];
                    coldata.Width = new GridLength(80);
                    var colLocal = listaGastos.Columns["Local"];
                    colLocal.Width = new GridLength(260);
                    var colValor = listaGastos.Columns["Valor"];
                    colValor.Width = new GridLength(140);

                    Dispatcher.BeginInvoke(() =>
                    {
                        Save();
                    });
                }

                tblDate.DataContext = info.DataUltimoBeneficioDataBeneficio;
                tblText.DataContext = "Último benefício";
                tblLast.DataContext = info.ValorUltimoBeneficio.Substring(6);

                tblDateNext.DataContext = info.DataProximoBeneficio != null ? info.DataProximoBeneficio : "N/D";
                tblTextNext.DataContext = "Próximo benefício";
                tblLastNext.DataContext = info.ValorProximoBeneficio != null ? info.ValorProximoBeneficio.Substring(6) : "N/D";

                tblTextSaldo.DataContext = "Saldo atual";
                tblSaldo.DataContext = info.getSaldo != null ? info.getSaldo : xDoc.Root.Value.Replace("Saldo ", "");

                tblDataPesquisa.DataContext = "Data da pesquisa: " + info.DataConsulta;
                title.DataContext = "Extrato";
                title.FontSize = 30;

                ApplicationBar.Buttons.RemoveAt(0);

                this.ApplicationBar = new ApplicationBar();

                var newButton = new ApplicationBarIconButton();
                newButton.IconUri = new Uri("/Resourses/appbar.refresh.png", UriKind.Relative);
                newButton.Text = "update";
                newButton.Click += UpdateServer;

                this.ApplicationBar.Buttons.Add(newButton);
                stackPanel.Visibility = Visibility.Collapsed;
                this.progressBar.IsIndeterminate = false;

            }
            else
            {
                if (this.progressBar.IsIndeterminate)
                {
                    using (var ctx = new visaValeDataContext(conn))
                    {
                        if (ctx.DatabaseExists())
                        {
                            var confirm = MessageBox.Show("Não foi possível obter conexão de dados! \n Deseja continuar com as informações da sua última pesquisa ?", "", MessageBoxButton.OKCancel);

                            if (confirm.ToString() == "OK")
                            {
                                foreach (var item in ctx.VisaVales)
                                {
                                    if (item.Id == 1)
                                    {
                                        tblDate.DataContext = item.DataUltimoBeneficioDataBeneficio;

                                        tblLast.DataContext = item.ValorUltimoBeneficio.Substring(6);

                                        tblDateNext.DataContext = item.DataProximoBeneficio != null ? item.DataProximoBeneficio : "N/D";
                                        tblTextNext.DataContext = "Próximo benefício";
                                        tblLastNext.DataContext = item.ValorProximoBeneficio != null ? item.ValorProximoBeneficio.Substring(6) : "N/D";

                                        tblTextSaldo.DataContext = "Saldo atual";
                                        tblSaldo.DataContext = item.GetSaldo;

                                        tblDataPesquisa.DataContext = "Data da pesquisa: " + item.DataConsulta;
                                        title.DataContext = "Extrato";
                                        title.FontSize = 30;

                                        ApplicationBar.Buttons.RemoveAt(0);

                                        this.ApplicationBar = new ApplicationBar();

                                        var newButton = new ApplicationBarIconButton();
                                        newButton.IconUri = new Uri("/Resourses/appbar.refresh.png", UriKind.Relative);
                                        newButton.Text = "update";
                                        newButton.Click += UpdateServer;

                                        this.ApplicationBar.Buttons.Add(newButton);
                                        stackPanel.Visibility = Visibility.Collapsed;
                                        this.progressBar.IsIndeterminate = false;

                                        List<VisaValeGastos> listaGastosVisa = new List<VisaValeGastos>();

                                        foreach (var item2 in item.VisaValeGastos)
                                        {
                                            listaGastosVisa.Add(new VisaValeGastos { Data = item2.Data, Local = item2.Local, Valor = item2.Valor });
                                        }

                                        listaGastosVisa.Reverse();

                                        listaGastos.ItemsSource = listaGastosVisa;
                                        listaGastos.Foreground = new SolidColorBrush(Colors.Black);
                                        var coldata = listaGastos.Columns["Data"];
                                        coldata.Width = new GridLength(80);
                                        var colLocal = listaGastos.Columns["Local"];
                                        colLocal.Width = new GridLength(260);
                                        var colValor = listaGastos.Columns["Valor"];
                                        colValor.Width = new GridLength(140);

                                        break;
                                    }
                                }
                            }
                        }
                        else if (!ctx.DatabaseExists())
                        {
                            MessageBox.Show("Não foi possível estabelecer conexão com o servidor de dados!");
                            NavigationService.GoBack();
                        }
                    }
                }
            }

            this.progressBar.IsIndeterminate = false;
            stackPanel.Visibility = Visibility.Collapsed;
        }
        private void DownloadCompleted(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Error == null)
            {
                HtmlDocument doc = e.Document;
                if (doc != null)
                {
                    string courseInfo = doc.DocumentNode.Element("html").
                        Element("body").
                        Elements("div").ElementAt(3).
                        Elements("table").ElementAt(0).
                        Elements("tr").ElementAt(0).
                        Element("th").InnerText;

                    string capacity = doc.DocumentNode.Element("html").
                        Element("body").
                        Elements("div").ElementAt(3).
                        Elements("table").ElementAt(0).
                        Elements("tr").ElementAt(1).
                        Element("td").
                        Element("table").
                        Element("tr").
                        Element("tr").
                        Elements("td").ElementAt(0).InnerText;

                    string actual = doc.DocumentNode.Element("html").
                        Element("body").
                        Elements("div").ElementAt(3).
                        Elements("table").ElementAt(0).
                        Elements("tr").ElementAt(1).
                        Element("td").
                        Element("table").
                        Element("tr").
                        Element("tr").
                        Elements("td").ElementAt(1).InnerText;

                    string remaining = doc.DocumentNode.Element("html").
                        Element("body").
                        Elements("div").ElementAt(3).
                        Elements("table").ElementAt(0).
                        Elements("tr").ElementAt(1).
                        Element("td").
                        Element("table").
                        Element("tr").
                        Element("tr").
                        Elements("td").ElementAt(2).InnerText;

                    capacityTextBlock.Visibility = System.Windows.Visibility.Visible;
                    actualTextBlock.Visibility = System.Windows.Visibility.Visible;
                    remainingTextBlock.Visibility = System.Windows.Visibility.Visible;
                    addBookmarkButton.Visibility = System.Windows.Visibility.Visible;
                    textBlock2.Visibility = System.Windows.Visibility.Visible;
                    textBlock3.Visibility = System.Windows.Visibility.Visible;
                    textBlock4.Visibility = System.Windows.Visibility.Visible;

                    courseTextBlock.Text = courseInfo;
                    capacityTextBlock.Text = capacity;
                    actualTextBlock.Text = actual;
                    remainingTextBlock.Text = remaining;

                }
            }
        }
Example #26
0
        protected void OnUrlLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            bool isHomeLoaded = false;
            _web.LoadCompleted -= OnUrlLoaded;

            DataLoadedEventArgs loadedEventArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                isHomeLoaded = LoadFromHtml(args.Document.DocumentNode, loadedEventArgs);
            }
            else
            {
                loadedEventArgs.Error = args.Error;
            }

            if (isHomeLoaded && LoadClubHome)
            {
                ClubHome.LoadFromUrl(_web, App.Settings.BuildUrl(MitbbsClubHome.ClubHomeUrl));
                return;
            }
            else
            {
                IsLoaded = isHomeLoaded;
                TriggerHomeLoaded(loadedEventArgs);
            }
        }
Example #27
0
        protected virtual void OnUrlLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            DataLoadedEventArgs loadedEventArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                try
                {
                    if (!LoadFromHtml(args.Document.DocumentNode, loadedEventArgs))
                    {
                        if (_alternateUrl != null)
                        {
                            Url = _alternateUrl;
                            _web.LoadAsync(Url);
                            return;
                        }
                    }
                    else if (_pageToLoad >= 1 && PageIndex >= 1 && _pageToLoad != PageIndex)
                    {
                        int pageNum = _pageToLoad;
                        if (_pageToLoad == int.MaxValue)
                        {
                            pageNum = LastPageIndex;
                        }

                        String newUrl;
                        if (PageLinks.TryGetValue(pageNum, out newUrl))
                        {
                            Url = newUrl;
                            ClearContent();
                            _web.LoadAsync(Url);
                            return;
                        }
                    }
                }
                catch (Exception e)
                {
                    loadedEventArgs.Error = e;
                }
            }
            else
            {
                loadedEventArgs.Error = args.Error;
            }

            _web.LoadCompleted -= OnUrlLoaded;

            if (_alternateUrl == null)
            {
                TriggerLoadedEvent(loadedEventArgs);
            }
        }
        private void OnSearchPageLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            _web.LoadCompleted -= OnSearchPageLoaded;

            DataLoadedEventArgs loadedArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                try
                {
                    IEnumerable<HtmlNode> formNodes = args.Document.DocumentNode.Descendants("form");
                    foreach (HtmlNode formNode in formNodes)
                    {
                        if ((formNode.Attributes["name"] != null) && (formNode.Attributes["name"].Value == "form_query"))
                        {
                            _web.FormElements = new FormElementCollection(formNode.ParentNode);
                            _resultUrl = HtmlUtilities.GetAbsoluteUrl(_searchUrl, formNode.Attributes["action"].Value);

                            _isSearchPageLoaded = true;
                        }
                    }
                }
                catch (Exception e)
                {
                    loadedArgs.Error = e;
                }
            }
            else
            {
                loadedArgs.Error = args.Error;
            }

            if (_isSearchPageLoaded)
            {
                LoadResultPage();
            }
            else
            {
                if (SearchCompleted != null)
                {
                    SearchCompleted(this, loadedArgs);
                }
            }
        }
Example #29
0
        private void OnUrlLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            _web.LoadCompleted -= OnUrlLoaded;
            DataLoadedEventArgs loadedEventArgs = new DataLoadedEventArgs();
            loadedEventArgs.Error = args.Error;

            if (args.Document != null)
            {
                try
                {
                    LoadFromHtml(args.Document.DocumentNode);
                }
                catch (Exception e)
                {
                    loadedEventArgs.Error = e;
                }
            }

            if (MailboxLoaded != null)
            {
                MailboxLoaded(this, loadedEventArgs);
            }
        }
 private void OnLoadCompleted(HtmlDocumentLoadCompleted htmlDocumentLoadCompleted)
 {
     if (LoadCompleted != null)
         LoadCompleted(this, htmlDocumentLoadCompleted);
 }
Example #31
0
        private void OnUrlLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            _web.LoadCompleted -= OnUrlLoaded;

            DataLoadedEventArgs loadedEventArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                LoadFromHtml(args.Document.DocumentNode, loadedEventArgs);
            }
            else
            {
                loadedEventArgs.Error = args.Error;
            }

            if (BoardGroupLoaded != null)
            {
                BoardGroupLoaded(this, loadedEventArgs);
            }
        }