I’m sure by now you have seen our Diagnostics control that allows your end user to send crash reports anytime your Windows Phone app throws an exception. With this control, you would typically receive the crash report via email or send the report to a web service that the developer has setup somewhere. While this approach works, it still depends on the user having internet access or the developer setting up a web service manually. We thought of a better way to implement this functionality with less work for you, the developer. This is where CloudDiagnostics comes in. With CloudDiagnotics, you can receive crash reports directly into your cloud account via Telerik Everlive Cloud Services. Also, CoudDiagnostics is aware of internet connectivity and will send the crash report only when there’s an internet connection available.
Note: The source code for this project can be found here.
Before we can get started, make sure that you have the latest bits installed. The Q2 2013 SP1 release contains both our traditional components as well as our cloud components. Please note that in order to get the cloud templates, you will need to uninstall the official Q2 2013 release bits and then install the SP1 release.
After you have the bits installed, you will find a new templates as shown in Figure 1.
Figure 1: The new cloud template installed with RadControls for Windows Phone 8.
The “Telerik Cloud Powered Windows Phone App” template is where we are going to begin, so select it and give it a name and press OK.
After doing so, you will be presented with a Cloud Services Configuration dialog, where you will need to enter your Telerik username and password and accept the terms and conditions. From this screen you can either select an existing project or create a new one. Let’s create a new one as shown in Figure 2. This information will carry over to our Everlive account which we will take a look at shortly.
Figure 2: Creating a new project with our Cloud Controls.
From here, we can simply click “Create” then finish and our project will be loaded in Visual Studio.
As our project begins spinning up, our application has gone out to our Everlive service and created a “User and File management” tables as well as given our project an API key. This API key has been automatically added to our App.xaml.cs and will be called upon startup. It will also initialize our CloudProvider to be used by the app. We can investigate this by looking into the InitializeProvider method as shown below.
If we log into everlive.com, we will see our newly created project as shown in Figure 3.
Figure 3: Everlive showing our new project we just created.
The name and description carried over from Visual Studio as stated earlier and we are now ready to implement the CloudDiagnostics feature.
We will need to click on “Create a Content Type” and give it the name of EverliveDiagnosticsInfo with the following fields:
Our final structure for this content type will look like the following as shown in Figure 4.
Figure 4: The completed content type for the CloudDiagnostics control.
By default if the user is not logged in the data is not captured, to allow anonymous users to submit this data then we will need to give them the “Create” permission as shown in Figure 5 and 6.
You can set the permissions by clicking on the setting icon of the content type and selecting permissions.
Figure 5: Adding the proper permissions to the anonymous role.
Figure 6: Adding the create permission to the anonymous role.
This is all that is required for our Cloud Control to capture error messages anonymously. Let’s move back into Visual Studio 2012 and write some code.
Let’s begin by adding a property for RadCloudDiagnostics that we can call from anywhere inside our app and a method to initialize the control.
While we are here, we will also need to call the method at the end of the App constructor.
Our next step is to add our helper class to provide device/stack trace information once the application has crashed as shown below:
Also to reinitialize the helper if the app is coming out of a tombstoned state:
Switch over to the MainPage.xaml and add a button with a click event handler inside the ContentPanel.
Switch to the MainPage.xaml.cs and in the following code:
Once the button is clicked, we are adding an ExceptionOccured event handler as well as manually triggering an error. One the error has been thrown, we are displaying a MessageBox asking the user if they would like to see the error or not. Obviously, you can remove this code if you do not wish to prompt the user.
If you switch the app from Device to Emulator, you will get the following error message, “Deployment failed because an app with target platform ARM cannot be deployed to Emulator WVGA 512MB. If the target platform is win32/ x86, select an emulator. If the target platform is ARM, select Device.” This error occurs because the cloud controls are either built against x86 (for the emulator) or ARM (for deploying on devices) because of the local storage (offline support) implemented with SQLite. If you would like to test with the emulator, you will need to go to:
1. Build -> Configuration Manager.
2. There is a ComboBox in the upper right named 'Active solution platform' -> choose x86.
3. Click on 'Close' button of dialog.
Launch the application in the emulator or device (depending on your preference) and click on the button and it should have triggered an error message. Now, you can log back into everlive.com and click on the EverliveDiagnosticsInfo content type and see the exception as shown in Figure 7.
Figure 7: Content Type showing the Exception Information as well as additional info.
If you click on the Exception Message, then you will get a detailed log as shown below:
Created by: Backend
Modified by: Backend
Created at: Jul 15, 2013, 02:40 PM
Modified at: Jul 15, 2013, 02:40 PM
at CloudDiagnostics.MainPage.Button_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)]
[OccurrenceDate]:[Mon, 15 Jul 2013 19:40:17 GMT]
[AppInstallDate]:[Mon, 15 Jul 2013 19:37:49 GMT]
[AppPreviousRunDate]:[Mon, 15 Jul 2013 19:38:48 GMT]
[OSVersion]:[Microsoft Windows NT 8.0.9903.0]
In this example, I am using the built-in emulator. This should give you an idea of the amount of information captured with this powerful component.
We looked at a new cloud component today called CloudDiagnostics that allows a developer to receive anonymous crash reports directly to their Everlive account. As you can tell from the exception information listed above, it contains a lot of details that can help you track down the bug and give your users a great app experience! We’d love to hear any feedback on this control, so please leave them below.
The source code for this project can be found here.
Michael Crump (@mbcrump)
Michael Crump is a Microsoft MVP, Pluralsight and MSDN author as well as an international speaker. He works at Telerik with a focus on everything mobile. You can follow him on Twitter at @mbcrump or keep up with his various blogs by visiting his Telerik Blog or his Personal Blog.
Subscribe to be the first to get our expert-written articles and tutorials for developers!