Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NonNB - 06 Feb 2008 07:07 GMT
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
NonNB - 07 Feb 2008 07:48 GMT
Hi

FYI below links show how this can be done.

Rich Newman is right - there is no need to add the Publication or even
the Event topic "constant" before "Firing it".

http://richnewman.wordpress.com/2007/09/23/events-in-the-cab-introduction-to-cab
scsf-part-12/

http://safari.oreilly.com/9780735624146/ch06lev1sec4
http://forums.lhotka.net/forums/ShowThread.aspx?PostID=10154#10154

Cheers.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.