Esempio n. 1
0
        internal static void Initialize()
        {
            EventAttribute.Initialize();

            //订阅事件
            SubscribeEvents();
            EventRestorer.RestoreAsync();

            InitTimer();
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tip"></param>
        private static void CanceleReverse(EventAttribute tip)
        {
            if (!tip.IsEnabled)
            {
                return;
            }

            var reverseName = EventUtil.GetReverse(tip.Name);

            EventPortal.Cancel(reverseName);
        }
Esempio n. 3
0
        /// <summary>
        /// 订阅回逆
        /// </summary>
        /// <param name="tip"></param>
        private static void SubscribeReverse(EventAttribute tip)
        {
            if (!tip.IsEnabled)
            {
                return;
            }

            var reverseName = EventUtil.GetReverse(tip.Name);

            EventPortal.Subscribe(reverseName, ReverseEventHandler.Instance);
        }
Esempio n. 4
0
        /// <summary>
        /// 订阅触发
        /// </summary>
        /// <param name="tip"></param>
        private static void SubscribeRaise(EventAttribute tip)
        {
            if (!tip.IsEnabled)
            {
                return;
            }

            var raiseName = EventUtil.GetRaise(tip.Name);

            //作为事件的提供方,我们订阅了触发事件,这样当外界发布了“触发事件”后,这里就可以收到消息并且执行事件
            EventPortal.Subscribe(raiseName, RaiseEventHandler.Instance);
        }
Esempio n. 5
0
        /// <summary>
        /// 禁用事件
        /// </summary>
        /// <param name="eventNames"></param>
        public static void DisabledEvent(params string[] eventNames)
        {
            var tips = EventAttribute.Tips;

            foreach (var eventName in eventNames)
            {
                var tip = EventAttribute.GetTip(eventName, false);
                if (tip != null)
                {
                    tip.IsEnabled = false;
                }
            }
        }
Esempio n. 6
0
        public static EventAttribute GetTip(string eventName, bool throwError)
        {
            EventAttribute tip = null;

            if (_nameTips.TryGetValue(eventName, out tip))
            {
                return(tip);
            }
            if (throwError)
            {
                throw new DomainEventException(string.Format(Strings.NoEvent, eventName));
            }
            return(null);
        }
Esempio n. 7
0
        public static DomainEvent GetLocalEvent(string eventName, DTObject args, bool throwError)
        {
            //因为领域事件的处理被事件锁锁了,所以这里不存在并发问题,不需要锁cache
            var tip = EventAttribute.GetTip(eventName, throwError);

            if (tip == null)
            {
                return(null);
            }
            if (!tip.IsEnabled)
            {
                return(null);                //如果宿主过滤该事件,那么事件不是本地的
            }
            var @event = (DomainEvent)tip.EventType.GetConstructor(Array.Empty <Type>()).CreateInstance(null);

            if (!args.IsEmpty())
            {
                @event.SetArgs(args);
            }
            return(@event);
        }