protected EventTable GetEventTable()
 {
     if (m_tblEvent == null)
     {
         m_tblEvent = new EventTable();
     }
     return(m_tblEvent);
 }
        /// <summary>
        /// 调用它以释放模块
        /// </summary>
        public override void Release()
        {
            if (m_tblEvent != null)
            {
                m_tblEvent.Clear();
                m_tblEvent = null;
            }

            base.Release();
        }
        public BusinessModule CreateModule(string name, object args = null)
        {
            this.Log("CreateModule() name = " + name + ", args = " + args);

            if (m_mapModules.ContainsKey(name))
            {
                this.LogError("CreateModule() The Module<{0}> Has Existed!");
                return(null);
            }

            BusinessModule module = null;
            Type           type   = Type.GetType(m_domain + "." + name);

            if (type != null)
            {
                module = Activator.CreateInstance(type) as BusinessModule;
            }
            else
            {
                module = new LuaModule(name);
            }
            m_mapModules.Add(name, module);

            //处理预监听的事件
            if (m_mapPreListenEvents.ContainsKey(name))
            {
                EventTable mgrEvent = null;
                mgrEvent = m_mapPreListenEvents[name];
                m_mapPreListenEvents.Remove(name);

                module.SetEventTable(mgrEvent);
            }

            module.Create(args);

            //处理缓存的消息
            if (m_mapCacheMessage.ContainsKey(name))
            {
                List <MessageObject> list = m_mapCacheMessage[name];
                for (int i = 0; i < list.Count; i++)
                {
                    MessageObject msgobj = list[i];
                    module.HandleMessage(msgobj.msg, msgobj.args);
                }
                m_mapCacheMessage.Remove(name);
            }

            return(module);
        }
        private EventTable GetPreEventTable(string target)
        {
            EventTable table = null;

            if (!m_mapPreListenEvents.ContainsKey(target))
            {
                table = new EventTable();
                m_mapPreListenEvents.Add(target, table);
            }
            else
            {
                table = m_mapPreListenEvents[target];
            }
            return(table);
        }
        /// <summary>
        /// 获得指定模块的事件
        /// </summary>
        /// <param name="target"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public ModuleEvent Event(string target, string type)
        {
            ModuleEvent    evt    = null;
            BusinessModule module = GetModule(target);

            if (module != null)
            {
                evt = module.Event(type);
            }
            else
            {
                //预创建事件
                EventTable table = GetPreEventTable(target);
                evt = table.GetEvent(type);
                this.LogWarning("Event() target不存在!将预监听事件! target:{0}, event:{1}", target, type);
            }
            return(evt);
        }
 internal void SetEventTable(EventTable mgrEvent)
 {
     m_tblEvent = mgrEvent;
 }