View
1.576
Download
1
Category
Preview:
DESCRIPTION
When developing applications for mobile devices (Windows Store or Windows Phone) we have to deal with connected data scenarios using cloud web services, and disconnected scenarios where data is stored locally. In this session we will explore all options to store information locally and remotely (files, Isolated Storage, IndexedDB, SQLite, NoSQL DBs and Azure Mobile Services), and how to build a system for synchronizing data when using a combination of these systems.
Citation preview
Working with disconnected data in Windows Store apps Alex Casquete
Thanks Event Sponsors.
Agenda
Disconnected scenarios SQLite IndexedDB Windows Azure Mobile Services CouchDB Synchronize
SQLite with Mobile Services IndexedDB with CouchDB
About me
Alex CasqueteMCT since 2010 Mobile Solutions Developeralex@casquete.es acasquete
Disconnected Scenarios
Disconnected Scenarios
In a connected World sometimes you are disconnected. Network bandwidth is more restricted. Less storage and processing capacity. You are not alone. Conflict resolution is necessary.
The applications require a local storage
Local Storage
SQLiteApp Data StoreFile System IndexedDB
C# / JavaScript Javascript
Open source RDBMS. Works as library instead of service Single file database. Cross Platform database. Implements most of the SQL standard.
What is SQLite?
DEMO: SQLite
Windows Azure Mobile Services
Data
Notifications
Auth
Server Logic Logging & Diag
ScaleScheduler
Key ScenariosWindows Azure Mobile Services are ideal for:
Modern mobile appsWindows Store Apps, Windows Phone, iOS, Android
Common ScenariosReduces the friction associated with repeating common tasks such as user authentication, push notifications and structured storage
Rapid DevelopmentTime is money. Get your app up and running sooner when you use Mobile Services to configure a straightforward and secure backend in less than five minutes.
DEMO: WAMS & Synchronization
Write changes to the same item, at the same time. Without any conflict detection, the last write would
overwrite any previous updates. Optimistic Concurrency Control assumes that each
transaction can commit. And verifies that no other transaction has modified the
data. WAMS detects write conflicts with __version property.
Conflict detection
DEMO: Conflict Resolution
And JavaScript?
Local Storage
SQLiteApp Data StoreFile System IndexedDB
C# / JavaScript Javascript
Supported by many browsers and also by Windows Store apps.
Each record is identified by a unique index or key. Store large amounts of structured data. API doesn’t give a way to synchronize the data.
What is IndexedDB?
Using IndexedDB
// Opening a Databasevar dbRequest = window.indexedDB.open("ContactsDB", version);
// Assume db is a database variable opened earliervar transaction = db.transaction(["people"],"readwrite");var store = transaction.objectStore("people");
// Define a personvar person = { name:name, email:email, created:new Date() }
// Perform the addvar request = store.add(person,1);
PouchDB is a implementation of Apache CouchDB Works in Firefox, Chrome, Opera, Safari, IE and Node.js and
Windows Store apps Same Data model Same API Same conflicts resolution Synchronizes with a CouchDB Database!
PouchDB
DEMO: PouchDB
Using PouchDB
// Opening a Databasevar db = new PouchDB('dbname');// Add an objectdb.put({ _id: ’me@email.com', name: ’Alex', age: 66 });// Subscripbe to changesdb.changes({ onChange: function() { console.log('Ch-Ch-Changes'); }});// Replicate to external DBdb.replicate.to('http://example.com/mydb');
Remember
Complete the user experience in your apps using offline capabilities
Use DB engines instead of implementing a new mechanism to store data
Synchronization is not simple!
Resources
Handling Database Write Conflicts with WAMS http://www.windowsazure.com/en-us/develop/mobile/tutorials/handle-database-wri
te-conflicts-dotnet/ SQL Data Sync (Preview)
http://msdn.microsoft.com/en-us/library/windowsazure/hh456371.aspx SQLite Documentation
http://www.sqlite.org/docs.html PouchDB
http://pouchdb.com
Thanks Event Sponsors.
Thanks!
Recommended