Recently a friend of mine was doing some work with the Pocket Outlook (or Outlook Mobile whatever it's called now) managed API. He commented that the managed API made it very easy to be notified of changes to the Tasks, Appointments, and Contacts that occurred within the application - however, he couldn't find a way to be notified of changes that occurred outside of his application.
This didn't sound right to me as I know that the native POOM API provides an excellent notification architecture that allows your application to be notified of changes made by your app, or changes made by other apps, or all changes. Since managed POOM is a wrapper over Native POOM, they must have exposed this functionality .... Well, much to my surprise that's not the case. If you dig into the Managed POOM implementation, it implements its own notification handling. Basically when you call Update or Delete, the managed API raises the appropriate event directly rather than cooperating with the Pocket Outlook engine as the Native API does.
Although I like the Managed POOM API overall, not being able to track changes made by the regular Pocket Outlook Tasks, Calendar, and Contacts applications is a pretty big limitation. And with that came the motivation for me to create the PoomFolderMonitor class.
Like the name sounds, the PoomFolderMonitor class monitors the Pocket Outlook Tasks, Appointments, and Contacts folders and exposes events that fire when a change is made to any of the items. It's basically a simple wrapper over the native POOM API that uses a MessageWindow to monitor for changes to the Pocket Outlook items, and then translates those changes into managed events.
The exposed events have the same signature as the events on the regular Managed POOM API. One change of note, is that in your event handling code, (if you would like to) you can cast the second parameter from ListChangedEventArgs to PoomFolderMonitorListChangedEventArgs. The PoomFolderMonitorListChangedEventArgs class includes a reference to the Task, Appointment, or Contact that was changed (except for in the case of deletes).
I haven't had a chance to write up anything formal on it yet so here's the information from the email I sent to my friend when I sent the PoomFolderMonitor implementation to him.
Here's PoomFolderMonitor class and a very simple sample
Basically you create an instance of the PoomFolderMonitor passing a reference to an OutlookSession object.
You then attach delegates to one or more of the AppointmentListChanged, ContactListChanged, TaskListChanged events. These events have the exact same signature of the Managed POOM ListChanged events.
Although the 2nd argument "e" to the event handlers is of type ListChangedEventArgs (for compatibility with ListChangedEventHandlers) it's actually an instance of the PoomFolderMonitorListChangedEventArgs class which inherits from ListChangedEventArgs. The extended class adds a reference to the changed item (except on delete) and the native OID.
The example program demonstrates sending both the Managed ListChanged events and the PoomFolderMonitor events to the same event handler and then checking the parameter to see if it's the extended version or not.
The PoomFolderMonitor events are consistent with the POOM ListChanged events with one exception. In the case of a delete, the POOM Managed classes cache the index of the item being deleted before deleting it and can therefore include the index in the event notification. They can do this because they are doing the delete themselves. Getting that index from the native API notifications isn't possible so I pass a -1 as the index of the deleted item. This is the only difference.
The sample app is super simple. It writes all of its output to the Visual Studio Output window. There are menu options to modify a task, appointment, and contact. In this case the menu handlers always just appends some text to the subject of the first item in the folder. There's a delete task option which always deletes the last task.
What, of course, is most interesting is to add, delete, change items using the regular Tasks, Contacts, and Calendar applications and seeing the sampel app write the appropriate output to the Visual Studio Output window.
Hopefully in the upcoming weeks, I'll have a chance to write and publish a short paper describing the PoomFolderMonitor implementation in more detail.
Feel free to ping me here with any questions.
Posted
Oct 18 2007, 05:45 PM
by
jim-wilson