Exemplo n.º 1
0
        internal static void HttpConfiguration(this CodeRoutingSettings settings, HttpConfiguration configuration)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Properties["HttpConfiguration"] = configuration;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CodeRoutingSettings"/> class,
        /// using the values from the provided settings instance.
        /// </summary>
        /// <param name="settings">Another <see cref="CodeRoutingSettings"/> instance to copy the settings from.</param>
        public CodeRoutingSettings(CodeRoutingSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            Import(settings);
        }
Exemplo n.º 3
0
        internal static HttpConfiguration HttpConfiguration(this CodeRoutingSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            object httpConfiguration;

            if (settings.Properties.TryGetValue("HttpConfiguration", out httpConfiguration))
            {
                return(httpConfiguration as HttpConfiguration);
            }

            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates routes for the specified root controller and all other controllers
        /// in the same namespace or any sub-namespace, in the same assembly, and prepends the
        /// provided base route to the URL of each created route.
        /// </summary>
        /// <param name="configuration">The <see cref="System.Web.Http.HttpConfiguration"/> configuration object.</param>
        /// <param name="baseRoute">A base route to prepend to the URL of each created route. This parameter can be null.</param>
        /// <param name="rootController">The root controller for the provided base route.</param>
        /// <param name="settings">A settings object that customizes the route creation process. This parameter can be null.</param>
        /// <returns>The created routes.</returns>
        public static ICollection <IHttpRoute> MapCodeRoutes(this HttpConfiguration configuration, string baseRoute, Type rootController, CodeRoutingSettings settings)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            if (rootController == null)
            {
                throw new ArgumentNullException("rootController");
            }

            if (settings != null)
            {
                settings = new CodeRoutingSettings(settings);
            }

            var registerSettings = new RegisterSettings(null, rootController)
            {
                BaseRoute = baseRoute,
                Settings  = settings
            };

            registerSettings.Settings.HttpConfiguration(configuration);

            IHttpRoute[] newRoutes = RouteFactory.CreateRoutes <IHttpRoute>(registerSettings);

            foreach (IHttpRoute route in newRoutes)
            {
                // In Web API v1 name cannot be null
                configuration.Routes.Add(Guid.NewGuid().ToString(), route);
            }

            EnableCodeRouting(configuration);

            return(newRoutes);
        }
Exemplo n.º 5
0
        void Import(CodeRoutingSettings settings)
        {
            this.EnableEmbeddedViews = settings.EnableEmbeddedViews;
            this.RootOnly            = settings.RootOnly;
            this.RouteFormatter      = settings.RouteFormatter;
            this.UseImplicitIdToken  = settings.UseImplicitIdToken;
            this.Configuration       = settings.Configuration;

            this.IgnoredControllers.Clear();

            foreach (Type item in settings.IgnoredControllers)
            {
                this.IgnoredControllers.Add(item);
            }

            this.DefaultConstraints.Clear();

            foreach (var item in settings.DefaultConstraints)
            {
                this.DefaultConstraints.Add(item.Key, item.Value);
            }

            this.ParameterBinders.Clear();

            foreach (var item in settings.ParameterBinders)
            {
                this.ParameterBinders.Add(item);
            }

            this.Properties.Clear();

            foreach (var item in settings.Properties)
            {
                this.Properties.Add(item.Key, item.Value);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Creates routes for the specified root controller and all other controllers
 /// in the same namespace or any sub-namespace, in the same assembly.
 /// </summary>
 /// <param name="configuration">The <see cref="System.Web.Http.HttpConfiguration"/> configuration object.</param>
 /// <param name="rootController">The root controller for the application.</param>
 /// <param name="settings">A settings object that customizes the route creation process. This parameter can be null.</param>
 /// <returns>The created routes.</returns>
 public static ICollection <IHttpRoute> MapCodeRoutes(this HttpConfiguration configuration, Type rootController, CodeRoutingSettings settings)
 {
     return(MapCodeRoutes(configuration, null, rootController, settings));
 }
        /// <summary>
        /// Creates routes for the specified root controller and all other controllers
        /// in the same namespace or any sub-namespace, in the same assembly, and prepends the
        /// provided base route to the URL of each created route.
        /// </summary>
        /// <param name="routes">A collection of routes for the application.</param>
        /// <param name="baseRoute">A base route to prepend to the URL of each created route. This parameter can be null.</param>
        /// <param name="rootController">The root controller for the provided base route.</param>
        /// <param name="settings">A settings object that customizes the route creation process. This parameter can be null.</param>
        /// <returns>The created routes.</returns>
        public static ICollection <Route> MapCodeRoutes(this RouteCollection routes, string baseRoute, Type rootController, CodeRoutingSettings settings)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            if (rootController == null)
            {
                throw new ArgumentNullException("rootController");
            }

            var registerSettings = new RegisterSettings(null, rootController)
            {
                BaseRoute = baseRoute,
                Settings  = settings
            };

            Route[] newRoutes = RouteFactory.CreateRoutes <Route>(registerSettings);

            foreach (Route route in newRoutes)
            {
                routes.Add(route);
            }

            if (newRoutes.Length > 0 &&
                registerSettings.Settings.EnableEmbeddedViews)
            {
                EmbeddedViewsVirtualPathProvider.RegisterAssembly(registerSettings);
            }

            return(newRoutes);
        }
 /// <summary>
 /// Creates routes for the specified root controller and all other controllers
 /// in the same namespace or any sub-namespace, in the same assembly.
 /// </summary>
 /// <param name="routes">A collection of routes for the application.</param>
 /// <param name="rootController">The root controller for the application.</param>
 /// <param name="settings">A settings object that customizes the route creation process. This parameter can be null.</param>
 /// <returns>The created routes.</returns>
 public static ICollection <Route> MapCodeRoutes(this RouteCollection routes, Type rootController, CodeRoutingSettings settings)
 {
     return(MapCodeRoutes(routes, null, rootController, settings));
 }