Ejemplo n.º 1
0
 private static void AddRestRoutes(RouteCollection routes, AppBuilderRouteHandler <Page> routeHandler, IEnumerable <RestService> restServices)
 {
     foreach (RestService s in restServices)
     {
         BuildRoute(routes, routeHandler, s);
     }
 }
Ejemplo n.º 2
0
        private static void BuildRoute(RouteCollection routes, AppBuilderRouteHandler <Page> routeHandler, RestService s)
        {
            Route  r;
            string routeUrl  = null;
            string routeName = null;



            if (s.SupportJSON)
            {
                routeName = String.Format("{0}_{1}_json", s.Folder, s.Name);
                routeUrl  = String.Format("{{folder}}/{1}.json", s.Folder, s.Resource);
                r         = new Route(routeUrl, routeHandler);
                if (r.DataTokens == null)
                {
                    r.DataTokens = new RouteValueDictionary();
                }
                r.DataTokens["rest-service-name"] = s.Name;
                routes.Add(routeName, r);
            }

            if (s.SupportXML)
            {
                routeName = String.Format("{0}_{1}_xml", s.Folder, s.Name);
                routeUrl  = String.Format("{{folder}}/{1}.xml", s.Folder, s.Resource);
                r         = new Route(routeUrl, routeHandler);
                if (r.DataTokens == null)
                {
                    r.DataTokens = new RouteValueDictionary();
                }
                r.DataTokens["rest-service-name"] = s.Name;
                routes.Add(routeName, r);
            }

            routeName = String.Format("{0}_{1}_default", s.Folder, s.Name);
            routeUrl  = String.Format("{{folder}}/{1}", s.Folder, s.Resource);
            r         = new Route(routeUrl, routeHandler);
            if (r.DataTokens == null)
            {
                r.DataTokens = new RouteValueDictionary();
            }
            r.DataTokens["rest-service-name"] = s.Name;
            routes.Add(routeName, r);
        }
Ejemplo n.º 3
0
        public static void LoadWebConfiguration(RouteCollection routes)
        {
            //load virtual path provider
            HostingEnvironment.RegisterVirtualPathProvider(new EmbeddedResourceProvider()
            {
                { Assembly.GetExecutingAssembly() }
            });

            CodeTorch.Core.ConfigurationLoader.LoadWebConfiguration();



            var routeHandler = new AppBuilderRouteHandler <Page>();

            Route appbuilderScreenRoute = new Route("App/{folder}/{page}", routeHandler);

            appbuilderScreenRoute.Defaults = new RouteValueDictionary {
                { "page", "default.aspx" }
            };
            routes.Add(appbuilderScreenRoute);

            var restServicesStatic = from svc in CodeTorch.Core.Configuration.GetInstance().RestServices
                                     where
                                     (
                (!String.IsNullOrEmpty(svc.Resource)) &&
                (!svc.Resource.Contains("{"))
                                     )
                                     orderby svc.Name
                                     select svc;

            var restServicesDynamic = from svc in CodeTorch.Core.Configuration.GetInstance().RestServices
                                      where
                                      (
                (!String.IsNullOrEmpty(svc.Resource)) &&
                (svc.Resource.Contains("{"))
                                      )
                                      orderby svc.Name
                                      select svc;

            AddRestRoutes(routes, routeHandler, restServicesStatic);
            AddRestRoutes(routes, routeHandler, restServicesDynamic);
        }