Пример #1
0
        public override void RunBackgroundTask()
        {
            // this task only works if the RSS feed is configured to be the datasource.
            if (GlossaryPlaceholderData.DataSource == GlossaryPlaceholderData.GlossaryDataSource.RssFeed)
            {
                string dataCacheKey    = GlossaryPlaceholderData.getRssDataPersistentVariableName();
                string lastRunCacheKey = dataCacheKey + "_LastRun";

                CmsPersistentVariable persistedLastRun = CmsPersistentVariable.Fetch(lastRunCacheKey);
                bool doFetch = false;
                if (persistedLastRun.Name == "" || persistedLastRun.PersistedValue == null)
                {
                    doFetch = true;
                }
                if (persistedLastRun.Name != "" && !doFetch)
                {
                    DateTime lastRunTime = (DateTime)persistedLastRun.PersistedValue;
                    if (lastRunTime < DateTime.Now.AddDays(-1))
                    {
                        doFetch = true;
                    }
                }

                if (doFetch)
                {
                    FetchAndSaveRemoteRSSGlossaryData();
                }
            }
        } // RunBackgroundTask
Пример #2
0
        } // RunBackgroundTask

        public bool FetchAndSaveRemoteRSSGlossaryData()
        {
            string dataCacheKey    = GlossaryPlaceholderData.getRssDataPersistentVariableName();
            string lastRunCacheKey = dataCacheKey + "_LastRun";

            string rssUrl = GlossaryPlaceholderData.getRssDataSourceUrl();

            Rss.RssFeed glossaryRss = Rss.RssFeed.Read(rssUrl);
            if (glossaryRss.Channels.Count == 0)
            {
                // html.Append("<em>Error: could not retrieve Glossary from "+rssUrl+"</em>");
            }
            else
            {
                GlossaryData[]        items         = GlossaryData.FromRSSItems(glossaryRss.Channels[0].Items);
                CmsPersistentVariable persistedData = CmsPersistentVariable.Fetch(dataCacheKey);
                persistedData.Name           = dataCacheKey;
                persistedData.PersistedValue = new List <GlossaryData>(items);
                bool b = persistedData.SaveToDatabase();

                if (b)
                {
                    CmsPersistentVariable persistedLastRun = CmsPersistentVariable.Fetch(lastRunCacheKey);
                    persistedLastRun.PersistedValue = DateTime.Now;
                    persistedLastRun.Name           = lastRunCacheKey;
                    return(persistedLastRun.SaveToDatabase());
                }
            }

            return(false);
        } // FetchAndSaveRemoteRSSGlossaryData
Пример #3
0
        } // saveUpdatedGlossary

        public GlossaryData[] FetchRssFeedGlossaryDataFromDatabase()
        {
            // "http://www.sadcwaterhub.org/glossary/feed?lang_tid[0]=2"
            string dataCacheKey = GlossaryPlaceholderData.getRssDataPersistentVariableName();
            CmsPersistentVariable persistedData = CmsPersistentVariable.Fetch(dataCacheKey);

            if (persistedData.Name != "")
            {
                List <GlossaryData> list = (List <GlossaryData>)persistedData.PersistedValue;
                return(list.ToArray());
            }
            else
            {
                return(new GlossaryData[0]);
            }
        }
Пример #4
0
        public void CanInsertLongBlobtoDatabase()
        {
            ServiceLocatorInitializer.Init();
            IRepository <CmsPersistentVariable> repository          = new Repository <CmsPersistentVariable>();
            IList <CmsPersistentVariable>       persistentvariables = repository.GetAll();

            Assert.IsNotNull(persistentvariables);
            Assert.That(persistentvariables, Is.Not.Empty);

            CmsPersistentVariable insertvariable = new CmsPersistentVariable();

            insertvariable.Name           = "This is a test variable for long blob type";
            insertvariable.PersistedValue = persistentvariables[0].PersistedValue;
            Assert.That(insertvariable, Is.Not.Null);

            CmsPersistentVariable returnvariable = repository.SaveOrUpdate(insertvariable);

            IList <CmsPersistentVariable> newvariables = repository.GetAll();

            Assert.That(newvariables.Count, Is.EqualTo(4));
        }