Пример #1
0
 /// <summary>
 /// 移除事件处理器。
 /// </summary>
 /// <param name="route">事件路由。</param>
 /// <param name="handler">事件处理器。</param>
 public virtual void RemoveAsyncEventHandler <T>(DomainServiceEventRoute route, DomainServiceAsyncEventHandler <T> handler)
     where T : EventArgs
 {
     if (route == null)
     {
         throw new ArgumentNullException(nameof(route));
     }
     if (handler == null)
     {
         throw new ArgumentNullException(nameof(handler));
     }
     if (route.HandlerType != typeof(DomainServiceAsyncEventHandler <T>))
     {
         throw new InvalidCastException("事件路由处理器类型与传入的类型不符。");
     }
     lock (_Events)
     {
         Delegate d = GetEventRouteDelegate(route);
         if (d == null)
         {
             SetEventRouteDelegate(route, handler);
         }
         else
         {
             SetEventRouteDelegate(route, Delegate.Remove(d, handler));
         }
     }
 }
Пример #2
0
 /// <summary>
 /// 添加事件处理器。
 /// </summary>
 /// <param name="route">事件路由。</param>
 /// <param name="handler">事件处理器。</param>
 public virtual void AddEventHandler(DomainServiceEventRoute route, DomainServiceEventHandler handler)
 {
     if (route == null)
     {
         throw new ArgumentNullException(nameof(route));
     }
     if (handler == null)
     {
         throw new ArgumentNullException(nameof(handler));
     }
     if (route.HandlerType != typeof(DomainServiceEventHandler))
     {
         throw new InvalidCastException("事件路由处理器类型与传入的类型不符。");
     }
     lock (_Events)
     {
         Delegate d = GetEventRouteDelegate(route);
         if (d == null)
         {
             SetEventRouteDelegate(route, handler);
         }
         else
         {
             SetEventRouteDelegate(route, Delegate.Combine(d, handler));
         }
     }
 }
Пример #3
0
        /// <summary>
        /// 引发事件。
        /// </summary>
        /// <param name="route">事件路由。</param>
        /// <param name="context">领域执行上下文。</param>
        /// <param name="eventArgs">事件参数。</param>
        public virtual void RaiseEvent <T>(DomainServiceEventRoute route, IDomainExecutionContext context, T eventArgs)
            where T : EventArgs
        {
            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (route.HandlerType != typeof(DomainServiceEventHandler <T>))
            {
                throw new InvalidCastException("事件路由处理器类型不符。");
            }
            Delegate d = GetEventRouteDelegate(route);

            if (d == null)
            {
                return;
            }
            foreach (var item in d.GetInvocationList().Cast <DomainServiceEventHandler <T> >())
            {
                item(context, eventArgs);
            }
            if (route.ParentRoute != null)
            {
                RaiseEvent(route.ParentRoute, context, eventArgs);
            }
        }
Пример #4
0
        /// <summary>
        /// 注册异步事件。
        /// </summary>
        /// <typeparam name="T">事件参数类型。</typeparam>
        /// <param name="name">事件名称。</param>
        /// <param name="ownerType">所有者类型。</param>
        /// <returns></returns>
        public static DomainServiceEventRoute RegisterAsyncEvent <T>(string name, Type ownerType)
            where T : EventArgs
        {
            DomainServiceEventRoute route = new DomainServiceEventRoute(name, ownerType, typeof(DomainServiceAsyncEventHandler <T>));

            return(route);
        }
Пример #5
0
 public override void RaiseEvent <T>(DomainServiceEventRoute route, IDomainExecutionContext context, T eventArgs)
 {
     base.RaiseEvent <T>(route, context, eventArgs);
     if (_Parent != null)
     {
         _Parent.RaiseEvent(route, context, eventArgs);
     }
 }
Пример #6
0
        public override async Task RaiseAsyncEvent <T>(DomainServiceEventRoute route, IDomainExecutionContext context, T eventArgs)
        {
            await base.RaiseAsyncEvent <T>(route, context, eventArgs);

            if (_Parent != null)
            {
                await _Parent.RaiseAsyncEvent(route, context, eventArgs);
            }
        }
Пример #7
0
        protected override Delegate GetEventRouteDelegate(DomainServiceEventRoute route)
        {
            Delegate d;

            if (!_Events.TryGetValue(route, out d))
            {
                return(null);
            }
            return(d);
        }
Пример #8
0
 /// <summary>
 /// 注册事件路由。
 /// </summary>
 /// <param name="route">事件路由。</param>
 public virtual void RegisterEventRoute(DomainServiceEventRoute route)
 {
     lock (_Events)
     {
         if (_Events.ContainsKey(route))
         {
             throw new InvalidOperationException("已添加的事件路由。");
         }
         _Events.Add(route, null);
     }
 }
Пример #9
0
 protected override void SetEventRouteDelegate(DomainServiceEventRoute route, Delegate value)
 {
     if (_Events.ContainsKey(route))
     {
         _Events[route] = value;
     }
     else
     {
         _Events.Add(route, value);
     }
 }
Пример #10
0
        /// <summary>
        /// 重载事件。
        /// </summary>
        /// <param name="route">事件路由。</param>
        /// <param name="ownerType">所有者类型。</param>
        /// <returns></returns>
        public static DomainServiceEventRoute OverrideEvent(DomainServiceEventRoute route, Type ownerType)
        {
            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }
            if (ownerType == null)
            {
                throw new ArgumentNullException(nameof(ownerType));
            }
            DomainServiceEventRoute newRoute = new DomainServiceEventRoute(route, ownerType);

            return(newRoute);
        }
