Пример #1
0
        public WpfExceptionReporter(Exception exception, ExceptionReportInfo info)
        {
            InitializeComponent();

            info.MainException = exception;
            this.DataContext   = new ExceptionReporterViewModel(info);
        }
Пример #2
0
        public void Two_Files_But_None_Exists_ReturnsEmptyString()
        {
            const string logFile1    = "file1.log";
            const string logFile2    = "file2.log";
            const string zipFilename = "Test.zip";

            _fileService.Setup(f => f.Exists(logFile1)).Returns(false);
            _fileService.Setup(f => f.Exists(logFile2)).Returns(false);
            _fileService.Setup(f => f.Exists(zipFilename)).Returns(true);
            _fileService.Setup(f => f.TempFile(zipFilename)).Returns(zipFilename);
            _zipper.Setup(z => z.Zip(zipFilename, It.IsAny <IEnumerable <string> >()));

            var filesToAttach = new List <string>
            {
                logFile1, logFile2
            };

            var config = new ExceptionReportInfo
            {
                FilesToAttach      = filesToAttach.ToArray(),
                TakeScreenshot     = false,
                AttachmentFilename = zipFilename
            };
            var zip    = new ZipAttachmentService(_zipper.Object, _screenshotTaker.Object, _fileService.Object);
            var result = zip.CreateZipReport(config);

            Assert.That(result, Is.EqualTo(string.Empty));
            _zipper.Verify(z => z.Zip(zipFilename, It.IsAny <IEnumerable <string> >()), Times.Never);
        }
        private void PopulateReportInfo(ExceptionReportInfo reportInfo)
        {
            urlEmail.Text             = reportInfo.ContactEmail;
            txtFax.Text               = reportInfo.Fax;
            lblContactMessageTop.Text = reportInfo.ContactMessageTop;
            txtPhone.Text             = reportInfo.Phone;
            urlWeb.Text               = reportInfo.WebUrl;
            lblExplanation.Text       = reportInfo.UserExplanationLabel;
            ShowFullDetail            = reportInfo.ShowFullDetail;
            ToggleShowFullDetail();
            btnDetailToggle.Visible = reportInfo.ShowLessMoreDetailButton;

            //TODO: show all exception messages
            txtExceptionMessageLarge.Text =
                txtExceptionMessage.Text  =
                    !string.IsNullOrEmpty(reportInfo.CustomMessage) ? reportInfo.CustomMessage : reportInfo.Exceptions[0].Message;

            txtExceptionMessageLarge2.Text = txtExceptionMessageLarge.Text;

            txtDate.Text            = reportInfo.ExceptionDate.ToShortDateString();
            txtTime.Text            = reportInfo.ExceptionDate.ToShortTimeString();
            txtRegion.Text          = reportInfo.RegionInfo;
            txtApplicationName.Text = reportInfo.AppName;
            txtVersion.Text         = reportInfo.AppVersion;

            btnClose.FlatStyle                =
                btnDetailToggle.FlatStyle     =
                    btnCopy.FlatStyle         =
                        btnEmail.FlatStyle    =
                            btnSave.FlatStyle = (reportInfo.ShowFlatButtons ? FlatStyle.Flat : FlatStyle.Standard);

            listviewAssemblies.BackColor                             =
                txtFax.BackColor                                     =
                    txtPhone.BackColor                               =
                        txtRegion.BackColor                          =
                            txtTime.BackColor                        =
                                txtTime.BackColor                    =
                                    txtVersion.BackColor             =
                                        txtApplicationName.BackColor =
                                            txtDate.BackColor        =
                                                txtExceptionMessageLarge.BackColor =
                                                    txtExceptionMessage.BackColor  = reportInfo.BackgroundColor;

            if (!reportInfo.ShowButtonIcons)
            {
                RemoveButtonIcons();
            }

            if (!reportInfo.ShowEmailButton)
            {
                RemoveEmailButton();
            }

            Text = reportInfo.TitleText;
            txtUserExplanation.Font = new Font(txtUserExplanation.Font.FontFamily, reportInfo.UserExplanationFontSize);
            lblContactCompany.Text  = string.Format("If this problem persists, please contact {0} support.", reportInfo.CompanyName);
            btnSimpleEmail.Text     = string.Format("{0} {1}",
                                                    reportInfo.SendMethod == ReportSendMethod.WebService ? "Send" : "Email",
                                                    reportInfo.SendMethod == ReportSendMethod.WebService ? "to " + reportInfo.CompanyName : reportInfo.CompanyName);
        }
 /// <summary>
 /// constructor accepting a view and the data/config of the report
 /// </summary>
 public ExceptionReportPresenter(IExceptionReportView view, ExceptionReportInfo info)
 {
     _reportGenerator = new ReportGenerator(info);
     _fileService     = new FileService();
     View             = view;
     ReportInfo       = info;
 }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <returns>Crash report as string</returns>
        public void Write(Exception e)
        {
            ExceptionReportInfo info = new ExceptionReportInfo {
                MainException = e
            };
            ExceptionReportGenerator reportGenerator = new ExceptionReportGenerator(info);
            ExceptionReport          report          = reportGenerator.CreateExceptionReport();

            string crashDir = Path.Combine(Preferences.instance().getProperty("application.support.path"),
                                           "CrashReporter");

            Directory.CreateDirectory(crashDir);
            using (StreamWriter outfile = new StreamWriter(Path.Combine(crashDir, DateTime.Now.Ticks + ".txt")))
            {
                outfile.Write(report.ToString());
            }
            TaskDialog   prompt = new TaskDialog();
            DialogResult result = prompt.ShowCommandBox(Locale.localizedString("Do you want to report the last crash?", "Crash"),
                                                        Locale.localizedString("Do you want to report the last crash?", "Crash"),
                                                        Locale.localizedString(
                                                            "The application %@ has recently crashed. To help improve it, you can send the crash log to the author.", "Crash").Replace("%@", Preferences.instance().getProperty("application.name")),
                                                        String.Format("{0}|{1}",
                                                                      Locale.localizedString("Send", "Crash"),
                                                                      Locale.localizedString("Don't Send", "Crash")),
                                                        false, SysIcons.Error);

            if (DialogResult.OK == result)
            {
                if (0 == prompt.CommandButtonResult)
                {
                    Post(report.ToString());
                }
            }
        }
        /// <summary>
        /// Initialise the ExceptionReporter
        /// <remarks>readConfig() should be called (explicitly) if you need to override default config settings</remarks>
        /// </summary>
        public ExceptionReporter()
        {
            var callingAssembly = Assembly.GetCallingAssembly();

            _reportInfo = new ExceptionReportInfo {
                AppAssembly = callingAssembly
            };
        }
