Rory:
One morning while creating an invoice and looking back over the timesheet for the software consulting I had been doing I noticed that I had forgot to enter my time for one day a week earlier. If only I had a simple way to enter my time daily. How about a Twitter style application - I could send an instant message that would automatically update our time keeping system with the date, duration, and description of the work I had done.
The Windows Service Architecture:
This program consists of a Windows Service that is running while our Windows Server is active. The service is using the DotMSN to listen for instant messages.
The plugin architecture: This system is extensible through a set of plug-ins that implement one function: MessageRecieved(string text). The Windows service will only load plug-ins that implement that function by inheriting the following interface:
using System;
namespace ActionPlugin.Common
{
///
/// Interface for the MessengerService plugins. Each plug-in that is
/// developed for the MessengerService must implement this interface.
/// </summary>
public interface IMessengerPlugin
{
/// <summary>
/// Authentication method
/// </summary>
bool MessageReceived( string text );
}
/// <summary>
/// This class allows metadata to be defined that
/// identifies the class that implements the
/// IMessengerPlugin interface and will be loaded
/// by main application.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class CommonMessengerPluginAttribute : Attribute
{
}
}
When a text message is received all loaded plug-ins are notified through there MessageRecieved function. Each individual plug-in parses the message and applies a specific behavior using the message data.
For example:
If the text message read "3h rhallman worked on C# develpment" then the timekeeping plugin would recognize that this was a timekeeping entry for the user rhallman who worked 3 hours on C# development and make an entry into the timekeeping system.
If the text message that the Windows service recieved read "Movie Add rhallman Superbad" the timekeeping plugin would discard the message since it is not in a 'timekeeping format' and the netflix plugin would read the message and Superbad to the movie list for rhallman (Keep an eye out for our blog on the upcoming Netflix API.
Conclusion:
This Twitter like technique can be helpful in many real world situations and with plugin architectures you can fully leverage this technique for your business or personal use.