Exemple #1
0
        private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            #if DEBUG
            System.Diagnostics.Debugger.Break();
            #endif

            var path = System.IO.Path.Combine(new[] { Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "ArmAUiEditorCrash.txt" });
            using (var writer = new XmlTextWriter(new System.IO.StreamWriter(path)))
            {
                writer.Formatting = Formatting.Indented;

                writer.WriteStartDocument();
                writer.WriteStartElement("root");
                #region <version>
                writer.WriteStartElement("version");
                writer.WriteString(Code.UpdateManager.Instance.AppVersion.ToString());
                writer.WriteEndElement();

                #endregion
                #region <report>
                writer.WriteStartElement("report");
            #if !DEBUG
                ArmA_UI_Editor.UI.CrashReportWindow repWin = new UI.CrashReportWindow();
                var res = repWin.ShowDialog();
                if (res.HasValue && res.Value)
                {
                    writer.WriteCData(repWin.ReportText);
                }
            #endif
                writer.WriteEndElement();
                #endregion
                #region <stacktrace>
                writer.WriteStartElement("stacktrace");
                var builder = new StringBuilder();
                var ex = e.Exception;
                int tabCount = 0;
                while (ex != null)
                {
                    builder.AppendLine(ex.Message);
                    builder.AppendLine(ex.StackTrace.Replace("\r", new string('\t', tabCount) + '\n'));
                    ex = ex.InnerException;
                    tabCount++;
                }
                writer.WriteCData(builder.ToString());
                writer.WriteEndElement();
                #endregion
                #region <trace>
                writer.WriteStartElement("trace");
                foreach (var it in this.TraceListenerInstance.StringQueue)
                {
                    writer.WriteStartElement("log");
                    writer.WriteString(it.Replace("\r", ""));
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                #endregion

                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Flush();
            }
            #if DEBUG
            System.Diagnostics.Process.Start(path);
            #else
            if (Settings.Instance.AutoReportCrash)
            {
                using (var file = System.IO.File.OpenRead(path))
                {
                    using (HttpClient client = new HttpClient())
                    {
                        var content = new FormUrlEncodedContent(new[]
                        {
                            new KeyValuePair<string, string>("content", new System.IO.StreamReader(file).ReadToEnd())
                        });
                        var response = client.PostAsync("http://x39.io/api.php?action=report&project=ArmA-UI-Editor", content).Result;
                    }
                }
                MessageBox.Show(string.Format("An unhandled exception was found ...\nThe crash-log got reported (can be changed at Settings -> Options)\nThe issue will be fixed ASAP :)\n\nSorry for your lost work (in case you did not saved) ...\nData Transfered can be reviewed at '{0}'", path), "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                MessageBox.Show(string.Format("An unhandled exception was found ...\nPlease report the crash at https://github.com/X39/ArmA-UI-Editor/issues/new\nThe issue will be fixed ASAP :)\nA CrashLog got created at '{0}'\n\nSorry for your lost work (in case you did not saved) ...", path), "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            #endif
            App.Current.Shutdown();
            e.Handled = true;
        }
        private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
#if DEBUG
            System.Diagnostics.Debugger.Break();
#endif

            var path = System.IO.Path.Combine(new[] { Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "ArmAUiEditorCrash.txt" });
            using (var writer = new XmlTextWriter(new System.IO.StreamWriter(path)))
            {
                writer.Formatting = Formatting.Indented;

                writer.WriteStartDocument();
                writer.WriteStartElement("root");
                #region <version>
                writer.WriteStartElement("version");
                writer.WriteString(Code.UpdateManager.Instance.AppVersion.ToString());
                writer.WriteEndElement();

                #endregion
                #region <report>
                writer.WriteStartElement("report");
#if !DEBUG
                ArmA_UI_Editor.UI.CrashReportWindow repWin = new UI.CrashReportWindow();
                var res = repWin.ShowDialog();
                if (res.HasValue && res.Value)
                {
                    writer.WriteCData(repWin.ReportText);
                }
#endif
                writer.WriteEndElement();
                #endregion
                #region <stacktrace>
                writer.WriteStartElement("stacktrace");
                var builder  = new StringBuilder();
                var ex       = e.Exception;
                int tabCount = 0;
                while (ex != null)
                {
                    builder.AppendLine(ex.Message);
                    builder.AppendLine(ex.StackTrace.Replace("\r", new string('\t', tabCount) + '\n'));
                    ex = ex.InnerException;
                    tabCount++;
                }
                writer.WriteCData(builder.ToString());
                writer.WriteEndElement();
                #endregion
                #region <trace>
                writer.WriteStartElement("trace");
                foreach (var it in this.TraceListenerInstance.StringQueue)
                {
                    writer.WriteStartElement("log");
                    writer.WriteString(it.Replace("\r", ""));
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                #endregion

                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Flush();
            }
#if DEBUG
            System.Diagnostics.Process.Start(path);
#else
            if (Settings.Instance.AutoReportCrash)
            {
                using (var file = System.IO.File.OpenRead(path))
                {
                    using (HttpClient client = new HttpClient())
                    {
                        var content = new FormUrlEncodedContent(new[]
                        {
                            new KeyValuePair <string, string>("content", new System.IO.StreamReader(file).ReadToEnd())
                        });
                        var response = client.PostAsync("http://x39.io/api.php?action=report&project=ArmA-UI-Editor", content).Result;
                    }
                }
                MessageBox.Show(string.Format("An unhandled exception was found ...\nThe crash-log got reported (can be changed at Settings -> Options)\nThe issue will be fixed ASAP :)\n\nSorry for your lost work (in case you did not saved) ...\nData Transfered can be reviewed at '{0}'", path), "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                MessageBox.Show(string.Format("An unhandled exception was found ...\nPlease report the crash at https://github.com/X39/ArmA-UI-Editor/issues/new\nThe issue will be fixed ASAP :)\nA CrashLog got created at '{0}'\n\nSorry for your lost work (in case you did not saved) ...", path), "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
#endif
            App.Current.Shutdown();
            e.Handled = true;
        }