Пример #11
0
        /// <summary>
        /// 引发异步事件。
        /// </summary>
        /// <param name="route">事件路由。</param>
        /// <param name="context">领域执行上下文。</param>
        public virtual async Task RaiseAsyncEvent(DomainServiceEventRoute route, IDomainExecutionContext context)
        {
            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (route.HandlerType != typeof(DomainServiceAsyncEventHandler))
            {
                throw new InvalidCastException("事件路由处理器类型不符。");
            }
            Delegate d = GetEventRouteDelegate(route);

            if (d == null)
            {
                return;
            }
            foreach (var item in d.GetInvocationList().Cast <DomainServiceAsyncEventHandler>())
            {
                if (route.AsyncMode == DomainServiceAsyncEventMode.Await)
                {
                    await item(context);
                }
                else
                {
                    Task itemTask = item(context);
                }
            }
            if (route.ParentRoute != null)
            {
                await RaiseAsyncEvent(route.ParentRoute, context);
            }
        }
 public override void RaiseEvent <T>(DomainServiceEventRoute route, IDomainExecutionContext context, T eventArgs)
 {
     base.RaiseEvent <T>(route, context, eventArgs);
     DomainContextEventManager.GlobalEventManager.RaiseEvent(route, context, eventArgs);
 }
Пример #13
0
 /// <summary>
 /// 移除事件处理器。
 /// </summary>
 /// <param name="route">事件路由。</param>
 /// <param name="handler">事件处理器。</param>
 protected virtual void RemoveAsyncEventHandler(DomainServiceEventRoute route, DomainServiceAsyncEventHandler handler)
 {
     DomainServiceEventManager.GlobalEventManager.RemoveAsyncEventHandler(route, handler);
 }
Пример #14
0
 /// <summary>
 /// 添加事件处理器。
 /// </summary>
 /// <param name="route">事件路由。</param>
 /// <param name="handler">事件处理器。</param>
 protected virtual void AddEventHandler(DomainServiceEventRoute route, DomainServiceEventHandler handler)
 {
     DomainServiceEventManager.GlobalEventManager.AddEventHandler(route, handler);
 }
Пример #15
0
 public override void RegisterEventRoute(DomainServiceEventRoute route)
 {
     throw new NotSupportedException("领域上下文当中的事件管理器不支持该方法。");
 }
Пример #16
0
 /// <summary>
 /// 移除事件处理器。
 /// </summary>
 /// <param name="route">事件路由。</param>
 /// <param name="handler">事件处理器。</param>
 protected virtual void RemoveAsyncEventHandler <T>(DomainServiceEventRoute route, DomainServiceAsyncEventHandler <T> handler)
     where T : EventArgs
 {
     DomainServiceEventManager.GlobalEventManager.RemoveAsyncEventHandler(route, handler);
 }
Пример #17
0
 protected virtual void RaiseEvent <TArgs>(DomainServiceEventRoute eventRoute, TArgs e)
     where TArgs : EventArgs
 {
     Context.DomainContext.EventManager.RaiseEvent(eventRoute, Context, e);
 }
Пример #18
0
 protected virtual void RaiseEvent(DomainServiceEventRoute eventRoute)
 {
     Context.DomainContext.EventManager.RaiseEvent(eventRoute, Context);
 }
Пример #19
0
 private DomainServiceEventRoute(DomainServiceEventRoute parentRoute, Type ownerType) : this(parentRoute.Name, ownerType, parentRoute.HandlerType, parentRoute.AsyncMode)
 {
     ParentRoute = parentRoute;
 }
Пример #20
0
        /// <summary>
        /// 注册异步事件。
        /// </summary>
        /// <param name="name">事件名称。</param>
        /// <param name="ownerType">所有者类型。</param>
        /// <returns></returns>
        public static DomainServiceEventRoute RegisterAsyncEvent(string name, Type ownerType)
        {
            DomainServiceEventRoute route = new DomainServiceEventRoute(name, ownerType, typeof(DomainServiceAsyncEventHandler));

            return(route);
        }
Пример #21
0
 protected virtual Task RaiseAsyncEvent(DomainServiceEventRoute eventRoute)
 {
     return(Context.DomainContext.EventManager.RaiseAsyncEvent(eventRoute, Context));
 }
Пример #22
0
 protected virtual Task RaiseAsyncEvent <TArgs>(DomainServiceEventRoute eventRoute, TArgs e)
     where TArgs : EventArgs
 {
     return(Context.DomainContext.EventManager.RaiseAsyncEvent(eventRoute, Context, e));
 }
Пример #23
0
 /// <summary>
 /// 设置事件路由委托。
 /// </summary>
 /// <param name="route">事件路由。</param>
 /// <param name="value">事件委托。</param>
 protected virtual void SetEventRouteDelegate(DomainServiceEventRoute route, Delegate value)
 {
     _Events[route] = value;
 }
        public override async Task RaiseAsyncEvent <T>(DomainServiceEventRoute route, IDomainExecutionContext context, T eventArgs)
        {
            await base.RaiseAsyncEvent <T>(route, context, eventArgs);

            await DomainContextEventManager.GlobalEventManager.RaiseAsyncEvent(route, context, eventArgs);
        }
Пример #25
0
 /// <summary>
 /// 获取事件路由委托。
 /// </summary>
 /// <param name="route">事件路由。</param>
 /// <returns>返回事件委托。</returns>
 protected virtual Delegate GetEventRouteDelegate(DomainServiceEventRoute route)
 {
     return(_Events[route]);
 }