Strategic Mine Planning Strategic Mine Planning Flexible mine ...
What does it take to make Mine for Facebook: learn and apply to your next Windows Store app
-
Upload
microsoft-developer-network-msdn-belgium-and-luxembourg -
Category
Technology
-
view
522 -
download
1
description
Transcript of What does it take to make Mine for Facebook: learn and apply to your next Windows Store app
MINE for Facebook - a case studyKevin Dockx, @KevinDockx, RealDolmen
What are we talking about?
A little story…
Five essentials, and how to achieve them
Agenda
A LITTLE STORY…
THE FACEBOOK API
… voted “Worst API of 2011” in developer survey
“buggy”
“unreliable”
“lack of documentation”
“slow response times”
“neverending API changes”
Five essentials, and how to achieve themFOCUS.LOOKS.RELIABILITY.PERFORMANCE.STATISTICS & LOGS.
FOCUS
LOOKS
Start hub
Story feed
Single story
RELIABILITY
Architecture
MINE.FacebookSDKBroker
MINE.Framework
MINE.Framework.WinRTComponent
MINE.FacebookClient
MINE.FacebookClient.BackgroundTask
MINE.FacebookClient.Common
What’s used inside those components?MVVM => MVVM Light
Data format & parsing => JSON .NET
Connecting to Facebook => Facebook C# SDK
Architecture & components
MINE.FacebookSDKBroker
MINE.Framework
MINE.Framework.WinRTComponent
MINE.FacebookClient
MINE.FacebookClient.BackgroundTask
MINE.FacebookClient.Common
MVVM Light, JSON .NET, FB SDK
JSON .NET, FB SDK
JSON .NET
Advantages of this architectureProven components, backed by community
Reuse in & outside of current project, WinRT component or otherwise
Takes a bit of time initially, but saves tremendous amounts of time after a while
One more tip: assume failure
Failunless
(condition A)
or(condition
B)
if (condition Z) Fail
else if (condition A)
do Aelse …
PERFORMANCE
Cancellation of tasksProblem: tasks run when I don’t need them anymore.
Solution: support Cancellation- Built-in- What about your own methods?
– Accept a Cancellation Token in your method signature– Check for cancellation in that method– Handle OperationCancelledException
Produce, Consume, Consume, ProduceProblem: different parts of code need access to objects from different threads
Solution: Producer/Consumer pattern- BlockingCollection<T>- TryAdd to add to collection- TryTake to take from collection- CompleteAdding to notify end of adding
•
Performance – the usual suspects- Offload long-running tasks to the background- Cancel Tasks when they’re no longer needed- Use async/await, Task.WhenAny, Task.WhenAll- Use an extended splash screen- Prefetch when possible- Show progress, determinate or indeterminate
- Profile your app using the performance profiler
Performance - the illusion of performance
Perception beats reality. Always.
Performance case: the story feed- “Show me the next 20 items”
- Easy, right? Fetch items, translate them, return them, add to bound collection
- What was done?- Prefetch with producer/consumer- On scroll, items often are in backing collection => immediate return- Consumer asks for items one by one instead of 20 at the same time- Results in perception of faster performance
Performance: reduce memory consumption- Well, hello captain obvious. Obvious? Yes, but for an additional reason
- The less memory your app uses, the more likely it is to stay in memory instead of being terminated, ensuring a faster restart after being suspended
XAML PerformanceDo not load resources that aren’t necessary• Resource Dictionaries are fully parsed, even though your page might
only use one resource of it• Your start page shouldn’t use application-wide dictionaries• If you use a resource throughout your app, put it in Application (through
a resource dictionary)• If you don’t, only reference that dictionary on the pages it is used, or
even in the page-specific resource dictionary
XAML PerformanceOptimize element count• Don’t write this:
<Grid> <Rectangle Fill="Black"/>
</Grid>
• But write this:
<Grid Background=“Black” />
XAML PerformanceReuse brushesDon’t write this:
<TextBox> <TextBox.Foreground> <SolidColorBrush Color="#FF3F42CC"/>
</TextBox.Foreground> </TextBox> <Button Content="Submit"><Button.Foreground>
<SolidColorBrush Color="#FF3F42CC"/> </Button.Foreground> </Button>
Write this:<TextBox Foreground="{StaticResource TextColor}" />
<Button Content="Submit" Foreground="{StaticResource TextColor}" />
XAML PerformanceMinimize redrawing to the same place on the screenDon’t write this
<Grid Background="Black"> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> <Rectangle Grid.Row="1" Fill="White" Opacity=".5"/> </Grid>
XAML PerformanceBut write this:
<Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Rectangle Grid.Row="1" Fill="Black"/> <Rectangle Grid.Row="1" Fill="#FF7F7F7F"/></Grid>
There’s more: http://msdn.microsoft.com/en-us/library/windows/apps/hh994641.aspx
STATISTICS & LOGS
Marked Up- User statistics
- Sessions, users, app installations, …
- Crashes, errors & diagnostics- Custom logging, exceptions, crashes, including full stacktraces
- Usage statistics- Time spent in the application, page views, custom events, …
- Commerce statistics
Marked Up – how?- Init
MarkedUp.AnalyticClient.Initialize(“key");
- Catch navigation
MarkedUp.AnalyticClient.RegisterNavigationFrame(rootFrame);
- Log excepMarkedUp.AnalyticClient.LogLastChanceException(e);tions
SummaryFOCUS.
LOOKS.
RELIABILITY.
PERFORMANCE.
STATISTICS & LOGS.
Build apps on Windows. Discover your new home.
http://msdn.be/apps
THANK YOU