SlideShare a Scribd company logo
1 of 62
Windows XAML
29 April 2014
Building Apps for Windows Phone 8.1 Jump Start
2
3
Installation
Folder
App data
FoldersApp data
FoldersApp data
Folders
Credential
Locker
Local or
Roaming
Settings File
App Creates/Manages
files and settings
Application
Files
App Data
Folder
Package
Manager
Installation Folder
WinRT Storage
APIs
Install
DB
Database file
DB Files (r/o)
Roaming
Folder Settings
• Other devices can
access what you put in
here
• Data roamed cross-
device
• Limited to 100kb per
application
• Held in OneDrive
storage
Local
Folder Settings
• Store local data here
for use by your
application
• Can store data up to
the limit of the storage
on the device
• Retained if the
application is updated
Temp
Folder
• Use for temporary
storage
• No guarantee it
will still be here
next time your
program runs
• Cleaned up in a
low storage
condition
PasswordVault
Credentials
• Credential Locker
• Use for secure
storage of
PasswordCredential
objects
• Data roamed cross-
device
7
Windows.Storage.StorageFolder roam = Windows.Storage.ApplicationData.Current.RoamingFolder;
Windows.Storage.StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
Windows.Storage.StorageFolder temp = Windows.Storage.ApplicationData.Current.TemporaryFolder;
Windows.Storage.ApplicationDataContainer localSettings =
Windows.Storage.ApplicationData.Current.LocalSettings;
Windows.Storage.ApplicationDataContainer roamingSettings =
Windows.Storage.ApplicationData.Current.RoamingSettings;
The StorageFolder object represents a folder and is used to access the
folder and its contents
The ApplicationDataContainer object represents a key-value pair
settings dictionary
8
9
// Create a simple setting
localSettings.Values["exampleSetting"] = "Hello Windows";
// Read data from a simple setting
Object value = localSettings.Values["exampleSetting"];
if (value == null)
{
// No data
}
else
{
// Access data in value
}
// Delete a simple setting
localSettings.Values.Remove("exampleSetting");
10
11
WP 8.1 App – PFN 12345
Roaming Local Temp
Windows App – PFN 12345
RoamingLocalTemp
PFN 12345
Roaming
folder
App writes data using standard
file/settings APIs.
Sync engine transfers data
periodically based on
triggers (user idle, battery,
network, etc.)
OneDrive stores up to 100kb of roaming
data per app (not included in user quota).
If app exceeds the limit, sync stops.
Other clients are notified of
updated data via Windows
Notification Service. If app is
running when sync occurs, an
event is raised.Roaming
settings
12
private void name_TextChanged(object sender, TextChangedEventArgs e)
{
Windows.Storage.ApplicationDataContainer roamingSettings =
Windows.Storage.ApplicationData.Current.RoamingSettings;
roamingSettings.Values["userName"] = name.Text;
}
13
Windows.Storage.ApplicationDataContainer roamingSettings =
Windows.Storage.ApplicationData.Current.RoamingSettings;
if (roamingSettings.Values.ContainsKey("userName"))
{
name.Text = roamingSettings.Values["userName"].ToString();
}
14
Windows.Storage.ApplicationData.Current.DataChanged += Current_DataChanged;
...
void Current_DataChanged(ApplicationData sender, object args)
{
// Refresh your settings...
}
The event is only fired if the application is active at the time
of the change
You should still load up all your data when your app starts
15
16
17
18
File Type/ API
Installation
Folder
App data folder Example
File access using
Windows.Storage
API via URIs
ms-appx:///
ms-appdata:///local/
ms-appdata:///roaming/
ms-appdata:///temp/
var file = await
Windows.StorageFile.GetFileFromApplicationUriAsync(
new Uri("ms-appdata:///local/AppConfigSettings.xml"));
File access using
Windows.Storage
API via
StorageFolder
references
Windows.
ApplicationModel.
Package.Current.
InstalledLocation
Windows.Storage.
ApplicationData.
Current
.LocalFolder /
.RoamingFolder /
.TempFolder
var localFolder =
Windows.Storage.ApplicationData.Current.LocalFolder;
Windows.Storage.StorageFile storageFile =
await localFolder.GetFileAsync("CaptainsLog.store");
20
private async void writeTextToLocalStorageFile(string filename, string text)
{
StorageFolder fold = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile file =
await fold.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
await FileIO.WriteTextAsync(file, text);
}
21
private async Task<string> readTextFromLocalStorage(string filename)
{
var fold = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile file = await fold.GetFileAsync(filename);
string result = await FileIO.ReadTextAsync(file);
return result;
}
23
24
private async void WriteToStreamButton_Click(object sender, RoutedEventArgs e)
{
StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile file = await localFolder.CreateFileAsync("JumpStart.txt");
string userContent = InputTextBox.Text;
if (!String.IsNullOrEmpty(userContent))
{
using (StorageStreamTransaction transaction = await file.OpenTransactedWriteAsync())
{
using (DataWriter dataWriter = new DataWriter(transaction.Stream))
{
dataWriter.WriteString(userContent);
transaction.Stream.Size = await dataWriter.StoreAsync(); // reset stream size to override the file
await transaction.CommitAsync();
}
}
}
}
26
27
28
29
using (Stream stream = await notesFolder.OpenStreamForWriteAsync(filename,
CreationCollisionOption.OpenIfExists))
{
DataContractJsonSerializer serializer =
new DataContractJsonSerializer(typeof(Customer[]));
serializer.WriteObject(stream, customers);
}
This code serializes a collection of customers
30
using (Stream stream = await notesFolder.OpenStreamForWriteAsync(filename,
CreationCollisionOption.OpenIfExists))
{
DataContractJsonSerializer serializer =
new DataContractJsonSerializer(typeof(Customers));
serializer.WriteObject(stream, customers);
}
This creates the serializer
The constructor is given the type of the object to store
31
using (Stream stream = await notesFolder.OpenStreamForWriteAsync(filename,
CreationCollisionOption.OpenIfExists))
{
DataContractJsonSerializer serializer =
new DataContractJsonSerializer(typeof(Customers));
serializer.WriteObject(stream, customers);
}
This writes the collection of customers to the output stream
32
using (Stream stream = await notesFolder.OpenStreamForReadAsync(filename))
{
DataContractJsonSerializer serializer =
new DataContractJsonSerializer(typeof(Customers));
Customers result = serializer.ReadObject(stream) as Customers;
}
The read process is the reverse of the writing one
Note that we have to cast the result of ReadObject(Stream)
to the required type
33
XmlSerializer serializer = new XmlSerializer(typeof(Customers));
serializer.Serialize(stream, customers);
XmlSerializer serializer = new XmlSerializer(typeof(Customers));
Customers result = serializer.Deserialize(stream) as Customers;
34
35
var s = await destFile.OpenAsync(FileAccessMode.ReadWrite);
Compressor compressor =
new Compressor(s.GetOutputStreamAt(0), CompressAlgorithm.Mszip, 0);
An application can use compression when it saves and loads
data
The compression stream can be used as any other stream,
but it compresses the data as it is transferred
36
var s = await destFile.OpenAsync(FileAccessMode.ReadWrite);
Compressor compressor =
new Compressor(s.GetOutputStreamAt(0), CompressAlgorithm.Mszip, 0);
There are a number of different algorithms available:
Lzms
Mszip
Xpress
XpressHuff
You can also set the block size for the compression, the
value 0 means use the default
37
var s = await destFile.OpenAsync(FileAccessMode.ReadWrite);
Compressor compressor =
new Compressor(s.GetOutputStreamAt(0), CompressAlgorithm.Mszip, 0);
The Decompressor complements the Compressor and
provides an input stream that can be used to decompress
files
App A
App B
MSA
void SaveCredential(string username, string password)
{
PasswordVault vault = new PasswordVault();
PasswordCredential cred = new PasswordCredential("MyAppResource", username, password);
vault.Add(cred);
}
IReadOnlyList<PasswordCredential> RetrieveCredential(string resource)
{
PasswordVault vault = new PasswordVault();
return vault.FindAllByResource(resource);
}
43
44
45
KnownFolders provides access to:
47
var pictures = await
Windows.Storage.KnownFolders.PicturesLibrary.GetFilesAsync();
49
50
51
Note that this is not required for applications accessing files in their own
local/roaming/temporary storage
This is the same mechanism used for app-to-app communications through file associations
(See Session 10)
52
53
54
var devices = Windows.Storage.KnownFolders.RemovableDevices;
var sdCards = await devices.GetFoldersAsync();
if (sdCards.Count == 0) return;
StorageFolder firstCard = sdCards[0];
These statements get a reference to the SD card on the
phone
They are part of a method that creates a file on the SD card
55
var devices = Windows.Storage.KnownFolders.RemovableDevices;
var sdCards = await devices.GetFoldersAsync();
if (sdCards.Count == 0) return;
StorageFolder firstCard = sdCards[0];
We get a list of SD cards using the KnownFolders API
There will only be 0 or 1
56
var devices = Windows.Storage.KnownFolders.RemovableDevices;
var sdCards = await devices.GetFoldersAsync();
if (sdCards.Count == 0) return;
StorageFolder firstCard = sdCards[0];
If there is not one present the value of the Count property
will be 0
This method returns if there are no SD Cards on the device
Your application must handle this eventuality gracefully
Not all devices have an SD card slot
The slot might not have a card fitted into it
57
var devices = Windows.Storage.KnownFolders.RemovableDevices;
var sdCards = await devices.GetFoldersAsync();
if (sdCards.Count == 0) return;
StorageFolder firstCard = sdCards[0];
The card is exposed as a StorageFolder, so we can use it in
the same way the previous devices we have seen
We can create folders and files
But we can only work with files types for which we have
declared a file association in the manifest
58
59
60
©2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the
U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft
must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after
the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related Content

