Save all files to wwwroot
This commit is contained in:
@ -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<IConfiguration>();
|
||||
|
||||
@ -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<IConfiguration>();
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -33,7 +33,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="wwwroot\" />
|
||||
<Folder Include="wwwroot\incoming\" />
|
||||
<Folder Include="wwwroot\outgoing\" />
|
||||
<Folder Include="wwwroot\parsing\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user