Beispiel #1
0
        public Task Dispatch(RequestDispatcherContext context)
        {
            // execute the template
            var resource = _resourceFunc(context.UriMatch);

            return(resource.Dispatch(context));
        }
Beispiel #2
0
        public Task Dispatch(RequestDispatcherContext context)
        {
            var owinContext = new OwinContext(context.OwinEnvironment);

            var serialized = JsonConvert.SerializeObject(CreateResponseObject(owinContext), _settings);

            owinContext.Response.ContentType = "application/json";
            owinContext.Response.WriteAsync(serialized);

            return(Task.FromResult(true));
        }
        public Task Dispatch(RequestDispatcherContext context)
        {
            var owinContext = new OwinContext(context.OwinEnvironment);

            // execute the template
            var template = _templateFunc(context.UriMatch);

            template.Assign(context);

            if (!string.IsNullOrEmpty(template.ContentType))
            {
                owinContext.Response.ContentType = template.ContentType;
            }
            return(owinContext.Response.WriteAsync(template.ToString()));
        }
Beispiel #4
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);

            if (context.Options?.MaxAge > 0)
            {
                owinContext.Response.Headers.Add("Cache-Control", new[] { context.Options.MaxAge.ToString() });
                //owinContext.Response.Headers.Add("ETag", new[] { "zxry" });
            }

            return(Task.FromResult(true));
        }
Beispiel #5
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);
            });
        }
 public CommandDispatcher(Func <RequestDispatcherContext, bool> command)
 {
     _command = context => command(RequestDispatcherContext.FromDashboardContext(context));
 }