/* Gating RSS Feed in dataview . */ public static DataView GetLastestFeeds() { Int16 nTopX = Convert.ToInt16(WebConfigurationManager.AppSettings["NoOfDaysForFeeds"].ToString()); Int16 NoOfFeedsPerDay = Convert.ToInt16(WebConfigurationManager.AppSettings["NoOfFeedsPerDay"].ToString()); Int16 NoOfFeedsLatest = Convert.ToInt16(WebConfigurationManager.AppSettings["NoOfFeedsLatest"].ToString()); DataView dv = new DataView(); if( HttpRuntime.Cache[CacheKey + "RssFeeds"]!= null) { /* If it is in cache then return from cache */ dv = (DataView)HttpRuntime.Cache[CacheKey + "RssFeeds"]; return dv; } else { /* Else get data from database and aggregate RSS using opml & then add into cache. */ OpmlService opml = new OpmlService(); Dictionary<DateTime, List<DataRowView>> _readerItems = new Dictionary<DateTime, List<DataRowView>>(); /* Build opml xml to load rss from */ string strOpmlXml = opml.BuildOPML(nTopX); strOpmlXml = strOpmlXml.Replace("version=\"1.1\"", "version='1.1'"); /* Load RSS from opml xml */ RssToolkit.Rss.RssDocument RSS = RssToolkit.Rss.RssDocument.Load(strOpmlXml); if (RSS.Channel.Items.Count > 0) { IEnumerable items = RSS.SelectItems(); DataView dvItems = (DataView)items; /* sort data in data view by pubDateParsed */ dvItems.Sort = "pubDateParsed DESC"; /* Add data view in cache with expiration after 1 hour. */ HttpRuntime.Cache.Add(CacheKey + "RssFeeds", (object)dvItems, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); } /* Return data view containing Rss Feeds */ return dv; } }
public static DataView GetLastestFeeds() { Int16 nTopX = Convert.ToInt16(WebConfigurationManager.AppSettings["NoOfDaysForFeeds"].ToString()); Int16 NoOfFeedsPerDay = Convert.ToInt16(WebConfigurationManager.AppSettings["NoOfFeedsPerDay"].ToString()); Int16 NoOfFeedsLatest = Convert.ToInt16(WebConfigurationManager.AppSettings["NoOfFeedsLatest"].ToString()); DataView dv = new DataView(); if( HttpRuntime.Cache["RssFeeds"]!= null) { /* If it is in cache then return from cache */ dv = (DataView)HttpRuntime.Cache["RssFeeds"]; return dv; } else { /* Else get data from database and aggregate RSS using opml & then add into cache. */ OpmlService opml = new OpmlService(); Dictionary<DateTime, List<DataRowView>> _readerItems = new Dictionary<DateTime, List<DataRowView>>(); /* Build opml xml to load rss from */ string strOpmlXml = opml.BuildOPML(nTopX); strOpmlXml = strOpmlXml.Replace("version=\"1.1\"", "version='1.1'"); /* Load RSS from opml xml */ RssDocument RSS = RssDocument.Load(strOpmlXml); if (RSS.Channel.Items.Count > 0) { IEnumerable items = RSS.SelectItems(); DataView dvItems = (DataView)items; dvItems.Sort = "pubDateParsed DESC"; HttpRuntime.Cache.Add("RssFeeds", (object)dvItems, null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); //foreach (DataRowView view in dvItems) //{ // DateTime date = DateTime.Parse(view["pubDateParsed"].ToString()); // if (_readerItems.ContainsKey(date.Date)) // _readerItems[Convert.ToDateTime(date.ToShortDateString())].Add(view); // else // { // List<DataRowView> list = new List<DataRowView>(); // list.Add(view); // _readerItems.Add(date.Date, list); // } // if (_readerItems.Count >= nTopX) // break; // else // nCurrent++; //} } return dv; //return (DataView)c.Get("RssFeeds"); } }
public static Dictionary<DateTime, List<SyndicationInfo>> GetLastestFeedsDictionary() { Dictionary<DateTime, List<SyndicationInfo>> _syndicationInfoDictionary = new Dictionary<DateTime, List<SyndicationInfo>>(); List<SyndicationInfo> list; Int16 nTopX = Convert.ToInt16(WebConfigurationManager.AppSettings["NoOfDaysForFeeds"].ToString()); Int16 NoOfFeedsPerDay = Convert.ToInt16(WebConfigurationManager.AppSettings["NoOfFeedsPerDay"].ToString()); Int16 NoOfFeedsLatest = Convert.ToInt16(WebConfigurationManager.AppSettings["NoOfFeedsLatest"].ToString()); int nCurrent = 0; if (HttpRuntime.Cache[CacheKey + "RssFeedsDictionary"] != null) { /* If it is in cache then return from cache */ _syndicationInfoDictionary = (Dictionary<DateTime, List<SyndicationInfo>>)HttpRuntime.Cache[CacheKey + "RssFeedsDictionary"]; return _syndicationInfoDictionary; } else { /* Else get data from database and aggregate RSS using opml & then add into cache. */ OpmlService opml = new OpmlService(); /* Build opml xml to load rss from */ string strOpmlXml = opml.BuildOPML(nTopX); strOpmlXml = strOpmlXml.Replace("version=\"1.1\"", "version='1.1'"); /* Load RSS from opml xml */ try { RssToolkit.Rss.RssDocument RSS = RssToolkit.Rss.RssDocument.Load(strOpmlXml); if (RSS.Channel.Items.Count > 0) { IEnumerable items = RSS.SelectItems(); DataView dvItems = (DataView)items; /* sort data in data view by pubDateParsed */ dvItems.Sort = "pubDateParsed DESC"; /* Add data view in data dictionary */ foreach (DataRowView view in dvItems) { DateTime date = DateTime.Parse(view["pubDateParsed"].ToString()); if (!_syndicationInfoDictionary.ContainsKey(date.Date)) { list = GetFilteredSyndicationList(date.Date, view.DataView.Table); _syndicationInfoDictionary.Add(date.Date, list); } } /* Add dictionary in cache with expiration after 1 hour. */ HttpRuntime.Cache.Add(CacheKey + "RssFeedsDictionary", (object)_syndicationInfoDictionary, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); } } catch (Exception) { // } return _syndicationInfoDictionary; } }