Event not working

I am new to the Tridion Event System. I wrote a little code.

[TcmExtension("MyEventHandlerExtension")] public class EH : TcmExtension { public EH() { Subscribe(); } public void Subscribe() { //EventSystem.Subscribe<Component, DeleteEventArgs>(HandlerForInitiated, EventPhases.Initiated); EventSystem.Subscribe<Tridion.ContentManager.CommunicationManagement.Page, Tridion.ContentManager.Extensibility.Events.PublishOrUnPublishEventArgs>(HandlerForCommitted, EventPhases.All); } private void HandlerForCommitted(IdentifiableObject subject, PublishOrUnPublishEventArgs args, EventPhases phase) { TDSE obj = new TDSE(); Tridion.ContentManager.Interop.TDS.Publication pub = obj.GetPublication("tcm:0-150-1"); Tridion.ContentManager.Interop.TDS.Page pubPage = obj.GetPage("tcm:150-12374-64", pub); pubPage.Publish("tcm:0-1-65538", false, true, false, default(DateTime), default(DateTime), default(DateTime)); } } 

using this code, I wanted to publish the page every time a publication and publication occurs. I create this code and register its path in the tridion configuration file. But its not working. Please, help

+4
source share
3 answers

Well, first of all, remove all your TDSE code, you should use TOM.NET. You can get a session as subject.Session

Then make sure you register this extension in Tridion.ContentManager.config and restart the system

And finally, if something doesn’t work, just add simple code that will create a file in your HandlerForCommitted whenever an event occurs, so you can see if the extension will be executed.

+8
source

The 2011 Event System uses the TOM.NET API, not the TOM API. Do not create new TDSE objects in the 2011 Event System. Despite the fact that you can reference the old Interop libraries, there is no reason to do this since 2011. Using the TOM.NET libraries, you should see better performance, as well as code in the future.

Mihai Cadariu has a good example where he uses TOM.NET to publish a page from a Tridion template. Setting the code to check the preview or publishing mode and setting your own user and priority (instead of reading it from the current transaction) should work well.

Below is the code http://yatb.mitza.net/2012/05/publishing-from-template-code-using.html

 public void Publish(Engine engine, String tcmUri, User user, PublishPriority priority) { Session session = new Session(user.Title); PublishInstruction publishInstruction = new PublishInstruction(session); RenderInstruction renderInstruction = new RenderInstruction(session); renderInstruction.RenderMode = RenderMode.Publish; // work around. needs to be specified for binaries. publishInstruction.RenderInstruction = renderInstruction; List<IdentifiableObject> items = new List<IdentifiableObject>() { session.GetObject(tcmUri) }; List<PublicationTarget> targets = new List<PublicationTarget>() { engine.PublishingContext.PublicationTarget }; PublishEngine.Publish(items, publishInstruction, targets, priority); session.Dispose(); } // called with PublishTransaction currentTransaction = TemplateUtils.GetPublishTransaction(engine); TemplateUtils.Publish(engine, itemUri, currentTransaction.Creator, currentTransaction.Priority); 
+6
source

There are three things in your code that I usually forget:

  • class public
  • it extends TcmExtension
  • has the TcmExtension attribute

If you correctly registered the class in the configuration file, you just need to restart the corresponding module (s). In this case, I expect these to be the Publisher and TcmServiceHost services.

After restarting these modules and starting the publishing action, you should see a registered event (in the Windows Event Viewer) in which your extension is loaded.

Even if it shows, it means that your assembly is loaded into the corresponding Tridion process, and the class is recognized and an instance is created.

If at this point your handler does not fire, you may need to consider listening to another event. Whenever I want to interact with a publication, I end up listening to SaveEventArgs PublishTransaction instead of PublishOrUnPublishEventArgs on Page .

+4
source

Source: https://habr.com/ru/post/1443216/


All Articles