/// <summary>
        /// This method is called by Web API system to select the controller for this request.
        /// </summary>
        /// <param name="request">Request object</param>
        /// <returns>The controller to be used</returns>
        public override HttpControllerDescriptor SelectController(HttpRequestMessage request)
        {
            //Get request and route data
            if (request == null)
            {
                return(base.SelectController(null));
            }

            var routeData = request.GetRouteData();

            if (routeData == null)
            {
                return(base.SelectController(request));
            }

            //Get serviceNameWithAction from route
            string serviceNameWithAction;

            if (!routeData.Values.TryGetValue("serviceNameWithAction", out serviceNameWithAction))
            {
                return(base.SelectController(request));
            }

            //Normalize serviceNameWithAction
            if (serviceNameWithAction.EndsWith("/"))
            {
                serviceNameWithAction = serviceNameWithAction.Substring(0, serviceNameWithAction.Length - 1);
                routeData.Values["serviceNameWithAction"] = serviceNameWithAction;
            }

            //Get the dynamic controller
            var hasActionName  = false;
            var controllerInfo = _dynamicApiControllerManager.FindOrNull(serviceNameWithAction);

            if (controllerInfo == null)
            {
                if (!DynamicApiServiceNameHelper.IsValidServiceNameWithAction(serviceNameWithAction))
                {
                    return(base.SelectController(request));
                }

                var serviceName = DynamicApiServiceNameHelper.GetServiceNameInServiceNameWithAction(serviceNameWithAction);
                controllerInfo = _dynamicApiControllerManager.FindOrNull(serviceName);
                if (controllerInfo == null)
                {
                    return(base.SelectController(request));
                }

                hasActionName = true;
            }

            //Create the controller descriptor
            var controllerDescriptor = new DynamicHttpControllerDescriptor(_configuration, controllerInfo);

            controllerDescriptor.Properties["__AbpDynamicApiControllerInfo"] = controllerInfo;
            controllerDescriptor.Properties["__AbpDynamicApiHasActionName"]  = hasActionName;
            return(controllerDescriptor);
        }
        /// <summary>
        /// This method is called by Web API system to select the controller for this request.
        /// </summary>
        /// <param name="request">Request object</param>
        /// <returns>The controller to be used</returns>
        public override HttpControllerDescriptor SelectController(HttpRequestMessage request)
        {
            //Get request and route data
            if (request == null)
            {
                return base.SelectController(null);
            }

            var routeData = request.GetRouteData();
            if (routeData == null)
            {
                return base.SelectController(request);
            }

            //Get serviceNameWithAction from route
            string serviceNameWithAction;
            if (!routeData.Values.TryGetValue("serviceNameWithAction", out serviceNameWithAction))
            {
                return base.SelectController(request);
            }

            //Normalize serviceNameWithAction
            if (serviceNameWithAction.EndsWith("/"))
            {
                serviceNameWithAction = serviceNameWithAction.Substring(0, serviceNameWithAction.Length - 1);
                routeData.Values["serviceNameWithAction"] = serviceNameWithAction;
            }

            //Get the dynamic controller
            var hasActionName = false;
            var controllerInfo = DynamicApiControllerManager.FindOrNull(serviceNameWithAction);
            if (controllerInfo == null)
            {
                if (!DynamicApiServiceNameHelper.IsValidServiceNameWithAction(serviceNameWithAction))
                {
                    return base.SelectController(request);
                }

                var serviceName = DynamicApiServiceNameHelper.GetServiceNameInServiceNameWithAction(serviceNameWithAction);
                controllerInfo = DynamicApiControllerManager.FindOrNull(serviceName);
                if (controllerInfo == null)
                {
                    return base.SelectController(request);
                }

                hasActionName = true;
            }

            //Create the controller descriptor
            var controllerDescriptor = new DynamicHttpControllerDescriptor(_configuration, controllerInfo.ServiceName, controllerInfo.ApiControllerType, controllerInfo.Filters);
            controllerDescriptor.Properties["__AbpDynamicApiControllerInfo"] = controllerInfo;
            controllerDescriptor.Properties["__AbpDynamicApiHasActionName"] = hasActionName;
            return controllerDescriptor;
        }