What's hot

Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net ArchitectureUmar Farooq
 
DIY Percolator
DIY PercolatorDIY Percolator
DIY Percolatorjdhok
 
Oracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseOracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseMarco Gralike
 
Yogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh Kushwah
 
Zend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingZend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingTricode (part of Dept)
 
In Defense Of Core Data
In Defense Of Core DataIn Defense Of Core Data
In Defense Of Core DataDonny Wals
 
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...SPTechCon
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2Neeraj Mathur
 
Dont call me cache april 17
Dont call me cache april 17Dont call me cache april 17
Dont call me cache april 17Nati Shalom
 
ADO.Net Improvements in .Net 2.0
ADO.Net Improvements in .Net 2.0ADO.Net Improvements in .Net 2.0
ADO.Net Improvements in .Net 2.0David Truxall
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programmingchhaichivon
 

What's hot (18)

Introduction to ASP.Net Viewstate
Introduction to ASP.Net ViewstateIntroduction to ASP.Net Viewstate
Introduction to ASP.Net Viewstate
 
Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net Architecture
 
DIY Percolator
DIY PercolatorDIY Percolator
DIY Percolator
 
Oracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseOracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory Database
 
JAXP
JAXPJAXP
JAXP
 
Yogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’s
 
Zend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingZend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching logging
 
