예제 #1
0
        public static MidFunc UsePugTraceDashboard(
            DashboardOptions options,
            TraceStorage storage,
            RouteCollection routes)
        {
            if (options == null) throw new ArgumentNullException("options");
            if (routes == null) throw new ArgumentNullException("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.AppPath,
                        storage,
                        context.Environment,
                        dispatcher.Item2);

                    return dispatcher.Item1.Dispatch(dispatcherContext);
                };
        }
예제 #2
0
        public Task Dispatch(RequestDispatcherContext context)
        {
            var owinContext = new OwinContext(context.OwinEnvironment);
            owinContext.Response.ContentType = "text/html";

            var page = _pageFunc(context.UriMatch);
            page.Assign(context);

            return owinContext.Response.WriteAsync(page.ToString());
        }
예제 #3
0
        public Task Dispatch(RequestDispatcherContext context)
        {
            var owinContext = new OwinContext(context.OwinEnvironment);

            owinContext.Response.ContentType = _contentType;
            owinContext.Response.Expires = DateTime.Now.AddYears(1);

            WriteResponse(owinContext.Response);

            return Task.FromResult(true);
        }
예제 #4
0
        internal void Assign(RequestDispatcherContext context)
        {
            var owinContext = new OwinContext(context.OwinEnvironment);

            Request = owinContext.Request;
            Response = owinContext.Response;
            Storage = context.Storage;
            AppPath = context.AppPath;
            Url = new UrlHelper(context.OwinEnvironment);
        }