A BlogEngine.Net Widget On The Way

by John 31. January 2011 12:38

I've had a BlogEngine.Net for about a year on my other site and one thing has always bugged me about their LinkList widget.  There's no (simple) way to order the lists.  You essentially have to add them the way you want them to show the first time.  If you find something else to add later, too bad buddy, it's going at the bottom.  Well, I finally got tired of that and started looking into what it takes to do give some order to the chaos.

 

I'm running the BE in SQL Server mode, so it was pretty easy to figure out the data is stored in a table... which table and how was something far more complex than I had imagined.  I did finally find the table (be_DataStoreSettings), but what I found was a nightmare of embedded XML - inside some other XML.  Oof.  Honestly, I'm not much of an XML guy. I've been dabbling in and around it for years, but I've never really spent too much energy learning the ins and outs of XSL or the XDoc DOM, etc.  So when I found a xml-based SerializedStringDictionary object as the value of the widget settings, I was a little put off.  

 

The first time I needed to arrange the links, I just manually edited the XML and saved it back to the database.  However, a few weeks ago, I had to do it again and thought: Well, I've done it more than once, I'll have to do it again - might as well write a little app to help out.  So, I began digging into the source code for BE.Net and I quickly realized something: is this thing super-architected, or what?!  To top things off, C# is not my primary language. Meaning, I can get the point and I can hold a conversation, but in all truth, I still look up some things up pretty frequently when the syntax doesn't easily translate in my VB brain.

 

So, naturally, I started writing a down'n'dirty vb/asp.net page to pull back the data, allow me to sort it, then send it back.  Then I remembered seeing something the Ajax Control Toolkit that allowed for drag'n'drop capability.  Behold: the ReorderList control!  First, I had to learn how to use that thing, then I had to somehow populate it with a collection it can handle (which meant translating the XmlNodeList I got back from the database into something that implements IList).

 

Tappity-tap-tap later, I had my own little DictionaryItem class implementing an IDictionaryItem interface, so I can easily use the generic List(Of T) collection to send to the control.

 

Now my LinkList data is parsed, displayed and orderable via drag'n'drop, all that's left is saving the new list back to the database!  It turns out, the ReorderList control is something of a ... how shall I say... less-than-intuitive control.  I (mistakenly) assumed the list items would be readily available in, for example, the Items collection property.  Well.... yes and no.  Yes, there are a ton of items in the collection, but none of them are actually my objects. Each item has a Controls collection, which houses another Controls collection and so on - but at the root, is just a literal control with the text of the item being displayed within an HTML table/row/cell/control.  This is no good. This means I have no way to iterate through all the items in the ReorderList control, at one time, and save off their new orders.  After some trial and error, I decided to go ahead and use a Session variable housing the working collection of DictionaryItems that would get modified in the ReorderList control's ItemReorder event.

 

After those kinks were all sorted out, the page was done.  I could load the page, select any of my LinkList widgets, and sort the order of the items displayed.  It works wonderfully.  Then it occurred to me: "I bet other people would like this option too!".  I had previously searched through the discussion board over at CodePlex for widgets allowing me to sort items and there were zero hits.  So now, it's up to me to provide one.  And that's okay.

 

However, I will now need to convert this little utility to something a bit more BE.Net friendly.  First off, I have to convert to C#; which should not be a big deal.  But, more importantly, I will have to start using their control hierarchy and their database functions (to get the table prefix and db-login information, etc).  I've found the "How to create a widget" documentation and am going through it now.  The one thing I'm not sure of is if I will have to change how any part of my code works when the blog is configured to use XML files instead of SQL Server.  I guess I'm going to have to install a blog locally and test to find out for sure.  I thinking that I won't have to do much, if anything at all, since the way they built the app doesn't really care how the data gets to the business layer - and for the most part, my code doesn't really care either.  I habitually separated out the business functions from the database interaction from the start, so I'm in good shape, I think.

 

I'll post the widget here when it's ready for testing and I'll announce it officially on the BE.Net forum as well.  Until then...

Tags: , , , , ,

Programming | C# | SQL Server

Comments are closed

About Me

I'm a .Net developer in St. Louis, MO working for Phase5 Consulting. 

Professional Info

Tag cloud