public UIDialogResult DisplayBugReportUI(Report report)
 {
     using (var ui = new Full())
     {
         return ui.ShowDialog(report);
     }
 }
示例#2
0
 public StorageElement(string name, Report report, Stream stream, IStorageBackend backend)
 {
     Name = name;
     Report = report;
     Stream = stream;
     _backend = backend;
 }
示例#3
0
文件: Full.cs 项目: mgnslndh/NCrash
        internal UIDialogResult ShowDialog(Report report)
        {
            Text = string.Format(Messages.Full_Window_Title, report.GeneralInfo.HostApplication);

            // Fill in the 'General' tab
            warningPictureBox.Image = SystemIcons.Warning.ToBitmap();
            exceptionTextBox.Text = report.Exception.Type;
            exceptionMessageTextBox.Text = report.Exception.Message;
            targetSiteTextBox.Text = report.Exception.TargetSite;
            applicationTextBox.Text = report.GeneralInfo.HostApplication + " [" + report.GeneralInfo.HostApplicationVersion + "]";
            ncrashTextBox.Text = report.GeneralInfo.NCrashVersion;
            dateTimeTextBox.Text = report.GeneralInfo.DateTime;
            clrTextBox.Text = report.GeneralInfo.ClrVersion;

            // Fill in the 'Exception' tab
            exceptionDetails.Initialize(report.Exception);

            // ToDo: Fill in the 'Report Contents' tab);

            ShowDialog();

            // Write back the user description (as we passed 'report' as a reference since it is a refence object anyway)
            report.GeneralInfo.UserDescription = descriptionTextBox.Text;
            return _uiDialogResult;
        }
示例#4
0
文件: Normal.cs 项目: mgnslndh/NCrash
        internal UIDialogResult ShowDialog(Report report)
        {
            Text = string.Format(Messages.Normal_Window_Title, report.GeneralInfo.HostApplication);
            exceptionMessageLabel.Text = report.GeneralInfo.ExceptionMessage;

            ShowDialog();

            return _uiDialogResult;
        }
示例#5
0
 public bool Send(Stream data, string fileName, Report report)
 {
     using (filew = new FileStream(fileName, FileMode.Create))
     {
         output = new byte[data.Length];
         data.Read(output, 0, output.Length);
         filew.Write(output, 0, output.Length);
         filew.Close();
     }
     return true;
 }
        public UIDialogResult DisplayBugReportUI(Report report)
        {
            var result = MessageBox.Show(
                new Form { TopMost = true },
                Messages.MinimalWinFormsUserInterface_Message_Text,
                string.Format(Messages.MinimalWinFormsUserInterface_Message_Title, report.GeneralInfo.HostApplication),
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning);

            return new UIDialogResult(result == DialogResult.Yes ? ExecutionFlow.ContinueExecution : ExecutionFlow.BreakExecution, SendReport);
        }
示例#7
0
        public bool Send(Stream data, string fileName, Report report)
        {
            data.Position = 0;
            var files = new[]
                {
                    new UploadFile {Name = "file", Filename = "test.zip", Stream = data}
                };
            var response = UploadFiles(_url, files, new NameValueCollection());
            // TODO: parse response
            Logger.Info("Response from HTTP server: " + Encoding.ASCII.GetString(response));
            data.Position = 0;

            return true;
        }
示例#8
0
        public UIDialogResult DisplayBugReportUI(Report report)
        {
            using (var dialog = new TaskDialog())
            {
                dialog.WindowTitle = string.Format(Messages.Normal_Window_Title, report.GeneralInfo.HostApplication);
                dialog.Content = Messages.Normal_Window_Message;
                dialog.CustomMainIcon = SystemIcons.Warning;

                var continueButton = new TaskDialogButton("Continue");
                var quitButton = new TaskDialogButton("Quit");
                dialog.Buttons.Add(continueButton);
                dialog.Buttons.Add(quitButton);

                TaskDialogButton button = dialog.ShowDialog();
                //if (button == continueButton)
                return new UIDialogResult(button == continueButton ? ExecutionFlow.ContinueExecution : ExecutionFlow.BreakExecution, SendReport);
            }
        }
