Esempio n. 1
0
        public RouteData WalkRoute(IDictionary<string, object> environment, RouteData info)
        {
            this.Environment = environment;

            CacheEntry<RouteData> cacheEntry;
            if (this.routeCache.TryGet(this.Method + "-" + this.Route, out cacheEntry))
            {
                info = cacheEntry.Info;
                info.Response = cacheEntry.OnComplete(info);

                info.FinalFunctionExecuted = true;

                return info;
            }

            if (!string.IsNullOrEmpty(this.Querystring))
            {
                var queries = this.Querystring.Split('&');
                foreach (var query in queries)
                {
                    if (query.Contains("="))
                    {
                        var operands = query.Split('=');
                        info.Parameters[operands[0]] = Uri.UnescapeDataString(operands[1]);
                    }
                }
            }

            this.RemainingSegments = new Queue<string>(this.Route.Split('/'));
            this.WalkRoute(info, this.baseNode);

            return info;
        }
Esempio n. 2
0
        public RouteData WalkRoute(string route, string method, RouteData info)
        {
            string querystring = null;
            this.Method = info.Method = method;
            this.Route = info.Url = route;

            CacheEntry<RouteData> cacheEntry;
            if (routeCache.TryGet(method + "-" + route, out cacheEntry))
            {
                info = cacheEntry.Info;
                info.Response = cacheEntry.OnComplete(info);

                info.FinalFunctionExecuted = true;

                return info;
            }

            var parts = route.Split('?');
            if (parts.Length > 0)
            {
                route = parts[0];
            }

            if (parts.Length > 1)
            {
                querystring = parts[1];
            }

            if (!string.IsNullOrEmpty(querystring))
            {
                var queries = querystring.Split('&');
                foreach (var query in queries)
                {
                    if (query.Contains("="))
                    {
                        var operands = query.Split('=');
                        info.Parameters[operands[0]] = Uri.UnescapeDataString(operands[1]);
                    }
                }
            }

            this.RemainingSegments = new Queue<string>(route.Split('/'));
            this.WalkRoute(info, this.baseNode);

            return info;
        }
Esempio n. 3
0
 private GraphNode FindNextMatch(RouteData info, string segment, IEnumerable<GraphNode> states)
 {
     return !string.IsNullOrEmpty(segment) ?
         states.FirstOrDefault(o => o.ActivationFunction(info, segment))
         : null;
 }
Esempio n. 4
0
        public void WalkRoute(RouteData info, GraphNode match)
        {
            FinalFunction onComplete = null;
            while (match != null)
            {
                foreach (var action in match.ActionFunctions.Values)
                {
                    action(info, this.PeekNextSegment());
                }

                if (this.RemainingSegments.Any())
                {
                    this.RemainingSegments.Dequeue();
                }

                if (onComplete != null)
                {
                    if (onComplete.IsExclusive)
                    {
                        onComplete = null;
                    }
                }

                if (match.FinalFunctions.Count > 0)
                {
                    var function = match.FinalFunctions.FirstOrDefault(o => o.MatchesFilter(this.Environment));
                    if (function != null)
                    {
                        onComplete = function;
                    }
                }

                var nextMatch = this.FindNextMatch(info, this.PeekNextSegment(), match.Edges);
                if (nextMatch == null)
                {
                    if (this.HasFinalsButNoneMatchTheCurrentMethod(match))
                    {
                        info.NoMatchingFinalFunction = true;
                        return;
                    }
                }

                match = nextMatch;
            }

            if (this.RemainingSegments.Any(o => !string.IsNullOrEmpty(o)))
            {
                info.ExtraneousMatch = true;
                return;
            }

            if (onComplete != null)
            {
                this.routeCache.Store(this.Method + "-" + this.Route, new CacheEntry<RouteData> { Info = info, OnComplete = onComplete.Function });
                info.Response = onComplete.Function(info);
                info.FinalFunctionExecuted = true;
            }
        }
Esempio n. 5
0
 private GraphNode FindNextMatch(RouteData info, string segment, IEnumerable <GraphNode> states)
 {
     return(!string.IsNullOrEmpty(segment) ?
            states.FirstOrDefault(o => o.ActivationFunction(info, segment))
         : null);
 }
Esempio n. 6
0
        public void WalkRoute(RouteData info, GraphNode match)
        {
            FinalFunction onComplete = null;

            while (match != null)
            {
                foreach (var action in match.ActionFunctions.Values)
                {
                    action(info, this.PeekNextSegment());
                }

                if (this.RemainingSegments.Any())
                {
                    this.RemainingSegments.Dequeue();
                }

                if (onComplete != null)
                {
                    if (onComplete.IsExclusive)
                    {
                        onComplete = null;
                    }
                }

                if (match.FinalFunctions.Count > 0)
                {
                    var function = match.FinalFunctions.FirstOrDefault(o => o.MatchesFilter(this.Environment));
                    if (function != null)
                    {
                        onComplete = function;
                    }
                }

                var nextMatch = this.FindNextMatch(info, this.PeekNextSegment(), match.Edges);
                if (nextMatch == null)
                {
                    if (this.HasFinalsButNoneMatchTheCurrentMethod(match))
                    {
                        info.NoMatchingFinalFunction = true;
                        return;
                    }
                }

                match = nextMatch;
            }

            if (this.RemainingSegments.Any(o => !string.IsNullOrEmpty(o)))
            {
                info.ExtraneousMatch = true;
                return;
            }

            if (onComplete != null)
            {
                this.routeCache.Store(this.Method + "-" + this.Route, new CacheEntry <RouteData> {
                    Info = info, OnComplete = onComplete.Function
                });
                info.Response = onComplete.Function(info);
                info.FinalFunctionExecuted = true;
            }
        }