Have you ever dreamed to build a solid and fast application for your Windows Phone 8? Come to this session and you will see how to leverage the power of your device and how to deliver outstanding robust application. You'll discover how to unit test your WP8 application and how to tune its performance.
2. Software contractor :
- C# Asp.net mvc, Wpf, Windows Phone..
- Python, Django
- WebDeBs Founder
@piccoloaiutante - OrangeCodeMichele Capra
Who i am
Tuesday, May 14, 13
3. Building High Performance and Reliable
Windows Phone 8 Apps
@piccoloaiutante - OrangeCodeMichele Capra
What are we going to see
Tuesday, May 14, 13
4. Building High Performance and Reliable
Windows Phone 8 Apps
@piccoloaiutante - OrangeCodeMichele Capra
What are we going to see
Tuesday, May 14, 13
5. Building High Performance and Reliable
Windows Phone 8 Apps
@piccoloaiutante - OrangeCodeMichele Capra
What are we going to see
Tuesday, May 14, 13
6. In general, reliability (systemic def.) is the
ability of a person or system to perform
and maintain its functions in routine
circumstances, as well as hostile or
unexpected circumstances.
Wikipedia
@piccoloaiutante - OrangeCodeMichele Capra
Reliability
Tuesday, May 14, 13
7. @piccoloaiutante - OrangeCodeMichele Capra
Reliability
In general, reliability (systemic def.) is the
ability of a person or system to perform
and maintain its functions in routine
circumstances, as well as hostile or
unexpected circumstances.
Wikipedia
Tuesday, May 14, 13
8. How can we achieve reliability?
• Test your app
@piccoloaiutante - OrangeCodeMichele Capra
Reliability
Tuesday, May 14, 13
9. Use automatic tests while you’re building your
app.
Manually test your app at the end, especially
when you’re integrating logic and UI.
@piccoloaiutante - OrangeCodeMichele Capra
Testing
Tuesday, May 14, 13
10. Use automatic tests while you’re building your
app.
Manually test your app at the end, especially
when you’re integrating logic and UI.
@piccoloaiutante - OrangeCodeMichele Capra
Testing
Tuesday, May 14, 13
11. Basic application:
- Query Spotify database
- Show result
@piccoloaiutante - OrangeCodeMichele Capra
Sample App
Tuesday, May 14, 13
16. We have to make a REST call to Spotify
API.
We are going to create a service (a class
called SongService) that could support our
ViewModel in this action.
@piccoloaiutante - OrangeCodeMichele Capra
Make a query to Spotify
Tuesday, May 14, 13
23. public class SongService : ISongService
{
string _baseUrl;
private RestClient _client;
public SongService()
{
_client = new RestClient();
_client.BaseUrl =
"http://ws.spotify.com/search/1/track.json?q=";
}
public Task<info> Query(string query)
{
var request = new RestRequest(query, Method.GET);
var response= await _client.ExecuteTaskAsync<info>(request);
return response.Data;
}
}
@piccoloaiutante - OrangeCodeMichele Capra
SongService
Tuesday, May 14, 13
24. public class SongService : ISongService
{
string _baseUrl;
private RestClient _client;
public SongService()
{
_client = new RestClient();
_client.BaseUrl =
"http://ws.spotify.com/search/1/track.json?q=";
}
public Task<info> Query(string query)
{
var request = new RestRequest(query, Method.GET);
var response= await _client.ExecuteTaskAsync<info>(request);
return response.Data;
}
}
@piccoloaiutante - OrangeCodeMichele Capra
SongService
Tuesday, May 14, 13
25. [TestClass]
public class SongServiceFixture
{
private SongService _service;
public SongServiceFixture()
{
_service = new SongService();
}
[TestMethod]
public async Task Query_Should_Return_Result_From_Spotify_Service()
{
var data = await _service.Query("Madonna");
Assert.IsTrue(data.tracks.Count!=0);
}
}
@piccoloaiutante - OrangeCodeMichele Capra
SongService Test
Tuesday, May 14, 13
26. [TestClass]
public class SongServiceFixture
{
private SongService _service;
public SongServiceFixture()
{
_service = new SongService();
}
[TestMethod]
public async Task Query_Should_Return_Result_From_Spotify_Service()
{
var data = await _service.Query("Madonna");
Assert.IsTrue(data.tracks.Count!=0);
}
}
@piccoloaiutante - OrangeCodeMichele Capra
SongService Test
Tuesday, May 14, 13
28. public class MainViewModel
{
private readonly ISongService _songService;
public string SearchedText { get; set; }
public IList<track> TrackList { get; set; }
public MainViewModel(ISongService songService)
{
_songService = songService;
TrackList= new List<track>();
}
public async Task Search()
{
TrackList = (await _songService.Query(SearchedText)).tracks;
}
}
@piccoloaiutante - OrangeCodeMichele Capra
ViewModel with service
Tuesday, May 14, 13
29. public class MainViewModel
{
private readonly ISongService _songService;
public string SearchedText { get; set; }
public IList<track> TrackList { get; set; }
public MainViewModel(ISongService songService)
{
_songService = songService;
TrackList= new List<track>();
}
public async Task Search()
{
TrackList = (await _songService.Query(SearchedText)).tracks;
}
}
@piccoloaiutante - OrangeCodeMichele Capra
ViewModel with service
Tuesday, May 14, 13
30. [TestMethod]
public void Search_Should_Get_Songs_From_Service()
{
var viewModel = new MainViewModel(
new SongSearchService());
viewModel.SearchedText = "Madonna";
await viewModel.Search();
Assert.IsNotNull(viewModel.TrackList);
Assert.IsTrue(viewModel.TrackList.Count >= 1);
}
@piccoloaiutante - OrangeCodeMichele Capra
Testing ViewModel with Service
Tuesday, May 14, 13
31. [TestMethod]
public void Search_Should_Get_Songs_From_Service()
{
var viewModel = new MainViewModel(
new SongSearchService());
viewModel.SearchedText = "Madonna";
await viewModel.Search();
Assert.IsNotNull(viewModel.TrackList);
Assert.IsTrue(viewModel.TrackList.Count >= 1);
}
@piccoloaiutante - OrangeCodeMichele Capra
Testing ViewModel with Service
Tuesday, May 14, 13
34. Building High Performance and Reliable
Windows Phone 8 Apps
@piccoloaiutante - OrangeCodeMichele Capra
What are we going to see
Tuesday, May 14, 13
35. This subject involves different part of your
application.
• App startup
• UI Thread
• Images
@piccoloaiutante - OrangeCodeMichele Capra
Performance
Tuesday, May 14, 13
36. This subject involves different part of your
application.
• App startup
• UI Thread
• Images
@piccoloaiutante - OrangeCodeMichele Capra
Performance
Tuesday, May 14, 13
38. @piccoloaiutante - OrangeCodeMichele Capra
Windows Phone 8 - Thread Architecture
UI
Thread
(touch,
XAML,
draw visual,
handler)
Compsition
Thread
( feed GPU,
texture,
handle
transform)
GPU
Your
App
Maintaining a lightweight UI
thread is the key to writing a
responsive app.
Tuesday, May 14, 13
39. UI thread: handles all input, which
includes touching, parsing and creating
objects from XAML, layout calculations,
data binding, drawing all visuals (at least
the first time they are drawn), rendering/
rastering, process per-frame callbacks and
executing other user code and event
handlers.
@piccoloaiutante - OrangeCodeMichele Capra
UI thread
Tuesday, May 14, 13
40. Composition/Render thread: feeds the
GPU with textures and handles transform
(scale, rotate, translate) animations and
plane projections.
@piccoloaiutante - OrangeCodeMichele Capra
Slice titile
Tuesday, May 14, 13
41. • Microsoft recommendation related to
performance issues http://bit.ly/10yuFRw
• Performance best practice http://bit.ly/
PiOzz9
@piccoloaiutante - OrangeCodeMichele Capra
General Bottleneck
Tuesday, May 14, 13
42. How users perceive your app performance:
• Startup time
• Responsiveness
@piccoloaiutante - OrangeCodeMichele Capra
Performance
Tuesday, May 14, 13
43. Visual Studio 2012 provides the Windows
Phone Application Analysis tool.
Main feature:
• App Monitoring
• Profiling
@piccoloaiutante - OrangeCodeMichele Capra
Performance tools
Tuesday, May 14, 13
44. App Monitoring: you can evaluate the most
important behaviors of your app that
contribute to a good user experience, such
as start time and responsiveness.
@piccoloaiutante - OrangeCodeMichele Capra
App monitoring
Tuesday, May 14, 13
45. Profiling: you can evaluate either
execution-related or memory-usage aspects
of your app.
@piccoloaiutante - OrangeCodeMichele Capra
Profiling
Tuesday, May 14, 13
53. Visual Studio 2012 update 2, Windows
Phone 8 SDK
Unit testing:
• MS Test
• Moq as mocking framework
Profiling:
• Windows Phone Application Analysis tool
@piccoloaiutante - OrangeCodeMichele Capra
Quick recap
Tuesday, May 14, 13