Пример #3
0
        private Collection<ApiDescription> InitializeApiDescriptions()
        {
            var apiDescriptions = new Collection<ApiDescription>();

            foreach (var item in base.ApiDescriptions)
            {
                apiDescriptions.Add(item);
            }

            var dynamicApiControllerInfos = _dynamicApiControllerManager.GetAll();
            foreach (var dynamicApiControllerInfo in dynamicApiControllerInfos)
            {
                if (IsApiExplorerDisabled(dynamicApiControllerInfo))
                {
                    continue;
                }

                foreach (var dynamicApiActionInfo in dynamicApiControllerInfo.Actions.Values)
                {
                    if (IsApiExplorerDisabled(dynamicApiActionInfo))
                    {
                        continue;
                    }

                    var apiDescription = new ApiDescription();

                    var controllerDescriptor = new DynamicHttpControllerDescriptor(_abpWebApiConfiguration.HttpConfiguration, dynamicApiControllerInfo);
                    var actionDescriptor = new DynamicHttpActionDescriptor(_abpWebApiConfiguration, controllerDescriptor, dynamicApiActionInfo);

                    apiDescription.ActionDescriptor = actionDescriptor;
                    apiDescription.HttpMethod = actionDescriptor.SupportedHttpMethods[0];

                    var actionValueBinder = _abpWebApiConfiguration.HttpConfiguration.Services.GetActionValueBinder();
                    var actionBinding = actionValueBinder.GetBinding(actionDescriptor);

                    apiDescription.ParameterDescriptions.Clear();
                    foreach (var apiParameterDescription in CreateParameterDescription(actionBinding, actionDescriptor))
                    {
                        apiDescription.ParameterDescriptions.Add(apiParameterDescription);
                    }

                    SetResponseDescription(apiDescription, actionDescriptor);

                    apiDescription.RelativePath = "api/services/" + dynamicApiControllerInfo.ServiceName + "/" + dynamicApiActionInfo.ActionName;

                    apiDescriptions.Add(apiDescription);
                }
            }

            return apiDescriptions;
        }
        /// <summary>
        /// This method is called by Web API system to select the controller for this request.
        /// </summary>
        /// <param name="request">Request object</param>
        /// <returns>The controller to be used</returns>
        public override HttpControllerDescriptor SelectController(HttpRequestMessage request)
        {
            if (request != null)
            {
                var routeData = request.GetRouteData();
                if (routeData != null)
                {
                    string serviceNameWithAction;
                    if (routeData.Values.TryGetValue("serviceNameWithAction", out serviceNameWithAction) && DynamicApiServiceNameHelper.IsValidServiceNameWithAction(serviceNameWithAction))
                    {
                        var serviceName    = DynamicApiServiceNameHelper.GetServiceNameInServiceNameWithAction(serviceNameWithAction);
                        var controllerInfo = DynamicApiControllerManager.FindOrNull(serviceName);
                        if (controllerInfo != null)
                        {
                            var controllerDescriptor = new DynamicHttpControllerDescriptor(_configuration, controllerInfo.ServiceName, controllerInfo.Type, controllerInfo.Filters);
                            controllerDescriptor.Properties["__AbpDynamicApiControllerInfo"] = controllerInfo;
                            return(controllerDescriptor);
                        }
                    }
                }
            }

            return(base.SelectController(request));
        }
        /// <summary>
        /// This method is called by Web API system to select the controller for this request.
        /// </summary>
        /// <param name="request">Request object</param>
        /// <returns>The controller to be used</returns>
        public override HttpControllerDescriptor SelectController(HttpRequestMessage request)
        {
            if (request != null)
            {
                var routeData = request.GetRouteData();
                if (routeData != null)
                {
                    string serviceNameWithAction;
                    if (routeData.Values.TryGetValue("serviceNameWithAction", out serviceNameWithAction) && DynamicApiServiceNameHelper.IsValidServiceNameWithAction(serviceNameWithAction))
                    {
                        var serviceName = DynamicApiServiceNameHelper.GetServiceNameInServiceNameWithAction(serviceNameWithAction);
                        var controllerInfo = DynamicApiControllerManager.FindOrNull(serviceName);
                        if (controllerInfo != null)
                        {
                            var controllerDescriptor = new DynamicHttpControllerDescriptor(_configuration, controllerInfo.ServiceName, controllerInfo.Type, controllerInfo.Filters);
                            controllerDescriptor.Properties["__AbpDynamicApiControllerInfo"] = controllerInfo;
                            return controllerDescriptor;
                        }
                    }
                }
            }

            return base.SelectController(request);
        }