Joutsen v0.5.0+12-g5dd5f7e
Public Member Functions | Protected Member Functions | Properties | List of all members
Joutsen.Events.AggregatingEvent< TPayload > Class Template Referenceabstract

A base class for events that do not dispatch immediately but delay dispatching in order to collect multiple instances and dispatch them together. More...

Public Member Functions

 AggregatingEvent (string name)
 in derived classes creates a new instance of an event. More...
 
override void Fire (TPayload payload)
 Fires the event with the payload. More...
 
- Public Member Functions inherited from Joutsen.Events.PayloadEvent< TPayload >
 PayloadEvent (String eventName)
 Creates a new instance of an event. More...
 
virtual void Fire (TPayload payload)
 Fires the event with the payload. More...
 
void Fire (TPayload payload)
 Informs all listeners that the event was fired and passes the payload to them. More...
 

Protected Member Functions

void FireAggregatedEvent (Task task=null)
 Fires the event with the aggregated payload. More...
 
abstract TPayload Aggregate (TPayload newPayload, TPayload aggregatedPayload)
 Can be used in child classes to implement the aggregation of the payload. More...
 

Properties

TimeSpan AggregationInterval [get, set]
 The time to delay firing the event in order to aggregate changes in the payload. More...
 
- Properties inherited from Joutsen.Events.PayloadEvent< TPayload >
string Name [get]
 The name of the event which will also be passed to the listeners when the event is fired. More...
 
- Properties inherited from Joutsen.Events.Event< TPayload >
String Name [get]
 The name of the event which will also be passed to the listeners when the event is fired. More...
 

Additional Inherited Members

- Events inherited from Joutsen.Events.PayloadEvent< TPayload >
Action< string, TPayload > Fired
 The .NET event that will be fired if the event is fired. More...
 
- Events inherited from Joutsen.Events.Event< TPayload >
Action< string, TPayload > Fired
 The .NET event that will be fired if the event is fired. More...
 

Detailed Description

A base class for events that do not dispatch immediately but delay dispatching in order to collect multiple instances and dispatch them together.

Remarks
In order to create aggregating child events only the method Aggregate must be implemented. The method specifies how the payload can be aggregated in order to sent both events together. This aggregation mechanism is mostly used for consecutive updates or to collect multiple changed properties and dispatch them together. E.g. an event that informs listeners about a property change could use the Aggregation to only sent the last valid value. Similarly multiple property changes could be gathered before infroming the listeners if the payload is a complex object with multiple properties.
The default delay for aggregation is 500ms.
Since
0.2.0
Type Constraints
TPayload :class 

Constructor & Destructor Documentation

◆ AggregatingEvent()

Joutsen.Events.AggregatingEvent< TPayload >.AggregatingEvent ( string  name)

in derived classes creates a new instance of an event.

Parameters
namethe name of the event
Exceptions
System.ArgumentExceptionif the name is empty, null or consists only of wihtespace characters

Member Function Documentation

◆ Aggregate()

abstract TPayload Joutsen.Events.AggregatingEvent< TPayload >.Aggregate ( TPayload  newPayload,
TPayload  aggregatedPayload 
)
protectedpure virtual

Can be used in child classes to implement the aggregation of the payload.

Parameters
newPayloadthe payload of the latest event that is not aggregated yet
aggregatedPayloadthe aggregated payload of previous calls to Fire. It combines the payloads that were aggregated during the delay. It can be null if the event was not fired since the last dispatch.
Returns
the aggregation of newPayload and aggregatedPayload if they should/can be combined and dispatched together. Otherwise null.
Remarks
This method controls the actual dispatch of the event. If it returns null, the event with the new payload will be dispatched immediately if it returns a value this value will be the value that is dispatched as the payload when the delay interval is exceeded.

◆ Fire()

override void Joutsen.Events.AggregatingEvent< TPayload >.Fire ( TPayload  payload)
virtual

Fires the event with the payload.

Parameters
payloadthe payload to send

Reimplemented from Joutsen.Events.PayloadEvent< TPayload >.

◆ FireAggregatedEvent()

void Joutsen.Events.AggregatingEvent< TPayload >.FireAggregatedEvent ( Task  task = null)
protected

Fires the event with the aggregated payload.

Property Documentation

◆ AggregationInterval

TimeSpan Joutsen.Events.AggregatingEvent< TPayload >.AggregationInterval
getset

The time to delay firing the event in order to aggregate changes in the payload.

Exceptions
System.ArgumentExceptionif the interval is set to a negative value