,

Deployment of Local Databases

Understanding how local databases can be deployed to the phone is important when determining the best approach for your app. This section looks behind the scenes at what happens when an app is installed on the phone, and at the two locations for local database deployment.

It so happens that a XAP file, which is produced when you build your project, is also a Zip file. When an app is installed on the phone, the package manager extracts the app’s XAP file into an install directory (see Figure 29.1).

Image

FIGURE 29.1 Install and Application Data directories.

For more information on XAP files, see the section “Understanding the Role of XAP Files” in Chapter 2, “Fundamental Concepts in Windows Phone Development.”

The install directory is read-only. An app is not able to add or remove items from its install directory, nor is it able to make any changes to any items in the directory.

During installation, the app is also assigned a data directory. The contents of this directory and all subdirectories are readable and writable by the app.


Note

An app’s root directory and all contents therein are off-limits to any other app.


A local database can be placed either in isolated storage or in the app’s install directory by including it within the XAP. You see why the choice of where to place a local database is important in a moment.

An app’s data directory is persistent, whereas its install directory is not. When publishing an update for your app on the Windows Phone Marketplace, the install directory of your app is replaced, but the data directory for your app remains intact.

Moreover, when placed in the install directory, a database is read-only. This suits certain scenarios, such as when you want to include structured reference data with your app, data that may change with each application update but that is not modifiable by the app itself. An example of this kind of data is a dictionary of word definitions.

The most common place for a database, however, is in isolated storage. When in isolated storage the database is readable and writable and is retained during an app update.

There are two common scenarios for deploying a database to isolated storage. The first is where your app has a complex domain model and you want to persist its state. Perhaps your app is a shopping cart or a to-do list. The second scenario is where you fetch a subset of reference data from the cloud, cache it locally, and combine it with user-specific data.

This chapter demonstrates each deployment option and focuses on using a local database as a cache by creating a Twitter app that downloads timeline information and caches it in a database so that it is available when the phone is offline.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.64.89