mirror of https://github.com/abpframework/abp.git
Browse Source
Implemented: Support embedded files with manifest created by Microsoft.Extensions.FileProviders.Embeddedpull/4543/head
committed by
GitHub
20 changed files with 195 additions and 98 deletions
@ -0,0 +1,22 @@ |
|||
using System.Reflection; |
|||
using Microsoft.Extensions.FileProviders; |
|||
|
|||
namespace Volo.Abp.VirtualFileSystem.Embedded |
|||
{ |
|||
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,10 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using Microsoft.Extensions.FileProviders; |
|||
|
|||
namespace Volo.Abp.VirtualFileSystem |
|||
{ |
|||
public interface IVirtualFileSet |
|||
{ |
|||
void AddFiles(Dictionary<string, IFileInfo> files); |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using JetBrains.Annotations; |
|||
using Microsoft.Extensions.FileProviders; |
|||
|
|||
namespace Volo.Abp.VirtualFileSystem.Physical |
|||
{ |
|||
public class PhysicalVirtualFileSetInfo : VirtualFileSetInfo |
|||
{ |
|||
public string Root { get; } |
|||
|
|||
public PhysicalVirtualFileSetInfo( |
|||
[NotNull] IFileProvider fileProvider, |
|||
[NotNull] string root |
|||
) |
|||
: base(fileProvider) |
|||
{ |
|||
Root = Check.NotNullOrWhiteSpace(root, nameof(root)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using JetBrains.Annotations; |
|||
using Microsoft.Extensions.FileProviders; |
|||
|
|||
namespace Volo.Abp.VirtualFileSystem |
|||
{ |
|||
public class VirtualFileSetInfo |
|||
{ |
|||
public IFileProvider FileProvider { get; } |
|||
|
|||
public VirtualFileSetInfo([NotNull] IFileProvider fileProvider) |
|||
{ |
|||
FileProvider = Check.NotNull(fileProvider, nameof(fileProvider)); |
|||
} |
|||
} |
|||
} |
|||
@ -1,44 +1,90 @@ |
|||
using System; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using JetBrains.Annotations; |
|||
using Microsoft.Extensions.FileProviders; |
|||
using Microsoft.Extensions.FileProviders.Physical; |
|||
using Volo.Abp.VirtualFileSystem.Embedded; |
|||
using Volo.Abp.VirtualFileSystem.Physical; |
|||
|
|||
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) |
|||
public static void AddPhysical( |
|||
[NotNull] this VirtualFileSetList list, |
|||
[NotNull] string root, |
|||
ExclusionFilters exclusionFilters = ExclusionFilters.Sensitive) |
|||
{ |
|||
Check.NotNull(list, nameof(list)); |
|||
Check.NotNull(pyhsicalPath, nameof(pyhsicalPath)); |
|||
Check.NotNullOrWhiteSpace(root, nameof(root)); |
|||
|
|||
var assembly = typeof(T).Assembly; |
|||
var embeddedFileSets = list.OfType<EmbeddedFileSet>().Where(fs => fs.Assembly == assembly).ToList(); |
|||
var fileProvider = new PhysicalFileProvider(root, exclusionFilters); |
|||
list.Add(new PhysicalVirtualFileSetInfo(fileProvider, root)); |
|||
} |
|||
|
|||
private static IFileProvider CreateFileProvider( |
|||
[NotNull] Assembly assembly, |
|||
[CanBeNull] string baseNamespace = null, |
|||
[CanBeNull] string baseFolder = null) |
|||
{ |
|||
Check.NotNull(assembly, nameof(assembly)); |
|||
|
|||
foreach (var embeddedFileSet in embeddedFileSets) |
|||
var info = assembly.GetManifestResourceInfo("Microsoft.Extensions.FileProviders.Embedded.Manifest.xml"); |
|||
|
|||
if (info == null) |
|||
{ |
|||
list.Remove(embeddedFileSet); |
|||
return new AbpEmbeddedFileProvider(assembly, baseNamespace); |
|||
} |
|||
|
|||
if (baseFolder == null) |
|||
{ |
|||
return new ManifestEmbeddedFileProvider(assembly); |
|||
} |
|||
|
|||
if (!embeddedFileSet.BaseFolderInProject.IsNullOrEmpty()) |
|||
return new ManifestEmbeddedFileProvider(assembly, baseFolder); |
|||
} |
|||
|
|||
public static void ReplaceEmbeddedByPhysical<T>( |
|||
[NotNull] this VirtualFileSetList fileSets, |
|||
[NotNull] string physicalPath) |
|||
{ |
|||
Check.NotNull(fileSets, nameof(fileSets)); |
|||
Check.NotNullOrWhiteSpace(physicalPath, nameof(physicalPath)); |
|||
|
|||
var assembly = typeof(T).Assembly; |
|||
|
|||
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 = physicalPath; |
|||
|
|||
list.PhysicalPaths.Add(pyhsicalPath); |
|||
if (!embeddedVirtualFileSet.BaseFolder.IsNullOrEmpty()) |
|||
{ |
|||
thisPath = Path.Combine(thisPath, embeddedVirtualFileSet.BaseFolder); |
|||
} |
|||
|
|||
fileSets[i] = new PhysicalVirtualFileSetInfo(new PhysicalFileProvider(thisPath), thisPath); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1 @@ |
|||
//my{test}.2.9.min.js-content
|
|||
@ -1,6 +1,6 @@ |
|||
{ |
|||
"culture": "tr", |
|||
"texts": { |
|||
"ManageYourProfile": "Profil yönetimi" |
|||
"ManageYourProfile": "Profil yönetimi" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue