/// <summary>
        /// 处理未处理的领域事件
        /// </summary>
        public void HandleUncompletedEvents()
        {
            lock (_Sync)
            {
                //如果缓存中没有数据,则终止方法
                if (this.MemoryEventSources == null)
                {
                    return;
                }

                //如果有未处理的
                if (this.MemoryEventSources.Any(x => !x.Handled))
                {
                    foreach (Event eventSource in this.MemoryEventSources.Where(x => !x.Handled))
                    {
                        EventMediator.Handle((IEvent)eventSource);
                        eventSource.Handled = true;
                    }
                }

                //递归
                if (this.MemoryEventSources.Any(x => !x.Handled))
                {
                    this.HandleUncompletedEvents();
                }

                //处理完毕后置空缓存
                this.FreeMemoryEventSources();
            }
        }
Exemple #2
0
        /// <summary>
        /// 递归处理领域事件
        /// </summary>
        /// <param name="consumer">消息消费者</param>
        private void HandleRecursively(QueueingBasicConsumer consumer)
        {
            this._channel.BasicConsume(this._sessionId, false, consumer);

            BasicDeliverEventArgs eventArg;

            if (consumer.Queue.Dequeue(1000, out eventArg))
            {
                IEvent eventSource = this.ToObject <IEvent>(eventArg.Body);

                EventMediator.Handle(eventSource);

                this._channel.BasicAck(eventArg.DeliveryTag, false);

                this.HandleRecursively(consumer);
            }
        }
Exemple #3
0
        /// <summary>
        /// 处理未处理的领域事件
        /// </summary>
        public void HandleUncompletedEvents()
        {
            IOrderedEnumerable <Event> eventSources = this._table.OrderByDescending(x => x.AddedTime);

            //如果有未处理的
            foreach (Event eventSource in eventSources.ToArray())
            {
                EventMediator.Handle((IEvent)eventSource);
                this._table.RemoveStart();
            }

            //递归
            if (this._table.Any())
            {
                this.HandleUncompletedEvents();
            }
        }
Exemple #4
0
        /// <summary>
        /// 处理未处理的领域事件
        /// </summary>
        public void HandleUncompletedEvents()
        {
            RedisValue[] eventSourcesStr = this._redisClient.HashValues(this._sessionId);
            foreach (string eventSourceStr in eventSourcesStr)
            {
                IEvent eventSource = eventSourceStr.JsonToEvent();
                EventMediator.Handle(eventSource);

                this._redisClient.HashDelete(this._sessionId, eventSource.Id.ToString());
            }

            RedisValue[] newEventSourcesStr = this._redisClient.HashValues(this._sessionId);
            if (newEventSourcesStr.Any())
            {
                this.HandleUncompletedEvents();
            }
        }
        /// <summary>
        /// 处理未处理的领域事件
        /// </summary>
        public void HandleUncompletedEvents()
        {
            lock (_Sync)
            {
                //获取线程缓存
                object eventSources = CallContext.GetData(EventSessionKey);

                //如果缓存中没有数据,则终止方法
                if (eventSources == null)
                {
                    return;
                }

                //如果缓存不为空,则将事件源队列变量赋值为缓存
                this._eventSources = (IList <Event>)eventSources;

                //如果有未处理的
                if (this._eventSources.Any(x => !x.Handled))
                {
                    foreach (Event eventSource in this._eventSources.Where(x => !x.Handled))
                    {
                        EventMediator.Handle((IEvent)eventSource);
                        eventSource.Handled = true;
                    }
                }

                //递归
                if (this._eventSources.Any(x => !x.Handled))
                {
                    this.HandleUncompletedEvents();
                }

                //处理完毕后置空缓存
                CallContext.FreeNamedDataSlot(EventSessionKey);
            }
        }