Пример #7
0
 public PostSender(ExceptionReportInfo reportInfo)
 {
     AddParameter("version", reportInfo.AppVersion);
     AddParameter("assembly", reportInfo.AppAssembly.FullName);
     AddParameter("message", reportInfo.CustomMessage);
     AddParameter("user_message", reportInfo.UserExplanation);
     AddParameter("report", new ExceptionReportGenerator(reportInfo).CreateExceptionReport().ToString());
 }
Пример #8
0
        public ExceptionReportView(ExceptionReportInfo reportInfo)
        {
            InitializeComponent();

            _presenter = new ExceptionReportPresenter(this, reportInfo)
            {
                Clipboard = new WpfClipboard()
            };
        }
Пример #9
0
        public static T Create <T>(ViewResolver viewResolver, ExceptionReportInfo reportInfo) where T : class
        {
            Type view = viewResolver.Resolve <T>();

            ConstructorInfo constructor = view.GetConstructor(new[] { typeof(ExceptionReportInfo) });
            object          newInstance = constructor.Invoke(new object[] { reportInfo });

            return(newInstance as T);
        }
        public void Can_Create_Report_With_Local_Datetime()
        {
            var config = new ExceptionReportInfo {
                ExceptionDateKind = DateTimeKind.Local, MainException = new Exception()
            };
            var report = new ExceptionReportGenerator(config);

            Assert.That(config.ExceptionDate.Kind == DateTimeKind.Local);
        }
