Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var baseurl = new Uri("http://localhost:9000/");
            var config = new HttpSelfHostConfiguration(baseurl);

            //config.MessageHandlers.Add(new GitHubApiRouter(baseurl));

            //config.Routes.Add("default", new TreeRoute("",new TreeRoute("home").To<HomeController>(),
            //                                              new TreeRoute("contact",
            //                                                        new TreeRoute("{id}",
            //                                                            new TreeRoute("address",
            //                                                                 new TreeRoute("{addressid}").To<ContactAddressController>())
            //                                                        ).To<ContactController>())
            //                                              )
            //                  );

            var route = new TreeRoute("api");
            route.AddWithPath("home", r => r.To<HomeController>());
            route.AddWithPath("contact/{id}",r => r.To<ContactController>());
            route.AddWithPath("contact/{id}/adddress/{addressid}", r => r.To<ContactAddressController>());
            route.AddWithPath("act/A", r => r.To<ActionController>().ToAction("A"));
            route.AddWithPath("act/B", r => r.To<ActionController>().ToAction("B"));

            config.Routes.Add("default", route);

            var host = new HttpSelfHostServer(config);
            host.OpenAsync().Wait();

            Console.WriteLine("Host open.  Hit enter to exit...");

            Console.Read();

            host.CloseAsync().Wait();
        }
Ejemplo n.º 2
0
        public void BuildTreeFromPath()
        {
            var router = new TreeRoute("");

            router.AddWithPath("foo/bar/baz", r => r.To<FakeController>());
            router.AddWithPath("foo/bar", r => r.To<Fake2Controller>());
            router.AddWithPath("foo/bar/baz/blur", r => r.To<Fake3Controller>());

            var httpRequestMessage = new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost/foo/bar/baz")
            };

            var httpRequestMessage2 = new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost/foo/bar")
            };

            var httpRequestMessage3 = new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost/foo/bar/baz/blur")
            };

            var routeData = router.GetRouteData("/", httpRequestMessage);
            var routeData2 = router.GetRouteData("/", httpRequestMessage2);
            var routeData3 = router.GetRouteData("/", httpRequestMessage3);

            Assert.Equal("Fake",routeData.Values["controller"]);
            Assert.Equal("Fake2", routeData2.Values["controller"]);
            Assert.Equal("Fake3", routeData3.Values["controller"]);
        }
Ejemplo n.º 3
0
        public void BuildTreeFromPath()
        {
            var router = new TreeRoute("");

            router.AddWithPath("foo/bar/baz", r => r.To <FakeController>());
            router.AddWithPath("foo/bar", r => r.To <Fake2Controller>());
            router.AddWithPath("foo/bar/baz/blur", r => r.To <Fake3Controller>());


            var httpRequestMessage = new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost/foo/bar/baz")
            };

            var httpRequestMessage2 = new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost/foo/bar")
            };

            var httpRequestMessage3 = new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost/foo/bar/baz/blur")
            };

            var routeData  = router.GetRouteData("/", httpRequestMessage);
            var routeData2 = router.GetRouteData("/", httpRequestMessage2);
            var routeData3 = router.GetRouteData("/", httpRequestMessage3);

            Assert.Equal("Fake", routeData.Values["controller"]);
            Assert.Equal("Fake2", routeData2.Values["controller"]);
            Assert.Equal("Fake3", routeData3.Values["controller"]);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var baseurl = new Uri("http://localhost:9000/");
            var config  = new HttpSelfHostConfiguration(baseurl);

            //config.MessageHandlers.Add(new GitHubApiRouter(baseurl));

            //config.Routes.Add("default", new TreeRoute("",new TreeRoute("home").To<HomeController>(),
            //                                              new TreeRoute("contact",
            //                                                        new TreeRoute("{id}",
            //                                                            new TreeRoute("address",
            //                                                                 new TreeRoute("{addressid}").To<ContactAddressController>())
            //                                                        ).To<ContactController>())
            //                                              )
            //                  );

            var route = new TreeRoute("api");

            route.AddWithPath("home", r => r.To <HomeController>());
            route.AddWithPath("contact/{id}", r => r.To <ContactController>());
            route.AddWithPath("contact/{id}/adddress/{addressid}", r => r.To <ContactAddressController>());

            config.Routes.Add("default", route);


            var host = new HttpSelfHostServer(config);

            host.OpenAsync().Wait();

            Console.WriteLine("Host open.  Hit enter to exit...");

            Console.Read();

            host.CloseAsync().Wait();
        }
