Ejemplo n.º 1
0
        /// <summary>定时任务/每每天</summary>
        public static long AddDailySchedule <TH>(this IAgent agent, int hour, int minute, Param param = null, long unscheduleId = 0) where TH : ITimerHandler
        {
            if (unscheduleId > 0)
            {
                agent.Unschedule(unscheduleId);
            }
            if (HotfixMgr.IsFromHotfix(param))
            {
                LOGGER.Fatal($"不能添加hotfix工程的类型作为Schedule参数 4 {typeof(TH)} {param.GetType()}");
                return(-1);
            }
            getAgentInfo(agent, out var actorId, out var actorAgentType);
            long id = QuartzTimer.AddDailySchedule(hour, minute, actorId, actorAgentType, typeof(TH).FullName, param);

            return(id);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 分发事件
        /// </summary>
        public void DispatchEvent(int evtType, Param param = null)
        {
            if (HotfixMgr.IsFromHotfix(param))
            {
                LOGGER.Fatal($"不能添加hotfix工程的类型作为参数 DispatchEvent {param.GetType()}");
                return;
            }

            Event evt = new Event();

            evt.EventId = evtType;
            evt.Data    = param;

            if (eventHandlers.ContainsKey(evtType))
            {
                var list = eventHandlers[evtType];
                foreach (var handlerType in list)
                {
                    try
                    {
                        var handler   = HotfixMgr.GetInstance <IEventListener>(handlerType);
                        var agentType = handler.GetType().BaseType.GenericTypeArguments[1];
                        if (agentType.GetInterface(typeof(IComponentActorAgent).FullName) != null)
                        {
                            //actor
                            ownerActor.SendAsync(() => handler.InternalHandleEvent(ownerActor.GetAgent(agentType), evt));
                        }
                        else if (agentType.GetInterface(typeof(IComponentAgent).FullName) != null)
                        {
                            //component
                            var compType = agentType.BaseType.GenericTypeArguments[0];
                            ownerActor.SendAsync(async() => {
                                var comp = await ownerActor.GetComponent(compType);
                                await handler.InternalHandleEvent(comp.GetAgent(agentType), evt);
                            }, false);
                        }
                    }
                    catch (Exception e)
                    {
                        LOGGER.Error(e.ToString());
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>定时任务/一次性</summary>
        public static long AddOnceSchedule <TH>(this IAgent agent, DateTime dateTime, Param param = null, long unscheduleId = 0) where TH : ITimerHandler
        {
            if (unscheduleId > 0)
            {
                agent.Unschedule(unscheduleId);
            }
            if (HotfixMgr.IsFromHotfix(param))
            {
                LOGGER.Fatal($"不能添加hotfix工程的类型作为Schedule参数 3  {typeof(TH)} {param.GetType()}");
                return(-1);
            }
            if (Settings.Ins.IsDebug && !isListenerLegal <TH>(agent))
            {
                return(-1);
            }

            getAgentInfo(agent, out var actorId, out var actorAgentType);
            long id = QuartzTimer.AddOnceSchedule(dateTime, actorId, actorAgentType, typeof(TH).FullName, param);

            return(id);
        }