Ch05 state management
Ch05 state managementCh05 state management
Ch05 state management
 
B13 Investigating oracle by Julian Dyke
B13 Investigating oracle by Julian DykeB13 Investigating oracle by Julian Dyke
B13 Investigating oracle by Julian Dyke
 
In Defense Of Core Data
In Defense Of Core DataIn Defense Of Core Data
In Defense Of Core Data
 
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
 
Using Dojo
Using DojoUsing Dojo
Using Dojo
 
Java script
Java scriptJava script
Java script
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2
 
Dont call me cache april 17
Dont call me cache april 17Dont call me cache april 17
Dont call me cache april 17
 
ADO.Net Improvements in .Net 2.0
ADO.Net Improvements in .Net 2.0ADO.Net Improvements in .Net 2.0
ADO.Net Improvements in .Net 2.0
 
JSON
JSONJSON
JSON
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
 

Similar to 09 data storage, backup and roaming

Cloudbase.io MoSync Reload Course
Cloudbase.io MoSync Reload CourseCloudbase.io MoSync Reload Course
Cloudbase.io MoSync Reload Coursecloudbase.io
 
Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...
Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...
Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...Codemotion
 
Pandora FMS: Windows Phone 7 Agent
Pandora FMS: Windows Phone 7 AgentPandora FMS: Windows Phone 7 Agent
Pandora FMS: Windows Phone 7 AgentPandora FMS
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debuggingUtkarsh Mankad
 
