/// <summary>
        /// Enumerates all handlers in the <paramref name="collection"/> and passes each of them <paramref name="exception"/>.
        /// </summary>
        /// <param name="collection">The collection use handlers from.</param>
        /// <param name="exception">The exception to handle.</param>
        public static void Handle(this IExceptionHandlerCollection collection, Exception exception)
        {
            Ensure.NotNull(collection, "collection");
            Ensure.NotNull(exception, "exception");

            foreach (IExceptionHandler handler in collection.Enumerate())
            {
                handler.Handle(exception);
            }
        }
示例#2
0
 /// <summary>
 /// Creates new instance.
 /// </summary>
 /// <param name="interfaceType">The type of interface for handler. Used to find execute method for <see cref="HandlerDescriptor"/>.</param>
 /// <param name="contextGenericType">The type of the generic interface for context.</param>
 /// <param name="methodName">The 'executed' method name.</param>
 public HandlerDescriptorProvider(Type interfaceType, Type contextGenericType, string methodName, IExceptionHandlerCollection innerExceptionHandlers, IExceptionHandlerCollection outerExceptionHandlers)
 {
     Ensure.NotNull(interfaceType, "interfaceType");
     Ensure.NotNullOrEmpty(methodName, "methodName");
     Ensure.NotNull(innerExceptionHandlers, "innerExceptionHandlers");
     Ensure.NotNull(outerExceptionHandlers, "outerExceptionHandlers");
     this.interfaceType          = interfaceType;
     this.contextGenericType     = contextGenericType;
     this.methodName             = methodName;
     this.innerExceptionHandlers = innerExceptionHandlers;
     this.outerExceptionHandlers = outerExceptionHandlers;
 }
示例#3
0
        private void Initialize()
        {
            CommandExceptionHandlers    = new DefaultExceptionHandlerCollection();
            DispatcherExceptionHandlers = new DefaultExceptionHandlerCollection();

            descriptorProvider = new HandlerDescriptorProvider(
                typeof(ICommandHandler <>),
                null,
                TypeHelper.MethodName <ICommandHandler <object>, object, Task>(h => h.HandleAsync),
                CommandExceptionHandlers,
                DispatcherExceptionHandlers
                );
            handlers = new HandlerCollection(log.Factory, descriptorProvider);
        }
        /// <summary>
        /// Registers <paramref name="handler"/> to handle exceptions for all implemented interfaces <see cref="IExceptionHandler{T}"/>.
        /// </summary>
        /// <param name="collection">The collection of exception handlers.</param>
        /// <param name="handler">The exceptions handler.</param>
        /// <returns><paramref name="collection"/>.</returns>
        public static IExceptionHandlerCollection AddAll(this IExceptionHandlerCollection collection, object handler)
        {
            Ensure.NotNull(collection, "collection");
            Ensure.NotNull(handler, "handler");
            foreach (Type interfaceType in handler.GetType().GetInterfaces())
            {
                if (interfaceType.IsGenericType && typeof(IExceptionHandler <>) == interfaceType.GetGenericTypeDefinition())
                {
                    MethodInfo addMethod = typeof(_ExceptionHandlerCollectionExtensions).GetMethod(Constant.ExceptionHandlerCollectionAddMethodName).MakeGenericMethod(interfaceType.GetGenericArguments());
                    addMethod.Invoke(collection, new object[] { collection, handler });
                }
            }

            return(collection);
        }
        /// <summary>
        /// Creates new instance.
        /// </summary>
        /// <param name="store">The publishing store for command persistent delivery.</param>
        /// <param name="schedulingProvider">The provider of a delay computation for delayed events.</param>
        public PersistentEventDispatcher(IEventPublishingStore store, ISchedulingProvider schedulingProvider)
        {
            Ensure.NotNull(store, "store");
            Ensure.NotNull(schedulingProvider, "schedulingProvider");
            this.store = store;
            this.schedulingProvider = schedulingProvider;

            EventExceptionHandlers      = new DefaultExceptionHandlerCollection();
            DispatcherExceptionHandlers = new DefaultExceptionHandlerCollection();

            this.descriptorProvider = new HandlerDescriptorProvider(
                typeof(IEventHandler <>),
                typeof(IEventHandlerContext <>),
                TypeHelper.MethodName <IEventHandler <object>, object, Task>(h => h.HandleAsync),
                EventExceptionHandlers,
                DispatcherExceptionHandlers
                );

            Handlers = new HandlerCollection(storage, descriptorProvider);
        }
 /// <summary>
 /// Adds <paramref name="handler"/> to handle exceptions of type <typeparamref name="T"/>.
 /// </summary>
 /// <typeparam name="T">The type of the exception to handle by the <paramref name="handler"/>.</typeparam>
 /// <param name="collection">The collection to add handler to.</param>
 /// <param name="handler">The handler to add to the <paramref name="collection"/>.</param>
 /// <returns>Self (for fluency).</returns>
 public static IExceptionHandlerCollection Add <T>(this IExceptionHandlerCollection collection, IExceptionHandler <T> handler)
     where T : Exception
 {
     Ensure.NotNull(collection, "collection");
     return(collection.Add(new ExceptionHandlerBuilder().Handler(handler)));
 }
