From ee80c1a40bf31077e0a5b0e4f302733104831f61 Mon Sep 17 00:00:00 2001 From: "HOME-LAPTOP\\kshkulev" Date: Thu, 20 Nov 2025 15:44:31 +0900 Subject: [PATCH] Save all files to wwwroot --- .../BackgroundServices/OperationExecutionService.cs | 10 ++++++++-- Hcs.WebApp/BackgroundServices/ResultGetService.cs | 7 +++++-- Hcs.WebApp/Controllers/UploadController.cs | 11 +++++++---- Hcs.WebApp/Hcs.WebApp.csproj | 4 +++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Hcs.WebApp/BackgroundServices/OperationExecutionService.cs b/Hcs.WebApp/BackgroundServices/OperationExecutionService.cs index e5baa22..665c5aa 100644 --- a/Hcs.WebApp/BackgroundServices/OperationExecutionService.cs +++ b/Hcs.WebApp/BackgroundServices/OperationExecutionService.cs @@ -8,13 +8,19 @@ using Hcs.WebApp.Utils; namespace Hcs.WebApp.BackgroundServices { - public class OperationExecutionService(OperationExecutionState state, ExecutorFactory executorFactory, IServiceScopeFactory scopeFactory) : BackgroundService + public class OperationExecutionService( + OperationExecutionState state, + ExecutorFactory executorFactory, + IServiceScopeFactory scopeFactory, + IWebHostEnvironment webHostEnvironment) : BackgroundService { private const int SLEEP_TIME = 30000; + private const string OUTGOING_DIR_NAME = "outgoing"; private readonly OperationExecutionState state = state; private readonly ExecutorFactory executorFactory = executorFactory; private readonly IServiceScopeFactory scopeFactory = scopeFactory; + private readonly IWebHostEnvironment webHostEnvironment = webHostEnvironment; private Broker.Logger.ILogger logger; private IMessageCapturer messageCapturer; @@ -87,7 +93,7 @@ namespace Hcs.WebApp.BackgroundServices private void InitializeClient() { logger = new ActionLogger(); - messageCapturer = new FileMessageCapturer("outgoing", logger); + messageCapturer = new FileMessageCapturer(Path.Combine(webHostEnvironment.WebRootPath, OUTGOING_DIR_NAME), logger); using var scope = scopeFactory.CreateScope(); var configuration = scope.ServiceProvider.GetRequiredService(); diff --git a/Hcs.WebApp/BackgroundServices/ResultGetService.cs b/Hcs.WebApp/BackgroundServices/ResultGetService.cs index de2d83b..5a520e6 100644 --- a/Hcs.WebApp/BackgroundServices/ResultGetService.cs +++ b/Hcs.WebApp/BackgroundServices/ResultGetService.cs @@ -12,7 +12,8 @@ namespace Hcs.WebApp.BackgroundServices public class ResultGetService( ResultGetState state, ResultGetterFactory resultGetterFactory, - IServiceScopeFactory scopeFactory) : BackgroundService + IServiceScopeFactory scopeFactory, + IWebHostEnvironment webHostEnvironment) : BackgroundService { private class GetState { @@ -23,10 +24,12 @@ namespace Hcs.WebApp.BackgroundServices private const int ITERATION_TIME = 10000; private const int SLEEP_TIME = 30000; + private const string INCOMING_DIR_NAME = "incoming"; private readonly ResultGetState state = state; private readonly ResultGetterFactory resultGetterFactory = resultGetterFactory; private readonly IServiceScopeFactory scopeFactory = scopeFactory; + private readonly IWebHostEnvironment webHostEnvironment = webHostEnvironment; private readonly List<(Operation operation, GetState state)> entries = []; private Broker.Logger.ILogger logger; @@ -130,7 +133,7 @@ namespace Hcs.WebApp.BackgroundServices private void InitializeClient() { logger = new ActionLogger(); - messageCapturer = new FileMessageCapturer("incoming", logger); + messageCapturer = new FileMessageCapturer(Path.Combine(webHostEnvironment.WebRootPath, INCOMING_DIR_NAME), logger); using var scope = scopeFactory.CreateScope(); var configuration = scope.ServiceProvider.GetRequiredService(); diff --git a/Hcs.WebApp/Controllers/UploadController.cs b/Hcs.WebApp/Controllers/UploadController.cs index 9cd5629..cd149d8 100644 --- a/Hcs.WebApp/Controllers/UploadController.cs +++ b/Hcs.WebApp/Controllers/UploadController.cs @@ -5,21 +5,24 @@ namespace Hcs.WebApp.Controllers { [Authorize] [DisableRequestSizeLimit] - public class UploadController() : Controller + public class UploadController(IWebHostEnvironment webHostEnvironment) : Controller { + private readonly IWebHostEnvironment webHostEnvironment = webHostEnvironment; + [HttpPost("upload/parsing")] public IActionResult Single(IFormFile file) { try { const string directory = "parsing"; - if (!Directory.Exists(directory)) + var directoryPath = Path.Combine(webHostEnvironment.WebRootPath, directory); + if (!Directory.Exists(directoryPath)) { - Directory.CreateDirectory(directory); + Directory.CreateDirectory(directoryPath); } var fileName = $"{DateTime.Today:dd-MM-yyyy}-{Guid.NewGuid()}{Path.GetExtension(file.FileName)}"; - var path = Path.Combine(directory, fileName); + var path = Path.Combine(directoryPath, fileName); using var stream = new FileStream(path, FileMode.Create); file.CopyTo(stream); diff --git a/Hcs.WebApp/Hcs.WebApp.csproj b/Hcs.WebApp/Hcs.WebApp.csproj index 1e98475..da14e1a 100644 --- a/Hcs.WebApp/Hcs.WebApp.csproj +++ b/Hcs.WebApp/Hcs.WebApp.csproj @@ -33,7 +33,9 @@ - + + +