Esempio n. 1
0
        public static Dictionary<DateTime, List<SyndicationInfo>> GetLastestInstructorFeedsDictionary(int Id)
        {
            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());

            //Set variables.
            Int16 nTopX = 1;
            Int16 NoOfFeedsPerDay = 0;
            Int16 NoOfFeedsLatest = 6;

            int nCurrent = 0;


            //if (HttpRuntime.Cache["RssFeedsDictionary"] != null)
            //{
            //    /* If it is in cache then return from cache */
            //    _syndicationInfoDictionary = (Dictionary<DateTime, List<SyndicationInfo>>)HttpRuntime.Cache["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.BuildInstructorOPML(nTopX,Id);
                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 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("RssFeedsDictionary", (object)_syndicationInfoDictionary, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);

                }
                return _syndicationInfoDictionary;
            //}
        }