Esempio n. 1
0
        /// <summary>
        /// Thos method used to publish event and handle exception, if happened
        /// </summary>
        /// <param name="item"></param>
        protected virtual void onProcessQueueItem(IQueueItem item)
        {
            MethodInfo genericMethod = GetPublishMethodInfo(item.DeclaringEventType);
            object     typedEvent    = BuildGenericQueueEvent(item);
            object     sender        = BuildSender(item.DeclaringEventType);

            try
            {
                genericMethod.Invoke(_eventBusService, new[] { typedEvent, sender });
                onEventHandled(item);
            }
            // Exceptions from actual delegate are wrapped into TargetInvocationException by MethodBase.Invoke()
            catch (TargetInvocationException ex)
            {
                RetryNeededException retry = ex.InnerException as RetryNeededException;
                if (retry != null)
                {
                    onEventRetried(item, retry);
                }
                else
                {
                    onEventFailed(item, ex.InnerException);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Thos method used to publish event and handle exception, if happened
        /// </summary>
        /// <param name="item"></param>
        protected virtual void onProcessQueueItem(IQueueItem item)
        {
            MethodInfo genericMethod;
            object     typedEvent;
            object     sender;

            // Any exception within following try/catch block is final
            // report exception for handing and remove event from queue as failed
            try
            {
                genericMethod = GetPublishMethodInfo(item.DeclaringEventType);
                typedEvent    = BuildGenericQueueEvent(item);
                sender        = BuildSender(item.DeclaringEventType);
            }
            catch (Exception ex)
            {
                onEventFailed(item, ex);
                _eventBusService.Publish <Exception>(ex, this);
                return;
            }

            // Event handling here
            try
            {
                genericMethod.Invoke(_eventBusService, new[] { typedEvent, sender });
                onEventHandled(item);
            }
            // Exceptions from actual delegate are wrapped into TargetInvocationException by MethodBase.Invoke()
            catch (TargetInvocationException ex)
            {
                RetryNeededException retry = ex.InnerException as RetryNeededException;
                if (retry != null)
                {
                    onEventRetried(item, retry);
                }
                else
                {
                    onEventFailed(item, ex.InnerException);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Called when we need to retry event
 /// </summary>
 /// <param name="item"></param>
 /// <param name="ex"></param>
 protected virtual void onEventRetried(IQueueItem item, RetryNeededException ex)
 {
     _repository.UpdateItem(item);
 }