• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# RouteHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: UriParamsTest

        public void UriParamsTest()
        {
            var rh = new RouteHandler ("(?<name>.+)", "GET", new ActionTarget (FakeAction));
            var request = new MockHttpRequest ("GET", "hello");

            Should.NotBeNull (rh.Find (request), "target");

            Should.NotBeNull (request.UriData, "uri-data");

            Assert.AreEqual ("hello", request.UriData ["name"]);
        }
开发者ID:KevinT,项目名称:manos,代码行数:11,代码来源:RouteHandlerTest.cs


示例17: GetInstanceOfRouteHandler

        /// <summary>
        /// Gets the instance of route handler.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>IRouteHandler</returns>
        private static IRouteHandler GetInstanceOfRouteHandler(RouteConfigElement route)
        {
            IRouteHandler routeHandler;

            if(IsDebugEnabled)
                log.Debug("route={0}", route);

            if(route.RouteHandlerType.IsWhiteSpace())
                routeHandler = new RouteHandler<Page>(route.VirtualPath, true);
            else
            {
                try
                {
                    Type routeHandlerType = Type.GetType(route.RouteHandlerType);

                    if(IsDebugEnabled)
                        log.Debug("route={0}, routeHandlerType={1}", route, routeHandlerType);

                    routeHandler = Activator.CreateInstance(routeHandlerType) as IRouteHandler;
                }
                catch(Exception e)
                {
                    throw new ApplicationException(string.Format("Can't create an instance of IRouteHandler {0}", route.RouteHandlerType), e);
                }
            }

            if(IsDebugEnabled)
                log.Debug("route={0}, routeHandler={1}", route, routeHandler);

            return routeHandler;
        }
开发者ID:debop,项目名称:NFramework,代码行数:36,代码来源:RouteTableRegister.cs


示例18: AddHandlerForAction

        private void AddHandlerForAction(RouteHandler routes, HttpMethodAttribute att, MethodInfo info)
        {
            ManosAction action = ActionForMethod (info);

            ActionTarget target = new ActionTarget (action);

            string[] patterns = null == att.Patterns ? new string [] { "/" + info.Name } : att.Patterns;

            AddImplicitRouteHandlerForTarget (target, OpsForPatterns (patterns, att.MatchType), att.Methods);
        }
开发者ID:vbatz258,项目名称:manos,代码行数:10,代码来源:ManosModule.cs


示例19: AddDefaultHandlerForParameterizedAction

        private void AddDefaultHandlerForParameterizedAction(RouteHandler routes, MethodInfo info)
        {
            ParameterizedAction action = ParameterizedActionFactory.CreateAction (info);
            ParameterizedActionTarget target = new ParameterizedActionTarget (this, info, action);

            AddImplicitRouteHandlerForTarget (target, new string [] { "/" + info.Name }, HttpMethods.RouteMethods, MatchType.String);
        }
开发者ID:vbatz258,项目名称:manos,代码行数:7,代码来源:ManosModule.cs


示例20: AddDefaultHandlerForAction

        private void AddDefaultHandlerForAction(RouteHandler routes, MethodInfo info)
        {
            ManosAction action = ActionForMethod (info);

            ActionTarget target = new ActionTarget (action);
            AddImplicitRouteHandlerForTarget (target, new string [] { "/" + info.Name }, HttpMethods.RouteMethods, MatchType.String);
        }
开发者ID:vbatz258,项目名称:manos,代码行数:7,代码来源:ManosModule.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RouteValueDictionary类代码示例发布时间:2022-05-24
下一篇:
C# RouteDirection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap