69

Windows 8 BootCamp

Embed Size (px)

DESCRIPTION

A presentation I gave for Microsoft Partners, 19th of September 2012

Citation preview

Page 1: Windows 8 BootCamp
Page 2: Windows 8 BootCamp

Developing on Windows 8

Power point template by Colin Eberhardt

Page 3: Windows 8 BootCamp

Agenda

WinRT Platform Basics

Best practices

Pickers

Contracts

Tiles

Notifications

Process Lifetime Management

Page 4: Windows 8 BootCamp

Who am I

Einar Ingebrigtsen

[email protected]@einari

http://blog.dolittle.comhttp://www.ingebrigtsen.info

Page 5: Windows 8 BootCamp

The target

One runtime to rule them all

Page 6: Windows 8 BootCamp

Old school interop

Your Managed Code

Traditional Windows API

Manually Generated Interop Code

Page 7: Windows 8 BootCamp

Windows RT style

Your Managed Code Windows 8 API

Windows Runtime

Page 8: Windows 8 BootCamp

Architecture

Metro style appLanguage Support

(CLR, WinJS, CRT)

Language Projection

Windows Metadata & Namespace

Web Host (HTML, CSS, JavaScript)

Windows Core

Runtime Broker Windows Runtime Core

UI Pickers Controls Media

XAML Storage Network …

Page 9: Windows 8 BootCamp

Projections

Primitives(strings,

numbers, etc) Interfaces Enums Structs Delegates Classes

Constructors Static Members Methods Properties Events

Page 10: Windows 8 BootCamp

Collections

IReadOnlyDictionary<K,V>IMapView<K,V>

IEnumerable<T>IIterable<T>

IList<T>IVector<T>

IReadOnlyList<T>IVectorView<T>

IDictionary<K,V>IMap<K,V>

Page 11: Windows 8 BootCamp

Bridging the gap

FileOpenPicker picker = new FileOpenPicker();picker.FileTypeFilter.Add("*")a;

StorageFile file = await picker.PickSingleFileAsync();

Windows.Storage.Streams.IInputStream inputStream = await file.OpenReadAsync();

System.IO.Stream stream = inputStream.AsStreamForRead();System.IO.StreamReader reader = new StreamReader(stream);

string contents = reader.ReadToEnd();

Page 12: Windows 8 BootCamp

APIs

FundamentalsApplication

Services Threading/Timers Memory Management Authentication Cryptography Globalization

Devices

Geolocation Portable Sensors NFC

User Interface

SVG Tiles Input Accessibility Printing

HTML5/CSS XAML DirectX Controls Data Binding

Communications & Data

Memory Management XML Networking SMS

Notifications Streams

Contracts Local & Cloud Storage Web

Media

Playback Capture PlayTo Visual Effects

Page 13: Windows 8 BootCamp

Missing things

Reflection API changedType details through GetTypeInfo() – extension methodEmit namespace practically empty - security

Page 14: Windows 8 BootCamp

XAML

Originally developed for Windows Vista and exposed as WPF

Defines what you see

Layout is by default not flowing, as in HTML

Can observe changes (Active View)

Page 15: Windows 8 BootCamp

Tools

Visual Studio 2012

Blend for VS2012

Page 16: Windows 8 BootCamp

Dependency Object

Contains property bag for DependencyProperties on object

Holds attached Dependency Properties

DataContext aware

Page 17: Windows 8 BootCamp

Dependency Properties

A bindable property that can hold binding expressions

Registered on a DependencyObject

Callback when data changes

Page 18: Windows 8 BootCamp

Attached Dependency Properties

Cross cutting properties

Extend other dependency objects with properties they don’t have

Page 19: Windows 8 BootCamp

DataContext

HierarchicalChildren uses parents datacontext unless explicitly changing it

Container

Button

Container

TextBlock

TextBlock

Set DataContext = “Hello World”

DataContext = “Hello World”

Set DataContext = “Something else”

DataContext = “Something else”

DataContext = “Hello World”

Page 20: Windows 8 BootCamp

Binding

SourceDefaults to DataContextCan use StaticResource as source

ModeOneWay, TwoWay, OneTime – OneWay default

ValidationValidatesOnExceptionValidatesOnNotifyDataErrors

INotifyDataErrorInfo

Page 21: Windows 8 BootCamp

Binding

StringFormatStringFormat = ‘MMM.dd.yyyy’

