public static void NotifyOrThrow(this ExceptionNotificationHandler handler, object source, ExceptionNotification args)
 {
     if (handler != null)
     {
         handler(source, args);
     }
     else if (args.Severity == ExceptionSeverity.Error)
     {
         throw args.Exception;
     }
 }
Ejemplo n.º 2
0
        private PocoElementNode(Base instance, PocoElementNode parent, IElementDefinitionSummary definition, string location, string shortPath)
        {
            Current      = instance;
            _mySD        = new Lazy <PocoComplexTypeSerializationInfo>(() => (PocoComplexTypeSerializationInfo)PocoStructureDefinitionSummaryProvider.Provide(Current.GetType()));
            InstanceType = determineInstanceType(Current, definition);
            Definition   = definition ?? throw Error.ArgumentNull(nameof(definition));

            ExceptionHandler = parent.ExceptionHandler;
            Location         = location;
            ShortPath        = shortPath;
        }
Ejemplo n.º 3
0
 private PocoElementNode(object instance, PocoElementNode parent, string location, string shortPath, int arrayIndex,
                         IElementDefinitionSummary summary)
 {
     Current          = instance;
     InstanceType     = determineInstanceType(instance, summary);
     Provider         = parent.Provider;
     ExceptionHandler = parent.ExceptionHandler;
     Definition       = summary;
     Location         = location;
     ShortPath        = shortPath;
     ArrayIndex       = arrayIndex;
     Provider         = parent.Provider;
 }
        /// <summary>
        /// Registers an <see cref="ExceptionNotificationHandler" /> with an <see cref="IExceptionSource"/>.
        /// </summary>
        /// <seealso cref="ExceptionSourceExtensions.Catch(IExceptionSource, ExceptionNotificationHandler, bool)"/>
        public static IDisposable Catch(this ISourceNode node, ExceptionNotificationHandler handler, bool forward = false)
        {
            if (node == null)
            {
                throw Error.ArgumentNull(nameof(node));
            }
            if (handler == null)
            {
                throw Error.ArgumentNull(nameof(handler));
            }

            return(node is IExceptionSource s?
                   s.Catch(handler, forward)
                       : throw new NotImplementedException("Node does not implement IExceptionSource."));
        }
Ejemplo n.º 5
0
        private PocoElementNode(ModelInspector inspector, Base instance, PocoElementNode parent, PropertyMapping definition, string location, string shortPath)
        {
            Current    = instance;
            _inspector = inspector;

            var instanceType = determineInstanceType(instance.GetType(), definition);

            _myClassMapping = _inspector.ImportType(instanceType);
            InstanceType    = ((IStructureDefinitionSummary)_myClassMapping).TypeName;
            Definition      = definition ?? throw Error.ArgumentNull(nameof(definition));

            ExceptionHandler = parent.ExceptionHandler;
            Location         = location;
            ShortPath        = shortPath;
        }
            public ExceptionInterceptor(IExceptionSource source, ExceptionNotificationHandler handler, bool forward)
            {
                _source                 = source;
                _originalHandler        = source.ExceptionHandler;
                source.ExceptionHandler = nestedHandler;
                _forward                = forward;

                void nestedHandler(object s, ExceptionNotification a)
                {
                    handler(s, a);

                    if (forward)
                    {
                        _originalHandler.NotifyOrThrow(s, a);
                    }
                }
            }
 /// <summary>
 /// Registers an <see cref="ExceptionNotificationHandler" /> with an <see cref="IExceptionSource"/>.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="handler"></param>
 /// <param name="forward">If true, also forwards the error to the original handler (if any).</param>
 /// <returns>An object that, when disposed, unregisters the handler from the source.</returns>
 /// <remarks>
 /// <para>This function can be used directly inside a <c>using</c> block, to scope the interception
 /// of exceptions by the given handler to that block.</para>
 /// <para>The <paramref name="handler"/> replaces the handler already in place in the source (of any), but
 /// as soon as executing leaves the block, the handler is unregistered, and the original handler restored.</para>
 /// <para>If the source originally had a handler set, the <paramref name="forward"/> can be used to forward
 /// the exception to the original handler, after invoking the handler passed in with <paramref name="handler"/>.</para>
 /// </remarks>
 /// <example>
 /// <code>
 /// using(source.Catch((o,a) => lastError = a))
 /// {
 ///      var children = source.Children();
 /// }
 /// </code></example>
 public static IDisposable Catch(this IExceptionSource source, ExceptionNotificationHandler handler, bool forward = false) =>
 new ExceptionInterceptor(source, handler, forward);
 protected BaseController(INotificationHandler <ExceptionNotification> notifications)
 {
     _notifications = (ExceptionNotificationHandler)notifications;
 }
 protected CommandHandler(INotificationHandler <ExceptionNotification> notifications, IMediator bus, IUnitOfWork uow = null)
 {
     _uow           = uow;
     _notifications = (ExceptionNotificationHandler)notifications;
     _bus           = bus;
 }
Ejemplo n.º 10
0
 public static IDisposable Catch(this ITypedElement source, ExceptionNotificationHandler handler) =>
 source is IExceptionSource s?s.Catch(handler) : throw new NotImplementedException("Element does not implement IExceptionSource.");