In a previous blog post I covered how to create a Windows Live Writer plug-in and then provided the plug-in for download. The plug-in solves the problem of inserting Source Code Syntax formatted code snippets into a WordPress.com hosted blog post from within Live Writer. There are many Plug-ins that can be used with your own hosted WordPress blog but these don’t work with WordPress.com hosted blogs. This plug-in supports only WordPress.com blogs by inserting the relevant ‘ShortCode’ tag around your code that is required for WordPress to syntax highlight your code. As the plug-in has proved popular I’ve taken the time to update it to Version 1.1.
Since developing the first version WordPress have added extra functionality to their SourceCode shortcode. It now supports additional languages and provides more control over how the code snippet appears in your post. Some of the neatest new features include an option to specify specific lines of code within the snippet to highlight, and the ability to control the line number to start line numbering at.
Full Feature List:
| autolinks | Makes all URLs in your posted code clickable. |
| collapse | If true, the code box will be collapsed when the page loads, requiring the visitor to click to expand it. Good for large code posts. |
| gutter | Hides line numbering on the left side will be hidden. |
| firstline | Use this to change what number the line numbering starts at. |
| highlight | You can list the line numbers you want to be highlighted. For example “4,7,19″. |
| htmlscript | Highlights HTML/XML in your code. This is useful when you are mixing code into HTML, such as PHP inside of HTML. |
| light | A light version of the display, hiding line numbering and the toolbar. This is helpful when posting only one or two lines of code. |
| padlinenumbers | Allows you to control the line number padding. Options are automatic padding, no padding or a specified amount. |
| toolbar | Show or hide the toolbar containing the helpful buttons that appears when you hover over the code. |
| wraplines | Turn wrapping on or off. |
Checkout the WordPress support site for more detail on these.
The list of languages selectable within the Plug-in has been increased to include all the new ones now supported by WordPress. The current list is: actionscript3 , bash, coldfusion , cpp , csharp, css, delphi, erlang, fsharp, diff, groovy, javascript, java, javafx, matlab, objc, perl, php, text, powershell, python, ruby, scala, sql, vb, xml.
I’ve also provided a mechanism to modify the list of languages displayed in the Plug-in. This is useful for two reasons. Firstly it enables you to reduce the number languages in the dropdown list down to just the one’s you are likely to use. This can make the Plug-in slightly easier to use. Perhaps more important however is the fact this enables you to modify the list if WordPress.com decide to update their shortcode to support an additional language and you need to utilise this before the next version of my Plug-in is released. Just add the new language name to the list and away you go.
To modify this language list you need to have a text file named SyntaxHighlight_WordPressCom_WLWPlugIn.txt located in the same folder as the Plug-in (usually C:\Program Files\Windows Live\Writer\Plugins). The download Zip file for the V1.1 version of the Plug-in contains this file. Locate it with the plug-in and then it’s there for when you want to modify the list in the future. Interestingly if you don’t want to make use of this feature then it is optional and the text file is NOT required for the Plug-in to work (you’ll just get the full language list by default).
I have changed the display that is inserted into the Editor view when a snippet is inserted. Previously all code text and the shortcode tag was added to the Editor view. To improve readability of the code you’ve inserted a change has been made to only show the code and not the ShortCode tags. This is particularly useful now that the Shortcode tags are potentially longer with the new supported attributes.
A link to the WordPress.com sourcecode tag support page is also now included in the property editor for inserted code snippets.
The “Live Writer Source Code Plugin For WordPress.com” Version 1.1 is available for download here.
Filed under: Blogging, Live Writer, Tools, Wordpress | 3 Comments
Tags: Live Writer, WLW, Wordpress
I’m a fan of Windows Azure and have enjoyed using it during its CTP phase. Once the CTP was open for registration like many I jumped at the chance to play with this new paradigm in Software Development. During this CTP phase I have written some small private web applications that really do nothing more than experiment with the Azure platform. These have provided me with valuable experience and an insight into building a ‘real’ world application on ‘Azure’. I have also used this knowledge to demonstrate Azure to my colleagues and to promote the platform within my enterprise. All this has been possible due to the fact that the CTP version is completely free to use, however this period of experimentation will soon sadly come to an end.
As Windows Azure moves from a free to use CTP to a commercial product it is right that users have to pay for the privilege of using the platform but it seems that many developers are going to have a hard choice to make in the new year. Do you forget about developing on Azure or do you fork out $86/£55 a month for the privilege of experimentation. For those with an MSDN Premium Subscription they’ll have some more time to enjoy it free, but in 8 months the same decision will be required.
Windows Azure pricing details can be found here but if we assume that the transaction and storage costs are minimal for a developers experimental site and just take
the basic cost of running one instance per hour it is $0.12 (sounds cheap) but if we consider that there’s 24 hours in a day, 7 days a week etc the cost for a month is around $86 (£53). That’s not a small amount for the average developer to find. Whilst I am pleased by the free hours provided for MSDN subscribers this is a limited offer and it’s really just delaying the problem for those developers. That is unless Microsoft can come up with a basic cheaper proposition similar to the shared web hosting model. If a developer wants to experiment with web technologies for example they can host a web site (for public or private use) with a 3rd party web-hosting company. These hosting companies provide a selection of options based on your requirements. Whilst premium dedicated server hosting is available developers can get their fix from the cheap and cheerful shared server hosting which will provide most of the features on a smaller scale for around $10 (£6) per month. I realise that there is more to Azure than hosting a web site but the point is that you can only really experience a product when you are frequently interacting with it to build something real, and therefore it has to be accessible.
Now I’m not saying Azure is uncompetitive compared to it’s rivals (it actually competes favourably) or that you don’t get your money’s worth. For a new business starting up with some expected revenue then Azure provides huge advantages and the ability to scale up and down is ideal. It’s getting the developer community interested and informed that is the problem. Microsoft needs developers to buy-in to this seismic shift in computing and by making the barrier to entry so high it is making it difficult to spread the love for this excellent product. I believe that it is in Microsoft’s interest to provide some way to get grass routes developers to buy into this product and to gain exposure to it.
I hope that in the new year we will see a new low cost (even advertisement funded) offering for Azure aimed at getting developers tuned in and coding on this great platform without making a large financial commitment. I’m not alone in hoping for this, check out the requested feature list for Azure (the most popular by far at the time of writing is just this, a low cost option).
Filed under: Cloud Computing, Windows Azure | 2 Comments
Tags: Cloud, Windows Azure
The Java Runtime on my Dev machine prompted me to Update with a new Version. It didn’t prompt nicely via a little notification popup in the System Tray but instead blows straight into a full UAC prompt. Anyway in a moment of revenge I decided to turn off the ‘Auto Update’ feature. I opened the Java Control Panel and found the Update tab shown below:
I unchecked the “Check for Updates Automatically” option and then got this rather amusing ‘Warning’:
After guessing which button did what I closed the dialog to see this:
No matter how many times I try the same thing happens. I’m guessing that this is either:
- A very secret warning message that not just any mere mortal can read.
- A very obscure tactic to convince users not to turn off auto updates.
- A bug.
You decide.
Filed under: Uncategorized | Leave a Comment
Tags: Odd, UI
I have five years of Mini-DV Camcorder tapes stacked up on my shelve. My plan has always been to transfer the video off onto my PC and then reuse the tapes, but for various reasons this never quite happened, instead the pile just grew bigger and bigger. Not for any longer though as I am refusing to buy anymore tapes and forcing myself to get the video transferred.
Firstly I need to connect the camera and as my camcorder is a Sony its the good old Firewire card and unfortunately Windows 7 (and Vista before it) refuses to recognise it. After some messing about and moving slots (why oh why did Microsoft remove the ability to manually adjust IRQ settings?) I give up and order a new card (a Belkin 3 port FireWire PCI card) which happily Windows 7 finds and embraces straight away. My Sony then appears in Windows in the list of devices in "My Computer".
Now I have the connectivity I need the software to import the data in. There are numerous options but I already have two installed; Nero and Windows Live Movie Maker. Windows Live Movie Maker replaces Windows Movie Maker but is not included in the Windows 7 installation but instead is part of the free Windows Live Essentials pack for download separately. Nero Vision does a good job but Windows Live Movie Maker provides the option to automatically split the video into multiple files. It seems more natural to me to have a collection of video files instead of a monolithic 60 minute video. Separate files also makes it easy to quickly remove scenes and include extra ones later when adding the video to a DVD.
Importing via Windows Live Movie Maker:
1) Open Movie Maker and select “Import from device” from the top menu.
2) Select device:
3) Name the video and pick options:
To create multiple files instead of one monolithic file check the bottom checkbox.
4) Ok the options dialog and click Next, then sit back and wait for the video to stream. It will take as long as the length of video you’re streaming takes to play. If you selected to import the whole tape the video will play for the length of the tape and then will spend around 5 to 10 minutes to splitting up the file.
WARNING: It takes a lot of disk space to import video, with a 60 minute tape creating about 12GB of video files. Make sure that you have plenty of free space before you start to import the video. Also if you have chosen to split the video into multiple files you will need to have double the free space. This is because a single file is created initially (e.g. 12GB) and then the multiple individual files are created before the original is deleted which means that there will be twice the amount of data during this process (e.g. 24GB). If there is not enough disk space to create the individual files then Movie Maker will just inform you that it is unable to split the video into multiple files and you get left with the single file. You would then need to free some more space and then re-import the video again to end up with the desired collection of multiple videos which is a waste of a valuable hour of your life.
What format should I save the Video in?
Now that the video is imported I want to keep it in a digital format but should I store it? Well I wanted to create DVDs from the tapes and so I am using Nero for this purpose as I like the way it creates the DVD menu’s etc. DVD maker included with Windows 7 could alternatively be used for this purpose however. Creating the DVD is not so much for storage but for portability. I like the fact that I can watch my videos on any DVD player but it’s not the ideal way to store the video for the future. Video is compressed down to get it onto a DVD and although the quality is still very good it doesn’t maintain the complete raw format that ‘might’ be useful in the future when converting to new and improved video formats. When looking around for a format to store this 12GB/hour video it occurred to me that although this was a large amount of data it is in fact getting smaller by the day anyway as technology improves. When digital cameras first came out people were looking for ways to compress their images as several MB per photo seemed hard to store. Of course we now take it for granted that a photo is 5MB and hard drives are now sold in the Terabytes meaning it is less of a problem. So I’ve decided to keep my video in it’s raw AVI format for the foreseeable future, and have stored it on my already bulging Windows Home Server.
Filed under: Tips, Windows 7 | Leave a Comment
Tags: Movie Maker, Video Editing, Windows 7
Many development teams still regularly use Visual SourceSafe for their source control which can stimulate heated debates between those that have used it for many years without problems and those that have suffered some pain with it. Regardless of this debate there is no denying that SourceSafe is coming to the end of it’s useful life. It’s old technology and will come out of support in 2011, although a compatibility update is expected with Visual Studio 2010.
When Microsoft developed it’s replacement, Team Foundation Server (TFS), it focused on providing more than just a source control product but a whole development lifecycle management system. Regardless of the benefits of TFS (and there are many) it has been avoided by many small development teams due to its high costs and complex installation/management. Many have instead moved to alternative source control products such as the free Subversion, leading to a decline in Microsoft’s market share in this area.
So, what’s changed? Microsoft now plan to provide a ‘Basic’ version of TFS 2010 when it ships next year. I think that this is a huge step forward for TFS and it’s take up across the development community. Brian Harry details the ‘Basic’ version in this blog post. This version of TFS will have a fast and easy installation and provides many more implementation options for the product. It will install on SQL Express 2008 and can even be installed on Client Windows Operating Systems. This really is targeting the current SourceSafe users and provides a low cost (perhaps even free) entry to the benefits of TFS. You might think that this would only provide basic TFS functionality but no so. Included in the basic version is Source Control, Bug Tracking and Build Automation, which provide the bulk of the key TFS features. The screenshots also suggest that Web Access is also included. What’s not included is Report Services and SharePoint, which are arguably more geared towards the larger development teams anyway. The key benefits from TFS come from the Work Item interaction and ‘Continuous Integration’ friendly automated build features and these are included.
The move to TFS for a SourceSafe (or any other simple source control system) team will provide many benefits and this version should enable those benefits at a minimal cost. There are no details on pricing but personally I would expect it to be included in the Team Developer MSDN subscription.
SourceSafe is also used by hobbyist and professional developers to manage their own personal source code and I see this version of TFS being ideal for this. The ability to install on a client OS is a major factor to these users. There is also a comment on Brian’s blog post about running TFS basic on Windows Home Server which is something I am keen to try out.
By allowing more people to access this great product it will greatly contribute to the TFS community and it’s take up globally. If you can’t wait until TFS 2010 is released and would like to know more about TFS versus SourceSafe in terms of pricing then check out Eric Nelson’s post here.
Filed under: Team System, Tools, Windows Home Server | Leave a Comment
Tags: SourceSafe, TFS, Visual Studio, VS2010
I recently setup a new Windows Home Server and this post covers why I chose this operating system and how I setup my server.
Requirements:
My requirement was for an extendable ‘always on’ network attached file storage solution that would allow me to access my files from any machine in the house (and ideally remotely via the Internet when required) whilst providing some fault tolerance data protection. Having all my data in one place makes it easier to manage (less duplication of files across machines) and easier to back-up. This centralisation of data however means being more susceptible to hardware failure (e.g. hard disk failure) and so a solution with either a RAID configuration or something similar was required which ruled out most budget NAS Storage devices. After investigating the options I decided to build a Windows Home Server (WHS). This meets all the requirements above and also adds other neat features such as the extensible Add-In model (a huge bonus for a .Net developer like me).
Buy vs Build:
Having decided on Windows Home Server as the solution the next step was to decide whether to buy or build. There are several very smart WHS devices available from manufacturers like HP and Acer. Whilst these are the easy option they are not the cheapest or the easiest to extend. Also the availability of these devices varies depending on your geographical location. Based on these factors I decided to build.
Build Option:
The fact that WHS has such modest hardware requirements means that building a server is a very economical option. As my server will be ‘always on’ I put power efficiency as a key requirement in my build. To this end I considered the Intel Atom processor found in most ‘NetBooks’. These consume little power and pack enough punch to run WHS comfortably. The Atom CPU comes pre-attached to an Intel motherboard (you can’t buy them separately yet) for under £50. However as I wanted the storage in my server to be extendable and grow over the next few years I needed the space for at least 4 hard drives but the majority of Intel Atom boards only come with 2 SATA ports. Some boards do exist with four SATA ports but they are hard to source. Another possible Atom drawback is that it may be difficult to source Windows 2003 drivers (required for WHS) for ‘NetBook’ targeted Atom motherboards.
Buy Option:
Eventually after some investigations I had a list of parts to build into my shiny new server, but also a few reservations. Firstly would all these components play nicely together and would the build be solid enough to meet my ‘always on’ requirement. After discussions with a colleague he suggested I look for pre-built end of line servers, which is what I did. I quickly found the HP Proliant Ml110 G5 going for £170, bargain. With 1GB RAM, Dual Core Pentium 1.8Ghz CPU, on-board video, Gigabit NIC (Network Interface Card), 160GB HDD, DVD ROM and a multitude of SATA ports it was ideal.
Sure it lacked the power saving benefits of an Atom processor based server but it’s solid Enterprise level build quality more than makes up for it. As the server is designed to run Windows 2003 drivers would also not be a problem.
![]()
For storage I purchased two Western Digital Caviar Green 750GB SATA drives to sit alongside the HP’s 160GB disk. By buying two I can make full use of WHS’s data duplication features to protect my data. Whilst the ‘Green’ branded disks are not as fast as traditional drives they are packed with energy saving features which I value in an ‘always on’ server.
![]()
Hardware:
After much deliberation on whether to use the faster 160GB drive or the larger 750GB drive for the system drive I decided to install a 750GB drive as the system drive, mainly to ensure maximum extendibility. Whichever I installed as the system drive I would be stuck with (without reinstalling the Operating System) and I didn’t want to be limited to the smaller 160GB drive. To make installation of the OS easier I only connected up the first hard drive, and then connected the other two later once the OS was up and running.
Software Installation:
Once the hardware was sorted I put in the WHS DVD and followed the instructions. The installation went quicker than expected, surprisingly not spending long on performing the ‘Microsoft Updates’. Once installed I logged on to find that WHS didn’t have the right NIC (Network Interface Card) drivers and therefore the NIC hadn’t been installed. This of course explains why I didn’t have to wait for the install to download the updates as it couldn’t get on the web to find them. I installed the NIC drivers from the HP CD and rebooted to find that I could now access the internet via Internet Explorer but neither ‘Windows Update’ nor ‘Product Activation’ would connect. After further investigation (and much head scratching) I found this error in the Windows Event Log:
Type: Error. Source: W32Time.
Description: Time Provider NtpClient: An error occurred during DNS lookup of the manually configured peer ‘time.windows.com,0×1′. NtpClient will try the DNS lookup again in 15 minutes. The error was: A socket operation was attempted to an unreachable host. (0×80072751)
Checking the System Time revealed I was two years in the past (2007) for some unknown reason. After correcting the date I could connect to Windows Update fine. After a mammoth 70 updates and a reboot I’m presented with a strict ‘Activate Now’ prompt on logon. I presume that since my WHS install believes it has been installed for two years without activation it thinks it’s time to get serious. After I activate it I ran Windows Update again and this time it installs 5 more updates. Once the OS is stable I connect up the extra hard drives and add them to the storage pool via the WHS Console Server Storage tab.
Clients:
In order to connect to your Client PCs the server and Clients need to be in the same Workgroup making this alignment the next task, along with checking for useful machine names/descriptions. Once all the clients are ready I installed the Client Connector software on each client (all Windows 7 clients) and configure their backup schedules. All clients connected and performed a successful backup first time.
Before copying across all my data onto the Windows Home Server Shared Folders I made sure that ‘Folder Duplication’ was turned off. This was purely to maximise the transfer speed (as WHS didn’t have to perform any duplication during the copy process) but I made sure I turned ‘Folder Duplication’ on for all folders after the data was in place.
Setting up a Printer Server :
Next I wanted to set-up my server as a Print Server ensuring that I could print from any machine without having to turn on the Desktop hosting the printer first. The printer is a basic Lexmark Z615 but there are some unsupported Windows 2003 drivers on the Lexmark site. After trial and error with these though I abandoned them and reverted to the XP drivers which worked ok. I did have to reboot several times though to completely remove the failed printer installed with the Windows 2003 drivers.
An annoying feature of Windows is that it searches the local network for other printers and adds them to the server. I don’t want ‘Print to OneNote’ and ‘XPS Document Printer’ printers on my server but deleting them is pointless as they will reappear. To prevent Windows from performing this auto search you need to turn it off by deselecting the option in: My Computer > Tools > Folder Options > View > “Automatically Search for Network Folders & Printers’.
With my print server setup I attempted to add the printer to my Windows 7 client, but this was to prove difficult too. I couldn’t find an option to specify the correct drivers to use for the Printer and the Vista printers (needed for Windows 7) weren’t installed on my server. In the end I found this blog post where it explains how to use the Print Manager tool (new to Vista Sp1) to add additional drivers to your print server. This worked perfectly and on the next attempt it downloaded the Vista drivers correctly and installed the printer successfully.
WHS Add Ins:
I intend to install and (time permitting) write plenty of Add Ins for use with WHS as I think that they are an excellent way to add functionality to your server. So far I have installed the Microsoft WHS Toolkit v1.1 and Andreas M’s Advanced Admin Console. I find the Advanced Admin console useful for accessing admin tools via the Console without having to Remote Desktop into the server each time. Over the next few weeks I hope to review the Power Management Add-Ins and install one to help my server to get a few hours sleep over night when it’s not required, thus saving power and money.
Summary:
So that’s my build story. My home server is up and running and I’m so far very impressed with it. I aim to post some more articles about Windows Home Server over the coming months.
Filed under: Windows Home Server | 1 Comment
Tags: Home Networking, WHS, Windows Home Server
Windows Home Server
I have recently set-up a home server using the Windows Home Server Operating System. The details of the set-up will follow in a future post but firstly I thought I would quickly introduce the Windows Home Server (WHS) product and provide some useful links.
Windows Home Server was released by Microsoft in 2007 and is built on top of Windows Server 2003. It’s role is to sit quietly in your home and automatically backup all your PCs, provide NAS (Network Attached Storage) file sharing features, media streaming and remote access. It’s protects your data from hard drive failure by duplicating your data over multiple drives where you have a multi-drive system.
WHS can be bought pre-installed on custom devices from companies like HP and Acer or you can install it yourself on your own kit. As the hardware requirements are so light its possible to get it running on an old PC you might have lying around. Alternatively build or purchase a cheap low end PC for the purpose.
Particularly of interest to developers is the WHS Add-In model. WHS can be extended through the use of ‘Add-Ins’ from various ISVs (Independent Software Vendors) and enthusiast developers. Microsoft provides a Windows Home Server Add-In SDK for .Net Developers wanting to write Add-Ins for WHS and Brendan Grant has Visual Studio project templates on his blog.
Here’s a selection of links for more information:
Filed under: Windows Home Server | Leave a Comment
Tags: WHS, Windows Home Server
Nokia E71 – An update
In May posted an entry about my new Nokia E71 smart phone. This is a quick update post and I can confirm that the novelty factor has still yet to wane. I’ve found more uses for my E71 than I originally expected. In addition to the applications listed in my original post I have since downloaded these apps:
-
Twibble: If you do that ‘Twitter’ thing then this application is an excellent mobile client that makes it easy to keep up to date on the move, and it works great on the E71.
-
* UPDATE: I’ve since dumped Twibble for Snaptu. The Twitter client is excellent on Snaptu and you gain from the extra plugins such as RSS readers, FaceBook etc. *
-
Snakes: A new 3D take on the old Nokia ‘Snake’ game. The link I used for this is no longer valid, but it might still be available on the Nokia site.
-
Top Hits Solitaires: A nice selection of basic card games.
-
Global Race – Raging Thunder: A very smart driving game.
-
Ovi Store: Despite Nokia’s efforts this is no Apple iPhone ‘App Store’ but it’s worth having a look through the list of available applications for your Nokia phone periodically as there are a lot of apps available and many are free.
I listen to lots of podcasts and I’m finding that the E71 makes this so easy through its in-built Podcasting application. It enables you to add podcasts to your regular download list by searching by podcast name or you can just add the feed URL if you know it. You can then check for updates and download them for playing on the phone manually or automatically. The phones in-built speaker is solid too. It’s loud and clear enough to listen to in the car whilst travelling without the need for an additional FM Transmitter.
I find the Opera Mini browser makes mobile browsing really easy and slick on the E71. It’s very fast and easy to use, adjusting the view of the page to fit neatly on your screen minimising the amount of scrolling required per page.
All in all I’m still enjoying my E71 and am starting to wonder how I managed without it. My first months data transfer amount was a eye watering 1 GB of data which shows the extent to which I’ve been maximising the phones 3G connectivity features.
Filed under: Gadgets, Symbian OS | Leave a Comment
Tags: E71, Symbian
Recently someone asked me how I managed to access a list of files on my machine from a pop-up list on the Windows Taskbar. The ability to add folder links to the Windows Taskbar has been around for many versions of Windows I guess still not everyone realises how easy and/or useful it is. I find it helps my productivity and because they are very easy to create and remove it sometimes helps to create them for short to medium term use too.
To add a folder as a toolbar on the taskbar just right click on the taskbar, pick ‘Toolbars’ and then ‘Create Toolbar…’. This displays the ‘New Toolbar’ dialog which is basically just a folder picker for you to select the folder you want to display.
Once you’ve picked a folder, that’s it! Now you can move it around on the taskbar like any other toolbar. To remove it, just right click the taskbar again, pick ‘Toolbars’ and unselect it.
Filed under: Tips | Leave a Comment
Tags: Tips
Syntax Highlighting in WordPress.com hosted blogs and how to create a Windows Live Writer Plug-in
There are various ways of displaying code in a blog entry. Some authors insert images which enable them to ensure that the code is readable and in the required format, however the code can’t then be as easily viewed inside some feed readers, and the text is not searchable or easy to copy/paste. Alternatively an author can just type the text in and use indentation and font styles to distinguish it from the body of the text. By far the best solution however is use a Code Highlighter of some sort that will render the code into a readable format with additional benefits of copy to clipboard, line numbers and colour coding. One popular tool for this job is Syntax Highlighter by Alex Gorbatchev. This uses JavaScript to render the code on the client in a very readable format (see below). It integrates well with the WordPress blog engine and there are several Windows Live Writer Plug-ins for it making it easy to add code snippets to your posts.
Having decided on using Syntax Highlighter for my blog I hit a problem. I’m hosting on WordPress.com and therefore do not have the access required to add it to my site. I found a lot of posts on the web discussing how to integrate it with WordPress but these are for self hosted WordPress.org blogs. Eventually however, to much delight, I found that the WordPress.com developers themselves have already integrated Syntax Highlighter. There is a list of supported languages and details on how to use it here. To activate it you just add a wrap your code inside special tags. Excellent!
Writing a Windows Live Writer Plug-in (Part One)
My next thought though was that I needed to integrate into Windows Live Writer via a plug-in. I couldn’t find a WordPress.com specific plug-in so I fired up MSDN and looked at coding one. All the information you need is on MSDN here.
There are two types of plugins. Simple and Smart. As I just needed to add a block of code text surrounded by special tags I figured I would implement the simple type. Simple’s good! Right?
To start with I needed to create a new class library project, reference the Live Writer API (windowslive.writer.api.dll), and add a new class which derived from ‘ContentSource’ and has a ‘InsertableContentSourceAttribute’ attribute.
InsertableContentSourceAttribute("Highlighted Source Code")]
public class MyPlugin : ContentSource
{
}
Next override the CreateContent method on the base class. This is the method that gets called when the user clicks to activate our plug-in to insert some content. It returns a DialogResult and has a string parameter passed by-reference called ‘newContent’. This string parameter is how you set the text to be inserted into the blog post. In the code example shown below I am displaying a form for the user to enter the code block to insert. The form adds the required WordPress.com wrapper text and then the ‘newContent’ string is set to be the whole text content (code plus wrapper text):
public override System.Windows.Forms.DialogResult CreateContent(System.Windows.Forms.IWin32Window dialogOwner, ref string newContent)
{
using (codeEntryForm entryform = new codeEntryForm())
{
entryform.StartPosition = FormStartPosition.CenterParent;
DialogResult result = entryform.ShowDialog(dialogOwner);
if (result == DialogResult.OK)
{
newContent = entryform.GetData();
}
return result;
}
}
In addition to overriding the CreateContent method the WriterPluginAttribute needs to be set on the class. This basically provides Live Writer with information about your plug-in. For an explanation of the properties see here.
[WriterPlugin (
"BF15A85A-9668-480d-9FC2-EC5C16FC140D",
"WordPress.com Syntax Highliter Plugin",
ImagePath = "Images.image.bmp",
PublisherUrl = "http://www.richhewlett.com/",
Description = "Inserts WordPress.com code highlight tags around code snippets",
HasEditableOptions=false)
]
Once done compile it up and copy the assembly to the Plugins folder of your Windows Live writer installation (e.g. C:\Program Files\Windows Live\Writer). When the application starts all the plug-ins in that folder get loaded too. I now had my Syntax Highlighter plug-in, and it worked. I could insert code into my blog post and upload it to the server for WordPress to display using Syntax Highlighter.
Job done then hey? Well not quite. As I had coded this as a SimpleContentSource plug-in once the code snippet had been inserted into the post editor it was treated as plain text (just as if I had written it by hand into the editor). This meant that if I flipped between the Editor and Source windows Live Writer converted my code text to use escape characters. This meant that my code snippet’s quotes and ampersands etc were converted to their friendly alternatives, and WordPress.com would display them without converting them back.
Writing a Windows Live Writer Plug-in (Part Two)
In order to resolve the issue of Live Writer treating my code snippets as regular text I went back to MSDN and found that the SmartContentSource plug-in type provides more control over the HTML that gets sent for publishing. SmartContentSource plug-ins are not treated as regular text and provide more control. Building this type of plug-in is only slightly more work than the less smart plain ContentSource type.
Firstly I needed to change the plug-in class (from above) to override SmartContentSource instead of ContentSource.
[InsertableContentSourceAttribute("Highlighted Source Code")]
public class Plugin : SmartContentSource
{
}
Then we override the CreateContent method as we did before. Live Writer creates a ISmartContent object and passes it in for us to update with the content the user creates. Again as before this example has a dialog box being shown to the user for them to key the code snippet but this time the data is set within the ISmartContent properties.
public override System.Windows.Forms.DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent newContent)
{
using (CodeEntryForm entryform = new CodeEntryForm())
{
entryform.StartPosition = FormStartPosition.CenterParent;
DialogResult result = entryform.ShowDialog(dialogOwner);
if (result == DialogResult.OK)
{
newContent.Properties.SetString("OutputHTML", entryform.GetData());
newContent.Properties.SetString("RawCode", entryform.GetRawCodeSnippet());
newContent.Properties.SetString("SelectedLanguage", entryform.GetSelectedLanguage());
}
return result;
}
}
N,B: The reason I’m setting the ‘RawCode’ and the ‘SelectedLanguage’ properties as well as the combined total output is for use later when we want to display the dialog to the user again pre-populated.
In order to ensure that the correct text is being passed to the blog engine for publishing we override the GeneratePublishHtml method. The ISmartContent object passed in has the original data set as one of its properties so in this example I just return that.
public override string GeneratePublishHtml(ISmartContent content, IPublishingContext publishingContext)
{
return content.Properties["OutputHTML"].ToString();
}
This gets around the original problem that I experienced with the first ContentSource plug-in. Also SmartContentSource plug-ins benefit from being able to be edited via an editor view. This means that when an inserted code snippet is selected in the Editor in Live Writer we can display our own properties bar on the right hand side. To use this feature we need to add a UserControl to our project and make it derive from SmartContentEditor. We then add relevant controls to it to interact with our Content (i.e. code snippet). In my case I just added a link label control to re-launch the dialog box for the user to modify the code within the currently selected content (code snippet) in the editor. Once complete then override the CreateEditor method and return our own UserControl object as a SmartContentEditor object .
public override SmartContentEditor CreateEditor(ISmartContentEditorSite editorSite)
{
return new MySmartContentEditor();
}
An important point is that only one instance of the plug-in is used in Live Writer for all instances of content being inserted. For example you may add multiple code snippets into one blog post but only one instance of your plug-in will be created and reused, therefore you cannot store any state information specific to an individual content items (i.e. Code snippets) within the plug-in. That’s why the data is always passed in to these methods we have been overriding.
Compile it up and copy the assembly to the PlugIns folder of your Windows Live writer installation (e.g. C:\Program Files\Windows Live\Writer\Plugins) to test. This time the content added using SmartContentSource is treated as special and is not converted as you flip between the Editor and Source views.
To extend the plug-in further its possible to update the ‘WriterPlugin’ attribute property ‘HasEditableOptions’ to true and override the ‘EditOptions’ method to display an options dialog to the user. This means that you can let the user modify settings for your plug-in.
As you can see the plug-in model for Windows Live Writer is very simple and productive. It is surprisingly easy to quickly produce useful plug-ins.
If you want to make use of this plug-in for making it easier to add highlighted code to your WordPress.com blog then feel free to download it here.
Filed under: Live Writer, Tips, Tools | 6 Comments
Tags: Live Writer, WLW, Wordpress
Recent Entries
- New Version of Source Code Syntax Highlighting Live Writer Plugin for WordPress.com blogs
- Windows Azure Experimentation Is Currently Too Expensive
- “Java Update Secret Warning” or “You WILL Auto-Update”
- Capturing your Camcorder DV Video with Windows Live Movie Maker & Windows 7
- Team Foundation Server ‘Basic’ Edition
- ‘Windows Home Server’ Build & Setup
- Windows Home Server
- Nokia E71 – An update
- Folder Based Toolbars on the Windows Taskbar
- Syntax Highlighting in WordPress.com hosted blogs and how to create a Windows Live Writer Plug-in
- Bing (without the Bling)
Categories
- Architecture (2)
- Bing (1)
- Blogging (1)
- Cloud Computing (4)
- Deployment (2)
- Gadgets (4)
- IIS (1)
- Live Mesh (2)
- Live Writer (2)
- Smart Client (3)
- Symbian OS (3)
- Team System (2)
- Tips (8)
- Tools (3)
- Uncategorized (3)
- WCF (1)
- Windows 7 (1)
- Windows Azure (6)
- Windows Home Server (3)
- Wix (1)
- Wordpress (1)

Follow me on Twitter