本文整理汇总了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);
}
示例2:
SingleRoute IHttpServer.AddRoute(string path, IBlController controller, RouteHandler handler)
{
var route = add_route(new SingleRoute
{
Path = path,
Controller = controller,
Handler = handler
});
return route;
}
示例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);
}
示例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");
}
示例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);
}
示例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);
}
示例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
}
示例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/>");
});
}
示例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");
}
示例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");
}
示例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");
}
示例12: BuildRoute
public Route BuildRoute(RouteHandler handler, string path) =>
handler.ToRoute()
.MatchAndBindParameters(RouteParser.Parse(path))
.ForMethod(_method);
示例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");
}
示例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;
}
示例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;
}