public virtual HttpActionDescriptor SelectAction(HttpControllerContext controllerContext)
        {
            if (controllerContext == null)
            {
                throw Error.ArgumentNull("controllerContext");
            }

            ActionSelectorCacheItem internalSelector = GetInternalSelector(controllerContext.ControllerDescriptor);

            return(internalSelector.SelectAction(controllerContext));
        }
        public override HttpActionDescriptor SelectAction(HttpControllerContext controllerContext)
        {
            if (controllerContext == null)
            {
                throw
                    new Exception
                    (
                        @"Error.ArgumentNull(""controllerContext"")"
                    );
            }

            ActionSelectorCacheItem internalSelector = GetInternalSelector(controllerContext.ControllerDescriptor);

            return(internalSelector.SelectAction(controllerContext));
        }
Exemplo n.º 3
0
        public virtual ActionDescriptor SelectAction(ControllerContext controllerContext)
        {
            if (controllerContext == null)
            {
                throw Error.ArgumentNull("controllerContext");
            }
            var controller = controllerContext.Controller as Controller;
            if (controller == null)
            {
                throw new InvalidOperationException("Controller must inherit from System.Web.Mvc.Controller");
            }
            ApiControllerActionInvoker invoker = controller.ActionInvoker as ApiControllerActionInvoker;
            if (invoker == null)
            {
                throw new InvalidOperationException("ActionInvoker must inherit from ApiControllerActionInvoker.");
            }

            var controllerDescriptor = invoker.GetControllerDescriptor(controller.GetType());
            Func<object, object> valueFactory = null;

            if (this.cachedActionSelector == null)
            {
                ActionSelectorCacheItem actionSelectorItem = new ActionSelectorCacheItem(controllerDescriptor);
                Interlocked.CompareExchange<ActionSelectorCacheItem>(ref this.cachedActionSelector, actionSelectorItem, null);
                return actionSelectorItem.SelectAction(controllerContext);
            }
            if (this.cachedActionSelector.ControllerDescriptor == controllerDescriptor)
            {
                return this.cachedActionSelector.SelectAction(controllerContext);
            }
            if (valueFactory == null)
            {
                valueFactory = _ => new ActionSelectorCacheItem(controllerDescriptor);
            }
            var properties = ((ApiControllerDescriptor)controllerDescriptor).Properties;
            ActionSelectorCacheItem orAdd = (ActionSelectorCacheItem)properties.GetOrAdd(this._cacheKey, valueFactory);
            return orAdd.SelectAction(controllerContext);
        }