mirror of https://github.com/abpframework/abp.git
5 changed files with 116 additions and 28 deletions
@ -0,0 +1,31 @@ |
|||
using System.Collections.Concurrent; |
|||
using System.Collections.Generic; |
|||
using Microsoft.Extensions.FileProviders; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.VirtualFileSystem |
|||
{ |
|||
//TODO: Implement Watch!
|
|||
//TODO: Work with dictionaries?
|
|||
public class DynamicFileProvider : DictionaryBasedFileProvider, IDynamicFileProvider, ISingletonDependency |
|||
{ |
|||
protected override IDictionary<string, IFileInfo> Files => DynamicFiles; |
|||
|
|||
protected ConcurrentDictionary<string, IFileInfo> DynamicFiles { get; } |
|||
|
|||
public DynamicFileProvider() |
|||
{ |
|||
DynamicFiles = new ConcurrentDictionary<string, IFileInfo>(); |
|||
} |
|||
|
|||
public void AddOrUpdate(IFileInfo fileInfo) |
|||
{ |
|||
DynamicFiles.AddOrUpdate(fileInfo.PhysicalPath, fileInfo, (key, value) => fileInfo); |
|||
} |
|||
|
|||
public bool Delete(string filePath) |
|||
{ |
|||
return DynamicFiles.TryRemove(filePath, out _); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.IO; |
|||
using Microsoft.Extensions.FileProviders; |
|||
|
|||
namespace Volo.Abp.VirtualFileSystem |
|||
{ |
|||
public class InMemoryFileInfo : IFileInfo |
|||
{ |
|||
public bool Exists => true; |
|||
|
|||
public long Length => _fileContent.Length; |
|||
|
|||
public string PhysicalPath { get; } |
|||
|
|||
public string Name { get; } |
|||
|
|||
public DateTimeOffset LastModified { get; } |
|||
|
|||
public bool IsDirectory => false; |
|||
|
|||
private readonly byte[] _fileContent; |
|||
|
|||
public InMemoryFileInfo(byte[] fileContent, string physicalPath, string name) |
|||
{ |
|||
PhysicalPath = physicalPath; |
|||
Name = name; |
|||
_fileContent = fileContent; |
|||
LastModified = DateTimeOffset.Now; |
|||
} |
|||
|
|||
public Stream CreateReadStream() |
|||
{ |
|||
return new MemoryStream(_fileContent, false); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue