Creating a good module makes it sometimes very hard to improve upon that. The (still current) old release of the DotNetNuke Announcements module was such a module. Created in an era long forgotten, as a DotNetNuke 4 module, it was quite good at the time when it was released. The announcement module is a fairly simple module that is a useful tool on most websites, while at the same time showcasing important DotNetNuke API features, and thus playing also a role in helping developers understand DotNetNuke module development.

I feel pretty bad when I look at the last release date of the module though. May 15, 2009. More than 3 and a half years ago. The module might have been a good module back than, but it certainly is not anymore right now. What was regarded as using best practices back then, is currently not much more than using legacy code.

So… it is time to fix this with a new and shiny release, ready for the DotNetNuke 7 era that is upon us!. Let’s review the plans for this new version of the module:

DotNetNuke UI

The old module doesn’t look very nice anymore in the current DotNetNuke versions. Of course, in this reincarnation the DotNetNuke form pattern, as explained in the UX Guide is implemented. This is a screen shot of the Edit Announcement popup:

EditAnnouncements (click to enlarge)

Rewrite to C#

Some people in the DotNetNuke community used to think that the VB my nickname ErikVB was short for VisualBasic. It is of course nothing more than a coincidence that the VB happen to be the first letters of my last name. The switch to to C# may come as a surprise to some, but really it doesn’t matter that much. As it currently stands, there seems to be a movement in the direction of using C#. In my mind, one of the raisons d’être for this module is to be a good sample module for starting DotNetNuke developers.

As for the process of converting, I used Instance C# from Tangible Software. This automated conversion tool works pretty well, the only area of the project it had trouble with was the DAL (specifically the SqlDataprovider class). Of course that was not a huge problem, since the old DAL code was slated to be removed in the first place.

Implement DAL 2

One of the very nice new features is the introduction of the DAL 2. In a series of blog posts, starting with this one, Charles Nurse, Chief Architect of DotNetNuke Corp., outlines how the the face of Data Access is changing with DotNetnuke 7. We are implementing a Micro-ORM called PetaPoco, which provides us with a number of advantages. The bottom line of that is that it has become a lot less work for developers to access the DotNetNuke database. No more writing of StoredProcedures (well, to be fair, you can still do that if you need that), which apart from being faster, is also good for making less mistakes. In my experience, a lot of errors in modules actually originate in issues with missing ObjectQualifiers in the SQL scripts. The new DAL 2 automatically factors in the ObjectQualifier of the installation, so that leaves one less thing for the developer to think about.

In the new Announcements module, the AnnouncementInfo class now looks like this:

AnnouncementsInfo_Class

And in the AnnouncementsController class, the AddAnnouncement method changed to this:

AnnouncementsController_Class

I must say, this code is much cleaner than under DAL 1, and on top of that, as a bonus, we now get top notch caching of our business objects, by just marking them as being Cacheable.

Implement DotNetNuke WebAPI

Of course another very cool new feature of DotNetNuke 7 is the support for ASP.NET Web API. Many things have been written about it, and it is good to see that a lot of developers in the community are jumping on this new feature.

The new Announcements module will use the new WebAPI for a couple of different things: templating (think KnockoutJS), being able to generate an XML view on the module content, RSS/ATOM support etc. Of course WebAPI supports automatic output formatting based on what the client requests. By default this means that the output is either XML or JSON, however, I was particularly interested in the option to extend the output formats with your own.

My idea is to offer an alternative RSS feed for the module, that allows me to do something special: offer a combined feed of all the modules in a DotNetNuke site, that is filtered to the ones that you are actually allowed to see. I came across an interesting blog by Filip Woj, dealing about creating a RSS / Atom MediaTypeFormatter for WebAPI. Implementing this is very simple, and the beauty of it is that with the same code we can now also serve RSS and Atom feeds.

The first step in adding support for WebAPI starts with adding at least one route. In my case, i wanted to include an option to force the output in a certain format in the route, which let to this:

RegisterRoutes

and to this implementation for GetCurrentAnnouncements:

GetCurrentAnnouncements (click to enlarge)

As you can see, the ActionName is defined as “Current”, which means that, according to the defined route, the URL for this action is:

/DesktopModules/Announcements/API/Current

and optionally for instance this:

/DesktopModules/Announcements/API/Current/rss

The default value for the Output parameter is “default”, which means that in that case the auto formatting feature of WebAPI is used. All methods that return results based on a list of AnnouncementInfo objects, will use a single GenerateOutput method to send the output to the client, which means that all these methods will share in the goodness. GenerateOutput looks like this:

GenerateOutput (click to enlarge) 

The future

All of this is currently available in a CTP release that was released today. As much as I had wanted, the module is far from ready. The work that has been done so far is, apart from the UX upgrade, mainly in the invisible parts of the module. I feel this is the right direction to go, as the module really needed a new, strong, foundation. The next major enhancement will be the templating system. As it stands now, I am strongly considering adding support for multiple different templating systems:

  • DotNetNuke TokenReplace
  • KnockoutJS
  • Razor
  • XSL

Other than the current system, the new templating will be file based.. which will make some skinners out there a little bit more happy I would guess.

Other than that, I would say the module also needs support for the DotNetNuke Taxonomy system, and also for the Social API… but more about that later… For now, take a look at the CTP for the new Announcement module for DotNetNuke 7, available here: http://dnnannouncements.codeplex.com/releases/view/98256. Enjoy, but please do not use it in a production site yet! If you find any issues, please log them in the issue tracker on CodePlex.

Posted in: DotNetNuke

Comments

Joe Brinkman
# Joe Brinkman
Monday, November 26, 2012 2:20 PM
Erik,
Please consider adding decent editor support for templates. It is pretty easy to wire up CodeMirror syntax editor and it makes a big difference in the editing experience.
SuperUser Account
# SuperUser Account
Monday, November 26, 2012 5:12 PM
Thanks for that suggestion Joe, I will definitively look at that!

Post Comment

Name (required)

Email (required)

 I am Erik van Ballegoij. I work for DotNetNuke corporation as Technical Lead and Evangelist. On this blog I blog about DotNetNuke tips and tricks and whatever else comes to mind

powered by dotnetnuke follow me on twitter linkedin rss feed