예제 #1
0
        public static Route ConvertToWebRoute(object route, RegisterSettings registerSettings)
        {
            HttpConfiguration httpConfig = registerSettings.Settings.HttpConfiguration();

            CodeHttpRoute httpRoute = (CodeHttpRoute)route;

            // httpWebRoute is System.Web.Http.WebHost.Routing.HttpWebRoute
            // with HttpRoute property set to httpRoute

            GlobalConfiguration.Configuration.Routes.Add(null, httpRoute);
            Route httpWebRoute = (Route)RouteTable.Routes.Last();

            RouteTable.Routes.RemoveAt(RouteTable.Routes.Count - 1);

            foreach (var item in httpWebRoute.Constraints.ToArray())
            {
                var paramBindConstraint = item.Value as Web.Http.Routing.ParameterBindingRouteConstraint;

                if (paramBindConstraint != null)
                {
                    httpWebRoute.Constraints[item.Key] = new ParameterBindingRouteConstraint(paramBindConstraint.Binder);
                    continue;
                }

                var regexConstraint = item.Value as Web.Http.Routing.RegexRouteConstraint;

                if (regexConstraint != null)
                {
                    httpWebRoute.Constraints[item.Key] = new RegexRouteConstraint(regexConstraint.Regex);
                    continue;
                }

                var setConstraint = item.Value as Web.Http.Routing.SetRouteConstraint;

                if (setConstraint != null)
                {
                    httpWebRoute.Constraints[item.Key] = new SetRouteConstraint(setConstraint.GetValues());
                    continue;
                }
            }

            var codeWebRoute = new CodeHttpWebRoute(httpWebRoute, httpRoute);

            CodeRoutingHttpExtensions.EnableCodeRouting(httpConfig);

            return(codeWebRoute);
        }
      public static Route ConvertToWebRoute(object route, RegisterSettings registerSettings) {

         HttpConfiguration httpConfig = registerSettings.Settings.HttpConfiguration();

         CodeHttpRoute httpRoute = (CodeHttpRoute)route;

         // httpWebRoute is System.Web.Http.WebHost.Routing.HttpWebRoute
         // with HttpRoute property set to httpRoute

         GlobalConfiguration.Configuration.Routes.Add(null, httpRoute);
         Route httpWebRoute = (Route)RouteTable.Routes.Last();
         RouteTable.Routes.RemoveAt(RouteTable.Routes.Count - 1);

         foreach (var item in httpWebRoute.Constraints.ToArray()) {

            var paramBindConstraint = item.Value as Web.Http.Routing.ParameterBindingRouteConstraint;

            if (paramBindConstraint != null) {
               httpWebRoute.Constraints[item.Key] = new ParameterBindingRouteConstraint(paramBindConstraint.Binder);
               continue;
            }

            var regexConstraint = item.Value as Web.Http.Routing.RegexRouteConstraint;

            if (regexConstraint != null) {
               httpWebRoute.Constraints[item.Key] = new RegexRouteConstraint(regexConstraint.Regex);
               continue;
            }

            var setConstraint = item.Value as Web.Http.Routing.SetRouteConstraint;

            if (setConstraint != null) {
               httpWebRoute.Constraints[item.Key] = new SetRouteConstraint(setConstraint.GetValues());
               continue;
            }
         }

         var codeWebRoute = new CodeHttpWebRoute(httpWebRoute, httpRoute);

         CodeRoutingHttpExtensions.EnableCodeRouting(httpConfig);

         return codeWebRoute;
      }