/// <summary> /// Acknowledges notifications by a sender and given filter /// </summary> private void AcknowledgeByFilter(INotificationSender sender, Predicate <NotificationMap> filter) { _listLock.EnterWriteLock(); var publishes = _published.Where(m => filter(m)).ToArray(); _published.RemoveAll(filter); _pendingPubs.RemoveAll(filter); foreach (var published in publishes) { var managed = (IManagedNotification)published.Notification; managed.Acknowledged = DateTime.Now; managed.Acknowledger = sender.Identifier; _pendingAcks.Add(published); } _listLock.ExitWriteLock(); foreach (var published in publishes) { Acknowledged?.Invoke(this, published.Notification); } }
/// <inheritdoc /> public void Acknowledge(INotificationSender sender, INotification notification) { if (string.IsNullOrEmpty(sender.Identifier)) { throw new InvalidOperationException("The identifier of the sender must be set"); } if (notification == null) { throw new ArgumentNullException(nameof(notification), "Notification must be set"); } var managed = (IManagedNotification)notification; managed.Acknowledged = DateTime.Now; managed.Acknowledger = sender.Identifier; _listLock.EnterWriteLock(); var published = _published.SingleOrDefault(n => n.Notification.Identifier == notification.Identifier); if (published != null) { _published.Remove(published); } if (published == null) { published = _pendingPubs.SingleOrDefault(n => n.Notification.Identifier == notification.Identifier); if (published == null) { _listLock.ExitWriteLock(); throw new InvalidOperationException("Notification was not managed by the adapter. " + "The sender was not registered on the adapter"); } _pendingPubs.Remove(published); } _pendingAcks.Add(published); _listLock.ExitWriteLock(); Acknowledged?.Invoke(this, published.Notification); }
/// <inheritdoc /> void INotificationSourceAdapter.PublishProcessed(INotification notification) { _listLock.EnterWriteLock(); var map = _pendingPubs.SingleOrDefault(n => n.Notification.Identifier.Equals(notification.Identifier)); if (map != null) { _pendingPubs.Remove(map); _published.Add(map); _listLock.ExitWriteLock(); } else { // Notification is maybe not pending anymore - we only can acknowledge it _listLock.ExitWriteLock(); var managed = (IManagedNotification)notification; managed.Acknowledged = DateTime.Now; managed.Acknowledger = nameof(NotificationAdapter); Acknowledged?.Invoke(this, notification); } }
/// <inheritdoc /> void INotificationSourceAdapter.Sync() { // Publish pending notifications _listLock.EnterReadLock(); var pendingPublishs = _pendingPubs.ToArray(); _listLock.ExitReadLock(); foreach (var pendingPublish in pendingPublishs) { Published?.Invoke(this, pendingPublish.Notification); } // Acknowledge pending acknowledges _listLock.EnterReadLock(); var pendingAcks = _pendingAcks.ToArray(); _listLock.ExitReadLock(); foreach (var pendingAck in pendingAcks) { Acknowledged?.Invoke(this, pendingAck.Notification); } }
internal void ConsumeAck(ViscaAckStatus ack) { _ackStatus = ack; _ackWaiter.Set(); Acknowledged?.Invoke(this, ack); }
private void OnNotificationAcknowledged(object sender, INotification notification) { Acknowledged?.Invoke(this, notification); }