Exemplo n.º 1
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="cacheValue"></param>
        /// <param name="value">更新后的数据</param>
        /// <param name="oldValue">更新前的数据</param>
        /// <param name="memberMap"></param>
        protected void onUpdated(valueType cacheValue, valueType value, valueType oldValue, MemberMap <modelType> memberMap)
        {
            keyType key = getKey(value), oldKey = getKey(oldValue);

            if (key.Equals(oldKey))
            {
                targetType target = getValue(key);
                if (target == null)
                {
                    cache.SqlTable.Log.Debug(typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString(), LogLevel.Debug | LogLevel.Info | LogLevel.AutoCSer);
                }
                else
                {
                    LazyOrderArray <valueType> array = getMember(target);
                    if (array == null)
                    {
                        cache.SqlTable.Log.Fatal(typeof(valueType).FullName + " 缓存同步错误", LogLevel.Fatal | LogLevel.AutoCSer);
                    }
                    else
                    {
                        array.Update(cacheValue);
                    }
                }
            }
            else
            {
                onInserted(cacheValue, key);
                onDeleted(cacheValue, oldKey);
            }
        }
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="value">数据对象</param>
        /// <param name="key"></param>
        /// <param name="index"></param>
        protected void onInserted(valueType value, keyType key, int index)
        {
            targetType target = getValue(key);

            if (target == null)
            {
                cache.SqlTable.Log.Add(AutoCSer.Log.LogType.Debug | AutoCSer.Log.LogType.Info, typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString());
            }
            else
            {
                LazyOrderArray <valueType>[] arrays = getMember(target);
                LazyOrderArray <valueType>   array;
                if (arrays == null)
                {
                    setMember(target, arrays = new LazyOrderArray <valueType> [arraySize]);
                    array = null;
                }
                else
                {
                    array = arrays[index];
                }
                if (array == null)
                {
                    arrays[index] = array = new LazyOrderArray <valueType>();
                }
                array.Insert(value);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取不排序的数据集合
        /// </summary>
        /// <param name="key">关键字</param>
        /// <returns>数据集合</returns>
        public IEnumerable <valueType> GetCache(keyType key)
        {
            LazyOrderArray <valueType> array = getCache(key);

            if (array != null)
            {
                return(array.Array);
            }
            return(EmptyArray <valueType> .Array);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取有序数据
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="index">关键字</param>
        /// <returns>获取有序数据</returns>
        public valueType At(keyType key, int index)
        {
            LazyOrderArray <valueType> array = getCache(key);

            if (array != null && (uint)index < array.Array.Length)
            {
                Threading.LazyOrderArrayAtTask <valueType> task = new Threading.LazyOrderArrayAtTask <valueType>(index, array, sorter);
                cache.SqlTable.AddQueue(task);
                return(task.Wait());
            }
            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取分页数据集合
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="index">数组索引</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="currentPage">分页页号</param>
        /// <param name="isDesc">是否逆序</param>
        /// <returns>分页数据集合</returns>
        public Threading.Awaiter <KeyValue <valueType[], int> > GetPageAwaiter(keyType key, int index, int pageSize, int currentPage, bool isDesc = false)
        {
            LazyOrderArray <valueType> array = getCache(key, index);

            if (array != null)
            {
                Threading.LazyOrderArrayPageAwaiter <valueType> task = new Threading.LazyOrderArrayPageAwaiter <valueType>(pageSize, currentPage, isDesc, array, sorter);
                cache.SqlTable.AddQueue(task);
                return(task);
            }
            return(new Threading.PageAwaiter <valueType> .NullValue());
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取分页数据集合
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="currentPage">分页页号</param>
        /// <param name="count">数据总数</param>
        /// <param name="isDesc">是否逆序</param>
        /// <returns>分页数据集合</returns>
        public valueType[] GetPage(keyType key, int pageSize, int currentPage, out int count, bool isDesc = false)
        {
            LazyOrderArray <valueType> array = getCache(key);

            if (array != null)
            {
                Threading.LazyOrderArrayPageTask <valueType> task = new Threading.LazyOrderArrayPageTask <valueType>(pageSize, currentPage, isDesc, array, sorter);
                cache.SqlTable.AddQueue(task);
                return(task.Wait(out count));
            }
            count = 0;
            return(EmptyArray <valueType> .Array);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="value">数据对象</param>
        /// <param name="key"></param>
        protected void onInserted(valueType value, keyType key)
        {
            targetType target = getValue(key);

            if (target == null)
            {
                cache.SqlTable.Log.Debug(typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString(), LogLevel.Debug | LogLevel.Info | LogLevel.AutoCSer);
            }
            else
            {
                LazyOrderArray <valueType> array = getMember(target);
                if (array == null)
                {
                    setMember(target, array = new LazyOrderArray <valueType>());
                }
                array.Insert(value);
            }
        }
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="cacheValue"></param>
        /// <param name="value">更新后的数据</param>
        /// <param name="oldValue">更新前的数据</param>
        /// <param name="memberMap"></param>
        protected void onUpdated(valueType cacheValue, valueType value, valueType oldValue, MemberMap <modelType> memberMap)
        {
            keyType key = getKey(value), oldKey = getKey(oldValue);
            int     index = getIndex(value), oldIndex = getIndex(oldValue);

            if (key.Equals(oldKey))
            {
                if (index != oldIndex)
                {
                    targetType target = getValue(key);
                    if (target == null)
                    {
                        cache.SqlTable.Log.Add(AutoCSer.Log.LogType.Debug | AutoCSer.Log.LogType.Info, typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString());
                    }
                    else
                    {
                        LazyOrderArray <valueType>[] arrays = getMember(target);
                        if (arrays != null)
                        {
                            LazyOrderArray <valueType> array = arrays[index];
                            if (array == null)
                            {
                                arrays[index] = array = new LazyOrderArray <valueType>();
                            }
                            array.Insert(cacheValue);
                            if ((array = arrays[oldIndex]) != null)
                            {
                                array.Delete(cacheValue);
                                return;
                            }
                        }
                        cache.SqlTable.Log.Add(AutoCSer.Log.LogType.Fatal, typeof(valueType).FullName + " 缓存同步错误");
                    }
                }
            }
            else
            {
                onInserted(cacheValue, key, index);
                onDeleted(cacheValue, oldKey, getIndex(oldValue));
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="value">被删除的数据</param>
        /// <param name="key">被删除数据的关键字</param>
        protected void onDeleted(valueType value, keyType key)
        {
            targetType target = getValue(key);

            if (target == null)
            {
                cache.SqlTable.Log.Debug(typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString(), LogLevel.Debug | LogLevel.Info | LogLevel.AutoCSer);
            }
            else
            {
                LazyOrderArray <valueType> array = getMember(target);
                if (array == null)
                {
                    cache.SqlTable.Log.Fatal(typeof(valueType).FullName + " 缓存同步错误", LogLevel.Fatal | LogLevel.AutoCSer);
                }
                else
                {
                    array.Delete(value);
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="value">被删除的数据</param>
        /// <param name="key">被删除数据的关键字</param>
        protected void onDeleted(valueType value, keyType key)
        {
            targetType target = getValue(key);

            if (target == null)
            {
                cache.SqlTable.Log.Add(AutoCSer.Log.LogType.Debug | AutoCSer.Log.LogType.Info, typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString());
            }
            else
            {
                LazyOrderArray <valueType> array = getMember(target);
                if (array == null)
                {
                    cache.SqlTable.Log.Add(AutoCSer.Log.LogType.Fatal, typeof(valueType).FullName + " 缓存同步错误");
                }
                else
                {
                    array.Delete(value);
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 获取匹配的数据集合
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="isValue">数据匹配器</param>
        /// <returns>数据集合</returns>
        public valueType[] GetFindArray(keyType key, Func <valueType, bool> isValue)
        {
            LazyOrderArray <valueType> array = getCache(key);

            return(array == null ? EmptyArray <valueType> .Array : array.Array.GetFindArray(isValue));
        }
Exemplo n.º 12
0
        /// <summary>
        /// 获取匹配数量
        /// </summary>
        /// <param name="key">关键字</param>
        /// <returns>匹配数量</returns>
        public int Count(keyType key)
        {
            LazyOrderArray <valueType> array = getCache(key);

            return(array == null ? 0 : array.Array.Length);
        }