/// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="value">数据对象</param>
        /// <param name="key"></param>
        protected void onInserted(valueType value, keyType key, int index)
        {
            targetType target = getValue(key);

            if (target == null)
            {
                log.Error.Add(typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString(), new System.Diagnostics.StackFrame(), true);
            }
            else
            {
                ladyOrderArray <valueType>[] arrays = GetMember(target);
                ladyOrderArray <valueType>   array;
                if (arrays == null)
                {
                    setMember(target, arrays = new ladyOrderArray <valueType> [arraySize]);
                    array = null;
                }
                else
                {
                    array = arrays[index];
                }
                if (array == null)
                {
                    arrays[index] = array = new ladyOrderArray <valueType>();
                }
                array.Insert(value);
            }
        }
Пример #2
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="value">更新后的数据</param>
        /// <param name="oldValue">更新前的数据</param>
        protected void onUpdated(valueType cacheValue, valueType value, valueType oldValue, fastCSharp.code.memberMap <modelType> memberMap)
        {
            keyType key = getKey(value), oldKey = getKey(oldValue);

            if (key.Equals(oldKey))
            {
                targetType target = getValue(key);
                if (target == null)
                {
                    log.Error.Add(typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString(), new System.Diagnostics.StackFrame(), true);
                }
                else
                {
                    ladyOrderArray <valueType> array = GetMember(target);
                    if (array == null)
                    {
                        log.Error.Add(typeof(valueType).FullName + " 缓存同步错误", null, true);
                    }
                    else
                    {
                        array.Update(cacheValue);
                    }
                }
            }
            else
            {
                onInserted(cacheValue, key);
                onDeleted(cacheValue, oldKey);
            }
        }
        /// <summary>
        /// 获取逆序分页数据集合
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="currentPage">分页页号</param>
        /// <param name="count">数据总数</param>
        /// <returns>逆序分页数据集合</returns>
        public valueType[] GetPageDesc(keyType key, int index, int pageSize, int currentPage, out int count)
        {
            ladyOrderArray <valueType> array = getCache(key, index);

            if (array != null)
            {
                return(array.GetPageDesc(cache.SqlTool.Lock, sorter, pageSize, currentPage, out count));
            }
            count = 0;
            return(nullValue <valueType> .Array);
        }
Пример #4
0
        /// <summary>
        /// 获取逆序分页数据集合
        /// </summary>
        /// <typeparam name="arrayType"></typeparam>
        /// <param name="key">关键字</param>
        /// <param name="getValue">数组转换</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="currentPage">分页页号</param>
        /// <param name="count">数据总数</param>
        /// <returns>逆序分页数据集合</returns>
        public arrayType[] GetPageDesc <arrayType>(keyType key, Func <valueType, arrayType> getValue, int pageSize, int currentPage, out int count)
        {
            ladyOrderArray <valueType> array = getCache(key);

            if (array != null)
            {
                return(array.GetPageDesc(cache.SqlTool.Lock, Sorter, getValue, pageSize, currentPage, out count));
            }
            count = 0;
            return(nullValue <arrayType> .Array);
        }
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="value">更新后的数据</param>
        /// <param name="oldValue">更新前的数据</param>
        protected void onUpdated(valueType cacheValue, valueType value, valueType oldValue, fastCSharp.code.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)
                    {
                        log.Error.Add(typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString(), new System.Diagnostics.StackFrame(), true);
                    }
                    else
                    {
                        ladyOrderArray <valueType>[] arrays = GetMember(target);
                        if (arrays != null)
                        {
                            ladyOrderArray <valueType> array = arrays[index];
                            if (array == null)
                            {
                                arrays[index] = array = new ladyOrderArray <valueType>();
                            }
                            array.Insert(cacheValue);
                            if ((array = arrays[oldIndex]) != null)
                            {
                                array.Delete(cacheValue);
                                return;
                            }
                        }
                        log.Error.Add(typeof(valueType).FullName + " 缓存同步错误", null, true);
                    }
                }
            }
            else
            {
                onInserted(cacheValue, key, index);
                onDeleted(cacheValue, oldKey, getIndex(oldValue));
            }
        }
Пример #6
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)
            {
                log.Error.Add(typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString(), new System.Diagnostics.StackFrame(), true);
            }
            else
            {
                ladyOrderArray <valueType> array = GetMember(target);
                if (array == null)
                {
                    log.Error.Add(typeof(valueType).FullName + " 缓存同步错误", null, true);
                }
                else
                {
                    array.Delete(value);
                }
            }
        }
        ///// <summary>
        ///// 获取有序数据
        ///// </summary>
        ///// <param name="key">关键字</param>
        ///// <param name="index">关键字</param>
        ///// <returns>获取有序数据</returns>
        //public valueType At(keyType key, int index)
        //{
        //    ladyOrderArray<valueType> array = getCache(key);
        //    return array == null ? null : array.At(cache.SqlTool.Lock, sorter, index);
        //}
        /// <summary>
        /// 获取排序数据范围集合
        /// </summary>
        /// <param name="key">关键字</param>
        /// <returns>排序数据范围集合</returns>
        public valueType[] GetArray(keyType key, int index)
        {
            ladyOrderArray <valueType> array = getCache(key, index);

            return(array == null ? nullValue <valueType> .Array : array.GetArray(cache.SqlTool.Lock, sorter));
        }
        /// <summary>
        /// 获取不排序的数据集合
        /// </summary>
        /// <param name="key">关键字</param>
        /// <returns>数据集合</returns>
        public subArray <valueType> GetCache(keyType key, int index)
        {
            ladyOrderArray <valueType> array = getCache(key, index);

            return(array == null ? default(subArray <valueType>) : array.CurrentArray);
        }
        /// <summary>
        /// 获取匹配的数据集合
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="isValue">数据匹配器</param>
        /// <returns>数据集合</returns>
        public valueType[] GetFindArray(keyType key, int index, Func <valueType, bool> isValue)
        {
            ladyOrderArray <valueType> array = getCache(key, index);

            return(array == null ? nullValue <valueType> .Array : array.CurrentArray.GetFindArray(isValue));
        }
        /// <summary>
        /// 查找第一个匹配的数据
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="isValue">数据匹配器</param>
        /// <returns>第一个匹配的数据,失败返回null</returns>
        public valueType FirstOrDefault(keyType key, int index, Func <valueType, bool> isValue)
        {
            ladyOrderArray <valueType> array = getCache(key, index);

            return(array == null ? null : array.CurrentArray.FirstOrDefault(isValue));
        }
        /// <summary>
        /// 获取匹配数量
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="isValue">数据匹配器,禁止锁操作</param>
        /// <returns>匹配数量</returns>
        public int Count(keyType key, int index, Func <valueType, bool> isValue)
        {
            ladyOrderArray <valueType> array = getCache(key, index);

            return(array == null ? 0 : array.CurrentArray.GetCount(isValue));
        }
        /// <summary>
        /// 获取匹配数量
        /// </summary>
        /// <param name="key">关键字</param>
        /// <returns>匹配数量</returns>
        public int Count(keyType key, int index)
        {
            ladyOrderArray <valueType> array = getCache(key, index);

            return(array == null ? 0 : array.Count);
        }
Пример #13
0
        /// <summary>
        /// 获取有序数据
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="index">关键字</param>
        /// <returns>获取有序数据</returns>
        public valueType At(keyType key, int index)
        {
            ladyOrderArray <valueType> array = getCache(key);

            return(array == null ? null : array.At(cache.SqlTool.Lock, Sorter, index));
        }