Beispiel #1
0
        /// <summary>
        /// 判断数据是否存在,如果存在则返回Key
        /// </summary>
        public IEnumerable <string> Exist(IEnumerable <string> keyGroup)
        {
            //Aop
            BeforeGet(keyGroup);

            //获取当前存储Key
            var cur = ExistInner(keyGroup);///ToDo:Same Mode With Get

            if (!OnlyGetCurMedia)
            {
                //获取下级存储Key
                var nextKeyGroup = keyGroup.Except(cur);

                if (nextKeyGroup.Any())
                {
                    var next = NextMedia.Exist(nextKeyGroup);

                    if (next.Any())
                    {
                        //合并数据
                        var merge = cur.ToList();
                        merge.AddRange(next);
                        cur = merge;
                    }
                }
            }

            return(cur);
        }
Beispiel #2
0
        /// <summary>
        /// 获取数据
        /// </summary>
        public IEnumerable <T> Get(IEnumerable <string> keyGroup)
        {
            //Aop
            BeforeGet(keyGroup);

            //先从当前存储获取数据
            var cur = GetInner(keyGroup);

            if (!OnlyGetCurMedia)
            {
                //再从下级存储获取数据
                var nextKeyGroup = keyGroup.Except(cur.Select(item => item.Key_));

                if (nextKeyGroup.Any())
                {
                    var next = NextMedia.Get(nextKeyGroup);

                    if (next.Any())
                    {
                        //合并数据
                        var merge = cur.ToList();
                        merge.AddRange(next);
                        cur = merge;

                        //将下级的数据存储起来
                        AddInner(next);
                    }
                }
            }

            return(cur);
        }
Beispiel #3
0
        /// <summary>
        /// 新增数据
        /// </summary>
        public void Add(IEnumerable <T> group)
        {
            //如果Buffer存储不为空,则存到Buffer里
            if (BufferMedia != null)
            {
                lock (_BufferLock)
                {
                    if (_IsToBuffer)
                    {
                        //添加到Buffer
                        BufferMedia.Add(group);
                        _BufferCount += group.Count();

                        //如果超出最大数量,则清空Buffer
                        if (MaxBufferCount != null && _BufferCount >= MaxBufferCount)
                        {
                            FlushBuffer();
                        }

                        return;
                    }
                }
            }

            //先添加下级存储数据
            if (NextMedia != null)
            {
                NextMedia.Add(group);
            }

            //Aop
            BeforeUpdate(group);
            //再添加当前存储数据
            AddInner(group);
        }
Beispiel #4
0
        /// <summary>
        /// 删除数据
        /// </summary>
        public void Delete(IEnumerable <string> keyGroup)
        {
            //先删除下级存储数据
            if (NextMedia != null)
            {
                NextMedia.Delete(keyGroup);
            }

            //Aop
            BeforeDelete(keyGroup);
            //再删除当前存储数据
            DeleteInner(keyGroup);
        }
Beispiel #5
0
        /// <summary>
        /// 更新数据
        /// </summary>
        public void Update(IEnumerable <T> group)
        {
            //先更新下级存储数据
            if (NextMedia != null)
            {
                NextMedia.Update(group);
            }

            //Aop
            BeforeUpdate(group);
            //再更新当前存储数据
            UpdateInner(group);
        }
Beispiel #6
0
        /// <summary>
        /// 获取前执行的操作
        /// </summary>
        public virtual void BeforeGet(IEnumerable <string> keyGroup)
        {
            if (!_HasGet)
            {
                //如果是全部加载,则加载全部数据
                if (IsLoadAll && NextMedia != null)
                {
                    var next = NextMedia.GetAll();
                    AddInner(next);
                }

                _HasGet = true;
            }
        }
Beispiel #7
0
        /// <summary>
        /// 删除所有数据
        /// </summary>
        public void DeleteAll()
        {
            //删除下级数据
            if (NextMedia != null)
            {
                NextMedia.DeleteAll();
            }

            //Aop
            BeforeDelete(null);

            //删除本级数据
            DeleteAllInner();
        }
Beispiel #8
0
        /// <summary>
        /// 获取数据总数
        /// </summary>
        public int Count()
        {
            //Aop
            BeforeGet(null);

            if (OnlyGetCurMedia)
            {
                //获取当前存储数据总数
                var count = CountInner();
                return(count);
            }
            else
            {
                //获取下级存储数据总数
                var count = NextMedia.Count();
                return(count);
            }
        }
Beispiel #9
0
        /// <summary>
        /// 获取所有数据
        /// </summary>
        public IEnumerable <T> GetAll()
        {
            //Aop
            BeforeGet(null);

            if (OnlyGetCurMedia)
            {
                //从当前存储获取数据
                var group = GetAllInner();
                return(group);
            }
            else
            {
                //从下级存储获取数据
                var group = NextMedia.GetAllInner();
                return(group);
            }
        }