Commit 48b8b81e authored by Ghislain MARY's avatar Ghislain MARY

Use log collection upload for exception reports.

parent a26ff9b6
......@@ -183,7 +183,7 @@ namespace Linphone.Agents
/// <summary>
/// Callback for LinphoneCoreListener
/// </summary>
public void LogUploadProgressChanged(int progress)
public void LogUploadProgressIndication(int offset, int total)
{
}
#endregion
......
......@@ -1680,15 +1680,15 @@ void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *me
if (lMessage == nullptr) {
lMessage = (Linphone::Core::LinphoneChatMessage^)Linphone::Core::Utils::CreateLinphoneChatMessage(message);
}
listener->FileTransferProgressIndication(lMessage, (int)offset, total);
listener->FileTransferProgressIndication(lMessage, (int)offset, (int)total);
}
}
void log_collection_upload_progress_indication(LinphoneCore *lc, size_t progress) {
void log_collection_upload_progress_indication(LinphoneCore *lc, size_t offset, size_t total) {
Linphone::Core::LinphoneCoreListener^ listener = Linphone::Core::Globals::Instance->LinphoneCore->CoreListener;
if (listener != nullptr)
{
listener->LogUploadProgressChanged((int)progress);
listener->LogUploadProgressIndication((int)offset, (int)total);
}
}
......
......@@ -103,7 +103,7 @@ namespace Linphone
/// Callback method called when the progress of the current logs upload has changed.
/// </summary>
/// <param name="progress"></param>
void LogUploadProgressChanged(int progress);
void LogUploadProgressIndication(int offset, int total);
};
}
}
\ No newline at end of file
......@@ -18,7 +18,6 @@ namespace Linphone.Model
public class BugCollector
{
const string exceptionsFileName = "exceptions.log";
const string logFileName = "Linphone.log";
internal static void LogException(Exception e, string extra)
{
......@@ -28,7 +27,8 @@ namespace Linphone.Model
{
using (TextWriter output = new StreamWriter(store.OpenFile(exceptionsFileName, FileMode.Append)))
{
output.WriteLine("-------------------------");
DateTime now = DateTime.Now;
output.WriteLine("Date: {0:dddd, MMMM d, yyyy, HH:mm:ss}", now);
output.WriteLine("Type: {0}", extra);
output.WriteLine("Message: {0}", e.Message);
foreach (KeyValuePair<string, string> kvp in e.Data)
......@@ -36,23 +36,7 @@ namespace Linphone.Model
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 void LogMessage(string message)
{
try
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (TextWriter output = new StreamWriter(store.OpenFile(exceptionsFileName, FileMode.Append)))
{
output.WriteLine("Custom message: {0}", message);
output.WriteLine("-------------------------");
output.Flush();
output.Close();
}
......@@ -75,13 +59,14 @@ namespace Linphone.Model
return false;
}
internal static async void ReportExceptions()
internal static void ReportExceptions(string url)
{
try
{
string subject = "Logs report";
string body = "";
body += "Version of the app : " + XDocument.Load("WMAppManifest.xml").Root.Element("App").Attribute("Version").Value;
body += "--------------------";
body += "Version of the app: " + Linphone.Version.Number;
body += "\r\n--------------------\r\n";
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
......@@ -89,45 +74,25 @@ namespace Linphone.Model
{
using (TextReader input = new StreamReader(store.OpenFile(exceptionsFileName, FileMode.Open)))
{
subject = "Exception report";
body += input.ReadToEnd();
input.Close();
}
}
if (store.FileExists(logFileName))
{
body += "\r\n";
// Limit the amount of linphone logs
string logs = await ReadLogs();
body += logs.Length > 32000 ? logs.Substring(logs.Length - 32000) : logs;
}
}
if (url != "")
{
body += "\r\n" + url;
}
EmailComposeTask email = new EmailComposeTask();
email.To = "linphone-wphone@belledonne-communications.com";
email.Subject = "Exception report";
email.Subject = subject;
email.Body = body;
email.Show();
}
catch (Exception) { }
}
internal static async Task<string> ReadLogs()
{
ApplicationSettingsManager appSettings = new ApplicationSettingsManager();
appSettings.Load();
byte[] data;
StorageFolder folder = ApplicationData.Current.LocalFolder;
StorageFile file = await folder.GetFileAsync("linphone1.log");
using (Stream s = await file.OpenStreamForReadAsync())
{
data = new byte[s.Length];
await s.ReadAsync(data, 0, (int)s.Length);
}
return Encoding.UTF8.GetString(data, 0, data.Length);
}
internal static void DeleteFile()
{
try
......
......@@ -1132,7 +1132,7 @@ namespace Linphone.Model
{
if (state == LinphoneCoreLogCollectionUploadState.LinphoneCoreLogCollectionUploadStateDelivered)
{
SendEmail(info);
BugCollector.ReportExceptions(info);
}
else if (state == LinphoneCoreLogCollectionUploadState.LinphoneCoreLogCollectionUploadStateNotDelivered)
{
......@@ -1148,15 +1148,18 @@ namespace Linphone.Model
});
}
public delegate void LogUploadProgressIndicationEventHandler(int offset, int total);
public event LogUploadProgressIndicationEventHandler LogUploadProgressIndicationEH;
/// <summary>
/// Callback for LinphoneCoreListener
/// </summary>
public void LogUploadProgressChanged(int progress)
public void LogUploadProgressIndication(int offset, int total)
{
BaseModel.UIDispatcher.BeginInvoke(() =>
if (LogUploadProgressIndicationEH != null)
{
Logger.Msg(String.Format("[LinphoneManager] Logs upload progress is {0}", progress));
});
LogUploadProgressIndicationEH(offset, total);
}
}
#endregion
......@@ -1214,14 +1217,5 @@ namespace Linphone.Model
}
}
#endregion
private void SendEmail(string body)
{
EmailComposeTask email = new EmailComposeTask();
email.To = "linphone-wphone@belledonne-communications.com";
email.Subject = "Logs report";
email.Body = body;
email.Show();
}
}
}
......@@ -1591,6 +1591,15 @@ namespace Linphone.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Uploading logs....
/// </summary>
public static string UploadingLogs {
get {
return ResourceManager.GetString("UploadingLogs", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Vibrate on incoming message.
/// </summary>
......
......@@ -661,4 +661,7 @@ Do you want to report it to the developpers ? It will help fix it faster.</value
<data name="StatSentVideoSize" xml:space="preserve">
<value>Sent Video Size:</value>
</data>
<data name="UploadingLogs" xml:space="preserve">
<value>Uploading logs...</value>
</data>
</root>
\ No newline at end of file
......@@ -130,25 +130,31 @@
Checked="Debug_Checked" Unchecked="Debug_Unchecked">
</toolkit:ToggleSwitch>
<Button x:Name="SendLogs" Content="{Binding Path=LocalizedResources.SendLogsEmail, Source={StaticResource LocalizedStrings}}" Click="SendLogs_Click"/>
<Button x:Name="ResetLogs" Content="{Binding Path=LocalizedResources.ResetLogs, Source={StaticResource LocalizedStrings}}" Click="ResetLogs_Click"/>
<Border
x:Name="ProgressPopup"
Grid.Row="1"
Padding="5"
Visibility="Collapsed"
BorderThickness="10">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button x:Name="SendLogs" Grid.Row="0" Content="{Binding Path=LocalizedResources.SendLogsEmail, Source={StaticResource LocalizedStrings}}" Click="SendLogs_Click"/>
<Button x:Name="ResetLogs" Grid.Row="1" Content="{Binding Path=LocalizedResources.ResetLogs, Source={StaticResource LocalizedStrings}}" Click="ResetLogs_Click"/>
<StackPanel
x:Name="BugReportUploadPopup"
Grid.RowSpan="2"
Background="Black"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Visibility="Collapsed">
<ProgressBar
IsIndeterminate="True"
Width="300"/>
<TextBlock
Width="300"
TextAlignment="Center"
Text="{Binding LocalizedResources.Uploading, Source={StaticResource LocalizedStrings}}" />
x:Name="BugReportUploadProgressBar"
Grid.Row="0"
Margin="20,0"
IsIndeterminate="False"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
<TextBlock HorizontalAlignment="Center" Margin="20,0" Text="{Binding Path=LocalizedResources.UploadingLogs, Source={StaticResource LocalizedStrings}}" />
</StackPanel>
</Border>
</Grid>
</StackPanel>
</phone:PivotItem>
</phone:Pivot>
......
......@@ -110,8 +110,16 @@ namespace Linphone.Views
saveSettingsOnLeave = true;
// Create LinphoneCore if not created yet, otherwise do nothing
LinphoneManager.Instance.InitLinphoneCore();
}
ProgressPopup.Visibility = Visibility.Collapsed;
/// <summary>
/// Method called when the page is hidden.
/// </summary>
protected override void OnNavigatedFrom(NavigationEventArgs nee)
{
base.OnNavigatedFrom(nee);
LinphoneManager.Instance.LogUploadProgressIndicationEH -= LogUploadProgressIndication;
BugReportUploadPopup.Visibility = Visibility.Collapsed;
}
/// <summary>
......@@ -164,11 +172,23 @@ namespace Linphone.Views
appBarLinphoneValues.Click += linphone_Click_1;
}
private void LogUploadProgressIndication(int offset, int total)
{
BaseModel.UIDispatcher.BeginInvoke(() =>
{
BugReportUploadProgressBar.Maximum = total;
if (offset <= total)
{
BugReportUploadProgressBar.Value = offset;
}
});
}
private void SendLogs_Click(object sender, RoutedEventArgs e)
{
ProgressPopup.Visibility = Visibility.Visible;
SendLogs.IsEnabled = false;
saveSettingsOnLeave = false;
BugReportUploadPopup.Visibility = Visibility.Visible;
LinphoneManager.Instance.LogUploadProgressIndicationEH += LogUploadProgressIndication;
LinphoneManager.Instance.LinphoneCore.UploadLogCollection();
}
......
......@@ -246,8 +246,25 @@
</Button.Style>
</Button>
</Grid>
<Grid x:Name="BugReportUploadPopup"
Grid.Row="2" Margin="0,20,0,20" Visibility="Collapsed">
<StackPanel
Background="Black"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ProgressBar
x:Name="BugReportUploadProgressBar"
Grid.Row="0"
Margin="20,0"
IsIndeterminate="False"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
<TextBlock HorizontalAlignment="Center" Margin="20,0" Text="{Binding Path=LocalizedResources.UploadingLogs, Source={StaticResource LocalizedStrings}}" />
</StackPanel>
</Grid>
</Grid>
</Grid>
</linphone:BasePage>
\ No newline at end of file
......@@ -12,6 +12,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Navigation;
using System.Xml.Serialization;
using Windows.Storage;
......@@ -36,6 +37,18 @@ namespace Linphone
ContactManager contactManager = ContactManager.Instance; //Force creation and init of ContactManager
}
private void LogUploadProgressIndication(int offset, int total)
{
BaseModel.UIDispatcher.BeginInvoke(() =>
{
BugReportUploadProgressBar.Maximum = total;
if (offset <= total)
{
BugReportUploadProgressBar.Value = offset;
}
});
}
/// <summary>
/// Method called when the page is displayed.
/// Check if the uri contains a sip address, if yes, it starts a call to this address.
......@@ -62,7 +75,11 @@ namespace Linphone
switch (ev.Result)
{
case CustomMessageBoxResult.LeftButton:
BugCollector.ReportExceptions();
BugReportUploadProgressBar.Minimum = 0;
BugReportUploadProgressBar.Maximum = 100;
BugReportUploadPopup.Visibility = Visibility.Visible;
LinphoneManager.Instance.LogUploadProgressIndicationEH += LogUploadProgressIndication;
LinphoneManager.Instance.LinphoneCore.UploadLogCollection();
break;
}
BugCollector.DeleteFile();
......@@ -70,6 +87,10 @@ namespace Linphone
reportIssueDialog.Show();
}
else
{
BugReportUploadPopup.Visibility = Visibility.Collapsed;
}
}
StatusBar = status;
......@@ -96,6 +117,16 @@ namespace Linphone
}
}
/// <summary>
/// Method called when the page is hidden.
/// </summary>
protected override void OnNavigatedFrom(NavigationEventArgs nee)
{
base.OnNavigatedFrom(nee);
LinphoneManager.Instance.LogUploadProgressIndicationEH -= LogUploadProgressIndication;
BugReportUploadPopup.Visibility = Visibility.Collapsed;
}
private void call_Click_1(object sender, EventArgs e)
{
if (addressBox.Text.Length > 0)
......
linphone @ 82bec934
Subproject commit 593454ce53d0befec206a5556555201eca5b58bd
Subproject commit 82bec9343bc1c98a7a39557b3d7b00fc3792690b
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