Null and Fallback valuesTargetNullValue=‘(None)’FallbackValue=‘(Data Context Not Set)’

IValueConverter

Page 22: Windows 8 BootCamp

Element to Element

Can bind directly to other elements properties

Binds by name of element

Page 23: Windows 8 BootCamp

Active View

INotifyPropertyChanging / INotifyPropertyChanged

INotifyCollectionChanged – ObservableCollection<>

Property / Collection Changes

UI subscriber updates UIRaise an event

Page 24: Windows 8 BootCamp

ValueConverter

Simple interface; IValueConverterConvertConvertBack

Converts values during databinding

Page 25: Windows 8 BootCamp

TypeConverter

Converts data from XAML to CLR types and back

XAML will always give string

Can be defined on a DependencyProperty or on an object with attributes pointing to the converter

Page 26: Windows 8 BootCamp

Events

You still have events as before – buttons can be clicked and raise an event

RoutedEvents – bubbles through the UI

Page 27: Windows 8 BootCamp

Async

var future = DownloadDataAsync(...); future.ContinueWith(data => ProcessData(data));

DownloadDataAsync

ProcessData

STOP

ProcessDataDownloadData

var data = DownloadData(...);ProcessData(data);

Page 28: Windows 8 BootCamp

Async Models

Windows Runtime : IAsyncOperation<T>

.NET Framework : Task<T>

C# 5.0 – async / await

Page 29: Windows 8 BootCamp

Async – C# style

Marked with “async” modifier

Must return void or Task<T>

Use “await” operator to cooperatively yield control – remember to mark with “async”

Feels just like good old synchronous code

Page 30: Windows 8 BootCamp

Patterns & Practices

MVVMInspired by PresentationModel by Martin FowlerGood for decoupling – promotes testability

Compositioning

Commands

Actions / Triggers / Behaviors

Page 31: Windows 8 BootCamp

MVVM

Model

ViewModel

View

Observes

Observable

Page 32: Windows 8 BootCamp

Compositional UIs

HeaderN

avig

ati

on

Main Content

Footer

Page 33: Windows 8 BootCamp

Event Aggregator

ViewModel 1 ViewModel 2

Aggregator

Page 34: Windows 8 BootCamp
Page 35: Windows 8 BootCamp

Tiles

Tap on tile to launch or switch to an app

Static default tile specified in app manifest

Two sizes:

Both sizes can have live updates

Page 36: Windows 8 BootCamp

Live Tiles

Tiles updates using pre-defined templates

Templates provide rich rendering options

Text-only image-only or combination

JPEG or PNG only, max size 150 KB

Optional “peek” animation

Local or cloud updates

Page 37: Windows 8 BootCamp

Notification Queuing

Opt-in to automatically cycle tile through last five notifications

By default only last notification shown

Page 38: Windows 8 BootCamp

Secondary Tiles

Tiles created by “pinning” content from app

Pin initiated by app via simple runtime call

User confirms pin operation via system UI

Exposes a personalized surface for app

Same capabilities as app tiles

Launch leads to relevant content

Page 39: Windows 8 BootCamp
Page 40: Windows 8 BootCamp

Process Lifetime Management

System manages application lifetime

One foreground full screen window

Apps are quickly suspended to preserve battery life

Page 41: Windows 8 BootCamp

Suspend

System resources focused on the app that the user is interacting with in the foreground

Inactive apps have no impact on battery life or responsiveness, they are suspended by the OS

Enables instant switching between apps

Page 42: Windows 8 BootCamp

Suspend details

Suspended apps are not scheduled by the NT Kernel

No CPU, Disk or Network consumed

All threads are suspended

Apps remain in memory

Kernel ensures apps are not suspended in critical sections that could cause system wide deadlocks

Apps instantly resumed from suspend when brought to foreground

Page 43: Windows 8 BootCamp

Session State

SuspensionManagerSessionState

Property bag that is automatically serialized and saved when suspendedReloads property bag from disk on activationDoes not reload state if app crashed

Only save and restore user session metadata

Tip: Don’t wait till suspension to put data into SessionState

Page 44: Windows 8 BootCamp

Session State : Best practices

User using app

Save incrementally

App switch

Save navigation

Launch

Restore session

Resuming

Do nothing

Page 45: Windows 8 BootCamp

Termination

User explicitly closes the app: soft terminationSystem needs more memoryUser switch occursSystem shutdownApps crash

Apps does not get notified when they are getting terminated

