Friday, November 9, 2012

EventSystem - Components/Pages Publish and Unpublish

This is a code sample which shows how to subscribe to the following Tridion EventSystems:

  • Component Publish
  • Component Unpublish
  • Page Publish
  • Page Unpublish



using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.Extensibility;
using Tridion.ContentManager.Extensibility.Events;
using Tridion.Logging;
using System.Diagnostics;
using Tridion.ContentManager.CommunicationManagement;
namespace Tridion.EventSystem.Events
{
[TcmExtension("SDL Tridion Events 2011")]
public class Events : TcmExtension
{
public Events()
{
SampleEvents();
}
private void SampleEvents()
{
EventSystem.Subscribe<Component, UnPublishEventArgs>(ComponentUnpublish, EventPhases.Initiated);
            EventSystem.Subscribe<Component, PublishEventArgs>(ComponentPublish, EventPhases.Initiated);
            EventSystem.Subscribe<Page, PublishEventArgs>(PagePublish, EventPhases.Initiated);
            EventSystem.Subscribe<Page , UnPublishEventArgs>(PageUnpublish, EventPhases.Initiated);
}
        private void ComponentPublish(Component component, PublishEventArgs args, EventPhases phases)
{
            Logger.Write("[ComponentPublish]: ", component.Id, LoggingCategory.General, TraceEventType.Warning);
}
        private void ComponentUnpublish(Component component, UnPublishEventArgs args, EventPhases phases)
        {
            Logger.Write("[ComponentUnPublish]: ", component.Id, LoggingCategory.General, TraceEventType.Warning);            
        }
        private void PagePublish(Page page, PublishEventArgs args, EventPhases phases)
        {
            Logger.Write("[PagePublish]: ", page.Id, LoggingCategory.General, TraceEventType.Warning);            
        }
        private void PageUnpublish(Page page, UnPublishEventArgs args, EventPhases phases)
        {
            Logger.Write("[PageUnPublish]: ", page.Id, LoggingCategory.General, TraceEventType.Warning);            
        }
}
}

No comments:

Post a Comment