92 lines
3.1 KiB
C#
92 lines
3.1 KiB
C#
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();
|
||
}
|
||
}
|
||
}
|