Page 46: Windows 8 BootCamp

Process State Transitions

RunningApp

SuspendedApp

suspendingTerminated

AppLow Memory

Code gets to run No code runs App not running

resuming

User Launches

App

Splash screen

Page 47: Windows 8 BootCamp

Splash screen

System provides splash screen mechanism

Shown while Windows launches your app

Presented during activation

Developer provides color and image in app manifest

Apps need to present a window within 15 seconds of activation or the app will be terminated

Page 48: Windows 8 BootCamp

Background Audio Playback

Apps can play audio in the background

Developers must specify background audio in the app manifest

Each audio stream is given a type (communication, media, game)

Onle one audio stream type may play at a given time

Page 49: Windows 8 BootCamp

Upload/Download in the background

Use the BackgroundTransfer API to upload or download data over HTTP in the background

Initiate upload / download from the foreground and it can continue though your app is suspended

Page 50: Windows 8 BootCamp

Background tasks

Trigger / Condition basedSystem events

InternetAvailableNetworkStateChangeOnlineIdConnectedStateChangeSmsReceivedTimeZoneChange

Background tasks for lock screen capable appsControl ChannelTimerPush Notifications

System events for lock screen-capable appsUserPresentUserAwayControlChannelResetSessionConnectedLockScreenApplicationAddedLockScreenApplicationRemoved

Page 51: Windows 8 BootCamp

Background tasks : resources

  CPU resource quota Refresh period

Lock screen app 2 CPU seconds 15 minutes

Non-lock screen app 1 CPU second 2 hours

Page 52: Windows 8 BootCamp
Page 53: Windows 8 BootCamp

Windows Notification Service

Enables delivery of tile and toast notification over the internet

Tile updates and notifications shown to the user even if your app is not running

WNS handles communication with your app

Scales to millions of users

WNS is a free service for your app to use

Page 54: Windows 8 BootCamp

Push Notification Overview

Windows 8 Cloud Service

Windows Push Notification

Service

Metro Style App

Notification

Client Platform

2

3

1 3

1. Request Channel URI

2. Register with your Cloud Service

3. Authenticate & Push Notification

Page 55: Windows 8 BootCamp

Toast Notifications

Toast notifications deliver transient messages outside the context of the app

Use toast notifications to get user’s attention immediately

User is in control and can permanently turn off toast notifications from your app

Allows quick navigation to a contextually relevant location in your app

Toast notifications are easy to invoke from your app or from the cloud

Page 56: Windows 8 BootCamp

Toast Templates

Uses same template architecture as Live Tiles

Rich set of rendering options available

Page 57: Windows 8 BootCamp
Page 58: Windows 8 BootCamp

Contracts

Contracts enable integrating the Windows 8 experience into your app

Yields a consistent UI for all apps

Page 59: Windows 8 BootCamp

Search

Enables your app to interact and respond to

SuggestionsSearch Query

Page 60: Windows 8 BootCamp

Settings

Consistently given one place to get searchContext sensitive to the front facing app

Page 61: Windows 8 BootCamp

Share

Your app can share anything (text, images, binaries)Automatically filters available applications to share to

Your app can be a share target – receive sharing from othersAdd sharing target as a capability and you can receive share requests

Page 62: Windows 8 BootCamp

Play To

Ability to stream media to compatible devices

Page 63: Windows 8 BootCamp
Page 64: Windows 8 BootCamp

Data

Isolated Storage is the key http://metrostoragehelper.codeplex.com

DatabaseSQL Lite

http://timheuer.com/blog/archive/2012/05/20/using-sqlite-in-metro-style-app.aspx

Page 65: Windows 8 BootCamp

Summarized

Windows RT is a huge leap, both in faith but also technically

Consistent API that feels mature from day one

Well architected solutions putting the user first

Makes us as developers focus on adding the business value

Page 67: Windows 8 BootCamp

Resources

MVVM Lighthttp://mvvmlight.codeplex.com/

Setting up push notifications – registering your apphttps://manage.dev.live.com/build

WAT for Windows 8 + WnsRecipehttp://watwindows8.codeplex.com/releases/view/73334

Calisto – UI Framework for WinRThttps://github.com/timheuer/callisto

Get into the store – register as a deveveloperhttp://msdn.microsoft.com/en-us/windows/apps/

Page 68: Windows 8 BootCamp

Thanks for your attention

Page 69: Windows 8 BootCamp