Sunday, February 17, 2013

Easy Breezy SDL Tridion 2011 CoreService Setup

1. Create .NET console application
- File - New - Project

2. Add references
C:\Program Files\Tridion\bin\client\
- Tridion.ContentManager.CoreService.Client.dll
- (.NET) System.ServiceModel.dll
- (.NET) System.Runtime.Serialization.dll

3. Add namespaces
- using Tridion.ContentManager.CoreService.Client;

4. Copy CoreService configuration
- Tridion.ContentManager.CoreService.Client.dll.config
to application configuration file
- App.config (Project - Add New Item - Application Configuration File)

5. Connect the client using a specific binding
SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2011");

6. Code away..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tridion.ContentManager.CoreService.Client;
namespace CoreServiceApp
{
class Program
{
static void Main(string[] args)
{
SessionAwareCoreServiceClient coreServiceClient = new SessionAwareCoreServiceClient("netTcp_2011");
Console.Write("Connected to CoreService with user " + coreServiceClient.GetCurrentUser().Title + " in session " + coreServiceClient.GetSessionId());
//code..

coreServiceClient.Close();
}
}
}

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.