0

I wondering if it's possible to stop the publish flow in an event. I want to check some properties in the code-behind before I let the user publish the object.

magnattic
  • 12,638
  • 13
  • 62
  • 115
RClemens
  • 301
  • 2
  • 7

1 Answers1

0

You can use the static DataEvents<T> class which has a OnStoreChanged event you can hook into.

Example use from the api page:

DataEvents<IMyDataType>.OnStoreChanged += new StoreEventHandler(DataEvents_OnStoreChanged);

...

void DataEvents_OnStoreChanged(object sender, StoreEventArgs storeEventArgs)
{        
    if (!storeEventArgs.DataEventsFired)
    {
        // an external update event happened - DataEvents_OnBeforeAdd not fired
        // here a complete cache flush could be done
    }
}

If you care about page publishing you would have to use DataEvents<IPage> and check the StoreEventArgs for the PublicationScope which should tell you whether this was a publishing event or not.

From the documentation of DataEvents<T>.OnStoreChanged:

This event is fired after changes has happened to the Composite C1 data store. This may be atomic actions or a larger change to the underlying data store. The StoreEventArgs class describe the change in broad terms, including a flag indicating is detailed data event have been raised or not. You can use this event as a simple way to react to data changes (like clearing a cache) or you can mix this with atomic data events (add, delete, update) to make a build a more advanced cache. You should listen to this event in order to support scale out across multiple servers, since this event is meant to be signaled when changes happen on another server. In such situations detailed data events will not fire on other machines.

If you care about exactly what data was changed in the event, you have to use the other events of the DataEvents<T>class like OnAfterUpdate and get this information from the DataEventArgs.

magnattic
  • 12,638
  • 13
  • 62
  • 115