EventBroker in Composite Application Block - Generic way to Raise /Fire Events at Run Time?


N

NonNB

Hi

This must be quite a common question with CAB's Event Broker - is
there any way to Raise Events dynamically at runtime ?

We would like to remove the hard coding from our "Event Dispatching"
pump along the lines of the following pseudo code:

foreach (message in queue)
{
// e.g. Message.Topic might be "topic://SomeTopic"
EventBroker.FireEvent(message.Topic, new
[Data]EventArgs<MessageClass>(message));
}

The message is a standard format for all "Events"
(We might need to determine whether there are any subscribers to the
"SomeTopic" event - EventBroker again might be able to assist here.

And then in the respective modules, the EventSubscriptions remain "as
they are" (i.e. Design Time)

[EventSubscription("topic://SomeTopic")]
public void ActionSomeTopic(object sender,
[Data]EventArgs<MessageClass> e)


What we want to avoid is having to manually add new publications to
the dispatcher, i.e. NOT the current :

[EventPublication(EventTopicNames.SomeTopic1)]
public event EventHandler<EventArgs<MessageClass>> SomeTopic1Event;
[EventPublication(EventTopicNames.SomeTopic2)]
public event EventHandler<EventArgs<MessageClass>> SomeTopic2Event;
....
[EventPublication(EventTopicNames.SomeTopicN)]
public event EventHandler<EventArgs<MessageClass>> SomeTopic3Event;

void Dispatcher()
{
foreach (message in queue)
{
switch (message.Topic)
{
case "SomeTopic1":
if (SomeTopic1Event != null)
{
SomeTopic1Event(this, new
EventArgs<MessageClass>(message))
}
break;
case "SomeTopic2":
if (SomeTopic2Event != null)
{
SomeTopic2Event(this, new
EventArgs<MessageClass>(message))
}
break;
etc
}
}

A dynamic event raising mechanism would be far more elegant

Thanks in Advance!

Stuart
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top