Spring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenSpring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenJoshua Long
 
Synapseindia android apps introduction hello world
Synapseindia android apps introduction hello worldSynapseindia android apps introduction hello world
Synapseindia android apps introduction hello worldTarunsingh198
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...SPTechCon
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWAREFIWARE
 
Sparkling Water
Sparkling WaterSparkling Water
Sparkling Waterh2oworld
 
Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLaurence Svekis ✔
 
WP7 HUB_Consuming Data Services
WP7 HUB_Consuming Data ServicesWP7 HUB_Consuming Data Services
WP7 HUB_Consuming Data ServicesMICTT Palma
 
Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WAREFermin Galan
 
Taking care of a cloud environment
Taking care of a cloud environmentTaking care of a cloud environment
Taking care of a cloud environmentMaarten Balliauw
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppSyed Shahul
 

Similar to 09 data storage, backup and roaming (20)

Android Froyo
Android FroyoAndroid Froyo
Android Froyo
 
Cloudbase.io MoSync Reload Course
Cloudbase.io MoSync Reload CourseCloudbase.io MoSync Reload Course
Cloudbase.io MoSync Reload Course
 
Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...
Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...
Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...
 
70562 (1)
70562 (1)70562 (1)
70562 (1)
 
Pandora FMS: Windows Phone 7 Agent
Pandora FMS: Windows Phone 7 AgentPandora FMS: Windows Phone 7 Agent
Pandora FMS: Windows Phone 7 Agent
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
 
Spring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenSpring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in Heaven
 
Synapseindia android apps introduction hello world
Synapseindia android apps introduction hello worldSynapseindia android apps introduction hello world
Synapseindia android apps introduction hello world
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
Sparkling Water
Sparkling WaterSparkling Water
Sparkling Water
 
Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginners
 
WP7 HUB_Consuming Data Services
WP7 HUB_Consuming Data ServicesWP7 HUB_Consuming Data Services
WP7 HUB_Consuming Data Services
 
TO Hack an ASP .NET website?
TO Hack an ASP .NET website?  TO Hack an ASP .NET website?
TO Hack an ASP .NET website?
 
Android For All The Things
Android For All The ThingsAndroid For All The Things
Android For All The Things
 
Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
 
Hack ASP.NET website
Hack ASP.NET websiteHack ASP.NET website
Hack ASP.NET website
 
Taking care of a cloud environment
Taking care of a cloud environmentTaking care of a cloud environment
Taking care of a cloud environment
 
Android session-5-sajib
Android session-5-sajibAndroid session-5-sajib
Android session-5-sajib
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts App
 

More from WindowsPhoneRocks

23 silverlight apps on windows phone 8.1
23   silverlight apps on windows phone 8.123   silverlight apps on windows phone 8.1
23 silverlight apps on windows phone 8.1WindowsPhoneRocks
 
