Monitoring Pocket Outlook Changes that Occur Outside of your .NET CF Application

You Can Take it With You

Syndication

News

  • Don't miss the next Windows Mobile Webcast... Unit Testing for Mobile Devices: http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032382824&EventCategory=4&culture=en-US&CountryCode=US.

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

Comments

panish wrote re: Monitoring Pocket Outlook Changes that Occur Outside of your .NET CF Application
on 04-01-2008 4:40 AM
Hi,
Thanks for giving this sample.
It works fine in WindowsMobile6.0 but it is not working in WM5.0. There is an error while Pinvoking that DLL.
Can u pls tell me what is the problem in wm5.0
Jim Wilson wrote re: Monitoring Pocket Outlook Changes that Occur Outside of your .NET CF Application
on 04-01-2008 9:04 AM
Panish;

I'm not sure what the source of the problem is with WM5. It seems that on WM5 the app just doesn't want to load the native DLL.

I'll have to dig into more to get a handle what's wrong. It'll probably be later in the week when I have time to check it out. I'll follow up here as soon as I know how deal with the problem.

My apologies for the difficulty.

Jim
Gerardo wrote re: Monitoring Pocket Outlook Changes that Occur Outside of your .NET CF Application
on 04-01-2008 11:32 AM
Hi,

I have the same issue with WM5. Other than that, the code is excellent!!

Thank you,

Gerardo
Jim Wilson wrote re: Monitoring Pocket Outlook Changes that Occur Outside of your .NET CF Application
on 04-01-2008 12:21 PM
Gerardo;

Thanks for the kind words.

I'll hopefully have a chance in the next few days to figure out what's causing the trouble on WM5.

Thanks,
Jim
Panish wrote re: Monitoring Pocket Outlook Changes that Occur Outside of your .NET CF Application
on 04-17-2008 9:13 PM
Hi Jim,
Did u get any reasons for the problem in WM5?
Jim Wilson wrote re: Monitoring Pocket Outlook Changes that Occur Outside of your .NET CF Application
on 04-18-2008 6:21 AM
Panish;

My apologies, I've been swamped and haven't had a chance to spend any real time investigating.

I'm booked out solid through the end of the month. I will block out a day the week of 5-May to resolve the problem.

I'm sorry I can't take a look at it sooner, this is just an crazy busy time for me right now. I apologize for the inconvenience.

Jim
Gerben wrote re: Monitoring Pocket Outlook Changes that Occur Outside of your .NET CF Application
on 06-16-2008 10:14 AM
Hello Jim,

Great sample code!

When I test it, the sample code only runs on WM 6 Classic, not on WM 6 Professional or WM5.

Cheers,
Gerben
Jim Wilson wrote re: Monitoring Pocket Outlook Changes that Occur Outside of your .NET CF Application
on 06-16-2008 11:40 AM
Gerben;

Thank you for your kind words and the info on the platforms that aren't working.

I'll have a look at the code and see what might be breaking it on the other platforms.

Thanks,
Jim
Gerben wrote re: Monitoring Pocket Outlook Changes that Occur Outside of your .NET CF Application
on 06-26-2008 1:21 AM
Hello Jim,

I have tested the code a little bit further. It works on WM 6 Professional, but I cannot get it to work on WM 5.

Since I don't know anything about native development and you might not have the time to investigate it further, would you mind if I post a question about it on a MSDN forum?

If I get a solution, I will mail it to you, offcourse.

It is great code and it would be nice if it also worked on WM5.

Cheers,
Gerben

Add a Comment

(required)  
(optional)
(required)  
Remember Me?