Skip to main content
added 19 characters in body
Source Link
Matthew Dresser
  • 6.1k
  • 2
  • 29
  • 77

~In Sitecore 9 the event model has changed somewhat and events are now queued within each DB (master, core, web etc).~In Sitecore 9 the event model has changed somewhat and events are now queued within each DB (master, core, web etc).

EditEdit: turns out I was a bit wrong here. Sitecore has for some time had the ability to queue events with each DB. However, Sitecore.Eventing.EventManager.QueueEvent() has been deprecated in Sitecore 9.

Previously in Sitecore, we would use code like this to raise an event:

var args = new Testing.Events.MyEventArgs();
Sitecore.Events.Event.RaiseEvent("testing:myevent", args);

Note how the name of the event is passed ("testing:myevent") and then some args which I believe are generic event args which are then cast back to a specific EventArg type within the handling event.

In Sitecore 9 and later, we would use something like below

var database = Sitecore.Configuration.Factory.GetDatabase("web");
var eventQueue = database.RemoteEvents.EventQueue;
eventQueue.QueueEvent(someObject);

I'm confused as to what/how to create the object someObject. The QueueEvent method has two signatures:

QueueEvent(RemoteEventArgs<TEvent> event)
QueueEvent(RemoteEventArgs<TEvent> event, bool addToGlobalQueue, bool addToLocalQueue)

Say I want to raise the event publish:end:remote to trigger a cache clear, I look at the configs and see a load of different handlers for this event (I have SXA and Commerce installed) but looking at the OOTB one which is Sitecore.Publishing.HtmlCacheClearer within Sitecore.Kernel.dll it has a method ClearCache(object sender, EventArgs e) i.e. just a generic EventArgs parameter.

I don't understand how the event object passed to QueueEvent identifies the name of the event. I also don't see how the event could be identified magically by passing in a specific event arg type.

~In Sitecore 9 the event model has changed somewhat and events are now queued within each DB (master, core, web etc).~

Edit: turns out I was wrong here. Sitecore has for some time had the ability to queue events with each DB. However, Sitecore.Eventing.EventManager.QueueEvent() has been deprecated in Sitecore 9.

Previously in Sitecore, we would use code like this to raise an event:

var args = new Testing.Events.MyEventArgs();
Sitecore.Events.Event.RaiseEvent("testing:myevent", args);

Note how the name of the event is passed ("testing:myevent") and then some args which I believe are generic event args which are then cast back to a specific EventArg type within the handling event.

In Sitecore 9 and later, we would use something like below

var database = Sitecore.Configuration.Factory.GetDatabase("web");
var eventQueue = database.RemoteEvents.EventQueue;
eventQueue.QueueEvent(someObject);

I'm confused as to what/how to create the object someObject. The QueueEvent method has two signatures:

QueueEvent(RemoteEventArgs<TEvent> event)
QueueEvent(RemoteEventArgs<TEvent> event, bool addToGlobalQueue, bool addToLocalQueue)

Say I want to raise the event publish:end:remote to trigger a cache clear, I look at the configs and see a load of different handlers for this event (I have SXA and Commerce installed) but looking at the OOTB one which is Sitecore.Publishing.HtmlCacheClearer within Sitecore.Kernel.dll it has a method ClearCache(object sender, EventArgs e) i.e. just a generic EventArgs parameter.

I don't understand how the event object passed to QueueEvent identifies the name of the event. I also don't see how the event could be identified magically by passing in a specific event arg type.

In Sitecore 9 the event model has changed somewhat and events are now queued within each DB (master, core, web etc).

Edit: turns out I was a bit wrong here. Sitecore has for some time had the ability to queue events with each DB. However, Sitecore.Eventing.EventManager.QueueEvent() has been deprecated in Sitecore 9.

Previously in Sitecore, we would use code like this to raise an event:

var args = new Testing.Events.MyEventArgs();
Sitecore.Events.Event.RaiseEvent("testing:myevent", args);

Note how the name of the event is passed ("testing:myevent") and then some args which I believe are generic event args which are then cast back to a specific EventArg type within the handling event.

In Sitecore 9 and later, we would use something like below

var database = Sitecore.Configuration.Factory.GetDatabase("web");
var eventQueue = database.RemoteEvents.EventQueue;
eventQueue.QueueEvent(someObject);

I'm confused as to what/how to create the object someObject. The QueueEvent method has two signatures:

QueueEvent(RemoteEventArgs<TEvent> event)
QueueEvent(RemoteEventArgs<TEvent> event, bool addToGlobalQueue, bool addToLocalQueue)

Say I want to raise the event publish:end:remote to trigger a cache clear, I look at the configs and see a load of different handlers for this event (I have SXA and Commerce installed) but looking at the OOTB one which is Sitecore.Publishing.HtmlCacheClearer within Sitecore.Kernel.dll it has a method ClearCache(object sender, EventArgs e) i.e. just a generic EventArgs parameter.

I don't understand how the event object passed to QueueEvent identifies the name of the event. I also don't see how the event could be identified magically by passing in a specific event arg type.

Became Hot Network Question
added 200 characters in body
Source Link
Matthew Dresser
  • 6.1k
  • 2
  • 29
  • 77

In~In Sitecore 9 the event model has changed somewhat and events are now queued within each DB (master, core, web etc).~

Edit: turns out I was wrong here. Sitecore has for some time had the ability to queue events with each DB. However, Sitecore.Eventing.EventManager.QueueEvent() has been deprecated in Sitecore 9.

Previously in Sitecore, we would use code like this to raise an event:

var args = new Testing.Events.MyEventArgs();
Sitecore.Events.Event.RaiseEvent("testing:myevent", args);