Пример #11
0
        public ErrorReportViewModel(IEnumerable<Exception> exceptions)
        {
            Model = new ExceptionReportInfo { AppAssembly = Assembly.GetCallingAssembly() };
            Model.SetExceptions(exceptions);

            CopyCommand = new CaptionCommand<string>(Resources.Copy, OnCopyCommand);
            SaveCommand = new CaptionCommand<string>(Resources.Save, OnSaveCommand);
            SubmitCommand = new CaptionCommand<string>(Resources.Send, OnSubmitCommand);
        }
        private void PopulateReportInfo(ExceptionReportInfo reportInfo)
        {
            lblExplanation.Text = reportInfo.UserExplanationLabel ??
                                  Resources.Please_enter_a_brief_explanation_of_events_leading_up_to_this_exception;
            ShowFullDetail = reportInfo.ShowFullDetail;
            ToggleShowFullDetail();
            btnDetailToggle.Visible = reportInfo.ShowLessDetailButton;

            //TODO: show all exception messages
            txtExceptionMessageLarge.Text =
                txtExceptionMessage.Text  =
                    !string.IsNullOrEmpty(reportInfo.CustomMessage) ? reportInfo.CustomMessage : reportInfo.Exceptions.First().Message;

            txtExceptionMessageLarge2.Text = txtExceptionMessageLarge.Text;

            txtDate.Text            = reportInfo.ExceptionDate.ToShortDateString();
            txtTime.Text            = reportInfo.ExceptionDate.ToShortTimeString();
            txtApplicationName.Text = reportInfo.AppName;
            txtVersion.Text         = reportInfo.AppVersion;


            btnClose.FlatStyle                =
                btnDetailToggle.FlatStyle     =
                    btnCopy.FlatStyle         =
                        btnEmail.FlatStyle    =
                            btnSave.FlatStyle = reportInfo.ShowFlatButtons ? FlatStyle.Flat : FlatStyle.Standard;

            listviewAssemblies.BackColor                 =
                txtTime.BackColor                        =
                    txtTime.BackColor                    =
                        txtVersion.BackColor             =
                            txtApplicationName.BackColor =
                                txtDate.BackColor        =
                                    txtExceptionMessageLarge.BackColor =
                                        txtExceptionMessage.BackColor  = ColorTranslator.FromHtml(reportInfo.BackgroundColor);

            if (!reportInfo.ShowButtonIcons)
            {
                RemoveButtonIcons();
            }

            if (!reportInfo.ShowEmailButton)
            {
                RemoveEmailButton();
            }

            Text = reportInfo.TitleText ?? Resources.ErrorReport;
            txtUserExplanation.Font = new Font(txtUserExplanation.Font.FontFamily, reportInfo.UserExplanationFontSize);
            lblContactCompany.Text  =
                string.Format(
                    Resources.ExceptionReportView_PopulateReportInfo_If_this_problem_persists__please_contact__0__support_ +
                    Environment.NewLine, reportInfo.CompanyName);
            btnSimpleEmail.Text =
                $"{(reportInfo.SendMethod == ReportSendMethod.WebService ? Resources.Send : "Email")} {(reportInfo.SendMethod == ReportSendMethod.WebService && !reportInfo.CompanyName.IsEmpty() ? string.Format(Resources.to__0_, reportInfo.CompanyName) : reportInfo.CompanyName)}";
            btnEmail.Text = reportInfo.SendMethod == ReportSendMethod.WebService ? Resources.Send : "Email";
        }
 public ReportBuilder(ExceptionReportInfo info,
                      IAssemblyDigger assemblyDigger,
                      IStackTraceMaker stackTraceMaker,
                      ISysInfoResultMapper sysInfoMapper)
 {
     _info            = info;
     _assemblyDigger  = assemblyDigger;
     _stackTraceMaker = stackTraceMaker;
     _sysInfoMapper   = sysInfoMapper;
 }
        public void SetUp()
        {
            _info = new ExceptionReportInfo {
                MainException = new Exception()
            };
            _reportGenerator = new ReportGenerator(_info);

            // set for testing because the AppAssembly filled by default, is null in a test environment
            _info.AppAssembly = Assembly.GetExecutingAssembly();
        }
