feat: Перенесены внешние сервисы в Infrastructure. Удалены лишние проекты.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PARR.BLL;
|
||||
using PARR.Core;
|
||||
using PARR.DAL;
|
||||
using PARR.EsppSync;
|
||||
using PARR.EsppTemplateSync.Domain;
|
||||
using PARR.EsppTemplateSync.Settings;
|
||||
using PARR.Infrastructure;
|
||||
|
||||
namespace PARR.EsppTemplateSync
|
||||
{
|
||||
@@ -13,8 +14,9 @@ namespace PARR.EsppTemplateSync
|
||||
public static void InstallEsppTemplateSyncServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.InstallDalServices(configuration);
|
||||
services.InstallBllServices(configuration);
|
||||
services.InstallEsppSyncServices<EsppObjectTemplate>(configuration);
|
||||
services.AddCoreServices(configuration);
|
||||
services.AddInfrastructureServices(configuration);
|
||||
|
||||
var globalSettings = new GlobalSettings();
|
||||
configuration.GetSection(nameof(GlobalSettings)).Bind(globalSettings);
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
|
||||
<ProjectReference Include="..\PARR.Core\PARR.Core.csproj" />
|
||||
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
|
||||
<ProjectReference Include="..\PARR.EsppSync\PARR.EsppSync.csproj" />
|
||||
<ProjectReference Include="..\PARR.Infrastructure\PARR.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using PARR.EsppTemplateSync.Settings;
|
||||
|
||||
namespace PARR.EsppTemplateSync
|
||||
{
|
||||
internal class TemplateFileSyncer : ITemplateSyncer
|
||||
{
|
||||
private readonly ILogger<TemplateFileSyncer> logger;
|
||||
//private readonly IFileService fileService;
|
||||
private readonly GlobalSettings globalSettings;
|
||||
//private readonly IManager manager;
|
||||
private readonly string dirPath;
|
||||
private readonly string filterExtensions;
|
||||
|
||||
//private FileSystemWatcher? watcher;
|
||||
|
||||
public TemplateFileSyncer(
|
||||
BLL.Settings.StorageSettings storageSettings,
|
||||
ILogger<TemplateFileSyncer> logger,
|
||||
//IFileService fileService,
|
||||
GlobalSettings globalSettings//,
|
||||
// IManager manager
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
//this.fileService = fileService;
|
||||
this.globalSettings = globalSettings;
|
||||
//this.manager = manager;
|
||||
if (storageSettings.EsppTemplates == null)
|
||||
{
|
||||
logger.LogError("Нет секции настроек хранилища. StorageSettings, EsppTemplates");
|
||||
throw new Exception("Нет секции настроек хранилища. StorageSettings, EsppTemplates");
|
||||
}
|
||||
|
||||
string dirPath = Path.Combine(storageSettings.EsppTemplates.TemplatePath);
|
||||
this.dirPath = Path.Combine(storageSettings.StoragePath, dirPath);
|
||||
|
||||
filterExtensions = string.Join(",", storageSettings.EsppTemplates!.AllowedExtensions).Replace(".", "*.");
|
||||
}
|
||||
|
||||
public void StartAsync()
|
||||
{
|
||||
//смотрим, доступна ли папка
|
||||
if (!Directory.Exists(dirPath))
|
||||
{
|
||||
logger.LogError($"Не найдена папка: {dirPath}.");
|
||||
throw new Exception($"Не найдена папка: {dirPath}.");
|
||||
}
|
||||
|
||||
logger.LogInformation($"Запущена проверка директории. Интервал: {globalSettings.StorageSettings!.CheckIntervalSeconds} секунд. Фильтр: {filterExtensions}");
|
||||
|
||||
while (true)
|
||||
{
|
||||
//todo: new Task() ->
|
||||
//await GetFilesAsync();
|
||||
//await Task.Delay(globalSettings.StorageSettings!.CheckIntervalSeconds * 1000);
|
||||
}
|
||||
|
||||
|
||||
// сначала обрабатываем существующие файлы, до тех пор пока все не обработаем
|
||||
// после обработки всех файлов, запускаем вотчер
|
||||
//await GetFilesAsync();
|
||||
|
||||
// код ниже, это то что надо использовать, но в доккере не работает watcher
|
||||
////--- watcher
|
||||
//watcher = new FileSystemWatcher(dirPath);
|
||||
//watcher.NotifyFilter = NotifyFilters.FileName;
|
||||
////watcher.Changed += OnChanged;
|
||||
////todo: тут await???
|
||||
//watcher.Created += OnChanged;
|
||||
|
||||
//watcher.Filter = filterExtensions;
|
||||
//watcher.EnableRaisingEvents = true;
|
||||
//watcher.IncludeSubdirectories = false;
|
||||
|
||||
////=== watcher
|
||||
|
||||
//logger.LogInformation($"--- --- --- FileWatcher запущен --- --- ---");
|
||||
}
|
||||
|
||||
|
||||
public void StopAsync()
|
||||
{
|
||||
//watcher?.Dispose();
|
||||
logger.LogInformation($"=== === === FileWatcher остановлен === === ===");
|
||||
}
|
||||
|
||||
//private async void OnChanged(object sender, FileSystemEventArgs e)
|
||||
//{
|
||||
// var path = e.FullPath;
|
||||
// await ParseFileAsync(path);
|
||||
//}
|
||||
|
||||
private async Task GetFilesAsync()
|
||||
{
|
||||
// обрабатываем существующие файлы
|
||||
var files = Directory.GetFiles(this.dirPath, filterExtensions);
|
||||
|
||||
//logger.LogInformation($"Запуск первоначальной загрузки файлов после старта сервиса. (До старта вотчера). Найдено файлов: {files.Length} шт.");
|
||||
logger.LogInformation($"Найдено файлов: {files.Length} шт.");
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (File.Exists(file))
|
||||
await ParseFileAsync(file);
|
||||
else
|
||||
logger.LogInformation($"Файл не найден: {file}");
|
||||
}
|
||||
|
||||
|
||||
//если были файлы, запустим еще раз ручную обработку, вдруг за это время еще загрузили, а вотчер еще не был запущен
|
||||
//запускаем до тех пор, пока не останется необработанных файлов
|
||||
//if (files.Any())
|
||||
// await GetFilesAsync();
|
||||
}
|
||||
|
||||
|
||||
private async Task ParseFileAsync(string path)
|
||||
{
|
||||
logger.LogInformation($"--- --- Найден файл. Готов для парсинга {path} --- ---");
|
||||
//var parseResult = await manager.ManageFileAsync(path);//parserService.ParseFileAsync(path);
|
||||
|
||||
//if (parseResult)
|
||||
//{
|
||||
// logger.LogInformation($"Парсинг успешно завершен. Удаляю файл {path}");
|
||||
// var removeResult = fileService.DeleteFile(path);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// logger.LogError($"Парсинг завершен c ошибкой. Файл не удален {path}");
|
||||
//}
|
||||
}
|
||||
|
||||
Task ITemplateSyncer.StartAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Task ITemplateSyncer.StopAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.Core.Common.RabbitServices;
|
||||
using PARR.Core.Common.Interfaces.RabbitServices;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.EsppSync;
|
||||
|
||||
Reference in New Issue
Block a user