SDL Tridion 2011 .NET events

SDL Tridion 2011 comes with a new implementation of the event system. The event system is now part of the extensibility features that support extending the Content Manager kernel, which means you can make your event system modular.

Introduction

This new implementation of the event system allows you to subscribe to the delegate methods called by our core, which means you can use the TOM.NET API. The reasons behind this new implementation are simple. The old COM+ model is outdated. You get better performance since you're using TOM.NET instead of COM Interop. You have a finer granularity where you can hook into different levels. You implement only the events you need and you can do this in separate assemblies making your event system modular.

How does it work

The event system is still split into phases, but you get three additional phases compared to the SDL Tridion 2009 model. You can subscribe to an event based on a subject type, event type and a phase. The subjects are your Tridion items (i.e. Components and Pages). The event type is the action taking place (i.e. Save or Delete) and the phase is the timing on/around the action. The phases are fired in the following order:

  1. Initiated phase

  2. CMS action takes place (not a phase)

  3. Processed phase

  4. One of the transaction phases (TransactionCommitted if the transaction was successful, TransactionAborted in case of a transaction abort and TransactionInDoubt when the state of the transaction cannot be determined, it is neither commited nor aborted and never will be)

When subscribing to a certain event, you can choose a specific subject (i.e. Component), event type (i.e. SaveEventArgs) and phase (EventPhases.Processed). You can now also subscribe to the event for all Identifiable objects or subclasses thereof. The same can be done for the event type; you can drill down from TcmEventArgs to subscribe on all events or to a subclass to make it more specific. You can additionally subscribe to all event phases or just one of them. This means that if you need a certain action for all VersionedItems, RepositoryLocalObjects or something similar, you can use a single event handler because it uses the object hierarchy. You have the freedom to make it as generic or specific as you need. The following figure displays how the subject, event type and phase relate to each other and how they can be used.

SDL Tridion 2011 Event System

Further to everything described above, you can now also order your subscriptions and have them fire as either synchronous or asynchronous events. Having access to the event stack means you can detect if an action is performed as part of another action (for example, a Save on a VersionedItem with the parameter true will also Check-In the item and raise that event as part of the Save event).

Changes compared to SDL Tridion 2009 event system

In addition to the changes in granularity and API, there are three additional phases available: TransactionCommitted, TransactionAborted and TransactionInDoubt. Only one of these phases is fired within a process. When one of these transaction phases is executed the item itself is outside of the transaction which provides you with full control. For example, where a Page cannot be deleted in the Processed phase of a UnPublish event, because it is still in a transaction and thus in use, it can be deleted in the TransactionCommitted phase as it is successfully unpublished.

This event matrix shows a mapping of the SDL Tridion 2009 events to the new model, which should make it easier to upgrade your event system. This matrix is only a guide, always review your code before migrating it.

Note: Ensure that you use the right API. You should only make use of the TOM.NET API to ensure you are not depending on deprecated features. While it is technically possible to use (COM Interop) TOM API in your .NET event system, this is not a supported scenario.

Example implementation

As an example to show some of the new possibilities with the TOM.NET event system, I have created an implementation around Microsoft Windows performance counters. In this extension, the event system is used to measure the duration of Save and Publish actions. The information is recorded by perfmon and can also be analyzed through it. This very simple event system shows the usage of events with multiple subjects and the additional information available in it.

 Performance Monitor

Download the Performance Counter eXtension for free on the SDL Tridion World eXtension Community.

About the Author
Bart Koopman
Community Development Consultant

As a Community Development Consultant, Bart is the evangelist of all SDL Tridion products. Bart used to be a consultant and trainer at SDL Tridion, supporting both partners and customers with their implementations.

SDL CMT division

Related Downloads

SDL Tridion Event Matrix [Documentation] Minimize Text

Mapping of SDL Tridion 2009 events onto the SDL Tridion 2011 events


(size: 220.9KB)