Пример #15
0
        public void Can_Create_Subject_Without_CrLf()
        {
            var reportInfo = new ExceptionReportInfo();

            reportInfo.SetExceptions(new[] { new Exception("hello\r\nagain") });
            var mailSender = new MapiMailSender(reportInfo, null);

            Assert.That(mailSender.EmailSubject, Does.Not.Contain("\r"));
            Assert.That(mailSender.EmailSubject, Does.Not.Contain("\n"));
        }
        public ErrorReportViewModel(IEnumerable <Exception> exceptions)
        {
            Model = new ExceptionReportInfo {
                AppAssembly = Assembly.GetCallingAssembly()
            };
            Model.SetExceptions(exceptions);

            CopyCommand   = new CaptionCommand <string>(Resources.Copy, OnCopyCommand);
            SaveCommand   = new CaptionCommand <string>(Resources.Save, OnSaveCommand);
            SubmitCommand = new CaptionCommand <string>(Resources.Send, OnSubmitCommand);
        }
Пример #17
0
        public ExceptionReportView(ExceptionReportInfo reportInfo)
        {
            ShowFullDetail = true;
            InitializeComponent();
            TopMost = reportInfo.TopMost;

            _presenter = new ExceptionReportPresenter(this, reportInfo);

            WireUpEvents();
            PopulateTabs();
            PopulateReportInfo(reportInfo);
        }
Пример #18
0
        /// <summary>
        /// Initialise the ExceptionReporter
        /// <remarks>readConfig() should be called (explicitly) if you need to override default config settings</remarks>
        /// </summary>
        public ExceptionReporter()
        {
            var callingAssembly = Assembly.GetCallingAssembly();

            _reportInfo = new ExceptionReportInfo
            {
                AppAssembly = callingAssembly
            };

            _viewResolver          = new ViewResolver(callingAssembly);
            _internalExceptionView = ViewFactory.Create <IInternalExceptionView>(_viewResolver);
        }
        public void Can_Create_Report_With_Local_Datetime()
        {
            var reportInfo = new ExceptionReportInfo
            {
                ExceptionDateKind = DateTimeKind.Local,
                MainException     = new Exception()
            };

            // ReSharper disable once ObjectCreationAsStatement
            new ReportGenerator(reportInfo);
            Assert.That(reportInfo.ExceptionDate.Kind, Is.EqualTo(DateTimeKind.Local));
        }
Пример #20
0
        public void Can_Create_Subject()
        {
            var exception  = new Exception("hello");
            var reportInfo = new ExceptionReportInfo {
                TitleText = "test"
            };

            reportInfo.SetExceptions(new[] { exception });
            var mailSender = new MapiMailSender(reportInfo, null);

            Assert.That(mailSender.EmailSubject, Is.EqualTo("hello"));
        }
Пример #21
0
 void ConfigureSmtpEmail(ExceptionReportInfo config)
 {
     //--- Test SMTP - recommend using MailSlurper https://github.com/mailslurper
     config.MailMethod         = ExceptionReportInfo.EmailMethod.SMTP;                   // obsolete deprecated property used here, will be removed in later version
     config.SmtpServer         = "127.0.0.1";
     config.SmtpPort           = 2500;
     config.SmtpUsername       = "";
     config.SmtpPassword       = "";
     config.SmtpFromAddress    = "*****@*****.**";
     config.EmailReportAddress = "*****@*****.**";
     config.SmtpUseSsl         = false;         // NB you'll need to have "Allow less secure apps: ON" if using gmail for this
     //---
 }
        public void Can_Use_Custom_Subject()
        {
            var exception  = new Exception("Exception");
            var reportInfo = new ExceptionReportInfo {
                TitleText = "test"
            };

            reportInfo.SetExceptions(new[] { exception });
            reportInfo.EmailReportSubject = "hello";
            var mailSender = new MapiMailSender(reportInfo, null, new Mock <IScreenShooter>().Object);

            Assert.That(mailSender.EmailSubject, Is.EqualTo("hello"));
        }
