Saturday, May 19, 2007

Publishing Events

You can publish events using the EventPublication attribute on an event declaration. This attribute uses two parameters: the event name and the event scope.

The event name is a string that identifies the event, for example, event://UpdatesAvailable. The URI syntax convention is recommended to allow for organized and hierarchical naming. For example, event://UpdatesAvailable/New and event://UpdatesAvailable/Deleted.

Use the PublicationScope enumeration to define the event scope as global, available only to this WorkItem and its descendents, or local to this WorkItem.


To publish an event that is available in all WorkItem instances

  1. Create the event definition as shown in the following code.
    public event SomeEventHandler UpdatesAvailable;
  2. Add the EventPublication attribute to the definition using the PublicationScope.Global parameter as shown in the following code.
    [EventPublication("event://UpdatesAvailable", PublicationScope.Global)]
    public event SomeEventHandler UpdatesAvailable;


To publish a event available only to the local and descendant WorkItems

  1. Create the event definition as shown in the following code.
    public event SomeEventHandler UpdatesAvailable;
  2. Add the EventPublication attribute to the definition using the PublicationScope.Descendants parameter as shown in the following code.
    [EventPublication("event://UpdatesAvailable",
    PublicationScope.Descendants)]
    public event SomeEventHandler UpdatesAvailable;

To publish an event that is available only to the local WorkItem

  1. Create the event definition as shown in the following code.
    public event SomeEventHandler UpdatesAvailable;
  2. Add the EventPublication attribute to the definition using the PublicationScope.WorkItem parameter as shown in the following code.

    [EventPublication("event://UpdatesAvailable", PublicationScope.WorkItem)]
    public event SomeEventHandler UpdatesAvailable;


No comments: