protected virtual void SplitEvent(SignalWrapper <SignalEvent <TKey> > item) { List <EventSettings <TKey> > eventSettings = _eventSettingsQueries .SelectByKey(item.Signal.EventKey).Result; if (eventSettings.Count == 0) { _eventQueue.ApplyResult(item, ProcessingResult.NoHandlerFound); } else if (eventSettings.Count == 1) { item.Signal.EventSettingsId = eventSettings.First().EventSettingsId; item.IsUpdated = true; ComposeAndApplyResult(item); } else if (eventSettings.Count > 1) { var splitedEvents = new List <SignalEvent <TKey> >(); foreach (EventSettings <TKey> settings in eventSettings) { SignalEvent <TKey> clone = item.Signal.CreateClone(); clone.SignalEventId = default(TKey); clone.EventSettingsId = settings.EventSettingsId; splitedEvents.Add(clone); } _eventQueue.ApplyResult(item, ProcessingResult.Success); _eventQueue.Append(splitedEvents, false); } }
protected virtual void QueryStorage() { _lastQueryTimeUtc = DateTime.UtcNow; _isLastQueryMaxItemsReceived = false; Stopwatch storageQueryTimer = Stopwatch.StartNew(); List <SignalEvent <TKey> > items = null; try { items = _eventQueries .Find(ItemsQueryCount, MaxFailedAttempts) .Result; } catch (Exception ex) { items = new List <SignalEvent <TKey> >(); _logger.LogError(ex, SenderInternalMessages.DatabaseEventProvider_DatabaseError); } _monitor.EventPersistentStorageQueried(storageQueryTimer.Elapsed, items); _isLastQueryMaxItemsReceived = items.Count == ItemsQueryCount; if (_changeNotifier != null && _isLastQueryMaxItemsReceived == false) { _changeNotifier.StartMonitor(); } _eventQueue.Append(items, true); }
protected virtual async Task EnqueueSignalEvent(SignalEvent <TKey> signalEvent, SignalWriteConcern writeConcern) { writeConcern = _senderSettings.GetWriteConcernOrDefault(writeConcern); bool ensurePersisted = writeConcern == SignalWriteConcern.PersistentStorage; if (ensurePersisted) { await _eventQueries.Insert(new List <SignalEvent <TKey> > { signalEvent }) .ConfigureAwait(false); } var signalWrapper = new SignalWrapper <SignalEvent <TKey> >(signalEvent, ensurePersisted); _eventQueue.Append(signalWrapper); _monitor.EventReceived(signalEvent); }