PowerToys/Wox.CrashReporter/ReportWindow.xaml.cs

75 lines
2.3 KiB
C#
Raw Normal View History

2015-01-11 21:52:30 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
2015-01-16 23:42:12 +08:00
using System.Threading;
2015-01-11 21:52:30 +08:00
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Wox.Core;
using Wox.Core.Exception;
2015-01-12 22:46:36 +08:00
using Wox.Core.i18n;
2015-01-11 21:52:30 +08:00
using Wox.Core.UI;
using Wox.Core.UserSettings;
using Wox.Core.Version;
using Wox.Infrastructure.Http;
namespace Wox.CrashReporter
{
2015-01-12 22:46:36 +08:00
internal partial class ReportWindow
2015-01-11 21:52:30 +08:00
{
private Exception exception;
public ReportWindow(Exception exception)
{
this.exception = exception;
InitializeComponent();
SetException(exception);
}
private void SetException(Exception exception)
{
tbSummary.AppendText(exception.Message);
tbVersion.Text = VersionManager.Instance.CurrentVersion.ToString();
tbDatetime.Text = DateTime.Now.ToString();
tbStackTrace.AppendText(exception.StackTrace);
tbSource.Text = exception.Source;
tbType.Text = exception.GetType().ToString();
}
private void btnSend_Click(object sender, RoutedEventArgs e)
{
2015-01-21 23:00:56 +08:00
string sendingMsg = InternationalizationManager.Instance.GetTranslation("reportWindow_sending");
2015-01-12 22:46:36 +08:00
tbSendReport.Content = sendingMsg;
2015-01-11 21:52:30 +08:00
btnSend.IsEnabled = false;
2015-01-16 23:42:12 +08:00
ThreadPool.QueueUserWorkItem(o => SendReport());
}
private void SendReport()
{
2015-01-11 21:52:30 +08:00
string error = string.Format("{{\"data\":{0}}}", ExceptionFormatter.FormatExcpetion(exception));
string response = HttpRequest.Post(APIServer.ErrorReportURL, error, HttpProxy.Instance);
2015-01-12 22:46:36 +08:00
if (response.ToLower() == "ok")
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("reportWindow_report_succeed"));
2015-01-12 22:46:36 +08:00
}
else
{
2015-01-21 23:00:56 +08:00
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("reportWindow_report_failed"));
2015-01-12 22:46:36 +08:00
}
2015-01-16 23:42:12 +08:00
Dispatcher.Invoke(new Action(Close));
2015-01-11 21:52:30 +08:00
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}