Ejemplo n.º 1
0
        private IUrlParamsMapper GetInferredTaxonFilterMapper(ControllerBase controller, string actionName)
        {
            var actionDescriptor = new ReflectedControllerDescriptor(controller.GetType()).FindAction(controller.ControllerContext, actionName);

            if (actionDescriptor == null || actionDescriptor.GetParameters().Length == 0)
            {
                return(null);
            }

            IUrlParamsMapper result = null;

            if (actionDescriptor.GetParameters()[0].ParameterType == typeof(ITaxon))
            {
                var taxonParamName = actionDescriptor.GetParameters()[0].ParameterName;
                if (actionDescriptor.GetParameters()[1].ParameterType == typeof(int?))
                {
                    var pageParamName = actionDescriptor.GetParameters()[1].ParameterName;
                    result = new CustomActionParamsMapper(controller, () => "/{" + taxonParamName + ":category,tag}/{" + pageParamName + "}", actionName);
                }

                result = result.SetLast(new CustomActionParamsMapper(controller, () => "/{" + taxonParamName + ":category,tag}", actionName));
            }

            return(result);
        }
Ejemplo n.º 2
0
        private IUrlParamsMapper GetInferredPagingMapper(ControllerBase controller, string actionName)
        {
            var actionDescriptor = new ReflectedControllerDescriptor(controller.GetType()).FindAction(controller.ControllerContext, actionName);

            if (actionDescriptor == null || actionDescriptor.GetParameters().Length == 0 || actionDescriptor.GetParameters()[0].ParameterType != typeof(int?))
            {
                return(null);
            }

            return(new CustomActionParamsMapper(controller, () => "/{" + actionDescriptor.GetParameters()[0].ParameterName + ":int}", actionName));
        }
        private IUrlParamsMapper GetInferredTaxonFilterMapper(ControllerBase controller, string actionName)
        {
            var actionDescriptor = new ReflectedControllerDescriptor(controller.GetType()).FindAction(controller.ControllerContext, actionName);

            if (actionDescriptor == null || actionDescriptor.GetParameters().Length == 0)
            {
                return(null);
            }

            var contentType = GetModelProperty(controller, "ContentType") as Type;

            if (contentType == null && controller is IDynamicContentWidget)
            {
                var dynamicType = controller.GetDynamicContentType();
                if (dynamicType != null)
                {
                    contentType = TypeResolutionService.ResolveType(dynamicType.GetFullTypeName());
                }
            }

            ISet <Guid> taxonomiesForType = null;

            if (contentType != null)
            {
                var properties = TypeDescriptor.GetProperties(contentType);
                taxonomiesForType = properties.OfType <TaxonomyPropertyDescriptor>().Select(x => x.TaxonomyId).ToHashSet();
            }

            if (taxonomiesForType != null && taxonomiesForType.Count == 0)
            {
                return(null);
            }

            IUrlParamsMapper result = null;

            if (actionDescriptor.GetParameters()[0].ParameterType == typeof(ITaxon))
            {
                string routeTemplate  = GenerateRouteTemplate(taxonomiesForType);
                var    taxonParamName = actionDescriptor.GetParameters()[0].ParameterName;
                if (actionDescriptor.GetParameters()[1].ParameterType == typeof(int?))
                {
                    var pageParamName = actionDescriptor.GetParameters()[1].ParameterName;
                    var urlParamNames = new string[] { FeatherActionInvoker.TaxonNamedParamter, FeatherActionInvoker.PagingNamedParameter };
                    result = new CustomActionParamsMapper(controller, () => "/{" + taxonParamName + ":" + routeTemplate + "}/{" + pageParamName + "}", actionName, urlParamNames);
                }

                var urlTaxonParamNames = new string[] { FeatherActionInvoker.TaxonNamedParamter };
                result = result.SetLast(new CustomActionParamsMapper(controller, () => "/{" + taxonParamName + ":" + routeTemplate + "}", actionName, urlTaxonParamNames));
            }

            return(result);
        }
