views:

324

answers:

1

Hello,

Im developing a silverlight app and I need to synchronize a list in different silverlight instances that can be offline. I'll have a server online to sync them.

So we can imagine this:

pc1: A1 A2 A3

pc2: A1 A2 (A3 deleted)

server: A1 A2 A3 (deletes A3 to reflect pc2 and then updates pc1 to also delete)

It must reflect reorder of the items too. I'll want to use this with silverlight online and offline (out of the browser).

Has any of you solved a problem similar to this one? What are good approaches to it?

Thank you, Artur

+2  A: 

In a normal disconnected environment you'd use something like Synchronization Services to handle this, but that's a little heavy-weight to have on the Silverlight client.

I'd start by giving each item in the list a GUID. Then I'd maintain a log of inserts, updates, and deletes of the list on each client and on the server. Then every time a client connects to the server you have to do a merge synchronization. In that case you have to detect and handle conflicts:

  • Someone edits an item, while someone else deletes it
  • Two clients edit an item simultaneously

Your requirement to handle re-ordering of items adds some complexity. You might want to log a re-ordering as a "moved before item x" or "moved after item x" action, rather than updating all the indexes of all items in the list.

Scott Whitlock
Scot, thank you for the answer. I'm looking at Microsoft Sync Framework and it seems that I'll have to implement the sync stuff like you are saying. I was trying to avoid it. I'm storing the items in a List, so i can say InsertAt(x) and the problem is solved.
Artur Carvalho
@Artur: you are basically trying to implement an optimistic algorithm where you assume most updates won't conflict. However, the server still has to do a lot of work to make sure to detect conflicts, arbitrate them, and then update the relevant clients with the changes. This means after a user makes a change and thinks its committed, and the server has to overwrite that change, the user should get a message that their change was overwritten or lost.
Scott Whitlock