Themelia Pro A powerful new development platform built on ASP.NET.
 
Understanding State Processors
 
 

State processors are similar to init-processors in that they exist simply to work with information. A state processor, as its name suggests, runs after ASP.NET state has been initialized and therefore has full access to session information. So, if you need to configure some information in session, this is your place to do it.

This type of processor is actually the only processor that has direct access to session information. However, that doesn't mean that you can't set session in other processors. How's that possible if you don't have direct access to session? Themelia internally has a state processor called SessionStateProcessor which runs before any custom state processors. This state processor has a single object in it called Data of StringObjectMap. Any information set in this single, will be copied to session before custom state processors runs.

A state processor is made by creating a class that inherits from Themelia.Web.Processing.StateProcessorBase. This is an abstract class that requires you to implement the following signature:

StateProcessorBase Execute(System.Web.HttpContext context, params Object[] parameterArray);

Chaining

State processors, like init processors, have a special feature known as chaining. This feature allows you to use custom logic to see if you want to run another init processor. To use chaining, just return an instance of a differnet state processor. When the current processor finishes executing, the one your returned will immediately run

You can set the context and parameterArray be using the following method signature:

InitProcessorBase Initialize(HttpContext context, params Object[] parameterArray);

Setting Session Items Earlier.

The session processor is the only processor that has direct access to session information. However, that doesn't mean that you can't set session in other processors. How's that possible if you don't have direct access to session? Themelia internally has a post state processor called SessionStateProcessor, which holds a Themelia map (a dictionary type of type StringObjectMap) named Data which allows you to set information that will be plugged into session when it's available.

As an example, the following init-processor, which doesn't have direct access to session, registers a string to session via the SessionStateProcessor:

public class AuthenticationInitProcessor : Themelia.Web.Processing.InitProcessorBase
{
    //- @Execute -//
    public override InitProcessorBase Execute(System.Web.HttpContext context, params Object[] parameterArray)
    {
        SessionStateProcessor.Data["UserName"] = "John Doe";
        return null;
    }
}

When using this or the even items context, session data, or cache data, it's generally a good idea to scope your information using the scope operator. The above example is very poorly written because the session item name "UserName" is rather general and may be overwritten by someone else. Therefore, something like the following is recommend:

namespace ABCCorp.Web
{
    public class AuthenticationInitProcessor : Themelia.Web.Processing.InitProcessorBase
    {
        //- @Info -//
        public class Info
        {
            public const string Scope = "Authentication";
            //+
            public const string UserName = "UserName";
        }
 
        //- @Execute -//
        public override InitProcessorBase Execute(System.Web.HttpContext context, params Object[] parameterArray)
        {
            SessionStateProcessor.Data[ScopeTranscriber.Construct(Info.Scope, Info.UserName)] = "John Doe";
            //++ this is the same as the following untyped code:
            //++   SessionStateProcessor.Data["Authentication::UserName"] = "John Doe";
            //++
            //++ !typing is highly recommended!
            //++
            return null;
        }
    }
}

Themelia inherently understands item scope and uses it at many places internally. To access the above information after it's in session, you may use the following:

using System;
//+
using Themelia.Web;
//+
using AuthenticationInfo = ABCCorp.Web.AuthenticationInitProcessor.Info;
//+
namespace WebSite.Simple
{
    public class Faq : Themelia.Web.SimplePage
    {
        protected override void OnPreRender(EventArgs e)
        {
            litUserName.Text = HttpData.GetScopedSessionItem<String>(AuthenticationInfo.Scope, AuthenticationInfo.UserName);
            //+
            base.OnPreRender(e);
        }
    }
}