Commit e62d2702 authored by Sylvain Berfini's avatar Sylvain Berfini

Added own crash log collector

parent 02ee5e58
......@@ -255,6 +255,7 @@ namespace Linphone
// Code to execute if a navigation fails
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
BugCollector.LogException(e.Exception, "Navigation failed: " + e.Uri.ToString());
if (Debugger.IsAttached)
{
// A navigation has failed; break into the debugger
......@@ -265,6 +266,7 @@ namespace Linphone
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
BugCollector.LogException(e.ExceptionObject, "UnhandledException");
if (Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
......
......@@ -119,6 +119,7 @@
<Compile Include="Model\AlphaKeyGroup.cs" />
<Compile Include="Model\AssociationUriMapper.cs" />
<Compile Include="Model\BaseModel.cs" />
<Compile Include="Model\BugCollector.cs" />
<Compile Include="Model\CallControllerListener.cs" />
<Compile Include="Model\CallLog.cs" />
<Compile Include="Model\ContactManager.cs" />
......
using Microsoft.Phone.Tasks;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
namespace Linphone.Model
{
/// <summary>
/// Collects and reports uncatched exceptions
/// </summary>
public class BugCollector
{
const string exceptionsFileName = "exceptions.log";
internal static void LogException(Exception e, string extra)
{
try
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (TextWriter output = new StreamWriter(store.OpenFile(exceptionsFileName, FileMode.Append)))
{
output.WriteLine("-------------------------");
output.WriteLine("Type: {0}", extra);
output.WriteLine("Message: {0}", e.Message);
foreach (KeyValuePair<string, string> kvp in e.Data)
{
output.WriteLine("Data: Key= {0}, Value= {1}", kvp.Key, kvp.Value);
}
output.WriteLine("Stacktrace: {0}", e.StackTrace);
output.Flush();
output.Close();
}
}
}
catch (Exception) { }
}
internal static bool HasExceptionToReport()
{
try
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
return store.FileExists(exceptionsFileName);
}
}
catch (Exception) { }
return false;
}
internal static void ReportExceptions()
{
try
{
string body = "";
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (store.FileExists(exceptionsFileName))
{
using (TextReader input = new StreamReader(store.OpenFile(exceptionsFileName, FileMode.Open)))
{
body += input.ReadToEnd();
input.Close();
}
EmailComposeTask email = new EmailComposeTask();
email.To = "linphone-wphone@belledonne-communications.com";
email.Subject = "Exception report";
email.Body = body;
email.Show();
}
}
}
catch (Exception) { }
}
internal static void DeleteFile()
{
try
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
store.DeleteFile(exceptionsFileName);
}
}
catch (Exception) { }
}
}
}
......@@ -795,6 +795,34 @@ namespace Linphone.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Report.
/// </summary>
public static string ReportCrash {
get {
return ResourceManager.GetString("ReportCrash", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Crash detected.
/// </summary>
public static string ReportCrashDialogCaption {
get {
return ResourceManager.GetString("ReportCrashDialogCaption", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The application has detected a crash.
///Do you want to report it to the developpers ? It will help fix it faster..
/// </summary>
public static string ReportCrashDialogMessage {
get {
return ResourceManager.GetString("ReportCrashDialogMessage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Scale down sent pictures.
/// </summary>
......
......@@ -506,4 +506,14 @@ http://www.linphone.org/m/help
<data name="ResizeSetting" xml:space="preserve">
<value>Scale down sent pictures</value>
</data>
<data name="ReportCrash" xml:space="preserve">
<value>Report</value>
</data>
<data name="ReportCrashDialogCaption" xml:space="preserve">
<value>Crash detected</value>
</data>
<data name="ReportCrashDialogMessage" xml:space="preserve">
<value>The application has detected a crash.
Do you want to report it to the developpers ? It will help fix it faster.</value>
</data>
</root>
\ No newline at end of file
using Linphone.Controls;
using Linphone.Model;
using Linphone.Resources;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Threading.Tasks;
......@@ -36,11 +37,39 @@ namespace Linphone
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (BugCollector.HasExceptionToReport())
{
// Allow to report exceptions before the creation of the core in case the problem is in there
CustomMessageBox reportIssueDialog = new CustomMessageBox()
{
Caption = AppResources.ReportCrashDialogCaption,
Message = AppResources.ReportCrashDialogMessage,
LeftButtonContent = AppResources.ReportCrash,
RightButtonContent = AppResources.Close
};
reportIssueDialog.Dismissed += (s, ev) =>
{
switch (ev.Result)
{
case CustomMessageBoxResult.LeftButton:
BugCollector.ReportExceptions();
break;
case CustomMessageBoxResult.RightButton:
BugCollector.DeleteFile();
break;
}
};
reportIssueDialog.Show();
}
StatusBar = status;
BasePage.StatusBar.RefreshStatus(LinphoneManager.Instance.LastKnownState);
// Create LinphoneCore if not created yet, otherwise do nothing
Task t = LinphoneManager.Instance.InitLinphoneCore();
await LinphoneManager.Instance.InitLinphoneCore();
BuildLocalizedApplicationBar();
......@@ -50,8 +79,6 @@ namespace Linphone
String sipAddressToCall = NavigationContext.QueryString["sip"];
addressBox.Text = sipAddressToCall;
}
await t;
}
private void call_Click_1(object sender, EventArgs e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment