mirror of https://github.com/abpframework/abp.git
csharpabpc-sharpframeworkblazoraspnet-coredotnet-coreaspnetcorearchitecturesaasdomain-driven-designangularmulti-tenancy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
69 lines
1.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.Extensions.FileProviders;
|
|
using Microsoft.Extensions.Primitives;
|
|
|
|
namespace Volo.Abp.VirtualFileSystem;
|
|
|
|
public abstract class DictionaryBasedFileProvider : IFileProvider
|
|
{
|
|
protected abstract IDictionary<string, IFileInfo> Files { get; }
|
|
|
|
public virtual IFileInfo GetFileInfo(string? subpath)
|
|
{
|
|
if (subpath == null)
|
|
{
|
|
return new NotFoundFileInfo(subpath!);
|
|
}
|
|
|
|
var file = Files.GetOrDefault(NormalizePath(subpath)) ?? Files.GetOrDefault(subpath);
|
|
|
|
if (file == null)
|
|
{
|
|
return new NotFoundFileInfo(subpath);
|
|
}
|
|
|
|
return file;
|
|
}
|
|
|
|
public virtual IDirectoryContents GetDirectoryContents(string subpath)
|
|
{
|
|
var directory = GetFileInfo(subpath);
|
|
if (!directory.IsDirectory)
|
|
{
|
|
return NotFoundDirectoryContents.Singleton;
|
|
}
|
|
|
|
var fileList = new List<IFileInfo>();
|
|
|
|
var directoryPath = subpath.EnsureEndsWith('/');
|
|
foreach (var fileInfo in Files.Values)
|
|
{
|
|
var fullPath = fileInfo.GetVirtualOrPhysicalPathOrNull();
|
|
if (fullPath == null || !fullPath.StartsWith(directoryPath))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var relativePath = fullPath.Substring(directoryPath.Length);
|
|
if (relativePath.Contains("/"))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
fileList.Add(fileInfo);
|
|
}
|
|
|
|
return new EnumerableDirectoryContents(fileList);
|
|
}
|
|
|
|
public virtual IChangeToken Watch(string filter)
|
|
{
|
|
return NullChangeToken.Singleton;
|
|
}
|
|
|
|
protected virtual string NormalizePath(string subpath)
|
|
{
|
|
return subpath;
|
|
}
|
|
}
|
|
|