Just today I’ve published one of my first Windows Phone application Bugemos as Open Source on GitHub.
The app, that I created and published to Windows Phone Store back in late 2011, is just a simple RSS reader displaying latest comic strips from the web http://www.bugemos.com. The reason I’m publishing it as Open Source is that I think it might give a helpful insight to starting WP developers and to the community as well. Note the published source code is not the exact one, that was used in the currently published app. The app was updated from WP7.5 to WP8 and also instead of original AsyncCTP it now uses current Microsoft.Bcl.Async NuGet package.
So let’s see, how is the application designed and what it does.
First of all, the repository contains the Bugemos app and a secondary UtilityBelt library with some tools I’ve created and used back then across my projects. So what’s inside the UtilityBelt library that you should definitely check?
UtilityBelt.Serializer – back in 2011 I had no idea about the Json format and I used XML for any input and output data in my apps. This worked quite ok, but since I started using Json.NET, I no longer needed this.
UtilityBelt.ExcHelper – simple class for sending crash logs by email in case the app crashes. This class was called in the App.UnhandledException event handler, where it saved the Exception + callstack into IsolatedStorageSettings. Then the next time the app was started, it showed MessageBox to user, whether he wanted to send me an email with this crash log and maybe describe me, what happened. This method worked well, but right now I prefer to use in my apps continuous logging of events and commands and sending full log on my crash logging web server, after user agrees to it.
UtilityBelt.HackTest – this is nice tool for detecting, whether your app was pirated – whether the XAP file was modified and sideloaded on the phone. It detects the presence of WMAppPRHeader.xml file, that is only present in apps from store and cannot be part of sideloaded apps. Although I really haven’t used this detection in any of my apps for actualy limiting app behavior, it was useful to know, that there is a way how to do it. Note since circa 2012 the Windows Phone Store started sending only encrypted packages and this sideload detection is now no longer necessary.
UtilityBelt.Setting – one of most useful classes that I still use in my apps nowadays – wrapper for simple accessing the IsolatedStorageSettings object. Note the version I published is quite old, I’ve already added couple of improvements to it – first the access to IsolatedStorageSettings is now atomic so only one thread can read or write to it at a time. Also I’m now serializing all data into Json string, because the IsolatedStorageSettings has one not widely known problem: you can save complex types into it as well, not just simple value types. The problem is, when you update your app and the object you’ve serialized before now has different name or the assembly has changed its strong name. In this case the deserialization of previously stored data fails and you basically lost your persisted data! This actually happened in one of my apps on production where I done some refactoring and cleanup and after publishing update to my app, users were reporting, that stored data are lost. The solution to serialize every object to Json first solved this problem.
UtilityBelt.AppHelper – this one class contains various useful methods like IsBlackTheme for detecting, whether the black theme is currently active or not. This property was useful in some apps where I needed to show different icon based on the current app theme. The class also contains AppID property, that returns in apps published to Store the actual unique App ID, that can be used for sharing full app link using email/twitter/facebook. Lastly this class also contains lot of common methods like Rate, SendSMS, SendEmail, ShowWeb, ShowAppMarketplace, ShowAuthorMarketplace that I used on About pages.
Now let’s focus on the main project, my app Bugemos, what it uses and how it’s implemented.
The app uses simple design: MainPage that links to ImagePage and AboutPage. As a ViewModel I used StripModel class that referenced collection of Strips. It’s good to mention that back in 2011 I wasn’t using any MVVM toolkit so the model structure is not ideal. Currently I use for all of my apps MVVM Light Portable toolkit and it just works as I expect.
For downloading comic strips I used the class StripDownloader. This class uses not so widely known library System.ServiceModel.Syndication from Microsoft, that encapsulates logic for parsing RSS feeds. It’s really useful, if you plan to create any RSS reader app.
What’s interesting about the app, that back in 2011 it already used the Async CTP for asynchronously downloading RSS feed data. This Async CTP for Visual Studio 2010 later evolved into Async Targeting Pack for Visual Studio 2012, which finally evolved into extremely useful Microsoft.Bcl.Async NuGet library, that adds support for async/await C# feature into few other frameworks as well, namely into Windows Phone 7.5, Silverlight 5 and .NET 4.0.
Another library I’ve used in this app is Windows Phone Toolkit -> GestureListener. This listener was used for capturing touch gestures for resizing images and moving them around. Here I ran into another problem. Originally this GestureListener was based on XNA touch events under Windows Phone 7.5 and it was working just fine. Once Windows Phone 8 was released, this implementation in WPtoolkit based on XNA events was changed to use native WP8 touch events and since then the GestureListener is not working in landscape mode properly. That’s also the reason I still use in the app older WPtoolkit version and not the current one.
Last notable class in this app is the ImageSrc converter, that is receiving on input Uri of image, and it transparently downloads it on background into isolated storage and returns BitmapImage as the result. It solves really common problem in Windows Phone apps – caching of images on background. Note this implementation located in Converter is not ideal, it’s downloading images on UI thread and it can block the app on slow network connection.
The conclusion: when I was developing the Bugemos app back in 2011 I discovered lot of useful APIs in the process. Most of these APIs are still useful and valid today and I hope you find this article useful as well. If you have any comments and question about the source code, just let me know under this article or on my twitter, thanks!