22 universal apps for windows
22   universal apps for windows22   universal apps for windows
22 universal apps for windowsWindowsPhoneRocks
 
21 app packaging, monetization and publication
21   app packaging, monetization and publication21   app packaging, monetization and publication
21 app packaging, monetization and publicationWindowsPhoneRocks
 
19 programming sq lite on windows phone 8.1
19   programming sq lite on windows phone 8.119   programming sq lite on windows phone 8.1
19 programming sq lite on windows phone 8.1WindowsPhoneRocks
 
17 camera, media, and audio in windows phone 8.1
17   camera, media, and audio in windows phone 8.117   camera, media, and audio in windows phone 8.1
17 camera, media, and audio in windows phone 8.1WindowsPhoneRocks
 
16 interacting with user data contacts and appointments
16   interacting with user data contacts and appointments16   interacting with user data contacts and appointments
16 interacting with user data contacts and appointmentsWindowsPhoneRocks
 
15 sensors and proximity nfc and bluetooth
15   sensors and proximity nfc and bluetooth15   sensors and proximity nfc and bluetooth
15 sensors and proximity nfc and bluetoothWindowsPhoneRocks
 
14 tiles, notifications, and action center
14   tiles, notifications, and action center14   tiles, notifications, and action center
14 tiles, notifications, and action centerWindowsPhoneRocks
 
13 networking, mobile services, and authentication
13   networking, mobile services, and authentication13   networking, mobile services, and authentication
13 networking, mobile services, and authenticationWindowsPhoneRocks
 
12 maps, geolocation, and geofencing
12   maps, geolocation, and geofencing12   maps, geolocation, and geofencing
12 maps, geolocation, and geofencingWindowsPhoneRocks
 
11 background tasks and multitasking
11   background tasks and multitasking11   background tasks and multitasking
11 background tasks and multitaskingWindowsPhoneRocks
 
08 localization and globalization in windows runtime apps
08   localization and globalization in windows runtime apps08   localization and globalization in windows runtime apps
08 localization and globalization in windows runtime appsWindowsPhoneRocks
 
07 windows runtime app lifecycle
07   windows runtime app lifecycle07   windows runtime app lifecycle
07 windows runtime app lifecycleWindowsPhoneRocks
 
05 programming page controls and page transitions animations
05   programming page controls and page transitions animations05   programming page controls and page transitions animations
05 programming page controls and page transitions animationsWindowsPhoneRocks
 
04 lists and lists items in windows runtime apps
04   lists and lists items in windows runtime apps04   lists and lists items in windows runtime apps
04 lists and lists items in windows runtime appsWindowsPhoneRocks
 
03 page navigation and data binding in windows runtime apps
03   page navigation and data binding in windows runtime apps03   page navigation and data binding in windows runtime apps
03 page navigation and data binding in windows runtime appsWindowsPhoneRocks
 
02 getting started building windows runtime apps
02   getting started building windows runtime apps02   getting started building windows runtime apps
02 getting started building windows runtime appsWindowsPhoneRocks
 
01 introducing the windows phone 8.1
01   introducing the windows phone 8.101   introducing the windows phone 8.1
01 introducing the windows phone 8.1WindowsPhoneRocks
 

More from WindowsPhoneRocks (20)

3 554
3 5543 554
3 554
 
23 silverlight apps on windows phone 8.1
23   silverlight apps on windows phone 8.123   silverlight apps on windows phone 8.1
23 silverlight apps on windows phone 8.1
 
22 universal apps for windows
22   universal apps for windows22   universal apps for windows
22 universal apps for windows
 
21 app packaging, monetization and publication
21   app packaging, monetization and publication21   app packaging, monetization and publication
21 app packaging, monetization and publication
 
20 tooling and diagnostics
20   tooling and diagnostics20   tooling and diagnostics
20 tooling and diagnostics
 
