Global Item

Topics: Mobile Client Software Factory
Sep 18, 2007 at 5:51 PM
Hi,

I am new to the CAB philosophy and i am having a few issues.
I want to create something of the kind:
I have a connection with a gps, this connection then has several events that notify when speed, heading or whatever changes.
I want to create something in the shell, that initializes the gps and then have publish the above mentioned events so that other modules that have subscribed them can handle the changes. I know this must be a very simple question, but i can understand how to do this.

Thanks
Developer
Sep 19, 2007 at 2:38 PM
Edited Sep 19, 2007 at 2:40 PM
Hi

For the publication and subscription to events, CAB uses Event Broker.
After initializing your GPS you must publish the event of this way:

[EventPublication("topic://MyEvent", PublicationScope.Global)]
public event EventHandler<DataEventArgs<MyClass>> MyEvent;
The first parameter of the EventPublication attribute is the name. The name is a string that identifies the event, for example, “topic://MyEvent”. The URI syntax convention is recommended to allow for organized and hierarchical naming.

Later you must add the method that fire the event:

public void Fire(MyClass myObject)
{
    OnFireEvent(myObject);
}
 
protected virtual void OnFireEvent(MyClass myObject)
{
    if (MyEvent != null)
    {
       MyEvent(this, new DataEventArgs<MyClass>(myObject));
    }
}
You must call the Fire method when you want to fire the event.

Finally you must add the EventSuscription attribute to the method that you want to be execute when the event is fired:

[EventSubscription("topic://MyEvent", Thread = ThreadOption.UserInterface)]
public void OnGPSEventFired(object sender, DataEventArgs<MyClass> e)
{
    //TODO: Add the logic of your method.
}
I recommend to you that you read the topic Developing Applications Using the Composite UI Application Block | Publishing and Subscribing to Events of the CAB's help.

Please let me know if this helps!

Mariano Converti
http://staff.southworks.net/blogs/mconverti/