コード例 #1
0
        public void BlogDataService_GetEntriesWithFalse_Successful()
        {
            BlogDataServiceFactory.RemoveService(UnitTestsConstants.TestContentLocation);
            IBlogDataService blogdataservice = BlogDataServiceFactory.GetService(UnitTestsConstants.TestContentLocation,
                                                                                 LoggingDataServiceFactory.GetService(UnitTestsConstants.TestLoggingLocation));
            // gets both public and non-public
            var entries = blogdataservice.GetEntries(false);

            Assert.Equal(23, entries.Count);
        }
コード例 #2
0
        public void BlogDataService_GetEntryForEditDelete_Successful(IBlogDataService blogdataservice)
        {
            var entriesBefore = blogdataservice.GetEntries(false);
            var entry         = TestEntry.CreateEntry(String.Format("Test Entry 2"), 5, 2);

            blogdataservice.SaveEntry(entry, null);

            var dt          = DateTime.Now;
            var returnEntry = blogdataservice.GetEntryForEdit(entry.EntryId);

            Assert.NotNull(returnEntry);

            blogdataservice.DeleteEntry(entry.EntryId, null);

            var entryFailRetrieval = blogdataservice.GetEntry(entry.EntryId);

            Assert.Null(entryFailRetrieval);
            var entriesAfter = blogdataservice.GetEntries(false);

            Assert.Equal(entriesBefore, entriesAfter);
        }
コード例 #3
0
ファイル: BlogManager.cs プロジェクト: visualhu/dasblog-core
        public EntryCollection GetEntriesForPage(int pageIndex)
        {
            Predicate <Entry> pred = null;

            //Shallow copy as we're going to modify it...and we don't want to modify THE cache.
            EntryCollection cache = _dataService.GetEntries(null, pred, Int32.MaxValue, Int32.MaxValue);

            // remove the posts from the front page
            EntryCollection fp = GetFrontPagePosts();

            cache.RemoveRange(0, fp.Count);

            int entriesPerPage = _dasBlogSettings.SiteConfiguration.EntriesPerPage;

            // compensate for frontpage
            if ((pageIndex - 1) * entriesPerPage < cache.Count)
            {
                // Remove all entries before the current page's first entry.
                int end = (pageIndex - 1) * entriesPerPage;
                cache.RemoveRange(0, end);

                // Remove all entries after the page's last entry.
                if (cache.Count - entriesPerPage > 0)
                {
                    cache.RemoveRange(entriesPerPage, cache.Count - entriesPerPage);
                    // should match
                    bool postCount = cache.Count <= entriesPerPage;
                }

                return(_dataService.GetEntries(null, EntryCollectionFilter.DefaultFilters.IsInEntryIdCacheEntryCollection(cache),
                                               Int32.MaxValue,
                                               Int32.MaxValue));
            }

            return(new EntryCollection());
        }
コード例 #4
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                //Cache the sitemap for 8 hours...
                DataCache cache    = CacheFactory.GetCache();
                string    CacheKey = "TimelineXml";
                timeline  root     = cache[CacheKey] as timeline;
                if (root == null)                 //we'll have to build it...
                {
                    ILoggingDataService logService  = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
                    IBlogDataService    dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);
                    SiteConfig          siteConfig  = SiteConfig.GetSiteConfig();

                    root = new timeline();

                    root.events = new eventCollection();

                    int i = 0;

                    //All Pages (stop after 750...it gets too big and the browser can't handle it...we'd need
                    // to include dynamic paging
                    EntryCollection entryCache = dataService.GetEntries(false);
                    //Fortunately this comes in ordered by post date, descending
                    foreach (Entry e in entryCache)
                    {
                        if (e.IsPublic && (++i < 750))
                        {
                            //then add permalinks
                            string url = SiteUtilities.GetPermaLinkUrl(siteConfig, (ITitledEntry)e);
                            @event foo = new @event(e.CreatedLocalTime, false, TruncateDotDotDot(StripAllTags(e.Title), 50), url);
                            foo.text += String.Format("<div align=\"right\"><a href=\"{0}\">More...</a></div>", url);
                            root.events.Add(foo);
                        }
                    }

                    cache.Insert(CacheKey, root, DateTime.Now.AddHours(8));
                }

                XmlSerializer x = new XmlSerializer(typeof(timeline));
                x.Serialize(HttpContext.Current.Response.OutputStream, root);
                HttpContext.Current.Response.ContentType = "text/xml";
            }
            catch (Exception exc)
            {
                ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, exc);
            }
        }
コード例 #5
0
 public EntryCollection GetEntries()
 {
     return(dataService.GetEntries(false));
 }
