public ActionResult Index() { RSS model = new RSS(); model.getRss("http://www.horeca.ru/kernel/rss/news.restaurant.xml"); model.getRss("http://www.carbis.ru/forum/external.php?type=RSS2&forumids=112"); model.channels[model.channels.Count - 1].rssTitle = "Форум Carbis: R-Keeper 7"; model.getRss("http://www.carbis.ru/forum/external.php?type=RSS2&forumids=11"); model.channels[model.channels.Count - 1].rssTitle = "Форум Carbis: StoreHouse"; return View(model); }
public void getRss(string url) { XmlReader rdr = XmlReader.Create(url); SyndicationFeed news = SyndicationFeed.Load(rdr); rdr.Close(); RSS channel = channels.FirstOrDefault(p => p.uri == url); if (channel == null) { channel = new RSS(); channel.uri = url; channel.rssTitle = news.Title.Text; foreach (SyndicationItem newsItem in news.Items) { rssNewsItem n = new rssNewsItem(); n.newsLink = newsItem.Links[0].Uri.ToString(); n.newsTitle = newsItem.Title.Text; n.newsDescription = Regex.Replace(newsItem.Summary.Text, @"<div>.*?</div>", "", RegexOptions.Singleline); n.newsDescription = Regex.Replace(n.newsDescription, @"<.*?>", "", RegexOptions.IgnoreCase | RegexOptions.Singleline).Trim(); n.pubDate = newsItem.PublishDate.ToString("dd.MM.yyyy"); n.category = ""; channel.rssNews.Add(n); } channels.Add(channel); } else { foreach (SyndicationItem newsItem in news.Items) { rssNewsItem n = new rssNewsItem(); n.newsLink = newsItem.Links[0].Uri.ToString(); n.newsTitle = newsItem.Title.Text; n.newsPhoto = newsItem.Links[1].Uri.ToString(); n.newsDescription = Regex.Replace(newsItem.Summary.Text, @"<div>.*?</div>", "", RegexOptions.Singleline); n.newsDescription = Regex.Replace(n.newsDescription, @"<.*?>", "", RegexOptions.IgnoreCase | RegexOptions.Singleline).Trim(); n.pubDate = newsItem.PublishDate.ToString("dd.MM.yyyy"); n.category = ""; channel.rssNews.Add(n); } } }