示例#9
0
        /// <summary>
        /// Write report to storage
        /// </summary>
        /// <param name="report"></param>
        public void Write(Report report)
        {
            try
            {
                using (Stream reportStream = _settings.StorageBackend.CreateReportFile())
                {
                    using (var zipStorer = ZipStorer.Create(reportStream, string.Empty))
                    {
                        // write exception
                        WriteException(zipStorer, report.Exception);

                        // write report
                        WriteReport(zipStorer, report);

                        // Add the memory minidump to the report file (only if configured so)
                        var minidumpFilePath =
                            Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                                            "Exception_MiniDump_" + DateTime.UtcNow.ToFileTime() + ".mdmp");
                        if (DumpWriter.Write(minidumpFilePath, _settings.MiniDumpType))
                        {
                            zipStorer.AddFile(ZipStorer.Compression.Deflate, minidumpFilePath, StoredItemFile.MiniDump,
                                                string.Empty);
                            File.Delete(minidumpFilePath);
                        }

                        // Add any user supplied files in the report (if any)
                        if (_settings.AdditionalReportFiles != null && _settings.AdditionalReportFiles.Count > 0)
                        {
                            AddAdditionalFiles(zipStorer);
                        }
                    }

                    Logger.Trace("Created a new report file. Currently the number of report files queued to be send is: " +
                                    _settings.StorageBackend.GetReportCount());
                }
            }
            catch (TooManyReportsException ex)
            {
                Logger.Trace("Current report count is at its limit as per 'Settings.MaxQueuedReports (" +
                                ex.MaxQueuedReports + ")' setting: Skipping bug report generation.");
            }
        }
示例#10
0
 public UIDialogResult DisplayBugReportUI(Report report)
 {
     return new UIDialogResult(Flow, SendReport);
 }
示例#11
0
 private void WriteReport(Report report, StringBuilder sb)
 {
     var serializer = report.CustomInfo != null
                      ? new XmlSerializer(typeof(Report), new[] { report.CustomInfo.GetType() })
                      : new XmlSerializer(typeof(Report));
     TextWriter writer = new StringWriter(sb);
     serializer.Serialize(writer, report);
 }
示例#12
0
        public bool Send(Stream data, string fileName, Report report)
        {
            Logger.Trace("Submitting bug report via email.");
            if (data == null)
            {
                return false;
            }

            if (string.IsNullOrEmpty(From) || string.IsNullOrEmpty(To))
            {
                Logger.Warn("Empty mail 'From' or 'To' field");
                return false;
            }

            if (string.IsNullOrEmpty(ReplyTo))
            {
                ReplyTo = From;
            }

            if (Port == int.MinValue)
            {
                Port = UseSsl ? 465 : 25;
            }

            // Make sure that we can use authentication even with emtpy username and password
            if (!string.IsNullOrEmpty(Username))
            {
                UseAuthentication = true;
            }

            using (var smtpClient = new SmtpClient())
            using (var message = new MailMessage())
            {
                if (!string.IsNullOrEmpty(SmtpServer))
                {
                    smtpClient.Host = SmtpServer;
                }

                if (UseAuthentication)
                {
                    smtpClient.Credentials = new NetworkCredential(Username, Password);
                }

                if (UseSsl)
                {
                    smtpClient.EnableSsl = true;
                }

                if (!string.IsNullOrEmpty(Cc))
                {
                    message.CC.Add(Cc);
                }

                if (!string.IsNullOrEmpty(Bcc))
                {
                    message.Bcc.Add(Bcc);
                }

                if (!string.IsNullOrEmpty(Priority))
                {
                    switch (Priority.ToLower())
                    {
                        case "high":
                            message.Priority = MailPriority.High;
                            break;
                        case "normal":
                            message.Priority = MailPriority.Normal;
                            break;
                        case "low":
                            message.Priority = MailPriority.Low;
                            break;
                    }
                }

                message.To.Add(To);
                message.ReplyToList.Add(ReplyTo);
                message.From = !string.IsNullOrEmpty(FromName) ? new MailAddress(From, FromName) : new MailAddress(From);

                if (UseAttachment)
                {
                    // ToDo: Report file name should be attached to the report file object itself, file shouldn't be accessed directly!
                    data.Position = 0;
                    message.Attachments.Add(new Attachment(data, Path.GetFileName(fileName)));
                }

                if (!string.IsNullOrEmpty(CustomSubject))
                {
                    message.Subject = CustomSubject;
                }
                else
                {
                    message.Subject = "NCrash: " + report.GeneralInfo.HostApplication + " (" +
                                      report.GeneralInfo.HostApplicationVersion + "): " +
                                      report.GeneralInfo.ExceptionType + " @ " +
                                      report.GeneralInfo.TargetSite;
                }

                var sb = new StringBuilder();
                if (!string.IsNullOrEmpty(CustomBody))
                {
                    sb.Append(CustomBody).Append(Environment.NewLine).Append(Environment.NewLine);
                }
                WriteReport(report, sb);
                sb.Append(Environment.NewLine).Append(Environment.NewLine);
                WriteException(report.Exception, sb);
                message.Body = sb.ToString();

                smtpClient.Send(message);
                Logger.Trace("Submitted bug report email to: " + To);

                return true;
            }
        }
