mirror of https://github.com/abpframework/abp.git
12 changed files with 152 additions and 81 deletions
@ -0,0 +1,35 @@ |
|||
using System.IO; |
|||
using System.Reflection; |
|||
using Microsoft.Extensions.FileProviders; |
|||
|
|||
namespace Volo.Abp.VirtualFileSystem |
|||
{ |
|||
public class VirtualFileSetInfo |
|||
{ |
|||
public IFileProvider FileProvider |
|||
{ |
|||
get => _fileProvider; |
|||
set => _fileProvider = Check.NotNull(value, nameof(value)); |
|||
} |
|||
private IFileProvider _fileProvider; |
|||
|
|||
public VirtualFileSetInfo(IFileProvider fileProvider) |
|||
{ |
|||
FileProvider = fileProvider; |
|||
} |
|||
} |
|||
|
|||
public class EmbeddedVirtualFileSetInfo : VirtualFileSetInfo |
|||
{ |
|||
public Assembly Assembly { get; } |
|||
|
|||
public string BaseFolder { get; } |
|||
|
|||
public EmbeddedVirtualFileSetInfo(IFileProvider fileProvider, Assembly assembly, string baseFolder = null) |
|||
: base(fileProvider) |
|||
{ |
|||
Assembly = assembly; |
|||
BaseFolder = baseFolder; |
|||
} |
|||
} |
|||
} |
|||
@ -1,44 +1,76 @@ |
|||
using System; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using JetBrains.Annotations; |
|||
using Microsoft.Extensions.FileProviders; |
|||
using Volo.Abp.VirtualFileSystem.Embedded; |
|||
|
|||
namespace Volo.Abp.VirtualFileSystem |
|||
{ |
|||
public static class VirtualFileSetListExtensions |
|||
{ |
|||
public static void AddEmbedded<T>([NotNull] this VirtualFileSetList list, [CanBeNull] string baseNamespace = null, string baseFolderInProject = null) |
|||
public static void AddEmbedded<T>( |
|||
[NotNull] this VirtualFileSetList list, |
|||
[CanBeNull] string baseNamespace = null, |
|||
[CanBeNull] string baseFolder = null) |
|||
{ |
|||
Check.NotNull(list, nameof(list)); |
|||
|
|||
list.Add( |
|||
new EmbeddedFileSet( |
|||
typeof(T).Assembly, |
|||
baseNamespace, |
|||
baseFolderInProject |
|||
) |
|||
var assembly = typeof(T).Assembly; |
|||
var fileProvider = CreateFileProvider( |
|||
assembly, |
|||
baseNamespace, |
|||
baseFolder |
|||
); |
|||
|
|||
list.Add(new EmbeddedVirtualFileSetInfo(fileProvider, assembly, baseFolder)); |
|||
} |
|||
|
|||
public static void ReplaceEmbeddedByPhysical<T>([NotNull] this VirtualFileSetList list, [NotNull] string pyhsicalPath) |
|||
private static IFileProvider CreateFileProvider( |
|||
[NotNull] Assembly assembly, |
|||
[CanBeNull] string baseNamespace = null, |
|||
[CanBeNull] string baseFolder = null) |
|||
{ |
|||
Check.NotNull(list, nameof(list)); |
|||
Check.NotNull(pyhsicalPath, nameof(pyhsicalPath)); |
|||
Check.NotNull(assembly, nameof(assembly)); |
|||
|
|||
var assembly = typeof(T).Assembly; |
|||
var embeddedFileSets = list.OfType<EmbeddedFileSet>().Where(fs => fs.Assembly == assembly).ToList(); |
|||
var info = assembly.GetManifestResourceInfo("Microsoft.Extensions.FileProviders.Embedded.Manifest.xml"); |
|||
|
|||
foreach (var embeddedFileSet in embeddedFileSets) |
|||
if (info == null) |
|||
{ |
|||
list.Remove(embeddedFileSet); |
|||
return new EmbeddedFileSet(assembly, baseNamespace); |
|||
} |
|||
|
|||
if (baseFolder == null) |
|||
{ |
|||
return new ManifestEmbeddedFileProvider(assembly); |
|||
} |
|||
|
|||
return new ManifestEmbeddedFileProvider(assembly, baseFolder); |
|||
} |
|||
|
|||
public static void ReplaceEmbeddedByPhysical<T>( |
|||
[NotNull] this VirtualFileSetList fileSets, |
|||
[NotNull] string pyhsicalPath) |
|||
{ |
|||
Check.NotNull(fileSets, nameof(fileSets)); |
|||
Check.NotNullOrWhiteSpace(pyhsicalPath, nameof(pyhsicalPath)); |
|||
|
|||
var assembly = typeof(T).Assembly; |
|||
|
|||
if (!embeddedFileSet.BaseFolderInProject.IsNullOrEmpty()) |
|||
for (var i = 0; i < fileSets.Count; i++) |
|||
{ |
|||
if (fileSets[i] is EmbeddedVirtualFileSetInfo embeddedVirtualFileSet && |
|||
embeddedVirtualFileSet.Assembly == assembly) |
|||
{ |
|||
pyhsicalPath = Path.Combine(pyhsicalPath, embeddedFileSet.BaseFolderInProject); |
|||
} |
|||
var thisPath = pyhsicalPath; |
|||
|
|||
list.PhysicalPaths.Add(pyhsicalPath); |
|||
if (!embeddedVirtualFileSet.BaseFolder.IsNullOrEmpty()) |
|||
{ |
|||
thisPath = Path.Combine(thisPath, embeddedVirtualFileSet.BaseFolder); |
|||
} |
|||
|
|||
fileSets[i] = new VirtualFileSetInfo(new PhysicalFileProvider(thisPath)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1 @@ |
|||
//my{test}.2.9.min.js-content
|
|||
@ -0,0 +1 @@ |
|||
testing just... |
|||
Loading…
Reference in new issue