当前位置: 首页>>代码示例>>C#>>正文


C# RouteHandler类代码示例

本文整理汇总了C#中RouteHandler的典型用法代码示例。如果您正苦于以下问题:C# RouteHandler类的具体用法?C# RouteHandler怎么用?C# RouteHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RouteHandler类属于命名空间,在下文中一共展示了RouteHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Add

        public static void Add(this RouteCollection routes, FalcorMethod method,
            IReadOnlyList<PathMatcher> pathMatchers, RouteHandler handler)
        {
            var route = handler
                .ToRoute()
                .MatchAndBindParameters(pathMatchers)
                .ForMethod(method);

            routes.Add(route);
        }
开发者ID:falcordotnet,项目名称:falcor.net,代码行数:10,代码来源:RouteCollectionExtensions.cs

示例2:

        SingleRoute IHttpServer.AddRoute(string path, IBlController controller, RouteHandler handler)
        {
            var route = add_route(new SingleRoute
                {
                    Path = path,
                    Controller = controller,
                    Handler = handler
                });

            return route;
        }
开发者ID:Kidify,项目名称:L4p,代码行数:11,代码来源:WebApiController.cs

示例3: Find_PartialMatchAtBeginningOfChildlessHandler_ReturnsProperRoute

        public void Find_PartialMatchAtBeginningOfChildlessHandler_ReturnsProperRoute()
        {
            var rh_bad = new RouteHandler ("foo", "GET", new ActionTarget (FakeAction));
            var rh_good = new RouteHandler ("foobar", "GET", new ActionTarget (FakeAction2));
            var rh = new RouteHandler ();

            rh.Children.Add (rh_bad);
            rh.Children.Add (rh_good);

            var request = new MockHttpRequest ("GET", "foobar");
            var res = rh.Find (request);

            Assert.AreEqual (rh_good.Target, res);
        }
开发者ID:KevinT,项目名称:manos,代码行数:14,代码来源:RouteHandlerTest.cs

示例4: HasPatternsTest

        public void HasPatternsTest()
        {
            var rh = new RouteHandler ("foo", "GET");

            Assert.IsTrue (rh.HasPatterns, "a1");

            rh.Patterns.Clear ();
            Assert.IsFalse (rh.HasPatterns, "a2");

            rh.Patterns.Add ("foobar");
            Assert.IsTrue (rh.HasPatterns, "a3");

            rh.Patterns = null;
            Assert.IsFalse (rh.HasPatterns, "a4");
        }
开发者ID:KevinT,项目名称:manos,代码行数:15,代码来源:RouteHandlerTest.cs

示例5: Find_PartialMatchAtBeginningOfChildlessHandler_ReturnsProperRoute

        public void Find_PartialMatchAtBeginningOfChildlessHandler_ReturnsProperRoute()
        {
            IMatchOperation fooOp = MatchOperationFactory.Create("foo", MatchType.String);
            IMatchOperation foobarOp = MatchOperationFactory.Create("foobar", MatchType.String);
            var rh_bad = new RouteHandler(fooOp, HttpMethod.HTTP_GET, new ActionTarget(FakeAction));
            var rh_good = new RouteHandler(foobarOp, HttpMethod.HTTP_GET, new ActionTarget(FakeAction2));
            var rh = new RouteHandler();

            rh.Add(rh_bad);
            rh.Add(rh_good);

            var request = new MockHttpRequest(HttpMethod.HTTP_GET, "foobar");
            IManosTarget res = rh.Find(request);

            Assert.AreEqual(rh_good.Target, res);
        }
开发者ID:nuxleus,项目名称:manos,代码行数:16,代码来源:RouteHandlerTest.cs

