mobile services on windows azure (part2)

18
Mobile Services Data Storage Radu Vunvulea [email protected] http://vunvulearadu.blogspot.com

Upload: radu-vunvulea

Post on 25-May-2015

579 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mobile services on windows azure (part2)

Mobile ServicesData Storage

Radu [email protected]

http://vunvulearadu.blogspot.com

Page 2: Mobile services on windows azure (part2)

{“name” : “Radu Vunvulea,“company” : “iQuest”,“userType” : “enthusiastic”“technologies” : [ “.NET”, “JS”, “Azure”, “Web”, “Mobile”, “SL” ],“w8experience” : [ “2 LoB App”, “1 Travel App”],“blog” : “vunvulearadu.blogspot.com”,“email” : ”[email protected]”,“socialMedia” :

{“twitter” : “@RaduVunvulea”,

“fb” : “radu.vunvulea”}

}

Who am I?

Page 3: Mobile services on windows azure (part2)

• This is the topic for today meeting

Windows Azure Mobile Services

Page 4: Mobile services on windows azure (part2)

• Features• Pricing• Account setup• Account configuration for storing data• What kind of data can be added• Custom scripts• Authentication• Available API• Demo

Agenda

Page 5: Mobile services on windows azure (part2)

• User authentication• Windows Live• Facebook• Google• Twitter

• Store data in the cloud• Windows Azure Storage

• Push notification infrastructure • All the service is build in in Windows Azure

Features of Mobile Services

Page 6: Mobile services on windows azure (part2)

• Free package in the 90 days trial:• Outbound traffic included 165MB• Maximum 10 mobile services

• Reserved instance model:• 3 dedicated servers (small instances, pay-as-you-go model)• 100 mobile services• Outbound data transfer will be paid

• Price available during preview can change in the final release

Pricing of Mobile Services

Page 7: Mobile services on windows azure (part2)

• Free package in the 90 days trial:• Outbound traffic included 165MB• Maximum 10 mobile services

• Reserved instance model:• 3 dedicated servers (small instances, pay-as-you-go model)• 100 mobile services• Outbound data transfer will be paid

• Price available during preview can change in the final release

Pricing of Mobile Services

Page 8: Mobile services on windows azure (part2)

• Create a new mobile service from the “New/Mobile Service/Create”

• A unique name of the mobile service need to be created• If we need a fresh database can be created or an existing

one can be used (if is in the same region)• After creating the database, we can use it as a normal database

• The service can be active for one of the following platform:• IOS• Windows Phone 8• Windows Store

• For each of the platform, after creating the mobile service, we can download the project that contains all the configurations

Setup your account

Page 9: Mobile services on windows azure (part2)

• From the management portal each service contains a tab named “Data”

• We can managed all the tables that we have • Create/Edit/Delete each table• See the content of each table

• For each table, we can set the rights of each user of the given table:• Anybody with the application key• Everyone• Only authenticate user• Only scripts and admin

• This rights can be different for CRUD operations

Configure environment to store data

Page 10: Mobile services on windows azure (part2)

• Any kind of serializable data• Each entity have to be decorated with DataContract and

DataMember attributes• It is recomanded to use the Name field of DataMember[DataContract]public class MyFoo{

public int Id { get;set;}

[DataMember(Name = "Name"]public string Name { get;set;}

}The “Id” field don’t need to be decorated with DataMember attribute

What kind of data can be added?

Page 11: Mobile services on windows azure (part2)

• Each CRUD operation can contain a custom script that is executed on the server side

• This scripts can be for validation purposes or to add/set custom fields

• Language: JavaScriptfunction insert(item, user, request) { if (item.name == "Tom") { request.respond(statusCodes.BAD_REQUEST, 'Tom name cannot be added'); } else { request.execute(); }}• When this kind of error appear, the client need to catch

“MobileServiceInvalidOperationException” exception

Custom scripts

Page 12: Mobile services on windows azure (part2)

• Each script can have helper functions• Base action that need to be done by a script

• execute – execute the given action• respond – send a response back to the client

• We cannot define global variable, each call is executed in a separate request

• Some of the base modules are from node.js• Example: we can make a request to another web-service to check datafunction insert(item, user, request) { var request = require('request'); request('http://myFoo.com/Services/validate', function(err, response, body) { ... }); }

Custom scripts

Page 13: Mobile services on windows azure (part2)

Catch the exception on the clienttry{ await myTable.InsertAsync(item); items.Add(item);}catch (MobileServiceInvalidOperationException e){

Trace.Write("Error: " + e.Reponse.Content);}

Custom scripts

Page 14: Mobile services on windows azure (part2)

• Define custom scripts that check if the given user id has rights to access his data

function insert(item, user, request) { item.userId = user.userId; request.execute();}function read(query, user, request) { query.where({ userId: user.userId }); request.execute();}• We need to store the user id. • Each user will have a unique user id• The user id is generated automatically by the system• We cannot store this scripts in our source control system

Control user access to data

Page 15: Mobile services on windows azure (part2)

• Define custom scripts that check if the given user id has rights to access his data

App.MobileService.GetTable<MyEntity>()• Before this we need to create a table with the same name• Update: table.UpdateAsync(entity)• Delete: table.DeleteAsync(entity)• Insert: table.InsertAsync(entity)• Fetch with data:

• Where• Take• Skip• OrderBy• Select• ThenBy• ToListAsync

How to work with data

Page 16: Mobile services on windows azure (part2)

Demo

Page 17: Mobile services on windows azure (part2)
Page 18: Mobile services on windows azure (part2)

THE END

Radu [email protected]

http://vunvulearadu.blogspot.com