Ejemplo n.º 5
0
        public void gamesRoutes3()
        {
            var router = new TreeRoute("games");
            router.AddWithPath("{gametitle}/Setup/{gamesid}", apiRouter => apiRouter.To<SetupController>());
            router.AddWithPath("{gametitle}/Resources/{resourcetype}/{resourceid}", apiRouter => apiRouter.To<ResourceController>());
            router.AddWithPath("{gametitle}/{gameid}/{controller}/{id}", r => { });

            var getRouteData = router.GetRouteData("/", new HttpRequestMessage() { RequestUri = new Uri("http://localhost/games/GodsOfWar/277/Chat/177") });

            Assert.Equal("Chat", getRouteData.Values["controller"]);
            Assert.Equal("GodsOfWar", getRouteData.Values["gametitle"]);
            Assert.Equal("277", getRouteData.Values["gameid"]);
            Assert.Equal("177", getRouteData.Values["id"]);
        }
Ejemplo n.º 6
0
        public void gamesRoutes2()
        {
            var route = new TreeRoute("games");
            route.AddWithPath("{gametitle}/Setup/{gamesid}", r => r.To<SetupController>());
            route.AddWithPath("{gametitle}/Resources/{resourcetype}/{resourceid}", r => r.To<ResourceController>());
            route.AddWithPath("{gametitle}/{gameid}/Chat/{chatid}", r => r.To<ChatController>());
            route.AddWithPath("{gametitle}/{gameid}/State/{stateid}", r => r.To<StateController>());

            var getRouteData = route.GetRouteData("/", new HttpRequestMessage() { RequestUri = new Uri("http://localhost/games/GodsOfWar/277/Chat/177") });

            var url = route.GetUrlForController(typeof(ChatController));

            Assert.Equal("Chat", getRouteData.Values["controller"]);
            Assert.Equal("GodsOfWar", getRouteData.Values["gametitle"]);
            Assert.Equal("277", getRouteData.Values["gameid"]);
            Assert.Equal("177", getRouteData.Values["chatid"]);
            Assert.Equal("games/{gametitle}/{gameid}/Chat/{chatid}", url.OriginalString);
        }
Ejemplo n.º 7
0
        public void gamesRoutes3()
        {
            var router = new TreeRoute("games");

            router.AddWithPath("{gametitle}/Setup/{gamesid}", apiRouter => apiRouter.To <SetupController>());
            router.AddWithPath("{gametitle}/Resources/{resourcetype}/{resourceid}", apiRouter => apiRouter.To <ResourceController>());
            router.AddWithPath("{gametitle}/{gameid}/{controller}/{id}", r => { });

            var getRouteData = router.GetRouteData("/", new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost/games/GodsOfWar/277/Chat/177")
            });


            Assert.Equal("Chat", getRouteData.Values["controller"]);
            Assert.Equal("GodsOfWar", getRouteData.Values["gametitle"]);
            Assert.Equal("277", getRouteData.Values["gameid"]);
            Assert.Equal("177", getRouteData.Values["id"]);
        }
Ejemplo n.º 8
0
        public void DefaultWebApiRoute()
        {
            var route = new TreeRoute("api");
             route.AddWithPath("{controller}/{id}", r => { });

            var getRouteData = route.GetRouteData("/", new HttpRequestMessage() { RequestUri = new Uri("http://localhost/api/contact/23") });

            Assert.Equal("contact", getRouteData.Values["controller"]);
            Assert.Equal("23", getRouteData.Values["id"]);
        }
Ejemplo n.º 9
0
        public void gamesRoutes2()
        {
            var route = new TreeRoute("games");

            route.AddWithPath("{gametitle}/Setup/{gamesid}", r => r.To <SetupController>());
            route.AddWithPath("{gametitle}/Resources/{resourcetype}/{resourceid}", r => r.To <ResourceController>());
            route.AddWithPath("{gametitle}/{gameid}/Chat/{chatid}", r => r.To <ChatController>());
            route.AddWithPath("{gametitle}/{gameid}/State/{stateid}", r => r.To <StateController>());

            var getRouteData = route.GetRouteData("/", new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost/games/GodsOfWar/277/Chat/177")
            });

            var url = route.GetUrlForController(typeof(ChatController));

            Assert.Equal("Chat", getRouteData.Values["controller"]);
            Assert.Equal("GodsOfWar", getRouteData.Values["gametitle"]);
            Assert.Equal("277", getRouteData.Values["gameid"]);
            Assert.Equal("177", getRouteData.Values["chatid"]);
            Assert.Equal("games/{gametitle}/{gameid}/Chat/{chatid}", url.OriginalString);
        }
