コード例 #1
0
        public void Execute(TInstance instance)
        {
            while (true)
            {
                try
                {
                    _activities.Execute(instance);
                    return;
                }
                catch (Exception ex)
                {
                    try
                    {
                        ExceptionHandlerResult result = _exceptionHandler.Handle(instance, _event, ex);
                        if (result == ExceptionHandlerResult.Unhandled)
                        {
                            throw;
                        }

                        if (result == ExceptionHandlerResult.Return)
                        {
                            return;
                        }
                    }
                    catch (Exception innerException)
                    {
                        string message = "{0} occurred while handling {1} during {2}"
                                         .FormatWith(innerException.GetType().ToShortTypeName(), _event.Name, _state.Name);

                        throw new StateMachineWorkflowException(message, innerException);
                    }
                }
            }
        }
コード例 #2
0
        public ExceptionHandlerResult Handle(TInstance instance, Event eevent, Exception exception)
        {
            Type exceptionType = exception.GetType();

            IEnumerable <EventExceptionHandler <TInstance> > matching = _handlers
                                                                        .Where(x => x.ExceptionType.IsAssignableFrom(exceptionType));

            var finalResult = ExceptionHandlerResult.Unhandled;

            foreach (var handler in matching)
            {
                ExceptionHandlerResult result = handler.Handle(instance, eevent, exception);
                if (result == ExceptionHandlerResult.Return)
                {
                    finalResult = ExceptionHandlerResult.Return;
                    continue;
                }

                if (result != ExceptionHandlerResult.Unhandled)
                {
                    return(result);
                }
            }

            return(finalResult);
        }
コード例 #3
0
        public ExceptionHandlerResult Handle(TInstance instance, Event eevent, TBody body, Exception exception)
        {
            Type exceptionType = exception.GetType();

            IEnumerable <EventExceptionHandler <TInstance, TBody> > matching = _handlers
                                                                               .Where(x => x.ExceptionType.IsAssignableFrom(exceptionType));

            foreach (var handler in matching)
            {
                ExceptionHandlerResult result = handler.Handle(instance, eevent, body, exception);
                if (result != ExceptionHandlerResult.Unhandled)
                {
                    return(result);
                }
            }

            return(ExceptionHandlerResult.Unhandled);
        }
コード例 #4
0
        public void Execute <T>(TInstance instance, T bodyT)
        {
            if (typeof(TBody) != typeof(T))
            {
                throw new StateMachineWorkflowException("Body type mismatch for message event: " + Event.Name);
            }

            var body = (TBody)((object)bodyT);

            while (true)
            {
                try
                {
                    _activities.Execute(instance, body);
                    return;
                }
                catch (Exception ex)
                {
                    try
                    {
                        ExceptionHandlerResult result = _exceptionHandler.Handle(instance, _event, body, ex);
                        if (result == ExceptionHandlerResult.Unhandled)
                        {
                            throw;
                        }

                        if (result == ExceptionHandlerResult.Return)
                        {
                            return;
                        }
                    }
                    catch (Exception innerException)
                    {
                        string message = "{0} occurred while handling {1} during {2}"
                                         .FormatWith(innerException.GetType().ToShortTypeName(), _event.Name, _state.Name);

                        throw new StateMachineWorkflowException(message, innerException);
                    }
                }
            }
        }