Пример #23
0
 void ConfigureSmtpEmail(ExceptionReportInfo config)
 {
     //--- Test SMTP - recommended:
     // 1. MailSlurper https://github.com/mailslurper
     // 2. https://github.com/rnwood/smtp4dev
     //config.MailMethod = ExceptionReportInfo.EmailMethod.SMTP;
     config.SmtpServer         = "127.0.0.1";
     config.SmtpPort           = 2500;
     config.SmtpUsername       = "";
     config.SmtpPassword       = "";
     config.SmtpFromAddress    = "*****@*****.**";
     config.EmailReportAddress = "*****@*****.**";
     config.SmtpUseSsl         = false;
 }
Пример #24
0
        public ExceptionReportView(ExceptionReportInfo reportInfo)
        {
            ShowFullDetail = true;
            InitializeComponent();

            _presenter = new ExceptionReportPresenter(this, reportInfo)
            {
                Clipboard = new WinFormsClipboard()
            };

            WireUpEvents();
            PopulateTabs();
            PopulateReportInfo(reportInfo);
        }
Пример #25
0
        public static T Create <T>(ViewResolver viewResolver, ExceptionReportInfo reportInfo) where T : class
        {
            if (SyncUi.InvokeRequired)
            {
                return((T)SyncUi.Invoke(new Func <ViewResolver, ExceptionReportInfo, T>(Create <T>), viewResolver, reportInfo));
            }

            var view = viewResolver.Resolve <T>();

            var constructor = view.GetConstructor(new[] { typeof(ExceptionReportInfo) });
            var newInstance = constructor.Invoke(new object[] { reportInfo });

            return(newInstance as T);
        }
Пример #26
0
        public void None_Files_To_Add_To_Archive_ReturnsEmptyString()
        {
            const string zipFilename = "Test.zip";

            _fileService.Setup(f => f.TempFile(zipFilename)).Returns(zipFilename);
            _zipper.Setup(z => z.Zip(zipFilename, It.IsAny <IEnumerable <string> >()));

            var config = new ExceptionReportInfo
            {
                FilesToAttach      = new List <string>().ToArray(),
                TakeScreenshot     = false,
                AttachmentFilename = zipFilename
            };
            var zip    = new ZipAttachmentService(_zipper.Object, _screenshotTaker.Object, _fileService.Object);
            var result = zip.CreateZipReport(config);

            Assert.IsTrue(result == string.Empty);
            _zipper.Verify(z => z.Zip(zipFilename, It.IsAny <IEnumerable <string> >()), Times.Never);
        }
Пример #27
0
        public string CreateZipReport(ExceptionReportInfo reportInfo, string zipFilePath, IList <string> additionalFiles = null)
        {
            if (string.IsNullOrWhiteSpace(zipFilePath))
            {
                return(string.Empty);
            }

            var files = new List <string>();

            if (reportInfo.FilesToAttach.Length > 0)
            {
                files.AddRange(reportInfo.FilesToAttach);
            }
            if (additionalFiles?.Count > 0)
            {
                files.AddRange(additionalFiles);
            }
            try
            {
                if (reportInfo.TakeScreenshot)
                {
                    files.Add(ScreenShooter.TakeScreenShot());
                }
            }
            catch
            {
                /* ignored */
            }

            var filesThatExist = files.Where(f => FileService.Exists(f)).ToList();

            if (filesThatExist.Any())
            {
                Zipper.Zip(zipFilePath, filesThatExist);
            }
            else
            {
                return(string.Empty);
            }

            return(zipFilePath);
        }
Пример #28
0
        public void Take_Screenshot_False_DoesNotMakeScreenshot()
        {
            const string zipFilename        = "Test.zip";
            const string screenshotFilename = "Screenshot.jpg";

            _screenshotTaker.Setup(s => s.TakeScreenShot()).Returns(screenshotFilename);
            _fileService.Setup(f => f.Exists(screenshotFilename)).Returns(true);
            _fileService.Setup(f => f.TempFile(zipFilename)).Returns(zipFilename);

            var config = new ExceptionReportInfo
            {
                TakeScreenshot     = false,
                AttachmentFilename = zipFilename
            };
            var zip = new ZipAttachmentService(_zipper.Object, _screenshotTaker.Object, _fileService.Object);

            zip.CreateZipReport(config);

            _screenshotTaker.Verify(s => s.TakeScreenShot(), Times.Never());
        }
