Fixed virtual file static file middleware compatibility issue for asp.net core 3.0

pull/1810/head
Halil İbrahim Kalkan 5 years ago
parent a187831b73
commit be5406a5d0

@ -84,7 +84,7 @@ namespace Volo.Abp.Localization.VirtualFiles
var dictionary = CreateDictionaryFromFile(file);
if (dictionaries.ContainsKey(dictionary.CultureName))
{
throw new AbpException($"{file.PhysicalPath} dictionary has a culture name '{dictionary.CultureName}' which is already defined!");
throw new AbpException($"{file.GetVirtualOrPhysicalPathOrNull()} dictionary has a culture name '{dictionary.CultureName}' which is already defined!");
}
dictionaries[dictionary.CultureName] = dictionary;

@ -3,6 +3,7 @@ using System.IO;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.VirtualFileSystem.Embedded;
namespace Microsoft.Extensions.FileProviders
{
@ -57,5 +58,17 @@ namespace Microsoft.Extensions.FileProviders
return await stream.GetAllBytesAsync();
}
}
public static string GetVirtualOrPhysicalPathOrNull([NotNull] this IFileInfo fileInfo)
{
Check.NotNull(fileInfo, nameof(fileInfo));
if (fileInfo is EmbeddedResourceFileInfo embeddedFileInfo)
{
return embeddedFileInfo.VirtualPath;
}
return fileInfo.PhysicalPath;
}
}
}

@ -39,12 +39,13 @@ namespace Volo.Abp.VirtualFileSystem
var directoryPath = subpath.EnsureEndsWith('/');
foreach (var fileInfo in Files.Values)
{
if (!fileInfo.PhysicalPath.StartsWith(directoryPath))
var fullPath = fileInfo.GetVirtualOrPhysicalPathOrNull();
if (!fullPath.StartsWith(directoryPath))
{
continue;
}
var relativePath = fileInfo.PhysicalPath.Substring(directoryPath.Length);
var relativePath = fullPath.Substring(directoryPath.Length);
if (relativePath.Contains("/"))
{
continue;

@ -31,8 +31,9 @@ namespace Volo.Abp.VirtualFileSystem
public void AddOrUpdate(IFileInfo fileInfo)
{
DynamicFiles.AddOrUpdate(fileInfo.PhysicalPath, fileInfo, (key, value) => fileInfo);
ReportChange(fileInfo.PhysicalPath);
var filePath = fileInfo.GetVirtualOrPhysicalPathOrNull();
DynamicFiles.AddOrUpdate(filePath, fileInfo, (key, value) => fileInfo);
ReportChange(filePath);
}
public bool Delete(string filePath)

@ -29,7 +29,9 @@ namespace Volo.Abp.VirtualFileSystem.Embedded
}
private long? _length;
public string PhysicalPath { get; }
public string PhysicalPath => null;
public string VirtualPath { get; }
public string Name { get; }
@ -46,14 +48,14 @@ namespace Volo.Abp.VirtualFileSystem.Embedded
public EmbeddedResourceFileInfo(
Assembly assembly,
string resourcePath,
string physicalPath,
string virtualPath,
string name,
DateTimeOffset lastModified)
{
_assembly = assembly;
_resourcePath = resourcePath;
PhysicalPath = physicalPath;
VirtualPath = virtualPath;
Name = name;
LastModified = lastModified;
}
@ -63,7 +65,7 @@ namespace Volo.Abp.VirtualFileSystem.Embedded
{
var stream = _assembly.GetManifestResourceStream(_resourcePath);
if (!_length.HasValue)
if (!_length.HasValue && stream != null)
{
_length = stream.Length;
}
@ -73,7 +75,7 @@ namespace Volo.Abp.VirtualFileSystem.Embedded
public override string ToString()
{
return $"[EmbeddedResourceFileInfo] {Name} ({PhysicalPath})";
return $"[EmbeddedResourceFileInfo] {Name} ({this.VirtualPath})";
}
}
}

@ -72,18 +72,6 @@ namespace Volo.Abp.VirtualFileSystem
);
}
public override IFileInfo GetFileInfo(string subpath)
{
var result = base.GetFileInfo(subpath);
return result;
}
public override IDirectoryContents GetDirectoryContents(string subpath)
{
var result = base.GetDirectoryContents(subpath);
return result;
}
private Dictionary<string, IFileInfo> CreateFiles()
{
var files = new Dictionary<string, IFileInfo>(StringComparer.OrdinalIgnoreCase);

@ -10,6 +10,9 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<PreserveCompilationContext>true</PreserveCompilationContext>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
<PreserveCompilationReferences>true</PreserveCompilationReferences>
<RootNamespace />
</PropertyGroup>

@ -20,7 +20,7 @@ namespace Volo.Abp.AspNetCore
public override void ConfigureServices(ServiceConfigurationContext context)
{
var hostingEnvironment = context.Services.GetHostingEnvironment();
Configure<VirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpAspNetCoreTestModule>();

@ -1,4 +1,5 @@
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
@ -32,6 +33,19 @@ namespace Volo.Abp.VirtualFileSystem
}
}
[Fact]
public void Should_Define_And_Get_Embedded_Directory_Contents()
{
//Act
var contents = _virtualFileProvider.GetDirectoryContents("/js");
//Assert
contents.Exists.ShouldNotBeNull();
var contentList = contents.ToList();
contentList.ShouldContain(x => x.Name == "jquery-3-1-1-min.js");
}
[DependsOn(typeof(AbpVirtualFileSystemModule))]
public class TestModule : AbpModule
{

Loading…
Cancel
Save