/// <summary> /// 添加event item /// </summary> /// <param name="_eventItem"></param> /// <param name="_eventChannel"></param> /// <returns></returns> public IEventSystemItem AddEventItem(string _eventItem, IEventSystemChannel _eventChannel) { if (null == _eventChannel) { return(null); } return(AddEventItem(_eventItem, _eventChannel.ChannelName)); }
/// <summary> /// 通过指定的channel移除 /// </summary> /// <param name="_channel"></param> public static void RemoveChannel(IEventSystemChannel _channel) { if (null == _channel) { return; } RemoveChannel(_channel.ChannelName); }
/// <summary> /// 添加event item /// </summary> /// <param name="_eventItem"></param> /// <param name="_eventChannel"></param> /// <returns></returns> public IEventSystemItem AddEventItem(IEventSystemItem _eventItem, IEventSystemChannel _eventChannel) { if (null == _eventItem || null == _eventChannel) { return(null); } return(AddEventItem(_eventItem, _eventChannel)); }
/// <summary> /// 从所有Event Items中移除_channel.name名字的标签 /// </summary> /// <param name="_channel"></param> private void RemoveChannelTagInEventItems(IEventSystemChannel _channel) { if (null == _channel) { return; } foreach (var eventSystemItem in eventItemDic) { if (null != eventSystemItem.Value) { eventSystemItem.Value.RemoveChannelTag(_channel.ChannelName); } } }
/// <summary> /// 添加一个channel /// </summary> /// <param name="_channel"></param> /// <returns></returns> public IEventSystemChannel AddEventChannel(IEventSystemChannel _channel) { if (null == _channel) { return(null); } if (true == channelDic.ContainsKey(_channel.ChannelName)) { return(_channel); } ChannelTagCheck(_channel); channelDic.Add(_channel.ChannelName, _channel); return(_channel); }
/// <summary> /// 检测已有的event item中是否存在和自己tag相同的,加入到自己的队中 /// </summary> /// <param name="_channel"></param> private void ChannelTagCheck(IEventSystemChannel _channel) { if (null == _channel) { return; } foreach (var eventSystemItem in eventItemDic) { if (null != eventSystemItem.Value) { if (-1 != Arr.IndexOf(eventSystemItem.Value.GetChannelTags(), _channel.ChannelName)) { _channel.AddEventItem(eventSystemItem.Value); } } } }
/// <summary> /// channel name /// </summary> /// <param name="_channelName"></param> public void RemoveEventChannel(string _channelName) { if (true == string.IsNullOrEmpty(_channelName)) { return; } if (true == channelDic.ContainsKey(_channelName)) { IEventSystemChannel eventChannel = channelDic[_channelName]; if (null != eventChannel) { RemoveChannelTagInEventItems(eventChannel); ((IEventDispose)eventChannel).Dispose(); } channelDic.Remove(_channelName); } }
/// <summary> /// 根据 事件名字,和事件频道,添加一个具体的事件 /// </summary> /// <param name="_eventItemName"></param> /// <param name="_channelNames"></param> /// <returns></returns> public IEventSystemItem AddEventItem(string _eventItemName, params string[] _channelNames) { if (true == string.IsNullOrEmpty(_eventItemName)) { return(null); } if (null == _channelNames) { return(null); } // 检测是否已经存在event item IEventSystemItem eventItem = GetEventItem(_eventItemName); if (null != eventItem) { return(eventItem); } // 检测 chanenl foreach (var channelName in _channelNames) { IEventSystemChannel eventSystemChannel = GetEventChannel(channelName); if (null == eventSystemChannel) { var channel = AddEventChannel(channelName); if (null == channel) { this.Error(string.Format("创建Event Item[{0}]时,对应的Channel[{1}]创建失败", _eventItemName, channelName)); } } } // 创建event item eventItem = new EventSystemItem(_eventItemName, _channelNames); eventItemDic.Add(eventItem.EventName, eventItem); EventItemCheck(eventItem); return(eventItem); }
/// <summary> /// 添加消息频道 /// </summary> /// <param name="_channlName"></param> /// <returns></returns> public IEventSystemChannel AddEventChannel(string _channlName) { if (true == string.IsNullOrEmpty(_channlName)) { return(null); } IEventSystemChannel eventChannel = null; if (false == channelDic.ContainsKey(_channlName)) { eventChannel = new EventSystemChannel(_channlName); channelDic.Add(_channlName, eventChannel); ChannelTagCheck(eventChannel); } else { this.Info("已经存在相同key的channel = " + _channlName); eventChannel = channelDic[_channlName]; } return(eventChannel); }