Merge branch 'template-generator' into dev
This commit is contained in:
14
PARR.API.sln
14
PARR.API.sln
@@ -28,7 +28,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PARR.EsppTemplateSyncWorker
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PARR.EsppTemplateSync", "PARR.EsppTemplateSync\PARR.EsppTemplateSync.csproj", "{39FD9AAD-0792-46B2-A935-42486A993C32}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.MockData", "PARR.MockData\PARR.MockData.csproj", "{B02E5B16-59BD-4F02-9CC4-6873409DBD84}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PARR.MockData", "PARR.MockData\PARR.MockData.csproj", "{B02E5B16-59BD-4F02-9CC4-6873409DBD84}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.GeneratorTemplates", "PARR.GeneratorTemplates\PARR.GeneratorTemplates.csproj", "{79EC7AD8-9A16-4806-881A-E5632C48C461}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.GeneratorTemplatesWorker", "PARR.GeneratorTemplatesWorker\PARR.GeneratorTemplatesWorker.csproj", "{BE11D005-D3FE-4F29-93A2-7379E729C78D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -74,6 +78,14 @@ Global
|
||||
{B02E5B16-59BD-4F02-9CC4-6873409DBD84}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B02E5B16-59BD-4F02-9CC4-6873409DBD84}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B02E5B16-59BD-4F02-9CC4-6873409DBD84}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{79EC7AD8-9A16-4806-881A-E5632C48C461}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{79EC7AD8-9A16-4806-881A-E5632C48C461}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{79EC7AD8-9A16-4806-881A-E5632C48C461}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{79EC7AD8-9A16-4806-881A-E5632C48C461}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BE11D005-D3FE-4F29-93A2-7379E729C78D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BE11D005-D3FE-4F29-93A2-7379E729C78D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BE11D005-D3FE-4F29-93A2-7379E729C78D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BE11D005-D3FE-4F29-93A2-7379E729C78D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -5,7 +5,9 @@ using PARR.API.Contracts.V1.Requests;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.API.Settings;
|
||||
using PARR.BLL.Domain.Mq;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
@@ -13,18 +15,21 @@ namespace PARR.API.Controllers.V1
|
||||
public class GeneratorTemplateController : BaseApiController
|
||||
{
|
||||
private readonly IValidator<GeneratorTemplateRequest> validator;
|
||||
private readonly IMqGeneratorTemplateService mqGeneratorTemplateService;
|
||||
private readonly IMqService mqService;
|
||||
private readonly IUriService uriService;
|
||||
private readonly MqSettings mqSettings;
|
||||
|
||||
public GeneratorTemplateController(
|
||||
IValidator<GeneratorTemplateRequest> validator,
|
||||
IMqGeneratorTemplateService mqGeneratorTemplateService,
|
||||
IUriService uriService
|
||||
IMqService mqService,
|
||||
IUriService uriService,
|
||||
MqSettings mqSettings
|
||||
)
|
||||
{
|
||||
this.validator = validator;
|
||||
this.mqGeneratorTemplateService = mqGeneratorTemplateService;
|
||||
this.mqService = mqService;
|
||||
this.uriService = uriService;
|
||||
this.mqSettings = mqSettings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,8 +43,6 @@ namespace PARR.API.Controllers.V1
|
||||
if (!resultValidate.IsValid)
|
||||
return BadRequest(new Response(resultValidate.Errors));
|
||||
|
||||
// Todo: проверить есть ли в бд такие ворк и апп
|
||||
|
||||
var obj = new GeneratorTemplateMq
|
||||
{
|
||||
Action = request.Action,
|
||||
@@ -50,9 +53,9 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
var msg = JsonSerializer.Serialize(obj);
|
||||
|
||||
var result = mqGeneratorTemplateService.SendMsg(msg);
|
||||
var result = mqService.Send(mqSettings.GenerateTemplates, new[] { msg });
|
||||
|
||||
if (!result)
|
||||
if (!result.IsSuccess)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при отправке данных." } }));
|
||||
|
||||
var createdUri = uriService.GetAllUri(ApiRoutes.Template.GetAll);
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace PARR.API.Installers
|
||||
});
|
||||
|
||||
services.AddTransient<IClientService, ClientService>();
|
||||
services.AddTransient<IMqGeneratorTemplateService, MqGeneratorTemplateService>();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.API.Settings;
|
||||
using RabbitMQ.Client;
|
||||
using System.Text;
|
||||
|
||||
namespace PARR.API.Services.Implementations
|
||||
{
|
||||
public class MqGeneratorTemplateService : IMqGeneratorTemplateService
|
||||
{
|
||||
private readonly MqSettings mqSettings;
|
||||
private readonly ILogger<MqGeneratorTemplateService> logger;
|
||||
|
||||
public MqGeneratorTemplateService(MqSettings mqSettings, ILogger<MqGeneratorTemplateService> logger)
|
||||
{
|
||||
this.mqSettings = mqSettings;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public bool SendMsg(string msg)
|
||||
{
|
||||
var factory = new ConnectionFactory
|
||||
{
|
||||
HostName = mqSettings.GenerateTemplates.HostName,
|
||||
UserName = mqSettings.GenerateTemplates.User,
|
||||
Password = mqSettings.GenerateTemplates.Password
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
using (var connection = factory.CreateConnection())
|
||||
using (var channel = connection.CreateModel())
|
||||
{
|
||||
//https://www.rabbitmq.com/lazy-queues.html
|
||||
//Рекомендовано при работе порциями использовать ленивые очереди. сообщения не используют память
|
||||
//Формируем соответствующий аргумент
|
||||
var args = new Dictionary<string, object> { { "x-queue-mode", "lazy" } };
|
||||
|
||||
//Объявляем очередь с которой будем работать.
|
||||
//Если такой очереди ещё нет, то создатся.
|
||||
//Если нет, нужно параметры типа durable должны совпадать иначе будет ошибка.
|
||||
//В целом эти параметры можно посмотреть в админке RabbitMQ
|
||||
|
||||
channel.QueueDeclare(
|
||||
queue: mqSettings.GenerateTemplates.QueueName,
|
||||
durable: true,
|
||||
exclusive: false,
|
||||
autoDelete: false,
|
||||
arguments: args
|
||||
);
|
||||
|
||||
var body = Encoding.UTF8.GetBytes(msg);
|
||||
|
||||
var props = channel.CreateBasicProperties();
|
||||
//храним на диске
|
||||
props.DeliveryMode = 2;
|
||||
//время жизни, мс
|
||||
//props.Expiration = "60000";
|
||||
|
||||
channel.BasicPublish(exchange: "", routingKey: mqSettings.GenerateTemplates.QueueName, basicProperties: props, body: body);
|
||||
}
|
||||
|
||||
logger.LogDebug($"Отправлено сообщение в очередь: {mqSettings.GenerateTemplates.QueueName}, {msg}");
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"Ошибка при отправке сообщения в очередь {mqSettings.GenerateTemplates.QueueName}, {msg}");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace PARR.API.Services.Interfaces
|
||||
{
|
||||
public interface IMqGeneratorTemplateService
|
||||
{
|
||||
bool SendMsg(string msg);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace PARR.API.Settings
|
||||
using PARR.BLL.Contracts.Interfaces;
|
||||
|
||||
namespace PARR.API.Settings
|
||||
{
|
||||
public class MqSettings
|
||||
{
|
||||
@@ -12,12 +14,4 @@
|
||||
public string User { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public interface IMqSettings
|
||||
{
|
||||
string HostName { get; set; }
|
||||
string QueueName { get; set; }
|
||||
string User { get; set; }
|
||||
string Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
},
|
||||
"MqSettings": {
|
||||
"GenerateTemplates": {
|
||||
"HostName": "parr-rabbitmq",
|
||||
"HostName": "10.99.253.216",
|
||||
"QueueName": "parr-generate-templates",
|
||||
"User": "generate_templates_api",
|
||||
"Password": "DHhjgdsf*&%95"
|
||||
|
||||
13
PARR.BLL/Contracts/Interfaces/IMqSettings.cs
Normal file
13
PARR.BLL/Contracts/Interfaces/IMqSettings.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace PARR.BLL.Contracts.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Поля настроек MQ, используется для appsettings.json
|
||||
/// </summary>
|
||||
public interface IMqSettings
|
||||
{
|
||||
string HostName { get; set; }
|
||||
string QueueName { get; set; }
|
||||
string User { get; set; }
|
||||
string Password { get; set; }
|
||||
}
|
||||
}
|
||||
18
PARR.BLL/Domain/Mq/MqSendResult.cs
Normal file
18
PARR.BLL/Domain/Mq/MqSendResult.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace PARR.BLL.Domain.Mq
|
||||
{
|
||||
/// <summary>
|
||||
/// Результат отправки очереди в MQ
|
||||
/// </summary>
|
||||
public class MqSendResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Результат отправки
|
||||
/// </summary>
|
||||
public bool IsSuccess { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Неотправленные сообщения
|
||||
/// </summary>
|
||||
public string[]? NotSendMessages { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
|
||||
<PackageReference Include="RabbitMQ.Client" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace PARR.BLL
|
||||
|
||||
|
||||
services.AddTransient<IFileService, FileService>();
|
||||
services.AddTransient<IMqService, MqService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
159
PARR.BLL/Services/Implementations/MqService.cs
Normal file
159
PARR.BLL/Services/Implementations/MqService.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.BLL.Contracts.Interfaces;
|
||||
using PARR.BLL.Domain.Mq;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using RabbitMQ.Client;
|
||||
using RabbitMQ.Client.Events;
|
||||
using System.Text;
|
||||
|
||||
namespace PARR.BLL.Services.Implementations
|
||||
{
|
||||
internal class MqService : IMqService
|
||||
{
|
||||
private readonly ILogger<MqService> logger;
|
||||
|
||||
private IConnection? connection;
|
||||
private IModel? channel;
|
||||
|
||||
public event ReceivedHandler? Received;
|
||||
|
||||
public MqService(ILogger<MqService> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public MqSendResult Send(IMqSettings mqSettings, string[] msgList)
|
||||
{
|
||||
var factory = new ConnectionFactory
|
||||
{
|
||||
HostName = mqSettings.HostName,
|
||||
UserName = mqSettings.User,
|
||||
Password = mqSettings.Password
|
||||
};
|
||||
|
||||
// индекс текущей отправки в очередь из массива msgList
|
||||
// нужен для формирования списка неотправленных сообщений
|
||||
var sendIdx = 0;
|
||||
|
||||
try
|
||||
{
|
||||
using (var connection = factory.CreateConnection())
|
||||
using (var channel = connection.CreateModel())
|
||||
{
|
||||
//https://www.rabbitmq.com/lazy-queues.html
|
||||
//Рекомендовано при работе порциями использовать ленивые очереди. сообщения не используют память
|
||||
//Формируем соответствующий аргумент
|
||||
var args = new Dictionary<string, object> { { "x-queue-mode", "lazy" } };
|
||||
|
||||
//Объявляем очередь с которой будем работать.
|
||||
//Если такой очереди ещё нет, то создатся.
|
||||
//Если нет, нужно параметры типа durable должны совпадать иначе будет ошибка.
|
||||
//В целом эти параметры можно посмотреть в админке RabbitMQ
|
||||
|
||||
channel.QueueDeclare(
|
||||
queue: mqSettings.QueueName,
|
||||
durable: true,
|
||||
exclusive: false,
|
||||
autoDelete: false,
|
||||
arguments: args
|
||||
);
|
||||
|
||||
var props = channel.CreateBasicProperties();
|
||||
//храним на диске
|
||||
props.DeliveryMode = 2;
|
||||
//время жизни, мс
|
||||
//props.Expiration = "60000";
|
||||
|
||||
foreach (var msg in msgList)
|
||||
{
|
||||
var body = Encoding.UTF8.GetBytes(msg);
|
||||
channel.BasicPublish(exchange: "", routingKey: mqSettings.QueueName, basicProperties: props, body: body);
|
||||
|
||||
sendIdx++;
|
||||
logger.LogDebug($"Отправлено сообщение в очередь: {mqSettings.HostName} {mqSettings.QueueName}, {msg}");
|
||||
}
|
||||
}
|
||||
|
||||
return new MqSendResult { IsSuccess = true };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var notSendMsg = new List<string>();
|
||||
|
||||
// формируем список неотправленных элементов
|
||||
for (int i = sendIdx; i < msgList.Length; i++)
|
||||
notSendMsg.Add(msgList[i]);
|
||||
|
||||
logger.LogError(ex, $"Ошибка при отправке сообщения в очередь {mqSettings.HostName} {mqSettings.QueueName}, {string.Join(',', notSendMsg)}");
|
||||
|
||||
return new MqSendResult { IsSuccess = false, NotSendMessages = notSendMsg.ToArray() };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void InitConsumer(IMqSettings mqSettings)
|
||||
{
|
||||
logger.LogInformation($"Устанавливаю соединение с RabbitMQ: {mqSettings.HostName}, {mqSettings.QueueName}");
|
||||
|
||||
var facory = new ConnectionFactory
|
||||
{
|
||||
HostName = mqSettings.HostName,
|
||||
UserName = mqSettings.User,
|
||||
Password = mqSettings.Password,
|
||||
AutomaticRecoveryEnabled = true,
|
||||
DispatchConsumersAsync = true
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
//using var connection = facory.CreateConnection();
|
||||
//using var channel = connection.CreateModel();
|
||||
|
||||
connection = facory.CreateConnection();
|
||||
channel = connection.CreateModel();
|
||||
|
||||
var args = new Dictionary<string, object> { { "x-queue-mode", "lazy" } };
|
||||
|
||||
channel.QueueDeclare(
|
||||
queue: mqSettings.QueueName,
|
||||
durable: true,
|
||||
exclusive: false,
|
||||
autoDelete: false,
|
||||
arguments: args
|
||||
);
|
||||
|
||||
logger.LogInformation($"Соединение с RabbitMQ установлено: {mqSettings.HostName}, {mqSettings.QueueName}");
|
||||
|
||||
|
||||
var consumer = new AsyncEventingBasicConsumer(channel);
|
||||
consumer.Received += async (ch, ea) =>
|
||||
{
|
||||
var content = Encoding.UTF8.GetString(ea.Body.ToArray());
|
||||
logger.LogDebug($"Получено сообщение: {content}");
|
||||
|
||||
//https://metanit.com/sharp/tutorial/3.14.php
|
||||
Received?.Invoke(content);
|
||||
|
||||
channel.BasicAck(ea.DeliveryTag, false);
|
||||
await Task.Yield();
|
||||
};
|
||||
|
||||
channel.BasicConsume(mqSettings.QueueName, false, consumer);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"Ошибка при получении сообщений из очереди: {mqSettings.HostName}, {mqSettings.QueueName}");
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
channel?.Close();
|
||||
connection?.Close();
|
||||
|
||||
channel?.Dispose();
|
||||
connection?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
15
PARR.BLL/Services/Interfaces/IMqService.cs
Normal file
15
PARR.BLL/Services/Interfaces/IMqService.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using PARR.BLL.Contracts.Interfaces;
|
||||
using PARR.BLL.Domain.Mq;
|
||||
|
||||
namespace PARR.BLL.Services.Interfaces
|
||||
{
|
||||
public delegate void ReceivedHandler(string msg);
|
||||
|
||||
public interface IMqService : IDisposable
|
||||
{
|
||||
event ReceivedHandler? Received;
|
||||
|
||||
void InitConsumer(IMqSettings mqSettings);
|
||||
MqSendResult Send(IMqSettings mqSettings, string[] msgList);
|
||||
}
|
||||
}
|
||||
53
PARR.GeneratorTemplates/GeneratorTemplate.cs
Normal file
53
PARR.GeneratorTemplates/GeneratorTemplate.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using PARR.GeneratorTemplates.Settings;
|
||||
|
||||
namespace PARR.GeneratorTemplates
|
||||
{
|
||||
internal class GeneratorTemplate : IGeneratorTemplate
|
||||
{
|
||||
private readonly MqSettings mqSettings;
|
||||
private readonly IMqService mqService;
|
||||
private readonly ILogger<GeneratorTemplate> logger;
|
||||
|
||||
public GeneratorTemplate(
|
||||
MqSettings mqSettings,
|
||||
IMqService mqService,
|
||||
ILogger<GeneratorTemplate> logger
|
||||
)
|
||||
{
|
||||
this.mqSettings = mqSettings;
|
||||
this.mqService = mqService;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
mqService.Received += (msg) =>
|
||||
{
|
||||
logger.LogInformation($"Привет откуда надо!!! ${msg}");
|
||||
//todo: идем дальеш!
|
||||
|
||||
// создать отдельный метод
|
||||
// преобразовать json в модель
|
||||
// попробовать поиск по регулярке
|
||||
|
||||
// проверить как ту дела с асинком
|
||||
// логгер работает в разных потоках все таки или нет?
|
||||
|
||||
// поиск в существующих шаблонах, есть ли такие и есть ли у них эти работы
|
||||
// поиск в хостах эк которых еще нет в шаблонах и у них такие работы
|
||||
// генерим список и вставляем в шаблоны
|
||||
};
|
||||
|
||||
mqService.InitConsumer(mqSettings);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
mqService.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
41
PARR.GeneratorTemplates/GeneratorTemplateInstaller.cs
Normal file
41
PARR.GeneratorTemplates/GeneratorTemplateInstaller.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PARR.BLL;
|
||||
using PARR.DAL;
|
||||
using PARR.GeneratorTemplates.Settings;
|
||||
|
||||
namespace PARR.GeneratorTemplates
|
||||
{
|
||||
public static class GeneratorTemplateInstaller
|
||||
{
|
||||
//1
|
||||
public static void InstallGeneratorTemplateServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.InstallDalServices(configuration);
|
||||
services.InstallBllServices(configuration);
|
||||
|
||||
var mqSettings = new MqSettings();
|
||||
configuration.GetSection(nameof(MqSettings)).Bind(mqSettings);
|
||||
services.AddSingleton(mqSettings);
|
||||
|
||||
//add other services
|
||||
services.AddTransient<IGeneratorTemplate, GeneratorTemplate>();
|
||||
}
|
||||
|
||||
//2
|
||||
public static IConfigurationBuilder AddGeneratorTemplateConfigurations(this IConfigurationBuilder builder, IServiceCollection services)
|
||||
{
|
||||
builder.AddDalConfigurations(services);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
//3
|
||||
public static void AddGeneratorTemplateSettings(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddDallSettings(configuration);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
8
PARR.GeneratorTemplates/IGeneratorTemplate.cs
Normal file
8
PARR.GeneratorTemplates/IGeneratorTemplate.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace PARR.GeneratorTemplates
|
||||
{
|
||||
public interface IGeneratorTemplate
|
||||
{
|
||||
void Start();
|
||||
void Stop();
|
||||
}
|
||||
}
|
||||
14
PARR.GeneratorTemplates/PARR.GeneratorTemplates.csproj
Normal file
14
PARR.GeneratorTemplates/PARR.GeneratorTemplates.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
12
PARR.GeneratorTemplates/Settings/MqSettings.cs
Normal file
12
PARR.GeneratorTemplates/Settings/MqSettings.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using PARR.BLL.Contracts.Interfaces;
|
||||
|
||||
namespace PARR.GeneratorTemplates.Settings
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>dotnet-PARR.GeneratorTemplatesWorker-deb14157-f207-44e0-8d4b-963c6066a75e</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PARR.GeneratorTemplates\PARR.GeneratorTemplates.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
34
PARR.GeneratorTemplatesWorker/Program.cs
Normal file
34
PARR.GeneratorTemplatesWorker/Program.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using PARR.GeneratorTemplates;
|
||||
using PARR.GeneratorTemplatesWorker;
|
||||
using Serilog;
|
||||
|
||||
|
||||
IHost host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.InstallGeneratorTemplateServices(hostContext.Configuration);
|
||||
//hostContext.Configuration.AddGeneratorTemplateConfigurations(services);
|
||||
//services.AddGeneratorTemplateSettings(hostContext.Configuration);
|
||||
|
||||
//services.AddHostedService<Worker>();
|
||||
})
|
||||
//.ConfigureAppConfiguration((hostContext, configBuilder) =>
|
||||
//{
|
||||
//TODO: !!! !!! !!! не смог прикрутить AddGeneratorTemplateConfigurations, не могу прокинуть туда сервисы
|
||||
// configBuilder.AddGeneratorTemplateConfigurations(hostContext.Services);
|
||||
//})
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
//services.AddGeneratorTemplateSettings(hostContext.Configuration);
|
||||
|
||||
services.AddHostedService<Worker>();
|
||||
})
|
||||
.UseSerilog((hostContext, services, config) =>
|
||||
{
|
||||
config
|
||||
.WriteTo.Console()
|
||||
.ReadFrom.Configuration(hostContext.Configuration);
|
||||
})
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
11
PARR.GeneratorTemplatesWorker/Properties/launchSettings.json
Normal file
11
PARR.GeneratorTemplatesWorker/Properties/launchSettings.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"profiles": {
|
||||
"PARR.GeneratorTemplatesWorker": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
PARR.GeneratorTemplatesWorker/Worker.cs
Normal file
34
PARR.GeneratorTemplatesWorker/Worker.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using PARR.GeneratorTemplates;
|
||||
|
||||
namespace PARR.GeneratorTemplatesWorker
|
||||
{
|
||||
public class Worker : BackgroundService
|
||||
{
|
||||
private readonly ILogger<Worker> _logger;
|
||||
private readonly IGeneratorTemplate generatorTemplate;
|
||||
|
||||
public Worker(ILogger<Worker> logger, IGeneratorTemplate generatorTemplate)
|
||||
{
|
||||
_logger = logger;
|
||||
this.generatorTemplate = generatorTemplate;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
// todo: обернуть в таск?
|
||||
generatorTemplate.Start();
|
||||
//while (!stoppingToken.IsCancellationRequested)
|
||||
//{
|
||||
// _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
// await Task.Delay(1000, stoppingToken);
|
||||
//}
|
||||
}
|
||||
|
||||
public override Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
generatorTemplate.Stop();
|
||||
|
||||
return base.StopAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
PARR.GeneratorTemplatesWorker/appsettings.Development.json
Normal file
11
PARR.GeneratorTemplatesWorker/appsettings.Development.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"MqSettings": {
|
||||
"HostName": "10.99.253.216"
|
||||
}
|
||||
}
|
||||
32
PARR.GeneratorTemplatesWorker/appsettings.json
Normal file
32
PARR.GeneratorTemplatesWorker/appsettings.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Debug"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "log/log-.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"MqSettings": {
|
||||
"HostName": "10.99.253.216",
|
||||
"QueueName": "parr-generate-templates",
|
||||
"User": "generate_templates_worker",
|
||||
"Password": "Dhgdf%d&609sssa"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.AIHIT;
|
||||
using PARR.DAL;
|
||||
using PARR.Mail;
|
||||
using PARR.Worker;
|
||||
using PARR.Worker.Settings;
|
||||
using Serilog;
|
||||
|
||||
Reference in New Issue
Block a user