Пример #29
0
        static bool SaveErrorReportToFile(string path, ExceptionReportInfo reportInfo)
        {
            try
            {
                using (var reportGenerator = new ExceptionReportGenerator(reportInfo))
                {
                    var report = reportGenerator.CreateExceptionReport();
                    Logger.LogError(report.ToString());
                    File.WriteAllText(path, report.ToString());
                }

                Logger.LogNotice($"Successfully saved exception report to '{path}'");
                return(true);
            }
            catch (Exception e)
            {
                Logger.LogWarn(e, $"Unable to save error report to '{path}'");
            }

            return(false);
        }
Пример #30
0
        public void Only_Screenshot_To_Add_To_Archive_ReturnsArchiveWithOneFile()
        {
            const string zipFilename        = "Test.zip";
            const string screenshotFilename = "Screenshot.jpg";

            _screenshotTaker.Setup(s => s.TakeScreenShot()).Returns(screenshotFilename);
            _fileService.Setup(f => f.Exists(screenshotFilename)).Returns(true);
            _fileService.Setup(f => f.Exists(zipFilename)).Returns(true);
            _fileService.Setup(f => f.TempFile(zipFilename)).Returns(zipFilename);
            _zipper.Setup(z => z.Zip(zipFilename, It.Is <IEnumerable <string> >(en => en.Count() == 1)));

            var config = new ExceptionReportInfo
            {
                FilesToAttach      = new string[] {},
                TakeScreenshot     = true,
                AttachmentFilename = zipFilename
            };
            var zip    = new ZipAttachmentService(_zipper.Object, _screenshotTaker.Object, _fileService.Object);
            var result = zip.CreateZipReport(config);

            Assert.That(result, Is.EqualTo(zipFilename));
            _zipper.Verify(z => z.Zip(zipFilename, It.Is <IEnumerable <string> >(en => en.Count() == 1)), Times.AtLeastOnce);
        }
Пример #31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <returns>Crash report as string</returns>
        public void Write(Exception e)
        {
            ExceptionReportInfo info = new ExceptionReportInfo {
                MainException = e
            };
            ExceptionReportGenerator reportGenerator = new ExceptionReportGenerator(info);
            ExceptionReport          report          = reportGenerator.CreateExceptionReport();

            string crashDir = Path.Combine(PreferencesFactory.get().getProperty("application.support.path"),
                                           "CrashReporter");

            Directory.CreateDirectory(crashDir);
            using (StreamWriter outfile = new StreamWriter(Path.Combine(crashDir, DateTime.Now.Ticks + ".txt")))
            {
                outfile.Write(report.ToString());
            }
            TaskDialogResult result =
                TaskDialog.TaskDialog.Show(
                    title: LocaleFactory.localizedString("Do you want to report the last crash?", "Crash"),
                    mainInstruction: LocaleFactory.localizedString("Do you want to report the last crash?", "Crash"),
                    content:
                    LocaleFactory.localizedString(
                        "The application %@ has recently crashed. To help improve it, you can send the crash log to the author.",
                        "Crash").Replace("%@", PreferencesFactory.get().getProperty("application.name")),
                    commandLinks:
                    new string[]
            {
                LocaleFactory.localizedString("Send", "Crash"),
                LocaleFactory.localizedString("Don't Send", "Crash")
            }, mainIcon: TaskDialogIcon.Error);

            if (result.CommandButtonResult == 0)
            {
                Post(report.ToString());
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionReportBuilder"/> class.
 /// </summary>
 /// <param name="reportInfo">
 /// The report info.
 /// </param>
 /// <param name="sysInfoResults">
 /// The sys info results.
 /// </param>
 public ExceptionReportBuilder(ExceptionReportInfo reportInfo, IEnumerable<SysInfoResult> sysInfoResults)
     : this(reportInfo)
 {
     this._sysInfoResults = sysInfoResults;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionReportBuilder"/> class.
 /// </summary>
 /// <param name="reportInfo">
 /// The report info.
 /// </param>
 public ExceptionReportBuilder(ExceptionReportInfo reportInfo)
 {
     this._reportInfo = reportInfo;
 }