src/Web/WebMVC/Infrastructure/WebContextSeed.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

namespace WebMVC.Infrastructure;
using Serilog;

public class WebContextSeed
{
    public static void Seed(IApplicationBuilder applicationBuilder, IWebHostEnvironment env)
    {
        var log = Serilog.Log.Logger;

        var settings = (AppSettings)applicationBuilder
            .ApplicationServices.GetRequiredService<IOptions<AppSettings>>().Value;

        var useCustomizationData = settings.UseCustomizationData;
        var contentRootPath = env.ContentRootPath;
        var webroot = env.WebRootPath;

        if (useCustomizationData)
        {
            GetPreconfiguredImages(contentRootPath, webroot, log);

            GetPreconfiguredCSS(contentRootPath, webroot, log);
        }
    }

    static void GetPreconfiguredCSS(string contentRootPath, string webroot, ILogger log)
    {
        try
        {
            string overrideCssFile = Path.Combine(contentRootPath, "Setup", "override.css");
            if (!File.Exists(overrideCssFile))
            {
                log.Error("Override css file '{FileName}' does not exists.", overrideCssFile);
                return;
            }

            string destinationFilename = Path.Combine(webroot, "css", "override.css");
            File.Copy(overrideCssFile, destinationFilename, true);
        }
        catch (Exception ex)
        {
            log.Error(ex, "EXCEPTION ERROR: {Message}", ex.Message);
        }
    }

    static void GetPreconfiguredImages(string contentRootPath, string webroot, ILogger log)
    {
        try
        {
            string imagesZipFile = Path.Combine(contentRootPath, "Setup", "images.zip");
            if (!File.Exists(imagesZipFile))
            {
                log.Error("Zip file '{ZipFileName}' does not exists.", imagesZipFile);
                return;
            }

            string imagePath = Path.Combine(webroot, "images");
            string[] imageFiles = Directory.GetFiles(imagePath).Select(file => Path.GetFileName(file)).ToArray();

            using ZipArchive zip = ZipFile.Open(imagesZipFile, ZipArchiveMode.Read);
            foreach (ZipArchiveEntry entry in zip.Entries)
后面还有 23 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。