コード例 #1
0
        protected virtual EventHandleResult <Subscriber <TKey> > FetchSubscribers(
            EventSettings <TKey> settings, SignalEvent <TKey> signalEvent)
        {
            EventHandleResult <Subscriber <TKey> > subscribers = _subscribersFetcher.Select(settings, signalEvent);

            return(subscribers);
        }
コード例 #2
0
        //methods
        public virtual EventHandleResult <SignalDispatch <TKey> > ProcessEvent(
            EventSettings <TKey> settings, SignalEvent <TKey> signalEvent)
        {
            //check is any active templates exist
            bool hasActiveTemplates = settings.Templates.Any(x => x.IsActive);

            if (hasActiveTemplates == false)
            {
                return(new EventHandleResult <SignalDispatch <TKey> >()
                {
                    Result = ProcessingResult.Success,
                    Items = new List <SignalDispatch <TKey> >(),
                    IsFinished = true
                });
            }

            //select subscribers
            EventHandleResult <Subscriber <TKey> > subscribers = FetchSubscribers(settings, signalEvent);

            if (subscribers.Result != ProcessingResult.Success)
            {
                return(EventHandleResult <SignalDispatch <TKey> > .FromResult(subscribers.Result));
            }

            //build dispatches
            EventHandleResult <SignalDispatch <TKey> > dispatches = BuildDispatches(settings, signalEvent, subscribers.Items);

            if (dispatches.Result != ProcessingResult.Success)
            {
                return(dispatches);
            }

            //schedule send time
            ProcessingResult scheduleResult = ScheduleDispatches(settings, signalEvent, subscribers.Items, dispatches.Items);

            if (scheduleResult != ProcessingResult.Success)
            {
                return(EventHandleResult <SignalDispatch <TKey> > .FromResult(scheduleResult));
            }

            //update subscribers
            ProcessingResult updateResult = UpdateSubscribers(settings, signalEvent, subscribers.Items, dispatches.Items);

            if (updateResult != ProcessingResult.Success)
            {
                return(EventHandleResult <SignalDispatch <TKey> > .FromResult(updateResult));
            }

            //remember latest subscriber handled to resume on next iteration
            SetCurrentProgress(signalEvent, subscribers.Items);


            return(new EventHandleResult <SignalDispatch <TKey> >()
            {
                Result = ProcessingResult.Success,
                Items = dispatches.Items,
                IsFinished = subscribers.IsFinished
            });
        }
コード例 #3
0
        protected virtual EventHandleResult <SignalDispatch <TKey> > BuildDispatches(
            EventSettings <TKey> settings, SignalEvent <TKey> signalEvent, List <Subscriber <TKey> > subscribers)
        {
            EventHandleResult <SignalDispatch <TKey> > dispatches = _dispatchBuilder.Build(
                settings, signalEvent, subscribers);

            return(dispatches);
        }
コード例 #4
0
        protected virtual EventHandleResult <Subscriber <TKey> > QuerySubscribers(
            EventSettings <TKey> eventSettings, SignalEvent <TKey> signalEvent, SubscribersRangeParameters <TKey> rangeParameters)
        {
            if (eventSettings.Subscription == null)
            {
                _logger.LogError(SenderInternalMessages.Common_ParameterMissing, nameof(eventSettings.Subscription));
                return(EventHandleResult <Subscriber <TKey> > .FromResult(ProcessingResult.Fail));
            }

            //use TopicId from SignalEvent over default one in EventSettings
            //if both are null will not query for topic
            rangeParameters.TopicId = signalEvent.TopicId ?? eventSettings.Subscription.TopicId;

            //overwrite Subscription filters data with SignalEvent filters data
            rangeParameters.SubscriberFilters = new Dictionary <string, string>();
            rangeParameters.SubscriberFilters.Merge(eventSettings.Subscription.SubscriberFiltersData);
            rangeParameters.SubscriberFilters.Merge(signalEvent.SubscriberFiltersData);

            bool categoryParameterChecked = eventSettings.Subscription.CheckCategoryLastSendDate ||
                                            eventSettings.Subscription.CheckCategoryEnabled ||
                                            eventSettings.Subscription.CheckCategorySendCountNotGreater != null;

            rangeParameters.SelectFromCategories = eventSettings.Subscription.CategoryId != null &&
                                                   categoryParameterChecked;

            bool topicParameterChecked = eventSettings.Subscription.CheckTopicLastSendDate ||
                                         eventSettings.Subscription.CheckTopicEnabled ||
                                         eventSettings.Subscription.CheckTopicSendCountNotGreater != null;

            //if delivery type is not specified, will look for topic settings for all delivery types
            rangeParameters.SelectFromTopics = eventSettings.Subscription.CategoryId != null &&
                                               rangeParameters.TopicId != null &&
                                               topicParameterChecked;

            List <Subscriber <TKey> > subscribers = _subscriberQueries
                                                    .Select(eventSettings.Subscription, rangeParameters).Result;

            return(new EventHandleResult <Subscriber <TKey> >()
            {
                Items = subscribers,
                IsFinished = subscribers.Count < rangeParameters.Limit,
                Result = ProcessingResult.Success
            });
        }