Programming Metro-style                                   Apps Workshop                                   Matthew Baxter-R...
Agenda   •   From Zero to Hero   •   Moving from .NET   •   Asynchronous Programming   •   Sandboxing and Protection   •  ...
Hire me   • Like this presentation?          – Private, onsite presentations of this workshop            tailored to your ...
From Zero to HeroTwitter: @mbrit            4
The London Ringways                              1                          2                  4                      3Twi...
The London Ringways (2)        It would have affected life in the capital in every conceivable        way, changing the wa...
Windows 7.1   Highways Agency, CC-BYTwitter: @mbrit             7
Windows 8 and Metro-style – Microsoft’s London Ringways   • The Ringways only make sense once the time to     do it has pa...
The Land of Confusing Naming   • Metro is the name of a “design aesthetic”          – Created for Windows Phone          –...
The Land of Consuming Naming (2)   • Windows RT is the name given to new ARM-     based devices          – Sometimes contr...
WinRT defined   • “Windows Runtime”   • An old strategy – older than iPad          – The fact it’s happening now is coinci...
The Problem with Politics   • Building software with .NET is dead easy!          – But it depends on the type of software ...
The Problem with Politics (2)   • The .NET story has been “absorbed” into the     WinDiv team within Microsoft          – ...
The Problem with Politics (3)   • Ride the wave!Twitter: @mbrit         14
Windows 8 Editions   • Windows 8          – Home edition, no encryption   • Windows 8 Pro          – Domain-joinable, encr...
Windows RT Edition   • Windows RT          – ARM, licensed OEM only          – For whatever reason, this isn’t “Windows 8”...
Windows Server 2012 Editions   • SKUs not announced…          – Release will be this year thoughTwitter: @mbrit           ...
Post-PC   • It’s about relationships   • It’s primarily skewed towards retail   – …but Microsoft is an enterprise company ...
What’s Metro-style for? (Retail)   • In the retail space, it’s for what the iPad is for…          – Typical Top 100 paid i...
What’s Metro-style for? (Enterprise)   • So how are people using iPad in business?   • Will Metro-style offer different ve...
The iPad in business   • Strangely difficult to get information on this…          – Groupware                   Email, ca...
The iPad and native LOB   • Apple offers an iOS Developer Enterprise     Program…          – “Distribute your proprietary,...
How do you choose whether to do Metro-style or not?   • Retail?         • It’s your only choice!   • Enterprise?         •...
What about Silverlight?   • Generally…          – There are some legitimate uses for Silverlight            within the ent...
Touch on laptops   • Whitepaper          – “The Human Touch: Building Ultrabook            Applications in a Post-PC Age” ...
How to build Metro-style apps   • There are 2.5 ways to do it…          – C# and XAML          – JavaScript and HTML      ...
Dealing with constriction   • You’re going to feel like you’ve had your wings     clipped…          – Metro-style is not t...
What can/can’t you do on Windows RT?   • Metro-style apps only   • Can’t join to domain          – Managed through Microso...
Is there even a future for Windows RT?   • Windows RT was born at a time when Intel couldn’t     build a power-efficient c...
Windows Phone   • It’s now more obvious that Windows Phone 7     was just a stepping stone…          – The guts of the OS ...
Searching for “winrt” on Google   • Google interprets “winrt” as “winter”, so just     exclude out “winter”…              ...
Getting to RTM   • Nothing set in stone…          – “Release to Manufacturing” in late July          – “Retail release” in...
From Zero to Hero - Summary   • The naming is somewhat confusing   • A lot of the weirdness is caused by the conflict     ...
Moving from .NETTwitter: @mbrit           34
“.NET Core”   • You have to use a cut-down profile of .NET          – Precedent for this:                   .NET Compact ...
WinRT and .NET co-existence   • Driven through a shared metadata model          – COM’s metadata borrows .NET’s metadata  ...
Garbage collection   • You’re running .NET inside of a WinRT process…          – You’re fine – everything you’re used to i...
Choosing a UI track – HTML or XAML   • Individually and as a community, this is an     important choice…          – My per...
Special project templates      Distinct set of      templates for       Metro-styleTwitter: @mbrit         39
Special referencing         References are            shown as          “packages”                          Reflector show...
Limited options                  “.NET Core” is just one                          thingTwitter: @mbrit                    ...
Packages   • Packages aren’t just used for apps…          – They are used for system components too          – Both OS lev...
WinRT package                  c:Program Files (x86)Windows Kits8.0SDKManifest.xml     This is the package you            ...
Your own packages          c:Program Files (x86)Microsoft SDKsWindowsv8.0ExtensionSDKs                                    ...
XAML for .NET developers   • The XAML implementation is not .NET          – Hence why it’s not called “WPF”          – It’...
HTML5/JavaScript for .NET developers   • We’re going to look at this a bit later…Twitter: @mbrit                       46
What you don’t get   • Lots!   • Major sections are…          – No ADO.NET          – No serialization          – No Remot...
What’s changed?   • Some APIs are now asynchronous…          – …which we’ll come on to   • Some .NET types have been moved...
File system APIs   • Was fantastically straightforward in .NET…          – It’s now not fantastically straightforwardTwitt...
Multiplatform targeting   • You need one codebase that works in .NET and     WinRT…          – Let’s look at howTwitter: @...
Changes to “System.Reflection”   • Good example of an established API that has changed          – Basic properties have mo...
Shimming with extension methods   • One significant challenge is creating one code     base that works in .NET Full and .N...
Shimming - Example                                                       Our Reflection shim                              ...
Reverse shimming with extension methods   • We need to get parity between .NET and Metro-style…                           ...
Type aliasing with “using”                                                                    This has the effect of      ...
“#if…#endif”   • Use this to compile around code that’s not     supported, or to switch implementations          – The pre...
Solution structure   • Keep solutions and projects separate and use     symbolic links          – Wherever possible do not...
DEMO: One library, many targetsTwitter: @mbrit        58
The Open Source problem   • A significant problem with developing Metro-     style is the lack of OSS libraries…          ...
Open Source libraries resist porting   • Most actively used OSS libraries are cross     platform already…          – Silve...
Look to prefer “Silverlight libraries”   • .NET Core is closer to Silverlight than .NET Full…          – …you’ll probably ...
This is all a bit confusing and difficult, right?”   • Isn’t it just!          – …but you haven’t seen anything yet!Twitte...
Using the JavaScript track   • This is the first place where we see     “Windows Runtime components”…          – These are...
Using the JavaScript track (2)   • WinRT components restrictions…          – All the classes need to be sealed            ...
DEMO: Using the JavaScript trackTwitter: @mbrit        65
Databases   • For most platforms, this story is pretty good:          – iOS – baked in SQLite, native driver or Core Data ...
Moving from .NET - Summary   • ".NET Core" is a cut-down version of .NET          – …slightly more cut-down than Silverlig...
Asynchronous ProgrammingTwitter: @mbrit               68
The UI thread   • All threads are equal, but some threads are     more equal than others          – The UI thread is the m...
50ms rule   • If it’s going to take more than 50ms to run on     the UI thread, it has to be handed over to a     backgrou...
Task Parallel Library   • All of WinRT’s async stuff is based on the Task     Parallel Library (TPL)          – Introduced...
Task Parallel Library (2)   • Base currency is the Task          – It’s just a unit of workTwitter: @mbrit                ...
Task Parallel Library (3)   • You can add continuation handlers to Task instances          – (Which are callbacks, essenti...
Task Parallel Library (3)   • The final piece of magic is the Result…          – Use Task<T> to indicate you want a result...
Standard JavaScript “async/callback” patternTwitter: @mbrit               75
“async” and “await”   • Mind-bendingly brilliant…          – Everything that’s happened to C# and .NET over            the...
Making a network call without “async/await”Twitter: @mbrit              77
Making a network call with “async/await”Twitter: @mbrit               78
Async API design   • APIs generally don’t have both sync and async     calls…          – Async calls have to “do better” t...
Asynchronous programming - Summary   • UI thread is more important than the others   • If it takes more than 50ms to run, ...
Sandboxing and ProtectionTwitter: @mbrit                    81
Capabilities   • Much as you would expect          – Declared in the manifest          musicLibrary                  remov...
File Picker   • File Picker is the way you pick files in Metro-     style…         • Anything else is out-of-scope   • Hom...
“documentsLibrary”   • Microsoft’s strong preference is that you use     the “File Picker”          – documentsLibary is t...
A deeper look at the restrictions   • Let’s take a deeper look into what we can and     can’t do within our sandbox throug...
“System.Reflection.Emit”   • Fantastic example of how seriously Microsoft     are taking sandboxing…          – Vector for...
An illustration with Moq   • Moq uses CRE to create dynamic proxies          – Uses the Castle Project Dynamic Proxy libra...
Why Moq can’t run on Metro-style   • Moq will port happily to WinRT, its Castle Core     that won’t port…          – Most ...
“Cannot be used on the current platform”   • Not caspol – more fundamental…      System.InvalidOperationException: The API...
Just for fun…Twitter: @mbrit   90
Working round the sandboxing   • What you can do is load a “.NET Core” assembly     into a “.NET Full” process…          –...
Working around the sandboxing (2)   • Therefore we can:          – Create a version of Castle Core that uses a faked      ...
DEMO: Baked mocks using MoqRTTwitter: @mbrit     93
“I thought this was confusing and difficult before!”   • We haven’t even done anything difficult yet!Twitter: @mbrit      ...
Network access   • Locked down          – There’s a full sockets API implementation in Metro-            style…           ...
Contracts and extensions   • We’ll cover this later…Twitter: @mbrit                96
Local disk access   • Obviously highly restrictedTwitter: @mbrit                    97
Local disk access – Your special folders   • These are just for you…                            Windows.Storage.Applicatio...
Local disk access – Your shared folders   • These you share with others…                          Windows.Storage.Download...
Local disk access – File types   • Have to declare the types of files that you work     with in the manifestTwitter: @mbri...
Don’t depend on holes!   • Any hole you do find will get pluggedTwitter: @mbrit                     101
Sandboxing and Protection - Summary   • Apps declare capabilities   • Sandboxing restricts certain types of activities    ...
Unit testingTwitter: @mbrit       103
We all do unit testing, right?   • Right??Twitter: @mbrit          104
Visual Studio test framework   • Now in the Express editions   • Pretty decent test framework…          – Your only option...
The problem with testing Metro-style   • The App Domain has to be configured as a     Metro-style app…          – Only VS ...
Shimming test libraries   • We saw shimming before, so this is dead easy…Twitter: @mbrit                   107
Faking and mocking   • We spoke about Moq (and the problems with     it) before…          – Microsoft are doing a “Fakes” ...
Unit Testing - Summary   • Integrated unit testing story in VS remains good   • Now available in Express SKUs   • Metro-st...
Contacts and ExtensionsTwitter: @mbrit                  110
This is where life gets really easy   • If you go with the fundamental use cases of     Metro-style, life is fairly blissf...
Contracts   • A way of “de-siloing” applications          – Almost like how you would do DDE in 2012                   Sha...
Data that you can share   • You can share…          – Text          – URI          – Bitmap          – HTML          – RTF...
What sharing is not   • It’s not directive inter-app/cross-process     comms…          – The usage pattern is one where bo...
Share targets   • Simple steps…          – Add a “Share Target” component to your app          – Specify declaration in th...
DEMO: Share targetsTwitter: @mbrit       116
Share sources   • More simple steps…          – Register yourself with the DataTransferManager          – Call ShowShareUI...
Search contracts   • More or less as before…          – Add a “Search Target”          – Build a page that shows the data ...
DEMO: Search contractsTwitter: @mbrit      119
Settings contracts   • Slightly more complicated…          – Sign-up for CommandRequested on SettingsPaneView          – R...
Settings contracts (2)   • Caution on this is to use a Popup window…          – These go away automatically when the user ...
“App-to-App” Picking contract   • This is done with the File Picker control…Twitter: @mbrit                      122
Cached file updater contract   • Used for keeping local cache files in sync with     network copies…          – Docs call ...
Extensions   • These extend Windows features…                  Account picture provider     File activation               ...
File activation   • Again, really easy…          – Declare in manifest          – Handle FileActivated eventTwitter: @mbri...
DEMO: File activationTwitter: @mbrit         126
Background tasks   • We’ll take a look at this later…Twitter: @mbrit                         127
Contracts and Extensions - Summary   • Life here is mostly easy   • Contracts let you share information          – …Share ...
NotificationsTwitter: @mbrit        129
Notifications   • Unified notifications system…          – Tiles          – Badges          – Toast          – Consistent ...
Local vs Network updates   • Notification updates can either…          – Go through a “local loopback”          – Via Wind...
Live tiles   • Keyed into the notification system…          – Allows you to change data on the home screen   • Steps…     ...
Live tiles (2)                        There are *tons* of tile                          template formats…Twitter: @mbrit  ...
Badges   • Steps – as per tiles…          – Ask the BadgeUpdateManager to give you some            update XML          – P...
Badges (2)Twitter: @mbrit   135
Badge glyphs   • Badges can…          – Show a number from 1-99, or          – Show a glyphTwitter: @mbrit                ...
Toast   • Steps – as per the others!          – Ask the ToastUpdateManager to give you some            update XML         ...
Toast (2)Twitter: @mbrit   138
Windows Push Notification Service - WNS   • Register with WNS to broker requests                                          ...
Windows Push Notification Service - WNS   • Signalling…                                         Some          Your App    ...
Notifications - Summary   • Unified notification system for     tiles, badges, and toast   • Each have a set of templates ...
Application LifetimeTwitter: @mbrit               142
Battery   • “If it’s not running, it’s not using the battery”          – …therein lies everything you need to know about  ...
Micro-hibernation   • Even on a mains powered desktop, apps that     are in the background are spun to diskTwitter: @mbrit...
Process lifetime events   • As you would expect…                  Activated                    Suspending                 ...
Activation   • This is the period of time during which you see     the splashscreen…          – You can be activated becau...
Suspending   • Do everything in five seconds or you’re killed   • You could be suspended for days or weeksTwitter: @mbrit ...
Closing   • Follows the iPad model…          – There’s no close option in iPad apps          – If you put a close option i...
Crashing   • The required path is that you just “forget about     it”…          – User returns to the Start screen        ...
Removal   • You don’t get toldTwitter: @mbrit           150
Apps that sync in the background   • You probably can’t sell a sponsor on an app     that requires “always on” internet…  ...
Background tasks   • Register a class along with one trigger and optional conditions…          – Plus a manifest declarati...
Background tasks (2)                                15 minutes is the                             highest frequency that  ...
Background tasks (3)   • You don’t necessarily run inside your own     application’s process…          – PushNotificationT...
Background tasks (4)   • Some triggers are restricted to apps on the lock     screen…          – MaintenanceTrigger is not...
Background task progress reporting   • You should report progress back to your app…          – You’ll be given an IBackgro...
Using background tasks for background sync   • Steps…          – Keep track of changes to local state as you            no...
Using background tasks to sync… cheat mode   • To get through the store, you’re not allowed to     depend on third-party s...
Application Lifetime - Summary   • “If its not running, its not using the battery”   • Process states: NotRunning, Running...
Packaging and DeploymentTwitter: @mbrit                   160
Approaches   • Different approach for retail and enterprise…          – Retail follows the Apple App Store model          ...
AppX   • AppX is the new standard     packaging format for     Metro-style apps…                                     Conte...
Windows App Certification Kit   • Aka “WACK”Twitter: @mbrit        163
Packaging API   • There is an API for packaging…          – Package apps          – Deploy apps          – Query packagesT...
Enterprise scenarios   • Four scenarios to consider…          – Windows 8 ESD (Enterprise Supplied Device)          – Wind...
Enterprise Apps and the Store   • Enterprises can deliver their applications     through the store…          – Clever mode...
Sideloading   • This is the process by which applications are     loaded onto the device outside of the store          – E...
Sideloading – Restrictions apply   • Sideloading means you don’t have to pass the     store requirements…          – What’...
Windows 8 ESD   • It’s assumed in this scenario that the device is     joined to the domain…          – Possibly only work...
Windows 8 BYOD   • Here, we assume a BYOD scenario is one where     there is no domain membership          – Change Regist...
Windows RT – ESD and BYOD   • Picture remains unclear…          – Was discussed at TechEd          – This definitely needs...
Installing apps   • Two methods…          – Bake it into the image          – Deploy using PowerShellTwitter: @mbrit      ...
PowerShell installation   • This is the advantage of having everything     wrapped up into a single AppX file…          – ...
Updating via PowerShell   • The same add-appxpackage command will also     run updates          – …thus just deploy a new ...
Removing apps   • Again, having everything wrapped up nicely in     packages helps here…          – remove-appxpackageTwit...
Packaging and Deployment - Summary   • Different models for retail and enterprise   • Same packaging structure - AppX   • ...
Hire me   • Like this presentation?          – Private, onsite presentations of this workshop            tailored to your ...
Q&A                                                            Matthew Baxter-Reynolds                                    ...
Upcoming SlideShare
Loading in …5
×

Programming Metro-style Apps Workshop

3,758 views

Published on

An end-to-end look at Metro-style/WinRT development. Comments - @mbrit on Twitter.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,758
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
1
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Programming Metro-style Apps Workshop

  1. 1. Programming Metro-style Apps Workshop Matthew Baxter-Reynolds June 2012 – v1 (Public) http://programmingmetrostyle.com/Presentation licensed under the Creative Commons Attribution-ShareAlike license, see last slide
  2. 2. Agenda • From Zero to Hero • Moving from .NET • Asynchronous Programming • Sandboxing and Protection • Unit Testing • Contracts and Extensions • Notifications • Application Lifetime • Packaging and Deployment • Q&ATwitter: @mbrit 2
  3. 3. Hire me • Like this presentation? – Private, onsite presentations of this workshop tailored to your project programme – In-depth Metro-style training (public or private courses) – Consultancy on your Metro-style development plans – http://mbrit.com/Twitter: @mbrit 3
  4. 4. From Zero to HeroTwitter: @mbrit 4
  5. 5. The London Ringways 1 2 4 3Twitter: @mbrit 5
  6. 6. The London Ringways (2) It would have affected life in the capital in every conceivable way, changing the way London looked and functioned. It would have changed the development of the city forever. It was far- reaching and visionary; planning on a scale rarely seen in this country. It was a transport scheme to end all transport schemes. And it was utterly unacceptable to the general public. CBRD.co.uk - http://www.cbrd.co.uk/histories/ringways/Twitter: @mbrit 6
  7. 7. Windows 7.1 Highways Agency, CC-BYTwitter: @mbrit 7
  8. 8. Windows 8 and Metro-style – Microsoft’s London Ringways • The Ringways only make sense once the time to do it has passed… – You can’t revisit it once the moment has passed – A lot about Metro-style doesn’t make sense today – Especially the desktop play – …but it’s a good way of competing with the iPad – It’s all about market protectionTwitter: @mbrit 8
  9. 9. The Land of Confusing Naming • Metro is the name of a “design aesthetic” – Created for Windows Phone – Embraced vigorously by Microsoft • WOA was the name for “Windows on ARM” – A version of Windows that run on ARM processors • WinRT is the name of a new API for Windows – Replaces Win32Twitter: @mbrit 9
  10. 10. The Land of Consuming Naming (2) • Windows RT is the name given to new ARM- based devices – Sometimes contracted to “Win-RT” in the press and on Twitter • Metro-style is the name of the process model and deployment pattern used for a new class of applications – …specifically designed to address a post-PC ageTwitter: @mbrit 10
  11. 11. WinRT defined • “Windows Runtime” • An old strategy – older than iPad – The fact it’s happening now is coincidence • Pressures? – Building Windows, Office, SQL Server, etc is hard in Win32 – WinRT was designed to address this problem • It’s COM! – …or as I like to call it, “COM++”Twitter: @mbrit 11
  12. 12. The Problem with Politics • Building software with .NET is dead easy! – But it depends on the type of software you’re building…  Most of us don’t build operating systems, Office, or SQL Server • It’s always been a “DevDiv” product within Microsoft – As such tools have been targeted at developersTwitter: @mbrit 12
  13. 13. The Problem with Politics (2) • The .NET story has been “absorbed” into the WinDiv team within Microsoft – WinDiv generally not keen on things that look and behave like Java – .NET and WinRT coexist in a slightly awkward fashion – All of the Metro-style development messages are coming from the WinDiv team  …which is why it’s a bit weird  …and where all the C++ stuff comes fromTwitter: @mbrit 13
  14. 14. The Problem with Politics (3) • Ride the wave!Twitter: @mbrit 14
  15. 15. Windows 8 Editions • Windows 8 – Home edition, no encryption • Windows 8 Pro – Domain-joinable, encryption • Windows 8 Enterprise – Available only through volume licensing – As-yet-unspecified management featuresTwitter: @mbrit 15
  16. 16. Windows RT Edition • Windows RT – ARM, licensed OEM only – For whatever reason, this isn’t “Windows 8” – The only thing you can run on it is Metro-style apps  (Plus Office, and IE, at the moment)Twitter: @mbrit 16
  17. 17. Windows Server 2012 Editions • SKUs not announced… – Release will be this year thoughTwitter: @mbrit 17
  18. 18. Post-PC • It’s about relationships • It’s primarily skewed towards retail – …but Microsoft is an enterprise company • Microsoft also owns Office – But Office needs a keyboard? – If you’ve got a keyboard, it’s not post-PC – So is it a clamshell OS? • What about the desktop?Twitter: @mbrit 18
  19. 19. What’s Metro-style for? (Retail) • In the retail space, it’s for what the iPad is for… – Typical Top 100 paid iPad apps  80% games  19% non-games, but not “work” (Instagram, etc)  1% work (nearly always Documents-to-Go) – Similar split on iPhone, Android phones, and Windows PhoneTwitter: @mbrit 19
  20. 20. What’s Metro-style for? (Enterprise) • So how are people using iPad in business? • Will Metro-style offer different vectors? • Remember that the only tech stocks that have decent ROI are enterprise stocksTwitter: @mbrit 20
  21. 21. The iPad in business • Strangely difficult to get information on this… – Groupware  Email, calendar, contacts – Web browsing – Document viewing – Some document construction – Web browsing – Navigation  e.g. off the tube, where’s the meetingTwitter: @mbrit 21
  22. 22. The iPad and native LOB • Apple offers an iOS Developer Enterprise Program… – “Distribute your proprietary, in-house iOS apps to employees or members of your organisation” – $299/year – But unusual…  Do you know of anyone who does it?  Why’s it unusual?Twitter: @mbrit 22
  23. 23. How do you choose whether to do Metro-style or not? • Retail? • It’s your only choice! • Enterprise? • Same rules apply as per targeting iPad… • Should it not be a web app? • Would Silverlight be better?Twitter: @mbrit 23
  24. 24. What about Silverlight? • Generally… – There are some legitimate uses for Silverlight within the enterprise  Visualisation very common • Inside the enterprise – It’s unclear whether Metro-style replaces apps that run in Silverlight in the enterprise…  There’s lots of bits missing in this new world  Will the context switching between Metro-style and regular desktop kill usability?Twitter: @mbrit 24
  25. 25. Touch on laptops • Whitepaper – “The Human Touch: Building Ultrabook Applications in a Post-PC Age” – Lack of touch on new MacBook Pro is a misstepTwitter: @mbrit 25
  26. 26. How to build Metro-style apps • There are 2.5 ways to do it… – C# and XAML – JavaScript and HTML – C++ and DirectX  Mainly for games • We’ll talk about how to choose from the first two later…Twitter: @mbrit 26
  27. 27. Dealing with constriction • You’re going to feel like you’ve had your wings clipped… – Metro-style is not the place for clever hackery – (But remember WinRT is more than Metro-style) – Ride the wave (still)!Twitter: @mbrit 27
  28. 28. What can/can’t you do on Windows RT? • Metro-style apps only • Can’t join to domain – Managed through Microsoft InTune, probably • There is a desktop... – But only Office 2013 RT, Windows Explorer, and IE10 can use it – Probably will end up going away in future versionsTwitter: @mbrit 28
  29. 29. Is there even a future for Windows RT? • Windows RT was born at a time when Intel couldn’t build a power-efficient chip… – “Clover Trail” chipset  x86  <= 700g  <= 9mm thick  ~9h battery life – The new iPad  622g  9mm thick  10h battery life • In theory, anyone will be able to walk into PC World and buy a “proper” Windows 8 tablet for the price of a Windows RT tabletTwitter: @mbrit 29
  30. 30. Windows Phone • It’s now more obvious that Windows Phone 7 was just a stepping stone… – The guts of the OS will converge with Windows 8 – The development model for Windows Phone 8 has not been announced  Soon!Twitter: @mbrit 30
  31. 31. Searching for “winrt” on Google • Google interprets “winrt” as “winter”, so just exclude out “winter”… contracts winrt -winterTwitter: @mbrit 31
  32. 32. Getting to RTM • Nothing set in stone… – “Release to Manufacturing” in late July – “Retail release” in October – “Windows RT” devices Q1 2013?  (Based on quotes from Computex in early June)Twitter: @mbrit 32
  33. 33. From Zero to Hero - Summary • The naming is somewhat confusing • A lot of the weirdness is caused by the conflict between WinRT and .NET “philosophy” • Replicating iPad business applications is largely do-able • Possibly not a straightforward replacement for Silverlight • Use "-winter" on Google to surface WinRT content • RTM late July, shipping in OctoberTwitter: @mbrit 33
  34. 34. Moving from .NETTwitter: @mbrit 34
  35. 35. “.NET Core” • You have to use a cut-down profile of .NET – Precedent for this:  .NET Compact Framework, Silverlight for Windows Phone – More cut down than Silverlight  (Thumb in the air)Twitter: @mbrit 35
  36. 36. WinRT and .NET co-existence • Driven through a shared metadata model – COM’s metadata borrows .NET’s metadata – From time-to-time you’ll hit a “projection”...  Types mapped from one world to the other  e.g. IDictionary  IMap – You generally don’t need to worry about any of this thoughTwitter: @mbrit 36
  37. 37. Garbage collection • You’re running .NET inside of a WinRT process… – You’re fine – everything you’re used to is still there in terms of CLI – The only thing you’re missing is framework capabilityTwitter: @mbrit 37
  38. 38. Choosing a UI track – HTML or XAML • Individually and as a community, this is an important choice… – My personal view right now is XAML – Is the tooling going to be good enough? – Where will community support go? – Is the current interop story workable? – Where do we want to be in 2018?Twitter: @mbrit 38
  39. 39. Special project templates Distinct set of templates for Metro-styleTwitter: @mbrit 39
  40. 40. Special referencing References are shown as “packages” Reflector shows a special Windows reference. This is actually WinRTTwitter: @mbrit 40
  41. 41. Limited options “.NET Core” is just one thingTwitter: @mbrit 41
  42. 42. Packages • Packages aren’t just used for apps… – They are used for system components too – Both OS level components and APIs can be delivered using packages – Extends the work done with NuGetTwitter: @mbrit 42
  43. 43. WinRT package c:Program Files (x86)Windows Kits8.0SDKManifest.xml This is the package you References reference in your project for WinRT… CommonConfiguration Neutral …and this is the metadata file that you Windows.winmd consumeTwitter: @mbrit 43
  44. 44. Your own packages c:Program Files (x86)Microsoft SDKsWindowsv8.0ExtensionSDKs Appears in the WindowsExtensions node <YourFolder> in “Add References” <major.minor> SDKManifest.xml References CommonConfiguration Neutral These files will be automatically referenced in your project <YourBinaries>Twitter: @mbrit 44
  45. 45. XAML for .NET developers • The XAML implementation is not .NET – Hence why it’s not called “WPF” – It’s COM-based – Most of the types are the same • XAML is very different from HTML… – Like HTML, XAML is declarative – XAML is not document-centric  With XAML when you position things, other things don’t move out of the way – Styling is rudimentary, compared to CSS3 – XAML is an object-graph expressed as XMLTwitter: @mbrit 45
  46. 46. HTML5/JavaScript for .NET developers • We’re going to look at this a bit later…Twitter: @mbrit 46
  47. 47. What you don’t get • Lots! • Major sections are… – No ADO.NET – No serialization – No Remoting – No System.Reflection.Emit – No threading outside of Task Parallel LibraryTwitter: @mbrit 47
  48. 48. What’s changed? • Some APIs are now asynchronous… – …which we’ll come on to • Some .NET types have been moved to WinRT components… – …of which XAML is a good example • Some types/members are gone! – …of which the wholesale restructuring of System.Reflection is a (baffling) exampleTwitter: @mbrit 48
  49. 49. File system APIs • Was fantastically straightforward in .NET… – It’s now not fantastically straightforwardTwitter: @mbrit 49
  50. 50. Multiplatform targeting • You need one codebase that works in .NET and WinRT… – Let’s look at howTwitter: @mbrit 50
  51. 51. Changes to “System.Reflection” • Good example of an established API that has changed – Basic properties have moved out into a separate Extension method to System.Reflection.TypeInfo class access metadata – Mostly everything is available through extension methods …oddly offering less utility!Twitter: @mbrit 51
  52. 52. Shimming with extension methods • One significant challenge is creating one code base that works in .NET Full and .NET Core – Extension methods are your friend – Type aliasing is also your friend – #if…#endif is your other, other friend – Look to Silverlight ports in open source projects for helpTwitter: @mbrit 52
  53. 53. Shimming - Example Our Reflection shim Extension properties don’t exist Closer to the .NET original, but not quite right because of that “IsPublic” method…Twitter: @mbrit 53
  54. 54. Reverse shimming with extension methods • We need to get parity between .NET and Metro-style… A “reverse shim” that makes the .NET API look like the In a real Metro-style API implementation, the namespaces would be the sameTwitter: @mbrit 54
  55. 55. Type aliasing with “using” This has the effect of replacing the type at The original .NET compile-time implementation Unchanged underlying implementation Assuming “Bar” is unavailable in Metro- style, create a copy…Twitter: @mbrit 55
  56. 56. “#if…#endif” • Use this to compile around code that’s not supported, or to switch implementations – The preprocessor directive for Metro-style apps is NETFX_CORE – Pick the primary path and be consistentTwitter: @mbrit 56
  57. 57. Solution structure • Keep solutions and projects separate and use symbolic links – Wherever possible do not duplicate code filesTwitter: @mbrit 57
  58. 58. DEMO: One library, many targetsTwitter: @mbrit 58
  59. 59. The Open Source problem • A significant problem with developing Metro- style is the lack of OSS libraries… – The ecosystem is missing Castle Core SQLite sqlite-net xUnit ESENT Moq NInject NLog Lucene Interop Raven Newtonsoft Raven Client JSON EmbeddedTwitter: @mbrit 59
  60. 60. Open Source libraries resist porting • Most actively used OSS libraries are cross platform already… – Silverlight, Compact Framework, Mono, etc – But anything other than trivial projects end up being hard work…  Individually you’re unlikely to want to carry the cost  As a community, these libraries are going to take a while to come over  10 months since BUILDTwitter: @mbrit 60
  61. 61. Look to prefer “Silverlight libraries” • .NET Core is closer to Silverlight than .NET Full… – …you’ll probably have more luck using Silverlight versions of libraries as these are already cut-down to something closer to .NET CoreTwitter: @mbrit 61
  62. 62. This is all a bit confusing and difficult, right?” • Isn’t it just! – …but you haven’t seen anything yet!Twitter: @mbrit 62
  63. 63. Using the JavaScript track • This is the first place where we see “Windows Runtime components”… – These are a completely different beast to .NET components – You can’t just take a .NET assembly and reference it in a JavaScript project…  …but at least you can use .NET  Has real impact for business tier logicTwitter: @mbrit 63
  64. 64. Using the JavaScript track (2) • WinRT components restrictions… – All the classes need to be sealed  (JavaScript only) – Cannot expose out .NET types directly…  public List<string> Foo()  public IList<string>Foo() – Can’t use your own generics – Can’t do virtual methods – Can’t have members that vary by case  private string myString = private string MYSTRING – Can’t return Task/Task<T>  Use IAsyncOperation/IAsyncOperation<T>Twitter: @mbrit 64
  65. 65. DEMO: Using the JavaScript trackTwitter: @mbrit 65
  66. 66. Databases • For most platforms, this story is pretty good: – iOS – baked in SQLite, native driver or Core Data – Android – baked in SQLite, native driver – BlackBerry – baked in SQLite, native driver • Windows Phone and Metro-style? – *crickets* – SQLite supported by SQLite.org and “sqlite-net” OSS projectTwitter: @mbrit 66
  67. 67. Moving from .NET - Summary • ".NET Core" is a cut-down version of .NET – …slightly more cut-down than Silverlight • WinRT and .NET coexist via shared metadata and projections • My preference is the XAML UI track • Packages allow for straightforward extensions • Lots of changes and missing bits, lots of restrictions • Open source library support currently poor • SQLite support good, no other database support currentlyTwitter: @mbrit 67
  68. 68. Asynchronous ProgrammingTwitter: @mbrit 68
  69. 69. The UI thread • All threads are equal, but some threads are more equal than others – The UI thread is the most critical thread to protect – Metro-style is designed from the ground up to bias processor time to the UI thread  …but this is done at the application/API level, not at the operating system levelTwitter: @mbrit 69
  70. 70. 50ms rule • If it’s going to take more than 50ms to run on the UI thread, it has to be handed over to a background threadTwitter: @mbrit 70
  71. 71. Task Parallel Library • All of WinRT’s async stuff is based on the Task Parallel Library (TPL) – Introduced with .NET 4.0 – Used for scheduling parallel operations – Quite lovely  …plus ever-so much better than .NET’s previous effort – Used in the mind-meltingly bonkers “async/await” constructTwitter: @mbrit 71
  72. 72. Task Parallel Library (2) • Base currency is the Task – It’s just a unit of workTwitter: @mbrit 72
  73. 73. Task Parallel Library (3) • You can add continuation handlers to Task instances – (Which are callbacks, essentially) You’re more likely to see something like this, thoughTwitter: @mbrit 73
  74. 74. Task Parallel Library (3) • The final piece of magic is the Result… – Use Task<T> to indicate you want a resultTwitter: @mbrit 74
  75. 75. Standard JavaScript “async/callback” patternTwitter: @mbrit 75
  76. 76. “async” and “await” • Mind-bendingly brilliant… – Everything that’s happened to C# and .NET over the past decade has been converging on this capability – The basic idea is to park your currently executing code without you having to think about it – Have failed to draw a diagram of it!Twitter: @mbrit 76
  77. 77. Making a network call without “async/await”Twitter: @mbrit 77
  78. 78. Making a network call with “async/await”Twitter: @mbrit 78
  79. 79. Async API design • APIs generally don’t have both sync and async calls… – Async calls have to “do better” than the async method wrapped in a Task – Implement the one you want the caller to use – Don’t async unnecessarilyTwitter: @mbrit 79
  80. 80. Asynchronous programming - Summary • UI thread is more important than the others • If it takes more than 50ms to run, async it • Task Parallel Library basis of all parallel operations • "async/await" magical and wonderful, but slightly mind-meltingTwitter: @mbrit 80
  81. 81. Sandboxing and ProtectionTwitter: @mbrit 81
  82. 82. Capabilities • Much as you would expect – Declared in the manifest musicLibrary removeableStorage internetClient picturesLibrary microphone internetClientServer videosLibrary webcam privateNetworkClientServer location proximity documentsLibrary enterpriseAuthentication This one’s a bit strange… sharedUserCertificatesTwitter: @mbrit 82
  83. 83. File Picker • File Picker is the way you pick files in Metro- style… • Anything else is out-of-scope • HomeGroup – Ad hoc network of connected PCs – Available in Windows 7 – The “File Picker” regards HomeGroup as being “equal citizens” with the device you’re usingTwitter: @mbrit 83
  84. 84. “documentsLibrary” • Microsoft’s strong preference is that you use the “File Picker” – documentsLibary is the only way to provide programmatic access (as opposed to click and point) – Filtered to specific file types that you declare in the manifest – Cannot access files in the HomeGroup – local device onlyTwitter: @mbrit 84
  85. 85. A deeper look at the restrictions • Let’s take a deeper look into what we can and can’t do within our sandbox through the expedient of trying to work outside of our sandbox…Twitter: @mbrit 85
  86. 86. “System.Reflection.Emit” • Fantastic example of how seriously Microsoft are taking sandboxing… – Vector for all sorts of malware – Plenty of collateral damage – Specific protection within .NET Core for types of API Microsoft really don’t want you to useTwitter: @mbrit 86
  87. 87. An illustration with Moq • Moq uses CRE to create dynamic proxies – Uses the Castle Project Dynamic Proxy library – …which uses SRE, which is not allowed System. Moq Castle Core Runtime. Emit Emitted dynamic assemblyTwitter: @mbrit 87
  88. 88. Why Moq can’t run on Metro-style • Moq will port happily to WinRT, its Castle Core that won’t port… – Most of the Moq changes are an issue of shimming  …just like we discussed before… – …but eventually you find a big gap where Castle Core Dynamic Proxy needs System.Reflection.Emit – So what do we do about that?Twitter: @mbrit 88
  89. 89. “Cannot be used on the current platform” • Not caspol – more fundamental… System.InvalidOperationException: The API System.Reflection.Emit.TypeBuilder.DefineProperty(System.String, System.Reflection.Propert yAttributes, System.Reflection.CallingConventions, System.Type, System.Type[], System.Type[ ], System.Type[], System.Type[][], System.Type[][]) cannot be used on the current platform. See http://go.microsoft.com/fwlink/?LinkId=248273 for more information. Result StackTrace: at System.Delegate.CreateDelegateInternal(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags, StackCrawlMark& stackMark) at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure) at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method) at Castle.DynamicProxy.Generators.Emitters.PropertyEmitter..ctor(AbstractTypeEmitter parentTypeEmitter, String name, PropertyAttributes attributes, Type propertyType, Type[] arguments) at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CreateProperty(String name, PropertyAttributes attributes, Type propertyType, Type[] arguments) (etc.)Twitter: @mbrit 89
  90. 90. Just for fun…Twitter: @mbrit 90
  91. 91. Working round the sandboxing • What you can do is load a “.NET Core” assembly into a “.NET Full” process… – Whether the process is “full” or not depends on a private flag in the App Domain • So… – You can’t build the assembly on the fly, but you can use a normal “.NET Full” process to prepare stuff you need ahead of timeTwitter: @mbrit 91
  92. 92. Working around the sandboxing (2) • Therefore we can: – Create a version of Castle Core that uses a faked version of SRE – Compile our test library against a Metro-style version of Moq that that faked SRE interface – Load the test library into a normal “.NET Full” process and use Reflection to drive SRE, which is allowed – If we run the tests in , a dynamic assembly will be created, which we can save to disk for later use  I’m calling this “baking” – When we run the tests in Metro-style we can use the pre-built assembly containing the mocksTwitter: @mbrit 92
  93. 93. DEMO: Baked mocks using MoqRTTwitter: @mbrit 93
  94. 94. “I thought this was confusing and difficult before!” • We haven’t even done anything difficult yet!Twitter: @mbrit 94
  95. 95. Network access • Locked down – There’s a full sockets API implementation in Metro- style…  But you can’t establish a connection from a Metro-style app to a process on the local machine  Other machines on the network are OK  Access to the Internet is also OK  This arrangement kills cross-process comms outside of contracts and sharing o SQL Server?Twitter: @mbrit 95
  96. 96. Contracts and extensions • We’ll cover this later…Twitter: @mbrit 96
  97. 97. Local disk access • Obviously highly restrictedTwitter: @mbrit 97
  98. 98. Local disk access – Your special folders • These are just for you… Windows.Storage.ApplicationData.Current LocalFolder RoamingFolder TemporaryFolder Windows.ApplicationModel.Package.Current InstalledLocation Read-onlyTwitter: @mbrit 98
  99. 99. Local disk access – Your shared folders • These you share with others… Windows.Storage.DownloadsFolder Write-only Windows.Storage.KnownFolders DocumentsLibrary MusicLibrary PicturesLibrary VideosLibrary RemoveableDevices HomeGroup MediaServerDevices All require declared capabilities discussed earlierTwitter: @mbrit 99
  100. 100. Local disk access – File types • Have to declare the types of files that you work with in the manifestTwitter: @mbrit 100
  101. 101. Don’t depend on holes! • Any hole you do find will get pluggedTwitter: @mbrit 101
  102. 102. Sandboxing and Protection - Summary • Apps declare capabilities • Sandboxing restricts certain types of activities – …which has a knock-on to what you can support – …very deep, binary restriction • No local network access • Limited file and folder access • Have to declare the file types you work with • Dont depend on holes!Twitter: @mbrit 102
  103. 103. Unit testingTwitter: @mbrit 103
  104. 104. We all do unit testing, right? • Right??Twitter: @mbrit 104
  105. 105. Visual Studio test framework • Now in the Express editions • Pretty decent test framework… – Your only option in Metro-styleTwitter: @mbrit 105
  106. 106. The problem with testing Metro-style • The App Domain has to be configured as a Metro-style app… – Only VS does this at the moment – xUnit will almost certainly end up with first class support  …but not today – The Microsoft library is different between Metro- style and non-Metro-style  …shimming is requiredTwitter: @mbrit 106
  107. 107. Shimming test libraries • We saw shimming before, so this is dead easy…Twitter: @mbrit 107
  108. 108. Faking and mocking • We spoke about Moq (and the problems with it) before… – Microsoft are doing a “Fakes” framework  …but it’s Ultimate SKU only  Works at compile time – a little bit like bakingTwitter: @mbrit 108
  109. 109. Unit Testing - Summary • Integrated unit testing story in VS remains good • Now available in Express SKUs • Metro-style unit testing relies on a Metro-style app container • Cross-compiling unit tests requires shimming • Mocking (currently) impractical in Metro-styleTwitter: @mbrit 109
  110. 110. Contacts and ExtensionsTwitter: @mbrit 110
  111. 111. This is where life gets really easy • If you go with the fundamental use cases of Metro-style, life is fairly blissful…Twitter: @mbrit 111
  112. 112. Contracts • A way of “de-siloing” applications – Almost like how you would do DDE in 2012 Share contract App-to-App picking contract Search contract Cached file updater contract Settings contract “Play To” contractTwitter: @mbrit 112
  113. 113. Data that you can share • You can share… – Text – URI – Bitmap – HTML – RTF – “StorageItems” – i.e. filesTwitter: @mbrit 113
  114. 114. What sharing is not • It’s not directive inter-app/cross-process comms… – The usage pattern is one where both sides don’t know the other existsTwitter: @mbrit 114
  115. 115. Share targets • Simple steps… – Add a “Share Target” component to your app – Specify declaration in the manifest – Design the UI – DoneTwitter: @mbrit 115
  116. 116. DEMO: Share targetsTwitter: @mbrit 116
  117. 117. Share sources • More simple steps… – Register yourself with the DataTransferManager – Call ShowShareUI – Package your dataTwitter: @mbrit 117
  118. 118. Search contracts • More or less as before… – Add a “Search Target” – Build a page that shows the data matching the users requestTwitter: @mbrit 118
  119. 119. DEMO: Search contractsTwitter: @mbrit 119
  120. 120. Settings contracts • Slightly more complicated… – Sign-up for CommandRequested on SettingsPaneView – Register your command – Respond when chosenTwitter: @mbrit 120
  121. 121. Settings contracts (2) • Caution on this is to use a Popup window… – These go away automatically when the user clicks outside of the windowTwitter: @mbrit 121
  122. 122. “App-to-App” Picking contract • This is done with the File Picker control…Twitter: @mbrit 122
  123. 123. Cached file updater contract • Used for keeping local cache files in sync with network copies… – Docs call out SkyDrive as an example of this – Discussions imply this could be used for syncing (more later)Twitter: @mbrit 123
  124. 124. Extensions • These extend Windows features… Account picture provider File activation AutoPlay Game Explorer Background tasks Print task settings Camera settings Protocol activation Contact picker SSL/certificatesTwitter: @mbrit 124
  125. 125. File activation • Again, really easy… – Declare in manifest – Handle FileActivated eventTwitter: @mbrit 125
  126. 126. DEMO: File activationTwitter: @mbrit 126
  127. 127. Background tasks • We’ll take a look at this later…Twitter: @mbrit 127
  128. 128. Contracts and Extensions - Summary • Life here is mostly easy • Contracts let you share information – …Share Sources and Share Targets  DDE++ • Common metaphors – …via Search contracts, and Settings contracts • Extensions allow you to extend Windows featuresTwitter: @mbrit 128
  129. 129. NotificationsTwitter: @mbrit 129
  130. 130. Notifications • Unified notifications system… – Tiles – Badges – Toast – Consistent implementation between all threeTwitter: @mbrit 130
  131. 131. Local vs Network updates • Notification updates can either… – Go through a “local loopback” – Via Windows Push Notification Service (WNS)Twitter: @mbrit 131
  132. 132. Live tiles • Keyed into the notification system… – Allows you to change data on the home screen • Steps… – Ask the TileUpdateManager to give you some template XML – Populate the XML – Create a new TileNotification from the XML – Hand it back to tile TileUpdateManagerTwitter: @mbrit 132
  133. 133. Live tiles (2) There are *tons* of tile template formats…Twitter: @mbrit 133
  134. 134. Badges • Steps – as per tiles… – Ask the BadgeUpdateManager to give you some update XML – Populate the XML – Ask the BadgeUpdateManager to show your badgeTwitter: @mbrit 134
  135. 135. Badges (2)Twitter: @mbrit 135
  136. 136. Badge glyphs • Badges can… – Show a number from 1-99, or – Show a glyphTwitter: @mbrit 136
  137. 137. Toast • Steps – as per the others! – Ask the ToastUpdateManager to give you some update XML – Populate the XML – Ask the ToastUpdateManager to show it – Gotcha…  Need to set as “Toast capable” in the manifestTwitter: @mbrit 137
  138. 138. Toast (2)Twitter: @mbrit 138
  139. 139. Windows Push Notification Service - WNS • Register with WNS to broker requests Some Your App Your Server External Imperative Notification WNS Client Registration Process WindowsTwitter: @mbrit 139
  140. 140. Windows Push Notification Service - WNS • Signalling… Some Your App Your Server External Imperative Notification WNS Client Signalling Process WindowsTwitter: @mbrit 140
  141. 141. Notifications - Summary • Unified notification system for tiles, badges, and toast • Each have a set of templates to use • Manifest change required for toast • Windows Push Notification Server (WNS) for handling cloud updatesTwitter: @mbrit 141
  142. 142. Application LifetimeTwitter: @mbrit 142
  143. 143. Battery • “If it’s not running, it’s not using the battery” – …therein lies everything you need to know about application lifetime in Metro-styleTwitter: @mbrit 143
  144. 144. Micro-hibernation • Even on a mains powered desktop, apps that are in the background are spun to diskTwitter: @mbrit 144
  145. 145. Process lifetime events • As you would expect… Activated Suspending Running NotRunning Suspended Resuming You don’t get told about getting dumpedTwitter: @mbrit 145
  146. 146. Activation • This is the period of time during which you see the splashscreen… – You can be activated because someone clicked you directly… – …or if you’ve said you’ll provide some service…  i.e. a contract or extensionTwitter: @mbrit 146
  147. 147. Suspending • Do everything in five seconds or you’re killed • You could be suspended for days or weeksTwitter: @mbrit 147
  148. 148. Closing • Follows the iPad model… – There’s no close option in iPad apps – If you put a close option in, you won’t pass store certification • You can close an app programmatically… – …but Windows will assume that’s a “crash”Twitter: @mbrit 148
  149. 149. Crashing • The required path is that you just “forget about it”… – User returns to the Start screen – You’ll get information on the crash via your console on the storeTwitter: @mbrit 149
  150. 150. Removal • You don’t get toldTwitter: @mbrit 150
  151. 151. Apps that sync in the background • You probably can’t sell a sponsor on an app that requires “always on” internet… – Background tasks let you to this – Has to be light…  Docs specifically call out “SETI@home” as an example of something you shouldn’t doTwitter: @mbrit 151
  152. 152. Background tasks • Register a class along with one trigger and optional conditions… – Plus a manifest declaration Triggers Conditions/System trigger types InternetAvailable InternetNotAvailable ControlChannelTrigger LockScreenApplicationAdded LockScreenApplicationRemoved MaintenanceTrigger NetworkNotificationChannelReset OnlineIdConnectedStateChanged PushNotificationTrigger ServicingComplete SessionConnected SessionDisconnected SessionStart TimeTrigger SmsReceived TimeZoneChange SystemTrigger UserAway UserPresentTwitter: @mbrit 152
  153. 153. Background tasks (2) 15 minutes is the highest frequency that you can haveTwitter: @mbrit 153
  154. 154. Background tasks (3) • You don’t necessarily run inside your own application’s process… – PushNotificationTrigger and ControlChannelTrigger do… – The others do not • Resources are constrained/metered – Remember the battery!Twitter: @mbrit 154
  155. 155. Background tasks (4) • Some triggers are restricted to apps on the lock screen… – MaintenanceTrigger is not  …but only runs when on AC power – TimeTrigger is  …as is PushNotificationTrigger and ControlChannelTriggerTwitter: @mbrit 155
  156. 156. Background task progress reporting • You should report progress back to your app… – You’ll be given an IBackgroundTaskInstance to report status bar-type information – You can also receive cancellation notices via this interfaceTwitter: @mbrit 156
  157. 157. Using background tasks for background sync • Steps… – Keep track of changes to local state as you normally would – If the app is in the foreground…  Use TPL to schedule  Do time-critical stuff in situ – If the app is suspended/terminated…  Use a combination of TimeTrigger and SystemChangeTrigger to run every “n” minutes, plus when internet access resumes – Bonus points: Cached File Updater ContractTwitter: @mbrit 157
  158. 158. Using background tasks to sync… cheat mode • To get through the store, you’re not allowed to depend on third-party services… – But you could write a service that processes your SQLite database and syncs changesTwitter: @mbrit 158
  159. 159. Application Lifetime - Summary • “If its not running, its not using the battery” • Process states: NotRunning, Running, or Suspended • If you crash, just forget about it • Background tasks… – Look to schedule every 15 minutes, or on system events – Can run in their own process – Can be used to get close to an enterprise-style "database sync" patternTwitter: @mbrit 159
  160. 160. Packaging and DeploymentTwitter: @mbrit 160
  161. 161. Approaches • Different approach for retail and enterprise… – Retail follows the Apple App Store model – Enterprise follows…  A tools-centric approach for enterprise-owned devices  A “fiddly-yet-doable” approach for BYODTwitter: @mbrit 161
  162. 162. AppX • AppX is the new standard packaging format for Metro-style apps… Content – …Zip file, basically Manifest BlockMap Signature Stuff Allows for partial updates/deltas AppX PackageTwitter: @mbrit 162
  163. 163. Windows App Certification Kit • Aka “WACK”Twitter: @mbrit 163
  164. 164. Packaging API • There is an API for packaging… – Package apps – Deploy apps – Query packagesTwitter: @mbrit 164
  165. 165. Enterprise scenarios • Four scenarios to consider… – Windows 8 ESD (Enterprise Supplied Device) – Windows 8 BYOD – Windows RT ESD – Windows RT BYODTwitter: @mbrit 165
  166. 166. Enterprise Apps and the Store • Enterprises can deliver their applications through the store… – Clever model for handling licensing provided by Microsoft – …but an unlikely scenario for LOBTwitter: @mbrit 166
  167. 167. Sideloading • This is the process by which applications are loaded onto the device outside of the store – Enterprise deployment is all about enabling “sideloading”Twitter: @mbrit 167
  168. 168. Sideloading – Restrictions apply • Sideloading means you don’t have to pass the store requirements… – What’s impossible remains impossible  Still can’t SRE, sleep threads, work outside of sandbox, etc – Reminder: on Windows RT, there’s no sideloadingTwitter: @mbrit 168
  169. 169. Windows 8 ESD • It’s assumed in this scenario that the device is joined to the domain… – Possibly only works in Windows 8 Enterprise – This enables a group policy item – Sign the app – Optionally validate the app through the Store Certification Kit  (There are many reasons why you wouldn’t want to do this, however…) – Then deploy…Twitter: @mbrit 169
  170. 170. Windows 8 BYOD • Here, we assume a BYOD scenario is one where there is no domain membership – Change Registry to enable sideloading – Activate a “special product key”  Information on this is pending – Sign the app – Optionally validate the app – Then deploy…Twitter: @mbrit 170
  171. 171. Windows RT – ESD and BYOD • Picture remains unclear… – Was discussed at TechEd – This definitely needs to get through the WACK – Will almost certainly be some sort of centrally managed portalTwitter: @mbrit 171
  172. 172. Installing apps • Two methods… – Bake it into the image – Deploy using PowerShellTwitter: @mbrit 172
  173. 173. PowerShell installation • This is the advantage of having everything wrapped up into a single AppX file… – add-appxpackage fooserverappsmyapp.appx  (You can script dependencies too) – Script in the usual way!Twitter: @mbrit 173
  174. 174. Updating via PowerShell • The same add-appxpackage command will also run updates – …thus just deploy a new file, updates go out automaticallyTwitter: @mbrit 174
  175. 175. Removing apps • Again, having everything wrapped up nicely in packages helps here… – remove-appxpackageTwitter: @mbrit 175
  176. 176. Packaging and Deployment - Summary • Different models for retail and enterprise • Same packaging structure - AppX • Validate your apps using the Windows App Certification Kit • Sideloading possible to install your own apps – …but inherent Metro-style restrictions still apply • Most straightforward installation method is via PowerShellTwitter: @mbrit 176
  177. 177. Hire me • Like this presentation? – Private, onsite presentations of this workshop tailored to your project programme – In-depth Metro-style training (public or private courses) – Consultancy on your Metro-style development plans – http://mbrit.com/Twitter: @mbrit 177
  178. 178. Q&A Matthew Baxter-Reynolds Independent software development consultant, speaker, author and trainer http://mbrit.com/ @mbritLicenseThis presentation is licensed for use under the “Creative CommonsAttribution-ShareAlike 3.0 Unported” license:http://creativecommons.org/licenses/by-sa/3.0/IconsIdea icon: The Noun ProjectBeaker icon: The Noun ProjectFloppy disk icon: Mike Wirth, from The Noun ProjectAperture icon: P.J. Onori, from The Noun ProjectBarking dog icon: The Noun ProjectApprove icon: from The Noun ProjectTwitter: @mbrit 178

×