19 programming sq lite on windows phone 8.1
19   programming sq lite on windows phone 8.119   programming sq lite on windows phone 8.1
19 programming sq lite on windows phone 8.1
 
17 camera, media, and audio in windows phone 8.1
17   camera, media, and audio in windows phone 8.117   camera, media, and audio in windows phone 8.1
17 camera, media, and audio in windows phone 8.1
 
16 interacting with user data contacts and appointments
16   interacting with user data contacts and appointments16   interacting with user data contacts and appointments
16 interacting with user data contacts and appointments
 
15 sensors and proximity nfc and bluetooth
15   sensors and proximity nfc and bluetooth15   sensors and proximity nfc and bluetooth
15 sensors and proximity nfc and bluetooth
 
14 tiles, notifications, and action center
14   tiles, notifications, and action center14   tiles, notifications, and action center
14 tiles, notifications, and action center
 
13 networking, mobile services, and authentication
13   networking, mobile services, and authentication13   networking, mobile services, and authentication
13 networking, mobile services, and authentication
 
12 maps, geolocation, and geofencing
12   maps, geolocation, and geofencing12   maps, geolocation, and geofencing
12 maps, geolocation, and geofencing
 
11 background tasks and multitasking
11   background tasks and multitasking11   background tasks and multitasking
11 background tasks and multitasking
 
08 localization and globalization in windows runtime apps
08   localization and globalization in windows runtime apps08   localization and globalization in windows runtime apps
08 localization and globalization in windows runtime apps
 
07 windows runtime app lifecycle
07   windows runtime app lifecycle07   windows runtime app lifecycle
07 windows runtime app lifecycle
 
05 programming page controls and page transitions animations
05   programming page controls and page transitions animations05   programming page controls and page transitions animations
05 programming page controls and page transitions animations
 
04 lists and lists items in windows runtime apps
04   lists and lists items in windows runtime apps04   lists and lists items in windows runtime apps
04 lists and lists items in windows runtime apps
 
03 page navigation and data binding in windows runtime apps
03   page navigation and data binding in windows runtime apps03   page navigation and data binding in windows runtime apps
03 page navigation and data binding in windows runtime apps
 
02 getting started building windows runtime apps
02   getting started building windows runtime apps02   getting started building windows runtime apps
02 getting started building windows runtime apps
 
01 introducing the windows phone 8.1
01   introducing the windows phone 8.101   introducing the windows phone 8.1
01 introducing the windows phone 8.1
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

