Пример #1
0
 public MazeRequestExecuter(IRouteResolver routeResolver, IRouteCache routeCache,
                            ILogger <MazeRequestExecuter> logger)
 {
     _routeResolver = routeResolver;
     _routeCache    = routeCache;
     _logger        = logger;
 }
Пример #2
0
 /// <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;
 }
Пример #3
0
        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;
        }
Пример #4
0
        public RouteResolverTrie(ITrieNodeFactory nodeFactory, IRouteCache cache)
        {
            _nodeFactory = nodeFactory;
            _routeTries  = new Dictionary <string, TrieNode>(StringComparer.OrdinalIgnoreCase);

            BuildTrie(cache);
        }
Пример #5
0
        /// <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));
        }
Пример #6
0
        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);
        }
Пример #7
0
        /// <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);
        }
Пример #8
0
 public DefaultRouteResolver(
     IChatModuleCatalog catalog,
     IRouteCache routeCache)
 {
     this.catalog    = catalog;
     this.routeCache = routeCache;
 }
Пример #9
0
 /// <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;
 }
Пример #10
0
        /// <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;
        }
Пример #11
0
        /// <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);
                }
            }
        }
Пример #12
0
        /// <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);
                }
            }
        }
Пример #13
0
        /// <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;
        }
Пример #14
0
 /// <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;
 }
Пример #15
0
 /// <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;
 }
Пример #16
0
        /// <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);
        }
Пример #17
0
        /// <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);
        }
Пример #18
0
        /// <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();
        }
Пример #19
0
        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();
        }
Пример #21
0
        /// <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>());
        }
Пример #22
0
        /// <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>());
        }
Пример #23
0
        /// <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();
        }
Пример #24
0
        /// <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;
        }
Пример #25
0
 /// <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;
 }
Пример #26
0
        /// <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();
        }
Пример #27
0
        /// <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);
        }
Пример #28
0
 /// <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;
 }
Пример #29
0
 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));
 }
Пример #30
0
        /// <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);
            }
        }
Пример #31
0
        /// <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;
        }
Пример #32
0
 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;
 }
Пример #33
0
        /// <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);
        }
Пример #34
0
 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));
 }
Пример #35
0
 ResolveResult IRouteResolver.Resolve(NancyContext context, IRouteCache cache)
 {
     return(new ResolveResult(new FakeRoute(), new DynamicDictionary(), null, null));
 }
Пример #36
0
        /// <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);
        }
Пример #37
0
 /// <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);
 }
Пример #38
0
 ResolveResult IRouteResolver.Resolve(NancyContext context, IRouteCache cache)
 {
     return new ResolveResult(new FakeRoute(), new DynamicDictionary(), null, null);
 }
Пример #39
0
 public RouteWalker(GraphNode baseNode, IRouteCache routeCache)
 {
     this.baseNode = baseNode;
     this.routeCache = routeCache;
 }
Пример #40
0
 /// <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);
 }
Пример #42
0
 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);
 }
Пример #43
0
 private DefaultRouteResolver CreateResolver(IRouteCache cache)
 {
     return(new DefaultRouteResolver(this.catalog, this.matcher, this.moduleBuilder, cache));
 }
Пример #44
0
        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
            };
        }
Пример #45
0
        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);
 }
Пример #47
0
 public Route Resolve(Request request, IRouteCache cache)
 {
     return new FakeRoute();
 }
Пример #48
0
 public RouteWalker(GraphNode baseNode, IRouteCache routeCache)
 {
     this.baseNode   = baseNode;
     this.routeCache = routeCache;
 }