Esempio n. 1
0
        private static RouteValueDictionary GetConstraints(RouteConfigurationElement route)
        {
            try
            {
                var dictionary = GetDictionaryFromAttributes(route.Constraints.Attributes);

                for (var i = 0; i < route.Constraints.Count; i++)
                {
                    var constraint          = route.Constraints[i];
                    var routeConstraintType = Type.GetType(constraint.Type);

                    IRouteConstraint routeConstraint;
                    if (constraint.Params.Attributes.Count > 0)
                    {
                        var parameters = constraint.Params.Attributes.Values.ToArray();
                        routeConstraint = (IRouteConstraint)Activator.CreateInstance(routeConstraintType, parameters);
                    }
                    else
                    {
                        routeConstraint = (IRouteConstraint)Activator.CreateInstance(routeConstraintType);
                    }

                    dictionary.Add(constraint.Name, routeConstraint);
                }

                return(dictionary);
            }
            catch (Exception ex)
            {
                var message = String.Format("Can't create an instance of IRouteHandler {0}", route.RouteHandlerType);
                throw new ApplicationException(message, ex);
            }
        }
        protected virtual Type DetermineHandlerType(RouteConfigurationElement element)
        {
            Type defaultType = Configurations.Configuration.Instance.DefaultHandlerType;
            Type type        = Type.GetType(element.HandlerType, false, true);

            return(type ?? defaultType);
        }
        protected virtual RouteBase ProcessRoute(RouteConfigurationElement element)
        {
            Type            handlerType = DetermineHandlerType(element);
            ValueDictionary defaults    = ProcessDefaults(element.Defaults);
            ValueDictionary tokens      = ProcessTokens(element.Tokens);
            IEnumerable <IRouteConstraint> constraints = ProcessConstraints(element.Constraints);

            RouteDescriptor descriptor = new RouteDescriptor(
                element.Url, element.Type, element.Attributes, handlerType);

            return(CreateRoute(descriptor, defaults, tokens, constraints));
        }
Esempio n. 4
0
        private static RouteValueDictionary GetDefaults(RouteConfigurationElement route)
        {
            var dataTokensDictionary = new RouteValueDictionary();

            foreach (var dataToken in route.Defaults.Attributes)
            {
                if (dataToken.Value.Equals("Optional", StringComparison.InvariantCultureIgnoreCase))
                {
                    dataTokensDictionary.Add(dataToken.Key, UrlParameter.Optional);
                }
                else
                {
                    dataTokensDictionary.Add(dataToken.Key, dataToken.Value);
                }
            }

            return(dataTokensDictionary);
        }
Esempio n. 5
0
        private static IRouteHandler GetInstanceOfRouteHandler(RouteConfigurationElement route)
        {
            if (String.IsNullOrEmpty(route.RouteHandlerType))
            {
                return(new MvcRouteHandler());
            }

            try
            {
                Type routeHandlerType = Type.GetType(route.RouteHandlerType);
                return(Activator.CreateInstance(routeHandlerType) as IRouteHandler);
            }
            catch (Exception ex)
            {
                var message = String.Format("Can't create an instance of IRouteHandler {0}", route.RouteHandlerType);
                throw new ApplicationException(message, ex);
            }
        }
Esempio n. 6
0
 private static RouteValueDictionary GetDataTokens(RouteConfigurationElement route)
 {
     return(GetDictionaryFromAttributes(route.DataTokens.Attributes));
 }