private IViewComponentResult InvokeSyncCore(ViewComponentContext context)
        {
            var component = CreateComponent(context);

            using (_logger.ViewComponentScope(context))
            {
                var method    = context.ViewComponentDescriptor.MethodInfo;
                var arguments = ControllerActionExecutor.PrepareArguments(
                    context.Arguments,
                    method.GetParameters());

                _diagnosticSource.BeforeViewComponent(context, component);
                _logger.ViewComponentExecuting(context, arguments);

                var    startTimestamp = _logger.IsEnabled(LogLevel.Debug) ? Stopwatch.GetTimestamp() : 0;
                object result;
                try
                {
                    result = method.Invoke(component, arguments);
                }
                catch (TargetInvocationException ex)
                {
                    // Preserve callstack of any user-thrown exceptions.
                    var exceptionInfo = ExceptionDispatchInfo.Capture(ex.InnerException);
                    exceptionInfo.Throw();
                    return(null); // Unreachable
                }

                var viewComponentResult = CoerceToViewComponentResult(result);
                _logger.ViewComponentExecuted(context, startTimestamp, viewComponentResult);
                _diagnosticSource.AfterViewComponent(context, viewComponentResult, component);

                return(viewComponentResult);
            }
        }
Пример #2
0
        private async Task <IViewComponentResult> InvokeAsyncCore(ViewComponentContext context)
        {
            var component = _viewComponentFactory.CreateViewComponent(context);

            using (_logger.ViewComponentScope(context))
            {
                var method    = context.ViewComponentDescriptor.MethodInfo;
                var arguments = ControllerActionExecutor.PrepareArguments(context.Arguments, method.GetParameters());

                var methodExecutor = _viewComponentInvokerCache.GetViewComponentMethodExecutor(context);

                _diagnosticSource.BeforeViewComponent(context, component);
                _logger.ViewComponentExecuting(context, arguments);

                var startTimestamp = _logger.IsEnabled(LogLevel.Debug) ? Stopwatch.GetTimestamp() : 0;
                var result         = await ControllerActionExecutor.ExecuteAsync(methodExecutor, component, arguments);

                var viewComponentResult = CoerceToViewComponentResult(result);
                _logger.ViewComponentExecuted(context, startTimestamp, viewComponentResult);
                _diagnosticSource.AfterViewComponent(context, viewComponentResult, component);

                _viewComponentFactory.ReleaseViewComponent(context, component);

                return(viewComponentResult);
            }
        }
Пример #3
0
        private IViewComponentResult InvokeSyncCore(ObjectMethodExecutor executor, ViewComponentContext context)
        {
            var component = _viewComponentFactory.CreateViewComponent(context);

            using (_logger.ViewComponentScope(context))
            {
                var arguments = ControllerActionExecutor.PrepareArguments(
                    context.Arguments,
                    executor);

                _diagnosticSource.BeforeViewComponent(context, component);
                _logger.ViewComponentExecuting(context, arguments);

                var    startTimestamp = _logger.IsEnabled(LogLevel.Debug) ? Stopwatch.GetTimestamp() : 0;
                object result;

                try
                {
                    result = executor.Execute(component, arguments);
                }
                finally
                {
                    _viewComponentFactory.ReleaseViewComponent(context, component);
                }

                var viewComponentResult = CoerceToViewComponentResult(result);
                _logger.ViewComponentExecuted(context, startTimestamp, viewComponentResult);
                _diagnosticSource.AfterViewComponent(context, viewComponentResult, component);

                _viewComponentFactory.ReleaseViewComponent(context, component);

                return(viewComponentResult);
            }
        }
        private async Task <IWebSocketActionResult> InvokeActionMethodAsync(ObjectMethodExecutor executor, object controller, IDictionary <string, object> parameters)
        {
            // Order the parameters used to invoke the action
            var orderedParameters = ControllerActionExecutor.PrepareArguments(parameters, executor);

            // Execute the action
            var resultAsObject = executor.Execute(controller, orderedParameters);

            // If the result is not of type IWebSocketActionResult, create a WebSocketObjectResult with the result
            return(resultAsObject as IWebSocketActionResult ?? new WebSocketObjectResult(resultAsObject));
        }
Пример #5
0
        private async Task <IViewComponentResult> InvokeAsyncCore(ObjectMethodExecutor executor, ViewComponentContext context)
        {
            var component = _viewComponentFactory.CreateViewComponent(context);

            using (_logger.ViewComponentScope(context))
            {
                var arguments = ControllerActionExecutor.PrepareArguments(context.Arguments, executor);

                _diagnosticSource.BeforeViewComponent(context, component);
                _logger.ViewComponentExecuting(context, arguments);

                var startTimestamp = _logger.IsEnabled(LogLevel.Debug) ? Stopwatch.GetTimestamp() : 0;

                object resultAsObject  = null;
                var    taskGenericType = executor.TaskGenericType;

                if (taskGenericType == typeof(IViewComponentResult))
                {
                    resultAsObject = await(Task <IViewComponentResult>) executor.Execute(component, arguments);
                }
                else if (taskGenericType == typeof(string))
                {
                    resultAsObject = await(Task <string>) executor.Execute(component, arguments);
                }
                else if (taskGenericType == typeof(IHtmlContent))
                {
                    resultAsObject = await(Task <IHtmlContent>) executor.Execute(component, arguments);
                }
                else
                {
                    resultAsObject = await executor.ExecuteAsync(component, arguments);
                }

                var viewComponentResult = CoerceToViewComponentResult(resultAsObject);
                _logger.ViewComponentExecuted(context, startTimestamp, viewComponentResult);
                _diagnosticSource.AfterViewComponent(context, viewComponentResult, component);

                _viewComponentFactory.ReleaseViewComponent(context, component);

                return(viewComponentResult);
            }
        }