-
Notifications
You must be signed in to change notification settings - Fork 0
Sample Catalog
skradel edited this page Sep 13, 2010
·
3 revisions
Let’s consider a web application that needs to add some data to the user’s session from an LDAP datastore and, separately, log an event to a file or database.
This catalog demonstrates a catalog with two commands you can invoke – “userchain” and “audit”:
<?xml version=“1.0” encoding=“utf-8” ?>
<catalog xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns:xsd=“http://www.w3.org/2001/XMLSchema”
xmlns=“http://zetetic.net/schemas/chain/catalog.xsd”>
<chain name=“userchain”>
<command name=“userinfo” typeName=“Demo.GetUpnCommand, Demo”>
</command>
<command name=“Surname” typeName=“Demo.LdapSearchCommand, Demo”>
<add key=“LdapItem” value=“sn” />
<add key=“SessionItem” value=“LASTNM” />
<add key=“Attributes” value=“sn” />
<add key=“Filter” value=“(|(uid={0})(sAMAccountName={0}))” />
<add key=“LdapConfig” value=“ldap1” />
</command>
<command name=“Groups” typeName=“Demo.LdapSearchCommand, Demo”>
<add key=“LdapItem” value=“distinguishedName” />
<add key=“SessionItem” value=“GROUPDNS” />
<add key=“Attributes” value=“1.1” />
<add key=“Filter” value=“(|(member={0})(uniqueMember={0}))” />
<add key=“LdapConfig” value=“ldap2” />
</command>
</chain>
<command name=“audit” typeName=“Demo.SqlAuditor, Demo”>
<add key=“Connection” value=“MyConnectionString” />
</command>
</catalog>
As shown, you can reuse the same ICommand implementation class in multiple places with different configuration properties. The "key"s correspond to public properties of each command type/class. (See the general-purpose commands in Zetetic.Chain.Generic for a few quick examples.)
Usage of the catalog and its commands is straightforward:
ICatalog catalog = CatalogFactory.GetFactory().GetCatalog(“mycatalog.xml”);
IContext context = new ContextBase();
context[“just testing”] = true;catalog[“userchain”].Execute(context);
catalog[“audit”].Execute(context);
That’s all there is to it. With well-designed commands and chains, you won’t have to change your application code to pull in more values from the hypothetical LDAP source. The automatic configuration/property mapper in Zetetic.Chain means it’s often easier and more natural-feeling to make this stuff more flexible than less!