feat: Перенесен IntervalService
This commit is contained in:
@@ -4,6 +4,7 @@ using PARR.AIHITMainLoader.Models;
|
|||||||
using PARR.AIHITMainLoader.Services;
|
using PARR.AIHITMainLoader.Services;
|
||||||
using PARR.AIHITMainLoader.Settings;
|
using PARR.AIHITMainLoader.Settings;
|
||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.Core.Common;
|
||||||
using PARR.Core.Common.RabbitServices;
|
using PARR.Core.Common.RabbitServices;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using PARR.AIHITRelationshipsSyncer.Models;
|
|||||||
using PARR.AIHITRelationshipsSyncer.Services.Interfaces;
|
using PARR.AIHITRelationshipsSyncer.Services.Interfaces;
|
||||||
using PARR.AIHITRelationshipsSyncer.Settings;
|
using PARR.AIHITRelationshipsSyncer.Settings;
|
||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.Core.Common;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace PARR.AIHITRelationshipsSyncer
|
namespace PARR.AIHITRelationshipsSyncer
|
||||||
|
|||||||
@@ -16,14 +16,13 @@ namespace PARR.BLL
|
|||||||
services.AddSingleton(storageSettings);
|
services.AddSingleton(storageSettings);
|
||||||
|
|
||||||
|
|
||||||
services.AddTransient<IFileService, FileService>();
|
//services.AddTransient<IFileService, FileService>();
|
||||||
|
|
||||||
//services.AddTransient<IMqService, MqService>();
|
//services.AddTransient<IMqService, MqService>();
|
||||||
//services.AddTransient<IMqService, MqServiceV2>();
|
//services.AddTransient<IMqService, MqServiceV2>();
|
||||||
|
|
||||||
//services.AddHttpClient<IMqAdminService, MqAdminService>();
|
//services.AddHttpClient<IMqAdminService, MqAdminService>();
|
||||||
services.AddTransient<ITransformService, TransformService>();
|
services.AddTransient<ITransformService, TransformService>();
|
||||||
services.AddTransient<IIntervalService, IntervalService>();
|
|
||||||
services.AddTransient<ICalendarService, CalendarService>();
|
services.AddTransient<ICalendarService, CalendarService>();
|
||||||
services.AddTransient<ITemplateMaskValidator, TemplateMaskValidator>();
|
services.AddTransient<ITemplateMaskValidator, TemplateMaskValidator>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<FileService> logger;
|
|
||||||
|
|
||||||
public FileService(StorageSettings storageSettings, ILogger<FileService> 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<UploadResult?> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using PARR.BLL.Domain;
|
|
||||||
|
|
||||||
namespace PARR.BLL.Services.Interfaces
|
|
||||||
{
|
|
||||||
public interface IFileService
|
|
||||||
{
|
|
||||||
Task<UploadResult?> UploadAsync(IFormFile formFile, string[] rootFolderWithoutStorage);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Размер файла не превышает лимит?
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="formFile"></param>
|
|
||||||
/// <param name="limit"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
bool IsNotExceededLimit(IFormFile formFile, int limitMb);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Разрешено это расширение?
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="formFile"></param>
|
|
||||||
/// <param name="allowedExtensions"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
bool IsExtensionAllowed(IFormFile formFile, string[] allowedExtensions);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Удалить файл
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="path">Полный путь к файлу</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
bool DeleteFile(string path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
namespace PARR.BLL.Services.Interfaces
|
|
||||||
{
|
|
||||||
public delegate Task IntervalHandlerDelegate();
|
|
||||||
|
|
||||||
public interface IIntervalService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Метод выполняется с интервалом
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="intervalHandler">Метод который нужно выполнить</param>
|
|
||||||
/// <param name="interval">Интервал</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task IntervalInitAsync(IntervalHandlerDelegate intervalHandler, TimeSpan interval);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
16
PARR.Core/Common/IIntervalService.cs
Normal file
16
PARR.Core/Common/IIntervalService.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
namespace PARR.Core.Common
|
||||||
|
{
|
||||||
|
//public delegate Task IntervalHandlerDelegate();
|
||||||
|
|
||||||
|
public interface IIntervalService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Метод выполняется с интервалом
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handler">Метод который нужно выполнить</param>
|
||||||
|
/// <param name="interval">Интервал</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task IntervalInitAsync(Func<Task> handler, TimeSpan interval);
|
||||||
|
//Task IntervalInitAsync(IntervalHandlerDelegate intervalHandler, TimeSpan interval);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.Core.Common;
|
||||||
using PARR.DAL.Contracts;
|
using PARR.DAL.Contracts;
|
||||||
using PARR.EsppApi;
|
using PARR.EsppApi;
|
||||||
using PARR.EsppApi.Models;
|
using PARR.EsppApi.Models;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace PARR.EsppTemplateSync
|
|||||||
internal class TemplateFileSyncer : ITemplateSyncer
|
internal class TemplateFileSyncer : ITemplateSyncer
|
||||||
{
|
{
|
||||||
private readonly ILogger<TemplateFileSyncer> logger;
|
private readonly ILogger<TemplateFileSyncer> logger;
|
||||||
private readonly IFileService fileService;
|
//private readonly IFileService fileService;
|
||||||
private readonly GlobalSettings globalSettings;
|
private readonly GlobalSettings globalSettings;
|
||||||
//private readonly IManager manager;
|
//private readonly IManager manager;
|
||||||
private readonly string dirPath;
|
private readonly string dirPath;
|
||||||
@@ -18,13 +18,13 @@ namespace PARR.EsppTemplateSync
|
|||||||
public TemplateFileSyncer(
|
public TemplateFileSyncer(
|
||||||
BLL.Settings.StorageSettings storageSettings,
|
BLL.Settings.StorageSettings storageSettings,
|
||||||
ILogger<TemplateFileSyncer> logger,
|
ILogger<TemplateFileSyncer> logger,
|
||||||
IFileService fileService,
|
//IFileService fileService,
|
||||||
GlobalSettings globalSettings//,
|
GlobalSettings globalSettings//,
|
||||||
// IManager manager
|
// IManager manager
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.fileService = fileService;
|
//this.fileService = fileService;
|
||||||
this.globalSettings = globalSettings;
|
this.globalSettings = globalSettings;
|
||||||
//this.manager = manager;
|
//this.manager = manager;
|
||||||
if (storageSettings.EsppTemplates == null)
|
if (storageSettings.EsppTemplates == null)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using PARR.Core.Common;
|
||||||
using PARR.Core.Common.RabbitServices;
|
using PARR.Core.Common.RabbitServices;
|
||||||
|
using PARR.Infrastructure.Interval;
|
||||||
using PARR.Infrastructure.Rabbit;
|
using PARR.Infrastructure.Rabbit;
|
||||||
|
|
||||||
namespace PARR.Infrastructure
|
namespace PARR.Infrastructure
|
||||||
@@ -20,6 +22,7 @@ namespace PARR.Infrastructure
|
|||||||
services.AddHttpClient<IRabbitAdminService, RabbitAdminService>();
|
services.AddHttpClient<IRabbitAdminService, RabbitAdminService>();
|
||||||
services.AddTransient<IRabbitService, RabbitService>();
|
services.AddTransient<IRabbitService, RabbitService>();
|
||||||
|
|
||||||
|
services.AddTransient<IIntervalService, IntervalService>();
|
||||||
|
|
||||||
//services.AddTransient<IEmailService, EmailService>();
|
//services.AddTransient<IEmailService, EmailService>();
|
||||||
//services.AddTransient<IRabbitService, RabbitService>();
|
//services.AddTransient<IRabbitService, RabbitService>();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
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
|
internal class IntervalService : IIntervalService
|
||||||
{
|
{
|
||||||
@@ -12,7 +12,8 @@ namespace PARR.BLL.Services.Implementations
|
|||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task IntervalInitAsync(IntervalHandlerDelegate intervalHandler, TimeSpan interval)
|
//public async Task IntervalInitAsync(IntervalHandlerDelegate intervalHandler, TimeSpan interval)
|
||||||
|
public async Task IntervalInitAsync(Func<Task> handler, TimeSpan interval)
|
||||||
{
|
{
|
||||||
logger.LogInformation("Инициализация интервального сервиса с интервалом: {Interval}", interval);
|
logger.LogInformation("Инициализация интервального сервиса с интервалом: {Interval}", interval);
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ namespace PARR.BLL.Services.Implementations
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await intervalHandler.Invoke();
|
await handler.Invoke();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.Core.Common;
|
||||||
using PARR.Core.Common.RabbitServices;
|
using PARR.Core.Common.RabbitServices;
|
||||||
using PARR.DAL.Services.Interfaces.Job;
|
using PARR.DAL.Services.Interfaces.Job;
|
||||||
using PARR.Domain.Common.Rabbit.Messages;
|
using PARR.Domain.Common.Rabbit.Messages;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.Core.Common;
|
||||||
using PARR.Master.Services;
|
using PARR.Master.Services;
|
||||||
using PARR.Master.Settings;
|
using PARR.Master.Settings;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using PARR.BLL;
|
using PARR.BLL;
|
||||||
|
using PARR.Core;
|
||||||
using PARR.DAL;
|
using PARR.DAL;
|
||||||
|
using PARR.Infrastructure;
|
||||||
using PARR.NextRun.Services;
|
using PARR.NextRun.Services;
|
||||||
using PARR.NextRun.Settings;
|
using PARR.NextRun.Settings;
|
||||||
|
|
||||||
@@ -14,6 +16,9 @@ namespace PARR.NextRun
|
|||||||
services.InstallBllServices(configuration);
|
services.InstallBllServices(configuration);
|
||||||
services.InstallDalServices(configuration);
|
services.InstallDalServices(configuration);
|
||||||
|
|
||||||
|
services.AddCoreServices(configuration);
|
||||||
|
services.AddInfrastructureServices(configuration);
|
||||||
|
|
||||||
var settings = new WorkerSettings();
|
var settings = new WorkerSettings();
|
||||||
configuration.GetSection(nameof(WorkerSettings)).Bind(settings);
|
configuration.GetSection(nameof(WorkerSettings)).Bind(settings);
|
||||||
services.AddSingleton(settings);
|
services.AddSingleton(settings);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.Core.Common;
|
||||||
using PARR.Domain.Entities.Base.History;
|
using PARR.Domain.Entities.Base.History;
|
||||||
using PARR.Domain.Enums;
|
using PARR.Domain.Enums;
|
||||||
using PARR.NextRun.Services;
|
using PARR.NextRun.Services;
|
||||||
|
|||||||
@@ -8,7 +8,10 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
|
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
|
||||||
|
<ProjectReference Include="..\PARR.Common\PARR.Common.csproj" />
|
||||||
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
|
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
|
||||||
|
<ProjectReference Include="..\PARR.Domain\PARR.Domain.csproj" />
|
||||||
|
<ProjectReference Include="..\PARR.Infrastructure\PARR.Infrastructure.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PARR.BLL.Services.Interfaces;
|
using PARR.BLL.Services.Interfaces;
|
||||||
|
using PARR.Core.Common;
|
||||||
using PARR.DAL.DomainServices.Interfaces;
|
using PARR.DAL.DomainServices.Interfaces;
|
||||||
using PARR.DAL.Services.Interfaces;
|
using PARR.DAL.Services.Interfaces;
|
||||||
using PARR.Domain.Enums;
|
using PARR.Domain.Enums;
|
||||||
|
|||||||
Reference in New Issue
Block a user