views:

244

answers:

2

Hello,

I would like to make a SL app that could save certain data in local and access it if it is disconnected. I think that I could expose the entities in the services (no dtos), and saving it in the isolated storage. WCF ria services for the services, but what about the SL app? Which is the best way for having a "local disconnected cached model"?

Thanks in advance and merry christmas

A: 

One of the techniques used for saving data on local machine is called "Isolated Storage". I'd suggest starting with that.

Video #1 Video #2

Maciek
+3  A: 

Anyone who gives you a straight answer to that question doesn't know what he's talking about.

One of the biggest challenges (read: Why Developers are actually employed) is that creating a disconnected client is hard.
Not terribly hard, but it requires software engineering experience and early tradeoffs and planning.

The question you asked is essentially "Well, How Do I build a Smart Client?"
There's been many wonderful books written on the topic and dozens of frameworks shipped on this very topic. So, as I was saying, no easy answer here.

The first thing you have to ask yourself is: What level of Smart Client do you need?
Are you building a fully disconnected client? A Semi Online/Offline client? A Partially enabled offline client? etc etc etc.

The way I normally look at it, is through features:

  • Is the scenario you're trying to support a temporary network connectivity loss?
    Or prolonged network connectivity loss?

The length of offline time (more specifically, if there's a reboot of the app) determined whether your cache will be saved on disk or can be trusted to RAM.

  • Is the client assured to startup with Network connectivity?
    Or is there a possibility of an OOB startup with no network connectivity?

If the client might start from OOB without network connectivity, you'll have to store offline data to disk. You won't have the option of fetching fresh data from the server on startup.

  • When in offline mode, Can the user query previously retrieved data?

This is the one common thread between all smart clients. All Smart Client apps have access to offline data, but it's important to call this out as a feature IMO.

  • When in offline mode, can the user create new data?

So, if you've got an Purchasing app and there's no network connection, can the user create a new Order? If so, you'll have to cache this data locally and transmit it to the server on the first Client<->Sync cycle.

  • What is the scope of data that can be changed offline?

Can you limit the offline feature just to the creation of critical data? Or do you need to allow for the full spectrum of Create & Update & Delete for all your data offline?

My suggestion is to limit the offline changes since you'll run into very complicated scenarios to solve if you haven't. For instance, at 12AM User A deletes Customer#1, at 12:05 User B issues a new Order for Customer#2. Both users were offline. Now go figure out what's the correct business solution there :)

  • When in offline mode, what happens when the user queries for data that wasn't previously retrieved?

Let's assume your shared data (a customers table for instance) is massive. You've got 10M customers. You can't store that sensitive data on all clients. So what happens when an offline app needs excess to a Customer it doesn't have? Are you OK with saying to the end-user "Get on the damn network, will you?".

  • How Mission critical is your app?

The intersting part in that question is - If something goes bad, are you OK with shutting down that user? This question determines if you need to persist to disk on every Data Action (New data, retrieved data, form change field, etc) or if you're OK with persisting to disk only when the app is closed.

When looking at Silverlight, you've got a few good technical options.

  1. Keep data in memory.
    If your featureset survives it, Keep the RIA Services Domain Context as a static instance.
    when the client loses network connectivity, you still get to work off the RAM.

  2. As was mentioned before, IsoStore is your friend.
    You get 1MB (in-browser) / 25MB (out of browser) of your own magically private disk space and if your app needs it - you can ask for more.
    Serialize data down to disk.

  3. OODB - Object Oriented Database.
    OODBs running on the Silverlight IsoStore are a wonderfully easy way of persisting data.
    Just go to your RIA Services Domain Conext, and go "myEntity.Save()".
    There are 3 OODBs running on Silverlight IsoStore I know of: db40, mcObjects and SilverlightDB.

Based on NikhilK's blog post a few months back, RIA Services is planning on supporting "offlianability". But the scope and timeline aren't specified.

Cheers,
-- Justin

JustinAngel