Using the Scoring Game from POP Forums with your ASP.NET MVC app

Let me tell you a story of HR-discouraged workplace fun. Back in the day, prior to the crash-and-burn of, we had this thing in the development part of the company called the Scoring Game. I wrote about it a couple of years ago on my personal blog. The long and short of it is that we kept a running total of +/-1’s for virtually anything you can think of, for each participant. This was back in 2006, before it became trendy to do it for everything else on the Internets.

Later, Digg started doing all kinds of voting, and it was really the first active example that I can think of that I used in terms of measuring value of content (yes, slashdot did it, but I never went there). Various forums started doing it. StackOverflow based much of its value on a scoring system, along with achievements. When I worked at Microsoft, I worked on the reputation system that feeds the various MSDN properties. It seems inevitable that I’d have to add something like this to POP Forums.

Originally, I was thinking just in terms of voting up posts, but then I realized that there were actually two things to build. The voting mechanism was one part, but the actual scoring was a second part that should be decoupled from the voting. So the workflow goes like this:

Process Event –> Publish to user profile (optional) –> Get associated awards –> Qualify awards –> Give award

To use the system, you only need only a few lines of code. Use the dependency injection container (Ninject) to get the implementation of PopForums.ScoringGame.IEventPublisher.

Note: Yeah, the forums are currently wired to use ASP.NET MVC’s IDependencyResolver to new-up stuff. I realize that this is suboptimal, and a future version will fix this so you don’t have to commit to the same DI container the forum uses.

var publisher = PopForums.Web.PopForumsActivation.Kernel.Get<PopForums.ScoringGame.IEventPublisher>(); publisher.ProcessEvent("message for feed", user, "TestEventID");

Pretty simple, eh? The first string is the text that will be published to the user’s feed (if the event is set to publish), the second is the PopForums.Models.User object to associate with the event, and the third is the actual event ID. Event definitions are really simple.

Event Definitions

There are three events that are static, permanently built into the system. These are wired into the post voting, and the creation of new topics and posts. So for example, when someone votes up a post, a string of HTML is passed in to the ProcessEvent() method, with the user object associated with the post, and the event ID PostVote. The resulting mention in the user’s profile looks like this:

Profile with events

Events don’t have to be published to the user’s profile, and they don’t even need to assign points. New posts and topic events fall into this category. So what’s the point then? Awards! POP Forums leaves that up to you. Award definitions are super simple as well. Say we wanted to give an award for anyone who made 50 posts. The definition would look like this:

Award definition

We can assign any combination of events to the award. In this case, we look for 50 NewPost events, but we could just as easily require 25 PostVote events as well, for a combined set of conditions.

That’s really all there is to it. You can set up stuff anywhere in your app to record events, and publish them to the user profile. Give points, give awards. Knock yourself out!

No Comments