public IModuleRouteData WalkRoute(string route, string method, IModuleRouteData info) { this.Method = info.Method = method; this.Route = info.Url = route; CacheEntry<IModuleRouteData> cacheEntry; if (routeCache.TryGet(method + "-" + route, out cacheEntry)) { info.Parameters = cacheEntry.Info.Parameters; info.Response = cacheEntry.OnComplete(info); info.FinalFunctionExecuted = true; return info; } this.RemainingSegments = new Queue<string>(route.Split('/')); this.WalkRoute(info, this.baseNode); return info; }
public void WalkRoute(IModuleRouteData 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.Method == this.Method) ?? match.FinalFunctions.FirstOrDefault(o => string.IsNullOrEmpty(o.Method)); 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) { routeCache.Store(this.Method + "-" + this.Route, new CacheEntry<IModuleRouteData> { Info = info, OnComplete = onComplete.Function }); info.Response = onComplete.Function(info); info.FinalFunctionExecuted = true; } }
private GraphNode FindNextMatch(IModuleRouteData info, string segment, IEnumerable<GraphNode> states) { return !string.IsNullOrEmpty(segment) ? states.FirstOrDefault(o => o.ActivationFunction(info, segment)) : null; }
protected static object CheckAge(IModuleRouteData o) { return o.Parameters["Age"] >= 18 ? "Access granted" : "Too young"; }
protected static object CommentOnMood(IModuleRouteData o) { return (bool)o.Parameters["Happy"] ? "Me too!" : "Why so sad?"; }
protected static object HelloUnknown(IModuleRouteData o) { return "Hello Unknown Person"; }
protected static object Hello(IModuleRouteData o) { return string.Format("Hello {0}", o.Parameters["Name"]); }
public OwinRouteDataProvider(IModuleRouteData data) { this.data = data; }