forked from ddrilling/AsbCloudServer
Степанов Дмитрий Александрович
96786b1be7
1. Добавил репозиторий для уведомлений 2. Добавил сервисы для уведомлений
42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
|
|
namespace AsbCloudInfrastructure.Services;
|
|
|
|
public class NotificationSendingQueueService : INotificationSendingQueueService
|
|
{
|
|
private readonly ManualResetEventSlim manualResetEventSlim = new();
|
|
private readonly ConcurrentQueue<NotificationDto> notificationsQueue = new();
|
|
|
|
public bool IsEmpty => notificationsQueue.IsEmpty;
|
|
|
|
public void Enqueue(NotificationDto notification)
|
|
{
|
|
notificationsQueue.Enqueue(notification);
|
|
manualResetEventSlim.Set();
|
|
}
|
|
|
|
public void EnqueueRange(IEnumerable<NotificationDto> notifications)
|
|
{
|
|
foreach (var notification in notifications)
|
|
{
|
|
notificationsQueue.Enqueue(notification);
|
|
}
|
|
|
|
manualResetEventSlim.Set();
|
|
}
|
|
|
|
public bool TryDequeue(out NotificationDto notification)
|
|
{
|
|
return notificationsQueue.TryDequeue(out notification!);
|
|
}
|
|
|
|
public void Wait(CancellationToken cancellationToken)
|
|
{
|
|
manualResetEventSlim.Wait(cancellationToken);
|
|
manualResetEventSlim.Reset();
|
|
}
|
|
} |