|
|
@ -1,10 +1,5 @@ |
|
|
using System; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Linq; |
|
|
|
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Microsoft.Extensions.Caching.Distributed; |
|
|
|
|
|
using Volo.Abp.Application.Services; |
|
|
using Volo.Abp.Application.Services; |
|
|
using Volo.Abp.Caching; |
|
|
|
|
|
using Volo.Docs.Projects; |
|
|
using Volo.Docs.Projects; |
|
|
|
|
|
|
|
|
namespace Volo.Docs.Documents |
|
|
namespace Volo.Docs.Documents |
|
|
@ -12,59 +7,43 @@ namespace Volo.Docs.Documents |
|
|
public class DocumentAppService : ApplicationService, IDocumentAppService |
|
|
public class DocumentAppService : ApplicationService, IDocumentAppService |
|
|
{ |
|
|
{ |
|
|
private readonly IProjectRepository _projectRepository; |
|
|
private readonly IProjectRepository _projectRepository; |
|
|
private readonly IDistributedCache<List<VersionInfoDto>> _distributedCache; |
|
|
|
|
|
private readonly IDocumentStoreFactory _documentStoreFactory; |
|
|
private readonly IDocumentStoreFactory _documentStoreFactory; |
|
|
|
|
|
|
|
|
public DocumentAppService( |
|
|
public DocumentAppService( |
|
|
IProjectRepository projectRepository, |
|
|
IProjectRepository projectRepository, |
|
|
IDistributedCache<List<VersionInfoDto>> distributedCache, |
|
|
|
|
|
IDocumentStoreFactory documentStoreFactory) |
|
|
IDocumentStoreFactory documentStoreFactory) |
|
|
{ |
|
|
{ |
|
|
_projectRepository = projectRepository; |
|
|
_projectRepository = projectRepository; |
|
|
_distributedCache = distributedCache; |
|
|
|
|
|
_documentStoreFactory = documentStoreFactory; |
|
|
_documentStoreFactory = documentStoreFactory; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async Task<DocumentWithDetailsDto> GetByNameAsync( |
|
|
public async Task<DocumentWithDetailsDto> GetAsync(GetDocumentInput input) |
|
|
string projectShortName, |
|
|
|
|
|
string documentName, |
|
|
|
|
|
string version, |
|
|
|
|
|
bool normalize) |
|
|
|
|
|
{ |
|
|
{ |
|
|
var project = await _projectRepository.GetByShortNameAsync(projectShortName); |
|
|
var project = await _projectRepository.GetAsync(input.ProjectId); |
|
|
return await GetDocumentWithDetailsDto( |
|
|
return await GetDocumentWithDetailsDto( |
|
|
project, |
|
|
project, |
|
|
documentName, |
|
|
input.Name, |
|
|
version, |
|
|
input.Version |
|
|
normalize |
|
|
|
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async Task<DocumentWithDetailsDto> GetDefaultAsync( |
|
|
public async Task<DocumentWithDetailsDto> GetDefaultAsync(GetDefaultDocumentInput input) |
|
|
string projectShortName, |
|
|
|
|
|
string version, |
|
|
|
|
|
bool normalize) |
|
|
|
|
|
{ |
|
|
{ |
|
|
var project = await _projectRepository.GetByShortNameAsync(projectShortName); |
|
|
var project = await _projectRepository.GetAsync(input.ProjectId); |
|
|
return await GetDocumentWithDetailsDto( |
|
|
return await GetDocumentWithDetailsDto( |
|
|
project, |
|
|
project, |
|
|
project.DefaultDocumentName, |
|
|
project.DefaultDocumentName, |
|
|
version, |
|
|
input.Version |
|
|
normalize |
|
|
|
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public virtual async Task<NavigationWithDetailsDto> GetNavigationDocumentAsync( |
|
|
public virtual async Task<NavigationWithDetailsDto> GetNavigationDocumentAsync(GetNavigationDocumentInput input) |
|
|
string projectShortName, |
|
|
|
|
|
string version, |
|
|
|
|
|
bool normalize) |
|
|
|
|
|
{ |
|
|
{ |
|
|
var project = await _projectRepository.GetByShortNameAsync(projectShortName); |
|
|
var project = await _projectRepository.GetAsync(input.ProjectId); |
|
|
var documentDto = await GetDocumentWithDetailsDto( |
|
|
var documentDto = await GetDocumentWithDetailsDto( |
|
|
project, |
|
|
project, |
|
|
project.NavigationDocumentName, |
|
|
project.NavigationDocumentName, |
|
|
version, |
|
|
input.Version |
|
|
normalize |
|
|
|
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
return ObjectMapper.Map<DocumentWithDetailsDto, NavigationWithDetailsDto>(documentDto); |
|
|
return ObjectMapper.Map<DocumentWithDetailsDto, NavigationWithDetailsDto>(documentDto); |
|
|
@ -73,8 +52,7 @@ namespace Volo.Docs.Documents |
|
|
protected virtual async Task<DocumentWithDetailsDto> GetDocumentWithDetailsDto( |
|
|
protected virtual async Task<DocumentWithDetailsDto> GetDocumentWithDetailsDto( |
|
|
Project project, |
|
|
Project project, |
|
|
string documentName, |
|
|
string documentName, |
|
|
string version, |
|
|
string version) |
|
|
bool normalize) |
|
|
|
|
|
{ |
|
|
{ |
|
|
var documentStore = _documentStoreFactory.Create(project.DocumentStoreType); |
|
|
var documentStore = _documentStoreFactory.Create(project.DocumentStoreType); |
|
|
var document = await documentStore.Find(project, documentName, version); |
|
|
var document = await documentStore.Find(project, documentName, version); |
|
|
@ -84,54 +62,5 @@ namespace Volo.Docs.Documents |
|
|
|
|
|
|
|
|
return dto; |
|
|
return dto; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async Task<List<VersionInfoDto>> GetVersions(string projectShortName) |
|
|
|
|
|
{ |
|
|
|
|
|
//TODO: What if there is no version?
|
|
|
|
|
|
|
|
|
|
|
|
var project = await _projectRepository.GetByShortNameAsync(projectShortName); |
|
|
|
|
|
var documentStore = _documentStoreFactory.Create(project.DocumentStoreType); |
|
|
|
|
|
|
|
|
|
|
|
//TODO: Why not use GetOrAddAsync
|
|
|
|
|
|
var versions = await GetVersionsFromCache(projectShortName); |
|
|
|
|
|
if (versions == null) |
|
|
|
|
|
{ |
|
|
|
|
|
versions = await documentStore.GetVersions(project); |
|
|
|
|
|
await SetVersionsToCache(projectShortName, versions); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!project.MinimumVersion.IsNullOrEmpty()) |
|
|
|
|
|
{ |
|
|
|
|
|
var minVersionIndex = versions.FindIndex(v => v.Name == project.MinimumVersion); |
|
|
|
|
|
if (minVersionIndex > -1) |
|
|
|
|
|
{ |
|
|
|
|
|
versions = versions.GetRange(0, minVersionIndex + 1); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(project.LatestVersionBranchName)) |
|
|
|
|
|
{ |
|
|
|
|
|
versions.First().Name = project.LatestVersionBranchName; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return versions; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<VersionInfoDto>> GetVersionsFromCache(string projectShortName) |
|
|
|
|
|
{ |
|
|
|
|
|
return await _distributedCache.GetAsync(projectShortName); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task SetVersionsToCache(string projectShortName, List<VersionInfoDto> versions) |
|
|
|
|
|
{ |
|
|
|
|
|
await _distributedCache.SetAsync( |
|
|
|
|
|
projectShortName, |
|
|
|
|
|
versions, |
|
|
|
|
|
new DistributedCacheEntryOptions |
|
|
|
|
|
{ |
|
|
|
|
|
SlidingExpiration = TimeSpan.FromDays(1) |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |