PandaWood / ExceptionReporter.NET

ExceptionReporter is a .NET component that gathers detailed information on an Exception and the application/system running it. It allows the user to copy, save or send a custom-formatted report to the developer
MIT License
51 stars 32 forks source link

Screenshot not taken in silent mode #26

Closed PoLaKoSz closed 6 years ago

PoLaKoSz commented 6 years ago

Hi!

Thank You @PandaWood for this awesome library! Today I had the chance to try it out and I found a little bug:

When I try to send silently a crash report invoking the following

https://github.com/PandaWood/ExceptionReporter.NET/blob/72e858b3156cbc4b395175d3fa0063ca5832267c/src/ExceptionReporter/ExceptionReporter.cs#L79-L103

code the crash report not include the screenshot when I set the ExceptionReportingInfo.TakeScreenshot to true.

Solutions

It can be fixed easily calling the ScreenshotTaker.TakeScreenShot(); method when settings up the ExceptionReporter class

or

with this commit it can be fixed internally. If You like it I will happily make a PR :smile: (I had to make the ExceptionReportInfo to public to access inside the UnitTest).

Code to reproduce the bug

using ExceptionReporting;
using System;
using System.Threading;

namespace ConsoleApp
{
    public class Program
    {
        private static void Main(string[] args)
        {
            try
            {
                RunApp();
            }
            catch (Exception ex)
            {
                var exceptionReporter = new ExceptionReporter();
                ConfigureSmtpEmail(exceptionReporter.Config);

                exceptionReporter.Config.TakeScreenshot = true;

                // this is the quick fix
                //exceptionReporter.Config.ScreenshotImage = ScreenshotTaker.TakeScreenShot();

                exceptionReporter.Send(ex);
            }

            Thread.Sleep(10 * 1000);
        }

        private static void RunApp()
        {
            InitializeViewModels();
        }

        private static void InitializeViewModels()
        {
            ApplicationUpdater();
        }

        private static void ApplicationUpdater()
        {
            throw new Exception("Can not get the latest version from GitHub.com",
                new Exception("Encoding failed"));
        }

        private static void ConfigureSmtpEmail(ExceptionReportInfo config)
        {
            config.SendMethod = ReportSendMethod.SMTP;

            config.SmtpServer         = "________";
            config.SmtpPort           = 587;
            config.SmtpUsername       = "________";
            config.SmtpPassword       = "________";
            config.SmtpFromAddress    = "________";
            config.EmailReportAddress = "________";
            config.SmtpUseSsl         = true;
        }
    }
}

Failing Attacher UnitTest

using ExceptionReporting.Core;
using ExceptionReporting.Mail;
using Moq;
using NUnit.Framework;

namespace ExceptionReporting.Tests
{
    [Test]
    public void Should_Make_Screenshot_In_Silent_Mode__Issue_26()
    {
        var attacher = new Attacher(new ExceptionReportInfo { TakeScreenshot = true });

        attacher.AttachFiles(_iattach.Object);

        Assert.IsTrue(attacher.Config.ScreenshotAvailable);
    }
  }
}
PoLaKoSz commented 6 years ago

I would like to help You develop this library but with the indent_size = 2 config I can't really read and write the source code. Is there a way to use my preferred indention and command Visual Studio to convert my 4 space intention to 2 (or whatever is in the .editorconfig file) when I close the file and when I reopen it it show me with 4 space intention again?

Sorry for my bad English grammar 😢

PandaWood commented 6 years ago

Thanks a lot @PoLaKoSz

You've provided everything needed!

I could copy your changes in but it would be good for you to get a credit for being a "Contributor" ;-) So for that reason I'm very happy to accept a Pull Request.

Just be sure to squash your changes into a single commit on a branch (not master) before submitting.

<removed advice that turned out to be wrong on how to override .editoconfig>

SlyFoxHayes commented 6 years ago

This has to be changed in the .editorconfig. It overrides the Visual Studio settings. I just changed mine and now have the tabs indenting 4 spaces.

PandaWood commented 6 years ago

Actually correction, to override .editorconfig toggle off the Follow project coding conventions option in Tools > Options > Text Editor https://docs.microsoft.com/en-us/visualstudio/ide/media/coding_conventions_option.png

SlyFoxHayes commented 6 years ago

Ah, yeah, that is better!

PoLaKoSz commented 6 years ago

I don't know yet why, but when I uncheck the box, when I copy-paste code or just use the tab it still use 2 space not 4 (this is in my settings) - I need to delete .editorConfig every time after a commit. Can we remove the .editorConfig file?