Try our conversational search powered by Generative AI!

Johan Björnfot
Feb 25, 2011
  4867
(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:

    [InitializableModule]
    [ModuleDependency(typeof(DynamicDataTransferHandler))]
    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

Comments

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog