Exemplo n.º 1
0
        public InternalWorkerDataSync(IActionInvoker <TData> actionInvoker, ICounterBlocked counterBlocked)
        {
            counterBlocked.Increment();

            _actionInvoker  = actionInvoker;
            _counterBlocked = counterBlocked;
        }
Exemplo n.º 2
0
        private static bool CanSupportDynamicProxy(IActionInvoker actionInvoker)
        {
            var warnings = HttpContext.Current.GetWarnings();

            if (actionInvoker is ControllerActionInvoker)//TODO: What changes for AsyncControllerActionInvoker?
            {
                //Make sure there is a parameterless constructor and the type is not sealed
                var actionInvokerType  = actionInvoker.GetType();
                var proxy              = actionInvoker as IProxyTargetAccessor;
                var defaultConstructor = actionInvokerType.GetConstructor(new Type[] { });

                var result = (!actionInvokerType.IsSealed &&
                              defaultConstructor != null &&
                              proxy == null);

                if (!result)
                {
                    warnings.Add(new NotProxyableWarning(actionInvoker));
                }

                return(result);
            }

            warnings.Add(new NotAControllerActionInvokerWarning(actionInvoker));
            return(false);
        }
Exemplo n.º 3
0
        internal static bool CanSupportDynamicProxy(this IActionInvoker actionInvoker, IGlimpseLogger logger)
        {
            if (actionInvoker is ControllerActionInvoker)//TODO: What changes for AsyncControllerActionInvoker?
            {
                //Make sure there is a parameterless constructor and the type is not sealed
                var actionInvokerType  = actionInvoker.GetType();
                var proxy              = actionInvoker as IProxyTargetAccessor;
                var defaultConstructor = actionInvokerType.GetConstructor(new Type[] { });

                var result = (!actionInvokerType.IsSealed &&
                              defaultConstructor != null &&
                              proxy == null);

                if (!result)
                {
                    //TODO: Add logging
                }

                return(result);
            }

            //logger.Warn(actionInvoker.GetType() + " is not a System.Web.Mvc.ControllerActionInvoker.");
            //TODO add logging warnings.Add(new NotAControllerActionInvokerWarning(actionInvoker));
            return(false);
        }
Exemplo n.º 4
0
 public ViewPageResult(ContentItem thePage, IControllerMapper controllerMapper, IWebContext webContext, IActionInvoker actionInvoker)
 {
     _thePage          = thePage;
     _controllerMapper = controllerMapper;
     _webContext       = webContext;
     _actionInvoker    = actionInvoker;
 }
