public MazeRequestExecuter(IRouteResolver routeResolver, IRouteCache routeCache, ILogger <MazeRequestExecuter> logger) { _routeResolver = routeResolver; _routeCache = routeCache; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRouteResolver"/> class. /// </summary> /// <param name="nancyModuleCatalog">The module catalog that modules should be</param> /// <param name="routePatternMatcher">The route pattern matcher that should be used to verify if the route is a match to any of the registered routes.</param> /// <param name="moduleBuilder">The module builder that will make sure that the resolved module is full configured.</param> /// <param name="cache">The route cache that should be used to resolve modules from.</param> public DefaultRouteResolver(INancyModuleCatalog nancyModuleCatalog, IRoutePatternMatcher routePatternMatcher, INancyModuleBuilder moduleBuilder, IRouteCache cache) { this.nancyModuleCatalog = nancyModuleCatalog; this.routePatternMatcher = routePatternMatcher; this.moduleBuilder = moduleBuilder; this.cache = cache; }
public WorkAppService(IRepository <Signin> signinRepository, IRepository <Route> routeRepository, IRepository <RouteArticle> routeArticleRepository, IRepository <RouteTask> routeTaskRepository, IRepository <Depot> depotRepository, IRouteCache routeCache, IWorkRoleCache workRoleCache, IRouteTypeCache routeTypeCache, IArticleCache articleCache, IArticleTypeCache articleTypeCache, IBoxCache boxCache, IOutletCache outletCache, ICustomerTaskTypeCache customerTaskTypeCache, IOutletTaskTypeCache outletTaskTypeCache) { _signinRepository = signinRepository; _routeRepository = routeRepository; _routeArticleRepository = routeArticleRepository; _routeTaskRepository = routeTaskRepository; _depotRepository = depotRepository; _routeCache = routeCache; _workRoleCache = workRoleCache; _routeTypeCache = routeTypeCache; _articleCache = articleCache; _articleTypeCache = articleTypeCache; _boxCache = boxCache; _outletCache = outletCache; _customerTaskTypeCache = customerTaskTypeCache; _outletTaskTypeCache = outletTaskTypeCache; }
public RouteResolverTrie(ITrieNodeFactory nodeFactory, IRouteCache cache) { _nodeFactory = nodeFactory; _routeTries = new Dictionary <string, TrieNode>(StringComparer.OrdinalIgnoreCase); BuildTrie(cache); }
/// <summary> /// Gets the route, and the corresponding parameter dictionary from the URL /// </summary> /// <param name="context">Current context</param> /// <param name="routeCache">Route cache</param> /// <returns>Tuple - Item1 being the Route, Item2 being the parameters dictionary, Item3 being the prereq, Item4 being the postreq</returns> public ResolveResult Resolve(NancyContext context, IRouteCache routeCache) { if (routeCache.IsEmpty()) { return(new ResolveResult(new NotFoundRoute(context.Request.Method, context.Request.Uri), DynamicDictionary.Empty, null, null)); } var routesThatMatchRequestedPath = this.GetRoutesThatMatchRequestedPath(routeCache, context); if (NoRoutesWereAbleToBeMatchedInRouteCache(routesThatMatchRequestedPath)) { return(new ResolveResult(new NotFoundRoute(context.Request.Method, context.Request.Uri), DynamicDictionary.Empty, null, null)); } var routesWithCorrectRequestMethod = GetRoutesWithCorrectRequestMethod(context.Request, routesThatMatchRequestedPath); if (NoRoutesWereForTheRequestedMethod(routesWithCorrectRequestMethod)) { var allowedMethods = routesThatMatchRequestedPath.Select(x => x.Item3.Method); return(new ResolveResult(new MethodNotAllowedRoute(context.Request.Uri, context.Request.Method, allowedMethods), DynamicDictionary.Empty, null, null)); } var routeMatchesWithMostParameterCaptures = GetRouteMatchesWithMostParameterCaptures(routesWithCorrectRequestMethod); var routeMatchToReturn = GetSingleRouteToReturn(routeMatchesWithMostParameterCaptures); return(this.CreateRouteAndParametersFromMatch(context, routeMatchToReturn)); }
public Route Resolve(Request request, IRouteCache routeCache) { if (RouteCacheIsEmpty(routeCache)) { return new NotFoundRoute(request.Uri); } var routesThatMatchRequestedPath = GetRoutesThatMatchRequestedPath(routeCache, request); if (NoRoutesWereAbleToBeMatchedInRouteCache(routesThatMatchRequestedPath)) { return new NotFoundRoute(request.Uri); } var routesWithCorrectRequestMethod = GetRoutesWithCorrectRequestMethod(request, routesThatMatchRequestedPath); if (NoRoutesWereForTheRequestedMethod(routesWithCorrectRequestMethod)) { return new MethodNotAllowedRoute(request.Uri); } var routeMatchesWithMostParameterCaptures = GetRouteMatchesWithMostParameterCaptures(routesWithCorrectRequestMethod); var routeMatchToReturn = GetSingleRouteToReturn(routeMatchesWithMostParameterCaptures); return this.CreateRouteFromMatch(request, routeMatchToReturn); }
/// <summary> /// Gets the route, and the corresponding parameter dictionary from the URL /// </summary> /// <param name="context">Current context</param> /// <param name="routeCache">Route cache</param> /// <returns>Tuple - Item1 being the Route, Item2 being the parameters dictionary, Item3 being the prereq, Item4 being the postreq</returns> public ResolveResult Resolve(NancyContext context, IRouteCache routeCache) { if (routeCache.IsEmpty()) { return new ResolveResult(new NotFoundRoute(context.Request.Method, context.Request.Uri), DynamicDictionary.Empty, null, null); } var routesThatMatchRequestedPath = this.GetRoutesThatMatchRequestedPath(routeCache, context); if (NoRoutesWereAbleToBeMatchedInRouteCache(routesThatMatchRequestedPath)) { return new ResolveResult(new NotFoundRoute(context.Request.Method, context.Request.Uri), DynamicDictionary.Empty, null, null); } var routesWithCorrectRequestMethod = GetRoutesWithCorrectRequestMethod(context.Request, routesThatMatchRequestedPath); if (NoRoutesWereForTheRequestedMethod(routesWithCorrectRequestMethod)) { return new ResolveResult(new MethodNotAllowedRoute(context.Request.Uri, context.Request.Method), DynamicDictionary.Empty, null, null); } var routeMatchesWithMostParameterCaptures = GetRouteMatchesWithMostParameterCaptures(routesWithCorrectRequestMethod); var routeMatchToReturn = GetSingleRouteToReturn(routeMatchesWithMostParameterCaptures); return this.CreateRouteAndParametersFromMatch(context, routeMatchToReturn); }
public DefaultRouteResolver( IChatModuleCatalog catalog, IRouteCache routeCache) { this.catalog = catalog; this.routeCache = routeCache; }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="routeCache">Cache of all available routes</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="errorHandler">Error handler</param> public NancyEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory, IErrorHandler errorHandler) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } if (routeCache == null) { throw new ArgumentNullException("routeCache", "The routeCache parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (errorHandler == null) { throw new ArgumentNullException("errorHandler"); } this.resolver = resolver; this.routeCache = routeCache; this.contextFactory = contextFactory; this.errorHandler = errorHandler; }
/// <summary> /// Build the trie from the route cache /// </summary> /// <param name="cache">The route cache</param> public void BuildTrie(IRouteCache cache) { foreach (var cacheItem in cache) { var moduleKey = cacheItem.Key; var routeDefinitions = cacheItem.Value; foreach (var routeDefinition in routeDefinitions) { var routeIndex = routeDefinition.Item1; var routeDescription = routeDefinition.Item2; TrieNode trieNode; if (!this.routeTries.TryGetValue(routeDescription.Method, out trieNode)) { trieNode = this.nodeFactory.GetNodeForSegment(null, null); this.routeTries.Add(routeDefinition.Item2.Method, trieNode); } var segments = routeDefinition.Item2.Segments.ToArray(); trieNode.Add(segments, moduleKey, routeIndex, routeDescription); } } }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="routeCache">Cache of all available routes</param> /// <param name="contextFactory">A factory for creating contexts</param> /// <param name="errorHandlers">Error handlers</param> public NancyEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory, IEnumerable<IErrorHandler> errorHandlers) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } if (routeCache == null) { throw new ArgumentNullException("routeCache", "The routeCache parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } if (errorHandlers == null) { throw new ArgumentNullException("errorHandlers"); } this.resolver = resolver; this.routeCache = routeCache; this.contextFactory = contextFactory; this.errorHandlers = errorHandlers; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRouteResolver"/> class. /// </summary> /// <param name="nancyModuleCatalog">The module catalog that modules should be</param> /// <param name="routePatternMatcher">The route pattern matcher that should be used to verify if the route is a match to any of the registered routes.</param> /// <param name="moduleBuilder">The module builder that will make sure that the resolved module is full configured.</param> /// <param name="cache">The route cache that should be used to resolve modules from.</param> /// <param name="responseProcessors"></param> public DefaultRouteResolver(INancyModuleCatalog nancyModuleCatalog, IRoutePatternMatcher routePatternMatcher, INancyModuleBuilder moduleBuilder, IRouteCache cache, IEnumerable<IResponseProcessor> responseProcessors) { this.nancyModuleCatalog = nancyModuleCatalog; this.routePatternMatcher = routePatternMatcher; this.moduleBuilder = moduleBuilder; this.cache = cache; this.responseProcessors = responseProcessors; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRouteResolver"/> class. /// </summary> /// <param name="nancyModuleCatalog">The module catalog that modules should be</param> /// <param name="routePatternMatcher">The route pattern matcher that should be used to verify if the route is a match to any of the registered routes.</param> /// <param name="moduleBuilder">The module builder that will make sure that the resolved module is full configured.</param> /// <param name="cache">The route cache that should be used to resolve modules from.</param> /// <param name="responseProcessors"></param> public DefaultRouteResolver(INancyModuleCatalog nancyModuleCatalog, IRoutePatternMatcher routePatternMatcher, INancyModuleBuilder moduleBuilder, IRouteCache cache, IEnumerable <IResponseProcessor> responseProcessors) { this.nancyModuleCatalog = nancyModuleCatalog; this.routePatternMatcher = routePatternMatcher; this.moduleBuilder = moduleBuilder; this.cache = cache; this.responseProcessors = responseProcessors; }
/// <summary> /// Initializes a new instance of the RouteCacheFixture class. /// </summary> public RouteCacheFixture() { this.routeSegmentExtractor = A.Fake<IRouteSegmentExtractor>(); this.fakeModuleCatalog = new FakeModuleCatalog(); this.routeCache = new RouteCache(this.fakeModuleCatalog, new FakeModuleKeyGenerator(), A.Fake<INancyContextFactory>(), this.routeSegmentExtractor); }
/// <summary> /// Initializes a new instance of the RouteCacheFixture class. /// </summary> public RouteCacheFixture() { this.routeSegmentExtractor = A.Fake <IRouteSegmentExtractor>(); this.fakeModuleCatalog = new FakeModuleCatalog(); this.routeCache = new RouteCache(this.fakeModuleCatalog, new FakeModuleKeyGenerator(), A.Fake <INancyContextFactory>(), this.routeSegmentExtractor); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRouteResolver"/> class, using /// the provided <paramref name="catalog"/>, <paramref name="moduleBuilder"/>, /// <paramref name="routeCache"/> and <paramref name="trie"/>. /// </summary> /// <param name="catalog">A <see cref="INancyModuleCatalog"/> instance.</param> /// <param name="moduleBuilder">A <see cref="INancyModuleBuilder"/> instance.</param> /// <param name="routeCache">A <see cref="IRouteCache"/> instance.</param> /// <param name="trie">A <see cref="IRouteResolverTrie"/> instance.</param> public SoapRouteResolver(INancyModuleCatalog catalog, INancyModuleBuilder moduleBuilder, IRouteCache routeCache, IRouteResolverTrie trie)// : base(catalog, moduleBuilder, routeCache, trie) { this.catalog = catalog; this.moduleBuilder = moduleBuilder; this.routeCache = routeCache; this.trie = trie; this.BuildTrie(); }
public DefaultRouteResolver(INancyModuleCatalog catalog, INancyModuleBuilder moduleBuilder, IRouteCache routeCache, IRouteResolverTrie trie) { this.catalog = catalog; this.moduleBuilder = moduleBuilder; this.routeCache = routeCache; this.trie = trie; this.BuildTrie(); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRouteResolver"/> class, using /// the provided <paramref name="catalog"/>, <paramref name="moduleBuilder"/>, /// <paramref name="routeCache"/> and <paramref name="trie"/>. /// </summary> /// <param name="catalog">A <see cref="INancyModuleCatalog"/> instance.</param> /// <param name="moduleBuilder">A <see cref="INancyModuleBuilder"/> instance.</param> /// <param name="routeCache">A <see cref="IRouteCache"/> instance.</param> /// <param name="trie">A <see cref="IRouteResolverTrie"/> instance.</param> public DefaultRouteResolver(INancyModuleCatalog catalog, INancyModuleBuilder moduleBuilder, IRouteCache routeCache, IRouteResolverTrie trie) { this.catalog = catalog; this.moduleBuilder = moduleBuilder; this.routeCache = routeCache; this.trie = trie; this.BuildTrie(); }
/// <summary> /// Initializes a new instance of the RouteCacheFixture class. /// </summary> public RouteCacheFixture() { this.routeDescriptionProvider = A.Fake<IRouteDescriptionProvider>(); this.routeSegmentExtractor = A.Fake<IRouteSegmentExtractor>(); this.fakeModuleCatalog = new FakeModuleCatalog(); this.routeCache = new RouteCache(this.fakeModuleCatalog, A.Fake<INancyContextFactory>(), this.routeSegmentExtractor, this.routeDescriptionProvider, A.Fake<ICultureService>()); }
/// <summary> /// Initializes a new instance of the RouteCacheFixture class. /// </summary> public RouteCacheFixture() { this.routeDescriptionProvider = A.Fake <IRouteDescriptionProvider>(); this.routeSegmentExtractor = A.Fake <IRouteSegmentExtractor>(); this.fakeModuleCatalog = new FakeModuleCatalog(); this.routeCache = new RouteCache(this.fakeModuleCatalog, new FakeModuleKeyGenerator(), A.Fake <INancyContextFactory>(), this.routeSegmentExtractor, this.routeDescriptionProvider, A.Fake <ICultureService>()); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRouteResolver"/> class, using /// the provided <paramref name="catalog"/>, <paramref name="moduleBuilder"/>, /// <paramref name="routeCache"/> and <paramref name="trie"/>. /// </summary> /// <param name="catalog">An <see cref="INancyModuleCatalog"/> instance.</param> /// <param name="moduleBuilder">An <see cref="INancyModuleBuilder"/> instance.</param> /// <param name="routeCache">An <see cref="IRouteCache"/> instance.</param> /// <param name="trie">An <see cref="IRouteResolverTrie"/> instance.</param> /// <param name="environment">An <see cref="INancyEnvironment"/> instance.</param> public DefaultRouteResolver(INancyModuleCatalog catalog, INancyModuleBuilder moduleBuilder, IRouteCache routeCache, IRouteResolverTrie trie, INancyEnvironment environment) { this.catalog = catalog; this.moduleBuilder = moduleBuilder; this.routeCache = routeCache; this.trie = trie; this.configuration = new Lazy <RouteConfiguration>(environment.GetValue <RouteConfiguration>); this.BuildTrie(); }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="routeCache"></param> public NancyEngine(IRouteResolver resolver, IRouteCache routeCache) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } this.resolver = resolver; this.routeCache = routeCache; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRouteResolver"/> class. /// </summary> /// <param name="nancyModuleCatalog">The module catalog that modules should be</param> /// <param name="routePatternMatcher">The route pattern matcher that should be used to verify if the route is a match to any of the registered routes.</param> /// <param name="moduleBuilder">The module builder that will make sure that the resolved module is full configured.</param> /// <param name="cache">The route cache that should be used to resolve modules from.</param> /// <param name="responseProcessors"></param> public NSembleRouteResolver(INancyModuleCatalog nancyModuleCatalog, IRoutePatternMatcher routePatternMatcher, INancyModuleBuilder moduleBuilder, IRouteCache cache, IEnumerable <IResponseProcessor> responseProcessors, global::Nancy.TinyIoc.TinyIoCContainer container) { this.nancyModuleCatalog = nancyModuleCatalog; this.routePatternMatcher = routePatternMatcher; this.moduleBuilder = moduleBuilder; this.cache = cache; this.responseProcessors = responseProcessors; _container = container; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRouteResolver"/> class, using /// the provided <paramref name="catalog"/>, <paramref name="moduleBuilder"/>, /// <paramref name="routeCache"/> and <paramref name="trie"/>. /// </summary> /// <param name="catalog">An <see cref="INancyModuleCatalog"/> instance.</param> /// <param name="moduleBuilder">An <see cref="INancyModuleBuilder"/> instance.</param> /// <param name="routeCache">An <see cref="IRouteCache"/> instance.</param> /// <param name="trie">An <see cref="IRouteResolverTrie"/> instance.</param> /// <param name="environment">An <see cref="INancyEnvironment"/> instance.</param> public DefaultRouteResolver(INancyModuleCatalog catalog, INancyModuleBuilder moduleBuilder, IRouteCache routeCache, IRouteResolverTrie trie, INancyEnvironment environment) { this.catalog = catalog; this.moduleBuilder = moduleBuilder; this.routeCache = routeCache; this.trie = trie; this.configuration = new Lazy<RouteConfiguration>(environment.GetValue<RouteConfiguration>); this.BuildTrie(); }
/// <summary> /// Initializes a new instance of the RouteCacheFixture class. /// </summary> public RouteCacheFixture() { this.routeDescriptionProvider = A.Fake <IRouteDescriptionProvider>(); this.routeSegmentExtractor = A.Fake <IRouteSegmentExtractor>(); this.routeMetadataProviders = new IRouteMetadataProvider[0]; this.fakeModuleCatalog = new FakeModuleCatalog(); this.routeCache = new RouteCache(this.fakeModuleCatalog, A.Fake <INancyContextFactory>(), this.routeSegmentExtractor, this.routeDescriptionProvider, A.Fake <ICultureService>(), this.routeMetadataProviders); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRouteResolver"/> class. /// </summary> /// <param name="nancyModuleCatalog">The module catalog that modules should be</param> /// <param name="routePatternMatcher">The route pattern matcher that should be used to verify if the route is a match to any of the registered routes.</param> /// <param name="moduleBuilder">The module builder that will make sure that the resolved module is full configured.</param> /// <param name="cache">The route cache that should be used to resolve modules from.</param> /// <param name="responseProcessors"></param> public NSembleRouteResolver(INancyModuleCatalog nancyModuleCatalog, IRoutePatternMatcher routePatternMatcher, INancyModuleBuilder moduleBuilder, IRouteCache cache, IEnumerable<IResponseProcessor> responseProcessors, global::Nancy.TinyIoc.TinyIoCContainer container) { this.nancyModuleCatalog = nancyModuleCatalog; this.routePatternMatcher = routePatternMatcher; this.moduleBuilder = moduleBuilder; this.cache = cache; this.responseProcessors = responseProcessors; _container = container; }
private IEnumerable <RouteCandidate> GetRoutesThatMatchRequestedPath(IRouteCache routeCache, NancyContext context) { return(from cacheEntry in routeCache from cacheEntryRoutes in cacheEntry.Value let routeIndex = cacheEntryRoutes.Item1 let routeDescription = cacheEntryRoutes.Item2 where ((routeDescription.Condition == null) || (routeDescription.Condition(context))) let result = this.routePatternMatcher.Match(context.Request.Path, routeDescription.Path) where result.IsMatch select new RouteCandidate(cacheEntry.Key, routeIndex, routeDescription, result)); }
/// <inheritdoc /> public void BuildTrie(IRouteCache cache) { foreach (var routeDescription in cache.Routes.Select(x => x.Key)) { if (!_routeTries.TryGetValue(routeDescription.Method, out var rootNode)) { rootNode = _nodeFactory.GetRootNode(); _routeTries.Add(routeDescription.Method, rootNode); } rootNode.Add(routeDescription); } }
/// <summary> /// Initializes a new instance of the <see cref="NancyEngine"/> class. /// </summary> /// <param name="resolver">An <see cref="IRouteResolver"/> instance that will be used to resolve a route, from the modules, that matches the incoming <see cref="Request"/>.</param> /// <param name="routeCache">Cache of all available routes</param> /// <param name="contextFactory">A factory for creating contexts</param> public NancyEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory) { if (resolver == null) { throw new ArgumentNullException("resolver", "The resolver parameter cannot be null."); } if (routeCache == null) { throw new ArgumentNullException("routeCache", "The routeCache parameter cannot be null."); } if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } this.resolver = resolver; this.routeCache = routeCache; this.contextFactory = contextFactory; }
public RouteAppService(IRepository <Route> routeRepository, IRepository <RouteWorker> workerRepository, IRepository <RouteTask> taskRepository, IRepository <RouteEvent> eventRepository, IRepository <RouteArticle> articleRepository, IRepository <RouteInBox> inBoxRepository, IRepository <RouteOutBox> outBoxRepository, IRepository <PreRoute> preRouteRepository, IRepository <PreRouteWorker> preRouteWorkerRepository, IRepository <PreRouteTask> preRouteTaskRepository, IRepository <PreVehicleWorker> preVehicleWorkerRepository, IRepository <ArticleRecord> articleRecordRepository, IRepository <BoxRecord> boxRecordRepository, IRouteTypeCache routeTypeCache, ITaskTypeCache taskTypeCache, IWorkRoleCache workRoleCache, IRouteCache routeCache, IOutletCache outletCache) { _routeRepository = routeRepository; _workerRepository = workerRepository; _taskRepository = taskRepository; _eventRepository = eventRepository; _articleRepository = articleRepository; _inBoxRepository = inBoxRepository; _outBoxRepository = outBoxRepository; _preRouteRepository = preRouteRepository; _preRouteWorkerRepository = preRouteWorkerRepository; _preRouteTaskRepository = preRouteTaskRepository; _preVehicleWorkerRepository = preVehicleWorkerRepository; _articleRecordRepository = articleRecordRepository; _boxRecordRepository = boxRecordRepository; _routeTypeCache = routeTypeCache; _taskTypeCache = taskTypeCache; _workRoleCache = workRoleCache; _routeCache = routeCache; _outletCache = outletCache; }
/// <summary> /// Gets the route, and the corresponding parameter dictionary from the URL /// </summary> /// <param name="context">Current context</param> /// <param name="routeCache">Route cache</param> /// <returns>Tuple - Item1 being the Route, Item2 being the parameters dictionary, Item3 being the prereq, Item4 being the postreq</returns> public ResolveResult Resolve(NancyContext context, IRouteCache routeCache) { if (routeCache.IsEmpty()) { return new ResolveResult(new NotFoundRoute(context.Request.Method, context.Request.Path), DynamicDictionary.Empty, null, null); } var routesThatMatchRequestedPath = this.GetRoutesThatMatchRequestedPath(routeCache, context); if (NoRoutesWereAbleToBeMatchedInRouteCache(routesThatMatchRequestedPath)) { return new ResolveResult(new NotFoundRoute(context.Request.Method, context.Request.Path), DynamicDictionary.Empty, null, null); } var routesWithCorrectRequestMethod = GetRoutesWithCorrectRequestMethod(context.Request, routesThatMatchRequestedPath); if (NoRoutesWereForTheRequestedMethod(routesWithCorrectRequestMethod)) { var allowedMethods = routesThatMatchRequestedPath.Select(x => x.Item3.Method); return new ResolveResult(new MethodNotAllowedRoute(context.Request.Path, context.Request.Method, allowedMethods), DynamicDictionary.Empty, null, null); } var exactMatch = GetRouteMatchesWithExactPathMatch(routesWithCorrectRequestMethod).FirstOrDefault(); if (exactMatch != null) { return this.CreateRouteAndParametersFromMatch(context, exactMatch); } var routeMatchesWithMostParameterCaptures = GetTopRouteMatches(routesWithCorrectRequestMethod); var routeMatchToReturn = GetSingleRouteToReturn(routeMatchesWithMostParameterCaptures); return this.CreateRouteAndParametersFromMatch(context, routeMatchToReturn); }
public FakeEngine(IRouteResolver resolver, IRouteCache routeCache, INancyContextFactory contextFactory) { Resolver = resolver ?? throw new ArgumentNullException(nameof(resolver), "The resolver parameter cannot be null."); RouteCache = routeCache ?? throw new ArgumentNullException(nameof(routeCache), "The routeCache parameter cannot be null."); ContextFactory = contextFactory ?? throw new ArgumentNullException(nameof(contextFactory)); }
ResolveResult IRouteResolver.Resolve(NancyContext context, IRouteCache cache) { return(new ResolveResult(new FakeRoute(), new DynamicDictionary(), null, null)); }
/// <summary> /// Converts an <see cref="IRouteCache"/> into the format used by diagnostics to store route parsing results. /// </summary> /// <param name="cache">The cache that should be converted.</param> /// <returns>A tuple of valid and rejected routes.</returns> public static Tuple <List <Tuple <string, int, RouteDescription, IRoutePatternMatchResult> >, Dictionary <string, List <Tuple <string, int, RouteDescription, IRoutePatternMatchResult> > > > GetRouteCandidates(this IRouteCache cache) { var result = new Tuple <List <Tuple <string, int, RouteDescription, IRoutePatternMatchResult> >, Dictionary <string, List <Tuple <string, int, RouteDescription, IRoutePatternMatchResult> > > >( new List <Tuple <string, int, RouteDescription, IRoutePatternMatchResult> >(), new Dictionary <string, List <Tuple <string, int, RouteDescription, IRoutePatternMatchResult> > >() ); foreach (var cacheEntry in cache) { foreach (var candidate in cacheEntry.Value.Select(cacheEntryRoutes => new Tuple <string, int, RouteDescription, IRoutePatternMatchResult>(cacheEntry.Key, cacheEntryRoutes.Item1, cacheEntryRoutes.Item2, null))) { result.Item1.Add(candidate); } } return(result); }
/// <summary> /// Configures the bootstrapper to use the provided instance of <see cref="IRouteCache"/>. /// </summary> /// <param name="routeCache">The <see cref="IRouteCache"/> instance that should be used by the bootstrapper.</param> /// <returns>An instance to the current <see cref="FakeNancyBootstrapperConfigurator"/>.</returns> public FakeNancyBootstrapperConfigurator RouteCache(IRouteCache routeCache) { this.bootstrapper.configuredInstances[typeof(IRouteCache)] = routeCache; return(this); }
ResolveResult IRouteResolver.Resolve(NancyContext context, IRouteCache cache) { return new ResolveResult(new FakeRoute(), new DynamicDictionary(), null, null); }
public RouteWalker(GraphNode baseNode, IRouteCache routeCache) { this.baseNode = baseNode; this.routeCache = routeCache; }
/// <summary> /// Initializes a new instance of the RouteResolver class. /// </summary> /// <param name="routeCache">Route cache provider</param> /// <param name="moduleCatalog">Module catalog</param> /// <param name="templateSelector">Template selector</param> public DefaultRouteResolver(IRouteCache routeCache, INancyModuleCatalog moduleCatalog, ITemplateEngineSelector templateSelector) { _RouteCache = routeCache; _ModuleCatalog = moduleCatalog; _TemplateSelector = templateSelector; }
/// <summary> /// Initializes a new instance of the DefaultRouteCacheProviderFixture class. /// </summary> public DefaultRouteCacheProviderFixture() { _RouteCache = A.Fake <IRouteCache>(); _Provider = new DefaultRouteCacheProvider(() => _RouteCache); }
private IEnumerable<RouteCandidate> GetRoutesThatMatchRequestedPath(IRouteCache routeCache, NancyContext context) { return from cacheEntry in routeCache from cacheEntryRoutes in cacheEntry.Value let routeIndex = cacheEntryRoutes.Item1 let routeDescription = cacheEntryRoutes.Item2 where ((routeDescription.Condition == null) || (routeDescription.Condition(context))) let result = this.routePatternMatcher.Match(context.Request.Uri, routeDescription.Path) where result.IsMatch select new RouteCandidate(cacheEntry.Key, routeIndex, routeDescription, result); }
private DefaultRouteResolver CreateResolver(IRouteCache cache) { return(new DefaultRouteResolver(this.catalog, this.matcher, this.moduleBuilder, cache)); }
private ResolveResults Resolve(string path, NancyContext context, IRouteCache routeCache) { if (routeCache.IsEmpty()) { context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] No routes available")); return new ResolveResults { Selected = new ResolveResult(new NotFoundRoute(context.Request.Method, path), DynamicDictionary.Empty, null, null, null) }; } var routes = routeCache.GetRouteCandidates(); // Condition routes = routes.Filter(context, "Invalid condition", (ctx, route) => { var validCondition = ((route.Item3.Condition == null) || (route.Item3.Condition(ctx))); return new Tuple<bool, RouteCandidate>( validCondition, route ); }); if (!routes.Item1.Any()) { context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] No route had a valid condition")); return new ResolveResults { Selected = new ResolveResult(new NotFoundRoute(context.Request.Method, path), DynamicDictionary.Empty, null, null, null), Rejected = routes.Item2 }; } // Path routes = routes.Filter(context, "Path did not match", (ctx, route) => { var validationResult = this.routePatternMatcher.Match(path, route.Item3.Path, route.Item3.Segments, context); var routeToReturn = (validationResult.IsMatch) ? new RouteCandidate(route.Item1, route.Item2, route.Item3, validationResult) : route; return new Tuple<bool, RouteCandidate>( validationResult.IsMatch, routeToReturn ); }); if (!routes.Item1.Any()) { context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] No route matched the requested path")); return new ResolveResults { Selected = new ResolveResult(new NotFoundRoute(context.Request.Method, path), DynamicDictionary.Empty, null, null, null), Rejected = routes.Item2 }; } // Method routes = routes.Filter(context, "Request method did not match", (ctx, route) => { var routeMethod = route.Item3.Method.ToUpperInvariant(); var requestMethod = ctx.Request.Method.ToUpperInvariant(); var methodIsValid = routeMethod.Equals(requestMethod) || (routeMethod.Equals("GET") && requestMethod.Equals("HEAD")); return new Tuple<bool, RouteCandidate>( methodIsValid, route ); }); if (!routes.Item1.Any()) { var allowedMethods = routes.Item2.Values.SelectMany(x => x.Select(y => y.Item3.Method)).Distinct(); if (context.Request.Method.Equals("OPTIONS")) { return new ResolveResults { Selected = new ResolveResult(new OptionsRoute(context.Request.Path, allowedMethods), DynamicDictionary.Empty, null, null, null), Rejected = routes.Item2 }; } context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] Route Matched But Method Not Allowed")); return new ResolveResults { Selected = new ResolveResult(new MethodNotAllowedRoute(path, context.Request.Method, allowedMethods), DynamicDictionary.Empty, null, null, null), Rejected = routes.Item2 }; } // Exact match var exactMatchResults = routes.Filter(context, "No exact match", (ctx, route) => { var routeIsExactMatch = !route.Item4.Parameters.GetDynamicMemberNames().Any(); return new Tuple<bool, RouteCandidate>( routeIsExactMatch, route ); }); if (exactMatchResults.Item1.Any()) { context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] Found exact match route")); return new ResolveResults { Selected = this.CreateRouteAndParametersFromMatch(context, exactMatchResults.Item1.First()), Rejected = exactMatchResults.Item2 }; } // First match out of multiple candidates var selected = GetTopRouteMatchesNew(routes).First(); context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] Selected best match")); return new ResolveResults { Selected = this.CreateRouteAndParametersFromMatch(context, selected), Rejected = exactMatchResults.Item2 }; }
private ResolveResults Resolve(string path, NancyContext context, IRouteCache routeCache) { if (routeCache.IsEmpty()) { context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] No routes available")); return(new ResolveResults { Selected = new ResolveResult(new NotFoundRoute(context.Request.Method, path), DynamicDictionary.Empty, null, null, null) }); } var routes = routeCache.GetRouteCandidates(); // Condition routes = routes.Filter(context, "Invalid condition", (ctx, route) => { var validCondition = ((route.Item3.Condition == null) || (route.Item3.Condition(ctx))); return(new Tuple <bool, RouteCandidate>( validCondition, route )); }); if (!routes.Item1.Any()) { context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] No route had a valid condition")); return(new ResolveResults { Selected = new ResolveResult(new NotFoundRoute(context.Request.Method, path), DynamicDictionary.Empty, null, null, null), Rejected = routes.Item2 }); } // Path routes = routes.Filter(context, "Path did not match", (ctx, route) => { var validationResult = this.routePatternMatcher.Match(path, route.Item3.Path, route.Item3.Segments, context); var routeToReturn = (validationResult.IsMatch) ? new RouteCandidate(route.Item1, route.Item2, route.Item3, validationResult) : route; return(new Tuple <bool, RouteCandidate>( validationResult.IsMatch, routeToReturn )); }); if (!routes.Item1.Any()) { context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] No route matched the requested path")); return(new ResolveResults { Selected = new ResolveResult(new NotFoundRoute(context.Request.Method, path), DynamicDictionary.Empty, null, null, null), Rejected = routes.Item2 }); } // Method routes = routes.Filter(context, "Request method did not match", (ctx, route) => { var routeMethod = route.Item3.Method.ToUpperInvariant(); var requestMethod = ctx.Request.Method.ToUpperInvariant(); var methodIsValid = routeMethod.Equals(requestMethod) || (routeMethod.Equals("GET") && requestMethod.Equals("HEAD")); return(new Tuple <bool, RouteCandidate>( methodIsValid, route )); }); if (!routes.Item1.Any()) { var allowedMethods = routes.Item2.Values.SelectMany(x => x.Select(y => y.Item3.Method)).Distinct(); if (context.Request.Method.Equals("OPTIONS")) { return(new ResolveResults { Selected = new ResolveResult(new OptionsRoute(context.Request.Path, allowedMethods), DynamicDictionary.Empty, null, null, null), Rejected = routes.Item2 }); } context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] Route Matched But Method Not Allowed")); return(new ResolveResults { Selected = new ResolveResult(new MethodNotAllowedRoute(path, context.Request.Method, allowedMethods), DynamicDictionary.Empty, null, null, null), Rejected = routes.Item2 }); } // Exact match var exactMatchResults = routes.Filter(context, "No exact match", (ctx, route) => { var routeIsExactMatch = !route.Item4.Parameters.GetDynamicMemberNames().Any(); return(new Tuple <bool, RouteCandidate>( routeIsExactMatch, route )); }); if (exactMatchResults.Item1.Any()) { context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] Found exact match route")); return(new ResolveResults { Selected = this.CreateRouteAndParametersFromMatch(context, exactMatchResults.Item1.First()), Rejected = exactMatchResults.Item2 }); } // First match out of multiple candidates var selected = GetTopRouteMatchesNew(routes).First(); context.Trace.TraceLog.WriteLog(s => s.AppendLine("[DefaultRouteResolver] Selected best match")); return(new ResolveResults { Selected = this.CreateRouteAndParametersFromMatch(context, selected), Rejected = exactMatchResults.Item2 }); }
private DefaultRouteResolver CreateResolver(IRouteCache cache) { return new DefaultRouteResolver(this.catalog, this.matcher, this.moduleBuilder, cache, null); }
public Route Resolve(Request request, IRouteCache cache) { return new FakeRoute(); }