diff --git a/AsbCloudInfrastructure/Services/DrillingProgram/Convert/ConvertToPdf.cs b/AsbCloudInfrastructure/Services/DrillingProgram/Convert/ConvertToPdf.cs index 807b2afe..41bd29e4 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgram/Convert/ConvertToPdf.cs +++ b/AsbCloudInfrastructure/Services/DrillingProgram/Convert/ConvertToPdf.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using CliWrap; using System.Threading.Tasks; +using System.Threading; namespace AsbCloudInfrastructure.Services.DrillingProgram.Convert { @@ -36,14 +37,14 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram.Convert } } - private async Task StartConvertProcessAsync(string inputFileName, string outFileName) + private async Task StartConvertProcessAsync(string inputFileName, string outFileName, CancellationToken token) { var result = Cli.Wrap("/usr/bin/soffice") - .WithArguments($"--headless --convert-to pdf {inputFileName} --outdir {outFileName}"); - await result.ExecuteAsync(); + .WithArguments($"--headless --convert-to pdf {inputFileName} --outdir {outFileName}"); + await result.ExecuteAsync(token); } - public async Task GetConverteAndMergedFileAsync(IEnumerable filesNames, string resultPath) + public async Task GetConverteAndMergedFileAsync(IEnumerable filesNames, string resultPath, CancellationToken token) { foreach (var file in filesNames) { @@ -52,7 +53,6 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram.Convert { throw new FileFormatException($"Файл с именем: {file} - неподдерживаемого формата. Он не может быть добавлен в список файлов для конвертации и слияния в общий файл программы бурения."); } - } var listFileNames = filesNames @@ -64,8 +64,12 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram.Convert .ToList(); foreach (var fileName in listFileNames) { - if (!fileName.inputFile.ToLower().EndsWith(".pdf")) - await StartConvertProcessAsync(fileName.inputFile, fileName.convertedFile); + var fileExt = Path.GetExtension(fileName.inputFile); + if (fileExt != ".pdf") + { + //FileInfo fileInfo = new FileInfo(fileName.inputFile); + await StartConvertProcessAsync(fileName.inputFile, fileName.convertedFile, token); + } } DoMergedAsync(listFileNames.Select(c => c.convertedFile), resultPath); } diff --git a/AsbCloudInfrastructure/Services/DrillingProgram/Convert/ReadMe.md b/AsbCloudInfrastructure/Services/DrillingProgram/Convert/ReadMe.md index e230682d..ce426589 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgram/Convert/ReadMe.md +++ b/AsbCloudInfrastructure/Services/DrillingProgram/Convert/ReadMe.md @@ -15,5 +15,11 @@ Windows - C:\Program Files\LibreOffice\program\soffice.exe с "ненужным" или "неправильным" форматом просто не будут попадать в список на преобразование. +--список сигнатур файлов разных расширений +1.xlsx +(xlsDoc[0]==0x50) && (xlsDoc[1]==0x4B) +2.docx + + diff --git a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs index 16ee2191..ef1075d8 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs +++ b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs @@ -481,7 +481,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram var context = serviceProvider.GetRequiredService(); var fileService = serviceProvider.GetRequiredService(); var files = state.Parts.Select(p => fileService.GetUrl(p.File)); - await converter.GetConverteAndMergedFileAsync(files, tempResultFilePath); + await converter.GetConverteAndMergedFileAsync(files, tempResultFilePath, token); await fileService.MoveAsync(idWell, null, idFileCategoryDrillingProgram, resultFileName, tempResultFilePath, token); }; diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs index d9ad39b1..1a5fe613 100644 --- a/ConsoleApp1/Program.cs +++ b/ConsoleApp1/Program.cs @@ -28,6 +28,8 @@ namespace ConsoleApp1 .Distinct() .Where(f => fileExtension.Any(fe => f.ToLower().EndsWith(fe))) .ToList(); + FileInfo fileInfo = new FileInfo(resultFile); + matchesExtensions(inputFiles); foreach (var FileName in inputFiles) {