private void SelectExceptionStrategy() { switch (_exception) { case AccessViolationException _: _exceptionStrategy = new AccessViolationError(); break; case DuplicateNameException _: _exceptionStrategy = new DuplicateNameError(); break; case KeyNotFoundException _: _exceptionStrategy = new KeyNotFoundError(); break; case ArgumentException _: _exceptionStrategy = new ArgumentError(); break; case AuthenticationException _: _exceptionStrategy = new AuthenticationError(); break; case UnauthorizedAccessException _: _exceptionStrategy = new UnauthorizedAccessError(); break; default: _exceptionStrategy = new DefaultError(); break; } }
/// <summary> /// Any exceptions thrown by individual subscribers are /// caught and passed to the input exceptionHandler delegate. /// </summary> public static void PublishWithExceptionStrategy(this MulticastDelegate eventDelegate, object[] parameters, IExceptionStrategy exceptionHandler) { if (eventDelegate != null) { foreach (Delegate subscriber in eventDelegate.GetInvocationList()) { try { //Uses MethodInfo.Invoke method to publish event because //Delegate.DynamicInvoke method is not available in Compact Framework 3.5. //DynamicInvoke does essentially the same thing TODO:(? check IL to confirm.) subscriber.Method.Invoke(subscriber.Target, parameters); } catch (Exception e) { // Method.Invoke() wraps any exceptions thrown within the method in a // "TargetInvocationException". We unwrap it here. if (e.InnerException != null) { exceptionHandler.ProcessException(e.InnerException); } else { exceptionHandler.ProcessException(e); } } } } }
public PresentationException(Exception ex) { if (ex is IExceptionStrategy) { _strategy = ex as IExceptionStrategy; } else { _strategy = new Status500Strategy(ex, Level.PL); } }
public TapetiConsumer(CancellationToken cancellationToken, ITapetiConfig config, string queueName, IEnumerable <IBinding> bindings) { this.cancellationToken = cancellationToken; this.config = config; this.queueName = queueName; this.bindings = bindings.ToList(); logger = config.DependencyResolver.Resolve <ILogger>(); exceptionStrategy = config.DependencyResolver.Resolve <IExceptionStrategy>(); messageSerializer = config.DependencyResolver.Resolve <IMessageSerializer>(); }
public TapetiConsumer(TapetiWorker worker, string queueName, IDependencyResolver dependencyResolver, IEnumerable <IBinding> bindings, IReadOnlyList <IMessageMiddleware> messageMiddleware, IReadOnlyList <ICleanupMiddleware> cleanupMiddleware) { this.worker = worker; this.queueName = queueName; this.dependencyResolver = dependencyResolver; this.messageMiddleware = messageMiddleware; this.cleanupMiddleware = cleanupMiddleware; this.bindings = bindings.ToList(); logger = dependencyResolver.Resolve <ILogger>(); exceptionStrategy = dependencyResolver.Resolve <IExceptionStrategy>(); }
public BusinessException(Exception ex) { if (ex is IExceptionStrategy) { _strategy = ex as IExceptionStrategy; } else if (ex is ValidationException) { _strategy = new ValidationStrategy(ex as ValidationException, Level.BL); } else { _strategy = new Status500Strategy(ex, Level.DL); } }
public void RetrieveByBatches_NoExceptionsNotAliquotAmount_ReturnsExpectedAmount() { var strategySetup = new Mock <IExceptionStrategy>(MockBehavior.Strict); strategySetup.Setup(str => str.ShouldThrowException(It.IsAny <Query>())).Returns(false); _exceptionStrategy = strategySetup.Object; var batchSize = 5; var query = new Query { Count = 12 }; var sequence = _queryByBatches.RetrieveByBatches(query, batchSize).ToList(); sequence.Should().HaveCount(12); sequence.Should().BeInAscendingOrder(); query.TimesCountChanged.Should().BeLessOrEqualTo(12 / 5 + 2); }
public void RetrieveByBatches_ExceptionAtInitBatch_ReturnsExpectedAmount() { var strategySetup = new Mock <IExceptionStrategy>(MockBehavior.Strict); strategySetup.Setup(str => str.ShouldThrowException(It.Is <Query>(q => q.Count >= 4))).Returns(true); strategySetup.Setup(str => str.ShouldThrowException(It.Is <Query>(q => q.Count < 4))).Returns(false); _exceptionStrategy = strategySetup.Object; var batchSize = 4; var query = new Query { Count = 21 }; var sequence = _queryByBatches.RetrieveByBatches(query, batchSize).ToList(); sequence.Should().HaveCount(21); sequence.Should().BeInAscendingOrder(); query.TimesCountChanged.Should().BeLessOrEqualTo(21 / 2 + 1); }
/// <summary> /// Event delegates are invoked asynchronously. /// Any exceptions thrown by individual subscribers are /// caught and passed to the input exceptionHandler. /// </summary> public static void PublishWithExceptionStrategyAsync(this MulticastDelegate eventDelegate, object[] parameters, IExceptionStrategy exceptionHandler) { if (eventDelegate != null) { foreach (Delegate subscriber in eventDelegate.GetInvocationList()) { Delegate eventHandler = subscriber; //Uses MethodInfo.Invoke method to publish event because //Delegate.DynamicInvoke method is not available in Compact Framework 3.5. ThreadPool.QueueUserWorkItem( state => { try { eventHandler.Method.Invoke(eventHandler.Target, parameters); } catch (Exception exception) { // Method.Invoke() wraps any exceptions thrown within the method in a // "TargetInvocationException". We unwrap it here. if (exception.InnerException != null) { exceptionHandler.ProcessException(exception.InnerException); } else { exceptionHandler.ProcessException(exception); } } }); } } }
/// <summary> /// Event delegates are invoked asynchronously. /// Any exceptions thrown by individual subscribers are /// caught and passed to the input exceptionHandler. /// </summary> public static void PublishWithExceptionStrategyAsync(this MulticastDelegate eventDelegate, IExceptionStrategy exceptionHandler) { PublishWithExceptionStrategyAsync(eventDelegate, new object[] {}, exceptionHandler); }
public BusinessException(IExceptionStrategy strategy) { this._strategy = strategy; }
/// <summary> /// Process the input exception using the input IExceptionStrategy first /// and then the default strategy stack. /// </summary> /// <param name="e">Exception to process.</param> /// <param name="strategy">First exception strategy to use in processing the exception.</param> public static void HandleException(Exception e, IExceptionStrategy strategy) { HandleException(e, strategy.ProcessException); }
/// <param name="strategy">Unhandled exception strategy to be used in addition to default strategies.</param> public static void HandleUnhandledAppDomainExceptions(IExceptionStrategy strategy) { AppDomain.CurrentDomain.UnhandledException += (sender, e) => HandleException((Exception)e.ExceptionObject, strategy); }
public PresentationException(Exception ex, IExceptionStrategy strategy) { this._strategy = strategy; }
public DataException(IExceptionStrategy strategy) { this._strategy = strategy; }
public DataException(Exception ex) { _strategy = new Status500Strategy(ex, Level.DL); }
void IExceptionHandler.HandleException(Exception e, IExceptionStrategy strategy) { HandleException(e, strategy); }