Skip to main content

Syncronizing contacts in Exchange 2007 with other things - helper class

Copying a Contact in Exchange is one thing synchronizing is another this can be one of the great contradictions and issues that faces anybody looking at synchronizing contacts between different storage mediums. Whether that be a Database, CSV file or other Mail System underlying its the same information stored and accessed in a different way. Because Exchange isn't your normal flat file database more a relatively complex property store that uses some complex datatypes doing property level synchronization does provide a unique set of challenges. Exchange Web Service presents some of these properties in more workable format but apart from this doesn't give a lot of help is solving this fundamental issue. The SyncFolderItem and notification operations only provide an Item level ability to spot changes on an item so the brave souls who want to embark on a greater level of synchronization must take this challenge unto themselves.

If your going to compare two contacts it first helps to have them in the same format there are a few methods of doing this one way you might go about this if your using Exchange 2007 and SQL 2005 is using something like http://msdn.microsoft.com/en-gb/library/bb508823.aspx. The path I've gone down it to convert them into the ContactType class that's used in EWS. This may or may not be the best method but it does have a flexibility that I'm after. With flexibility comes a great ability to do some really cool things.

So what I've come up with is a method that takes two ContactType objects as parameters and then returns a generic list of SetItemFieldType updates that can then be used direct in a UpdateItem Operation. With EWS you need to have a separate SetItemFieldType for each property of an item you want to update. If you have a large number of properties you are updating on an Item especially if they are different datatypes then these requests can get lengthy and complex. The first contact object represents the source object which has the new information you want synchronized and the second is destination object which you want updated. The changes that are returned are the differences on the source object when compared against the destination object. Because Contacts are made up of complex datatypes the compare class needs to deal differently depending on which property you are looking at.

String Properties:
For string properties a simple comparison is done to work out if one property is different from the other.

String Arrays: For String arrays the elements of the arrays are joined and then the strings of the joined array is compared.

Email Addresses, Phone Numbers, Street Addresses: These are special indexed arrays so to compare the index valued two hashtables are used. The Hashtables allow the ability to do string comparison of the values based on the on the indexed values. With Street Addresses because of the way the indexing works with these properties nested hash tables are used.

Extended Properties:Extended Mapi properties are one of the things that make objects in Exchange hard to deal with. The class will go through any that are set in the source contact and that are retrieved in the destination object and and will do a comparison based on either the propertyID or propertyTag. Because there is no real good method to get all the Extended properties that have been set on a item unless you use ExMapi this is one area where you can and will loose fidelity on items you might be synchronizing because each of these properties must be explicitly specified if you want to synchronize them.

Because the SetItemUpdate will be different for each of these types there is a separate method that handles building the update.

Whats missing - This helper class will look for whats been added or changed in a contact and produce an update for those properties. But it wont produce
DeleteItemFieldType to delete properties that may have been removed in the source contact.

How to use this : Watch this space i'll have a few sample over the next couple of weeks on how to use this but i just wanted to introduce the code in a seperate post. I've put a download of the code I've talked about here the actual code is too large to post.







Popular posts from this blog

The MailboxConcurrency limit and using Batching in the Microsoft Graph API

If your getting an error such as Application is over its MailboxConcurrency limit while using the Microsoft Graph API this post may help you understand why. Background   The Mailbox  concurrency limit when your using the Graph API is 4 as per https://docs.microsoft.com/en-us/graph/throttling#outlook-service-limits . This is evaluated for each app ID and mailbox combination so this means you can have different apps running under the same credentials and the poor behavior of one won't cause the other to be throttled. If you compared that to EWS you could have up to 27 concurrent connections but they are shared across all apps on a first come first served basis. Batching Batching in the Graph API is a way of combining multiple requests into a single HTTP request. Batching in the Exchange Mail API's EWS and MAPI has been around for a long time and its common, for email Apps to process large numbers of smaller items for a variety of reasons.  Batching in the Gr...

Sending a Message in Exchange Online via REST from an Arduino MKR1000

This is part 2 of my MKR1000 article, in this previous post  I looked at sending a Message via EWS using Basic Authentication.  In this Post I'll look at using the new Outlook REST API  which requires using OAuth authentication to get an Access Token. The prerequisites for this sketch are the same as in the other post with the addition of the ArduinoJson library  https://github.com/bblanchon/ArduinoJson  which is used to parse the Authentication Results to extract the Access Token. Also the SSL certificates for the login.windows.net  and outlook.office365.com need to be uploaded to the devices using the wifi101 Firmware updater. To use Token Authentication you need to register an Application in Azure https://msdn.microsoft.com/en-us/office/office365/howto/add-common-consent-manually  with the Mail.Send permission. The application should be a Native Client app that use the Out of Band Callback urn:ietf:wg:oauth:2.0:oob. You ...

How to test SMTP using Opportunistic TLS with Powershell and grab the public certificate a SMTP server is using

Most email services these day employ Opportunistic TLS when trying to send Messages which means that wherever possible the Messages will be encrypted rather then the plain text legacy of SMTP.  This method was defined in RFC 3207 "SMTP Service Extension for Secure SMTP over Transport Layer Security" and  there's a quite a good explanation of Opportunistic TLS on Wikipedia  https://en.wikipedia.org/wiki/Opportunistic_TLS .  This is used for both Server to Server (eg MTA to MTA) and Client to server (Eg a Message client like Outlook which acts as a MSA) the later being generally Authenticated. Basically it allows you to have a normal plain text SMTP conversation that is then upgraded to TLS using the STARTTLS verb. Not all servers will support this verb so if its not supported then a message is just sent as Plain text. TLS relies on PKI certificates and the administrative issue s that come around certificate management like expired certificates which is why ...
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.