示例6: Find_PartialMatchAtBeginningOfHandlerWithChildren_ReturnsProperRoute

        public void Find_PartialMatchAtBeginningOfHandlerWithChildren_ReturnsProperRoute()
        {
            var rh_bad = new RouteHandler ("foo", HttpMethod.HTTP_GET);
            var rh_good = new RouteHandler ("foobar", HttpMethod.HTTP_GET, new ActionTarget (FakeAction2));
            var rh = new RouteHandler ();

            rh_bad.Children.Add (new RouteHandler ("blah", HttpMethod.HTTP_GET, new ActionTarget (FakeAction)));

            rh.Children.Add (rh_bad);
            rh.Children.Add (rh_good);

            var request = new MockHttpRequest (HttpMethod.HTTP_GET, "foobar");
            var res = rh.Find (request);

            Assert.AreEqual (rh_good.Target, res);
        }
开发者ID:vbatz258,项目名称:manos,代码行数:16,代码来源:RouteHandlerTest.cs

示例7: Configure

        // Routes must configured in Configure
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            var trackPackageRouteHandler = new RouteHandler(context =>
            {
                var routeValues = context.GetRouteData().Values;
                return context.Response.WriteAsync(
                    $"Hello! Route values: {string.Join(", ", routeValues)}");
            });

            var routeBuilder = new RouteBuilder(app, trackPackageRouteHandler);

            routeBuilder.MapRoute(
                "Track Package Route",
                "package/{operation:regex(track|create|detonate)}/{id:int}");

            routeBuilder.MapGet("hello/{name}", context =>
            {
                var name = context.GetRouteValue("name");
                // This is the route handler when HTTP GET "hello/<anything>"  matches
                // To match HTTP GET "hello/<anything>/<anything>, 
                // use routeBuilder.MapGet("hello/{*name}"
                return context.Response.WriteAsync($"Hi, {name}!");
            });            

            var routes = routeBuilder.Build();
            app.UseRouter(routes);

            // Show link generation when no routes match.
            app.Run(async (context) =>
            {
                var dictionary = new RouteValueDictionary
                {
                    { "operation", "create" },
                    { "id", 123}
                };

                var vpc = new VirtualPathContext(context, null, dictionary, "Track Package Route");
                var path = routes.GetVirtualPath(vpc).VirtualPath;

                context.Response.ContentType = "text/html";
                await context.Response.WriteAsync("Menu<hr/>");
                await context.Response.WriteAsync($"<a href='{path}'>Create Package 123</a><br/>");
            });
            // End of app.Run
        }
开发者ID:ColinDabritz,项目名称:Docs,代码行数:46,代码来源:Startup.cs

示例8: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
            ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(minLevel: LogLevel.Trace);

            var defaultHandler = new RouteHandler((c) => 
                c.Response.WriteAsync($"Hello world! Route values: " +
                $"{string.Join(", ", c.GetRouteData().Values)}")
                );

            var routeBuilder = new RouteBuilder(app, defaultHandler);

            routeBuilder.AddHelloRoute(app);

            routeBuilder.MapRoute(
                "Track Package Route",
                "package/{operation:regex(track|create|detonate)}/{id:int}");

            app.UseRouter(routeBuilder.Build());

            // demonstrate link generation
            var trackingRouteCollection = new RouteCollection();
            trackingRouteCollection.Add(routeBuilder.Routes[1]); // "Track Package Route"

            app.Run(async (context) =>
            {
                var dictionary = new RouteValueDictionary
                {
                    {"operation","create" },
                    {"id",123}
                };

                var vpc = new VirtualPathContext(context,
                    null, dictionary, "Track Package Route");

                context.Response.ContentType = "text/html";
                await context.Response.WriteAsync("Menu<hr/>");
                await context.Response.WriteAsync(@"<a href='" +
                    trackingRouteCollection.GetVirtualPath(vpc).VirtualPath +
                    "'>Create Package 123</a><br/>");
            });
        }
开发者ID:Corays,项目名称:Docs,代码行数:43,代码来源:Startup.cs

