本文整理汇总了C#中IRouter类的典型用法代码示例。如果您正苦于以下问题:C# IRouter类的具体用法?C# IRouter怎么用?C# IRouter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IRouter类属于命名空间,在下文中一共展示了IRouter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EdgeApplication
// Consumers should use IoC or the Default UseEdge extension method to initialize this.
public EdgeApplication(
IFileSystem fileSystem,
string virtualRoot,
IRouter router,
ICompilationManager compiler,
IPageActivator activator,
IPageExecutor executor,
ITraceFactory tracer)
: this()
{
Requires.NotNull(fileSystem, "fileSystem");
Requires.NotNullOrEmpty(virtualRoot, "virtualRoot");
Requires.NotNull(router, "router");
Requires.NotNull(compiler, "compiler");
Requires.NotNull(activator, "activator");
Requires.NotNull(executor, "executor");
Requires.NotNull(tracer, "tracer");
FileSystem = fileSystem;
VirtualRoot = virtualRoot;
Router = router;
CompilationManager = compiler;
Executor = executor;
Activator = activator;
Tracer = tracer;
}
示例2: Add
/// <summary>
/// Add a new router.
/// </summary>
/// <param name="router">Router to add</param>
/// <exception cref="InvalidOperationException">Server have been started.</exception>
public void Add(IRouter router)
{
if (_isStarted)
throw new InvalidOperationException("Server have been started.");
_routers.Add(router);
}
示例3: Match
//private string requiredSiteFolder;
//public SiteFolderRouteConstraint(string folderParam)
//{
// requiredSiteFolder = folderParam;
//}
public bool Match(
HttpContext httpContext,
IRouter route,
string parameterName,
IDictionary<string,object> values,
RouteDirection routeDirection)
{
string requestFolder = RequestSiteResolver.GetFirstFolderSegment(httpContext.Request.Path);
//return string.Equals(requiredSiteFolder, requestFolder, StringComparison.CurrentCultureIgnoreCase);
ISiteResolver siteResolver = httpContext.ApplicationServices.GetService<ISiteResolver>();
if(siteResolver != null)
{
try
{
// exceptions expected here until db install scripts have run or if db connection error
ISiteSettings site = siteResolver.Resolve();
if ((site != null) && (site.SiteFolderName == requestFolder)) { return true; }
}
catch
{
// do we need to log this?
}
}
return false;
}
示例4: NancyRouterModule
public NancyRouterModule(IRouter router)
{
foreach (var route in router.Routes)
{
switch (route.Key.Method)
{
case Route.RouteMethod.Get:
Get[route.Key.Path] = x => (route.Value(CreateOwinContext()));
break;
case Route.RouteMethod.Delete:
Delete[route.Key.Path] = x => (route.Value(CreateOwinContext()));
break;
case Route.RouteMethod.Patch:
Patch[route.Key.Path] = x => (route.Value(CreateOwinContext()));
break;
case Route.RouteMethod.Post:
Post[route.Key.Path] = x => (route.Value(CreateOwinContext()));
break;
case Route.RouteMethod.Put:
Put[route.Key.Path] = x => (route.Value(CreateOwinContext()));
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
示例5: TemplateRoute
public TemplateRoute(
IRouter target,
string routeName,
string routeTemplate,
IDictionary<string, object> defaults,
IDictionary<string, object> constraints,
IDictionary<string, object> dataTokens,
IInlineConstraintResolver inlineConstraintResolver)
{
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
_target = target;
_routeTemplate = routeTemplate ?? string.Empty;
Name = routeName;
_dataTokens = dataTokens == null ? RouteValueDictionary.Empty : new RouteValueDictionary(dataTokens);
// Data we parse from the template will be used to fill in the rest of the constraints or
// defaults. The parser will throw for invalid routes.
_parsedTemplate = TemplateParser.Parse(RouteTemplate);
_constraints = GetConstraints(inlineConstraintResolver, RouteTemplate, _parsedTemplate, constraints);
_defaults = GetDefaults(_parsedTemplate, defaults);
_matcher = new TemplateMatcher(_parsedTemplate, Defaults);
_binder = new TemplateBinder(_parsedTemplate, Defaults);
}
示例6: TenantRoute
public TenantRoute(IRouter target,
string urlHost,
RequestDelegate pipeline) {
_target = target;
_urlHost = urlHost;
_pipeline = pipeline;
}
示例7: AttributeRoute
public AttributeRoute(
IRouter target,
IActionDescriptorsCollectionProvider actionDescriptorsCollectionProvider,
IInlineConstraintResolver constraintResolver,
ILoggerFactory loggerFactory)
{
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
if (actionDescriptorsCollectionProvider == null)
{
throw new ArgumentNullException(nameof(actionDescriptorsCollectionProvider));
}
if (constraintResolver == null)
{
throw new ArgumentNullException(nameof(constraintResolver));
}
if (loggerFactory == null)
{
throw new ArgumentNullException(nameof(loggerFactory));
}
_target = target;
_actionDescriptorsCollectionProvider = actionDescriptorsCollectionProvider;
_constraintResolver = constraintResolver;
_routeLogger = loggerFactory.CreateLogger<InnerAttributeRoute>();
_constraintLogger = loggerFactory.CreateLogger(typeof(RouteConstraintMatcher).FullName);
}
示例8: GuidedVNS
/// <summary>
/// Creates a new Guided Variable Neighbourhood Search solver.
/// </summary>
/// <param name="router"></param>
/// <param name="max"></param>
/// <param name="delivery_time"></param>
/// <param name="threshold_precentage"></param>
/// <param name="lambda"></param>
/// <param name="sigma"></param>
public GuidedVNS(IRouter<RouterPoint> router, Second max, Second delivery_time,
float threshold_precentage, float lambda, float sigma)
: base(max, delivery_time)
{
_threshold_percentage = threshold_precentage;
_lambda = lambda;
_sigma = sigma;
_intra_improvements = new List<IImprovement>();
//_intra_improvements.Add(
// new ArbitraryInsertionSolver());
_intra_improvements.Add(
new HillClimbing3OptSolver(true, true));
_inter_improvements = new List<IInterImprovement>();
_inter_improvements.Add(
new RelocateImprovement());
_inter_improvements.Add(
new ExchangeInterImprovement());
//_inter_improvements.Add(
// new TwoOptInterImprovement());
_inter_improvements.Add(
new RelocateExchangeInterImprovement());
_inter_improvements.Add(
new CrossExchangeInterImprovement());
}
示例9: Match
public bool Match(HttpContext httpContext, IRouter route, string routeKey, IDictionary<string, object> values, RouteDirection routeDirection)
{
var context = httpContext.ApplicationServices.GetService<IPantherContext>();
var url = "/";
if (context == null)
return false;
//if (values.ContainsKey("culture") && !CheckCulture(values["culture"].ToString()))
// return false;
if(values.ContainsKey("url") && values["url"] != null)
url = values["url"].ToString();
var canHandle = context.CanHandleUrl(context.Path);
if (!canHandle)
return false;
if (!string.IsNullOrEmpty(context.Current.Controller))
values["controller"] = context.Current.Controller;
if (!string.IsNullOrEmpty(context.Current.Action))
values["action"] = context.Current.Action;
if (!string.IsNullOrEmpty(context.Current.Route))
context.Router.AddVirtualRouteValues(context.Current.Route, context.VirtualPath, values);
values["context"] = context;
return context.Current != null;
}
示例10: DefaultRouter
public DefaultRouter(IRouter defaultHandler, IRouteResolver routeResolver, IVirtualPathResolver virtualPathResolver, RequestCulture defaultRequestCulture)
{
if (defaultHandler == null)
{
throw new ArgumentNullException(nameof(defaultHandler));
}
if (routeResolver == null)
{
throw new ArgumentNullException(nameof(routeResolver));
}
if (virtualPathResolver == null)
{
throw new ArgumentNullException(nameof(virtualPathResolver));
}
if (defaultRequestCulture == null)
{
throw new ArgumentNullException(nameof(defaultRequestCulture));
}
_defaultHandler = defaultHandler;
_routeResolver = routeResolver;
_virtualPathResolver = virtualPathResolver;
_defaultRequestCulture = defaultRequestCulture;
}
示例11: CreateAttributeMegaRoute
/// <summary>
/// Creates an attribute route using the provided services and provided target router.
/// </summary>
/// <param name="target">The router to invoke when a route entry matches.</param>
/// <param name="services">The application services.</param>
/// <returns>An attribute route.</returns>
public static IRouter CreateAttributeMegaRoute(IRouter target, IServiceProvider services)
{
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
var actionDescriptorProvider = services.GetRequiredService<IActionDescriptorCollectionProvider>();
var inlineConstraintResolver = services.GetRequiredService<IInlineConstraintResolver>();
var pool = services.GetRequiredService<ObjectPool<UriBuildingContext>>();
var urlEncoder = services.GetRequiredService<UrlEncoder>();
var loggerFactory = services.GetRequiredService<ILoggerFactory>();
return new AttributeRoute(
target,
actionDescriptorProvider,
inlineConstraintResolver,
pool,
urlEncoder,
loggerFactory);
}
示例12: VirtualPathData
/// <summary>
/// Initializes a new instance of the <see cref="VirtualPathData"/> class.
/// </summary>
/// <param name="router">The object that is used to generate the URL.</param>
/// <param name="virtualPath">The generated URL.</param>
/// <param name="dataTokens">The collection of custom values.</param>
public VirtualPathData(
IRouter router,
string virtualPath,
IDictionary<string, object> dataTokens)
: this(router, CreatePathString(virtualPath), dataTokens)
{
}
示例13: AddPrefixRoute
public static IRouteBuilder AddPrefixRoute(this IRouteBuilder routeBuilder,
string prefix,
IRouter handler)
{
routeBuilder.Routes.Add(new PrefixRoute(handler, prefix));
return routeBuilder;
}
示例14: RazorApplication
// Consumers should use IoC or the Default UseRazor extension method to initialize this.
public RazorApplication(
AppFunc nextApp,
IFileSystem fileSystem,
string virtualRoot,
IRouter router,
ICompilationManager compiler,
IPageActivator activator,
IPageExecutor executor,
ITraceFactory tracer)
: this(nextApp)
{
Requires.NotNull(fileSystem, "fileSystem");
Requires.NotNullOrEmpty(virtualRoot, "virtualRoot");
Requires.NotNull(router, "router");
Requires.NotNull(compiler, "compiler");
Requires.NotNull(activator, "activator");
Requires.NotNull(executor, "executor");
Requires.NotNull(tracer, "tracer");
FileSystem = fileSystem;
VirtualRoot = virtualRoot;
Router = router;
CompilationManager = compiler;
Executor = executor;
Activator = activator;
Tracer = tracer;
ITrace global = Tracer.ForApplication();
global.WriteLine("Started at '{0}'", VirtualRoot);
}
示例15: AddTenantRoute
public static IRouteBuilder AddTenantRoute(this IRouteBuilder routeBuilder,
string urlHost,
IRouter handler,
RequestDelegate pipeline) {
routeBuilder.Routes.Add(new TenantRoute(handler, urlHost, pipeline));
return routeBuilder;
}