private void LoadData() { try { // CheckConnect Internet if (SEDInternetConnection.CheckConnectTimeOutWait(splashScreenManagerWebPage) == false) return; var url = gvShowCateInfor.GetRowCellValue(_index, "Link").ToString(); splashScreenManagerWebPage.ShowWaitForm(); splashScreenManagerWebPage.SetWaitFormCaption(SEDConst.SET_PLEASE_WAIT); Task.Factory.StartNew(() => { var xDoc = XDocument.Load(url); var xDataRss = xDoc.Descendants("item"); var lstFeeds = new List<Feeds>(); foreach (var nodeItem in xDataRss) { try { var xElement = nodeItem.Element("title"); if (xElement != null) { var feed = new Feeds { Title = xElement.Value.ReplaceNew().Trim(), Link = nodeItem.Element("link").Value.Trim(), PubDate = nodeItem.Element("pubDate").Value }; lstFeeds.Add(feed); } } catch (NullReferenceException) { } } return lstFeeds; }).ContinueWith(pre => { gcShowFeeds.DataSource = pre.Result; splashScreenManagerWebPage.CloseWaitForm(); }, TaskScheduler.FromCurrentSynchronizationContext()); //lblChildCateDynamic.Text = gvShowCateInfor.GetRowCellValue(_index, "TopicName").ToString(); //lblTotalChildDynamic.Text = lstFeeds.Count.ToString(); } catch (NotSupportedException) { splashScreenManagerWebPage.CloseWaitForm(); SEDFuncCall.MessageWarning(SEDConst.MESSAGE_LINK_INVALID, SEDConst.TITLE_WARNING); } catch (Exception ex) { splashScreenManagerWebPage.CloseWaitForm(); SEDFuncCall.MessageWarning(ex.Message, SEDConst.TITLE_WARNING); } }
private void LoadData(string url) { #region Pending //var htmlDocument = ResultWebClient("http://www.24h.com.vn/upload/rss/tintuctrongngay.rss"); //List<Feeds> query2 = htmlDocument.DocumentNode.SelectNodes("//item") // .Select(a => new Feeds // { // Title = a.Element("title").InnerText, // //Link = a.Element("link").InnerText // //PubDate = a.Element("pubDate").InnerText, // Description = a.Element("description").InnerText // }).ToList(); //var query = new List<Feeds>(); //var test = htmlDocument.DocumentNode.SelectNodes("//item"); //foreach (var item in test) //{ // var x = item.Element("title").InnerText; // query.Add(new Feeds { Title = x }); //} //================= Not Use Bescause Ignore Exception //var lstFeeds = xDoc.Descendants("item").Select(a => new Feeds //{ // Title = a.Element("title").Value, // Link = a.Element("link").Value, // PubDate = a.Element("pubDate").Value, // Image = SplitSrc(a.Element("description").Value), // Description = Description(a.Element("description").Value) //}); //gcShowFeeds.DataSource = query; #endregion try { // CheckConnect Internet var checkConnect = SEDInternetConnection.CheckConnectTimeOutWait(splashScreenManagerWebPage); if (checkConnect == false) return; splashScreenManagerWebPage.ShowWaitForm(); splashScreenManagerWebPage.SetWaitFormCaption(SEDConst.SET_PLEASE_WAIT); var xDoc = XDocument.Load(url); var xDataRss = xDoc.Descendants("item"); var lstFeeds = new List<Feeds>(); foreach (var nodeItem in xDataRss) { try { var xElement = nodeItem.Element("title"); if (xElement != null) { var feed = new Feeds { Title = xElement.Value.ReplaceNew().Trim(), Link = nodeItem.Element("link").Value.Trim(), PubDate = nodeItem.Element("pubDate").Value, Image = SplitSrc(nodeItem.Element("description").Value), Description = Description(nodeItem.Element("description").Value) }; lstFeeds.Add(feed); } } catch (NullReferenceException) { } } gcShowFeeds.DataSource = lstFeeds; lblChildCateDynamic.Text = gvShowCateInfor.GetRowCellValue(_index, "TopicName").ToString(); lblTotalChildDynamic.Text = lstFeeds.Count.ToString(); splashScreenManagerWebPage.CloseWaitForm(); } catch (NotSupportedException) { splashScreenManagerWebPage.CloseWaitForm(); SEDFuncCall.MessageWarning(SEDConst.MESSAGE_LINK_INVALID, SEDConst.TITLE_WARNING); } catch (Exception ex) { splashScreenManagerWebPage.CloseWaitForm(); SEDFuncCall.MessageWarning(ex.Message, SEDConst.TITLE_WARNING); } }
private void btnParseData_Click(object sender, EventArgs e) { if (gvListRss.RowCount < 1) { SEDFuncCall.MessageWarning("There is no data to be analyzed!", SEDConst.TITLE_WARNING); return; } // CheckConnect Internet var checkConnect = SEDInternetConnection.CheckConnectTimeOutWait(splashScreenManagerMultiplePage); if (checkConnect == false) return; splashScreenManagerMultiplePage.ShowWaitForm(); splashScreenManagerMultiplePage.SetWaitFormDescription(SEDConst.SET_PLEASE_WAIT); var stw = new Stopwatch(); stw.Start(); var lstFeeds = new List<Feeds>(); var intLinkFail = 0; for (var i = 0; i < gvListRss.RowCount; i++) { try { var xDoc = XDocument.Load(gvListRss.GetRowCellValue(i, "Link").ToString()); var idSet = Convert.ToInt32(gvListRss.GetRowCellValue(i, "IdSet")); var xDataRss = xDoc.Descendants("item"); foreach (var nodeItem in xDataRss) { try { var feed = new Feeds { IdRssPage = idSet, Title = nodeItem.Element("title").Value.ReplaceNew(), Link = nodeItem.Element("link").Value, PubDate = nodeItem.Element("pubDate").Value, Image = SplitSrc(nodeItem.Element("description").Value), Description = Description(nodeItem.Element("description").Value) }; lstFeeds.Add(feed); } catch (NullReferenceException) { intLinkFail++; } } ; } //Ngoại lệ không phù hợp không thể parse Dư liệu => chuyển qua tiếp tục catch (XmlException) { intLinkFail++; } catch (NotSupportedException) { intLinkFail++; SEDFuncCall.MessageWarning(SEDConst.MESSAGE_LINK_INVALID, SEDConst.TITLE_WARNING); //Riêng ở phần parse Multiple này ta sẽ để cho nó tiếp tục parse để tránh ảnh hướng tới //quá trình parse dữ liệu từ các phần ở dưới } catch (WebException) { intLinkFail++; } catch (Exception ex) { intLinkFail++; //Debug.WriteLine("Error Location " + i + " Information eror:" + gvListRss.GetRowCellValue(i, "Link").ToString()); SEDFuncCall.MessageWarning(ex.Message, SEDConst.TITLE_WARNING); return; } } stw.Stop(); splashScreenManagerMultiplePage.CloseWaitForm(); gcShowFeeds.DataSource = lstFeeds; lblLinkDiedDynamic.Text = intLinkFail.ToString(); lblTimeExcuteDynamic.Text = stw.Elapsed.ToString(); lblTotalChildDynamic.Text = new StringBuilder(gvShowFeeds.RowCount.ToString()) .Append(" posts!").ToString(); }