private void BuildErrorHandler()
        {
            errorLog = new ErrorLog(new DefaultLogFormatter());
            ILogFactory logFactory = new DefaultLogFactory()
                                     .AddSerializer(errorLog)
#if DEBUG
                                     .AddConsole()
#endif
            ;

            log = logFactory.Scope("Root");

            ExceptionHandlerBuilder builder = new ExceptionHandlerBuilder();

            builder
            .Filter <UnauthorizedAccessException>()
            .Handler(new UnauthorizedAccessExceptionHandler(Settings.Default, this, () => { mainWindow?.Close(); mainFactory.ClearService(); }));

            builder
            .Filter(e => !(e is UnauthorizedAccessException))
            .Handler(new LogExceptionHandler(log))
            .Handler(new MessageBoxExceptionHandler(this));

            exceptionHandler = builder;
        }
Esempio n. 2
0
        private void InitializeErrorHandler()
        {
            executorFactory = new FileLogBatchFactory(TimeSpan.FromSeconds(30));

            logService = new IsolatedLogService();

            logFactory = new DefaultLogFactory()
                         .AddSerializer(AddDisposable(new FileLogSerializer(new DefaultLogFormatter(), () => settings.LogLevel, executorFactory)))
                         .AddSerializer(AddDisposable(new ErrorLogSerializer(new DefaultLogFormatter(), executorFactory)))
#if DEBUG
                         .AddConsole()
#endif
            ;

            ILog rootLog = logFactory.Scope("Root");

            ExceptionHandlerBuilder builder = new ExceptionHandlerBuilder();
            builder
            .Filter <UnauthorizedAccessException>()
            .Handler(new UnauthorizedAccessExceptionHandler(settings, this, () => { mainWindow?.Close(); mainFactory.ClearService(); }));

            builder
            .Filter(e => !(e is UnauthorizedAccessException))
            .Handler(new LogExceptionHandler(rootLog))
            .Handler(new MessageBoxExceptionHandler(this));

            exceptionHandler = builder;
        }
Esempio n. 3
0
 public ApiHub(IEventHandlerCollection eventHandlers, FormatterContainer formatters, ExceptionHandlerBuilder exceptionHandlerBuilder)
 {
     Ensure.NotNull(eventHandlers, "eventHandlers");
     Ensure.NotNull(formatters, "formatters");
     this.formatters = formatters;
     eventHandlers.AddAll(this);
     exceptionHandlerBuilder.Filter <AggregateRootException>().Handler(this);
 }
Esempio n. 4
0
        private void BuildExceptionHandler()
        {
            var exceptionBuilder = new ExceptionHandlerBuilder();

            exceptionBuilder
            .Handler(new LogExceptionHandler(LogFactory.Scope("Exception")));

            var unauthorized = new UnauthorizedExceptionHandler(ProcessService);

            exceptionBuilder
            .Filter <UnauthorizedAccessException>()
            .Handler(unauthorized);

            exceptionBuilder
            .Filter <PackagesConfigWriterException>()
            .Filter(e => e.InnerException is FileNotFoundException)
            .Handler(unauthorized);

            exceptionBuilder
            .Filter <NuGetConfigurationException>()
            .Filter(e => e.InnerException is UnauthorizedAccessException)
            .Handler(unauthorized);

            exceptionBuilder
            .Filter <FatalProtocolException>()
            .Handler(new NuGetFatalProtocolExceptionHandler(Navigator));

            var packageContent = new PackageInstallExceptionHandler(Navigator);

            exceptionBuilder
            .Handler <PackageFileExtractionException>(packageContent)
            .Handler <PackageFileRemovalException>(packageContent);

            exceptionBuilder
            .Handler(new RestartAsAdministratorCancelledExceptionHandler(Navigator, this));

            exceptionBuilder
            .Handler(new MessageExceptionHandler(Navigator))
            .Handler(new ShutdownExceptionHandler(this));

            ExceptionHandler = exceptionBuilder;
        }
Esempio n. 5
0
        public void Base()
        {
            ExceptionHandlerBuilder builder = new ExceptionHandlerBuilder();

            ArgumentExceptionHandler    handler1 = new ArgumentExceptionHandler();
            InnerExceptionIsNullHandler handler2 = new InnerExceptionIsNullHandler();
            MessageLongerThanTenHandler handler3 = new MessageLongerThanTenHandler();
            MessageLongerThanTenHandler handler4 = new MessageLongerThanTenHandler();

            builder
            .Handler(handler1);

            builder
            .Filter(a => a.InnerException == null)
            .Handler(handler2)
            .Filter(a => a.Message.Length > 10)
            .Handler(handler3);

            builder
            .Filter(a => a.Message.Length > 10)
            .Handler(handler4);

            IExceptionHandlerCollection collection = new DefaultExceptionHandlerCollection()
                                                     .Add(builder);

            collection.Handle(new Exception("<= 10ch"));
            collection.Handle(new Exception("Long message > 10ch", new Exception()));
            collection.Handle(new Exception("===== 10ch"));

            collection.Handle(new ArgumentException("<= 10ch"));
            collection.Handle(new ArgumentException("Long message > 10ch"));
            collection.Handle(new ArgumentException("===== 10ch", new Exception()));

            Assert.AreEqual(3, handler1.CallCount);
            Assert.AreEqual(4, handler2.CallCount);
            Assert.AreEqual(1, handler3.CallCount);
            Assert.AreEqual(2, handler4.CallCount);
        }