Julian Wraith

Menu Close

Tag: event system

Event Systems in SDL Tridion 2011

Event Horizon

As I mentioned in one of my previous post the event system has been revised to me more modular and, probably more importantly, to be native .NET.

An event, an action from a user, triggers the event system which is one or more .NET classes which will act upon this event in some way. In versions of Tridion prior to 2011 the event system has been a single class which then leads to having to combine different event activity into the same piece of code. For instance, additional logging and workflow elements might have to be combined; this leads to unnecessary complexity in the code itself. It also means you cannot easily turn off (and on) part of the code.

In SDL Tridion 2011, this has changed (although you can still run older event systems) to allow you to hook into events using multiple separate event systems. As Bart Koopman explains in this article, when we hook into the events we concern ourselves with the phase of the event, the type of event and the object itself.

The phase relates to where in the event you are, for example, initiated, processed, committed etc. The type refers to the type of event, e.g. Publishing, BluePrint, or Data Modification events. Lastly our object (or in more familiar terms “item”) itself; our Component, Page, Schema etc. With these I can easily define that I would like to fire an event on a Component, when it is published and after that publish action has started.

Two more additional features are important. Firstly, it is quite possible that you have more than one event system hooked into the same event, so with the “Event Subscription Order” you can also specify the order in which your code is triggered (creating a event system stack). Secondly, you can also specify an event to run asynchronously rather than wait for code to complete before other code can continue (synchronously).

Event System Example

We need to do two simple things to get this to work:

1)      Define out event system class

2)      Configure SDL Tridion to load the event system and make it active

The Event System Class

We need to define our event system and this being .NET we can pretty much do anything we want from here, however, we need to at minimum hook (or rather subscribe) to an event.

Our event is going to log everything that happens to a Windows Event log called “Message Log”. We open our class and declare all the variables we need etc:

using System;
using System.Diagnostics;
using System.Threading;
using Tridion.ContentManager;
using Tridion.ContentManager.Extensibility;
using Tridion.ContentManager.Extensibility.Events;

namespace Tridion.Utilities. ExampleEventSystem {
      public class ExampleEventSystem : TcmExtension {
           #region Local Variables
           private static EventLog messageLog = new EventLog();

In our constructor we will initialize out Windows Event Log and call our subscribe method:

          public AuditLogger() {

Create the event log:

          private static void Init() {
               if (!EventLog.SourceExists("TridionMessages")) {
                   EventLog.CreateEventSource("TridionMessages ", "Message Log");
               messageLog.Source = " TridionMessages ";

Subscribe to our events:

          public void Subscribe() {
               EventSystem.Subscribe<IdentifiableObject, TcmEventArgs>( LogMessage, EventPhases.Processed);

In this case I have used all “IdentifiableObject” which is everything, the method, LogMessage, that will called when the event fires and the phase is “processed”. The method signatures for subscribing are:

Subscribe<TSubject, TEvent>(TcmEventHandler<TSubject, TEvent> eventHandler, EventPhases phases, EventSubscriptionOrder order)
SubscribeAsync<TSubject, TEvent>(TcmEventHandler<TSubject, TEvent> eventHandler, EventPhases phases, EventSubscriptionOrder order)

In our case we defined no subscription order so it will be “normal” order.

And finally define the method that will actually log our message:

          private static void LogMessage(IdentifiableObject subject, TcmEventArgs args, EventPhases phase) {
               String message = "Session user: " + subject.Session.User.Title.ToString();
               message = message + "\nTarget URI: " + subject.Id;
               message = message + "\nItem Type: " + subject.GetType().Name;
               message = message + "\nEvent: " + args.GetType().ToString();
               message = message + "\nPhase: " + phase.ToString();
               messageLog.WriteEntry(message, EventLogEntryType.Information, 0, 0);

Configuring Tridion

To load our event system, we must load the class responsible. This we do in the Tridion.ContentManager.config which can be found under the %TRIDION_HOME%\config directory and we add a line to the extensions section to add our assembly:

<add assemblyFileName="C:\myevevntsystem\messagelogger.dll"/>

Five things you must know about SDL Tridion 2011

Online Marketing Explorer

It has been released and I decided to list out five things that I think are very important to the release of 2011. Mostly talk has been about the new Content Manager Explorer (and it’s cross browser functionality) but this is just the surface. Underneath there are many changes of which just five is a small snippet of what you can find in the box…

The five:

Scalable Deployer

To meet the demands of a large scale enterprise the deployer is now much more scalable than before allowing organizations to constantly grow their environment to meet the demands placed upon it by a growing content organization. The scalable deployer allows multiple processes to simultaneously process deployments as well as updating the publisher on how much load they can handle to avoid overloading.

Storage Layer

The new Content Delivery storage layer is based upon the Java Persistence API (JPA) and its concrete implementation, Hibernate.  With this you are able to expand the single Content Delivery storage layer to encompass multiple different data sources (e.g. product information or user generated content)  into one single layer.

Online Marketing Explorer

Drive Customer Impact with the new Online Marketing Explorer. Giving an overview of your marketing activities with a centralized model of campaigns, reporting and actionable insights.

Content Services

Content Services is the new RESTful webservice on Content Delivery based upon the oData and oAuth standards. You now have your published content available through a webservice to any application, mobile app, affiliate, white label site, 3rd party the list goes on…

Event System

The new fully .NET event system is modular. Does not sound like much but you can add one or more separate event systems to the same Content Management environment. Each event system can work alone hooking into different CM activities or can work together as part of coordinated event driven activities.

© 2019 Julian Wraith. All rights reserved.

Theme by Anders Norén.