Exemplo n.º 5
0
        public Task RouteAsync(RouteContext context)
        {
            String?path = GetPath(context.HttpContext.Request.Path.Value);

            if (path == null)
            {
                throw new InvalidOperationException("Cannot resolve path " + context.HttpContext.Request.Path.Value);
            }

            IReadOnlyList <ActionDescriptor> candidates = SelectCandidates(_actionDescriptors.Items,
                                                                           context.HttpContext, context.RouteData.Values, path, context.HttpContext.Request.Method);

            if (candidates.Count == 0)
            {
                return(Task.CompletedTask);
            }
            if (candidates.Count > 1)
            {
                throw new InvalidOperationException("Ambiguous action " + path + " " + String.Join(";", candidates.Select(c => c.DisplayName)));
            }

            context.Handler = async ctx =>
            {
                var            actionContext = new ActionContext(context.HttpContext, ctx.GetRouteData(), candidates[0]);
                IActionInvoker actionInvoker = _actionInvokerFactory.CreateInvoker(actionContext);
                if (actionInvoker == null)
                {
                    return;
                }

                await actionInvoker.InvokeAsync().ConfigureAwait(false);
            };

            return(Task.CompletedTask);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LiteApiMiddleware"/> class.
        /// </summary>
        /// <param name="next">The next, provided by ASP.NET</param>
        /// <param name="options">The options, passed by <see cref="IApplicationBuilder"/> extension method.</param>
        /// <param name="services">The services, provided by ASP.NET</param>
        /// <exception cref="Exception">Middleware is already registered.</exception>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException">Assemblies with controllers is not passed to the LiteApiMiddleware</exception>
        public LiteApiMiddleware(RequestDelegate next, LiteApiOptions options, IServiceProvider services)
        {
            if (IsRegistered)
            {
                throw new Exception("Middleware is already registered.");
            }
            Options = options ?? throw new ArgumentNullException(nameof(options));

            options.InternalServiceResolver.Initialize(services, options);

            if (options.ControllerAssemblies?.Count == 0)
            {
                throw new ArgumentException("Assemblies with controllers is not passed to the LiteApiMiddleware");
            }
            if (options.LoggerFactory != null)
            {
                _logger           = new InternalLogger(true, options.LoggerFactory.CreateLogger <LiteApiMiddleware>());
                _isLoggingEnabled = true;
            }
            else
            {
                _logger = new InternalLogger(false, null);
            }
            // Services = services;
            _next        = next;
            IsRegistered = true;

            Initialize(services);

            _actionInvoker    = options.InternalServiceResolver.GetActionInvoker();
            _discoveryHandler = options.InternalServiceResolver.GetDiscoveryHandler();
            _pathResolver     = options.InternalServiceResolver.GetPathResolver();
        }
Exemplo n.º 7
0
 public InvokerBehavior(IContainer container, RequestContext requestContext,
                        IActionInvoker actionInvoker)
 {
     _container      = container;
     _requestContext = requestContext;
     _actionInvoker  = actionInvoker;
 }
Exemplo n.º 8
0
 public InvokerBehavior(IContainer container, ActionMethod actionMethod,
                        IActionInvoker actionInvoker)
 {
     _container     = container;
     _actionMethod  = actionMethod;
     _actionInvoker = actionInvoker;
 }
Exemplo n.º 9
0
            public void Register <TMessage>(object recipient, object token, bool receiveInheritedMessages, Action action)
            {
                IActionInvoker actionInvoker = CreateActionInvoker <TMessage>(recipient, action);

                RegisterCore(token, receiveInheritedMessages, typeof(TMessage), actionInvoker);
                RequestCleanup();
            }
Exemplo n.º 10
0
 public ViewPageResult(ContentItem thePage, IControllerMapper controllerMapper, IWebContext webContext, IActionInvoker actionInvoker)
 {
     _thePage = thePage;
     _controllerMapper = controllerMapper;
     _webContext = webContext;
     _actionInvoker = actionInvoker;
 }
Exemplo n.º 11
0
        public static CoursesController Create(
            IDependencyResolver value_iDependencyResolver,
            IActionInvoker value_iActionInvoker,
            ITempDataProvider value_iTempDataProvider,
            UrlHelper value_urlHelper,
            ViewEngineCollection value_viewEngineCollection,
            ControllerContext value_controllerContext,
            TempDataDictionary value_tempDataDictionary,
            bool value_b,
            IValueProvider value_iValueProvider,
            ViewDataDictionary value_viewDataDictionary
            )
        {
            CoursesController coursesController = new CoursesController();

            ((Controller)coursesController).Resolver         = value_iDependencyResolver;
            ((Controller)coursesController).ActionInvoker    = value_iActionInvoker;
            ((Controller)coursesController).TempDataProvider = value_iTempDataProvider;
            ((Controller)coursesController).Url = value_urlHelper;
            ((Controller)coursesController).ViewEngineCollection =
                value_viewEngineCollection;
            ((ControllerBase)coursesController).ControllerContext = value_controllerContext;
            ((ControllerBase)coursesController).TempData          = value_tempDataDictionary;
            ((ControllerBase)coursesController).ValidateRequest   = value_b;
            ((ControllerBase)coursesController).ValueProvider     = value_iValueProvider;
            ((ControllerBase)coursesController).ViewData          = value_viewDataDictionary;
            return(coursesController);

            // TODO: Edit factory method of CoursesController
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
Exemplo n.º 12
0
        public IWorkerChain Post <TData>(IActionInvoker <TData> actionInvoker, TData data, TimeSpan lifetime)
        {
            var internalWorkerValue = new InternalWorkerValueLifetime <TData>(actionInvoker, data, lifetime);

            _workerChainDefaults.Enqueue(internalWorkerValue);

            return(this);
        }
        public ServicesConfigProcessor(IActionInvoker actionInvoker, DeploymentServices deploymentServices)
            : base(actionInvoker)
        {
            _deploymentServices = deploymentServices;

            WhenStateChanges <ServicesConfigState>().FromEvent(s => s.ConfigChanged)
            .ToFlow().Action(NewConfiguration);
        }
Exemplo n.º 14
0
        public IWorkerChain Post <TData>(IActionInvoker <TData> actionInvoker, TData data)
        {
            var internalWorkerWalue = new InternalWorkerValue <TData>(actionInvoker, data);

            _workerChainDefaults.Enqueue(internalWorkerWalue);

            return(this);
        }
Exemplo n.º 15
0
 public SingleCommandInvoker(IActionInvoker moveActionInvoker,
                             IActionInvoker rotateLeftActionInvoker,
                             IActionInvoker rotateRightInvoker)
 {
     actionInvokerMap.Add("M", moveActionInvoker);
     actionInvokerMap.Add("L", rotateLeftActionInvoker);
     actionInvokerMap.Add("R", rotateRightInvoker);
 }
 public WorkerProgressReportCompleted(IQueueWorker sender,
                                      WorkerProgressData[] datas,
                                      IActionInvoker <WorkerCompletedData> actionInvoker)
     : base(datas)
 {
     _queueWorker   = sender;
     _actionInvoker = actionInvoker;
 }
Exemplo n.º 17
0
 protected virtual void Initialize(MvcApplication application, NavigationContext requestContext)
 {
     NavigationContext = requestContext;
     ActionInvoker     = new ControllerActionInvoker();
     ControllerContext = new ControllerContext {
         Application = application, NavigationContext = NavigationContext, Controller = this
     };
 }
Exemplo n.º 18
0
        protected StatefulActorModel(IActionInvoker actionInvoker, TModelState state)
            : base(state)
        {
            ActionInvoker = actionInvoker;

            Receive <IncommingEvent>(evt => evt.Action());
            Receive <IOperationResult>(OnOperationCompled);
        }
 public ViewPageResult(ContentItem thePage, IControllerMapper controllerMapper, IWebContext webContext, IActionInvoker actionInvoker)
 {
     this.controllerFactory = ControllerBuilder.Current.GetControllerFactory();
     this.thePage           = thePage;
     this.controllerMapper  = controllerMapper;
     this.webContext        = webContext;
     this.actionInvoker     = actionInvoker;
 }
Exemplo n.º 20
0
 public ViewPageResult(ContentItem thePage, IControllerMapper controllerMapper, IWebContext webContext, IActionInvoker actionInvoker)
 {
     this.controllerFactory = ControllerBuilder.Current.GetControllerFactory();
     this.thePage = thePage;
     this.controllerMapper = controllerMapper;
     this.webContext = webContext;
     this.actionInvoker = actionInvoker;
 }
        public SubmitActionNameActionInvoker(IActionInvoker actionInvoker)
        {
            if (actionInvoker == null)
            {
                throw new ArgumentNullException("actionInvoker");
            }

            _actionInvoker = actionInvoker;
        }
        public virtual void RegisterActionInvoker(IActionInvoker actionInvoker = null)
        {
            if (actionInvoker == null && _actionInvoker == null)
            {
                _actionInvoker = new ExpressionActionInvoker();
            }

            _actionInvoker = actionInvoker;
        }
        public virtual IActionInvoker GetActionInvoker()
        {
            if (_actionInvoker == null)
            {
                _actionInvoker = new ExpressionActionInvoker();
            }

            return(_actionInvoker);
        }
Exemplo n.º 24
0
        public void Post <TData>(IActionInvoker <TData> actionInvoker, TData data, TimeSpan lifetime)
        {
            if (actionInvoker == null)
            {
                throw new ArgumentNullException(nameof(actionInvoker));
            }

            _queueWorker.Post(new InternalWorkerValueLifetime <TData>(actionInvoker, data, lifetime));
        }
Exemplo n.º 25
0
        public void Post(IActionInvoker actionInvoker)
        {
            if (actionInvoker == null)
            {
                throw new ArgumentNullException(nameof(actionInvoker));
            }

            _queueWorker.Post(actionInvoker);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ActionInvokerWrapper"/> class that wraps the specified synchronous action invoker.
        /// </summary>
        /// <param name="actionInvoker">The synchronous action invoker to wrap.</param>
        /// <exception cref="ArgumentNullException"><paramref name="actionInvoker"/> is <c>null</c>.</exception>
        public ActionInvokerWrapper(IActionInvoker actionInvoker)
        {
            if (actionInvoker == null)
            {
                throw new ArgumentNullException(nameof(actionInvoker));
            }

            this.mActionInvoker = actionInvoker;
        }
Exemplo n.º 27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ActionInvokerWrapper"/> class that wraps the specified synchronous action invoker.
        /// </summary>
        /// <param name="actionInvoker">The synchronous action invoker to wrap.</param>
        /// <exception cref="ArgumentNullException"><paramref name="actionInvoker"/> is <c>null</c>.</exception>
        public ActionInvokerWrapper(IActionInvoker actionInvoker)
        {
            if (actionInvoker == null)
            {
                throw new ArgumentNullException("actionInvoker");
            }

            this.mActionInvoker = actionInvoker;
        }
Exemplo n.º 28
0
        private void OnMessage(IMessage message)
        {
            if (!message.IsResponse)
            {
                IActionInvoker invoker = this;

                invoker.Invoke(message).ContinueWith((t) => channelDispatcher.Post(t.Result));
            }
        }
 public ActionDeciderByPositionActionInvoker(IActionInvoker nActionInvoker,
                                             IActionInvoker sActionInvoker,
                                             IActionInvoker wActionInvoker,
                                             IActionInvoker eActionInvoker)
 {
     actionInvokerMap.Add(Direction.N, nActionInvoker);
     actionInvokerMap.Add(Direction.S, sActionInvoker);
     actionInvokerMap.Add(Direction.W, wActionInvoker);
     actionInvokerMap.Add(Direction.E, eActionInvoker);
 }
 public DeviserControllerFactory(ILifetimeScope container, IScopeService scopeService)
 {
     _logger           = container.Resolve <ILogger <DeviserControllerFactory> >();
     _actionInvoker    = container.Resolve <IActionInvoker>();
     _actionSelector   = container.Resolve <IActionSelector>();
     _htmlHelper       = container.Resolve <IHtmlHelper>();
     _pageRepository   = container.Resolve <IPageRepository>();
     _moduleRepository = container.Resolve <IModuleRepository>();
     _scopeService     = scopeService;
 }
Exemplo n.º 31
0
        /// <summary>
        /// Handle exception.
        /// </summary>
        /// <param name="context">The cu<see cref="Filters.ExceptionContext"/>.</param>
        /// <returns>The task to handle exception.</returns>
        public override async Task OnExceptionAsync(Filters.ExceptionContext context)
        {
            Guard.ArgumentNotNull(context, nameof(context));
            context.ExceptionHandled = true;
            _options = context.HttpContext.RequestServices.GetRequiredService <IOptions <HandleExceptionFilterOptions> >().Value;
            if (context.Exception == null)
            {
                return;
            }

            ExceptionManager manager         = context.HttpContext.RequestServices.GetRequiredService <ExceptionManager>();
            string           exceptionPolicy = this.GetExceptionPolicy(context);

            try
            {
                if (!string.IsNullOrEmpty(exceptionPolicy))
                {
                    await manager.HandleExceptionAsync(context.Exception, exceptionPolicy);
                }
                else
                {
                    manager.HandleExceptionAsync(context.Exception).Wait();
                }
            }
            catch (Exception ex)
            {
                ex = (ex as AggregateException)?.InnerException ?? ex;
                var exceptionInfo = new ExceptionInfo(ex, _options.IncludeInnerException);
                if (this.TryGetHandlerAction(context, out ActionDescriptor handlerAction))
                {
                    context.HttpContext.SetExceptionInfo(exceptionInfo);
                    ActionContext  actionContext = new ActionContext(context.HttpContext, context.RouteData, handlerAction);
                    IActionInvoker actionInvoker = context.HttpContext.RequestServices.GetRequiredService <IActionInvokerFactory>().CreateInvoker(actionContext);
                    await actionInvoker.InvokeAsync();

                    return;
                }

                if (context.HttpContext.IsAjaxRequest())
                {
                    JsonResult json = new JsonResult(exceptionInfo, _options.JsonSerializerSettings);
                    await json.ExecuteResultAsync(new ActionContext(context));

                    return;
                }
                var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), context.ModelState)
                {
                    Model = exceptionInfo
                };
                ViewResult view = new ViewResult {
                    ViewData = viewData
                };
                await view.ExecuteResultAsync(context);
            }
        }
Exemplo n.º 32
0
        public void ActionInvokerIsAsyncInvokerByDefault()
        {
            // Arrange
            EmptyController controller = new EmptyController();

            // Act
            IActionInvoker invoker = controller.ActionInvoker;

            // Assert
            Assert.IsInstanceOfType(invoker, typeof(AsyncControllerActionInvoker));
        }
Exemplo n.º 33
0
        public void ActionInvokerProperty()
        {
            // Arrange
            EmptyController controller = new EmptyController();

            // Act
            IActionInvoker invoker = controller.ActionInvoker;

            // Assert
            Assert.IsType <AsyncControllerActionInvoker>(invoker);
        }
        /// <summary>
        /// Gets the registered <see cref="IActionInvoker"/> within the system.
        /// </summary>
        /// <returns></returns>
        protected virtual IActionInvoker GetActionInvoker() {
            if (actionInvoker == null) {
                lock (_lock) {
                    if (actionInvoker == null) {
                        try {
                            actionInvoker = ServiceLocator.Resolve<IActionInvoker>();
                        }
                        catch (ServiceResolutionException) {
                            actionInvoker = new TurbineActionInvoker(InferredActions.Current);
                        }
                    }
                }
            }

            return actionInvoker;
        }
Exemplo n.º 35
0
        private static bool CanSupportDynamicProxy(IActionInvoker actionInvoker)
        {
            var warnings = HttpContext.Current.GetWarnings();

            if (actionInvoker is ControllerActionInvoker)//TODO: What changes for AsyncControllerActionInvoker?
            {
                //Make sure there is a parameterless constructor and the type is not sealed
                var actionInvokerType = actionInvoker.GetType();
                var proxy = actionInvoker as IProxyTargetAccessor;
                var defaultConstructor = actionInvokerType.GetConstructor(new Type[] { });

                var result = (!actionInvokerType.IsSealed &&
                        defaultConstructor != null &&
                        proxy == null);

                if (!result)
                    warnings.Add(new NotProxyableWarning(actionInvoker));

                return result;
            }

            warnings.Add(new NotAControllerActionInvokerWarning(actionInvoker));
            return false;
        }
Exemplo n.º 36
0
 /// <summary>
 /// Initialises this client.
 /// </summary>
 /// <param name="invoker">The invoker.</param>
 /// <returns></returns>
 public bool Initialise(IActionInvoker invoker)
 {
     this.Invoker = invoker;
     return this.OnInitialise();
 }
Exemplo n.º 37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseController"/> class.
 /// </summary>
 /// <param name="actionInvoker">The action invoker.</param>
 protected BaseController(IActionInvoker actionInvoker)
 {
     this.ActionInvoker = actionInvoker;
 }
 public InspectorActionInvoker(IActionInvoker invoker)
 {
     _invoker = invoker;
 }
Exemplo n.º 39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WcfChannel"/> class.
 /// </summary>
 /// <param name="invoker">The invoker.</param>
 public WcfChannel(IActionInvoker invoker)
 {
     this.Invoker = invoker;
 }
Exemplo n.º 40
0
 public ControllerBase()
 {
     _actionInvoker = new DefaultActionInvoker();
 }
Exemplo n.º 41
0
 public NHibernateControllerFactory(IActionInvoker actionInvoker)
     : base(actionInvoker)
 {
 }
 public CommandControllerActivator(IServiceLocator serviceLocator, IocActionInvoker actionInvoker)
 {
     _serviceLocator = serviceLocator;
     _actionInvoker = actionInvoker;
 }
Exemplo n.º 43
0
 protected virtual void Initialize(MvcApplication application, NavigationContext requestContext)
 {
     NavigationContext = requestContext;
     ActionInvoker = new ControllerActionInvoker();
     ControllerContext = new ControllerContext { Application = application, NavigationContext = NavigationContext, Controller = this };
 }
 public DependencyResolvingControllerFactory(IActionInvoker actionInvoker)
 {
     this.actionInvoker = actionInvoker;
 }
Exemplo n.º 45
0
 public ControllerBase()
 {
     this.ActionInvoker = new ControllerActionInvoker();
 }
 public DependencyResolvingControllerFactory()
 {
     this.actionInvoker = new ControllerActionInvoker();
 }
 public NotAControllerActionInvokerWarning(IActionInvoker actionInvoker)
 {
     Message = actionInvoker.GetType() + " is not a System.Web.Mvc.ControllerActionInvoker.";
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="WcfChannel"/> class.
 /// </summary>
 /// <param name="invoker">The invoker.</param>
 public WcfChannelInstanceProvider(IActionInvoker invoker)
 {
     this.Invoker = invoker;
 }
 public ActionInvokerWrapper(IActionInvoker actionInvoker)
 {
     this.actionInvoker = actionInvoker;
 }
Exemplo n.º 50
0
 public TestController(IActionInvoker invokerToUse)
 {
     this.ActionInvoker = invokerToUse;
 }