Ejemplo n.º 4
0
        private IUrlParamsMapper GetInferredDetailActionParamsMapper(ControllerBase controller)
        {
            var controllerType      = controller.GetType();
            IUrlParamsMapper result = null;

            var detailsAction = new ReflectedControllerDescriptor(controllerType).FindAction(controller.ControllerContext, DetailActionParamsMapper.DefaultActionName);

            if (detailsAction != null)
            {
                var contentParam = detailsAction.GetParameters().FirstOrDefault();
                if (contentParam != null && contentParam.ParameterType.ImplementsInterface(typeof(IDataItem)))
                {
                    Type contentType;
                    if (typeof(DynamicContent) == contentParam.ParameterType)
                    {
                        var dynamicContentType = controller.GetDynamicContentType();
                        contentType = dynamicContentType != null?TypeResolutionService.ResolveType(dynamicContentType.GetFullTypeName(), throwOnError : false) : null;
                    }
                    else
                    {
                        contentType = contentParam.ParameterType;
                    }

                    if (contentType != null)
                    {
                        var providerNames = this.GetModelProperty(controller, "ProviderName") as string;
                        result = result.SetLast(new DetailActionParamsMapper(controller, contentType, () => providerNames));
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the type of the content item for specified controller.
        /// </summary>
        /// <param name="controller">The controller.</param>
        private Type GetItemType(ControllerBase controller)
        {
            var  controllerType = controller.GetType();
            Type contentType    = null;
            var  detailsAction  = new ReflectedControllerDescriptor(controllerType).FindAction(controller.ControllerContext, DetailActionParamsMapper.DefaultActionName);

            if (detailsAction != null)
            {
                var contentParam = detailsAction.GetParameters().FirstOrDefault();
                if (contentParam != null && contentParam.ParameterType.ImplementsInterface(typeof(IDataItem)))
                {
                    if (typeof(DynamicContent) == contentParam.ParameterType)
                    {
                        var controllerName     = this.GetControllerName(controller);
                        var dynamicContentType = controller.GetDynamicContentType(controllerName);
                        contentType = dynamicContentType != null?TypeResolutionService.ResolveType(dynamicContentType.GetFullTypeName(), throwOnError : false) : null;
                    }
                    else
                    {
                        contentType = contentParam.ParameterType;
                    }
                }
            }

            return(contentType);
        }
Ejemplo n.º 6
0
        private IUrlParamsMapper GetInferredClassificationFilterMapper(ControllerBase controller, string actionName)
        {
            var actionDescriptor = new ReflectedControllerDescriptor(controller.GetType()).FindAction(controller.ControllerContext, actionName);

            if (actionDescriptor == null || actionDescriptor.GetParameters().Length == 0)
            {
                return(null);
            }

            return(new TaxonomyUrlParamsMapper(controller, new TaxonUrlMapper(new TaxonUrlEvaluatorAdapter())));
        }
Ejemplo n.º 7
0
        private IUrlParamsMapper GetInferredTaxonFilterQueryParamsMapper(ControllerBase controller, string actionName)
        {
            IUrlParamsMapper result = null;

            var actionDescriptor = new ReflectedControllerDescriptor(controller.GetType()).FindAction(controller.ControllerContext, actionName);

            if (actionDescriptor == null || actionDescriptor.GetParameters().Length == 0)
            {
                return(null);
            }

            var queryParams = controller.ControllerContext.RequestContext.HttpContext.Request.QueryString;

            if (actionDescriptor.GetParameters()[0].ParameterType == typeof(ITaxon) && queryParams.Count == 3)
            {
                if (queryParams.Keys.Contains("taxonomy"))
                {
                    result = new TaxonomyUrlParamsMapper(controller, new TaxonUrlMapper(new TaxonUrlEvaluatorAdapter()));
                }
            }

            return(result);
        }