public void FetchRssFeed() { new Thread(new ThreadStart(() => { try { if (MainWindow._current._configClient.GetVar("FirstRun") == "True") { MainWindow._current._configClient.SetVar("RSS", JsonConvert.SerializeObject(new string[] { "https://www.cnet.com/rss/news/", "https://www.cnet.com/rss/reviews/" })); } RssFeed rs; foreach (string l in JsonConvert.DeserializeObject <string[]>(MainWindow._current._configClient.GetVar("RSS"))) { rs = RssHelper.ReadFeed(@l); foreach (RssItem r in rs.Items) { Dispatcher.Invoke(() => { news.Children.Add(new Separator() { Width = 8 }); Card t = new Card(); StackPanel Items = new StackPanel(); TextBlock text = new TextBlock(); text.Text = r.Title; text.FontSize = 16; text.TextWrapping = TextWrapping.Wrap; text.FontFamily = new FontFamily(@"pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"); text.Height = 75; text.Padding = new Thickness(5, 0, 5, 2); Button b = new Button(); b.Style = (Style)Application.Current.Resources["MaterialDesignFlatButton"]; b.Click += (object sender, RoutedEventArgs e) => { Process.Start(r.Link); }; b.Content = "Read More..."; b.HorizontalAlignment = HorizontalAlignment.Right; t.Height = news.Height - 15; news.Width += t.Width; Items.Width = 200; Items.Height = 100; Items.Children.Add(text); Items.Children.Add(b); t.Content = Items; news.Children.Add(t); }); } } } catch { // shall we repeat the code above or what? } })).Start(); }
public static async Task <ObservableCollection <LearningResource> > GetBlogs(string url) { try { RssFeed feed = null; await Task.Factory.StartNew( () => { try { feed = RssHelper.ReadFeed(new Uri(url)); } catch (Exception ex) { } }); ObservableCollection <LearningResource> learningResources = new ObservableCollection <LearningResource>(); if (feed == null) { return(null); } foreach (var item in feed.Items) { try { LearningResource v = new LearningResource(); v.Description = HtmlUtilities.ConvertToText(item.Description) .Replace("\n", "") .Replace("\r", ""); v.Link = item.Link; v.Title = item.Title; v.PublicationTime = item.PublicationUtcTime; learningResources.Add(v); } catch (Exception) { // } } return(learningResources); } catch (Exception ex) { return(null); } }
public Artigo ObterArtigo() { // Obtendo os posts do Blog var feed = RssHelper.ReadFeed(this.Fonte.Url); // Selecionando um artigo var articles = feed.Items .Select(i => new Artigo(i.Title, i.Link)) .Where(a => a.Url.Contains(this.Fonte.TermoFiltragem)); // Obtendo um artigo aleatório var random = new Random(); var randomNumber = random.Next(0, articles.Count()); var article = articles.ToArray()[randomNumber]; return(article); }
public static RssResult getRss() { // Make configuration property string[] feeds = { "http://www.rtlnieuws.nl/service/rss/nieuws/index.xml", "http://tweakers.net/feeds/nieuws.xml" }; int numberOfItems = 5; //Retrieve every item in every feed List <RssItem> items = new List <RssItem>(); foreach (string feed in feeds) { RssFeed rssFeed = RssHelper.ReadFeed(feed); items.AddRange(rssFeed.Items); } //Sort all on publication datetime items = items.OrderByDescending(x => x.PublicationUtcTime).Take(numberOfItems).ToList(); RssResult result = new RssResult(); result.setRssItems(items); return(result); }