Themelia Pro A powerful new development platform built on ASP.NET.
 
Creating Configurable Http Handlers
 
 

One of the enhancements Themelia Pro makes to the ASP.NET concept of HTTP handlers is that is it allows the creation of parameterized HTTP handlers. These are handlers which accept configuration parameters. Below is an example of using a parameterized handler:

<themelia.web>
  <webDomains enableWebDomainMissingSlash="true">
    <add defaultPage="/Page_/Home/Root.aspx" enableMissingSlash="true" catchAllMode="RedirectToRoot">
      <endpoints>
        <add selector="webDomainPathStartsWith" text="image/download" type="Sample.Web.ImageOverlayRender, Sample.Web">
          <parameters>
            <add name="ImageName" value="ProductDownload.png" />
            <add name="Text" value="Version 1.0.2.1" />
            <add name="TextColor" value="#ffffff" />
            <add name="TopPosition" value="29" />
            <add name="LeftPosition" value="52" />
            <add name="FontFamily" value="Calibri, Arial" />
            <add name="FontSize" value="12" />
          </parameters>
        </add>
      </endpoints>
    </add>
  </webDomains>
</themelia.web>

To add parameterization to an handler, you just implement the Themelia.IHasParameterMap interface, which looks like this:

public interface IHasParameterMap
{
    String DefaultParameter { get; set; }
    Map ParameterMap { get; set; }
}

In your handler, you will will access your parameters using ParameterMap. Here's an example:

String imageName = ParameterMap.PeekSafely("ImageName");
Int32 topPosition = ParameterMap.PeekSafely<Int32>("TopPosition");
Int32 leftPosition = ParameterMap.PeekSafely<Int32>("LeftPosition");
String text = ParameterMap.PeekSafely("Text");
String textColor = ParameterMap.PeekSafely("TextColor");
String fontFamily = ParameterMap.PeekSafely("FontFamily");
Double fontSize = ParameterMap.PeekSafely<Double>("FontSize");

Default Parameter

An extension to parameterized handlers is the addition of a default parameter.  These greatly simplify the configuration required when a parameterized handler requires only one parameter.  In using Themelia Pro, you will use default parameters a lot. Every time you setup a page alias you are using a default parameter:

<themelia.web>
  <webDomains>
    <add defaultPage="/Page_/Home/Home.aspx">
      <endpoints>
        <add matchType="pathStartsWith" type="PageAlias" text="/contact/" parameter="/Sequence_/Contact.aspx" />
      </endpoints>
    </add>
  </webDomains>
</themelia.web>

This is possible due to the fact that the internal components of Themelia Pro utilize parameterized handlers and default parameters. Your own custom parameterized handlers can use default parameters as well.

To use a default parameter, have the DefaultParameter of your parameterized handler return the name of the parameter to return. Then, instead of requiring the user of your handler to specify a single parameter in a larger configuration block, he or she can just set the "parameter" attribute of your endpoint.

Here's a DefaultParameter example:

//- @DefaultParameter -//
public String DefaultParameter
{
    get
    {
        return "LicenseKey";
    }
    set
    {
    }
}

Using this, you can turn the following longer configuration:

<themelia.web>
  <webDomains>
    <add defaultPage="/Page_/Home/Root.aspx">
      <endpoints>
        <add selector="webDomainPathStartsWith" text="pdf/create" type="Sample.Web.PdfCreator, Sample.Web">
          <parameters>
            <add name="LicenseKey" value="D1C4065B-8DEC-402f-A509-56F034AE9A60" />
          </parameters>
        </add>
      </endpoints>
    </add>
  </webDomains>
</themelia.web>

...into...

<themelia.web>
  <webDomains>
    <add defaultPage="/Page_/Home/Root.aspx">
      <endpoints>
        <add selector="webDomainPathStartsWith" text="pdf/create" type="Sample.Web.PdfCreator, Sample.Web" parameter="D1C4065B-8DEC-402f-A509-56F034AE9A60" />
      </endpoints>
    </add>
  </webDomains>
</themelia.web>