Sunday, February 10, 2013

Setup SDL Tridion 2011 Event System 2011

In a nutshell..

1. Open Visual Studio 2010 and create a new Class Library

2. Add references to C:\Tridion\bin\client

  • Tridion.Common.dll
  • Tridion.ContentManager.dll
  • Tridion.ContentManager.Common.dll
  • Tridion.ContentManager.Publishing.dll

3. Add Tridion.ContentManager namespaces using statements

  • using Tridion.ContentManager.ContentManagement;
  • using Tridion.ContentManager.Extensibility;
  • using Tridion.ContentManager.Extensibility.Events;

4. Implement TcmExtension abstract class

namespace TridionEventSystem
{
// The class attribute is unique per Event System dll on the server.
// In 2011 we can have multiple Event System dlls on 1 server.
[ TcmExtension( "TridionEventSystem" )] // This needs to be unique per Event System

public class TestFastForward : TcmExtension
{
...

5. Build the constuctor

Note: if additional subscriptions are done in separate classes, each class will need to be explicitly referenced in Tridion.ContentManager.config

public FastForward()
{
//EventSystem.Subscribe(OnComponentSavePost, EventPhases.TransactionCommitted);

EventSystem.SubscribeAsync(OnComponentCheckIn, EventPhases .TransactionCommitted);
}

6. Code the event logic

//private void OnComponentSavePost(Component comp, SaveEventArgs args, EventPhases phases)

private void OnComponentCheckIn( Component comp, CheckInEventArgs args, EventPhases phases)
{
//eventlogic
}

7. Build the project to create the DLL

8. Copy the DLL somewhere on the CMS server

9. Register the event class by updating the C:\Tridion\Config\Tridion.ContentManager.config file

<extensions>
<add assemblyFileName="C:\Program Files (x86)\Tridion\bin\TridionEventSystem.dll"/>
</extensions>

10. Restart

  • Tridion COM+
  • Tridion Content Manager Service Host service
  • Tridion Content Manager Publisher service

11. To debug and troubleshoot, in Visual Studio go to Debug -- Attach to Process..

  • Generic CMS events -- dllhost.exe
  • Publisher related events -- TcmPublisher.exe

Make sure the Visual Studio project is identical to the DLL deployed or else you will not be able to trace the code.

You can attach to multiple processes at the same time in Visual Studio.

For instance, in case there are events triggered by the Publisher, such as OnComponentPublishPre, you can simultaneously attach to both processes above.

1 comment:

  1. Google Analytics tells me my most popular posts are about humor, lolcats, and Tridion setup guides.

    Google Search tells me this post makes the top five for "setup tridion event system" (just a few days after posting it). Nice job and thanks for the guide, Elena! The future me that needs to set up an event system project thanks you already. :-)

    ReplyDelete