示例#13
0
        private void WriteReport(ZipStorer zipStorer, Report report)
        {
            using (var stream = new MemoryStream())
            {
                // Store the report as XML file
                try
                {
                    var serializer = report.CustomInfo != null
                                     ? new XmlSerializer(typeof(Report), new[] { report.CustomInfo.GetType() })
                                     : new XmlSerializer(typeof(Report));

                    serializer.Serialize(stream, report);
                }
                catch (Exception exception)
                {
                    if (report.CustomInfo != null)
                    {
                        Logger.Error(
                            string.Format(
                                "The given custom info of type [{0}] cannot be serialized. Make sure that given type and inner types are XML serializable.",
                                report.CustomInfo.GetType()), exception);
                    }
                    report.CustomInfo = null;
                    var serializer = new XmlSerializer(typeof(Report));
                    serializer.Serialize(stream, report);
                }

                stream.Position = 0;
                zipStorer.AddStream(ZipStorer.Compression.Deflate, StoredItemFile.Report, stream, DateTime.UtcNow,
                                    string.Empty);
            }
        }
示例#14
0
        /// <summary>
        /// Report exception and show UI in given thread.
        /// </summary>
        /// <param name="exception"></param>
        /// <returns></returns>
        protected virtual ExecutionFlow Report(Exception exception)
        {
            try
            {
                Logger.Trace("Starting to generate a bug report for the exception.");
                var serializableException = new SerializableException(exception);
                var report = new Report(serializableException);

                if (_settings.Plugins != null && _settings.Plugins.Count > 0)
                {
                    Logger.Trace("Processing plugins.");
                    foreach (IPlugin plugin in _settings.Plugins)
                    {
                        plugin.PreProcess(_settings);
                    }
                }

                var handler = ProcessingException;
                if (handler != null)
                {
                    Logger.Trace("Notifying the user before handling the exception.");

                    // Allowing user to add any custom information to the report
                    handler(exception, report);
                }

                var uiDialogResult = _settings.UserInterface.DisplayBugReportUI(report);

                if (uiDialogResult.SendReport)
                {
                    // Test if it has NOT been more than x many days since entry assembly was last modified)
                    if (_settings.StopReportingAfter >= 0 &&
                        InstallationDate.AddDays(_settings.StopReportingAfter).CompareTo(DateTime.Now) <= 0)
                    {
                        // TODO: this should be moved to task
                        // clear written reports
                        Logger.Trace("As per setting 'Settings.StopReportingAfter(" + _settings.StopReportingAfter +
                                        ")', bug reporting feature was enabled for a certain amount of time which has now expired: Truncating all expired bug reports. Bug reporting is now disabled.");
                        _storage.Clear();
                    }
                    else
                    {
                        _storage.Write(report);

                        // notify dispatcher to dispatch
                        lock (_backgroundLock)
                        {
                            Monitor.PulseAll(_backgroundLock);
                        }
                    }

                }

                if (_settings.Plugins != null && _settings.Plugins.Count > 0)
                {
                    Logger.Trace("PostProcessing plugins.");
                    foreach (IPlugin plugin in _settings.Plugins)
                    {
                        plugin.PostProcess(_settings);
                    }
                }

                return uiDialogResult.Execution;
            }
            catch (Exception ex)
            {
                Logger.Error("An exception occurred during bug report generation process. See the inner exception for details.", ex);
                return ExecutionFlow.BreakExecution; // Since an internal exception occured
            }
        }
示例#15
0
 public UIDialogResult DisplayBugReportUI(Report report)
 {
     _report = report;
     return _awaitedResult;
 }
示例#16
0
 public bool Send(Stream data, string fileName, Report report)
 {
     Logger.WarnFormat("Report {0} removed by NoOpSender. Report was {1}", fileName, report);
     return false;
 }