public NotificationResult Post([FromBody] HeadlessNotification notification)
        {
            var pagePath = GetPagePath(notification.Id);

            StazorFileManagementService.DeletePage(pagePath);
            return(new NotificationResult {
                Status = NotificationStatus.Success, Message = "Stazor page deleted successfully."
            });
        }
コード例 #2
0
        /// <summary>
        /// Adds services needed to generate static HTML pages.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
        /// <param name="env">The <see cref="IWebHostEnvironment"/>.</param>
        /// <returns>An <see cref="IServiceCollection"/>.</returns>
        public static IServiceCollection AddStazorPages(this IServiceCollection services, IWebHostEnvironment env)
        {
            StazorFileManagementService.EnsureStazorPageDirectory();

            services.Configure <StazorFileOptions>(
                options =>
            {
                options.FileProvider = new PhysicalFileProvider(
                    Path.Combine(env.ContentRootPath, DefaultFilePaths.StazorPageDirectory));
            });

            services.AddSingleton <StazorRouteTransformer>();

            services.AddSingleton <StazorFileDetector>();

            return(services);
        }
コード例 #3
0
        /// <summary>
        /// Enables the generation of static HTML pages on the first request.
        /// </summary>
        /// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
        /// <param name="env">The <see cref="IWebHostEnvironment"/>.</param>
        /// <param name="useMiddleWare">Enables the generation of static HTML pages. Can be switched off for debugging purposes.</param>
        /// <returns>A reference to the <paramref name="app"/> after the operation has completed.</returns>
        /// <remarks>
        /// This should only be enabled in the Development environment as it deletes static pages at every startup.
        /// </remarks>
        public static IApplicationBuilder UseStazorPagesInDevelopment(this IApplicationBuilder app, IWebHostEnvironment env, bool useMiddleWare = true)
        {
            UseRewriter(app);

            UseStaticFiles(app, env);

            if (useMiddleWare)
            {
                app.UseMiddleware <StazorMiddleware>();
            }

            // re-add this here to show detailed messages - TODO: Bubble up errors to middleware
            app.UseDeveloperExceptionPage();

            StazorFileManagementService.CleanStazorPageDirectory();

            return(app);
        }
コード例 #4
0
        public async Task InvokeSavePage(HttpContext context)
        {
            var    response = context.Response;
            string responseBody;

            await using (var responseMemoryStream = new MemoryStream())
            {
                var originalResponseBodyReference = response.Body;
                response.Body = responseMemoryStream;

                await _next(context);

                response.Body.Seek(0, SeekOrigin.Begin);
                responseBody = await new StreamReader(response.Body).ReadToEndAsync();
                response.Body.Seek(0, SeekOrigin.Begin);

                await responseMemoryStream.CopyToAsync(originalResponseBodyReference);
            }

            if (response.StatusCode == StatusCodes.Status200OK)
            {
                await StazorFileManagementService.SavePage(responseBody, context.Request.RouteValues[RouteParameters.FilePath]?.ToString());
            }
        }