Codemania 2010 Continued

blog header image

I just realized that I in this previous post forgot to share my “search page provider” – a page provider that searches for the newest pages in a specific page type using Johan Olofssons LINQ to PageData – and returns the results as children.

It’s a little bit special because it in itself does not actually create any pages – it just returns links to other already existing pages.

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Linq;
   4: using System.Web;
   5: using EPiServer.Core;
   6: using EPiServer.Research.Page.Linq;
   7:  
   8: namespace EPiServer.PageProviders
   9: {
  10:     public class SearchProvider : PageProviderBase
  11:     {
  12:         protected override PageReferenceCollection GetChildrenReferences(PageReference pageLink, string languageID)
  13:         {
  14:             PageQuery pq = new PageQuery(PageReference.StartPage, "en");
  15:             var results = from page in pq
  16:                           where page.PageTypeID==4
  17:                           orderby page.StartPublish descending
  18:                           select page;
  19:             var lst=results.ToList();
  20:             
  21:             return new PageReferenceCollection(lst.Select( pd => pd.PageLink).Take(10));
  22:  
  23:         }
  24:  
  25:         protected override PageData GetLocalPage(PageReference pageLink, ILanguageSelector languageSelector)
  26:         {
  27:             return DataFactory.Instance.GetPage(pageLink, languageSelector);
  28:         }
  29:  
  30:         protected override Uri ResolveLocalPage(PageReference pageLink, out Guid guid)
  31:         {
  32:             guid = Guid.Empty;
  33:             return null;
  34:         }
  35:  
  36:         protected override Uri ResolveLocalPage(Guid pageGuid, out PageReference pageLink)
  37:         {
  38:             pageLink = PageReference.EmptyReference;
  39:             return null;
  40:         }
  41:  
  42:         #region Disable Caching
  43:         protected override void SetCacheSettings(PageData page, CacheSettings cacheSettings)
  44:         {
  45:             cacheSettings.CancelCaching = true;
  46:         }
  47:  
  48:         protected override void SetCacheSettings(PageReference pageLink, PageReferenceCollection childrenReferences, CacheSettings cacheSettings)
  49:         {
  50:             cacheSettings.CancelCaching = true;
  51:         }
  52:         #endregion
  53:     }
  54: }
Recent posts