Exemplo n.º 1
0
        public static HabrArticle GetHabrArticleFromInternet(int articleId)
        {
            HtmlDocument document;

            try
            {
                var web = new HtmlWeb();
                document = web.Load(Resources.postString + articleId + "/");
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("Невозможно получить доступ к ресурсу!");
                return(null);
            }

            try
            {
                var tags     = document.DocumentNode.SelectNodes("//a[contains(@class,'hub')]");
                var tempTags = new List <string>();
                tempTags.AddRange(tags.Select(x => x.InnerText));


                var habrArticle = new HabrArticle
                {
                    HabrId          = articleId,
                    Theme           = document.DocumentNode.SelectSingleNode("//h1[contains(@class,'post__title')]//a").InnerText,
                    Title           = document.DocumentNode.SelectNodes("//h1[contains(@class,'post__title')]//span")[1].InnerText,
                    Tags            = tempTags,
                    PublicationDate = document.DocumentNode.SelectSingleNode("//span[contains(@class,'post__time_published')]").InnerText
                };

                return(habrArticle);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error 404: Article not found =(");
                return(null);
            }
        }
Exemplo n.º 2
0
        public static void AddHabrArticleToDb(HabrArticle habrArticle)
        {
            Connect();

            _habrArticleCollection?.InsertOne(habrArticle);
        }
Exemplo n.º 3
0
 public HabrArticleViewModel(HabrArticle habrArticle)
 {
     HabrArticle = habrArticle;
 }