Browse Source

LocalizedTemplateContentReaderFactory: Make CreateAsync method virtual and private fields protected to easier extend.

pull/3935/head
Halil İbrahim Kalkan 6 years ago
parent
commit
eb59629d21
  1. 20
      framework/src/Volo.Abp.TextTemplating/Volo/Abp/TextTemplating/VirtualFiles/LocalizedTemplateContentReaderFactory.cs

20
framework/src/Volo.Abp.TextTemplating/Volo/Abp/TextTemplating/VirtualFiles/LocalizedTemplateContentReaderFactory.cs

@ -9,33 +9,33 @@ namespace Volo.Abp.TextTemplating.VirtualFiles
{ {
public class LocalizedTemplateContentReaderFactory : ILocalizedTemplateContentReaderFactory, ISingletonDependency public class LocalizedTemplateContentReaderFactory : ILocalizedTemplateContentReaderFactory, ISingletonDependency
{ {
private readonly IVirtualFileProvider _virtualFileProvider; protected IVirtualFileProvider VirtualFileProvider { get; }
private readonly ConcurrentDictionary<string, ILocalizedTemplateContentReader> _readerCache; protected ConcurrentDictionary<string, ILocalizedTemplateContentReader> ReaderCache { get; }
protected SemaphoreSlim SyncObj; protected SemaphoreSlim SyncObj;
public LocalizedTemplateContentReaderFactory(IVirtualFileProvider virtualFileProvider) public LocalizedTemplateContentReaderFactory(IVirtualFileProvider virtualFileProvider)
{ {
_virtualFileProvider = virtualFileProvider; VirtualFileProvider = virtualFileProvider;
_readerCache = new ConcurrentDictionary<string, ILocalizedTemplateContentReader>(); ReaderCache = new ConcurrentDictionary<string, ILocalizedTemplateContentReader>();
SyncObj = new SemaphoreSlim(1, 1); SyncObj = new SemaphoreSlim(1, 1);
} }
public async Task<ILocalizedTemplateContentReader> CreateAsync(TemplateDefinition templateDefinition) public virtual async Task<ILocalizedTemplateContentReader> CreateAsync(TemplateDefinition templateDefinition)
{ {
if (_readerCache.TryGetValue(templateDefinition.Name, out var reader)) if (ReaderCache.TryGetValue(templateDefinition.Name, out var reader))
{ {
return reader; return reader;
} }
using (await SyncObj.LockAsync()) using (await SyncObj.LockAsync())
{ {
if (_readerCache.TryGetValue(templateDefinition.Name, out reader)) if (ReaderCache.TryGetValue(templateDefinition.Name, out reader))
{ {
return reader; return reader;
} }
reader = await CreateInternalAsync(templateDefinition); reader = await CreateInternalAsync(templateDefinition);
_readerCache[templateDefinition.Name] = reader; ReaderCache[templateDefinition.Name] = reader;
return reader; return reader;
} }
} }
@ -49,7 +49,7 @@ namespace Volo.Abp.TextTemplating.VirtualFiles
return NullLocalizedTemplateContentReader.Instance; return NullLocalizedTemplateContentReader.Instance;
} }
var fileInfo = _virtualFileProvider.GetFileInfo(virtualPath); var fileInfo = VirtualFileProvider.GetFileInfo(virtualPath);
if (!fileInfo.Exists) if (!fileInfo.Exists)
{ {
throw new AbpException("Could not find a file/folder at the location: " + virtualPath); throw new AbpException("Could not find a file/folder at the location: " + virtualPath);
@ -58,7 +58,7 @@ namespace Volo.Abp.TextTemplating.VirtualFiles
if (fileInfo.IsDirectory) if (fileInfo.IsDirectory)
{ {
var folderReader = new VirtualFolderLocalizedTemplateContentReader(); var folderReader = new VirtualFolderLocalizedTemplateContentReader();
await folderReader.ReadContentsAsync(_virtualFileProvider, virtualPath); await folderReader.ReadContentsAsync(VirtualFileProvider, virtualPath);
return folderReader; return folderReader;
} }
else //File else //File

Loading…
Cancel
Save