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

44 lines
1.3 KiB
C#
Raw Permalink Normal View History

using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
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;
2024-08-19 10:01:07 +05:00
namespace AsbCloudInfrastructure.Background;
/// <summary>
/// Класс для отправки email
/// </summary>
internal class WorkToSendEmail : Work
2023-12-21 10:50:26 +05:00
{
2024-08-19 10:01:07 +05:00
private NotificationDto notification;
2023-12-21 10:50:26 +05:00
2024-08-19 10:01:07 +05:00
public WorkToSendEmail(NotificationDto notification) : base(MakeWorkId(notification))
{
this.notification = notification;
}
2023-12-21 10:50:26 +05:00
2024-08-19 10:01:07 +05:00
protected override async Task Action(string id, IServiceProvider services, Action<string, double?> onProgressCallback, CancellationToken token)
{
var notificationService = services.GetRequiredService<INotificationTransportService>();
var notificationRepository = services.GetRequiredService<INotificationRepository>();
2024-08-19 10:01:07 +05:00
await notificationService.SendAsync(notification, token);
2024-08-19 10:01:07 +05:00
notification.SentDate = DateTimeOffset.UtcNow;
await notificationRepository.UpdateAsync(notification, token);
2024-08-19 10:01:07 +05:00
}
2024-08-19 10:01:07 +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
}
}