|
Power Up Your Apps With Event Sinks
Exchange 2000's event sinks can respond to events as they are occurring as well as after they occur.
by Patricia Cardoza
Posted July 22, 2002
Exchange 2000 introduced a new technology to developers: event sinks. Previous versions of Exchange had only event agents, which could respond to events after they occurred. This worked fine in many circumstances, but imposed severe limitations in others. For example, if you wanted to write an event agent to perform an operation when an item was deleted from a public folder, the agent would fire, but it would have no idea what item had actually been deleted because the item would already have been gone by the time the agent fired. Exchange 2000's event sinks can respond to events as they are occurring as well as after they occur. This gives developers greater flexibility and power in their applications.
Synchronous events fire after a client application has made a request to Exchange, but before the request is processed. These events can either commit the transaction in process or cancel it, depending on the code in the event. A typical use of synchronous events is to validate data before an item is saved. The two synchronous events are OnSyncSave and OnSyncDelete. OnSyncSave, which fires immediately before an item is saved, fires when a new item is created, changes are saved, or an item is copied or moved to a new location. OnSyncDelete fires immediately before an item is removed from its current location by deleting or moving. Asynchronous events fire after the data request has been completed. Two events are exposed here: OnSave and OnDelete.
Two components make up a functional event. The first is the event sink, which is a Component Object Model (COM) component containing code that fires when the event occurs. You can create event sinks using Visual Basic, Visual C++, or even VBScript. The second component is an event registration, a hidden item that contains the association between an event and an event sink. This registration is saved in the folder firing the event. You create event registrations using ADO, XML, or VBScript.
To create an event sink using Visual Basic 6 (SP5), start with an ActiveX DLL project. From the Project menu, select References and add a reference to the ExOLEDB Type Library (exoledb.dll). This allows you to create the specific event procedures you'll need in your event sink. Other libraries you might want to include: ActiveX Data Objects Library for ADO access to an item's properties; CDO for Exchange 2000 to generate notifications from your event; and Active DS Type Library to manage distribution groups and identify the user, domain, and server the script is running on.
Build the event by implementing the proper interfaces and calling their methods. If you're using synchronous events, use this statement:
Implements ExOLEDB.IExStoreSyncEvents
Back to top
|