src/EasyFrameWork/Mvc/Plugin/DeveloperViewFileProvider.cs

(完整代码) 1KB

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using Easy.Extend;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.FileProviders.Physical;
using Microsoft.Extensions.Primitives;
using System;
using System.IO;

namespace Easy.Mvc.Plugin
{
    public class DeveloperViewFileProvider : IFileProvider
    {
        public const string ProjectRootPath = "/Porject.RootPath/";
        public DeveloperViewFileProvider(IWebHostEnvironment hostingEnvironment)
        {
            HostingEnvironment = hostingEnvironment;
        }
        public IDirectoryContents GetDirectoryContents(string subpath)
        {
            return null;
        }
        public IWebHostEnvironment HostingEnvironment { get; }

        public IFileInfo GetFileInfo(string subpath)
        {
            if (subpath.StartsWith(ProjectRootPath, StringComparison.Ordinal))
            {
                var parent = new DirectoryInfo(HostingEnvironment.ContentRootPath).Parent;
                var file = Path.Combine(parent.FullName, subpath.Replace(ProjectRootPath, string.Empty).ToFilePath());
                if (File.Exists(file))
                {
                    return new PhysicalFileInfo(new FileInfo(file));
                }
            }
            return null;
        }

        public IChangeToken Watch(string filter)
        {
            if (filter.StartsWith(ProjectRootPath, StringComparison.Ordinal))
            {
                var parent = new DirectoryInfo(HostingEnvironment.ContentRootPath).Parent;
                var file = Path.Combine(parent.FullName, filter.Replace(ProjectRootPath, string.Empty).ToFilePath());
                if (File.Exists(file))
                {
                    return new PollingFileChangeToken(new FileInfo(file));
                }
            }
            return null;
        }
    }
}

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

AI 解读 AI

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

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