Format code.

This commit is contained in:
ngfrolov 2023-01-27 10:11:04 +05:00
parent d5fd53595e
commit 1d618302f8
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
2 changed files with 27 additions and 32 deletions

View File

@ -12,7 +12,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram.Convert
#nullable enable #nullable enable
sealed internal class ConvertToPdf sealed internal class ConvertToPdf
{ {
private static readonly string[] filesExtensions = { ".xlsx", ".xls", ".ods", ".odt", ".doc", ".docx", ".pdf" }; internal static readonly string[] filesExtensions = { ".xlsx", ".xls", ".ods", ".odt", ".doc", ".docx", ".pdf" };
private static void MergeFiles(IEnumerable<string> inputFiles, string outFile) private static void MergeFiles(IEnumerable<string> inputFiles, string outFile)
{ {
@ -50,14 +50,15 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram.Convert
} }
var listFiles = files var listFiles = files
.Distinct() .Distinct()
.Select(f => new { .Select(f => new
{
inputFile = f, inputFile = f,
convertedFile = Path.Combine(convertedFilesDir, "pdf", Path.ChangeExtension(Path.GetFileName(f), ".pdf")) convertedFile = Path.Combine(convertedFilesDir, "pdf", Path.ChangeExtension(Path.GetFileName(f), ".pdf"))
}) })
.ToList(); .ToList();
foreach (var file in listFiles) foreach (var file in listFiles)
{ {
var fileExt = Path.GetExtension(file.inputFile); var fileExt = Path.GetExtension(file.inputFile).ToLower();
if (fileExt != ".pdf") if (fileExt != ".pdf")
{ {
await StartConvertProcessAsync(file.inputFile, Path.GetDirectoryName(file.convertedFile)!, token); await StartConvertProcessAsync(file.inputFile, Path.GetDirectoryName(file.convertedFile)!, token);

View File

@ -51,7 +51,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
private const int idStateReady = 3; private const int idStateReady = 3;
private const int idStateError = 4; private const int idStateError = 4;
private static readonly string[] filePermittedExt = { ".xlsx", ".xls", ".ods", ".odt", ".doc", ".docx", ".pdf" }; private static readonly string[] validFileExtensions = ConvertToPdf.filesExtensions;
public DrillingProgramService( public DrillingProgramService(
IAsbCloudDbContext context, IAsbCloudDbContext context,
@ -163,17 +163,16 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
await EnqueueMakeProgramWorkAsync(idWell, state, token); await EnqueueMakeProgramWorkAsync(idWell, state, token);
return state; return state;
} }
private bool ValidExtFile(string file)
private static bool IsFileExtensionValid(string file)
{ {
var fileExt = Path.GetExtension(file); var fileExt = Path.GetExtension(file).ToLower();
var badExt = Array.Find(filePermittedExt, e => e == fileExt); return validFileExtensions.Contains(fileExt);
if (badExt is null)
return false;
return true;
} }
public async Task<int> AddFile(int idWell, int idFileCategory, int idUser, string fileFullName, System.IO.Stream fileStream, CancellationToken token = default)
public async Task<int> AddFile(int idWell, int idFileCategory, int idUser, string fileFullName, Stream fileStream, CancellationToken token = default)
{ {
if (!ValidExtFile(fileFullName)) if (!IsFileExtensionValid(fileFullName))
throw new FileFormatException($"Файл {fileFullName} - неподдерживаемого формата. Файл не может быть загружен."); throw new FileFormatException($"Файл {fileFullName} - неподдерживаемого формата. Файл не может быть загружен.");
var part = await context.DrillingProgramParts var part = await context.DrillingProgramParts
@ -346,9 +345,6 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
await NotifyPublisherOnFullAccepAsync(fileMarkDto, token); await NotifyPublisherOnFullAccepAsync(fileMarkDto, token);
} }
} }
return result; return result;
} }
@ -477,8 +473,6 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
return part; return part;
} }
private async Task EnqueueMakeProgramWorkAsync(int idWell, DrillingProgramStateDto state, CancellationToken token) private async Task EnqueueMakeProgramWorkAsync(int idWell, DrillingProgramStateDto state, CancellationToken token)
{ {
if (state.IdState == idStateCreating) if (state.IdState == idStateCreating)