mirror of https://github.com/abpframework/abp.git
14 changed files with 301 additions and 1 deletions
@ -0,0 +1,33 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0;net9.0</TargetFrameworks> |
|||
<AssemblyName>Volo.Docs.Common.Application.Contracts</AssemblyName> |
|||
<PackageId>Volo.Docs.Common.Application.Contracts</PackageId> |
|||
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<EmbeddedResource Include="Volo\Docs\Common\Localization\Resources\Docs\ApplicationContracts\*.json" /> |
|||
<Content Remove="Volo\Docs\Common\Localization\Resources\Docs\ApplicationContracts\*.json" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Docs.Domain.Shared\Volo.Docs.Domain.Shared.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Application.Contracts\Volo.Abp.Ddd.Application.Contracts.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Authorization.Abstractions\Volo.Abp.Authorization.Abstractions.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<Folder Include="Volo\Docs\Common\Localization\Resources\Docs\" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,31 @@ |
|||
using Volo.Abp.Application; |
|||
using Volo.Abp.Authorization; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.VirtualFileSystem; |
|||
using Volo.Docs.Localization; |
|||
|
|||
namespace Volo.Docs.Common; |
|||
|
|||
[DependsOn( |
|||
typeof(DocsDomainSharedModule), |
|||
typeof(AbpDddApplicationContractsModule), |
|||
typeof(AbpAuthorizationAbstractionsModule) |
|||
)] |
|||
public class DocsCommonApplicationContractsModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpVirtualFileSystemOptions>(options => |
|||
{ |
|||
options.FileSets.AddEmbedded<DocsCommonApplicationContractsModule>(); |
|||
}); |
|||
|
|||
Configure<AbpLocalizationOptions>(options => |
|||
{ |
|||
options.Resources |
|||
.Get<DocsResource>() |
|||
.AddVirtualJson("Volo/Docs/Admin/Localization/Resources/Docs/ApplicationContracts"); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Docs.Localization; |
|||
|
|||
namespace Volo.Docs.Common |
|||
{ |
|||
public class DocsCommonPermissionDefinitionProvider : PermissionDefinitionProvider |
|||
{ |
|||
public override void Define(IPermissionDefinitionContext context) |
|||
{ |
|||
var group = context.AddGroup(DocsCommonPermissions.GroupName, L("Permission:DocumentManagement.Common")); |
|||
|
|||
group.AddPermission(DocsCommonPermissions.Documents.PdfCreation, L("Permission:PdfCreation")); |
|||
} |
|||
|
|||
private static LocalizableString L(string name) |
|||
{ |
|||
return LocalizableString.Create<DocsResource>(name); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using Volo.Abp.Reflection; |
|||
|
|||
namespace Volo.Docs.Common |
|||
{ |
|||
public class DocsCommonPermissions |
|||
{ |
|||
public const string GroupName = "Docs.Common"; |
|||
|
|||
public static class Documents |
|||
{ |
|||
public const string PdfCreation = GroupName + ".PdfCreation"; |
|||
} |
|||
|
|||
public static string[] GetAll() |
|||
{ |
|||
return ReflectionHelper.GetPublicConstantsRecursively(typeof(DocsCommonPermissions)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace Volo.Docs.Common |
|||
{ |
|||
public static class DocsCommonRemoteServiceConsts |
|||
{ |
|||
public const string RemoteServiceName = "AbpDocsCommon"; |
|||
|
|||
public const string ModuleName = "docs-common"; |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Docs.Common.Documents; |
|||
|
|||
public class DocumentPdfGeneratorInput |
|||
{ |
|||
public Guid ProjectId { get; set; } |
|||
|
|||
public string Version { get; set; } |
|||
|
|||
public string LanguageCode { get; set; } |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Content; |
|||
|
|||
namespace Volo.Docs.Common.Documents; |
|||
|
|||
public interface IDocumentPdfGeneratorAppService : IApplicationService |
|||
{ |
|||
Task<IRemoteStreamContent> GeneratePdfAsync(DocumentPdfGeneratorInput input); |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net9.0</TargetFramework> |
|||
<AssemblyName>Volo.Docs.Common.Application</AssemblyName> |
|||
<PackageId>Volo.Docs.Common.Application</PackageId> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Docs.Common.Application.Contracts\Volo.Docs.Common.Application.Contracts.csproj" /> |
|||
<ProjectReference Include="..\Volo.Docs.Domain\Volo.Docs.Domain.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Caching\Volo.Abp.Caching.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Application\Volo.Abp.Ddd.Application.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BlobStoring\Volo.Abp.BlobStoring.csproj" /> |
|||
<PackageReference Include="Markdig.Signed" /> |
|||
<PackageReference Include="Scriban" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -0,0 +1,25 @@ |
|||
using Volo.Abp.Application; |
|||
using Volo.Abp.Authorization; |
|||
using Volo.Abp.AutoMapper; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.VirtualFileSystem; |
|||
using Volo.Docs.Localization; |
|||
|
|||
namespace Volo.Docs.Common; |
|||
|
|||
[DependsOn( |
|||
typeof(DocsDomainModule), |
|||
typeof(DocsCommonApplicationContractsModule), |
|||
typeof(AbpCachingModule), |
|||
typeof(AbpAutoMapperModule), |
|||
typeof(AbpDddApplicationModule) |
|||
)] |
|||
public class DocsCommonApplicationModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Volo.Abp.BlobStoring; |
|||
|
|||
namespace Volo.Docs.Common; |
|||
|
|||
[BlobContainerName("docs-document-pdf")] |
|||
public class DocsDocumentPdfContainer |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,88 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.BlobStoring; |
|||
using Volo.Abp.Content; |
|||
using Volo.Docs.Documents; |
|||
using Volo.Docs.Projects; |
|||
using Volo.Extensions; |
|||
|
|||
namespace Volo.Docs.Common.Documents; |
|||
|
|||
public class DocumentPdfGeneratorAppService : ApplicationService, IDocumentPdfGeneratorAppService |
|||
{ |
|||
protected IBlobContainer<DocsDocumentPdfContainer> BlobContainer { get; } |
|||
protected IProjectRepository ProjectRepository { get; } |
|||
protected IDocumentSourceFactory DocumentStoreFactory { get; } |
|||
protected IDocumentRepository DocumentRepository { get; } |
|||
|
|||
public DocumentPdfGeneratorAppService( |
|||
IBlobContainer<DocsDocumentPdfContainer> blobContainer, |
|||
IProjectRepository projectRepository, |
|||
IDocumentSourceFactory documentStoreFactory, |
|||
IDocumentRepository documentRepository) |
|||
{ |
|||
BlobContainer = blobContainer; |
|||
ProjectRepository = projectRepository; |
|||
DocumentStoreFactory = documentStoreFactory; |
|||
DocumentRepository = documentRepository; |
|||
} |
|||
|
|||
public virtual async Task<IRemoteStreamContent> GeneratePdfAsync(DocumentPdfGeneratorInput input) |
|||
{ |
|||
var project = await ProjectRepository.GetAsync(input.ProjectId); |
|||
var fileName = CalculateDocumentPdfFileName(project.Name, input.Version, input.LanguageCode); |
|||
var stream = await BlobContainer.GetOrNullAsync(fileName); |
|||
|
|||
if(stream != null) |
|||
{ |
|||
return new RemoteStreamContent(stream, fileName , "application/pdf"); |
|||
} |
|||
|
|||
var documentStore = DocumentStoreFactory.Create(project.DocumentStoreType); |
|||
var navigation = await GetNavigationAsync(documentStore, project, input.LanguageCode, input.Version); |
|||
|
|||
|
|||
} |
|||
|
|||
protected virtual string CalculateDocumentPdfFileName(string projectName, string version, string languageCode) |
|||
{ |
|||
return $"{projectName.ToLower()}-{version.ToLower()}--{languageCode.ToLower()}"; |
|||
} |
|||
|
|||
private async Task<NavigationNode> GetNavigationAsync( |
|||
IDocumentSource documentStore, |
|||
Project project, |
|||
string languageCode, |
|||
string version) |
|||
{ |
|||
var navigationDocument = await GetDocumentAsync(documentStore, project, project.NavigationDocumentName, languageCode, version); |
|||
|
|||
if (!DocsJsonSerializerHelper.TryDeserialize<NavigationNode>(navigationDocument.Content, out var navigation)) |
|||
{ |
|||
throw new UserFriendlyException($"Cannot validate navigation file '{project.NavigationDocumentName}' for the project {project.Name}."); |
|||
} |
|||
|
|||
return navigation; |
|||
} |
|||
|
|||
private async Task<Document> GetDocumentAsync( |
|||
IDocumentSource documentStore, |
|||
Project project, |
|||
string documentName, |
|||
string languageCode, |
|||
string version) |
|||
{ |
|||
version = string.IsNullOrWhiteSpace(version) ? project.LatestVersionBranchName : version; |
|||
var document = await DocumentRepository.FindAsync(project.Id, documentName, version, languageCode); |
|||
|
|||
if (document != null) |
|||
{ |
|||
return document; |
|||
} |
|||
|
|||
document = await documentStore.GetDocumentAsync(project, documentName, languageCode, version); |
|||
|
|||
return document; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue