示例#1
0
        public IActionResult OnGet(int pageNumber)
        {
            int postsCount = _blogPostRepository.PostsCount();
            var pagesCount = postsCount / POSTS_PER_PAGE
                             - (postsCount % POSTS_PER_PAGE == 0 ? 1 : 0);

            if (pageNumber > pagesCount)
            {
                return(RedirectToPage("/LostAndNotFound"));
            }

            this.PageNum  = pageNumber;
            this.PrevPage = pageNumber >= pagesCount ? (int?)null : (pageNumber + 1);
            this.NextPage = pageNumber == 0 ? (int?)null : (pageNumber - 1);
            this.Posts    = _blogPostRepository.FindPostsByPage(this.PageNum, POSTS_PER_PAGE).ToList();

            var handler = _serviceProvider.GetService <IncrementViewsHandler>();

            (handler as IncrementViewsHandler)?
            .Handle(new IncrementViewsHandlerRequest());

            this.Version = _versionService.GetCurrentGitSHA();

            return(Page());
        }
示例#2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment environment,
            IServiceProvider serviceProvider,
            ILoggerFactory loggerFactory,
            IGitRepository gitRepository,
            IVersionService versionService,
            IConfiguration configuration)
        {
            var logsPath = configuration["LogsLocalPath"];

            if (!Directory.Exists(logsPath))
            {
                Directory.CreateDirectory(logsPath);
            }

            loggerFactory.AddFile(logsPath + "/hysite-{Date}.log");

            var logger  = loggerFactory.CreateLogger("startup");
            var version = versionService.GetCurrentGitSHA();

            logger.LogWarning($"git commit: {version}");

            if (environment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            var postsPath = configuration["PostsLocalPath"];

            var configParsed = bool.TryParse(configuration["loadFromGit"], out bool loadFromGit);

            if (configParsed && loadFromGit)
            {
                if (Directory.Exists(postsPath))
                {
                    Directory.Delete(postsPath, recursive: true);
                }

                gitRepository.Clone();
            }

            var postsFullPath = Path.Combine(Directory.GetCurrentDirectory(), postsPath);
            var imagesFullPth = Path.Combine(postsFullPath, "img");

            if (!Directory.Exists(postsFullPath))
            {
                Directory.CreateDirectory(postsFullPath);
            }

            if (!Directory.Exists(imagesFullPth))
            {
                Directory.CreateDirectory(imagesFullPth);
            }

            app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(postsFullPath),
                RequestPath  = new PathString("")
            });
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(imagesFullPth),
                RequestPath  = new PathString("")
            });
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(postsFullPath),
                RequestPath  = new PathString("/.well-known/pki-validation") //@todo: this is for https cert validation, probably can be removed später?
            });

            app.UseRouting();
            app.UseHttpsRedirection();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}"
                    );
            });

            var fileParser = serviceProvider.GetService <IFileParserService>();

            fileParser.ParseExistingFiles();
        }
示例#3
0
 public IActionResult OnGet()
 {
     this.Version   = _versionService.GetCurrentGitSHA();
     this.Framework = _versionService.GetFrameworkVersion();
     return(Page());
 }