示例9: TestChangePatterns

        public void TestChangePatterns()
        {
            //
            // Ensure that changing the patterns property works.
            // This is a bit of an edge case because internally
            // the patterns strings are cached as an array of
            // regexes.
            //

            var target = new MockManosTarget ();
            var rh = new RouteHandler ("^foo", "GET", target);
            var request = new MockHttpRequest ("GET", "foo");

            Assert.AreEqual (target, rh.Find (request), "sanity-1");

            rh.Patterns [0] = "baz";
            Assert.IsNull (rh.Find (request), "sanity-2");

            request = new MockHttpRequest ("GET", "baz");
            Assert.AreEqual (target, rh.Find (request), "changed");
        }
开发者ID:KevinT,项目名称:manos,代码行数:21,代码来源:RouteHandlerTest.cs

示例10: TestStrMatch

        public void TestStrMatch()
        {
            var target = new MockManosTarget ();
            var rh = new RouteHandler ("^foo", "GET", target);
            var request = new MockHttpRequest ("GET", "foo");

            Assert.AreEqual (target, rh.Find (request), "should-match");

            request = new MockHttpRequest ("GET", "garbage-foo");
            Assert.IsNull (rh.Find (request), "garbage-input");
        }
开发者ID:KevinT,项目名称:manos,代码行数:11,代码来源:RouteHandlerTest.cs

示例11: TestStrMatchDeep

        public void TestStrMatchDeep()
        {
            var target = new MockManosTarget ();
            var rh = new RouteHandler ("foo/", "GET") {
                new RouteHandler ("bar", "GET", target),
            };

            var request = new MockHttpRequest ("GET", "foo/bar");
            Assert.AreEqual (target, rh.Find (request));

            request = new MockHttpRequest ("GET", "foo/foo");
            Assert.IsNull (rh.Find (request), "repeate-input");

            request = new MockHttpRequest ("GET", "foo/badbar");
            Assert.IsNull (rh.Find (request), "matched-input");
        }
开发者ID:KevinT,项目名称:manos,代码行数:16,代码来源:RouteHandlerTest.cs

示例12: BuildRoute

 public Route BuildRoute(RouteHandler handler, string path) =>
     handler.ToRoute()
     .MatchAndBindParameters(RouteParser.Parse(path))
     .ForMethod(_method);
开发者ID:gitter-badger,项目名称:falcor.net,代码行数:4,代码来源:RouteBuilder.cs

示例13: TestSetPatternsNull

        public void TestSetPatternsNull()
        {
            var target = new MockManosTarget ();
            var rh = new RouteHandler ("^foo", "GET", target);
            var request = new MockHttpRequest ("GET", "foo");

            Assert.AreEqual (target, rh.Find (request), "sanity-1");

            rh.Patterns = null;

            Assert.IsNull (rh.Find (request), "is null");
        }
开发者ID:KevinT,项目名称:manos,代码行数:12,代码来源:RouteHandlerTest.cs

示例14: AddRouteHandler

        private RouteHandler AddRouteHandler(IManosTarget target, string [] patterns, HttpMethod [] methods)
        {
            // TODO: Need to decide if this is a good or bad idea
            // RemoveImplicitHandlers (action);

            if (target == null)
                throw new ArgumentNullException ("action");
            if (patterns == null)
                throw new ArgumentNullException ("patterns");
            if (methods == null)
                throw new ArgumentNullException ("methods");

            RouteHandler res = new RouteHandler (SimpleOpsForPatterns (patterns), methods, target);
            Routes.Children.Add (res);
            return res;
        }
开发者ID:vbatz258,项目名称:manos,代码行数:16,代码来源:ManosModule.cs

示例15: AddImplicitRouteHandler

        private RouteHandler AddImplicitRouteHandler(IManosTarget target, string [] patterns, string [] methods)
        {
            RouteHandler res = new RouteHandler (patterns, methods, target) {
                IsImplicit = true,
            };

            Routes.Children.Add (res);
            return res;
        }
开发者ID:emiaj,项目名称:manos,代码行数:9,代码来源:ManosModule.cs


注:本文中的RouteHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。