thefrozencoder

Programming and Technology blog

Code highlighting integration for BlogEngine.NET 1.5.x

I decided to integrate some code highlighting into my blog rather than taking screen captures of my code and posting those into the blog.  As I found this requires integrating a code inserting plug-in for TinyMCE 3.x to insert code into the editor and format it properly and syntax highlighting extension for the actual posted code.  The two I chose were:

David Pokluda’s Windows Live Writer Source Code Plug-in found here. I simply took the BlogEngine.NET bits from the download and followed the instructions to install it.  This download also included Alex Gorbatchev’s syntax highlighter - v. 2.0.296 – found here.  The idea is there is a BlogEngine.NET extension that writes the SyntaxHighlighter js code to the pages.

And the code inserting plug-in for TinyMCE v3.x I got from Nawaf’s Blog found here.

I had to do some tweaking to get the TinyMCE plug-in to work the way I wanted.  By default the plug-in wraps the code in a HTML textarea along with some attributes (settings) in the class attribute.  I really don’t like that approach (having a textarea in a post and or the TinyMCE editor when editing).  So I ended up changing the plug-in code to output a HTML pre tag and mapping some of the settings from the plug-in to the settings of the syntax highlighter code since Alex Gorbatchev’s code looks for a pre tag anyway.

The changes I made to the plug-in were in the codehighlighting\js\codehighlighting.js file and these are the changes I made:

function Save_Button_onclick() {
    var lang = document.getElementById("ProgrammingLangauges").value;
    var code = WrapCode(lang);
    code = code + document.getElementById("CodeArea").value;
    code = code + "</pre>";
    if (document.getElementById("CodeArea").value == '') 
    {
        tinyMCEPopup.close();
        return false;
    }
    tinyMCEPopup.execCommand('mceInsertContent', false, code);
    tinyMCEPopup.close();
}

function WrapCode(lang) {

    var options = "auto-links: true; first-line: 1; light: false; ruler: false; smart-tabs: true; tab-size: 4;brush: " + lang + ";";
    var html = "";

    if (lang == 'js' || lang == 'jscript' || lang == 'javascript')
        options = options + "html-script: true;";
    else 
        options = options + "html-script: false;";
        
    if (document.getElementById("nogutter").checked == true)
        options = options + "gutter: false;";

    if (document.getElementById("collapse").checked == true)
        options = options + "collapse: true;";

    if (document.getElementById("nocontrols").checked == true)
        options = options + "toolbar: false;";

    html = "<pre class='" + options + "'>";

    return html;
}

function Cancel_Button_onclick() {
    tinyMCEPopup.close();
    return false;
}

As you can see most of the changes were to the WrapCode function (if you compare the original to my version side by side).  Other than that nothing really needed to be done to the syntax highlighter code or the BlogEngine.NET extension.

Instructions for installation can be found on each respective website.

Note: There is a bit of weirdness with the TinyMCE plug-in where if there is HTML tags in your code you will need to manually encode them, I am not sure what is going on but I find it's not that much of a big deal.

Enjoy

New Year and New Hosting

I decided not to renew my hosting (Webhost4life) and decided to give Lunarpages a try.  The reason for my move was not because I had any issues with Webhost4life, I have been with them since 2006 and have had almost zero problems with them over the two years I just found that Lunarpages offered some better features and the initial cost was cheaper than renewing.

During my time with Webhost4life I was signed up under the Advanced Windows Plan which gave me some pretty good options especially being a developer I liked the idea of being able to do more with my account.  Here are some of the features that I liked and the things I didn’t like about my experience.

