A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

pappabj0rn
Jul 21, 2010
  5540
(0 votes)

Community Recognition Program – The Parts You Don’t See

As you may or may not have noticed, we’ve just released (Tuesday 20th) our community recognition program (CRP). We’ve published a page about the community recognition program explaining how to score points etc., but we though we’d show you how it was built. It’s not super advanced or anything, but hopefully it can act as another sample for how to work with the DDS.

Firstly, here’s a picture I drew to illustrate how it all works:

CRP_idea

As you can see, all the things you users do on EPiServer World, like post blogs (syndicated blogs also count), write comments, reply to forum threads etc, generates a contribution object that goes into the DDS bucket. The contribution object holds info about date, type (blog post, article, etc), pageid (to link a contribution to a page if relevant), points, user and notes (for internal use).

As shown in the picture, the DDS also holds the config monster and a book of levels. These two enable us to set how much points each contribution should be worth and how many points you need to advance to a higher level.

To make all this work, we’ve used a little something we like to call “code”, Let’s dig in!

Firstly we have a plug-in to subscribe to the relevant events and handle the creation of contribution points whenever you, well, contribute.

   1: public class CommunityRecognitionPlugin : PlugInAttribute
   2: {
   3:     public static void Start()
   4:     {
   5:         // this will set us up the bomb
   6:         DataFactory.Instance.DeletedPage += new PageEventHandler(Instance_DeletedPage);
   7:         DataFactory.Instance.PublishedPage += new PageEventHandler(Instance_PublishedPage);
   8:         DataFactory.Instance.MovedPage += new PageEventHandler(Instance_MovedPage);
   9:     }
  10:  
  11:     ...
  12:  
  13:     static void Instance_PublishedPage(object sender, PageEventArgs e)
  14:     {
  15:         ...
  16:         else if (e.Page.PageTypeName == "Article")
  17:         {
  18:             string contributor = e.Page["crmAuthor"] as string ?? "N/A";
  19:             Data.AddContribution(contributor, ContributionType.article, e.Page.PageLink.ID, false);
  20:         }
  21:         ...
  22:     }
  23:  
  24:     ...
  25: }

The plug-in simply pulls out the relevant information from the pages and sends the values to our contribution data layer that handles all dealing with the DDS.

   1: public static class Data
   2: {
   3:     public static ILog log = LogManager.GetLogger(typeof(Data));
   4:     
   5:     public static EPiServer.Data.Dynamic.DynamicDataStore GetStore(Type t)
   6:     {
   7:         // GetStore will only return null the first time this method is called for a Type
   8:         // In that case the ?? C# operator will call CreateStore
   9:         // http://world.episerver.com/Blogs/Paul-Smith/Dates1/2010/1/Using-a-DynamicDataStore-instance-correctly/
  10:         return EPiServer.Data.Dynamic.DynamicDataStoreFactory.Instance.GetStore(t) ??
  11:             EPiServer.Data.Dynamic.DynamicDataStoreFactory.Instance.CreateStore(t);
  12:     }
  13:  
  14:     ...
  15:  
  16:     //There are a bunch of overloads for AddContribution but they all end up in SaveContribution
  17:     public static void SaveContribution(Contribution c, bool skipProfileUpdate)
  18:     {
  19:         if(log.IsInfoEnabled)
  20:             log.InfoFormat("Saving contribution for {0} of type {1} (pageid:{2}).", c.Contributor, c.Action.ToString(),c.ContributionPageID);
  21:  
  22:         //This is just to filter out some old stuff, like EP Import
  23:         if (Util.IsBannedName(c.Contributor))
  24:             return;
  25:  
  26:         DynamicDataStore store = GetStore(typeof(Contribution));
  27:         store.Save(c);
  28:         if(log.IsInfoEnabled)
  29:             log.InfoFormat("Saved contribution for {0} of type {1} (pageid:{2}).", c.Contributor, c.Action.ToString(), c.ContributionPageID);
  30:  
  31:         if (!skipProfileUpdate)
  32:             UpdateProfileLevel(c.Contributor);
  33:  
  34:         if(c.Action != ContributionType.ecd)
  35:             CheckAndAddECDContribution(c.Contributor);
  36:     }
  37:  
  38:     public static void DeleteContribution(Contribution c, bool skipProfileUpdate)
  39:     {
  40:         DynamicDataStore store = GetStore(typeof(Contribution));
  41:         store.Delete(c);
  42:  
  43:         if(!skipProfileUpdate)
  44:             UpdateProfileLevel(c.Contributor);
  45:     }
  46:  
  47:     ...
  48:  
  49:     public static List<Contribution> GetContributions(string contributor)
  50:     {
  51:         DynamicDataStore store = GetStore(typeof(Contribution));
  52:         List<Contribution> contributions = (from c in store.Items<Contribution>()
  53:                                             where c.Contributor == contributor
  54:                                             select c).ToList<Contribution>();
  55:         return contributions;
  56:     }
  57:  
  58:     ...
  59:  
  60:     // The ContributionData object is used by our recognition gadget and is generated on the fly rather than storing it in the DDS
  61:     public static ContributionData GetContributionDataForContributor(string contributor)
  62:     {
  63:         List<Contribution> contribs = GetContributions(contributor);
  64:  
  65:         int score = 0;
  66:         foreach (var contribution in contribs)
  67:         {
  68:             score += contribution.Points;
  69:         }
  70:  
  71:         return new ContributionData()
  72:         {
  73:             Contributor = contributor,
  74:             Count = contribs.Count,
  75:             Score = score
  76:         };
  77:     }
  78:  
  79:     ...
  80: }

Sure, I’ve removed a lot of code for clarity, but basically, that’s about it.

I won’t show the recognition gadget, because it’s really nothing fancy, or pretty, but I might be back with another blog post covering some gadget stuff.

Some cred should go to Pontus Lidén who built the first prototype of the CRP during his internship with us.

Jul 21, 2010

Comments

Please login to comment.
Latest blogs
A day in the life of an Optimizely OMVP: Learning Optimizely Just Got Easier: Introducing the Optimizely Learning Centre

On the back of my last post about the Opti Graph Learning Centre, I am now happy to announce a revamped interactive learning platform that makes...

Graham Carr | Jan 31, 2026

Scheduled job for deleting content types and all related content

In my previous blog post which was about getting an overview of your sites content https://world.optimizely.com/blogs/Per-Nergard/Dates/2026/1/sche...

Per Nergård (MVP) | Jan 30, 2026

Working With Applications in Optimizely CMS 13

💡 Note:  The following content has been written based on Optimizely CMS 13 Preview 2 and may not accurately reflect the final release version. As...

Mark Stott | Jan 30, 2026

Experimentation at Speed Using Optimizely Opal and Web Experimentation

If you are working in experimentation, you will know that speed matters. The quicker you can go from idea to implementation, the faster you can...

Minesh Shah (Netcel) | Jan 30, 2026

How to run Optimizely CMS on VS Code Dev Containers

VS Code Dev Containers is an extension that allows you to use a Docker container as a full-featured development environment. Instead of installing...

Daniel Halse | Jan 30, 2026

A day in the life of an Optimizely OMVP: Introducing Optimizely Graph Learning Centre Beta: Master GraphQL for Content Delivery

GraphQL is transforming how developers query and deliver content from Optimizely CMS. But let's be honest—there's a learning curve. Between...

Graham Carr | Jan 30, 2026