Writing an Input Adapter for Particls is quite a simple exercise. Your main concern will be finding something to actually input!
To get started, create a new Class Library project. In this post, I'll discuss implementing a C# adapter, however nothing stops the same being done in any other .NET language (such as VB.NET or even J#.NET).
To be able to implement a Particls Input Adapter, your project will need to reference Particls.Core.dll (in Program Files\Particls).
In your class Library, create a class that implements Particls.Core.Adapters.IInputAdapter. This interface requires implementing the following methods:
- Init(IItemListener pListener, IItemFactory pFactory) - this method will be called as your adapter is first loaded. It provides you with two very important pieces of information. The IItemListener allows you to inject items into Particls. The IItemFactory allows you to create new instances of the Item class - the generic format that Particls passes all information around in. Note that Init does not signal that you should start doing your work - only that you should prepare yourself.
- Finish() - the opposite of the Init method. This will be called when Particls is shutting down your adapter, and requires you to free up your resources.
- Start() - indicates that your adapter should start its work. Note that this differs from Init in that it may be called multiple times if a user chooses to stop and start your functionality.
- Pause() - indicates that your adapter should stop doing its work. Any temporary resources can be freed at this point (if you allocated them in line with your Start method), but your adapter may be required to start again upon a call to Start.
And thats it. Four methods to implement. Now, for a simple implementation.
using System;
using System.Reflection;
using System.Threading;
using Particls.Core;
using Particls.Core.Adapters;
using Particls.Core.Entities;
namespace Particls.SDK.Input.HelloWorldSpam {
public class AdapterBase : IInputAdapter {
private IItemListener mItemListener;
private IItemFactory mItemFactory;
private Thread mGeneratorThread;
private bool mContinueFlag;
private object mContinueMonitor;
private int mItemCounter = 0;
public void Init(IItemListener pListener, IItemFactory pFactory) {
mItemListener = pListener;
mItemFactory = pFactory;
// Init the item counter
mItemCounter = 0;
// No need to allocate anything here - we'll do it in Start.
}
public void Finish() {
// Nothing to do here, since we didn't allocate any resources in Init.
}
public ItemStatus Start() {
mContinueFlag = true;
mContinueMonitor = new object();
mGeneratorThread = new Thread(new ThreadStart(GeneratorThread_Start));
mGeneratorThread.IsBackground = true; // Make sure we can't hold up Touchstone shutdown
mGeneratorThread.Start();
return ItemStatus.Success;
}
public ItemStatus Pause() {
lock (mContinueMonitor) {
mContinueFlag = false;
Monitor.PulseAll(mContinueMonitor);
}
// Wait for the thread to finish
mGeneratorThread.Join();
return ItemStatus.Success;
}
private void GeneratorThread_Start() {
while (mContinueFlag) {
// Generator our Item
Item item = mItemFactory.CreateItem();
// Set all the properties on the item
item.GuID = "Particls.SDK.Input.HelloWorldSpam:" + mItemCounter + ":" + DateTime.Now;
item.Title = "Hello World " + mItemCounter + " " + DateTime.Now;
item.SetPublishedDate(DateTime.Now);
item.Description = "Hello World. This is item number " + mItemCounter;
item.Publisher = "Particls Example";
item.OwnerAdapterAssemblyInformation = Assembly.GetExecutingAssembly().FullName;
item.OwnerAdapterName = "Particls Hello World Spam Adapter";
item.SourceName = "Hello World Spammer";
item.SourcePath = "HelloWorldSpammer";
item.DeclaredImportance = 5;
// Send the item to Particls
mItemListener.HandleItem(item);
// Increment the item counter (so items look different)
++mItemCounter;
lock (mContinueMonitor) {
// Delay for 5 seconds
Monitor.Wait(mContinueMonitor, 5000);
}
}
}
}
}
Build the adapter, and put the resulting Adapter in your Program Files\Particls\Adapters directory. Start (or restart) Particls. The spam should arrive in no time!
Input Adapters Ideas
- RSS/Atom Feed Reader (You can make one way better than ours)
- Azureus (or other Bittorrent Client) download monitor
- Newsgater Alerts – Tap into newsgater’s syndication platform
- Microsoft Money Monitor (any overdue bills?)
- Stock quotes and other financial information
- Salesforce CRM tracking
- eBay auction tracking (is your auction closing soon?)
- mySpace messaging tracker (do you have any new messages?)
- Digg tracker (new news on the front page)
- An adapter, adapter (something that allows script kiddies to make simple scripts to inject items)
- A Footiefox.com adapter to feed current soccer match scores
- A cyclr.com adapter which feeds your current balance (total or regarding your best friends) and allows you to quick-add new obligations
- geoRSS adapter, filter feeds according to location (just show me stuff thats about London)... and corresponding output adapter mapping
Comments (0)
You don't have permission to comment on this page.