using AsbCloudApp.Data; using AsbCloudApp.Repositories; using AsbCloudApp.Services.Notifications; using Microsoft.Extensions.DependencyInjection; using System; using System.Threading; using System.Threading.Tasks; namespace AsbCloudInfrastructure.Background; /// /// Класс для отправки email /// internal class WorkToSendEmail : Work { private NotificationDto notification; public WorkToSendEmail(NotificationDto notification) : base(MakeWorkId(notification)) { this.notification = notification; } protected override async Task Action(string id, IServiceProvider services, Action onProgressCallback, CancellationToken token) { var notificationService = services.GetRequiredService(); var notificationRepository = services.GetRequiredService(); await notificationService.SendAsync(notification, token); notification.SentDate = DateTimeOffset.UtcNow; await notificationRepository.UpdateAsync(notification, token); } private static string MakeWorkId(NotificationDto notification) { var hash = notification.IdUser.GetHashCode(); hash ^= notification.Title.GetHashCode(); hash ^= notification.Message.GetHashCode(); return hash.ToString("x"); } }