private UrlSegment MatchUrlSegment(PomonaRequest request) { var match = new PomonaRouteResolver(Routes).Resolve(this, request.RelativePath); if (match == null) { throw new ResourceNotFoundException("Resource not found."); } var finalSegmentMatch = match.Root.SelectedFinalMatch; if (finalSegmentMatch == null) { // Route conflict resolution: var node = match.Root.NextConflict; while (node != null) { var actualResultType = node.ActualResultType; // Reduce using input type difference var validSelection = node.Children .Where(x => x.Route.InputType.IsAssignableFrom(actualResultType)) .SingleOrDefaultIfMultiple(); if (validSelection == null) { throw new ResourceNotFoundException("No route alternative found due to conflict."); } node.SelectedChild = validSelection; node = node.NextConflict; } finalSegmentMatch = match.Root.SelectedFinalMatch; } return(finalSegmentMatch); }
public PomonaContext(UrlSegment node, PomonaRequest request = null, string expandedPaths = null, bool executeQueryable = false, bool handleException = true, Type acceptType = null) { if (node == null) throw new ArgumentNullException(nameof(node)); Node = node; Request = request ?? new PomonaRequest(node.RelativePath, node.RelativePath); ExpandedPaths = expandedPaths ?? GetExpandedPathsFromRequest(Request.Headers, Query); ExecuteQueryable = executeQueryable; HandleException = handleException; AcceptType = acceptType; }
public static PomonaResponse Get(this IPomonaSession session, string url) { // TODO: Move this to some other class. string urlWithoutQueryPart = url; DynamicDictionary query = null; var queryStart = url.IndexOf('?'); if (queryStart != -1) { urlWithoutQueryPart = url.Substring(0, queryStart); query = url.Substring(queryStart + 1).AsQueryDictionary(); } var relativePath = session.GetInstance<IUriResolver>().ToRelativePath(urlWithoutQueryPart); var req = new PomonaRequest(url, relativePath, query : query); return session.Dispatch(req); }
public PomonaContext(UrlSegment node, PomonaRequest request = null, string expandedPaths = null, bool executeQueryable = false, bool handleException = true, Type acceptType = null) { if (node == null) { throw new ArgumentNullException(nameof(node)); } Node = node; Request = request ?? new PomonaRequest(node.RelativePath, node.RelativePath); ExpandedPaths = expandedPaths ?? GetExpandedPathsFromRequest(Request.Headers, Query); ExecuteQueryable = executeQueryable; HandleException = handleException; AcceptType = acceptType; }
public static PomonaResponse Get(this IPomonaSession session, string url) { // TODO: Move this to some other class. string urlWithoutQueryPart = url; DynamicDictionary query = null; var queryStart = url.IndexOf('?'); if (queryStart != -1) { urlWithoutQueryPart = url.Substring(0, queryStart); query = url.Substring(queryStart + 1).AsQueryDictionary(); } var relativePath = session.GetInstance <IUriResolver>().ToRelativePath(urlWithoutQueryPart); var req = new PomonaRequest(url, relativePath, query: query); return(session.Dispatch(req)); }
public virtual PomonaResponse Dispatch(PomonaRequest request) { var finalSegmentMatch = MatchUrlSegment(request); return(Dispatch(new PomonaContext(finalSegmentMatch, request, executeQueryable: true))); }
private PomonaResponse GetResource() { var pathNodes = GetPathNodes(); var rootNode = new DataSourceRootNode(TypeMapper, this.dataSource); PathNode node = rootNode; foreach (var pathPart in pathNodes.WalkTree(x => x.Next).Skip(1).Select(x => x.Value)) node = node.GetChildNode(pathPart); var pomonaRequest = new PomonaRequest(node, Context, new PomonaJsonSerializerFactory(Context.GetSerializationContextProvider())); if (!node.AllowedMethods.HasFlag(pomonaRequest.Method)) ThrowMethodNotAllowedForType(node.AllowedMethods); var response = new DefaultRequestProcessorPipeline().Process(pomonaRequest); if (response == null) throw new PomonaException("Unable to find RequestProcessor able to handle request."); return response; }
protected virtual IPomonaRequestProcessor OnGetRequestProcessor(PomonaRequest request) { return null; }
public IEnumerable<IPomonaRequestProcessor> GetRequestProcessors(PomonaRequest request) { var nodeProcessor = OnGetRequestProcessor(request); var head = nodeProcessor != null ? nodeProcessor.WrapAsEnumerable() : Enumerable.Empty<IPomonaRequestProcessor>(); return Parent != null ? head.Concat(Parent.GetRequestProcessors(request)) : head; }
protected override IPomonaRequestProcessor OnGetRequestProcessor(PomonaRequest request) { return new DataSourceRequestProcessor(this.dataSource); }