Simplify EmbeddedFileSet.

pull/179/head
Halil İbrahim Kalkan 7 years ago
parent ab34dc7dca
commit c667f9372e

@ -28,7 +28,6 @@ namespace AbpDesk.Blogging
{
options.FileSets.Add(
new EmbeddedFileSet(
"/",
GetType().Assembly,
"" //TODO: This is not tested yet!
)

@ -21,7 +21,6 @@ namespace Volo.Abp.Account.Web
{
options.FileSets.Add(
new EmbeddedFileSet(
"/",
GetType().Assembly,
"Volo.Abp.Account.Web"
)

@ -19,7 +19,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
{
options.FileSets.Add(
new EmbeddedFileSet(
"/",
GetType().Assembly,
"Volo.Abp.AspNetCore.Mvc.UI.Bootstrap"
)

@ -19,7 +19,6 @@ namespace Volo.Abp.AspNetCore.Mvc
{
options.FileSets.Add(
new EmbeddedFileSet(
"/",
GetType().Assembly,
"Volo.Abp.AspNetCore.Mvc"
)

@ -27,7 +27,6 @@ namespace Volo.Abp.Identity.Web
{
options.FileSets.Add(
new EmbeddedFileSet(
"/",
GetType().Assembly,
"Volo.Abp.Identity.Web"
)

@ -3,23 +3,25 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.Extensions.FileProviders;
namespace Volo.Abp.VirtualFileSystem.Embedded
{
public class EmbeddedFileSet : IVirtualFileSet
{
public string RootPath { get; }
[NotNull]
public Assembly Assembly { get; }
public string ResourceNamespace { get; }
[CanBeNull]
public string BaseNamespace { get; }
public EmbeddedFileSet(string rootPath, Assembly assembly, string resourceNamespace)
public EmbeddedFileSet([NotNull] Assembly assembly, string baseNamespace)
{
RootPath = rootPath.EnsureEndsWith('/');
Check.NotNull(assembly, nameof(assembly));
Assembly = assembly;
ResourceNamespace = resourceNamespace;
BaseNamespace = baseNamespace;
}
public void AddFiles(Dictionary<string, IFileInfo> files)
@ -28,12 +30,12 @@ namespace Volo.Abp.VirtualFileSystem.Embedded
foreach (var resourcePath in Assembly.GetManifestResourceNames())
{
if (!resourcePath.StartsWith(ResourceNamespace))
if (!BaseNamespace.IsNullOrEmpty() && !resourcePath.StartsWith(BaseNamespace))
{
continue;
}
var fullPath = RootPath + ConvertToRelativePath(resourcePath);
var fullPath = ConvertToRelativePath(resourcePath).EnsureStartsWith('/');
if (fullPath.Contains("/"))
{
@ -92,7 +94,10 @@ namespace Volo.Abp.VirtualFileSystem.Embedded
private string ConvertToRelativePath(string resourceName)
{
resourceName = resourceName.Substring(ResourceNamespace.Length + 1);
if (!BaseNamespace.IsNullOrEmpty())
{
resourceName = resourceName.Substring(BaseNamespace.Length + 1);
}
var pathParts = resourceName.Split('.');
if (pathParts.Length <= 2)

@ -23,7 +23,7 @@ namespace Volo.Abp.VirtualFileSystem
public void Should_Define_And_Get_Embedded_Resources()
{
//Act
var resource = _embeddedFileManager.GetFileInfo("/MyApp/MyResources/js/jquery-3.1.1.min.js");
var resource = _embeddedFileManager.GetFileInfo("/js/jquery-3.1.1.min.js");
//Assert
resource.ShouldNotBeNull();
@ -44,7 +44,6 @@ namespace Volo.Abp.VirtualFileSystem
{
options.FileSets.Add(
new EmbeddedFileSet(
"/MyApp/MyResources/",
GetType().Assembly,
"Volo.Abp.VirtualFileSystem.MyResources"
)

Loading…
Cancel
Save