2023-12-21 10:50:26 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2024-01-09 16:43:39 +05:00
|
|
|
|
using AsbCloudApp.Services.Notifications;
|
2023-12-21 10:50:26 +05:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Background
|
|
|
|
|
{
|
2023-12-21 12:31:25 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс для отправки email
|
|
|
|
|
/// </summary>
|
2023-12-21 10:50:26 +05:00
|
|
|
|
internal class WorkToSendEmail : Work
|
|
|
|
|
{
|
|
|
|
|
private NotificationDto notification;
|
|
|
|
|
|
2024-01-09 16:43:39 +05:00
|
|
|
|
public WorkToSendEmail(NotificationDto notification) : base(MakeWorkId(notification))
|
2023-12-21 10:50:26 +05:00
|
|
|
|
{
|
|
|
|
|
this.notification = notification;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task Action(string id, IServiceProvider services, Action<string, double?> onProgressCallback, CancellationToken token)
|
|
|
|
|
{
|
2024-01-09 16:43:39 +05:00
|
|
|
|
var notificationService = services.GetRequiredService<INotificationTransportService>();
|
|
|
|
|
await notificationService.SendAsync(notification, token);
|
2023-12-21 10:50:26 +05:00
|
|
|
|
}
|
2023-12-21 14:48:08 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static string MakeWorkId(NotificationDto notification)
|
|
|
|
|
{
|
|
|
|
|
var hash = notification.IdUser.GetHashCode();
|
|
|
|
|
hash ^= notification.Title.GetHashCode();
|
|
|
|
|
hash ^= notification.Message.GetHashCode();
|
|
|
|
|
return hash.ToString("x");
|
|
|
|
|
}
|
2023-12-21 10:50:26 +05:00
|
|
|
|
}
|
|
|
|
|
}
|