Friday, April 28, 2006

Event Manager Code - EventPublisherAttribute.cs

The EventPublisherAttribute is a C# attribute that decorates a function that publishes an internal event. Any function that publishes an event out to our little event broker should decorate itself with this attribute.For example:


[EventPublisher("Brokerage.TradingSystem.Trade.ReceivedFromBackend")]
public void OnTradeReceived(Trade trade)
{
.......
EventManager.Fire(this, "Brokerage.TradingSystem.Trade.ReceivedFromBackend",
tradeArgs);
}



Here is the code:


using System;
// --------------------------------------------------------------------
//
// This code is (C) Copyright 2005 Marc Adler
//
// --------------------------------------------------------------------

namespace Magmasystems.EventManager
{
///
/// EventPublisherAttribute
///

public class EventPublisherAttribute : Attribute
{
private string _topicName;

public EventPublisherAttribute()
{
}

///
/// EventPublisherAttribute
///

/// The name of the event
public EventPublisherAttribute(string topicName)
{
this._topicName = topicName;
}

public string Topic
{
get
{
return this._topicName;
}
set
{
this._topicName = value;
}
}
}
}


©2006 Marc Adler - All Rights Reserved

No comments: