Try our conversational search powered by Generative AI!

Johan Björnfot
Feb 25, 2011
(0 votes)

New events in DynamicDataStore

In CMS6 R2 we have added some new events to the DynamicDataStore class. Now there are three methods to attach event handlers that are called when Save, Delete or DeleteAll is called on a store instance:

  • public static void RegisterItemSavedEventHandler(string storeName, EventHandler<ItemEventArgs> eventHandler)
  • public static void RegisterItemDeletedEventHandler(string storeName, EventHandler<ItemEventArgs> eventHandler)
  • public static void RegisterDeletedAllEventHandler(string storeName, EventHandler<ItemEventArgs> eventHandler)

There are also corresponding UnRegister methods. The reason that the events do not have the “ordinary” event signature (meaning you cant use += and –= to attach/detach an event handler), is to make the event subscription to be on a per store basis.

New events in DynamicDataSerializer

We have also added two events to the DynamicDataSerializer class:

  • public event EventHandler<SerializationEventArgs> DeserializedObject
  • public event EventHandler<SerializationEventArgs> SerializingObject

The DynamicDataSerializer is used when importing/exporting DDS objects. The typical use case for using the events is if there is an object that has some site specific data that needs to be changed during import or export (e.g. if your object holds a reference to a page).

The SerializingObject event is raised when a DDS object is about to be serialized to a stream (typically used at export). Through an event handler you can either change some state of the object or cancel the object from being written to the stream. The DeserializedObject event is raised when an object has been instantiated from an import stream but not yet saved to the DDS.

To attach to the event during CMS Import, Export, Mirroring or Copy, you do not attach to the event directly on the DynamicDataSerializer but through the DynamicDataTransferHandler on DataExporter or DataImporter like:

    public class MyDDSImportHandler : IInitializableModule
        public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
            DataImporter.Importing += new EventHandler(DataImporter_Importing);

        public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context)
            DataImporter.Importing -= new EventHandler(DataImporter_Importing);

        void DataImporter_Importing(object sender, EventArgs e)
            DynamicDataTransferHandler ddsHandler = 
                (sender as DataImporter).TransferHandlers.Where(
                th => th.GetType() == typeof(DynamicDataTransferHandler)).Single() as DynamicDataTransferHandler;

            ddsHandler.DeserializedObject += delegate(object source, SerializationEventArgs args)
                MyType instance = args.ObjectInstance as MyType;
                if (instance != null)
                    //Check if referenced page guid have got new value, if so update reference
                    Guid mappedGuid;
                    if (ddsHandler.TransferContext.LinkGuidMap.TryGetValue(instance.PageGuid, out mappedGuid))
                        instance.PageGuid = mappedGuid;

        public void Preload(string[] parameters){}
Feb 25, 2011


Please login to comment.
Latest blogs
Introducing Image Transformer - AI Assistant for Optimizely

We've got something super cool to share with you, and it's all about giving your images a fresh spin. Image Transformer, the latest feature from ou...

Luc Gosso (MVP) | Feb 26, 2024 | Syndicated blog

Welcome 2024 Winter OMVPs

Hello, Optimizely community! We are thrilled to announce and welcome the newest members to the Optimizely Most Valuable Professionals (OMVP) progra...

Patrick Lam | Feb 26, 2024

Optimizely Opal... what it does actually do?

At Opticon 2023, Optimizely announced its first AI product Opal. AI is definitely the new tech buzzword in 2024 and with promises that AI will be...

Jon Jones | Feb 25, 2024 | Syndicated blog

How to add more Content Area Context Menu Item in Optimizely CMS 12

Hey folks, today I will share something related to Context Menu customization in the Content Area of Optimizely CMS. As you know, the content area ...

Binh Nguyen | Feb 25, 2024