09 data storage, backup and roaming

  • 1. Windows XAML 29 April 2014 Building Apps for Windows Phone 8.1 Jump Start
  • 2. 2
  • 3. 3
  • 5. Local or Roaming Settings File App Creates/Manages files and settings Application Files App Data Folder Package Manager Installation Folder WinRT Storage APIs Install DB Database file DB Files (r/o)
  • 6. Roaming Folder Settings • Other devices can access what you put in here • Data roamed cross- device • Limited to 100kb per application • Held in OneDrive storage Local Folder Settings • Store local data here for use by your application • Can store data up to the limit of the storage on the device • Retained if the application is updated Temp Folder • Use for temporary storage • No guarantee it will still be here next time your program runs • Cleaned up in a low storage condition PasswordVault Credentials • Credential Locker • Use for secure storage of PasswordCredential objects • Data roamed cross- device
  • 7. 7 Windows.Storage.StorageFolder roam = Windows.Storage.ApplicationData.Current.RoamingFolder; Windows.Storage.StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFolder temp = Windows.Storage.ApplicationData.Current.TemporaryFolder; Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; The StorageFolder object represents a folder and is used to access the folder and its contents The ApplicationDataContainer object represents a key-value pair settings dictionary
  • 8. 8
  • 9. 9 // Create a simple setting localSettings.Values["exampleSetting"] = "Hello Windows"; // Read data from a simple setting Object value = localSettings.Values["exampleSetting"]; if (value == null) { // No data } else { // Access data in value } // Delete a simple setting localSettings.Values.Remove("exampleSetting");
  • 10. 10
  • 11. 11 WP 8.1 App – PFN 12345 Roaming Local Temp Windows App – PFN 12345 RoamingLocalTemp PFN 12345 Roaming folder App writes data using standard file/settings APIs. Sync engine transfers data periodically based on triggers (user idle, battery, network, etc.) OneDrive stores up to 100kb of roaming data per app (not included in user quota). If app exceeds the limit, sync stops. Other clients are notified of updated data via Windows Notification Service. If app is running when sync occurs, an event is raised.Roaming settings
  • 12. 12 private void name_TextChanged(object sender, TextChangedEventArgs e) { Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; roamingSettings.Values["userName"] = name.Text; }
  • 13. 13 Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; if (roamingSettings.Values.ContainsKey("userName")) { name.Text = roamingSettings.Values["userName"].ToString(); }
  • 14. 14 Windows.Storage.ApplicationData.Current.DataChanged += Current_DataChanged; ... void Current_DataChanged(ApplicationData sender, object args) { // Refresh your settings... } The event is only fired if the application is active at the time of the change You should still load up all your data when your app starts
  • 15. 15
  • 16. 16
  • 17. 17
  • 18. 18
  • 19. File Type/ API Installation Folder App data folder Example File access using Windows.Storage API via URIs ms-appx:/// ms-appdata:///local/ ms-appdata:///roaming/ ms-appdata:///temp/ var file = await Windows.StorageFile.GetFileFromApplicationUriAsync( new Uri("ms-appdata:///local/AppConfigSettings.xml")); File access using Windows.Storage API via StorageFolder references Windows. ApplicationModel. Package.Current. InstalledLocation Windows.Storage. ApplicationData. Current .LocalFolder / .RoamingFolder / .TempFolder var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile storageFile = await localFolder.GetFileAsync("CaptainsLog.store");
  • 20. 20 private async void writeTextToLocalStorageFile(string filename, string text) { StorageFolder fold = Windows.Storage.ApplicationData.Current.LocalFolder; StorageFile file = await fold.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, text); }
  • 21. 21 private async Task<string> readTextFromLocalStorage(string filename) { var fold = Windows.Storage.ApplicationData.Current.LocalFolder; StorageFile file = await fold.GetFileAsync(filename); string result = await FileIO.ReadTextAsync(file); return result; }
  • 22.
  • 23. 23
  • 24. 24 private async void WriteToStreamButton_Click(object sender, RoutedEventArgs e) { StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; StorageFile file = await localFolder.CreateFileAsync("JumpStart.txt"); string userContent = InputTextBox.Text; if (!String.IsNullOrEmpty(userContent)) { using (StorageStreamTransaction transaction = await file.OpenTransactedWriteAsync()) { using (DataWriter dataWriter = new DataWriter(transaction.Stream)) { dataWriter.WriteString(userContent); transaction.Stream.Size = await dataWriter.StoreAsync(); // reset stream size to override the file await transaction.CommitAsync(); } } } }
  • 25.
  • 26. 26
  • 27. 27
  • 28. 28
  • 29. 29 using (Stream stream = await notesFolder.OpenStreamForWriteAsync(filename, CreationCollisionOption.OpenIfExists)) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Customer[])); serializer.WriteObject(stream, customers); } This code serializes a collection of customers
  • 30. 30 using (Stream stream = await notesFolder.OpenStreamForWriteAsync(filename, CreationCollisionOption.OpenIfExists)) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Customers)); serializer.WriteObject(stream, customers); } This creates the serializer The constructor is given the type of the object to store
  • 31. 31 using (Stream stream = await notesFolder.OpenStreamForWriteAsync(filename, CreationCollisionOption.OpenIfExists)) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Customers)); serializer.WriteObject(stream, customers); } This writes the collection of customers to the output stream
  • 32. 32 using (Stream stream = await notesFolder.OpenStreamForReadAsync(filename)) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Customers)); Customers result = serializer.ReadObject(stream) as Customers; } The read process is the reverse of the writing one Note that we have to cast the result of ReadObject(Stream) to the required type
  • 33. 33 XmlSerializer serializer = new XmlSerializer(typeof(Customers)); serializer.Serialize(stream, customers); XmlSerializer serializer = new XmlSerializer(typeof(Customers)); Customers result = serializer.Deserialize(stream) as Customers;
  • 34. 34
  • 35. 35 var s = await destFile.OpenAsync(FileAccessMode.ReadWrite); Compressor compressor = new Compressor(s.GetOutputStreamAt(0), CompressAlgorithm.Mszip, 0); An application can use compression when it saves and loads data The compression stream can be used as any other stream, but it compresses the data as it is transferred
  • 36. 36 var s = await destFile.OpenAsync(FileAccessMode.ReadWrite); Compressor compressor = new Compressor(s.GetOutputStreamAt(0), CompressAlgorithm.Mszip, 0); There are a number of different algorithms available: Lzms Mszip Xpress XpressHuff You can also set the block size for the compression, the value 0 means use the default
  • 37. 37 var s = await destFile.OpenAsync(FileAccessMode.ReadWrite); Compressor compressor = new Compressor(s.GetOutputStreamAt(0), CompressAlgorithm.Mszip, 0); The Decompressor complements the Compressor and provides an input stream that can be used to decompress files
  • 38.
  • 39.
  • 41. MSA
  • 42. void SaveCredential(string username, string password) { PasswordVault vault = new PasswordVault(); PasswordCredential cred = new PasswordCredential("MyAppResource", username, password); vault.Add(cred); } IReadOnlyList<PasswordCredential> RetrieveCredential(string resource) { PasswordVault vault = new PasswordVault(); return vault.FindAllByResource(resource); }
  • 43. 43
  • 44. 44
  • 45. 45
  • 46.
  • 47. KnownFolders provides access to: 47 var pictures = await Windows.Storage.KnownFolders.PicturesLibrary.GetFilesAsync();
  • 48.
  • 49. 49
  • 50. 50
  • 51. 51
  • 52. Note that this is not required for applications accessing files in their own local/roaming/temporary storage This is the same mechanism used for app-to-app communications through file associations (See Session 10) 52
  • 53. 53
  • 54. 54 var devices = Windows.Storage.KnownFolders.RemovableDevices; var sdCards = await devices.GetFoldersAsync(); if (sdCards.Count == 0) return; StorageFolder firstCard = sdCards[0]; These statements get a reference to the SD card on the phone They are part of a method that creates a file on the SD card
  • 55. 55 var devices = Windows.Storage.KnownFolders.RemovableDevices; var sdCards = await devices.GetFoldersAsync(); if (sdCards.Count == 0) return; StorageFolder firstCard = sdCards[0]; We get a list of SD cards using the KnownFolders API There will only be 0 or 1
  • 56. 56 var devices = Windows.Storage.KnownFolders.RemovableDevices; var sdCards = await devices.GetFoldersAsync(); if (sdCards.Count == 0) return; StorageFolder firstCard = sdCards[0]; If there is not one present the value of the Count property will be 0 This method returns if there are no SD Cards on the device Your application must handle this eventuality gracefully Not all devices have an SD card slot The slot might not have a card fitted into it
  • 57. 57 var devices = Windows.Storage.KnownFolders.RemovableDevices; var sdCards = await devices.GetFoldersAsync(); if (sdCards.Count == 0) return; StorageFolder firstCard = sdCards[0]; The card is exposed as a StorageFolder, so we can use it in the same way the previous devices we have seen We can create folders and files But we can only work with files types for which we have declared a file association in the manifest
  • 58. 58
  • 59. 59
  • 60. 60
  • 61.
  • 62. ©2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.