raffaele rialdi_introduction to windows runtime

18
Introduction to Windows Runtime (WinRT) Raffaele Rialdi @raffaeler [email protected] http://www.iamraf.net

Upload: jakub-dvorak

Post on 30-Nov-2015

30 views

Category:

Documents


0 download

DESCRIPTION

Intro to Windows Runtime

TRANSCRIPT

Introduction to Windows

Runtime (WinRT)

Raffaele Rialdi

@raffaeler

[email protected] http://www.iamraf.net

Tailored User Experience

Metro

Immersive

Engaging and Alive

Connected

Touch-first

Metro

Multiple form factors

Inspiring Confidence

Multitasking

full screen

live tiles

use live data

small devices

fast and fluid

secure, trustable

different resolutions

Current problems

• No marketplace: how can you trust an application?

• Admin privilege is required to install most Apps

• Interoperability is difficult (PInvoke / COM) –Memory and Performance costs are high

–Accessing OS API can be tough

• Mixing native and managed language is hard • "C" APIs lifecycle is error-prone (CreateFile … CloseHandle)

• I/Os are blocking (network, storage, …)

• No standards for App to App communication • Search, Tweets, Facebook posts, …

Windows Runtime Architecture

Metro apps Desktop apps

Windows Runtime APIs and Services

Win32

Language Projections

.NET / Js / C++

XAML DirectX HTML HTML WPF SL Win form

MFC

DX

.NET / Js / C++

Windows Kernel Services

Win32 XAML Pickers … Network

UI Controls Media Storage

Windows Metadata

Windows Runtime Core

Runtime Broker

Filtered access to WinRT

BCL / libraries

What is the Windows Runtime?

• It's the evolution of the Component Object Model (COM)

• The infrastructure reuse old concepts like apartments, IUnknown

and addref/release

• IDispatch is gone, IInspectable is the new base interface

• New support for Events (no connection points) and static types

• Totally different Type System (no Variants, no BSTRs, …)

• WinRT use ECMA-335 (.net Framework) metadata

• WinRT and CLR talks the same "language"

• No marshalling gotchas

It's not a replacement for the CLR

• CLR is required for managed languages infrastructure

WinRT Type System

• Basic types - bool, integers, floats, enum, guid, type, object

• Strings - binary compatibile with .NET (string) and C++ STL (wstring)

- are immutable

- are value-types (non-nullable)

• There are Reference Types - All types that implement WinRT interfaces

• There are Value Types - All the others … for example arrays and structures

- Structures can't declare reference (deep/shallow copy problem)

• "Complex" types - Vector (collection) and Map (dictionary)

- Vector<T> implements IObservableVector<T> that is mapped to INotifyCollectionChanged

Language Projections

Projections map WinRT types to the projected language

• Different casing standards - Javascript (camelCase), C++ and .NET (PascalCase)

• Developers need to understand edge-cases - Javascript standard only support IEEE-754 (floats).

This means the max integer is 53 bit maximum

• Few types are defined both in WinRT and .NET - They are treated as 'special' and seen as equivalent

- INotifyPropertyChanged, INotifyCollectionChanged, …

• Some .NET types cannot be mapped transparently - Streams, Buffers, Tasks are mapped via extension methods

• I expect third party projections too - Java?, Python?, D language?, Delphi?, …

Contracts : «XXI century's clipboard»

• A standard way to "talk" to other Apps or OS services

• A sort of publisher / subscriber pattern

• Main Contracts available:

• Search, Share, Protocol, PlayTo, App to App picking

• WinRT activate Apps that expose Contracts

• Running Apps is done via Launch Contract

• Tiles are NOT shortcuts!

• Apps use the Manifest to opt-in for Contracts

• They receive parameters in the activation method

Class Catalog

Explorer.exe

Activation System

Activate RPCSS

DCOM Launch

Application.exe

Application Activation

Asynchronous by design

Special objects wraps Asynchronous Operations

• In WinRT they implement IAsyncOperation<T> • AsTask extension method is used to convert it to a Task<T>

• In .NET these objects are Task<T> • AsAsyncOperation extension method to obtain an

IAsyncOperation<T>

C# 5.0 have new async/await keywords

Javascript and C++ can use "promises" pattern

Tomorrow Hall 4 - 10:45

Problem: Apps should never block UI thread

Solution: API that may take more than 50ms are only async

Marketplace

The sandbox

Application Package

WinRT

Windows Kernel Services

Win32

Security Broker Proxy

Libraries

White-listed

Manifest

Application code

Developing with WinRT

• XAML UI for .NET and C++

• XAML / DirectX can share surfaces • DirectX inside a XAML control

• Large virtual DirectX surface in conjunction with XAML

• High Performance DirectX drawing, XAML overlapped

• Custom WinRT components are easy to write • i.e. exposing C# or C++ code to Javascript or vice-versa

• Custom components are private to the App (no RegSvr32)

• Cross language calls are cheap • No more P-Invokes!

• As fast as a vtable call

• Desktop Apps can use a WinRT APIs subset

• CLR have an additional weapon: "Portable Class Library" • A DLL with code that run on Metro, desktop, SL, …

• As it's IL code, it runs as 32 or 64 bits as well

Metro profile for .NET development

What else is not in the Metro profile?

• APIs that are already in WinRT (Storage, Sockets, Network, etc.)

• Server libraries like WCF, Asp.net, …

• APIs that could bypass the sandbox • System.Data, Remoting, AppDomain, Private Reflection, …

Metro Fx 4.5 WP7

# assemblies 15 120 22

# namespaces 60 400 88

# types ~1'000 ~14'000 ~2'000

# members ~10'000 ~110'000 ~14'000

Metro profile was a good opportunity to clean BCL • Removed: Xml DOM, WebClient, Threads, … • Moved Reflection in System.Reflection

• GetTypeInfo extension method to access reflection classes

Developer thoughts

• No need to elevate (UAC) a Metro App • Admin Apps will run in the old desktop

• Storage • Apps can access only locations specified by manifest

• Users can pick (via UI) a file that is stored elsewhere

• No local db APIs at the moment

• Media and Sensors • Easy access to cameras, accelerometer, …

• Require user consent (requested via manifest)

• Network • Great library to ease oAuth authentication

• Flexible HttpClient replace WebClient

• Websockets support

• Dig into the APIs and discover it by yourself!

Takeaways

• WinRT is a great step in Windows evolution

• Exposes native OS services in a pure OOP way

• Closes the gap between managed and native languages

• Developers can use their current knowledge to

create Apps from small devices to classic PCs

• Marketplace is an opportunity for developers and

a sweet experience for end-users

• Think about performance/battery issues

• It's Framework.NET best friend

Windows 8 Cheat Sheet

C Charms Bar

H Share charm

K Connect charm

I Settings charm

Q Search pane

F File Search

W Settings Search

V Cycles through toasts

O Locks device orientation

Tiles to the left / right ()

Split left/right

Temporarily peek at the desktop

Cycle apps /

Cycle input language & keyboard

Narrator

Z Application Bar

Tools for WinRT

WinRT.codeplex.com

(more to come …)

Don’t forget to submit

your feedback and win a

great Nokia smartphone

and Kindle e-reader!