Example #1
0
        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="eventID">事件ID</param>
        public static void DelEvent(String eventID)
        {
            using (lockObj.GetLock(mClassName, ReaderWriterLockUtil.LockTypeEnum.Writer))
            {
                if (!mData.ContainsKey(eventID))
                {
                    return;
                }

                var gEvent = mData[eventID];
                mData.Remove(eventID);

                DeleteInfo(gEvent);
                GEventHandle.RemoveImpl(gEvent.ID);
            }
        }
Example #2
0
        /// <summary>
        /// 添加事件
        /// </summary>
        /// <param name="gEvent">事件</param>
        public static void AddEvent(GlobalEvent gEvent)
        {
            using (lockObj.GetLock(mClassName, ReaderWriterLockUtil.LockTypeEnum.Writer))
            {
                if (mData.ContainsKey(gEvent.ID))
                {
                    throw new Exception($"GlobalEventBLL.AddEvent方法中,已经存在ID={gEvent.ID}的事件");
                }

                mData[gEvent.ID] = gEvent;
                InsertInfo(gEvent);

                // 加入处理队列
                GEventHandle.AddEvent(gEvent);
            }
        }
Example #3
0
        /// <summary>
        /// 添加或更新事件
        /// </summary>
        /// <param name="id">事件id</param>
        /// <param name="eventType">事件类型</param>
        /// <param name="playerId">玩家id</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">EndTime</param>
        /// <param name="content">事件内容</param>
        public static void AddOrUpdateEvent(String id, Int32 eventType, Guid playerId, DateTime startTime, DateTime endTime, String content)
        {
            using (lockObj.GetLock(mClassName, ReaderWriterLockUtil.LockTypeEnum.Writer, 500))
            {
                if (mData.ContainsKey(id))
                {
                    // 事件存在,更新事件(添加事件锁)
                    var item = mData[id];
                    using (item.GetLock(ReaderWriterLockUtil.LockTypeEnum.Writer, 10000))
                    {
                        item.StartTime = startTime;
                        item.EndTime   = endTime;
                        item.IsDone    = false;

                        UpdateInfo(item);
                    }

                    return;
                }

                // 事件不存在,添加事件
                var newEvent = new GlobalEvent
                {
                    ID        = id,
                    EventType = eventType,
                    IsDone    = false,
                    PlayerID  = playerId,
                    StartTime = startTime,
                    EndTime   = endTime,
                    Content   = content
                };

                // 插入数据
                mData[id] = newEvent;
                InsertInfo(newEvent);

                // 加入处理队列
                GEventHandle.AddEvent(newEvent);
            }
        }