Ejemplo n.º 10
0
        public void DefaultWebApiRoute()
        {
            var route = new TreeRoute("api");

            route.AddWithPath("{controller}/{id}", r => { });

            var getRouteData = route.GetRouteData("/", new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost/api/contact/23")
            });

            Assert.Equal("contact", getRouteData.Values["controller"]);
            Assert.Equal("23", getRouteData.Values["id"]);
        }
Ejemplo n.º 11
0
        public void SetupBigRouteTable()
        {
            var route = new TreeRoute("");

            route.AddWithPath("x/foo/{controller}/{id}", r => { });
            route.AddWithPath("x/bar/{controller}/{id}", r => { });
            route.AddWithPath("x/baz/{controller}/{id}", r => { });
            route.AddWithPath("y/blip/{controller}/{id}", r => { });
            route.AddWithPath("y/flid/{controller}/{id}", r => { });
            route.AddWithPath("y/flod/{controller}/{id}", r => { });


            var routes = new HttpRouteCollection();

            routes.MapHttpRoute("a", "x/foo/{controller}/{id}");
            routes.MapHttpRoute("b", "x/bar/{controller}/{id}");
            routes.MapHttpRoute("c", "x/baz/{controller}/{id}");
            routes.MapHttpRoute("d", "y/blip/{controller}/{id}");
            routes.MapHttpRoute("e", "y/flid/{controller}/{id}");
            routes.MapHttpRoute("f", "y/flod/{controller}/{id}");

            var httpRequestMessage = new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost/y/flid/boo/22")
            };

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            for (int i = 0; i < 1000000; i++)
            {
                var getRouteData = route.GetRouteData("/", httpRequestMessage);
            }

            stopwatch.Stop();
            Debug.WriteLine("That took " + stopwatch.ElapsedMilliseconds);

            stopwatch.Reset();
            stopwatch.Start();

            for (int i = 0; i < 1000000; i++)
            {
                var mvcroute = routes.GetRouteData(httpRequestMessage);
            }
            stopwatch.Stop();
            Debug.WriteLine("That took " + stopwatch.ElapsedMilliseconds);
        }
Ejemplo n.º 12
0
        public void SetupBigRouteTable()
        {
            var route = new TreeRoute("");
            route.AddWithPath("x/foo/{controller}/{id}", r => { });
            route.AddWithPath("x/bar/{controller}/{id}", r => { });
            route.AddWithPath("x/baz/{controller}/{id}", r => { });
            route.AddWithPath("y/blip/{controller}/{id}", r => { });
            route.AddWithPath("y/flid/{controller}/{id}", r => { });
            route.AddWithPath("y/flod/{controller}/{id}", r => { });

            var routes = new HttpRouteCollection();
            routes.MapHttpRoute("a", "x/foo/{controller}/{id}");
            routes.MapHttpRoute("b", "x/bar/{controller}/{id}");
            routes.MapHttpRoute("c", "x/baz/{controller}/{id}");
            routes.MapHttpRoute("d", "y/blip/{controller}/{id}");
            routes.MapHttpRoute("e", "y/flid/{controller}/{id}");
            routes.MapHttpRoute("f", "y/flod/{controller}/{id}");

            var httpRequestMessage = new HttpRequestMessage() { RequestUri = new Uri("http://localhost/y/flid/boo/22") };

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            for (int i = 0; i < 1000000; i++)
            {
                var getRouteData = route.GetRouteData("/", httpRequestMessage);
            }

            stopwatch.Stop();
            Debug.WriteLine("That took " + stopwatch.ElapsedMilliseconds);

            stopwatch.Reset();
            stopwatch.Start();

            for (int i = 0; i < 1000000; i++)
            {
                var mvcroute = routes.GetRouteData(httpRequestMessage);
            }
            stopwatch.Stop();
            Debug.WriteLine("That took " + stopwatch.ElapsedMilliseconds);
        }