feat(esppScheduleSync): создан проект. Добавлена основная логика синхронизации. Docker
This commit is contained in:
14
PARR.EsppScheduleSync/Domain/EsppObjectSchedule.cs
Normal file
14
PARR.EsppScheduleSync/Domain/EsppObjectSchedule.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using PARR.Constants;
|
||||
using PARR.EsppSync;
|
||||
|
||||
namespace PARR.EsppScheduleSync.Domain
|
||||
{
|
||||
internal class EsppObjectSchedule : IEsppObject
|
||||
{
|
||||
public required string TemplateName { get; set; }
|
||||
|
||||
public RobotsEnum Robot => RobotsEnum.ScheduleOrder;
|
||||
|
||||
//todo:
|
||||
}
|
||||
}
|
||||
37
PARR.EsppScheduleSync/EsppScheduleSyncInstaller.cs
Normal file
37
PARR.EsppScheduleSync/EsppScheduleSyncInstaller.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PARR.BLL;
|
||||
using PARR.DAL;
|
||||
using PARR.EsppSync;
|
||||
using PARR.EsppScheduleSync.Domain;
|
||||
using PARR.EsppScheduleSync.Settings;
|
||||
|
||||
namespace PARR.EsppScheduleSync
|
||||
{
|
||||
public static class EsppScheduleSyncInstaller
|
||||
{
|
||||
public static void InstallEsppScheduleSyncServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.InstallBllServices(configuration);
|
||||
services.InstallEsppSyncServices<EsppObjectSchedule>(configuration);
|
||||
|
||||
var globalSettings = new GlobalSettings();
|
||||
configuration.GetSection(nameof(GlobalSettings)).Bind(globalSettings);
|
||||
services.AddSingleton(globalSettings);
|
||||
|
||||
services.AddTransient<IScheduleSyncher, ScheduleSyncher>();
|
||||
}
|
||||
|
||||
public static IConfigurationBuilder AddEsppScheduleConfigurations(this IConfigurationBuilder builder, IServiceCollection services)
|
||||
{
|
||||
builder.AddDalConfigurations(services);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static void AddEsppScheduleSettings(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddDallSettings(configuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
PARR.EsppScheduleSync/IScheduleSyncher.cs
Normal file
8
PARR.EsppScheduleSync/IScheduleSyncher.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace PARR.EsppScheduleSync
|
||||
{
|
||||
public interface IScheduleSyncher
|
||||
{
|
||||
void Start();
|
||||
void Stop();
|
||||
}
|
||||
}
|
||||
15
PARR.EsppScheduleSync/PARR.EsppScheduleSync.csproj
Normal file
15
PARR.EsppScheduleSync/PARR.EsppScheduleSync.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
|
||||
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
|
||||
<ProjectReference Include="..\PARR.EsppSync\PARR.EsppSync.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
91
PARR.EsppScheduleSync/ScheduleSyncher.cs
Normal file
91
PARR.EsppScheduleSync/ScheduleSyncher.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.EsppScheduleSync.Domain;
|
||||
using PARR.EsppScheduleSync.Settings;
|
||||
using PARR.EsppSync;
|
||||
|
||||
namespace PARR.EsppScheduleSync
|
||||
{
|
||||
internal class ScheduleSyncher : IScheduleSyncher
|
||||
{
|
||||
private readonly ILogger<ScheduleSyncher> logger;
|
||||
private readonly GlobalSettings globalSettings;
|
||||
private readonly IMqService mqService;
|
||||
private readonly ISyncService<EsppObjectSchedule> syncService;
|
||||
private readonly SettingsFromDb settingsFromDb;
|
||||
|
||||
public ScheduleSyncher(
|
||||
ILogger<ScheduleSyncher> logger,
|
||||
GlobalSettings globalSettings,
|
||||
IMqService mqService,
|
||||
ISyncService<EsppObjectSchedule> syncService,
|
||||
SettingsFromDb settingsFromDb
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.globalSettings = globalSettings;
|
||||
this.mqService = mqService;
|
||||
this.syncService = syncService;
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
|
||||
if (globalSettings.MqSettings == null)
|
||||
{
|
||||
logger.LogError("Нет секции настроек хранилища. MqSettings, EsppTemplates");
|
||||
throw new Exception("Нет секции настроек хранилища. MqSettings, EsppTemplates");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Start()
|
||||
{
|
||||
var isConnected = mqService.InitConsumer(globalSettings!.MqSettings!, SyncScheduleAsync);
|
||||
|
||||
if (!isConnected)
|
||||
throw new Exception("Ошибка при подключении к RabbitMq");
|
||||
|
||||
logger.LogInformation($"Запущена проверка очереди {globalSettings.MqSettings!.QueueName}.");
|
||||
}
|
||||
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
mqService.Dispose();
|
||||
|
||||
logger.LogInformation($"=== === === Соединение с очередью {globalSettings.MqSettings!.QueueName} закрыто === === ===");
|
||||
}
|
||||
|
||||
|
||||
private async Task SyncScheduleAsync(string str)
|
||||
{
|
||||
await syncService.SyncEsppObjectAsync(str, ParseStrToEsppObject, ConvertDbObjToEsppObj);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Преобразование модели БД в модель для сравнения
|
||||
/// </summary>
|
||||
/// <param name="template"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private EsppObjectSchedule ConvertDbObjToEsppObj(Template template)
|
||||
{
|
||||
//todo:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Парсинг из строки в модель для сравнения
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private EsppObjectSchedule? ParseStrToEsppObject(string str)
|
||||
{
|
||||
//todo:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
PARR.EsppScheduleSync/Settings/GlobalSettings.cs
Normal file
18
PARR.EsppScheduleSync/Settings/GlobalSettings.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using PARR.BLL.Contracts.Interfaces;
|
||||
|
||||
namespace PARR.EsppScheduleSync.Settings
|
||||
{
|
||||
internal class GlobalSettings
|
||||
{
|
||||
public MqSettings? MqSettings { get; set; }
|
||||
public string ParsingSeparator { get; set; } = "<|>";
|
||||
}
|
||||
|
||||
internal class MqSettings : IMqSettings
|
||||
{
|
||||
public string HostName { get; set; } = string.Empty;
|
||||
public string QueueName { get; set; } = string.Empty;
|
||||
public string User { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user