Exemple #1
0
        private async Task ExecuteRouter(string routeName, HttpContext context)
        {
            var route = _routes.FirstOrDefault(x => x.Path.Equals(routeName, StringComparison.OrdinalIgnoreCase));

            if (route != null)
            {
                var component = (Component)_provider.GetRequiredService(route.Component);

                await context.Response.WriteAsync(StartCompile(component));
            }
            else
            {
                context.Response.StatusCode = 404;
            }
        }
Exemple #2
0
        private async Task ExecuteRouter(RouteContext context)
        {
            context.HttpContext.Request.Path = context.HttpContext.Request.Path.Value.Replace("/c/", "/");
            var       actualRoute = (Route)context.RouteData.Routers[1];
            RouteTree routeTree;
            var       bibaRoute = _routes.FirstOrDefault(x => x.Path.ToLower().Equals(actualRoute.Name));

            if (bibaRoute != null)
            {
                routeTree = new RouteTree {
                    Route = bibaRoute, RouteName = bibaRoute.Path
                }
            }
            ;
            else
            {
                routeTree = BuildRouteTree(TemplateParser.Parse(context.HttpContext.Request.Path.Value.Remove(0, 1)).Segments,
                                           TemplateParser.Parse(PathString.FromUriComponent(
                                                                    new Uri(context.HttpContext.Request.Headers["Referer"].ToString(), UriKind.Absolute)).Value.Remove(0, 1)).Segments);
            }

            var completeTemplate = new RouterResult();

            try
            {
                completeTemplate = await CompileRoutes(routeTree, context);
            }
            catch (UnauthorizedAccessException)
            {
                context.HttpContext.Response.StatusCode = 401;
                await context.HttpContext.Response.WriteAsync("Unauthorize");
            }

            await context.HttpContext.Response.WriteAsync(JsonConvert.SerializeObject(completeTemplate,
                                                                                      new JsonSerializerSettings {
                ContractResolver = _contractResolver
            }));
        }
Exemple #3
0
 public static BibaRoute FindRoute(this Routes source, string routePath) =>
 source.FirstOrDefault(x => x.Path.Equals(routePath, StringComparison.CurrentCultureIgnoreCase));