feat: add DOCX workbench and Word automation
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using DocumentAutomation.Shared;
|
||||
|
||||
namespace DocxWorkbench.Core;
|
||||
|
||||
public interface IDocumentInspector
|
||||
{
|
||||
DocumentInspectionResult Inspect(string docxPath);
|
||||
}
|
||||
|
||||
public interface IWordDocumentService
|
||||
{
|
||||
Task<WordDocumentResult> BuildDocumentAsync(WordDocumentBuildRequest request, IProgress<string>? progress, CancellationToken cancellationToken);
|
||||
Task<WordPreviewResult> ExportPdfAsync(string docxPath, string outputPdfPath, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public static class DocumentInputValidation
|
||||
{
|
||||
public static void Validate(WordDocumentBuildRequest request)
|
||||
{
|
||||
if (!File.Exists(request.TemplatePath)) throw new FileNotFoundException("Шаблон DOCX не найден.", request.TemplatePath);
|
||||
if (!File.Exists(request.BodyPath)) throw new FileNotFoundException("Файл тела документа не найден.", request.BodyPath);
|
||||
if (!request.TemplatePath.EndsWith(".docx", StringComparison.OrdinalIgnoreCase)) throw new ArgumentException("Шаблон должен быть DOCX.");
|
||||
if (Path.GetFullPath(request.TemplatePath).Equals(Path.GetFullPath(request.OutputDocxPath), StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException("Нельзя перезаписывать исходный шаблон.");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(request.OutputDocxPath))!);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user