示例#1
0
        public static MidFunc UseDashboard(
            DashboardOptions options,
            RouteCollection routes)
        {
            if (options == null) throw new ArgumentNullException(nameof(options));
            if (routes == null) throw new ArgumentNullException(nameof(routes));

            return
                next =>
                    env =>
                    {
                        var context = new OwinContext(env);
                        var dispatcher = routes.FindDispatcher(context.Request.Path.Value);

                        if (dispatcher == null)
                        {
                            return next(env);
                        }

                        if (options.AuthorizationFilters.Any(filter => !filter.Authorize(context.Environment)))
                        {
                            context.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
                            return Task.FromResult(false);
                        }

                        var dispatcherContext = new RequestDispatcherContext(
                            options,
                            options.Name,
                            options.AppPath,
                            context.Environment,
                            dispatcher.Item2);

                        return dispatcher.Item1.Dispatch(dispatcherContext);
                    };
        }
示例#2
0
        public static IAppBuilder UseDashboard(
            this IAppBuilder builder,
            string pathMatch         = null,
            DashboardOptions options = null,
            RouteCollection routes   = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (string.IsNullOrEmpty(pathMatch))
            {
                pathMatch = "/dashboard";
            }
            if (options == null)
            {
                options = new DashboardOptions();
            }
            if (routes == null)
            {
                routes = new RouteCollectionBuilder().Routes;
            }

            SignatureConversions.AddConversions(builder);

            builder.Map(pathMatch, subApp => subApp
                        .UseOwin()
                        .UseDashboard(options, routes));

            return(builder);
        }
示例#3
0
        public static BuildFunc UseDashboard(
            this BuildFunc builder,
            DashboardOptions options,
            RouteCollection routes)
        {
            if (builder == null) throw new ArgumentNullException(nameof(builder));
            if (options == null) throw new ArgumentNullException(nameof(options));
            if (routes == null) throw new ArgumentNullException(nameof(routes));

            builder(_ => UseDashboard(options, routes));

            return builder;
        }
        public RequestDispatcherContext(
            DashboardOptions options,
            string name,
            string appPath,
            IDictionary<string, object> owinEnvironment,
            Match uriMatch)
        {
            if (options == null) throw new ArgumentNullException(nameof(options));
            if (name == null) throw new ArgumentNullException(nameof(name));
            if (appPath == null) throw new ArgumentNullException(nameof(appPath));
            if (owinEnvironment == null) throw new ArgumentNullException(nameof(owinEnvironment));
            if (uriMatch == null) throw new ArgumentNullException(nameof(uriMatch));

            Options = options;
            Name = name;
            AppPath = appPath;
            OwinEnvironment = owinEnvironment;
            UriMatch = uriMatch;
        }
示例#5
0
        public static IAppBuilder UseDashboard(
            this IAppBuilder builder,
            string pathMatch = null,
            DashboardOptions options = null,
            RouteCollection routes = null)
        {
            if (builder == null) throw new ArgumentNullException(nameof(builder));
            if (string.IsNullOrEmpty(pathMatch)) pathMatch = "/dashboard";
            if (options == null) options = new DashboardOptions();
            if (routes == null) routes = new RouteCollectionBuilder().Routes;

            SignatureConversions.AddConversions(builder);

            builder.Map(pathMatch, subApp => subApp
                .UseOwin()
                .UseDashboard(options, routes));

            return builder;
        }
示例#6
0
        public static MidFunc UseDashboard(
            DashboardOptions options,
            RouteCollection routes)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (routes == null)
            {
                throw new ArgumentNullException(nameof(routes));
            }

            return
                (next =>
                 env =>
            {
                var context = new OwinContext(env);
                var dispatcher = routes.FindDispatcher(context.Request.Path.Value);

                if (dispatcher == null)
                {
                    return next(env);
                }

                if (options.AuthorizationFilters.Any(filter => !filter.Authorize(context.Environment)))
                {
                    context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                    return Task.FromResult(false);
                }

                var dispatcherContext = new RequestDispatcherContext(
                    options,
                    options.Name,
                    options.AppPath,
                    context.Environment,
                    dispatcher.Item2);

                return dispatcher.Item1.Dispatch(dispatcherContext);
            });
        }
示例#7
0
        public static BuildFunc UseDashboard(
            this BuildFunc builder,
            DashboardOptions options,
            RouteCollection routes)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (routes == null)
            {
                throw new ArgumentNullException(nameof(routes));
            }

            builder(_ => UseDashboard(options, routes));

            return(builder);
        }