architecting applications for windows 8 and windows phone 8 by karl ots / @fincooper

33
Architecting applications for WinRT and WinPRT

Upload: karl-ots

Post on 24-May-2015

1.625 views

Category:

Technology


0 download

DESCRIPTION

WinRT and WinPRT share the same core, so it makes a lot of sense to optimize your applications for maximum codeshare. I give an overview of the key similarities and differences of the platforms. I share best practices of some common application scenarios.

TRANSCRIPT

Page 1: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

Architecting applications for WinRT and WinPRT

Page 2: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

About the the presenter

• Karl Ots, Technical Consultant at Symbio

• Windows Phone 8 and Windows 8 trainer

• Windows Azure Insider

• Co-founder of Young Developers Finland

• Microsoft Student Partner

Page 3: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

What we’ll cover

• What shared core means and what it doesn’t

• UX differences

• Porting vs maximum reuse

• Best practices of common scenarios

• Demos

Page 4: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

Shared core

Page 5: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Shared WinRT Core

Networking

Proximity

Sensors

Location

File System

Core app

model

Threading

Page 6: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Windows 8 Platform

Page 7: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

• CLR – common language runtime

• BCL – base class library

• FCL – framework class library

Some definitions

Page 8: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Windows 8 app model

Page 9: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

WP8 MANAGED app model

Page 10: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

WP8 app model

Native app model Legacy app model

Page 11: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Windows Phone Runtime

Full WinRT (around

11,000 members)Subset adopted for

Windows Phone

Runtime (around

2,800 members)

New for Windows

Phone Runtime

(around 600

members)

•Phone-specific additions to Windows Runtime include

• Speech synthesis and recognition

•Windows.Phone.PersonalInformation

• LockScreen and LockScreenManager

•More…

Page 12: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

Targeting maximum reuse

Page 13: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Strategies for targeting both platforms

• Use Model-View-ViewModel

• Share portable .NET code in Portable Class Library

• Use common Windows Runtime API (Add as Link)

• Use Windows Runtime Components for language interoperability

• Use #if conditionals for small code differences

• Use extension methods to bridge implementation differences

Page 14: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Cross-platform app architecture with PLC

Page 15: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

Régis

LaurentDirector of Operations,

Global Knowledge

Competencies include:

Gold Learning

Silver System Management

DEMOPixPresenter

Page 16: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

What’s portable in PixPresenter?

Platform-specific

Portable /shareable

Platform-specific

Windows Phone app Windows Store app

Page 17: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

“Add as Link”

Page 18: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

Régis

LaurentDirector of Operations,

Global Knowledge

Competencies include:

Gold Learning

Silver System Management

DEMOAdd as Link

Page 19: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Small code differences

Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>{

double _accelX = args.Reading.AccelerationX;double _accelY = args.Reading.AccelerationY;// Update ellipse location

});

Deployment.Current.Dispatcher.BeginInvoke(() =>{

double _accelX = args.Reading.AccelerationX;double _accelY = args.Reading.AccelerationY;//Update ellipse location

});

Page 20: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Threading

#if NETFX_COREDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {#elseDeployment.Current.Dispatcher.BeginInvoke(() => {#endif

double _accelX = args.Reading.AccelerationX;double _accelY = args.Reading.AccelerationY;

#if conditional blocks

Page 21: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

HttpWebResponse and HttpWebRequest

var request = (HttpWebRequest)WebRequest.Create(autoCompleteUri);

HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();

// retrieve data using StreamReader

Page 22: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

HttpWebResponse and HttpWebRequest

var request = (HttpWebRequest)WebRequest.Create(autoCompleteUri);request.BeginGetResponse(new AsyncCallback(AutoCompleteCallback), request);}

private void AutoCompleteCallback(IAsyncResult callback){

HttpWebRequest request = (HttpWebRequest)callback.AsyncState;HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(callback);// retrieve data using StreamReader

}

Page 23: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Extension Methods

public static Task<HttpWebResponse> GetResponseAsync(this HttpWebRequest request){

var taskComplete = new TaskCompletionSource<HttpWebResponse>();request.BeginGetResponse(asyncResponse =>{

HttpWebRequest responseRequest = (HttpWebRequest)asyncResponse.AsyncState;

HttpWebResponse someResponse = (HttpWebResponse)responseRequest.EndGetResponse(asyncResponse);

taskComplete.TrySetResult(someResponse);}, request);

return taskComplete.Task;}

Page 24: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

HttpWebResponse and HttpWebRequest

#if WINDOWS_PHONEusing MyExtensionClass#endif

var request = (HttpWebRequest)WebRequest.Create(autoCompleteUri);

HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();

// retrieve data using StreamReader

Use carefully – performance in ABYSMAL

Page 25: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

Best practices

Page 26: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Most common reasons to fail certification

• Windows Phone: failure to check for (light) themes

• Windows 8: no privacy policy

Page 27: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

Do NOT share XAML. Just don’t.

Page 28: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Different Form Factors Require Different UX

Page 29: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Translating UX

Page 30: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Translating UX – Details View

Page 31: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

CaseMoomin video store

Page 32: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Case: Moomin video store

• Windows 8 client ported to Windows Phone 8

• Core Models and ViewModels unchanged

• Azure backend for distributing media (Win8) and keeping track of in-app purchases receipts

• Different Store, different in-app purchases

• WP: download limitations

• Different media players

Page 33: Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @fincooper

#td2013fi @fincooper

Thank you!Time for QA and a quick raffle!