/// <summary> /// 缓存时间事件 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getTime">时间获取器</param> /// <param name="run">事件委托</param> /// <param name="isReset">是否绑定事件与重置数据</param> public Timer(Event.Cache <valueType, modelType> cache, Func <valueType, DateTime> getTime, Action run, bool isReset) { if (cache == null) { throw new ArgumentNullException("cache is null"); } if (getTime == null) { throw new ArgumentNullException("getTime is null"); } if (run == null) { throw new ArgumentNullException("run is null"); } runTimeHandle = runTime; this.cache = cache; this.getTime = getTime; this.run = run; minTime = DateTime.MaxValue; if (isReset) { foreach (valueType value in cache.Values) { DateTime time = getTime(value); if (time < minTime && time > AutoCSer.Date.BaseTime) { minTime = time; } } Append(minTime); cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; } }
/// <summary> /// 分组列表缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getIndex">数组索引获取器</param> /// <param name="arraySize">数组容器大小</param> /// <param name="isRemoveEnd">移除数据并使用最后一个数据移动到当前位置</param> /// <param name="isReset">是否绑定事件并重置数据</param> public ArrayList(Event.Cache <valueType, modelType> cache, Func <valueType, int> getIndex, int arraySize, bool isRemoveEnd, bool isReset) { if (cache == null) { throw new ArgumentNullException("cache is null"); } if (getIndex == null) { throw new ArgumentNullException("getIndex is null"); } array = new ListArray <valueType> [arraySize]; this.cache = cache; this.getIndex = getIndex; this.isRemoveEnd = isRemoveEnd; if (isReset) { foreach (valueType value in cache.Values) { int index = getIndex(value); ListArray <valueType> list = array[index]; if (list == null) { array[index] = list = new ListArray <valueType>(); } list.Add(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }
/// <summary> /// 字典缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组字典关键字获取器</param> /// <param name="isReset">是否初始化</param> public DictionaryArray(Event.Cache <valueType, modelType> cache, Func <valueType, keyType> getKey, bool isReset = true) { if (cache == null) { throw new ArgumentNullException("cache is null"); } if (getKey == null) { throw new ArgumentNullException("getKey is null"); } this.cache = cache; this.getKey = getKey; if (isReset) { Array.Reset(); foreach (valueType value in cache.Values) { onInserted(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }
/// <summary> /// 分组列表缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组关键字获取器</param> /// <param name="getSort">排序关键字获取器</param> /// <param name="isReset">是否初始化</param> public DictionarySearchTreeDictionary (Event.Cache <valueType, modelType> cache, Func <valueType, keyType> getKey, Func <valueType, sortType> getSort, bool isReset = true) { if (cache == null) { throw new ArgumentNullException("cache is null"); } if (getKey == null) { throw new ArgumentNullException("getKey is null"); } if (getSort == null) { throw new ArgumentNullException("getSort is null"); } this.cache = cache; this.getKey = getKey; this.getSort = getSort; groups = DictionaryCreator <RandomKey <keyType> > .Create <AutoCSer.SearchTree.Dictionary <sortType, valueType> >(); if (isReset) { foreach (valueType value in cache.Values) { onInserted(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }
/// <summary> /// 分组列表缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组字典关键字获取器</param> /// <param name="isRemoveEnd">移除数据并使用最后一个数据移动到当前位置</param> /// <param name="isReset">是否绑定事件并重置数据</param> public DictionaryList(Event.Cache <valueType, modelType> cache, Func <valueType, keyType> getKey, bool isRemoveEnd = false, bool isReset = true) { if (cache == null) { throw new ArgumentNullException("cache is null"); } if (getKey == null) { throw new ArgumentNullException("getKey is null"); } this.cache = cache; this.getKey = getKey; this.isRemoveEnd = isRemoveEnd; groups = DictionaryCreator <RandomKey <keyType> > .Create <ListArray <valueType> >(); if (isReset) { foreach (valueType value in cache.Values) { onInserted(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }
/// <summary> /// 字典缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组字典关键字获取器</param> /// <param name="isReset">是否初始化</param> public Dictionary(Event.Cache <valueType, modelType> cache, Func <valueType, keyType> getKey, bool isReset = true) { if (cache == null) { throw new ArgumentNullException("cache is null"); } if (getKey == null) { throw new ArgumentNullException("getKey is null"); } this.cache = cache; this.getKey = getKey; if (isReset) { dictionary = DictionaryCreator <RandomKey <keyType> > .Create <valueType>(cache.ValueCount); foreach (valueType value in cache.Values) { dictionary.Add(getKey(value), value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } else { dictionary = DictionaryCreator <RandomKey <keyType> > .Create <valueType>(); } }
/// <summary> /// 分组列表 延时排序缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组字典关键字获取器</param> /// <param name="getValue">获取目标对象委托</param> /// <param name="getIndex">获取数组索引</param> /// <param name="arraySize">数组容器大小</param> /// <param name="member">缓存字段表达式</param> /// <param name="getTargets"></param> /// <param name="sorter">排序器</param> /// <param name="isReset">是否初始化</param> public MemberArrayLadyOrderArray(Event.Cache <valueType, modelType> cache, Func <modelType, keyType> getKey , Func <keyType, targetType> getValue, Func <valueType, int> getIndex, int arraySize, Expression <Func <targetType, LadyOrderArray <valueType>[]> > member , Func <IEnumerable <targetType> > getTargets, Func <LeftArray <valueType>, LeftArray <valueType> > sorter, bool isReset) : base(cache, getKey, getValue, member, getTargets) { if (getIndex == null) { throw new ArgumentNullException("getIndex is null"); } if (sorter == null) { throw new ArgumentNullException("sorter is null"); } if (arraySize <= 0) { throw new IndexOutOfRangeException("arraySize[" + arraySize.toString() + "] <= 0"); } this.getIndex = getIndex; this.arraySize = arraySize; this.sorter = sorter; if (isReset) { foreach (valueType value in cache.Values) { onInserted(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }
/// <summary> /// 分组列表缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getIndex">数组索引获取器</param> /// <param name="arraySize">数组大小</param> /// <param name="getSort">排序关键字获取器</param> /// <param name="isReset">是否初始化</param> public ArraySearchTreeDictionary(Event.Cache <valueType, modelType> cache, Func <valueType, int> getIndex, int arraySize, Func <valueType, sortType> getSort, bool isReset = true) { if (cache == null) { throw new ArgumentNullException("cache is null"); } if (getIndex == null) { throw new ArgumentNullException("getIndex is null"); } if (getSort == null) { throw new ArgumentNullException("getSort is null"); } treeArray = new AutoCSer.SearchTree.Dictionary <sortType, valueType> [arraySize]; this.cache = cache; this.getIndex = getIndex; this.getSort = getSort; if (isReset) { foreach (valueType value in cache.Values) { onInserted(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }
/// <summary> /// 分组列表 延时排序缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组字典关键字获取器</param> /// <param name="getValue">获取目标对象委托</param> /// <param name="member">缓存字段表达式</param> /// <param name="getTargets"></param> /// <param name="sorter">排序器</param> /// <param name="isReset">是否初始化</param> public MemberOrderList(Event.Cache <valueType, modelType> cache, Func <modelType, keyType> getKey , Func <keyType, targetType> getValue, Expression <Func <targetType, ListArray <valueType> > > member , Func <IEnumerable <targetType> > getTargets, Func <LeftArray <valueType>, LeftArray <valueType> > sorter, bool isReset) : base(cache, getKey, getValue, member, getTargets) { if (sorter == null) { throw new ArgumentNullException(); } this.sorter = sorter; if (isReset) { HashSet <keyType> keys = HashSetCreator <keyType> .Create(); foreach (valueType value in cache.Values) { keyType key = getKey(value); targetType target = getValue(key); if (target == null) { cache.SqlTable.Log.Debug(typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString(), LogLevel.Debug | LogLevel.Info | LogLevel.AutoCSer); } else { ListArray <valueType> list = getMember(target); if (list == null) { (list = new ListArray <valueType>()).Add(value); setMember(target, list); } else { list.Add(value); keys.Add(key); } } } foreach (keyType key in keys) { ListArray <valueType> list = getMember(getValue(key)); list.Array = sorter(list.Array); //list.Array.Array = list.Array.Array.notNull(); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }
/// <summary> /// 分组列表缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组关键字获取器</param> /// <param name="getSort">排序关键字获取器</param> /// <param name="isValue">缓存值判定</param> public DictionarySearchTreeDictionaryWhere(Event.Cache <valueType, modelType> cache, Func <valueType, keyType> getKey, Func <valueType, sortType> getSort, Func <valueType, bool> isValue) : base(cache, getKey, getSort, false) { if (isValue == null) { throw new ArgumentNullException(); } this.isValue = isValue; foreach (valueType value in cache.Values) { onInserted(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; }
/// <summary> /// 分组列表缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组字典关键字获取器</param> /// <param name="getValue">获取目标对象委托</param> /// <param name="member">缓存字段表达式</param> /// <param name="getTargets">获取缓存目标对象集合</param> /// <param name="isRemoveEnd">移除数据并使用最后一个数据移动到当前位置</param> /// <param name="isReset">是否绑定事件并重置数据</param> public MemberList(Event.Cache <valueType, modelType> cache, Func <modelType, keyType> getKey , Func <keyType, targetType> getValue, Expression <Func <targetType, ListArray <valueType> > > member , Func <IEnumerable <targetType> > getTargets, bool isRemoveEnd = false, bool isReset = true) : base(cache, getKey, getValue, member, getTargets) { this.isRemoveEnd = isRemoveEnd; if (isReset) { foreach (valueType value in cache.Values) { onInserted(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }
/// <summary> /// 分组列表缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组字典关键字获取器</param> /// <param name="getValue">获取目标对象委托</param> /// <param name="member">缓存字段表达式</param> /// <param name="getTargets"></param> /// <param name="isValue">数据匹配器</param> /// <param name="isRemoveEnd">移除数据并使用最后一个数据移动到当前位置</param> public MemberListWhere(Event.Cache <valueType, modelType> cache, Func <modelType, keyType> getKey , Func <keyType, targetType> getValue, Expression <Func <targetType, ListArray <valueType> > > member , Func <IEnumerable <targetType> > getTargets, Func <valueType, bool> isValue, bool isRemoveEnd = false) : base(cache, getKey, getValue, member, getTargets, isRemoveEnd, false) { if (isValue == null) { throw new ArgumentNullException(); } this.isValue = isValue; foreach (valueType value in cache.Values) { onInserted(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; }
/// <summary> /// 分组字典缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组字典关键字获取器</param> /// <param name="getValue">获取目标对象委托</param> /// <param name="member">缓存字段表达式</param> /// <param name="getTargets"></param> /// <param name="getValueKey">获取数据关键字委托</param> /// <param name="isReset">是否绑定事件并重置数据</param> public MemberDictionary(Event.Cache <valueType, modelType> cache, Func <modelType, keyType> getKey , Func <keyType, targetType> getValue, Expression <Func <targetType, Dictionary <RandomKey <valueKeyType>, valueType> > > member , Func <IEnumerable <targetType> > getTargets, Func <modelType, valueKeyType> getValueKey, bool isReset = true) : base(cache, getKey, getValue, member, getTargets) { if (getValueKey == null) { throw new ArgumentNullException(); } this.getValueKey = getValueKey; if (isReset) { foreach (valueType value in cache.Values) { onInserted(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }
/// <summary> /// 分组列表 延时排序缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组字典关键字获取器</param> /// <param name="getValue">获取目标对象委托</param> /// <param name="member">缓存字段表达式</param> /// <param name="getTargets"></param> /// <param name="sorter">排序器</param> /// <param name="isReset">是否初始化</param> public MemberLazyOrderArray(Event.Cache <valueType, modelType> cache, Func <modelType, keyType> getKey , Func <keyType, targetType> getValue, Expression <Func <targetType, LazyOrderArray <valueType> > > member , Func <IEnumerable <targetType> > getTargets, Func <LeftArray <valueType>, LeftArray <valueType> > sorter, bool isReset) : base(cache, getKey, getValue, member, getTargets) { if (sorter == null) { throw new ArgumentNullException(); } this.sorter = sorter; if (isReset) { foreach (valueType value in cache.Values) { onInserted(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }
/// <summary> /// 分组列表缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getKey">分组字典关键字获取器</param> /// <param name="getValue">获取目标对象委托</param> /// <param name="member">缓存字段表达式</param> /// <param name="getTargets">获取缓存目标对象集合</param> public Member(Event.Cache <valueType, modelType> cache, Func <modelType, keyType> getKey, Func <keyType, targetType> getValue , Expression <Func <targetType, cacheType> > member, Func <IEnumerable <targetType> > getTargets) { if (cache == null) { throw new ArgumentNullException("cache is null"); } if (getKey == null) { throw new ArgumentNullException("getKey is null"); } if (getValue == null) { throw new ArgumentNullException("getValue is null"); } if (getTargets == null) { throw new ArgumentNullException("getTargets is null"); } if (member == null) { throw new ArgumentNullException("member is null"); } MemberExpression <targetType, cacheType> expression = new MemberExpression <targetType, cacheType>(member); if (expression.Field == null) { throw new InvalidCastException("member is not MemberExpression"); } this.cache = cache; this.getKey = getKey; this.getValue = getValue; //XXX //this.getTargets = getTargets; getMember = expression.GetMember; setMember = expression.SetMember; }
/// <summary> /// 缓存时间事件 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getTime">时间获取器</param> /// <param name="run">事件委托</param> /// <param name="isValue">数据匹配器</param> public TimerWhere(Event.Cache <valueType, modelType> cache, Func <valueType, DateTime> getTime, Action run, Func <valueType, bool> isValue) : base(cache, getTime, run, false) { if (isValue == null) { throw new ArgumentNullException(); } this.isValue = isValue; foreach (valueType value in cache.Values) { if (isValue(value)) { DateTime time = getTime(value); if (time < minTime && time > AutoCSer.Date.BaseTime) { minTime = time; } } } Append(minTime); cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; }
/// <summary> /// 分组列表缓存 /// </summary> /// <param name="cache">整表缓存</param> /// <param name="getSort">排序关键字获取器</param> /// <param name="isReset">是否绑定事件与重置数据</param> public SearchTreeDictionary(Event.Cache <valueType, modelType> cache, Func <valueType, sortType> getSort, bool isReset = true) { if (cache == null) { throw new ArgumentNullException("cache is null"); } if (getSort == null) { throw new ArgumentNullException("getSort is null"); } this.cache = cache; this.getSort = getSort; if (isReset) { foreach (valueType value in cache.Values) { onInserted(value); } cache.OnInserted += onInserted; cache.OnUpdated += onUpdated; cache.OnDeleted += onDeleted; } }