Creating Controllers

CMSControllerBase Class

Because the CMS plug-in system locates plug-in applications via MVC routing, every plug-in application must start with a controller.

CMS plug-in system uses MEF to lazy-load types exported in all plug-in folders, creating a controller instance in real time based on the URL of the application. The base type the plug-in system expects is CMSControllerBase.

	public abstract class CMSControllerBase : Controller
		protected CMS_Common _Common;
		protected ContentStore _ContentStore;
		protected IReadonlyUser _CurrentUser;
		protected Exception _InitializationException;
		protected Ingeniux.CMS.L10N.LocalizationProvider _L10nProvider;
		protected string _XmlFolderLocation;
		protected void _GetCommonObject();
		protected void _GetContentStore(RequestContext requestContext, 
			HttpApplicationStateBase application);
		public static Ingeniux.CMS.L10N.LocalizationProvider GetL10nProvider
			(RequestContext requestContext, HttpApplicationStateBase application);
		protected override void Initialize(RequestContext requestContext);
		protected IUserSession OpenReadSession();
		protected IUserWriteSession OpenWriteSession();

The CMSControllerBase class contains important members that are used to retrieve information of the CMS application and user session context.

  • The _Common field wraps up all the necessary information on the CMS user context.
  • The _ContentStore field is the connection to the back-end database (Singleton object).
  • The _CurrentUser field is used to open sessions.
  • The _XmlFolderLocation field is location of the XML folder.
  • The _L10NProvider field is for retrieving localized strings for specific UI languages.
  • The _InitializationException field indicates whether or not has failed to initialize. If it is not null, the initialization failed.

Use OpenReadSession and OpenWriteSession to open session to retrieve and manipulate objects. Objects only reside in each session and are disposed upon session disposal.

CustomTabController Class

CustomTabController is the base class for controllers in custom tab applications. All custom tab controllers must derive from it. It is derived from CMSControllerBase.

	public abstract class CustomTabApplicationController : CMSControllerBase
		public CustomTabParameters CMSContext { get; protected set; }

The CMSContext property of this class contains the environmental context of custom tab applications. It is derived from CMSControllerUrlContext class.

	public class CMSControllerUrlContext
		public string AssetBaseUrl;
		public string BaseUrl;

	public class CustomTabParameters : CMSControllerUrlContext
		public CustomTabParameters(CMS_Common common, RequestContext requestContext);
		public string PageId { get; protected set; }
		public string PublishingTargetId { get; protected set; }
		public IPublishingTarget GetCurrentPublishingTarget(IUserSession session);
		public IUser GetCurrentUser(IUserSession session);
		public IPage GetPage(IUserSession session);

This model class also provides support methods to retrieve context objects, like Page and Publishing Target.

DynamicExecuteInterfaceApplicationController Class

DynamicExecuteInterfaceApplicationController is also derived from CMSControllerBase. It is the base controller for Dynamic Execute User Interface applications.

	public abstract class DynamicExecuteInterfaceApplicationController : CMSControllerBase
		public ExecuteElementData ElementData { get; protected set; }

This controller contains the ElementData property, which is the object representation of the client-side JavaScript model for data of a element field. In this case, it's the data of a Dynamic Execute field.

	public class ExecuteElementData
		public Dictionary attributes;
		public ExecuteElementData[] childElements;
		public bool readOnly;
		public string type;
		public string ToJson();

Since Dynamic Execute fields change all elements from the original schema into attributes, the childElements field is normally empty or null.

WorkflowClientApplicationController Class

WorkflowClientApplicationController is also derived from CMSControllerBase. It is the base controller for Workflow External Client applications.

	public abstract class WorkflowClientApplicationController : CMSControllerBase
		public WorkflowClientParameters TransitionContext { get; protected set; }

The TransitionContext property contains all the information on the page's workflow status and transition.

	public class WorkflowClientParameters : CustomTabParameters
		public WorkflowClientParameters(CMS_Common common, RequestContext requestContext);

		public string TransitionId { get; protected set; }

		public ITransition GetTransition(IUserSession session);