diff --git a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs index 5083237e..32773c5d 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs +++ b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs @@ -51,6 +51,8 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram private const int idStateReady = 3; private const int idStateError = 4; + private static readonly string[] filePermittedExt = { ".xlsx", ".xls", ".ods", ".odt", ".doc", ".docx", ".pdf" }; + public DrillingProgramService( IAsbCloudDbContext context, FileService fileService, @@ -161,13 +163,23 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram await EnqueueMakeProgramWorkAsync(idWell, state, token); return state; } - + private bool ValidExtFile(string file) + { + var fileExt = Path.GetExtension(file); + var badExt = Array.Find(filePermittedExt, e => e == fileExt); + if (badExt is null) + return false; + return true; + } public async Task AddFile(int idWell, int idFileCategory, int idUser, string fileFullName, System.IO.Stream fileStream, CancellationToken token = default) { + if (!ValidExtFile(fileFullName)) + throw new FileFormatException($"Файл {fileFullName} - неподдерживаемого формата. Файл не может быть загружен. "); + var part = await context.DrillingProgramParts - .Include(p => p.RelatedUsers) - .ThenInclude(r => r.User) - .FirstOrDefaultAsync(p => p.IdWell == idWell && p.IdFileCategory == idFileCategory, token); + .Include(p => p.RelatedUsers) + .ThenInclude(r => r.User) + .FirstOrDefaultAsync(p => p.IdWell == idWell && p.IdFileCategory == idFileCategory, token); if (part == null) throw new ArgumentInvalidException($"DrillingProgramPart id == {idFileCategory} does not exist", nameof(idFileCategory)); @@ -465,6 +477,8 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram return part; } + + private async Task EnqueueMakeProgramWorkAsync(int idWell, DrillingProgramStateDto state, CancellationToken token) { if (state.IdState == idStateCreating)