|
|
|
@ -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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|