Ejemplo n.º 1
0
        public PageActionInvoker(
            DiagnosticListener diagnosticSource,
            ILogger logger,
            IPageFactory factory,
            IPageModelFactory modelFactory,
            IPageHandlerMethodSelector selector,
            IModelMetadataProvider metadataProvider,
            ITempDataDictionaryFactory tempDataFactory,
            IOptions <MvcViewOptions> viewOptions,
            IFilterMetadata[] filters,
            IReadOnlyList <IValueProviderFactory> valueProviderFactories,
            ActionContext actionContext,
            CompiledPageActionDescriptor actionDescriptor,
            TempDataPropertyProvider tempDataPropertyProvider)
        {
            _diagnosticSource         = diagnosticSource;
            _logger                   = logger;
            _factory                  = factory;
            _modelFactory             = modelFactory;
            _selector                 = selector;
            _metadataProvider         = metadataProvider;
            _tempDataFactory          = tempDataFactory;
            _viewOptions              = viewOptions.Value;
            _filters                  = filters;
            _valueProviderFactories   = new CopyOnWriteList <IValueProviderFactory>(valueProviderFactories);
            _actionContext            = actionContext;
            _actionDescriptor         = actionDescriptor;
            _tempDataPropertyProvider = tempDataPropertyProvider;

            _cursor = new FilterCursor(_filters);
        }
Ejemplo n.º 2
0
 public ControllerActionInvokerInternal(
     ControllerContext controllerContext,
     ActionDescriptor actionDescriptor,
     IDictionary <string, object> parameters,
     IEnumerable <Filter> filters)
 {
     _controllerContext = controllerContext;
     _actionDescriptor  = actionDescriptor;
     _parameters        = parameters;
     _cursor            = new FilterCursor(filters);
 }
Ejemplo n.º 3
0
        public virtual async Task InvokeAsync()
        {
            _filters = GetFilters();
            _cursor  = new FilterCursor(_filters);

            await InvokeAllAuthorizationFiltersAsync();

            // If Authorization Filters return a result, it's a short circuit because
            // authorization failed. We don't execute Result Filters around the result.
            Debug.Assert(_authorizationContext != null);
            if (_authorizationContext.Result != null)
            {
                await _authorizationContext.Result.ExecuteResultAsync(ActionContext);

                return;
            }

            // >> ExceptionFilters >> ActionFilters >> Action
            await InvokeAllExceptionFiltersAsync();

            // If Exception Filters provide a result, it's a short-circuit due to an exception.
            // We don't execute Result Filters around the result.
            Debug.Assert(_exceptionContext != null);
            if (_exceptionContext.Result != null)
            {
                await _exceptionContext.Result.ExecuteResultAsync(ActionContext);
            }
            else if (_exceptionContext.Exception != null)
            {
                // If we get here, this means that we have an unhandled exception
                if (_exceptionContext.ExceptionDispatchInfo != null)
                {
                    _exceptionContext.ExceptionDispatchInfo.Throw();
                }
                else
                {
                    throw _exceptionContext.Exception;
                }
            }
            else
            {
                // We have a successful 'result' from the action or an Action Filter, so run
                // Result Filters.
                Debug.Assert(_actionExecutedContext != null);
                var result = _actionExecutedContext.Result;

                // >> ResultFilters >> (Result)
                await InvokeAllResultFiltersAsync(result);
            }
        }
Ejemplo n.º 4
0
        public virtual async Task InvokeAsync()
        {
            _filters = GetFilters();
            _cursor  = new FilterCursor(_filters);

            ActionContext.ModelState.MaxAllowedErrors = _maxModelValidationErrors;

            await InvokeAllAuthorizationFiltersAsync();

            // If Authorization Filters return a result, it's a short circuit because
            // authorization failed. We don't execute Result Filters around the result.
            Debug.Assert(_authorizationContext != null);
            if (_authorizationContext.Result != null)
            {
                await InvokeResultAsync(_authorizationContext.Result);

                return;
            }

            try
            {
                await InvokeAllResourceFiltersAsync();
            }
            finally
            {
                // Release the instance after all filters have run. We don't need to surround
                // Authorizations filters because the instance will be created much later than
                // that.
                if (Instance != null)
                {
                    ReleaseInstance(Instance);
                }
            }

            // We've reached the end of resource filters. If there's an unhandled exception on the context then
            // it should be thrown and middleware has a chance to handle it.
            Debug.Assert(_resourceExecutedContext != null);
            if (_resourceExecutedContext.Exception != null && !_resourceExecutedContext.ExceptionHandled)
            {
                if (_resourceExecutedContext.ExceptionDispatchInfo == null)
                {
                    throw _resourceExecutedContext.Exception;
                }
                else
                {
                    _resourceExecutedContext.ExceptionDispatchInfo.Throw();
                }
            }
        }
Ejemplo n.º 5
0
        public ResourceInvoker(
            DiagnosticSource diagnosticSource,
            ILogger logger,
            IActionResultTypeMapper mapper,
            ActionContext actionContext,
            IFilterMetadata[] filters,
            IList <IValueProviderFactory> valueProviderFactories)
        {
            _diagnosticSource = diagnosticSource ?? throw new ArgumentNullException(nameof(diagnosticSource));
            _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
            _mapper           = mapper ?? throw new ArgumentNullException(nameof(mapper));
            _actionContext    = actionContext ?? throw new ArgumentNullException(nameof(actionContext));

            _filters = filters ?? throw new ArgumentNullException(nameof(filters));
            _valueProviderFactories = valueProviderFactories ?? throw new ArgumentNullException(nameof(valueProviderFactories));
            _cursor = new FilterCursor(filters);
        }
Ejemplo n.º 6
0
        public async Task InvokeAsync()
        {
            _filters = GetFilters();
            _cursor  = new FilterCursor(_filters);

            _module = (MvcModule)_moduleFactory.CreateModule(Context);
            using (_module as IDisposable)
            {
                await InvokeAllModuleFiltersAsync();

                if (_moduleExecutedContext.Canceled)
                {
                    await _moduleExecutedContext.Result.ExecuteResultAsync(Context);

                    return;
                }

                await InvokeAllResultFiltersAsync(_moduleExecutedContext.Result);
            }
        }
Ejemplo n.º 7
0
        public async Task InvokeActionAsync()
        {
            _actionContext.Controller = _controllerFactory.CreateController(_actionContext);

            _filters = GetFilters();
            _cursor  = new FilterCursor(_filters);

            // >> ExceptionFilters >> AuthorizationFilters >> ActionFilters >> Action
            await InvokeActionExceptionFilters();

            // If Exception Filters or Authorization Filters provide a result, it's a short-circuit, we don't execute
            // result filters around it.
            if (_authorizationContext.Result != null)
            {
                await _authorizationContext.Result.ExecuteResultAsync(_actionContext);
            }
            else if (_exceptionContext.Result != null)
            {
                await _exceptionContext.Result.ExecuteResultAsync(_actionContext);
            }
            else if (_exceptionContext.Exception != null)
            {
                // If we get here, this means that we have an unhandled exception
                if (_exceptionContext.ExceptionDispatchInfo != null)
                {
                    _exceptionContext.ExceptionDispatchInfo.Throw();
                }
                else
                {
                    throw _exceptionContext.Exception;
                }
            }
            else
            {
                var result = _actionExecutedContext.Result;

                // >> ResultFilters >> (Result)
                await InvokeActionResultWithFilters(result);
            }
        }