Simon Fell > Its just code > BlogThis

Tuesday, April 8, 2003

I should of gone to bed, instead I started looking at the Synderilla code to prototype up my blog this extensibility point idea. I have the extensibility point working, although the plug-in does nothing more interesting than message box the XML, but I find its easier to explain ideas with code than words.

First off, we need a common interface definition for all the tools to reference, I just wanted something simple, so went with this

using System;
using System.Xml ;

namespace Syndication.Extensibility
{
	public interface BlogThis
	{
		void BlogItem(XmlDocument rssFragment) ;
	}
}

Then I wrote my "plug-in" that implements this interface

class test : Syndication.Extensibility.BlogThis
{
	public test()
	{
	}

	public void BlogItem ( System.Xml.XmlDocument rssFragment )
	{
		System.Windows.Forms.MessageBox.Show(rssFragment.OuterXml) ;
	}
}

Then I modified Syderilla to add a BlogThis context menu and for it to dynamically load the plug-in and call it

public void BlogThisItem(NewsItem item)
{
	XmlDocument xml = BuildRssFragment(item) ;
	Console.WriteLine(xml.OuterXml) ;

	Type typePlugin = Type.GetType("test, test") ;
	Syndication.Extensibility.BlogThis bp =
		(Syndication.Extensibility.BlogThis)Activator.CreateInstance(typePlugin) ;
	if(bp!=null)
		bp.BlogItem(xml) ;
}

Compile everything up, drop test.dll and blogthis.dll into the same directory as Synerilla.exe and fire it up, click BlogThis, up pops my message box. :)

Currently the type of the plug-in class is hard coded in the GetType call, that just needs pulling out into some config value, and then just wire an implementation of BlogThis in my RESTLog client and its done. It would also be easy to write a plug-in that exposes the data as XML/Sockets as Sam has been talking about, for extensibility outside of .NET