IDataEvent
The IDataEventrepresents a contract for event notification containing minimal information about modified items. As you want to have a global event for all content, you can subscribe to the IDataEvent - it will be thrown on the Create, Update, and Delete actions for all content. Inside the event handler you can get information about the:
- Event
ActionNew (corresponds to Create action)UpdatedDeleted
ItemTypeItemIdProviderName
This data is sufficient to allow you to load the corresponding manager and retrieve the actual item.
To subscribe to the IDataEvent:
-
In Visual Studio, in your project, open the
Global.asaxfile.NOTE: If you do not have a
Global.asaxfile, create a newGlobal.asaxfile and add it to your project. In the context menu of your project, click Add » New Item… » Visual C# » Web » Global Application Class.. -
Add the following code:
C#using System; using Telerik.Sitefinity.Abstractions; using Telerik.Sitefinity.Data; using Telerik.Sitefinity.Data.Events; using Telerik.Sitefinity.Services; namespace SitefinityWebApp { public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { Bootstrapper.Bootstrapped += Bootstrapper_Bootstrapped; } private void Bootstrapper_Bootstrapped(object sender, EventArgs e) { EventHub.Subscribe<IDataEvent>(evt => DataEventHandler(evt)); } public void DataEventHandler(IDataEvent eventInfo) { var action = eventInfo.Action; var contentType = eventInfo.ItemType; var itemId = eventInfo.ItemId; var providerName = eventInfo.ProviderName; var manager = ManagerBase.GetMappedManager(contentType, providerName); var item = manager.GetItemOrDefault(contentType, itemId); } } }
As a result you are subscribed to theIDataEvent and you can access the event's ID, provider name, action, item type. and so forth. You can modify the event's attributes, subscribe an email address to the event, and so on.