Executive Summary

It is axiomatic that applications running on smart devices need to have robust capabilities for local data handling. This is the case because at least some of the time (and for some applications, all of the time), devices will be disconnected from any external network or data source. That is why local data handling is the first essential architectural concept addressed in this book.

As a result, it is imperative that any programming model for smart devices include three fundamental services, including programmatic access, or the ability to work with data via code; persistence, or the ability to save and retrieve data directly on the device; and UI support, or the ability to display, edit, and validate data in a straightforward fashion. Fortunately, for organizations looking to build solutions on the Compact Framework and SDP, there is plenty of functionality built into the product to support files, XML, and relational data, not to mention custom objects.

For example, to access files and folders on a device, developers can use the classes in the System.IO namespace that include stream readers and writers used to read and write plaintext and binary files, as well as classes to manipulate files and folders directly. These can be augmented with some simple calls to the Windows CE API in order to retrieve system file paths as well. The Compact Framework, although not supporting all the asynchronous capabilities of its desktop cousin, even supports asynchronous I/O through direct thread manipulation and an elegant technique for updating the UI after work has been completed.

To handle XML, the classes in the System.Xml namespace can be used in both a streamed fashion through a reader and writer, as well as through the familiar Document Object Model (DOM), although the cursor-based reader and writer are faster and consume less memory on the device.

Relational data can be manipulated locally (perhaps after being retrieved from a remote source) using the DataSet, DataTable, and associated objects in the System.Data namespace commonly referred to as ADO.NET. The methods of the data set particularly can be used to read and write data and track changes between application sessions on the device using an XML grammar referred to as a DiffGram.

Finally, UI support is included in the Compact Framework through both simple and complex data binding. Data from objects including the DataTable and DataView, as well as arrays and custom collection objects supporting the IList interface, can be bound to the DataGrid, ListBox, and ComboBox controls, as well as simpler controls, such as the TextBox. When the control does not support binding, a manual binding approach may also be used.

The end result is that the Compact Framework adroitly provides all the essential support for handling data locally on the device.