working with disconnected data in windows store apps

26
Working with disconnected data in Windows Store apps Alex Casquete

Upload: alex-casquete

Post on 01-Nov-2014

1.577 views

Category:

Technology


1 download

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.

TRANSCRIPT

Page 1: Working with disconnected data in Windows Store apps

Working with disconnected data in Windows Store apps Alex Casquete

Page 2: Working with disconnected data in Windows Store apps

Thanks Event Sponsors.

Page 3: Working with disconnected data in Windows Store apps

Agenda

Disconnected scenarios SQLite IndexedDB Windows Azure Mobile Services CouchDB Synchronize

SQLite with Mobile Services IndexedDB with CouchDB

Page 4: Working with disconnected data in Windows Store apps

About me

Alex CasqueteMCT since 2010 Mobile Solutions [email protected] acasquete

Page 5: Working with disconnected data in Windows Store apps
Page 6: Working with disconnected data in Windows Store apps

Disconnected Scenarios

Page 7: Working with disconnected data in Windows Store apps

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

Page 8: Working with disconnected data in Windows Store apps

Local Storage

SQLiteApp Data StoreFile System IndexedDB

C# / JavaScript Javascript

Page 9: Working with disconnected data in Windows Store apps

Open source RDBMS. Works as library instead of service Single file database. Cross Platform database. Implements most of the SQL standard.

What is SQLite?

Page 10: Working with disconnected data in Windows Store apps

DEMO: SQLite

Page 11: Working with disconnected data in Windows Store apps

Windows Azure Mobile Services

Data

Notifications

Auth

Server Logic Logging & Diag

ScaleScheduler

Page 12: Working with disconnected data in Windows Store apps

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.

Page 13: Working with disconnected data in Windows Store apps

DEMO: WAMS & Synchronization

Page 14: Working with disconnected data in Windows Store apps

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

Page 15: Working with disconnected data in Windows Store apps

DEMO: Conflict Resolution

Page 16: Working with disconnected data in Windows Store apps

And JavaScript?

Page 17: Working with disconnected data in Windows Store apps

Local Storage

SQLiteApp Data StoreFile System IndexedDB

C# / JavaScript Javascript

Page 18: Working with disconnected data in Windows Store apps

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?

Page 19: Working with disconnected data in Windows Store apps

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);

Page 20: Working with disconnected data in Windows Store apps

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

Page 21: Working with disconnected data in Windows Store apps

DEMO: PouchDB

Page 22: Working with disconnected data in Windows Store apps

Using PouchDB

// Opening a Databasevar db = new PouchDB('dbname');// Add an objectdb.put({ _id: ’[email protected]', 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');

Page 23: Working with disconnected data in Windows Store apps

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!

Page 24: Working with disconnected data in Windows Store apps

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

Page 25: Working with disconnected data in Windows Store apps

Thanks Event Sponsors.

Page 26: Working with disconnected data in Windows Store apps

Thanks!