示例#7
0
 /// <summary>
 /// Sets <paramref name="dispatcherExceptionHandlers"/> to be used for handling infrastructure exceptions.
 /// </summary>
 /// <param name="dispatcherExceptionHandlers">A collection of handlers for infrastructure exceptions.</param>
 /// <returns>Self (for fluency).</returns>
 public PersistentCommandDispatcherBuilder UseDispatcherExceptionHandlers(IExceptionHandlerCollection dispatcherExceptionHandlers)
 {
     this.dispatcherExceptionHandlers = dispatcherExceptionHandlers;
     return(this);
 }
示例#8
0
 /// <summary>
 /// Sets <paramref name="commandExceptionHandlers"/> to be used for handling command processing exceptions.
 /// </summary>
 /// <param name="commandExceptionHandlers">A collection of handlers for command processing exceptions.</param>
 /// <returns>Self (for fluency).</returns>
 public PersistentCommandDispatcherBuilder UseCommandExceptionHandlers(IExceptionHandlerCollection commandExceptionHandlers)
 {
     this.commandExceptionHandlers = commandExceptionHandlers;
     return(this);
 }
示例#9
0
 public static bool Compare(this IExceptionHandlerCollection source, IExceptionHandlerCollection n, Func<IExceptionHandler, IExceptionHandler, Action<string, string>, bool> checkitem, Action<string, string> errAct)
 {
     return Compare<IExceptionHandler>(source,n,checkitem,errAct);
 }
示例#10
0
 public static bool Compare(this IExceptionHandlerCollection source, IExceptionHandlerCollection n, Func<IExceptionHandler, IExceptionHandler, bool> checkitem)
 {
     return Compare<IExceptionHandler>(source,n,checkitem);
 }
示例#11
0
 public static bool Compare(this IExceptionHandlerCollection source, IExceptionHandlerCollection n)
 {
     return Compare<IExceptionHandler>(source,n);
 }
示例#12
0
 public static bool Compare(this IExceptionHandlerCollection source, IExceptionHandlerCollection n, Func <IExceptionHandler, IExceptionHandler, Action <string, string>, bool> checkitem, Action <string, string> errAct)
 {
     return(Compare <IExceptionHandler>(source, n, checkitem, errAct));
 }
示例#13
0
 public static bool Compare(this IExceptionHandlerCollection source, IExceptionHandlerCollection n, Func <IExceptionHandler, IExceptionHandler, bool> checkitem)
 {
     return(Compare <IExceptionHandler>(source, n, checkitem));
 }
示例#14
0
 public static bool Compare(this IExceptionHandlerCollection source, IExceptionHandlerCollection n)
 {
     return(Compare <IExceptionHandler>(source, n));
 }
        public virtual IExceptionHandlerCollection TransformExceptionHandlerCollection(IExceptionHandlerCollection value)
        {
            IExceptionHandler[] array = new IExceptionHandler[value.Count];
            for (int i = 0; i < value.Count; i++)
            {
                array[i] = this.TransformExceptionHandler(value[i]);
            }

            IExceptionHandlerCollection target = new ExceptionHandlerCollection();
            target.AddRange(array);
            return target;
        }
 private void InsituTransformExceptionHandlerCollection(IExceptionHandlerCollection value)
 {
     for (int i = 0; i < value.Count; i++)
     {
         value[i] = this.TransformExceptionHandler(value[i]);
     }
 }