Event handlers allow you to disable content staging and integration bus synchronization for certain pages or objects. The system provides two types of events that you can use:
When changes are made to pages and objects (such as creating, editing or deleting), the system logs the change data. Content staging and the integration bus use the data to create synchronization tasks, which then transfer the changes to the target server or application.
To completely prevent the system from starting the staging or integration process, handle the following events:
You can use two different approaches to disable staging or integration inside the event handlers:
Set the properties of the event handler's LogDocumentChangeArgs/LogObjectChangeArgs parameter:
e.Settings.LogStaging = false;
e.Settings.LogIntegration = false;Directly switches off logging of staging or integration tasks. The properties can be changed later during the execution of the LogChange event.
OR
Call the Using method of the event handler's LogDocumentChangeArgs/LogObjectChangeArgs parameter with a new CMSActionContext object as the parameter. Set the LogSynchronization or LogIntegration properties in the CMSActionContext constructor.
e.Using(new CMSActionContext() {LogSynchronization = false, LogIntegration = false} );Disables logging of staging or integration tasks within the entire context of the LogChange event.
The following example demonstrates how to use LogChange handlers to disable content staging and integration for pages in the /Archive section of a website.
Open your Xperience solution in Visual Studio (using the WebApp.sln file).
Create a custom module class.
Override the module's OnInit method and assign handlers to the DocumentEvents.LogChange.Before event.
using CMS;
using CMS.Base;
using CMS.DataEngine;
using CMS.DocumentEngine;
// Registers the custom module into the system
[assembly: RegisterModule(typeof(LogChangeHandlerModule))]
public class LogChangeHandlerModule : Module
{
// Module class constructor, the system registers the module under the name "LogChangeHandlers"
public LogChangeHandlerModule()
: base("LogChangeHandlers")
{
}
// Contains initialization code that is executed when the application starts
protected override void OnInit()
{
base.OnInit();
// Assigns a handler to the DocumentEvents.LogChange.Before event
// This event occurs when pages are modified, before the system starts logging the changes
DocumentEvents.LogChange.Before += LogDocumentChange_Before;
}
}Define the handler methods (inside the custom module class):
// Disables logging of staging and outgoing integration tasks for the content of pages in the /Archive section of the website
private void LogDocumentChange_Before(object sender, LogDocumentChangeEventArgs e)
{
// Gets the synchronized page
TreeNode page = e.Settings.Node;
// Excludes pages under the "/Archive" path from content staging and integration bus synchronization
if (page.NodeAliasPath.StartsWith("/Archive"))
{
e.Using(new CMSActionContext()
{
LogSynchronization = false,
LogIntegration = false
}
);
}
}Save the class and Rebuild the solution.
The custom handlers ensure that the system does not create synchronization tasks for the content and metadata of pages in the website's /Archive section.
Content staging and the integration bus use synchronization tasks to transfer changes to the target server or application. You can cancel the creation of synchronization tasks during the following system events:
Excluding content via the LogTask events provides the following advantages and disadvantages:
The following example demonstrates how to use the LogTask handler to disable content staging for the deletion of role objects and for content synchronization of certain pages.
Open your Xperience solution in Visual Studio (using the WebApp.sln file).
Create a custom module class.
Override the module's OnInit method and assign a handler to the StagingEvents.LogTask.Before event.
using CMS;
using CMS.DataEngine;
using CMS.Synchronization;
using CMS.DocumentEngine;
// Registers the custom module into the system
[assembly: RegisterModule(typeof(LogTaskHandlerModule))]
public class LogTaskHandlerModule : Module
{
// Module class constructor, the system registers the module under the name "LogTaskHandlers"
public LogTaskHandlerModule()
: base("LogTaskHandlers")
{
}
// Contains initialization code that is executed when the application starts
protected override void OnInit()
{
base.OnInit();
// Assigns a handler to the StagingEvents.LogTask.Before event
// This event occurs before the system creates content staging synchronization tasks
StagingEvents.LogTask.Before += LogTask_Before;
}
}Define the handler method (inside the custom module class):
private void LogTask_Before(object sender, StagingLogTaskEventArgs e)
{
// Handles content staging exclusion of documents
if (e.Object is TreeNode)
{
// Gets the synchronized document
TreeNode document = (TreeNode)e.Object;
// Cancels the creation of content staging tasks for documents under the "/Archive" path
if (document.NodeAliasPath.StartsWith("/Archive"))
{
e.Cancel();
}
}
// Handles content staging exclusion of objects
else
{
// Gets the synchronized object
BaseInfo synchronizedObject = e.Object;
// Gets the synchronization task
StagingTaskInfo stagingTask = e.Task;
// Cancels the creation of content staging tasks for the deletion of role objects
if ((synchronizedObject.TypeInfo.ObjectType == CMS.Membership.RoleInfo.OBJECT_TYPE)
&& (stagingTask.TaskType == TaskTypeEnum.DeleteObject))
{
e.Cancel();
}
}
}Save the class and Rebuild the solution.
The handler ensures that the system does not create staging tasks: