DD.WellWorkover.Cloud/AsbCloudInfrastructure/Background/WorkToSendEmail.cs

38 lines
1.2 KiB
C#
Raw Normal View History

2023-12-21 10:50:26 +05:00
using AsbCloudApp.Data;
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;
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)
{
var notificationService = services.GetRequiredService<INotificationTransportService>();
await notificationService.SendAsync(notification, token);
2023-12-21 10:50:26 +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
}
}