The Good

  • You can connect to your SQL Server using Enterprise Manager (2000) or Management Studio (2005/2008)
  • No SQL Express (this is a good thing)
  • Browser based SFTP Java applet for uploading to your account
  • Allows you to manage your DNS zone (including adding a SPF record)
  • They utilize DNS effectively; SQL Servers have a DNS entry rather than an IP address as well your mail.yourdomain.com resolves to a mail server and your web mail
  • Simple DB tools for MS SQL Server (backup/restore/etc.)
  • You have an FTP site for your Database (to do backup/restore from)
  • You can override your websites physical root folder anywhere in your hosting folder.  This is good if you want to create a subdomain and not put it in a folder under your primary domain
  • They use two SMTP ports for your mail (the reason for the alternate port is some ISPs block all outgoing on port 25 unless it’s to their own servers)
  • Add-on services are pretty cheap like extra domains and such
  • Support is better than average for responding in a timely manner.  You can set the priority on your ticket from 1 (high) to 5 (low).  I usually used 3 and averaged about a 4 hour response time and they addressed my problems without having to give more info or respond.  It seems that they have only one level of support and each support person can take care of the issue whatever it is.
  • Your sites run under full trust (your own app pool)
  • They use awstats for basic web metrics
  • They have an FTP site for your raw IIS logs (they don’t include cookies in the log)

 The Bad

  • They dropped free WSS (Windows Sharepoint Services) you now have to pay $19 a year for WSS 3.0
  • They dropped the MS SQL Server limit to one DB per domain (adv. plan) (it used to be unlimited when I first signed up, then they went to two only and finally one)
  • Your app pool for ASP.NET recycles often (every 5 min) so your site (if big) will seem like it is constantly reloading/recompiling (this might be the norm for most hosting companies since there are probably a lot of crappy coders out there)
  • A high website/server ratio something like 300 sites on one server, I am not sure if this is the norm or not which explains the 5min app pool recycling
  • Like most hosting providers they never tell you when something is wrong, the server where my SQL DB was scheduled to be replaced (do to hardware issues it was having), I tried to do a backup and it kept failing.  I sent a ticket and only then they told me why the issues
  • They have a support forum but it is pretty unutilized by the users of Webhost4life
  • They rolled their own control panel which looks really unprofessional but it does do what it’s supposed to

All in all I have no real issues with Webhost4life; I found the service to be pretty much what I expected from a shared hosting provider but it was time to try something new and give another company a try.

So far with Lunarpages I had a couple of issues (one almost made me cancel my account over).  When my second domain was setup (willyd.ca) right from the start the DNS settings for my MX record (mail) was configured wrong, it was pointing to two separate IP addresses (the web server and mail server) and since the order of the records was web server first I would often not be able to check my mail (using Outlook) since it would try to access the web server (which would not work duh, it’s a web server).  It took me 2 full days to have the problem fixed, mostly because the ticket had to be escalated from a tier one tech support to tier two.  They second issue had to do with the hosting environment and some permissions which took less time to fix probably because the tier one could do that kind of stuff.  Here are some of my initial thoughts for the service so far.

The Good

  • Web mail is SmarterMail (same as Webhost4life)
  • The control panel is Plesk (pretty cool control panel for Windows hosting)
  • There is a backup solution for your domain that you can configure and schedule
  • Windows Hosting allows for 2 unique domains under your account for your initial price
  • Account information (disk space used/bandwidth used/etc.) is all visible from the "home" control panel)
  • Unlimited SQL Server DB’s per account (probably limited by the actual amount of hosting space you get)
  • Their forum support is pretty impressive and the community actually uses it
  • Lots of reports that can be emailed to you on a schedule (part of Plesk)

 The Bad

  • They don’t inform you that they use DNS for databases rather than IP address and no mail.yourdomain.com to web mail (no big deal but it looks cooler)
  • Support is a level system, level ones are pretty much useless and the higher you go the longer it takes to get anything fixed
  • No DNS zone edits under Windows hosting
  • The help files seem to be out of date in the control panel and reference Linux Hosting items more than Windows so the info might not be valid
  • Some services you log into are not SSL (I even checked the form post action)
  • No SQL Server Ent. / Management Studio support; they use MyLittleAdmin (which is pretty much the same interface)
  • I am not sure about this one but it would seem that both domains (under your account if setup) run under the same app pool.  That means that one site could bring down your other site if it gets out of control
  • There is a 1% CPU cap on your app pool.  Reading through the forums it seems that if you go over the 1% CPU usage you account can be disabled.  So if your app pool continuously used 1% of the CPU on that server over an undeterminate time they can axe your site(s).  I guess as long as it just does the burst usage then that is ok (not that my sites will chew up that much CPU)

For the ongoing story of my DNS issues with Lunarpages see New Year and New Hosting Part Deux

Site up up up and away

Finally got a real site up, decided not to roll my own but try out a ready made blog engine.  I already rolled a home brew site willyd.ca which I will be slowly moving away from that site over time.

I have added some of my tech blogs from my other web site just for content, look for some interesting topics and items soon.