Note how the name of the event is passed ("testing:myevent") and then some args which I believe are generic event args which are then cast back to a specific EventArg type within the handling event.

In Sitecore 9 and later, we would use something like below

var database = Sitecore.Configuration.Factory.GetDatabase("web");
var eventQueue = database.RemoteEvents.EventQueue;
eventQueue.QueueEvent(someObject);

I'm confused as to what/how to create the object someObject. The QueueEvent method has two signatures:

QueueEvent(RemoteEventArgs<TEvent> event)
QueueEvent(RemoteEventArgs<TEvent> event, bool addToGlobalQueue, bool addToLocalQueue)

Say I want to raise the event publish:end:remote to trigger a cache clear, I look at the configs and see a load of different handlers for this event (I have SXA and Commerce installed) but looking at the OOTB one which is Sitecore.Publishing.HtmlCacheClearer within Sitecore.Kernel.dll it has a method ClearCache(object sender, EventArgs e) i.e. just a generic EventArgs parameter.

I don't understand how the event object passed to QueueEvent identifies the name of the event. I also don't see how the event could be identified magically by passing in a specific event arg type.

In Sitecore 9 the event model has changed somewhat and events are now queued within each DB (master, core, web etc).

Previously in Sitecore, we would use code like this to raise an event:

var args = new Testing.Events.MyEventArgs();
Sitecore.Events.Event.RaiseEvent("testing:myevent", args);

Note how the name of the event is passed ("testing:myevent") and then some args which I believe are generic event args which are then cast back to a specific EventArg type within the handling event.

In Sitecore 9 and later, we would use something like below

var database = Sitecore.Configuration.Factory.GetDatabase("web");
var eventQueue = database.RemoteEvents.EventQueue;
eventQueue.QueueEvent(someObject);

I'm confused as to what/how to create the object someObject. The QueueEvent method has two signatures:

QueueEvent(RemoteEventArgs<TEvent> event)
QueueEvent(RemoteEventArgs<TEvent> event, bool addToGlobalQueue, bool addToLocalQueue)

Say I want to raise the event publish:end:remote to trigger a cache clear, I look at the configs and see a load of different handlers for this event (I have SXA and Commerce installed) but looking at the OOTB one which is Sitecore.Publishing.HtmlCacheClearer within Sitecore.Kernel.dll it has a method ClearCache(object sender, EventArgs e) i.e. just a generic EventArgs parameter.

I don't understand how the event object passed to QueueEvent identifies the name of the event. I also don't see how the event could be identified magically by passing in a specific event arg type.

~In Sitecore 9 the event model has changed somewhat and events are now queued within each DB (master, core, web etc).~

Edit: turns out I was wrong here. Sitecore has for some time had the ability to queue events with each DB. However, Sitecore.Eventing.EventManager.QueueEvent() has been deprecated in Sitecore 9.

Previously in Sitecore, we would use code like this to raise an event:

var args = new Testing.Events.MyEventArgs();
Sitecore.Events.Event.RaiseEvent("testing:myevent", args);

Note how the name of the event is passed ("testing:myevent") and then some args which I believe are generic event args which are then cast back to a specific EventArg type within the handling event.

In Sitecore 9 and later, we would use something like below

var database = Sitecore.Configuration.Factory.GetDatabase("web");
var eventQueue = database.RemoteEvents.EventQueue;
eventQueue.QueueEvent(someObject);

I'm confused as to what/how to create the object someObject. The QueueEvent method has two signatures:

QueueEvent(RemoteEventArgs<TEvent> event)
QueueEvent(RemoteEventArgs<TEvent> event, bool addToGlobalQueue, bool addToLocalQueue)

Say I want to raise the event publish:end:remote to trigger a cache clear, I look at the configs and see a load of different handlers for this event (I have SXA and Commerce installed) but looking at the OOTB one which is Sitecore.Publishing.HtmlCacheClearer within Sitecore.Kernel.dll it has a method ClearCache(object sender, EventArgs e) i.e. just a generic EventArgs parameter.

I don't understand how the event object passed to QueueEvent identifies the name of the event. I also don't see how the event could be identified magically by passing in a specific event arg type.

Source Link
Matthew Dresser
  • 6.1k
  • 2
  • 29
  • 77

How to raise an event in Sitecore 9+

In Sitecore 9 the event model has changed somewhat and events are now queued within each DB (master, core, web etc).

Previously in Sitecore, we would use code like this to raise an event:

var args = new Testing.Events.MyEventArgs();
Sitecore.Events.Event.RaiseEvent("testing:myevent", args);

Note how the name of the event is passed ("testing:myevent") and then some args which I believe are generic event args which are then cast back to a specific EventArg type within the handling event.

In Sitecore 9 and later, we would use something like below

var database = Sitecore.Configuration.Factory.GetDatabase("web");
var eventQueue = database.RemoteEvents.EventQueue;
eventQueue.QueueEvent(someObject);

I'm confused as to what/how to create the object someObject. The QueueEvent method has two signatures:

QueueEvent(RemoteEventArgs<TEvent> event)
QueueEvent(RemoteEventArgs<TEvent> event, bool addToGlobalQueue, bool addToLocalQueue)

Say I want to raise the event publish:end:remote to trigger a cache clear, I look at the configs and see a load of different handlers for this event (I have SXA and Commerce installed) but looking at the OOTB one which is Sitecore.Publishing.HtmlCacheClearer within Sitecore.Kernel.dll it has a method ClearCache(object sender, EventArgs e) i.e. just a generic EventArgs parameter.

I don't understand how the event object passed to QueueEvent identifies the name of the event. I also don't see how the event could be identified magically by passing in a specific event arg type.