diff --git a/PARR.AIHITMainLoader/AihitMainLoader.cs b/PARR.AIHITMainLoader/AihitMainLoader.cs index 8fadc1c9..2721b2da 100644 --- a/PARR.AIHITMainLoader/AihitMainLoader.cs +++ b/PARR.AIHITMainLoader/AihitMainLoader.cs @@ -4,6 +4,7 @@ using PARR.AIHITMainLoader.Models; using PARR.AIHITMainLoader.Services; using PARR.AIHITMainLoader.Settings; using PARR.BLL.Services.Interfaces; +using PARR.Core.Common; using PARR.Core.Common.RabbitServices; using System.Text.Encodings.Web; using System.Text.Json; diff --git a/PARR.AIHITRelationshipsSyncer/RelationshipsSyncer.cs b/PARR.AIHITRelationshipsSyncer/RelationshipsSyncer.cs index f63915ff..ad283a88 100644 --- a/PARR.AIHITRelationshipsSyncer/RelationshipsSyncer.cs +++ b/PARR.AIHITRelationshipsSyncer/RelationshipsSyncer.cs @@ -3,6 +3,7 @@ using PARR.AIHITRelationshipsSyncer.Models; using PARR.AIHITRelationshipsSyncer.Services.Interfaces; using PARR.AIHITRelationshipsSyncer.Settings; using PARR.BLL.Services.Interfaces; +using PARR.Core.Common; using System.Text.Json; namespace PARR.AIHITRelationshipsSyncer diff --git a/PARR.BLL/ParrBllInstaller.cs b/PARR.BLL/ParrBllInstaller.cs index 114a6fa9..83f86460 100644 --- a/PARR.BLL/ParrBllInstaller.cs +++ b/PARR.BLL/ParrBllInstaller.cs @@ -16,14 +16,13 @@ namespace PARR.BLL services.AddSingleton(storageSettings); - services.AddTransient(); + //services.AddTransient(); //services.AddTransient(); //services.AddTransient(); //services.AddHttpClient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); } diff --git a/PARR.BLL/Services/Implementations/FileService.cs b/PARR.BLL/Services/Implementations/FileService.cs deleted file mode 100644 index 439a6daf..00000000 --- a/PARR.BLL/Services/Implementations/FileService.cs +++ /dev/null @@ -1,124 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Logging; -using PARR.BLL.Domain; -using PARR.BLL.Services.Interfaces; -using PARR.BLL.Settings; - -namespace PARR.BLL.Services.Implementations -{ - internal class FileService : IFileService - { - private readonly StorageSettings storageSettings; - private readonly ILogger logger; - - public FileService(StorageSettings storageSettings, ILogger logger) - { - this.storageSettings = storageSettings; - this.logger = logger; - } - - public bool IsExtensionAllowed(IFormFile formFile, string[] allowedExtensions) - { - var extension = Path.GetExtension(formFile.FileName).ToLower(); - - return !string.IsNullOrEmpty(extension) && allowedExtensions.Contains(extension); - } - - public bool IsNotExceededLimit(IFormFile formFile, int limitMb) - { - var fileSizeByte = formFile.Length; - var fileSizeMByte = fileSizeByte / 1024.0 / 1024.0; - - return fileSizeMByte < limitMb; - } - - public async Task UploadAsync(IFormFile formFile, string[] rootFolderWithoutStorage) - { - InitRootFolders(rootFolderWithoutStorage); - - //Генерим уникальное имя файла: старое имя + рандом в середину - var newFileName = $"{Path.GetFileNameWithoutExtension(formFile.FileName)}-{Path.GetFileNameWithoutExtension(Path.GetRandomFileName())}{Path.GetExtension(formFile.FileName)}"; - - - var relativePath = Path.Combine(Path.Combine(rootFolderWithoutStorage), newFileName); - var absPath = Path.Combine(storageSettings.StoragePath, relativePath); - - if (File.Exists(absPath)) - { - logger.LogError($"Не могу сохранить файл, такой файл уже существует: {absPath}"); - return null; - } - - try - { - var origFileName = Path.GetFileName(formFile.FileName); - - using (var stream = new FileStream(absPath, FileMode.Create)) - { - await formFile.CopyToAsync(stream); - logger.LogInformation($"Файл сохранен {origFileName}, {absPath}"); - } - - return new UploadResult { FileName = origFileName, Path = relativePath }; - } - catch (Exception ex) - { - logger.LogError(ex, $"Ошибка при сохранении файла {absPath}"); - return null; - } - } - - private void InitRootFolders(string[] rootFolderWithoutStorage) - { - if (!rootFolderWithoutStorage.Any()) - return; - - var path = string.Empty; - foreach (var item in rootFolderWithoutStorage) - { - path = Path.Combine(path, item); - CreateDirectory(path); - } - } - - private void CreateDirectory(string relativePath) - { - var absolutePath = Path.Combine(storageSettings.StoragePath, relativePath); - - try - { - if (!Directory.Exists(absolutePath)) - Directory.CreateDirectory(absolutePath); - - // не нужно ничего возвращать, при сохраненнии файла будет ошибка и ее обработаем - //return true; - } - catch (Exception e) - { - logger.LogError(e, $"Не могу создать директорию: {absolutePath}"); - //return false; - } - } - - public bool DeleteFile(string path) - { - logger.LogInformation($"Удаляю файл: {path}"); - - try - { - if (!File.Exists(path)) - return true; - - File.Delete(path); - logger.LogInformation($"Файл удален: {path}"); - - return true; - } - catch (Exception e) - { - logger.LogError(e, $"Ошибка при удалении файла {path}"); - return false; - } - } - } -} diff --git a/PARR.BLL/Services/Interfaces/IFileService.cs b/PARR.BLL/Services/Interfaces/IFileService.cs deleted file mode 100644 index 3d0a36f1..00000000 --- a/PARR.BLL/Services/Interfaces/IFileService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Http; -using PARR.BLL.Domain; - -namespace PARR.BLL.Services.Interfaces -{ - public interface IFileService - { - Task UploadAsync(IFormFile formFile, string[] rootFolderWithoutStorage); - - /// - /// Размер файла не превышает лимит? - /// - /// - /// - /// - bool IsNotExceededLimit(IFormFile formFile, int limitMb); - - /// - /// Разрешено это расширение? - /// - /// - /// - /// - bool IsExtensionAllowed(IFormFile formFile, string[] allowedExtensions); - - /// - /// Удалить файл - /// - /// Полный путь к файлу - /// - bool DeleteFile(string path); - } -} diff --git a/PARR.BLL/Services/Interfaces/IIntervalService.cs b/PARR.BLL/Services/Interfaces/IIntervalService.cs deleted file mode 100644 index ac45f577..00000000 --- a/PARR.BLL/Services/Interfaces/IIntervalService.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace PARR.BLL.Services.Interfaces -{ - public delegate Task IntervalHandlerDelegate(); - - public interface IIntervalService - { - /// - /// Метод выполняется с интервалом - /// - /// Метод который нужно выполнить - /// Интервал - /// - Task IntervalInitAsync(IntervalHandlerDelegate intervalHandler, TimeSpan interval); - } -} \ No newline at end of file diff --git a/PARR.Core/Common/IIntervalService.cs b/PARR.Core/Common/IIntervalService.cs new file mode 100644 index 00000000..7feba9c4 --- /dev/null +++ b/PARR.Core/Common/IIntervalService.cs @@ -0,0 +1,16 @@ +namespace PARR.Core.Common +{ + //public delegate Task IntervalHandlerDelegate(); + + public interface IIntervalService + { + /// + /// Метод выполняется с интервалом + /// + /// Метод который нужно выполнить + /// Интервал + /// + Task IntervalInitAsync(Func handler, TimeSpan interval); + //Task IntervalInitAsync(IntervalHandlerDelegate intervalHandler, TimeSpan interval); + } +} \ No newline at end of file diff --git a/PARR.EsppOrderLoader/EsppOrderLoader.cs b/PARR.EsppOrderLoader/EsppOrderLoader.cs index 1e0f8e7a..571540f0 100644 --- a/PARR.EsppOrderLoader/EsppOrderLoader.cs +++ b/PARR.EsppOrderLoader/EsppOrderLoader.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using PARR.BLL.Services.Interfaces; +using PARR.Core.Common; using PARR.DAL.Contracts; using PARR.EsppApi; using PARR.EsppApi.Models; diff --git a/PARR.EsppTemplateSync/TemplateFileSyncer.cs b/PARR.EsppTemplateSync/TemplateFileSyncer.cs index 01c8d7b9..05e056a8 100644 --- a/PARR.EsppTemplateSync/TemplateFileSyncer.cs +++ b/PARR.EsppTemplateSync/TemplateFileSyncer.cs @@ -7,7 +7,7 @@ namespace PARR.EsppTemplateSync internal class TemplateFileSyncer : ITemplateSyncer { private readonly ILogger logger; - private readonly IFileService fileService; + //private readonly IFileService fileService; private readonly GlobalSettings globalSettings; //private readonly IManager manager; private readonly string dirPath; @@ -18,13 +18,13 @@ namespace PARR.EsppTemplateSync public TemplateFileSyncer( BLL.Settings.StorageSettings storageSettings, ILogger logger, - IFileService fileService, + //IFileService fileService, GlobalSettings globalSettings//, // IManager manager ) { this.logger = logger; - this.fileService = fileService; + //this.fileService = fileService; this.globalSettings = globalSettings; //this.manager = manager; if (storageSettings.EsppTemplates == null) diff --git a/PARR.Infrastructure/DependencyInjection.cs b/PARR.Infrastructure/DependencyInjection.cs index ef27fb9a..cd8ae3d7 100644 --- a/PARR.Infrastructure/DependencyInjection.cs +++ b/PARR.Infrastructure/DependencyInjection.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using PARR.Core.Common; using PARR.Core.Common.RabbitServices; +using PARR.Infrastructure.Interval; using PARR.Infrastructure.Rabbit; namespace PARR.Infrastructure @@ -20,6 +22,7 @@ namespace PARR.Infrastructure services.AddHttpClient(); services.AddTransient(); + services.AddTransient(); //services.AddTransient(); //services.AddTransient(); diff --git a/PARR.BLL/Services/Implementations/IntervalService.cs b/PARR.Infrastructure/Interval/IntervalService.cs similarity index 88% rename from PARR.BLL/Services/Implementations/IntervalService.cs rename to PARR.Infrastructure/Interval/IntervalService.cs index 4d61f401..2493b198 100644 --- a/PARR.BLL/Services/Implementations/IntervalService.cs +++ b/PARR.Infrastructure/Interval/IntervalService.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Logging; -using PARR.BLL.Services.Interfaces; +using PARR.Core.Common; -namespace PARR.BLL.Services.Implementations +namespace PARR.Infrastructure.Interval { internal class IntervalService : IIntervalService { @@ -12,7 +12,8 @@ namespace PARR.BLL.Services.Implementations this.logger = logger; } - public async Task IntervalInitAsync(IntervalHandlerDelegate intervalHandler, TimeSpan interval) + //public async Task IntervalInitAsync(IntervalHandlerDelegate intervalHandler, TimeSpan interval) + public async Task IntervalInitAsync(Func handler, TimeSpan interval) { logger.LogInformation("Инициализация интервального сервиса с интервалом: {Interval}", interval); @@ -26,7 +27,7 @@ namespace PARR.BLL.Services.Implementations try { - await intervalHandler.Invoke(); + await handler.Invoke(); } catch (Exception ex) { diff --git a/PARR.JobAutoControl/JobAutoControlManager.cs b/PARR.JobAutoControl/JobAutoControlManager.cs index 5d840065..0aa6b280 100644 --- a/PARR.JobAutoControl/JobAutoControlManager.cs +++ b/PARR.JobAutoControl/JobAutoControlManager.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using PARR.BLL.Services.Interfaces; +using PARR.Core.Common; using PARR.Core.Common.RabbitServices; using PARR.DAL.Services.Interfaces.Job; using PARR.Domain.Common.Rabbit.Messages; diff --git a/PARR.Master/Master.cs b/PARR.Master/Master.cs index 6efe9224..d0f6cd92 100644 --- a/PARR.Master/Master.cs +++ b/PARR.Master/Master.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using PARR.BLL.Services.Interfaces; +using PARR.Core.Common; using PARR.Master.Services; using PARR.Master.Settings; diff --git a/PARR.NextRun/NextRunInstaller.cs b/PARR.NextRun/NextRunInstaller.cs index 8a3b03c5..fd3f04d5 100644 --- a/PARR.NextRun/NextRunInstaller.cs +++ b/PARR.NextRun/NextRunInstaller.cs @@ -1,7 +1,9 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using PARR.BLL; +using PARR.Core; using PARR.DAL; +using PARR.Infrastructure; using PARR.NextRun.Services; using PARR.NextRun.Settings; @@ -14,6 +16,9 @@ namespace PARR.NextRun services.InstallBllServices(configuration); services.InstallDalServices(configuration); + services.AddCoreServices(configuration); + services.AddInfrastructureServices(configuration); + var settings = new WorkerSettings(); configuration.GetSection(nameof(WorkerSettings)).Bind(settings); services.AddSingleton(settings); diff --git a/PARR.NextRun/NextRunIntervalService.cs b/PARR.NextRun/NextRunIntervalService.cs index 92f79547..557b6289 100644 --- a/PARR.NextRun/NextRunIntervalService.cs +++ b/PARR.NextRun/NextRunIntervalService.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using PARR.BLL.Services.Interfaces; +using PARR.Core.Common; using PARR.Domain.Entities.Base.History; using PARR.Domain.Enums; using PARR.NextRun.Services; diff --git a/PARR.NextRun/PARR.NextRun.csproj b/PARR.NextRun/PARR.NextRun.csproj index 21190861..21a28b32 100644 --- a/PARR.NextRun/PARR.NextRun.csproj +++ b/PARR.NextRun/PARR.NextRun.csproj @@ -8,7 +8,10 @@ + + + diff --git a/PARR.Test/Worker.cs b/PARR.Test/Worker.cs index feaa09c8..47e71b7b 100644 --- a/PARR.Test/Worker.cs +++ b/PARR.Test/Worker.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using PARR.BLL.Services.Interfaces; +using PARR.Core.Common; using PARR.DAL.DomainServices.Interfaces; using PARR.DAL.Services.Interfaces; using PARR.Domain.Enums;