Пример #1
0
        /// <summary>
        /// Jumps to detail view news page
        /// </summary>
        /// <param name="obj">ItemNews</param>
        /// <returns></returns>
        private async Task DetailsPage(object obj)
        {
            ItemsNews feedItem = obj as ItemsNews;

            if (feedItem != null)
            {
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => NavigationService.Navigate(typeof(ViewNewsPage), feedItem.LinkNews));
            }
        }
Пример #2
0
        /// <summary>
        /// Parsing news section page
        /// </summary>
        /// <param name="path"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public async Task <ObservableCollection <ItemsNews> > NewsItemList(string path, string pathDB)
        {
            if (!HttpRequest.HasInternet())
            {
                return(null);
            }
            myItems = new ObservableCollection <ItemsNews>();

            await Task.Run(async() =>
            {
                HttpClient httpClient = new HttpClient();
                oldNewsItem           = new ObservableCollection <ItemsNews>();
                ResultHtmlPage        = await HttpRequest.GetRequestOnlinerAsync(path);
                resultat.LoadHtml(ResultHtmlPage);

                List <HtmlNode> titleList = resultat.DocumentNode.Descendants().Where
                                                (x => (x.Name == "article" && x.Attributes["class"] != null && x.Attributes["class"].Value.Contains
                                                           ("b-posts-1-item b-content-posts-1-item news_for_copy"))).ToList();

                //db news collections
                var DBNewsList = await GetNeedList(pathDB);

                foreach (var item in titleList)
                {
                    _itemNews        = new ItemsNews();
                    _itemNews.NewsID = item.Descendants("span").
                                       Where(div => div.GetAttributeValue("class", string.Empty) == "show_news_view_count").FirstOrDefault().Attributes["news_id"].Value;
                    NewsListId.Add(QueryString(_itemNews.NewsID));

                    //data for update
                    _itemNews.LinkNews = item.Descendants("h3").
                                         Where(div => div.GetAttributeValue("class", string.Empty) == "b-posts-1-item__title").FirstOrDefault().Descendants("a").FirstOrDefault().Attributes["href"].Value;
                    _itemNews.CountViews = GetFirstOrDefaultTwoTagInARowHtmlInnerText(item, "a", "span");
                    _itemNews.Footer     = Regex.Replace(item.Descendants("span").
                                                         Where(div => div.GetAttributeValue("class", string.Empty) == "right-side").LastOrDefault().InnerText.Replace("\n", "").Trim(), @"\s+", " ");

                    var popularCount = item?.Descendants("span").Where(div => div.GetAttributeValue("class", string.Empty) == "popular-count").FirstOrDefault();
                    if (popularCount != null)
                    {
                        _itemNews.Popularcount = popularCount.InnerText;
                    }

                    if (DBNewsList != null)
                    {
                        var containItem = DBNewsList.FirstOrDefault(x => x.LinkNews == _itemNews.LinkNews);
                        if (containItem != null)
                        {
                            oldNewsItem.Add(_itemNews);
                            continue;
                        }
                    }

                    _itemNews.Themes = GetFirstOrDefaultTwoTagInARowHtmlInnerText(item, "div", "strong");
                    _itemNews.Title  = GetFirstOrDefaultThreeTagInARowHtmlInnerText(item, "h3", "a", "span");

                    string clearLink      = ClearImageLink(GetFirstOrDefaultTwoTagInARowHtmlInnerHtml(item, "figure", "a"));
                    _itemNews.Image       = await client.GetByteArrayAsync(clearLink);
                    _itemNews.Description = ScrubHtml(item.Descendants("div").LastOrDefault().Descendants("p").First().InnerText.Trim());

                    //photo
                    _itemNews.Bmediaicon = GetFirstOrDefaultTagHtmlInnerText(item, "span", "class", "b-mediaicon");
                    //video
                    _itemNews.Mediaicongray = GetFirstOrDefaultTagHtmlInnerText(item, "span", "class", "b-mediaicon gray");

                    myItems.Add(_itemNews);
                }
                UpdateViewNews(oldNewsItem, path);
            });

            return(myItems);
        }