No fórum da MSDN dedicado ao SQL Compact surgiu uma questão arquitectural que, de forma resumida, pretende que se debata um modelo sobre como abstraír uma aplicação da questão se está ou não online. A minha resposta, em inglês foi a seguinte:
I think we can break this in two parts: getting data from the server and putting data on the server.
To get data from the server, you have to think how much data you may need on the client side, and how often it may change on the server side. As app like a survey app is very different from an app where you can insert orders, getting the current stock level for each product you select and get the most up-to-date information about the customer credit balance.
So, depending on those details you should consider a simple model, where the app on startup get’s all up to date information it needs and stores it in objects in memory or cached locally, or a more complex model, where while connected the client app has to keep a local cache up to date, either with a polling mechanism (the client checks for updates) or a notification mechanism (the server notifies the client).
About putting the infomation created/updated/deleted back on the server, I would consider a permanent cache, like a SQL Compact database, and a flag mechanism per record. All operations on the client app would be done locally on the cache, updating the flag status accordingly and whenever the server was reachable, a differnent thread would be uploading those operations and reseting the flag.
The critical issue when you assume that your app has to work mostly online but also offline, is that in most scenarios you don’t know when you are going to offline, so no chance for a last breath to get up to date information.
About the technology to sync information, you may roll out your own, or if your client app is a desktop app, take a look athe the ADO.net Sync Services, namely the current v2 CTP, which is a very optimized mechanism based on rules to synchronize databases.
Se tiverem dificuldade em perceber alguma coisa, ou quiserem partilhar um comentário sobre o tema, estejam à vontade para usar os comentários do blog.