コード例 #6
0
        public urlset GetGoogleSiteMap()
        {
            urlset root = new urlset();

            root.url = new urlCollection();

            //Default first...
            url basePage = new url(dasBlogSettings.GetBaseUrl(), DateTime.Now, changefreq.daily, 1.0M);

            root.url.Add(basePage);

            //Archives next...
            url archivePage = new url(dasBlogSettings.RelativeToRoot("archives"), DateTime.Now, changefreq.daily, 1.0M);

            root.url.Add(archivePage);

            //All Pages
            EntryCollection entryCache = dataService.GetEntries(false);

            foreach (Entry e in entryCache)
            {
                if (e.IsPublic)
                {
                    //Start with a RARE change freq...newer posts are more likely to change more often.
                    // The older a post, the less likely it is to change...
                    changefreq freq = changefreq.daily;

                    //new stuff?
                    if (e.CreatedLocalTime < DateTime.Now.AddMonths(-9))
                    {
                        freq = changefreq.yearly;
                    }
                    else if (e.CreatedLocalTime < DateTime.Now.AddDays(-30))
                    {
                        freq = changefreq.monthly;
                    }
                    else if (e.CreatedLocalTime < DateTime.Now.AddDays(-7))
                    {
                        freq = changefreq.weekly;
                    }
                    if (e.CreatedLocalTime > DateTime.Now.AddDays(-2))
                    {
                        freq = changefreq.hourly;
                    }

                    //Add comments pages, since comments have indexable content...
                    // Only add comments if we aren't showing comments on permalink pages already
                    if (dasBlogSettings.SiteConfiguration.ShowCommentsWhenViewingEntry == false)
                    {
                        url commentPage = new url(dasBlogSettings.GetCommentViewUrl(e.CompressedTitle), e.CreatedLocalTime, freq, 0.7M);
                        root.url.Add(commentPage);
                    }

                    //then add permalinks
                    url permaPage = new url(dasBlogSettings.RelativeToRoot(dasBlogSettings.GetPermaTitle(e.CompressedTitle)), e.CreatedLocalTime, freq, 0.9M);
                    root.url.Add(permaPage);
                }
            }

            //All Categories
            CategoryCacheEntryCollection catCache = dataService.GetCategories();

            foreach (CategoryCacheEntry cce in catCache)
            {
                if (cce.IsPublic)
                {
                    url catPage = new url(dasBlogSettings.GetCategoryViewUrl(cce.Name), DateTime.Now, changefreq.weekly, 0.6M);
                    root.url.Add(catPage);
                }
            }

            return(root);
        }
コード例 #7
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                //Cache the sitemap for 12 hours...
                string    CacheKey = "GoogleSiteMap";
                DataCache cache    = CacheFactory.GetCache();

                urlset root = cache[CacheKey] as urlset;
                if (root == null) //we'll have to build it...
                {
                    ILoggingDataService logService  = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
                    IBlogDataService    dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);
                    SiteConfig          siteConfig  = SiteConfig.GetSiteConfig();

                    root = new urlset();

                    root.url = new urlCollection();

                    //Default first...
                    url basePage = new url(SiteUtilities.GetBaseUrl(siteConfig), DateTime.Now, changefreq.daily, 1.0M);
                    root.url.Add(basePage);

                    url defaultPage = new url(SiteUtilities.GetStartPageUrl(siteConfig), DateTime.Now, changefreq.daily, 1.0M);
                    root.url.Add(defaultPage);

                    //Archives next...
                    url archivePage = new url(SiteUtilities.RelativeToRoot(siteConfig, "archives.aspx"), DateTime.Now, changefreq.daily, 1.0M);
                    root.url.Add(archivePage);

                    //All Pages
                    EntryCollection entryCache = dataService.GetEntries(false);
                    foreach (Entry e in entryCache)
                    {
                        if (e.IsPublic)
                        {
                            //Start with a RARE change freq...newer posts are more likely to change more often.
                            // The older a post, the less likely it is to change...
                            changefreq freq = changefreq.daily;

                            //new stuff?
                            if (e.CreatedLocalTime < DateTime.Now.AddMonths(-9))
                            {
                                freq = changefreq.yearly;
                            }
                            else if (e.CreatedLocalTime < DateTime.Now.AddDays(-30))
                            {
                                freq = changefreq.monthly;
                            }
                            else if (e.CreatedLocalTime < DateTime.Now.AddDays(-7))
                            {
                                freq = changefreq.weekly;
                            }
                            if (e.CreatedLocalTime > DateTime.Now.AddDays(-2))
                            {
                                freq = changefreq.hourly;
                            }

                            //Add comments pages, since comments have indexable content...
                            // Only add comments if we aren't showing comments on permalink pages already
                            if (siteConfig.ShowCommentsWhenViewingEntry == false)
                            {
                                url commentPage = new url(SiteUtilities.GetCommentViewUrl(siteConfig, e.EntryId), e.CreatedLocalTime, freq, 0.7M);
                                root.url.Add(commentPage);
                            }

                            //then add permalinks
                            url permaPage = new url(SiteUtilities.GetPermaLinkUrl(siteConfig, (ITitledEntry)e), e.CreatedLocalTime, freq, 0.9M);
                            root.url.Add(permaPage);
                        }
                    }

                    //All Categories
                    CategoryCacheEntryCollection catCache = dataService.GetCategories();
                    foreach (CategoryCacheEntry cce in catCache)
                    {
                        if (cce.IsPublic)
                        {
                            url catPage = new url(SiteUtilities.GetCategoryViewUrl(siteConfig, cce.Name), DateTime.Now, changefreq.weekly, 0.6M);
                            root.url.Add(catPage);
                        }
                    }
                    cache.Insert(CacheKey, root, DateTime.Now.AddHours(12));
                }

                XmlSerializer x = new XmlSerializer(typeof(urlset));
                x.Serialize(context.Response.OutputStream, root);
                context.Response.ContentType = "text/xml";
            }
            catch (Exception exc)
            {
                ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, exc);
            }
        }