Example #1
0
        public static void WriteErrorReport(Exception e, string inputPath, string outputPath = null)
        {
            if (outputPath == null)
            {
                outputPath = Path.GetDirectoryName(inputPath);
            }

            string inputFileName = Path.GetFileNameWithoutExtension(inputPath);

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            var resultsFileName = Path.Combine(outputPath, "ErrorReport.txt");

            e.Data.Add("folder", outputPath);

            using (StreamWriter file = new StreamWriter(resultsFileName))
            {
                file.WriteLine(SystemInfo.CompleteSystemInfo()); //OS, OS Version, .Net Version, RAM, processor count, MSFileReader .dll versions X3
                file.Write("e: " + e);
                file.Write("e.Message: " + e.Message);
                file.Write("e.InnerException: " + e.InnerException);
                file.Write("e.Source: " + e.Source);
                file.Write("e.StackTrace: " + e.StackTrace);
                file.Write("e.TargetSite: " + e.TargetSite);
            }
        }
        private void EverythingRunnerExceptionHandler(Task obj)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.BeginInvoke(new Action(() => EverythingRunnerExceptionHandler(obj)));
            }
            else
            {
                Exception e = obj.Exception;
                while (e.InnerException != null)
                {
                    e = e.InnerException;
                }

                var message          = "Run failed, Exception: " + e.Message;
                var messageBoxResult = System.Windows.MessageBox.Show(message + "\n\nWould you like to report this crash?", "Runtime Error", MessageBoxButton.YesNo);

                Exception exception = e;
                //Find Output Folder
                string outputFolder = e.Data["folder"].ToString();
                string tomlText     = "";
                if (Directory.Exists(outputFolder))
                {
                    var tomls = Directory.GetFiles(outputFolder, "*.toml");
                    //will only be 1 toml per task
                    foreach (var tomlFile in tomls)
                    {
                        tomlText += "\n" + File.ReadAllText(tomlFile);
                    }

                    if (!tomls.Any())
                    {
                        tomlText = "TOML not found";
                    }
                }
                else
                {
                    tomlText = "Directory not found";
                }

                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    string body = exception.Message + "%0D%0A" + exception.Data +
                                  "%0D%0A" + exception.StackTrace +
                                  "%0D%0A" + exception.Source +
                                  "%0D%0A %0D%0A %0D%0A %0D%0A SYSTEM INFO: %0D%0A " +
                                  SystemInfo.CompleteSystemInfo() +
                                  "%0D%0A%0D%0A MetaMorpheus: version " + GlobalVariables.MetaMorpheusVersion
                                  + "%0D%0A %0D%0A %0D%0A %0D%0A TOML: %0D%0A " +
                                  tomlText;
                    body = body.Replace('&', ' ');
                    body = body.Replace("\n", "%0D%0A");
                    body = body.Replace("\r", "%0D%0A");
                    string mailto = string.Format("mailto:{0}?Subject=MetaMorpheus. Issue:&Body={1}", "*****@*****.**", body);
                    GlobalVariables.StartProcess(mailto);
                    Console.WriteLine(body);
                }
            }
        }