예제 #1
0
        private static ActionExecutedContext InvokeActionFilter(IActionFilter filter, 
            ActionExecutionContext context, Func<ActionExecutedContext> continuation)
        {
            filter.OnExecuting(context);
            if (context.Cancel)
                return new ActionExecutedContext(context, null) { 
					Result = context.Result 
				};

            bool wasError = false;
            ActionExecutedContext postContext = null;
            try
            {
                postContext = continuation();
            }
            catch (Exception ex)
            {
                wasError = true;
                postContext = new ActionExecutedContext(context, ex);
                filter.OnExecuted(postContext);

                if (!postContext.ExceptionHandled)
                    throw;
            }
            if (!wasError)
                filter.OnExecuted(postContext);
            
            return postContext;
        }
예제 #2
0
        private static ActionExecutedContext InvokeActionFilter(IActionFilter filter,
                                                                ActionExecutionContext context, Func <ActionExecutedContext> continuation)
        {
            filter.OnExecuting(context);
            if (context.Cancel)
            {
                return new ActionExecutedContext(context, null)
                       {
                           Result = context.Result
                       }
            }
            ;

            bool wasError = false;
            ActionExecutedContext postContext = null;

            try
            {
                postContext = continuation();
            }
            catch (Exception ex)
            {
                wasError    = true;
                postContext = new ActionExecutedContext(context, ex);
                filter.OnExecuted(postContext);

                if (!postContext.ExceptionHandled)
                {
                    throw;
                }
            }
            if (!wasError)
            {
                filter.OnExecuted(postContext);
            }

            return(postContext);
        }
예제 #3
0
        protected static Func <ActionExecutedContext> InvokeActionFilterAsynchronously(IActionFilter filter,
                                                                                       ActionExecutionContext preContext, Func <Func <ActionExecutedContext> > next)
        {
            filter.OnExecuting(preContext);
            if (preContext.Result != null)
            {
                ActionExecutedContext shortCircuitedPostContext = new ActionExecutedContext(preContext, null)
                {
                    Result = preContext.Result
                };
                return(() => shortCircuitedPostContext);
            }
            try
            {
                Func <ActionExecutedContext> continuation = next();
                return(() => {
                    ActionExecutedContext postContext;
                    bool wasError = true;
                    try
                    {
                        postContext = continuation();
                        wasError = false;
                    }
                    catch (ThreadAbortException)
                    {
                        postContext = new ActionExecutedContext(preContext, null);
                        filter.OnExecuted(postContext);

                        throw;
                    }
                    catch (Exception ex)
                    {
                        postContext = new ActionExecutedContext(preContext, ex);
                        filter.OnExecuted(postContext);

                        if (!postContext.ExceptionHandled)
                        {
                            throw;
                        }
                    }
                    if (!wasError)
                    {
                        filter.OnExecuted(postContext);
                    }

                    return postContext;
                });
            }
            catch (ThreadAbortException)
            {
                ActionExecutedContext postContext =
                    new ActionExecutedContext(preContext, null);

                filter.OnExecuted(postContext);
                throw;
            }
            catch (Exception ex)
            {
                ActionExecutedContext postContext = new ActionExecutedContext(preContext, ex);
                filter.OnExecuted(postContext);
                if (postContext.ExceptionHandled)
                {
                    return(() => postContext);
                }

                throw;
            }
        }
		protected static Func<ActionExecutedContext> InvokeActionFilterAsynchronously(IActionFilter filter,
			ActionExecutionContext preContext, Func<Func<ActionExecutedContext>> next)
		{
			filter.OnExecuting(preContext);
			if (preContext.Result != null)
			{
				ActionExecutedContext shortCircuitedPostContext = new ActionExecutedContext(preContext, null) {
					Result = preContext.Result
				};
				return () => shortCircuitedPostContext;
			}
			try
			{
				Func<ActionExecutedContext> continuation = next();
				return () => {
					ActionExecutedContext postContext;
					bool wasError = true;
					try
					{
						postContext = continuation();
						wasError = false;
					}
					catch (ThreadAbortException)
					{
						postContext = new ActionExecutedContext(preContext, null);
						filter.OnExecuted(postContext);

						throw;
					}
					catch (Exception ex)
					{
						postContext = new ActionExecutedContext(preContext, ex);
						filter.OnExecuted(postContext);

						if (!postContext.ExceptionHandled)
							throw;
					}
					if (!wasError)
						filter.OnExecuted(postContext);

					return postContext;
				};
			}
			catch (ThreadAbortException)
			{
				ActionExecutedContext postContext =
					new ActionExecutedContext(preContext, null);

				filter.OnExecuted(postContext);
				throw;
			}
			catch (Exception ex)
			{
				ActionExecutedContext postContext = new ActionExecutedContext(preContext, ex);
				filter.OnExecuted(postContext);
				if (postContext.ExceptionHandled)
					return () => postContext;

				throw;
			}
		}