The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024


[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

RE: xFx How-To #2: creating a simple xFx plugin


  • Subject: RE: xFx How-To #2: creating a simple xFx plugin
  • From: Edward Pearson
  • Date: Sat, 06 Mar 2004 12:25:00 +0000

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<TITLE>Message</TITLE>
<DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial" color="#0000ff"
size="2">Stuart,</FONT></SPAN></DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial" color="#0000ff"
size="2"></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial" color="#0000ff" size="2">many
thanks for posting this example; tutorial stuff like this makes it so much
easier for people (like me) to climb up that first, very slippery, part of
the learning curve.</FONT></SPAN></DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial" color="#0000ff"
size="2"></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial" color="#0000ff" size="2">I'd
like to do the exercise and I'll post my experiences here to help others. I
have a couple of questions before I begin
though:</FONT></SPAN></DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial" color="#0000ff"
size="2"></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial" color="#0000ff" size="2">1)
what runtime environment(s) should I use? The versions of console and
service on your site look quite old -&nbsp;<SPAN
class="555532112-06032004">a</SPAN>re they up to
date?</FONT></SPAN></DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial" color="#0000ff"
size="2"></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial"><FONT color="#0000ff"><FONT
size="2">2) you seem to be saying that the best runtime to use
for a GUI plug-in is currently the slim connector - should I download that
one and throw away the slim specific parts (I've not got a slim)<SPAN
class="555532112-06032004">?</SPAN></FONT></FONT></FONT></SPAN></DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial" color="#0000ff"
size="2"></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial"><FONT color="#0000ff"><FONT
size="2">3) can you please reveal the identity
of&nbsp;<SPAN class="555532112-06032004">the
</SPAN>"<SPAN class="555532112-06032004">few
extra lines of code" needed to get around the "slight buglet in
the GUI plugin runtime"&nbsp; - you
tease.</SPAN></FONT></FONT></FONT></SPAN></DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial"><FONT color="#0000ff"><FONT
size="2"><SPAN
class="555532112-06032004"></SPAN></FONT></FONT></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class="400481512-06032004"><FONT
face="Arial"><FONT color="#0000ff"><FONT
size="2"><SPAN
class="555532112-06032004">Edward</SPAN></FONT></FONT></FONT></SPAN></DIV></DIV>
<BLOCKQUOTE>
<DIV></DIV>
<DIV class="OutlookMessageHeader" lang="en-us"
dir="ltr" align="left"><FONT
face="Tahoma" size="2">-----Original
Message-----<B>From:</B> Stuart Booth [mailto:lists@xxxxxxx]
<B>Sent:</B> 02 March 2004 22:48<B>To:</B>
xAP_developer@xxxxxxx<B>Subject:</B> [xAP_developer] xFx How-To
#2: creating a simple xFx plugin</FONT></DIV><TT>Here's
something for the curious. I've been asked a few times recentlyhow to go
about creating a xFx-based xAPplication, e.g. one that sitsin a GUI like
the xAP SlimServer Connector does:<<A href="http://www.xapframework.net/modules.php?name=Sections&amp;op=viewarticle&amp;artid=9";>http://www.xapframework.net/modules.php?name=Sections&amp;op=viewarticle&amp;artid=9</A>>This
is reasonably straight-forward I think (but then I would do Isuppose!). So
here's the start of a new technical note on an aspect ofxAPFramework that
may be of interest to some. There are lots morefeatures you can make use of
(which the SlimServer Connector doesextensively) but they're not needed
right now (for example, how youcan 2x click an event message and display
detailed informationincluding the actual xAP message if appropriate).In
this example I'm written a very, very simple xAPplication called"xAP
Echo Target" that echoes any xAP messages targetted directly atit back
to the sender.So if I sent out a message such as the following (note the
Targetaddress):xap-header{v=12Hop=1UID=FF123400Class=xAP-OSD.DisplaySource=KCSoft.Send.AnyaTarget=KCSoft.EchoTarget.Anya}{
... the body ... }It will swap the Source/Target address around so as to
send it fromthe xAP Echo Target applica
tion back to its original source. Thisconveniently avoids infinite network
traffic.xap-header{v=12Hop=1UID=FF123400Class=xAP-OSD.DisplaySource=KCSoft.EchoTarget.AnyaTarget=KCSoft.Send.Anya}{
... the body ... }The C# code to achieve this, implemented as a xFx-based
Plugin DLL isas follows. The end results can be viewed here:<A
href="http://www.xapframework.net/xAPImages/SimplePlugin.jpg";>http://www.xapframework.net/xAPImages/SimplePlugin.jpg</A>I
was hoping to say you could compile this code up and drop it intothe
SlimConnector's "Plugins" directory, but I discovered a
slightbuglette in the GUI plugin runtime. It's easily fixed with a few
extralines of code here, but as they're unnecessary for the example
Idecided to omit them.using System;using KCS.xAP.Framework.Message;using
KCS.xAP.Framework.Transport;using KCS.xAP.Framework.Plugins
;namespace
KCS.xAP.Applications.EchoTarget{[xAPPluginMessageHandler][xAPPluginDisplayName("xAP
Echo
Target")][xAPPluginServiceName("xAPEchoTarget")][xAPPluginServiceDisplayName("xAP
Echo Target")][xAPPluginServiceDescription("Echoes messages
targetted at the application back onto the xAP
network.")][xAPPluginAppConfigSettingAttribute("xAPHeaderSourceVendor",
xAPHeaderSource.DEFAULT_SOURCE_VENDOR)][xAPPluginAppConfigSettingAttribute("xAPHeaderSourceDevice",
"EchoTarget")]public class EchoTargetPlugin :
xAPPluginModuleBase{&nbsp;&nbsp;&nbsp; protected override void
MessageReceived (object
sender,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
xAPMessageEventArgs event_args)&nbsp;&nbsp;&nbsp;
{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
try&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if (event_args.Message.Header.Target != null
&amp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
event_args.Message.Header.Target.CompareAddressTo(Heartbeat.Source))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
OutputMessage(event_args.Message.Header.Class.ToString(),&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
event_args.Message.Header.Source.ToString());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
xAPTargetAddress target = new xAPTargetAddress
(event_args.Message.Header.Source);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
event_args.Message.Header.Target =
target;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
event_args.Message.Header.Source =
Heartbeat.Source;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
xAPSender.ApplicationSender.Send(event_args.Message);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
catch (Exception
exc)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
OutputMessage(event_args.Message.Header.Class.ToString(),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
exc.Message);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}&nbsp;&
nbsp;&nbsp; }} // End of class EchoTargetPlugin} // End of
namespaceThat's all that is required to achieve something as simple as
this:<A href="http://www.xapframework.net/xAPImages/SimplePlugin.jpg";>http://www.xapframework.net/xAPImages/SimplePlugin.jpg</A>This
can be loaded by the Console, GUI or Windows Service runtimes, soyou can
deploy your application any way you wish. Multiple plugins caneven be
combined together under the one 'shell' application.A lot of common
boilerplate code is implemented in thexAPPluginModuleBase class, from
xAPUtilities.DLL in xAPFramework.Technically you just need to implement the
IxAPPluginModule interfaceon your plugin class, but I find it easier to
inheritxAPPluginModuleBase, which implements the IxAPPluginModule
interface,and then override MessageReceived() as you can see above.The
interesting stuff is pr
obably the attributes that decorate theclass declaration above. I'll trot
through them:[xAPPluginMessageHandler]This is the real magic flag as it
identifies this class as a pluginclass to be loaded by the plugin manager.
Add this attribute to yourIxAPPluginModule implementing class and you're
more or less away.[xAPPluginDisplayName("xAP Echo Target")]This
is just a pretty presentation name for the plugin when it getsloaded. You
can see how it gets used as the application title when theplugin runtime
engine detects only the single
plugin.[xAPPluginServiceName("xAPEchoTarget")][xAPPluginServiceDisplayName("xAP
Echo Target")][xAPPluginServiceDescription("Echoes messages
targetted at the application back onto the xAP network.")]These are
used when the plugin DLL is installed as a Windows Serviceand should be
fairly self explanatory. You can see these in theService Control Manager in
Control Panel/Administrative Tools/Sevicesof your Windows
OS.[xAPPluginAppConfigSettingAttr
ibute("xAPHeaderSourceVendor",
xAPHeaderSource.DEFAULT_SOURCE_VENDOR)][xAPPluginAppConfigSettingAttribute("xAPHeaderSourceDevice",
"EchoTarget")]These two fix down the Vendor and Device addresses
of your pluginapplication. I've talked in the past about how to do this in
code fora standalone application to configure its own Vendor name, and
anappropriate device name. These achieve the same for plugins.That's it
really. The code in the MessageReceived() function should bepretty clear I
hope. This is exactly how the root of the SlimServerConnector is
implemented, although it's a whole lot more complicatedthan the echo
application above!Any further queries/comments, fire away.S-- Stuart Booth
<stuart@xxxxxxx>xAPFramework.net - a xAP software development
framework for .net<A href="http://www.xapautomation.org/";>http://www.xapautomation.org/</A>&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp; <A href="http://www.xapframework.net/";>http://www.xapframework.net/</A></TT>




xAP_Development Main Index | xAP_Development Thread Index | xAP_Development Home | Archives Home

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.